[FL-2627] Flipper applications: SDK, build and debug system (#1387)
* Added support for running applications from SD card (FAPs - Flipper Application Packages) * Added plugin_dist target for fbt to build FAPs * All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default * Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them * Added debugging support for FAPs with fbt debug & VSCode * Added public firmware API with automated versioning Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: SG <who.just.the.doctor@gmail.com> Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
30
applications/main/gpio/scenes/gpio_scene.c
Normal file
30
applications/main/gpio/scenes/gpio_scene.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "gpio_scene.h"
|
||||
|
||||
// Generate scene on_enter handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_enter,
|
||||
void (*const gpio_scene_on_enter_handlers[])(void*) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_event,
|
||||
bool (*const gpio_scene_on_event_handlers[])(void* context, SceneManagerEvent event) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers array
|
||||
#define ADD_SCENE(prefix, name, id) prefix##_scene_##name##_on_exit,
|
||||
void (*const gpio_scene_on_exit_handlers[])(void* context) = {
|
||||
#include "gpio_scene_config.h"
|
||||
};
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Initialize scene handlers configuration structure
|
||||
const SceneManagerHandlers gpio_scene_handlers = {
|
||||
.on_enter_handlers = gpio_scene_on_enter_handlers,
|
||||
.on_event_handlers = gpio_scene_on_event_handlers,
|
||||
.on_exit_handlers = gpio_scene_on_exit_handlers,
|
||||
.scene_num = GpioSceneNum,
|
||||
};
|
29
applications/main/gpio/scenes/gpio_scene.h
Normal file
29
applications/main/gpio/scenes/gpio_scene.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/scene_manager.h>
|
||||
|
||||
// Generate scene id and total number
|
||||
#define ADD_SCENE(prefix, name, id) GpioScene##id,
|
||||
typedef enum {
|
||||
#include "gpio_scene_config.h"
|
||||
GpioSceneNum,
|
||||
} GpioScene;
|
||||
#undef ADD_SCENE
|
||||
|
||||
extern const SceneManagerHandlers gpio_scene_handlers;
|
||||
|
||||
// Generate scene on_enter handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_enter(void*);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_event handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) \
|
||||
bool prefix##_scene_##name##_on_event(void* context, SceneManagerEvent event);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
||||
|
||||
// Generate scene on_exit handlers declaration
|
||||
#define ADD_SCENE(prefix, name, id) void prefix##_scene_##name##_on_exit(void* context);
|
||||
#include "gpio_scene_config.h"
|
||||
#undef ADD_SCENE
|
5
applications/main/gpio/scenes/gpio_scene_config.h
Normal file
5
applications/main/gpio/scenes/gpio_scene_config.h
Normal file
@@ -0,0 +1,5 @@
|
||||
ADD_SCENE(gpio, start, Start)
|
||||
ADD_SCENE(gpio, test, Test)
|
||||
ADD_SCENE(gpio, usb_uart, UsbUart)
|
||||
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)
|
||||
ADD_SCENE(gpio, usb_uart_close_rpc, UsbUartCloseRpc)
|
104
applications/main/gpio/scenes/gpio_scene_start.c
Normal file
104
applications/main/gpio/scenes/gpio_scene_start.c
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "../gpio_app_i.h"
|
||||
#include "furi_hal_power.h"
|
||||
#include "furi_hal_usb.h"
|
||||
|
||||
enum GpioItem {
|
||||
GpioItemUsbUart,
|
||||
GpioItemTest,
|
||||
GpioItemOtg,
|
||||
};
|
||||
|
||||
enum GpioOtg {
|
||||
GpioOtgOff,
|
||||
GpioOtgOn,
|
||||
GpioOtgSettingsNum,
|
||||
};
|
||||
|
||||
const char* const gpio_otg_text[GpioOtgSettingsNum] = {
|
||||
"OFF",
|
||||
"ON",
|
||||
};
|
||||
|
||||
static void gpio_scene_start_var_list_enter_callback(void* context, uint32_t index) {
|
||||
furi_assert(context);
|
||||
GpioApp* app = context;
|
||||
if(index == GpioItemTest) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventManualControl);
|
||||
} else if(index == GpioItemUsbUart) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventUsbUart);
|
||||
}
|
||||
}
|
||||
|
||||
static void gpio_scene_start_var_list_change_callback(VariableItem* item) {
|
||||
GpioApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, gpio_otg_text[index]);
|
||||
if(index == GpioOtgOff) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOff);
|
||||
} else if(index == GpioOtgOn) {
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, GpioStartEventOtgOn);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_scene_start_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
|
||||
VariableItem* item;
|
||||
variable_item_list_set_enter_callback(
|
||||
var_item_list, gpio_scene_start_var_list_enter_callback, app);
|
||||
|
||||
variable_item_list_add(var_item_list, "USB-UART Bridge", 0, NULL, NULL);
|
||||
|
||||
variable_item_list_add(var_item_list, "GPIO Manual Control", 0, NULL, NULL);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"5V on GPIO",
|
||||
GpioOtgSettingsNum,
|
||||
gpio_scene_start_var_list_change_callback,
|
||||
app);
|
||||
if(furi_hal_power_is_otg_enabled()) {
|
||||
variable_item_set_current_value_index(item, GpioOtgOn);
|
||||
variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOn]);
|
||||
} else {
|
||||
variable_item_set_current_value_index(item, GpioOtgOff);
|
||||
variable_item_set_current_value_text(item, gpio_otg_text[GpioOtgOff]);
|
||||
}
|
||||
|
||||
variable_item_list_set_selected_item(
|
||||
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioSceneStart));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewVarItemList);
|
||||
}
|
||||
|
||||
bool gpio_scene_start_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GpioStartEventOtgOn) {
|
||||
furi_hal_power_enable_otg();
|
||||
} else if(event.event == GpioStartEventOtgOff) {
|
||||
furi_hal_power_disable_otg();
|
||||
} else if(event.event == GpioStartEventManualControl) {
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemTest);
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneTest);
|
||||
} else if(event.event == GpioStartEventUsbUart) {
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneStart, GpioItemUsbUart);
|
||||
if(!furi_hal_usb_is_locked()) {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUart);
|
||||
} else {
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCloseRpc);
|
||||
}
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void gpio_scene_start_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
}
|
30
applications/main/gpio/scenes/gpio_scene_test.c
Normal file
30
applications/main/gpio/scenes/gpio_scene_test.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "../gpio_app_i.h"
|
||||
|
||||
void gpio_scene_test_ok_callback(InputType type, void* context) {
|
||||
furi_assert(context);
|
||||
GpioApp* app = context;
|
||||
|
||||
if(type == InputTypePress) {
|
||||
notification_message(app->notifications, &sequence_set_green_255);
|
||||
} else if(type == InputTypeRelease) {
|
||||
notification_message(app->notifications, &sequence_reset_green);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_scene_test_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
gpio_item_configure_all_pins(GpioModeOutputPushPull);
|
||||
gpio_test_set_ok_callback(app->gpio_test, gpio_scene_test_ok_callback, app);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewGpioTest);
|
||||
}
|
||||
|
||||
bool gpio_scene_test_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
void gpio_scene_test_on_exit(void* context) {
|
||||
UNUSED(context);
|
||||
gpio_item_configure_all_pins(GpioModeAnalog);
|
||||
}
|
67
applications/main/gpio/scenes/gpio_scene_usb_uart.c
Normal file
67
applications/main/gpio/scenes/gpio_scene_usb_uart.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "../gpio_app_i.h"
|
||||
#include "../usb_uart_bridge.h"
|
||||
|
||||
typedef struct {
|
||||
UsbUartConfig cfg;
|
||||
UsbUartState state;
|
||||
} SceneUsbUartBridge;
|
||||
|
||||
static SceneUsbUartBridge* scene_usb_uart;
|
||||
|
||||
void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
GpioApp* app = context;
|
||||
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
|
||||
if(prev_state == 0) {
|
||||
scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
|
||||
scene_usb_uart->cfg.vcp_ch = 0; // TODO: settings load
|
||||
scene_usb_uart->cfg.uart_ch = 0;
|
||||
scene_usb_uart->cfg.flow_pins = 0;
|
||||
scene_usb_uart->cfg.baudrate_mode = 0;
|
||||
scene_usb_uart->cfg.baudrate = 0;
|
||||
app->usb_uart_bridge = usb_uart_enable(&scene_usb_uart->cfg);
|
||||
}
|
||||
|
||||
usb_uart_get_config(app->usb_uart_bridge, &scene_usb_uart->cfg);
|
||||
usb_uart_get_state(app->usb_uart_bridge, &scene_usb_uart->state);
|
||||
|
||||
gpio_usb_uart_set_callback(app->gpio_usb_uart, gpio_scene_usb_uart_callback, app);
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 0);
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUart);
|
||||
notification_message(app->notifications, &sequence_display_backlight_enforce_on);
|
||||
}
|
||||
|
||||
bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1);
|
||||
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
|
||||
return true;
|
||||
} else if(event.type == SceneManagerEventTypeTick) {
|
||||
uint32_t tx_cnt_last = scene_usb_uart->state.tx_cnt;
|
||||
uint32_t rx_cnt_last = scene_usb_uart->state.rx_cnt;
|
||||
usb_uart_get_state(app->usb_uart_bridge, &scene_usb_uart->state);
|
||||
gpio_usb_uart_update_state(
|
||||
app->gpio_usb_uart, &scene_usb_uart->cfg, &scene_usb_uart->state);
|
||||
if(tx_cnt_last != scene_usb_uart->state.tx_cnt)
|
||||
notification_message(app->notifications, &sequence_blink_blue_10);
|
||||
if(rx_cnt_last != scene_usb_uart->state.rx_cnt)
|
||||
notification_message(app->notifications, &sequence_blink_green_10);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
|
||||
if(prev_state == 0) {
|
||||
usb_uart_disable(app->usb_uart_bridge);
|
||||
free(scene_usb_uart);
|
||||
}
|
||||
notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
#include "../gpio_app_i.h"
|
||||
#include "../gpio_custom_event.h"
|
||||
|
||||
void gpio_scene_usb_uart_close_rpc_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
|
||||
widget_add_icon_element(app->widget, 78, 0, &I_ActiveConnection_50x64);
|
||||
widget_add_string_multiline_element(
|
||||
app->widget, 3, 2, AlignLeft, AlignTop, FontPrimary, "Connection\nis active!");
|
||||
widget_add_string_multiline_element(
|
||||
app->widget,
|
||||
3,
|
||||
30,
|
||||
AlignLeft,
|
||||
AlignTop,
|
||||
FontSecondary,
|
||||
"Disconnect from\nPC or phone to\nuse this function.");
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
|
||||
}
|
||||
|
||||
bool gpio_scene_usb_uart_close_rpc_on_event(void* context, SceneManagerEvent event) {
|
||||
GpioApp* app = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GpioCustomEventErrorBack) {
|
||||
if(!scene_manager_previous_scene(app->scene_manager)) {
|
||||
scene_manager_stop(app->scene_manager);
|
||||
view_dispatcher_stop(app->view_dispatcher);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_close_rpc_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
widget_reset(app->widget);
|
||||
}
|
137
applications/main/gpio/scenes/gpio_scene_usb_uart_config.c
Normal file
137
applications/main/gpio/scenes/gpio_scene_usb_uart_config.c
Normal file
@@ -0,0 +1,137 @@
|
||||
#include "../usb_uart_bridge.h"
|
||||
#include "../gpio_app_i.h"
|
||||
#include "furi_hal.h"
|
||||
|
||||
typedef enum {
|
||||
UsbUartLineIndexVcp,
|
||||
UsbUartLineIndexBaudrate,
|
||||
UsbUartLineIndexUart,
|
||||
UsbUartLineIndexFlow,
|
||||
} LineIndex;
|
||||
|
||||
static UsbUartConfig* cfg_set;
|
||||
|
||||
static const char* vcp_ch[] = {"0 (CLI)", "1"};
|
||||
static const char* uart_ch[] = {"13,14", "15,16"};
|
||||
static const char* flow_pins[] = {"None", "2,3", "6,7"};
|
||||
static const char* baudrate_mode[] = {"Host"};
|
||||
static const uint32_t baudrate_list[] = {
|
||||
2400,
|
||||
9600,
|
||||
19200,
|
||||
38400,
|
||||
57600,
|
||||
115200,
|
||||
230400,
|
||||
460800,
|
||||
921600,
|
||||
};
|
||||
|
||||
bool gpio_scene_usb_uart_cfg_on_event(void* context, SceneManagerEvent event) {
|
||||
UNUSED(context);
|
||||
UNUSED(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void line_vcp_cb(VariableItem* item) {
|
||||
GpioApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, vcp_ch[index]);
|
||||
|
||||
cfg_set->vcp_ch = index;
|
||||
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
||||
}
|
||||
|
||||
static void line_port_cb(VariableItem* item) {
|
||||
GpioApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, uart_ch[index]);
|
||||
|
||||
if(index == 0)
|
||||
cfg_set->uart_ch = FuriHalUartIdUSART1;
|
||||
else if(index == 1)
|
||||
cfg_set->uart_ch = FuriHalUartIdLPUART1;
|
||||
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
||||
}
|
||||
|
||||
static void line_flow_cb(VariableItem* item) {
|
||||
GpioApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
variable_item_set_current_value_text(item, flow_pins[index]);
|
||||
|
||||
cfg_set->flow_pins = index;
|
||||
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
||||
}
|
||||
|
||||
static void line_baudrate_cb(VariableItem* item) {
|
||||
GpioApp* app = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
|
||||
char br_text[8];
|
||||
|
||||
if(index > 0) {
|
||||
snprintf(br_text, 7, "%lu", baudrate_list[index - 1]);
|
||||
variable_item_set_current_value_text(item, br_text);
|
||||
cfg_set->baudrate = baudrate_list[index - 1];
|
||||
} else {
|
||||
variable_item_set_current_value_text(item, baudrate_mode[index]);
|
||||
cfg_set->baudrate = 0;
|
||||
}
|
||||
cfg_set->baudrate_mode = index;
|
||||
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_cfg_on_enter(void* context) {
|
||||
GpioApp* app = context;
|
||||
VariableItemList* var_item_list = app->var_item_list;
|
||||
|
||||
cfg_set = malloc(sizeof(UsbUartConfig));
|
||||
usb_uart_get_config(app->usb_uart_bridge, cfg_set);
|
||||
|
||||
VariableItem* item;
|
||||
char br_text[8];
|
||||
|
||||
item = variable_item_list_add(var_item_list, "USB Channel", 2, line_vcp_cb, app);
|
||||
variable_item_set_current_value_index(item, cfg_set->vcp_ch);
|
||||
variable_item_set_current_value_text(item, vcp_ch[cfg_set->vcp_ch]);
|
||||
|
||||
item = variable_item_list_add(
|
||||
var_item_list,
|
||||
"Baudrate",
|
||||
sizeof(baudrate_list) / sizeof(baudrate_list[0]) + 1,
|
||||
line_baudrate_cb,
|
||||
app);
|
||||
variable_item_set_current_value_index(item, cfg_set->baudrate_mode);
|
||||
if(cfg_set->baudrate_mode > 0) {
|
||||
snprintf(br_text, 7, "%lu", baudrate_list[cfg_set->baudrate_mode - 1]);
|
||||
variable_item_set_current_value_text(item, br_text);
|
||||
} else {
|
||||
variable_item_set_current_value_text(item, baudrate_mode[cfg_set->baudrate_mode]);
|
||||
}
|
||||
|
||||
item = variable_item_list_add(var_item_list, "UART Pins", 2, line_port_cb, app);
|
||||
variable_item_set_current_value_index(item, cfg_set->uart_ch);
|
||||
variable_item_set_current_value_text(item, uart_ch[cfg_set->uart_ch]);
|
||||
|
||||
item = variable_item_list_add(var_item_list, "RTS/DTR Pins", 3, line_flow_cb, app);
|
||||
variable_item_set_current_value_index(item, cfg_set->flow_pins);
|
||||
variable_item_set_current_value_text(item, flow_pins[cfg_set->flow_pins]);
|
||||
|
||||
variable_item_list_set_selected_item(
|
||||
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUartCfg));
|
||||
|
||||
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUartCfg);
|
||||
}
|
||||
|
||||
void gpio_scene_usb_uart_cfg_on_exit(void* context) {
|
||||
GpioApp* app = context;
|
||||
scene_manager_set_scene_state(
|
||||
app->scene_manager,
|
||||
GpioAppViewUsbUartCfg,
|
||||
variable_item_list_get_selected_item_index(app->var_item_list));
|
||||
variable_item_list_reset(app->var_item_list);
|
||||
free(cfg_set);
|
||||
}
|
Reference in New Issue
Block a user