Skip to content

Commit

Permalink
Wifi support and much more (#9)
Browse files Browse the repository at this point in the history
* add wifi service

* updates for service/app registry changes

* wifi wip

* basic wifi functionality

radio on/off is working
scanning state is working

* fix for wifi switch state

* reduce singleton usage

* various improvements

* improved error handling for low memory issues

* working scanning

* various improvements

* various improvements and fixes

+ added auto-start support in Config

* allow hardwareconfig customizations

* fix for rgb format

* increased lvgl fps

17ms works but 16ms makes the touch events hang for some reason

* layout improvements

* wip on multi-screen view

* basic connection dialog

* more connection logic

* created proper app stack and lifecycle

* cleanup

* cleanup

* cleanup lv widgets

* proper toolbar implementation

* split up wifi apps

* wip

* revert naming

* wip

* temp fix for internal disconnect

* added bundle

* app/service vs appdata/servicedata

* working wifi connect parameters
  • Loading branch information
KenVanHoeylandt authored Jan 13, 2024
1 parent 83e226f commit 64a01df
Show file tree
Hide file tree
Showing 90 changed files with 2,655 additions and 914 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: None
AlignOperands: Align
AlignOperands: DontAlign
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ and [esp_lcd_touch](https://components.espressif.com/components/espressif/esp_lc
### Devices

Predefined configurations are available for:
- Yellow Board: 2.4" with capacitive touch (2432S024) (see AliExpress [1](https://www.aliexpress.com/item/1005005902429049.html), [2](https://www.aliexpress.com/item/1005005865107357.html))
- Yellow Board: 2.4" with capacitive touch (2432S024C) (see AliExpress [1](https://www.aliexpress.com/item/1005005902429049.html), [2](https://www.aliexpress.com/item/1005005865107357.html))
- LilyGo T-Deck (see [lilygo.cc](https://www.lilygo.cc/products/t-deck), [AliExpress](https://www.aliexpress.com/item/1005005692235592.html))
- (more will follow)

Expand Down
2 changes: 1 addition & 1 deletion boards/lilygo_tdeck/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static bool create_display_device(DisplayDevice* display) {
ESP_LOGI(TAG, "install driver");
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = GPIO_NUM_NC,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
.data_endian = LCD_RGB_DATA_ENDIAN_BIG,
.bits_per_pixel = LCD_BITS_PER_PIXEL,
.flags = {
Expand Down
4 changes: 0 additions & 4 deletions boards/lilygo_tdeck/lilygo_tdeck.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "lilygo_tdeck.h"

void lilygo_tdeck_bootstrap();
DisplayDriver lilygo_tdeck_display_driver();
TouchDriver lilygo_tdeck_touch_driver();

const HardwareConfig lilygo_tdeck = {
.bootstrap = &lilygo_tdeck_bootstrap,
.display_driver = &lilygo_tdeck_display_driver,
Expand Down
13 changes: 13 additions & 0 deletions boards/lilygo_tdeck/lilygo_tdeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@

#include "tactility.h"

#ifdef __cplusplus
extern "C" {
#endif

// Available for HardwareConfig customizations
void lilygo_tdeck_bootstrap();
DisplayDriver lilygo_tdeck_display_driver();
TouchDriver lilygo_tdeck_touch_driver();

extern const HardwareConfig lilygo_tdeck;

#ifdef __cplusplus
}
#endif
2 changes: 1 addition & 1 deletion boards/yellow_board/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static bool create_display_device(DisplayDevice* display) {
ESP_LOGI(TAG, "install driver");
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = GPIO_NUM_NC,
.rgb_endian = LCD_RGB_ENDIAN_RGB,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
.bits_per_pixel = LCD_BITS_PER_PIXEL,
};

Expand Down
3 changes: 0 additions & 3 deletions boards/yellow_board/yellow_board.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "yellow_board.h"

DisplayDriver board_2432s024_create_display_driver();
TouchDriver board_2432s024_create_touch_driver();

const HardwareConfig yellow_board_24inch_cap = {
.bootstrap = NULL,
.display_driver = &board_2432s024_create_display_driver,
Expand Down
12 changes: 12 additions & 0 deletions boards/yellow_board/yellow_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,17 @@

#include "tactility.h"

#ifdef __cplusplus
extern "C" {
#endif

// Available for HardwareConfig customizations
DisplayDriver board_2432s024_create_display_driver();
TouchDriver board_2432s024_create_touch_driver();

// Capacitive touch version of the 2.4" yellow board
extern const HardwareConfig yellow_board_24inch_cap;

#ifdef __cplusplus
}
#endif
134 changes: 120 additions & 14 deletions components/furi/src/app.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,128 @@
#include "app_i.h"
#include "furi_core.h"
#include "log.h"
#include "furi_string.h"

#define TAG "app"
#include <stdio.h>

App* furi_app_alloc(const AppManifest* _Nonnull manifest) {
App app = {
static AppFlags app_get_flags_default(AppType type);

// region Alloc/free

App app_alloc(const AppManifest* manifest, Bundle* _Nullable parameters) {
AppData* data = malloc(sizeof(AppData));
*data = (AppData) {
.mutex = furi_mutex_alloc(FuriMutexTypeRecursive),
.state = APP_STATE_INITIAL,
.flags = app_get_flags_default(manifest->type),
.manifest = manifest,
.context = {
.data = NULL
}
.parameters = parameters,
.data = NULL
};
App* app_ptr = malloc(sizeof(App));
return memcpy(app_ptr, &app, sizeof(App));
return (App*)data;
}

void furi_app_free(App* app) {
furi_assert(app);
free(app);
void app_free(App app) {
AppData* data = (AppData*)app;
if (data->parameters) {
bundle_free(data->parameters);
}
furi_mutex_free(data->mutex);
free(data);
}

// endregion

// region Internal

static void app_lock(AppData* data) {
furi_mutex_acquire(data->mutex, FuriMutexTypeRecursive);
}

static void app_unlock(AppData* data) {
furi_mutex_release(data->mutex);
}

static AppFlags app_get_flags_default(AppType type) {
static const AppFlags DEFAULT_DESKTOP_FLAGS = {
.show_toolbar = false,
.show_statusbar = true
};

static const AppFlags DEFAULT_APP_FLAGS = {
.show_toolbar = true,
.show_statusbar = true
};

return type == AppTypeDesktop
? DEFAULT_DESKTOP_FLAGS
: DEFAULT_APP_FLAGS;
}

// endregion Internal

// region Public getters & setters

void app_set_state(App app, AppState state) {
AppData* data = (AppData*)app;
app_lock(data);
data->state = state;
app_unlock(data);
}

AppState app_get_state(App app) {
AppData* data = (AppData*)app;
app_lock(data);
AppState state = data->state;
app_unlock(data);
return state;
}

const AppManifest* app_get_manifest(App app) {
AppData* data = (AppData*)app;
// No need to lock const data;
return data->manifest;
}

AppFlags app_get_flags(App app) {
AppData* data = (AppData*)app;
app_lock(data);
AppFlags flags = data->flags;
app_unlock(data);
return flags;
}

void app_set_flags(App app, AppFlags flags) {
AppData* data = (AppData*)app;
app_lock(data);
data->flags = flags;
app_unlock(data);
}

void* app_get_data(App app) {
AppData* data = (AppData*)app;
app_lock(data);
void* value = data->data;
app_unlock(data);
return value;
}

void app_set_data(App app, void* value) {
AppData* data = (AppData*)app;
app_lock(data);
data->data = value;
app_unlock(data);
}

/** TODO: Make this thread-safe.
* In practice, the bundle is writeable, so someone could be writing to it
* while it is being accessed from another thread.
* Consider creating MutableBundle vs Bundle.
* Consider not exposing bundle, but expose `app_get_bundle_int(key)` methods with locking in it.
*/
Bundle* _Nullable app_get_parameters(App app) {
AppData* data = (AppData*)app;
app_lock(data);
Bundle* bundle = data->parameters;
app_unlock(data);
return bundle;
}

// endregion Public getters & setters
51 changes: 51 additions & 0 deletions components/furi/src/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#pragma once

#include "app_manifest.h"
#include "bundle.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
APP_STATE_INITIAL, // App is being activated in loader
APP_STATE_STARTED, // App is in memory
APP_STATE_SHOWING, // App view is created
APP_STATE_HIDING, // App view is destroyed
APP_STATE_STOPPED // App is not in memory
} AppState;

typedef union {
struct {
bool show_statusbar : 1;
bool show_toolbar : 1;
};
unsigned char flags;
} AppFlags;

typedef void* App;

/** @brief Create an app
* @param manifest
* @param parameters optional bundle. memory ownership is transferred to App
* @return
*/
App app_alloc(const AppManifest* manifest, Bundle* _Nullable parameters);
void app_free(App app);

void app_set_state(App app, AppState state);
AppState app_get_state(App app);

const AppManifest* app_get_manifest(App app);

AppFlags app_get_flags(App app);
void app_set_flags(App app, AppFlags flags);

void* _Nullable app_get_data(App app);
void app_set_data(App app, void* data);

Bundle* _Nullable app_get_parameters(App app);

#ifdef __cplusplus
}
#endif
26 changes: 20 additions & 6 deletions components/furi/src/app_i.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
#pragma once

#include "app.h"

#include "app_manifest.h"
#include "thread.h"
#include "context.h"
#include "mutex.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
FuriMutex* mutex;
const AppManifest* manifest;
Context context;
} App;

App* furi_app_alloc(const AppManifest* _Nonnull manifest);
void furi_app_free(App* _Nonnull app);
AppState state;
AppFlags flags;
/** @brief Optional parameters to start the app with
* When these are stored in the app struct, the struct takes ownership.
* Do not mutate after app creation.
*/
Bundle* _Nullable parameters;
/** @brief @brief Contextual data related to the running app's instance
* The app can attach its data to this.
* The lifecycle is determined by the on_start and on_stop methods in the AppManifest.
* These manifest methods can optionally allocate/free data that is attached here.
*/
void* _Nullable data;
} AppData;

#ifdef __cplusplus
}
Expand Down
15 changes: 11 additions & 4 deletions components/furi/src/app_manifest.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "context.h"
#include <stdio.h>

#ifdef __cplusplus
Expand All @@ -9,16 +8,19 @@ extern "C" {

// Forward declarations
typedef struct _lv_obj_t lv_obj_t;
typedef void* App;

typedef enum {
AppTypeDesktop,
AppTypeSystem,
AppTypeSettings,
AppTypeUser
} AppType;

typedef void (*AppOnStart)(Context* context);
typedef void (*AppOnStop)(Context* context);
typedef void (*AppOnShow)(Context* context, lv_obj_t* parent);
typedef void (*AppOnStart)(App app);
typedef void (*AppOnStop)(App app);
typedef void (*AppOnShow)(App app, lv_obj_t* parent);
typedef void (*AppOnHide)(App app);

typedef struct {
/**
Expand Down Expand Up @@ -55,6 +57,11 @@ typedef struct {
* Non-blocking method to create the GUI
*/
const AppOnShow _Nullable on_show;

/**
* Non-blocking method, called before gui is destroyed
*/
const AppOnHide _Nullable on_hide;
} AppManifest;

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions components/furi/src/app_manifest_registry.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "app_manifest_registry.h"

#include "furi_core.h"
#include "m-dict.h"
#include "m_cstr_dup.h"
Expand Down
Loading

0 comments on commit 64a01df

Please sign in to comment.