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
+5
View File
@@ -2,5 +2,10 @@
#define NANOBAKE_H
#include "nb_platform.h"
#include "nb_app.h"
extern void nanobake_run(nb_platform_config_t _Nonnull * config);
//extern nb_app_config_t[32] nanobake_apps(nb_app_config_t app_configs, ...);
#endif //NANOBAKE_H
+49
View File
@@ -0,0 +1,49 @@
#ifndef NANOBAKE_NB_APP_H
#define NANOBAKE_NB_APP_H
#define NB_APP_ID_LENGTH 32
#define NB_APP_NAME_LENGTH 32
#include <stdio.h>
#include <esp_err.h>
#include <lvgl.h>
// region Forward declarations
struct nb_platform;
typedef struct nb_platform nb_platform_t;
//endregion
typedef enum nb_app_type nb_app_type_t;
enum nb_app_type {
SERVICE,
SYSTEM,
USER
};
typedef struct nb_app_config nb_app_config_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 {
char id[NB_APP_ID_LENGTH];
char name[NB_APP_NAME_LENGTH];
nb_app_type_t type;
nb_app_callback_on_create _Nullable on_create;
nb_app_callback_on_destroy _Nullable on_destroy;
nb_app_callback_update _Nullable on_update;
size_t update_task_stack_size;
uint32_t update_task_priority;
};
typedef struct nb_app nb_app_t;
struct nb_app {
nb_app_config_t config;
};
esp_err_t nb_app_config_validate(nb_app_config_t* _Nonnull app);
#endif //NANOBAKE_NB_APP_H
+8 -5
View File
@@ -6,22 +6,25 @@
typedef struct nb_display nb_display_t;
struct nb_display {
bool io_initialized;
uint16_t horizontal_resolution;
uint16_t vertical_resolution;
uint16_t draw_buffer_height;
uint16_t bits_per_pixel;
esp_lcd_panel_io_handle_t io_handle;
esp_lcd_panel_handle_t display_handle;
esp_lcd_panel_io_handle_t _Nonnull io_handle;
esp_lcd_panel_handle_t _Nonnull display_handle;
};
typedef struct nb_display_driver nb_display_driver_t;
struct nb_display_driver {
const char name[32];
char name[32];
esp_err_t (*create_display)(nb_display_t* display);
};
extern esp_err_t nb_display_create(nb_display_driver_t driver, nb_display_t* display);
/**
* @param[in] driver
* @return allocated display object
*/
nb_display_t _Nonnull* nb_display_create(nb_display_driver_t _Nonnull* driver);
#endif // NANOBAKE_NB_DISPLAY_H
+22 -8
View File
@@ -3,28 +3,42 @@
#include "nb_display.h"
#include "nb_touch.h"
#include "nb_app.h"
#include <esp_err.h>
#include <lvgl.h>
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 {
nb_display_driver_t display_driver;
nb_touch_driver_t touch_driver;
// Required driver for display
create_display_driver _Nonnull display_driver;
// Optional driver for touch input
create_touch_driver _Nullable touch_driver;
// List of user applications
create_app apps[];
};
typedef struct nb_lvgl nb_lvgl_t;
struct nb_lvgl {
lv_disp_t* disp;
lv_indev_t* touch_indev;
lv_disp_t* _Nonnull disp;
lv_indev_t* _Nullable touch_indev;
};
typedef struct nb_platform nb_platform_t;
struct nb_platform {
nb_display_t display;
nb_touch_t touch;
nb_lvgl_t lvgl;
nb_display_t* _Nonnull display;
nb_touch_t* _Nullable touch;
nb_lvgl_t* _Nonnull lvgl;
};
esp_err_t nb_platform_create(nb_platform_config_t config, nb_platform_t* platform);
/**
* @param[in] config
* @return a newly allocated platform instance (caller takes ownership)
*/
nb_platform_t _Nonnull* nb_platform_create(nb_platform_config_t _Nonnull* config);
#endif // NANOBAKE_NB_PLATFORM_H
+8 -4
View File
@@ -7,7 +7,7 @@
typedef struct nb_touch_driver nb_touch_driver_t;
struct nb_touch_driver {
const char name[32];
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);
};
@@ -15,10 +15,14 @@ struct nb_touch_driver {
typedef struct nb_touch nb_touch_t;
struct nb_touch {
esp_lcd_panel_io_handle_t io_handle;
esp_lcd_touch_handle_t touch_handle;
esp_lcd_panel_io_handle_t _Nonnull io_handle;
esp_lcd_touch_handle_t _Nonnull touch_handle;
};
esp_err_t nb_touch_create(nb_touch_driver_t driver, nb_touch_t* touch);
/**
* @param[in] driver
* @return a newly allocated instance
*/
nb_touch_t _Nonnull* nb_touch_create(nb_touch_driver_t _Nonnull* driver);
#endif // NANOBAKE_NB_TOUCH_H