Skip to content

Commit

Permalink
code style aligned with furi lib
Browse files Browse the repository at this point in the history
  • Loading branch information
KenVanHoeylandt committed Dec 27, 2023
1 parent f4088f5 commit 34a067c
Show file tree
Hide file tree
Showing 36 changed files with 159 additions and 173 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ During the pre-alpha stage, contributions will not yet be considered.

# Code Style

See [github.com/MaJerle/c-code-style](https://github.com/MaJerle/c-code-style).
See [this document](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/CODING_STYLE.md).

6 changes: 3 additions & 3 deletions components/board_2432s024/board_2432s024_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ IRAM_ATTR static bool prv_on_color_trans_done(esp_lcd_panel_io_handle_t io_handl
return (need_yield == pdTRUE);
}

static bool prv_create_display(nb_display_t* display) {
static bool prv_create_display(NbDisplay* display) {
ESP_LOGI(TAG, "creating display");

gpio_config_t io_conf = {
Expand Down Expand Up @@ -122,8 +122,8 @@ static bool prv_create_display(nb_display_t* display) {
return true;
}

nb_display_driver_t board_2432s024_create_display_driver() {
return (nb_display_driver_t) {
NbDisplayDriver board_2432s024_create_display_driver() {
return (NbDisplayDriver) {
.name = "ili9341_2432s024",
.create_display = &prv_create_display
};
Expand Down
2 changes: 1 addition & 1 deletion components/board_2432s024/board_2432s024_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include <nb_display.h>

extern nb_display_driver_t board_2432s024_create_display_driver();
extern NbDisplayDriver board_2432s024_create_display_driver();

#endif //NANOBAKE_BOARD_2432S024_DISPLAY_H
4 changes: 2 additions & 2 deletions components/board_2432s024/board_2432s024_touch.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static bool prv_create_touch(esp_lcd_panel_io_handle_t* io_handle, esp_lcd_touch
return true;
}

nb_touch_driver_t board_2432s024_create_touch_driver() {
return (nb_touch_driver_t) {
NbTouchDriver board_2432s024_create_touch_driver() {
return (NbTouchDriver) {
.name = "cst816s_2432s024",
.create_touch = &prv_create_touch
};
Expand Down
2 changes: 1 addition & 1 deletion components/board_2432s024/board_2432s024_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include <nb_touch.h>

nb_touch_driver_t board_2432s024_create_touch_driver();
NbTouchDriver board_2432s024_create_touch_driver();

#endif // NANOBAKE_BOARD_2432S024_TOUCH_H
20 changes: 10 additions & 10 deletions components/nanobake/src/applications/nb_applications.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#include "nb_applications.h"

// System services
extern const nb_app_t desktop_app;
extern const nb_app_t gui_app;
extern const nb_app_t loader_app;
extern const NbApp desktop_app;
extern const NbApp gui_app;
extern const NbApp loader_app;

// System apps
extern const nb_app_t system_info_app;
extern const NbApp system_info_app;

const nb_app_t* const FLIPPER_SERVICES[] = {
const NbApp* const FLIPPER_SERVICES[] = {
&desktop_app,
&gui_app,
&loader_app
};

const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(nb_app_t*);
const size_t FLIPPER_SERVICES_COUNT = sizeof(FLIPPER_SERVICES) / sizeof(NbApp*);

const nb_app_t* const FLIPPER_SYSTEM_APPS[] = {
const NbApp* const FLIPPER_SYSTEM_APPS[] = {
&system_info_app
};

const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SYSTEM_APPS) / sizeof(nb_app_t*);
const size_t FLIPPER_SYSTEM_APPS_COUNT = sizeof(FLIPPER_SYSTEM_APPS) / sizeof(NbApp*);

const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[] = {
const NbOnSystemStart FLIPPER_ON_SYSTEM_START[] = {
};

const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(nb_on_system_start_);
const size_t FLIPPER_ON_SYSTEM_START_COUNT = sizeof(FLIPPER_ON_SYSTEM_START) / sizeof(NbOnSystemStart);
12 changes: 5 additions & 7 deletions components/nanobake/src/applications/nb_applications.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#pragma once

#include "nb_app.h"
#include "nb_hardware.h"

#ifdef __cplusplus
extern "C" {
#endif

// Forward declaration
typedef struct nb_hardware nb_hardware_t;
typedef void (*NbOnSystemStart)(NbHardware* hardware);

typedef void (*nb_on_system_start_)(nb_hardware_t* hardware);

extern const nb_app_t* const FLIPPER_SERVICES[];
extern const NbApp* const FLIPPER_SERVICES[];
extern const size_t FLIPPER_SERVICES_COUNT;

extern const nb_app_t* const FLIPPER_SYSTEM_APPS[];
extern const NbApp* const FLIPPER_SYSTEM_APPS[];
extern const size_t FLIPPER_SYSTEM_APPS_COUNT;

extern const nb_on_system_start_ FLIPPER_ON_SYSTEM_START[];
extern const NbOnSystemStart FLIPPER_ON_SYSTEM_START[];
extern const size_t FLIPPER_ON_SYSTEM_START_COUNT;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static int32_t prv_desktop_main(void* param) {
return 0;
}

const nb_app_t desktop_app = {
const NbApp desktop_app = {
.id = "desktop",
.name = "Desktop",
.type = SERVICE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern "C" {
#endif

extern const nb_app_t desktop_app;
extern const NbApp desktop_app;

#ifdef __cplusplus
}
Expand Down
55 changes: 18 additions & 37 deletions components/nanobake/src/applications/services/gui/gui.c
Original file line number Diff line number Diff line change
@@ -1,55 +1,36 @@
#include "gui.h"
#include "gui_i.h"
#include "core_defines.h"
#include <record.h>
#include <mutex.h>
#include <check.h>
#include <m-dict.h>
#include <m-core.h>

typedef struct screen screen_t;
struct screen {
screen_id_t id;
lv_obj_t* parent;
on_init_lvgl _Nonnull callback;
};

static screen_id_t screen_counter = 0;

DICT_DEF2(screen_dict, screen_id_t, M_BASIC_OPLIST, screen_t, M_POD_OPLIST)

typedef struct Gui Gui;
struct Gui {
// TODO: use mutex
FuriMutex* mutex;
screen_dict_t screens;
};
static ScreenId screen_counter = 0;

Gui* gui_alloc() {
Gui* gui = malloc(sizeof(Gui));
NbGuiHandle gui_alloc() {
struct NbGui* gui = malloc(sizeof(struct NbGui));
screen_dict_init(gui->screens);
gui->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
return gui;
}

void gui_free(Gui* gui) {
void gui_free(NbGuiHandle gui) {
screen_dict_clear(gui->screens);
furi_mutex_free(gui->mutex);
free(gui);
}

void gui_lock(Gui* gui) {
void gui_lock(NbGuiHandle gui) {
furi_assert(gui);
furi_check(furi_mutex_acquire(gui->mutex, FuriWaitForever) == FuriStatusOk);
}

void gui_unlock(Gui* gui) {
void gui_unlock(NbGuiHandle gui) {
furi_assert(gui);
furi_check(furi_mutex_release(gui->mutex) == FuriStatusOk);
}

screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) {
screen_id_t id = screen_counter++;
screen_t screen = {
ScreenId gui_screen_create(NbGuiHandle gui, InitScreen callback) {
ScreenId id = screen_counter++;
NbScreen screen = {
.id = id,
.parent = NULL,
.callback = callback
Expand All @@ -68,20 +49,20 @@ screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback) {
return id;
}

lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id) {
screen_t* screen = screen_dict_get(gui->screens, id);
lv_obj_t* gui_screen_get_parent(NbGuiHandle gui, ScreenId id) {
NbScreen* screen = screen_dict_get(gui->screens, id);
furi_check(screen != NULL);
return screen->parent;
}

void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent) {
screen_t* screen = screen_dict_get(gui->screens, id);
void gui_screen_set_parent(NbGuiHandle gui, ScreenId id, lv_obj_t* parent) {
NbScreen* screen = screen_dict_get(gui->screens, id);
furi_check(screen != NULL);
screen->parent = parent;
}

void gui_screen_free(Gui* gui, screen_id_t id) {
screen_t* screen = screen_dict_get(gui->screens, id);
void gui_screen_free(NbGuiHandle gui, ScreenId id) {
NbScreen* screen = screen_dict_get(gui->screens, id);
furi_check(screen != NULL);

// TODO: notify? use callback? (done from desktop service)
Expand All @@ -93,13 +74,13 @@ void gui_screen_free(Gui* gui, screen_id_t id) {
static int32_t prv_gui_main(void* param) {
UNUSED(param);

Gui* gui = gui_alloc();
struct NbGui* gui = gui_alloc();
furi_record_create(RECORD_GUI, gui);
printf("gui app init\n");
return 0;
}

const nb_app_t gui_app = {
const NbApp gui_app = {
.id = "gui",
.name = "GUI",
.type = SERVICE,
Expand Down
16 changes: 8 additions & 8 deletions components/nanobake/src/applications/services/gui/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ extern "C" {

#define RECORD_GUI "gui"

typedef uint16_t screen_id_t;
typedef uint16_t ScreenId;

typedef struct Gui Gui;
typedef void (*on_init_lvgl)(lv_obj_t*, screen_id_t);
typedef struct NbGui* NbGuiHandle;
typedef void (*InitScreen)(lv_obj_t*, ScreenId);

screen_id_t gui_screen_create(Gui* gui, on_init_lvgl callback);
void gui_screen_free(Gui* gui, screen_id_t id);
ScreenId gui_screen_create(NbGuiHandle _Nonnull gui, InitScreen callback);
void gui_screen_free(NbGuiHandle _Nonnull gui, ScreenId id);
// TODO make internal
void gui_screen_set_parent(Gui* gui, screen_id_t id, lv_obj_t* parent);
lv_obj_t* gui_screen_get_parent(Gui* gui, screen_id_t id);
void gui_screen_set_parent(NbGuiHandle _Nonnull gui, ScreenId id, lv_obj_t* parent);
lv_obj_t* gui_screen_get_parent(NbGuiHandle _Nonnull gui, ScreenId id);

extern const nb_app_t gui_app;
extern const NbApp gui_app;

#ifdef __cplusplus
}
Expand Down
20 changes: 20 additions & 0 deletions components/nanobake/src/applications/services/gui/gui_i.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "gui.h"
#include <mutex.h>
#include <m-dict.h>
#include <m-core.h>

typedef struct {
ScreenId id;
lv_obj_t* parent;
InitScreen _Nonnull callback;
} NbScreen;

DICT_DEF2(screen_dict, ScreenId, M_BASIC_OPLIST, NbScreen, M_POD_OPLIST)

struct NbGui {
// TODO: use mutex
FuriMutex* mutex;
screen_dict_t screens;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static int32_t prv_loader_main(void* param) {
return 0;
}

const nb_app_t loader_app = {
const NbApp loader_app = {
.id = "loader",
.name = "Loader",
.type = SERVICE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern "C" {
#endif

extern const nb_app_t loader_app;
extern const NbApp loader_app;

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static int32_t system_info_entry_point(void* param) {
return 0;
}

nb_app_t system_info_app = {
NbApp system_info_app = {
.id = "systeminfo",
.name = "System Info",
.type = SYSTEM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern "C" {
#endif

extern nb_app_t system_info_app;
extern NbApp system_info_app;

#ifdef __cplusplus
}
Expand Down
14 changes: 7 additions & 7 deletions components/nanobake/src/nanobake.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "nanobake.h"
#include "nb_hardwarei.h"
#include "nb_lvgli.h"
#include "nb_appi.h"
#include "nb_hardware_i.h"
#include "nb_lvgl_i.h"
#include "nb_app_i.h"
#include "applications/nb_applications.h"
#include <esp_log.h>
#include <m-list.h>
Expand Down Expand Up @@ -34,7 +34,7 @@ size_t nanobake_get_app_thread_count() {
return thread_ids_size(prv_thread_ids);
}

static void prv_start_app(const nb_app_t _Nonnull* app) {
static void prv_start_app(const NbApp _Nonnull* app) {
ESP_LOGI(TAG, "Starting %s app \"%s\"",
nb_app_type_to_string(app->type),
app->name
Expand All @@ -58,11 +58,11 @@ static void prv_start_app(const nb_app_t _Nonnull* app) {
thread_ids_push_back(prv_thread_ids, thread_id);
}

__attribute__((unused)) extern void nanobake_start(nb_config_t _Nonnull* config) {
__attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull* config) {
prv_furi_init();

nb_hardware_t hardware = nb_hardware_create(config);
/*nb_lvgl_t lvgl =*/ nb_lvgl_init(&hardware);
NbHardware hardware = nb_hardware_create(config);
/*NbLvgl lvgl =*/ nb_lvgl_init(&hardware);

thread_ids_init(prv_thread_ids);

Expand Down
3 changes: 1 addition & 2 deletions components/nanobake/src/nanobake.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ extern "C" {

// Forward declarations
typedef void* FuriThreadId;
typedef struct nb_lvgl nb_lvgl_t;

__attribute__((unused)) extern void nanobake_start(nb_config_t _Nonnull * config);
__attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull * config);

extern FuriThreadId nanobake_get_app_thread_id(size_t index);
extern size_t nanobake_get_app_thread_count();
Expand Down
4 changes: 2 additions & 2 deletions components/nanobake/src/nb_app.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "nb_appi.h"
#include "nb_app_i.h"
#include <check.h>

const char* prv_type_service = "service";
const char* prv_type_system = "system";
const char* prv_type_user = "user";

const char* nb_app_type_to_string(nb_app_type_t type) {
const char* nb_app_type_to_string(NbAppType type) {
switch (type) {
case SERVICE:
return prv_type_service;
Expand Down
Loading

0 comments on commit 34a067c

Please sign in to comment.