improvements to apps and drivers
This commit is contained in:
@@ -21,13 +21,13 @@ enum nb_app_type {
|
||||
USER
|
||||
};
|
||||
|
||||
typedef struct nb_app_config nb_app_config_t;
|
||||
typedef struct nb_app nb_app_t;
|
||||
|
||||
typedef void (*nb_app_callback_on_create) (nb_platform_t* platform, lv_obj_t* lv_parent);
|
||||
typedef void (*nb_app_callback_update) (nb_platform_t* platform, lv_obj_t* lv_parent);
|
||||
typedef void (*nb_app_callback_on_destroy) (nb_platform_t* platform);
|
||||
|
||||
struct nb_app_config {
|
||||
struct nb_app {
|
||||
char id[NB_APP_ID_LENGTH];
|
||||
char name[NB_APP_NAME_LENGTH];
|
||||
nb_app_type_t type;
|
||||
@@ -38,12 +38,12 @@ struct nb_app_config {
|
||||
uint32_t update_task_priority;
|
||||
};
|
||||
|
||||
typedef struct nb_app nb_app_t;
|
||||
typedef struct nb_app_instance nb_app_instance_t;
|
||||
|
||||
struct nb_app {
|
||||
nb_app_config_t config;
|
||||
struct nb_app_instance {
|
||||
nb_app_t config;
|
||||
};
|
||||
|
||||
esp_err_t nb_app_config_validate(nb_app_config_t* _Nonnull app);
|
||||
esp_err_t nb_app_validate(nb_app_t* _Nonnull app);
|
||||
|
||||
#endif //NANOBAKE_NB_APP_H
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef struct nb_display_driver nb_display_driver_t;
|
||||
|
||||
struct nb_display_driver {
|
||||
char name[32];
|
||||
esp_err_t (*create_display)(nb_display_t* display);
|
||||
bool (*create_display)(nb_display_t* display);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
typedef nb_touch_driver_t (*create_touch_driver)();
|
||||
typedef nb_display_driver_t (*create_display_driver)();
|
||||
|
||||
typedef nb_app_config_t (*create_app)();
|
||||
|
||||
typedef struct nb_platform_config nb_platform_config_t;
|
||||
struct nb_platform_config {
|
||||
// Required driver for display
|
||||
@@ -19,7 +17,7 @@ struct nb_platform_config {
|
||||
// Optional driver for touch input
|
||||
create_touch_driver _Nullable touch_driver;
|
||||
// List of user applications
|
||||
create_app apps[];
|
||||
nb_app_t* apps[];
|
||||
};
|
||||
|
||||
typedef struct nb_lvgl nb_lvgl_t;
|
||||
|
||||
@@ -8,8 +8,7 @@ typedef struct nb_touch_driver nb_touch_driver_t;
|
||||
|
||||
struct nb_touch_driver {
|
||||
char name[32];
|
||||
esp_err_t (*init_io)(esp_lcd_panel_io_handle_t* io_handle);
|
||||
esp_err_t (*create_touch)(esp_lcd_panel_io_handle_t io_handle, esp_lcd_touch_handle_t* touch_handle);
|
||||
bool (*create_touch)(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch_handle_t* touch_handle);
|
||||
};
|
||||
|
||||
typedef struct nb_touch nb_touch_t;
|
||||
|
||||
@@ -23,14 +23,11 @@ static void prv_on_create(nb_platform_t _Nonnull* platform, lv_obj_t _Nonnull* l
|
||||
lvgl_port_unlock();
|
||||
}
|
||||
|
||||
nb_app_config_t system_info_app_config() {
|
||||
nb_app_config_t config = {
|
||||
.id = "systeminfo",
|
||||
.name = "System Info",
|
||||
.type = SYSTEM,
|
||||
.on_create = &prv_on_create,
|
||||
.on_update = NULL,
|
||||
.on_destroy = NULL
|
||||
};
|
||||
return config;
|
||||
}
|
||||
nb_app_t system_info_app = {
|
||||
.id = "systeminfo",
|
||||
.name = "System Info",
|
||||
.type = SYSTEM,
|
||||
.on_create = &prv_on_create,
|
||||
.on_update = NULL,
|
||||
.on_destroy = NULL
|
||||
};
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
#include "nb_app.h"
|
||||
|
||||
nb_app_config_t system_info_app_config();
|
||||
extern nb_app_t system_info_app;
|
||||
|
||||
#endif // NANOBAKE_SYSTEM_INFO_H
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "nanobake.h"
|
||||
#include "applications/main/system_info/system_info.h"
|
||||
|
||||
void nb_app_start(nb_platform_t _Nonnull* platform, nb_app_config_t _Nonnull* config) {
|
||||
void nb_app_start(nb_platform_t _Nonnull* platform, nb_app_t _Nonnull* config) {
|
||||
lv_obj_t* scr = lv_scr_act();
|
||||
ESP_ERROR_CHECK(nb_app_config_validate(config));
|
||||
ESP_ERROR_CHECK(nb_app_validate(config));
|
||||
config->on_create(platform, scr);
|
||||
}
|
||||
|
||||
extern void nanobake_run(nb_platform_config_t _Nonnull* config) {
|
||||
nb_platform_t _Nonnull* platform = nb_platform_create(config);
|
||||
nb_app_config_t app_config = system_info_app_config();
|
||||
nb_app_start(platform, &app_config);
|
||||
|
||||
nb_app_start(platform, config->apps[0]);
|
||||
// nb_app_start(platform, &system_info_app);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
static const char* TAG = "nb_app";
|
||||
|
||||
esp_err_t nb_app_config_validate(nb_app_config_t* _Nonnull app) {
|
||||
esp_err_t nb_app_validate(nb_app_t* _Nonnull app) {
|
||||
ESP_RETURN_ON_FALSE(
|
||||
strlen(app->id) < NB_APP_ID_LENGTH,
|
||||
ESP_FAIL,
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
nb_display_t _Nonnull* nb_display_create(nb_display_driver_t _Nonnull* driver) {
|
||||
nb_display_t _Nonnull* display = malloc(sizeof(nb_display_t));
|
||||
NB_ASSERT(driver->create_display(display) == ESP_OK, "failed to create display");
|
||||
NB_ASSERT(driver->create_display(display), "failed to create display");
|
||||
return display;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ nb_platform_t _Nonnull* nb_platform_create(nb_platform_config_t _Nonnull* config
|
||||
platform->touch = NULL;
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK(prv_lvgl_init(platform));
|
||||
NB_ASSERT(prv_lvgl_init(platform) == ESP_OK, "failed to init lvgl");
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#include "nb_touch.h"
|
||||
#include "nb_assert.h"
|
||||
#include <esp_check.h>
|
||||
|
||||
nb_touch_t _Nonnull* nb_touch_create(nb_touch_driver_t _Nonnull* driver) {
|
||||
nb_touch_t _Nonnull* touch = malloc(sizeof(nb_touch_t));
|
||||
assert(driver->init_io(&(touch->io_handle)) == ESP_OK);
|
||||
driver->create_touch(touch->io_handle, &(touch->touch_handle));
|
||||
bool success = driver->create_touch(
|
||||
&(touch->io_handle),
|
||||
&(touch->touch_handle)
|
||||
);
|
||||
NB_ASSERT(success, "touch driver failed");
|
||||
return touch;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user