basic application support

This commit is contained in:
Ken Van Hoeylandt
2023-12-25 17:53:58 +01:00
parent 7886d5c2f9
commit e6525364c6
21 changed files with 341 additions and 122 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "."
INCLUDE_DIRS "."
SRC_DIRS "src"
"src/hello_world"
REQUIRES nanobake board_2432s024
)
-48
View File
@@ -1,48 +0,0 @@
#include <esp_err.h>
#include <esp_log.h>
#include <nanobake.h>
// Nanobake board support with drivers:
#include <board_2432s024_touch.h>
#include <board_2432s024_display.h>
#include <esp_lvgl_port.h>
static const char *TAG = "main";
static void prv_button_callback(lv_event_t* event) {
ESP_LOGI(TAG, "tap");
}
static void prv_main_vgl(nb_platform_t* platform) {
lv_obj_t* scr = lv_scr_act();
lvgl_port_lock(0);
lv_obj_t* label = lv_label_create(scr);
lv_label_set_recolor(label, true);
lv_obj_set_width(label, (lv_coord_t)platform->display.horizontal_resolution);
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
lv_label_set_text(label, "Hello, world!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
lv_obj_t* btn = lv_btn_create(scr);
label = lv_label_create(btn);
lv_label_set_text_static(label, "Button");
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 30);
lv_obj_add_event_cb(btn, prv_button_callback, LV_EVENT_CLICKED, NULL);
lvgl_port_unlock();
}
void app_main(void) {
nb_platform_config_t platform_config = {
.touch_driver = board_2432s024_create_touch_driver(),
.display_driver = board_2432s024_create_display_driver()
};
static nb_platform_t platform;
ESP_ERROR_CHECK(nb_platform_create(platform_config, &platform));
prv_main_vgl(&platform);
}
+42
View File
@@ -0,0 +1,42 @@
#include "hello_world.h"
#include "esp_lvgl_port.h"
#include <esp_log.h>
#include "nb_platform.h"
static const char* TAG = "app_helloworld";
static void prv_on_button_click(lv_event_t _Nonnull* event) {
ESP_LOGI(TAG, "button clicked");
}
static void prv_on_create(nb_platform_t _Nonnull* platform, lv_obj_t _Nonnull* lv_parent) {
lvgl_port_lock(0);
lv_obj_t* label = lv_label_create(lv_parent);
lv_label_set_recolor(label, true);
lv_obj_set_width(label, (lv_coord_t)platform->display->horizontal_resolution);
lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_CENTER, 0);
lv_label_set_text(label, "Hello, world!");
lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
lv_obj_t* btn = lv_btn_create(lv_parent);
label = lv_label_create(btn);
lv_label_set_text_static(label, "Button");
lv_obj_align(btn, LV_ALIGN_CENTER, 0, 30);
lv_obj_add_event_cb(btn, prv_on_button_click, LV_EVENT_CLICKED, NULL);
lvgl_port_unlock();
}
nb_app_config_t hello_world_app_config() {
nb_app_config_t config = {
.id = "helloworld",
.name = "Hello World",
.type = USER,
.on_create = &prv_on_create,
.on_update = NULL,
.on_destroy = NULL
};
return config;
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef NANOBAKE_HELLO_WORLD_H
#define NANOBAKE_HELLO_WORLD_H
#include "nb_app.h"
nb_app_config_t hello_world_app_config();
#endif //NANOBAKE_HELLO_WORLD_H
+20
View File
@@ -0,0 +1,20 @@
#include <nanobake.h>
// Hardware
#include <board_2432s024_touch.h>
#include <board_2432s024_display.h>
// Apps
#include "hello_world/hello_world.h"
void app_main(void) {
static nb_platform_config_t platform_config = {
.display_driver = &board_2432s024_create_display_driver,
.touch_driver = &board_2432s024_create_touch_driver,
.apps = {
&hello_world_app_config
}
};
nanobake_run(&platform_config);
}