[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:
131
applications/main/gpio/views/gpio_test.c
Normal file
131
applications/main/gpio/views/gpio_test.c
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "gpio_test.h"
|
||||
#include "../gpio_item.h"
|
||||
|
||||
#include <gui/elements.h>
|
||||
|
||||
struct GpioTest {
|
||||
View* view;
|
||||
GpioTestOkCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint8_t pin_idx;
|
||||
} GpioTestModel;
|
||||
|
||||
static bool gpio_test_process_left(GpioTest* gpio_test);
|
||||
static bool gpio_test_process_right(GpioTest* gpio_test);
|
||||
static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event);
|
||||
|
||||
static void gpio_test_draw_callback(Canvas* canvas, void* _model) {
|
||||
GpioTestModel* model = _model;
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "GPIO Output Mode Test");
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
elements_multiline_text_aligned(
|
||||
canvas, 64, 16, AlignCenter, AlignTop, "Press < or > to change pin");
|
||||
elements_multiline_text_aligned(
|
||||
canvas, 64, 32, AlignCenter, AlignTop, gpio_item_get_pin_name(model->pin_idx));
|
||||
}
|
||||
|
||||
static bool gpio_test_input_callback(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
GpioTest* gpio_test = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyRight) {
|
||||
consumed = gpio_test_process_right(gpio_test);
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
consumed = gpio_test_process_left(gpio_test);
|
||||
}
|
||||
} else if(event->key == InputKeyOk) {
|
||||
consumed = gpio_test_process_ok(gpio_test, event);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
static bool gpio_test_process_left(GpioTest* gpio_test) {
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
if(model->pin_idx) {
|
||||
model->pin_idx--;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gpio_test_process_right(GpioTest* gpio_test) {
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
||||
model->pin_idx++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
if(event->type == InputTypePress) {
|
||||
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
||||
gpio_item_set_pin(model->pin_idx, true);
|
||||
} else {
|
||||
gpio_item_set_all_pins(true);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
||||
gpio_item_set_pin(model->pin_idx, false);
|
||||
} else {
|
||||
gpio_item_set_all_pins(false);
|
||||
}
|
||||
consumed = true;
|
||||
}
|
||||
gpio_test->callback(event->type, gpio_test->context);
|
||||
return true;
|
||||
});
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
GpioTest* gpio_test_alloc() {
|
||||
GpioTest* gpio_test = malloc(sizeof(GpioTest));
|
||||
|
||||
gpio_test->view = view_alloc();
|
||||
view_allocate_model(gpio_test->view, ViewModelTypeLocking, sizeof(GpioTestModel));
|
||||
view_set_context(gpio_test->view, gpio_test);
|
||||
view_set_draw_callback(gpio_test->view, gpio_test_draw_callback);
|
||||
view_set_input_callback(gpio_test->view, gpio_test_input_callback);
|
||||
|
||||
return gpio_test;
|
||||
}
|
||||
|
||||
void gpio_test_free(GpioTest* gpio_test) {
|
||||
furi_assert(gpio_test);
|
||||
view_free(gpio_test->view);
|
||||
free(gpio_test);
|
||||
}
|
||||
|
||||
View* gpio_test_get_view(GpioTest* gpio_test) {
|
||||
furi_assert(gpio_test);
|
||||
return gpio_test->view;
|
||||
}
|
||||
|
||||
void gpio_test_set_ok_callback(GpioTest* gpio_test, GpioTestOkCallback callback, void* context) {
|
||||
furi_assert(gpio_test);
|
||||
furi_assert(callback);
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
UNUSED(model);
|
||||
gpio_test->callback = callback;
|
||||
gpio_test->context = context;
|
||||
return false;
|
||||
});
|
||||
}
|
14
applications/main/gpio/views/gpio_test.h
Normal file
14
applications/main/gpio/views/gpio_test.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
|
||||
typedef struct GpioTest GpioTest;
|
||||
typedef void (*GpioTestOkCallback)(InputType type, void* context);
|
||||
|
||||
GpioTest* gpio_test_alloc();
|
||||
|
||||
void gpio_test_free(GpioTest* gpio_test);
|
||||
|
||||
View* gpio_test_get_view(GpioTest* gpio_test);
|
||||
|
||||
void gpio_test_set_ok_callback(GpioTest* gpio_test, GpioTestOkCallback callback, void* context);
|
157
applications/main/gpio/views/gpio_usb_uart.c
Normal file
157
applications/main/gpio/views/gpio_usb_uart.c
Normal file
@@ -0,0 +1,157 @@
|
||||
#include "../usb_uart_bridge.h"
|
||||
#include "../gpio_app_i.h"
|
||||
#include "furi_hal.h"
|
||||
#include <gui/elements.h>
|
||||
|
||||
struct GpioUsbUart {
|
||||
View* view;
|
||||
GpioUsbUartCallback callback;
|
||||
void* context;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
uint32_t baudrate;
|
||||
uint32_t tx_cnt;
|
||||
uint32_t rx_cnt;
|
||||
uint8_t vcp_port;
|
||||
uint8_t tx_pin;
|
||||
uint8_t rx_pin;
|
||||
bool tx_active;
|
||||
bool rx_active;
|
||||
} GpioUsbUartModel;
|
||||
|
||||
static void gpio_usb_uart_draw_callback(Canvas* canvas, void* _model) {
|
||||
GpioUsbUartModel* model = _model;
|
||||
char temp_str[18];
|
||||
elements_button_left(canvas, "Config");
|
||||
canvas_draw_line(canvas, 2, 10, 125, 10);
|
||||
canvas_draw_line(canvas, 44, 52, 123, 52);
|
||||
|
||||
canvas_set_font(canvas, FontPrimary);
|
||||
canvas_draw_str(canvas, 2, 9, "USB Serial");
|
||||
canvas_draw_str(canvas, 3, 25, "TX:");
|
||||
canvas_draw_str(canvas, 3, 42, "RX:");
|
||||
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
snprintf(temp_str, 18, "COM PORT:%u", model->vcp_port);
|
||||
canvas_draw_str_aligned(canvas, 126, 8, AlignRight, AlignBottom, temp_str);
|
||||
snprintf(temp_str, 18, "Pin %u", model->tx_pin);
|
||||
canvas_draw_str(canvas, 22, 25, temp_str);
|
||||
snprintf(temp_str, 18, "Pin %u", model->rx_pin);
|
||||
canvas_draw_str(canvas, 22, 42, temp_str);
|
||||
|
||||
if(model->baudrate == 0)
|
||||
snprintf(temp_str, 18, "Baud: ????");
|
||||
else
|
||||
snprintf(temp_str, 18, "Baud: %lu", model->baudrate);
|
||||
canvas_draw_str(canvas, 45, 62, temp_str);
|
||||
|
||||
if(model->tx_cnt < 100000000) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 127, 24, AlignRight, AlignBottom, "B.");
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
snprintf(temp_str, 18, "%lu", model->tx_cnt);
|
||||
canvas_draw_str_aligned(canvas, 116, 24, AlignRight, AlignBottom, temp_str);
|
||||
} else {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 127, 24, AlignRight, AlignBottom, "KB.");
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
snprintf(temp_str, 18, "%lu", model->tx_cnt / 1024);
|
||||
canvas_draw_str_aligned(canvas, 111, 24, AlignRight, AlignBottom, temp_str);
|
||||
}
|
||||
|
||||
if(model->rx_cnt < 100000000) {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 127, 41, AlignRight, AlignBottom, "B.");
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
snprintf(temp_str, 18, "%lu", model->rx_cnt);
|
||||
canvas_draw_str_aligned(canvas, 116, 41, AlignRight, AlignBottom, temp_str);
|
||||
} else {
|
||||
canvas_set_font(canvas, FontSecondary);
|
||||
canvas_draw_str_aligned(canvas, 127, 41, AlignRight, AlignBottom, "KB.");
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
snprintf(temp_str, 18, "%lu", model->rx_cnt / 1024);
|
||||
canvas_draw_str_aligned(canvas, 111, 41, AlignRight, AlignBottom, temp_str);
|
||||
}
|
||||
|
||||
if(model->tx_active)
|
||||
canvas_draw_icon(canvas, 48, 14, &I_ArrowUpFilled_14x15);
|
||||
else
|
||||
canvas_draw_icon(canvas, 48, 14, &I_ArrowUpEmpty_14x15);
|
||||
|
||||
if(model->rx_active)
|
||||
canvas_draw_icon(canvas, 48, 34, &I_ArrowDownFilled_14x15);
|
||||
else
|
||||
canvas_draw_icon(canvas, 48, 34, &I_ArrowDownEmpty_14x15);
|
||||
}
|
||||
|
||||
static bool gpio_usb_uart_input_callback(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
GpioUsbUart* usb_uart = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
consumed = true;
|
||||
furi_assert(usb_uart->callback);
|
||||
usb_uart->callback(GpioUsbUartEventConfig, usb_uart->context);
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
GpioUsbUart* gpio_usb_uart_alloc() {
|
||||
GpioUsbUart* usb_uart = malloc(sizeof(GpioUsbUart));
|
||||
|
||||
usb_uart->view = view_alloc();
|
||||
view_allocate_model(usb_uart->view, ViewModelTypeLocking, sizeof(GpioUsbUartModel));
|
||||
view_set_context(usb_uart->view, usb_uart);
|
||||
view_set_draw_callback(usb_uart->view, gpio_usb_uart_draw_callback);
|
||||
view_set_input_callback(usb_uart->view, gpio_usb_uart_input_callback);
|
||||
|
||||
return usb_uart;
|
||||
}
|
||||
|
||||
void gpio_usb_uart_free(GpioUsbUart* usb_uart) {
|
||||
furi_assert(usb_uart);
|
||||
view_free(usb_uart->view);
|
||||
free(usb_uart);
|
||||
}
|
||||
|
||||
View* gpio_usb_uart_get_view(GpioUsbUart* usb_uart) {
|
||||
furi_assert(usb_uart);
|
||||
return usb_uart->view;
|
||||
}
|
||||
|
||||
void gpio_usb_uart_set_callback(GpioUsbUart* usb_uart, GpioUsbUartCallback callback, void* context) {
|
||||
furi_assert(usb_uart);
|
||||
furi_assert(callback);
|
||||
|
||||
with_view_model(
|
||||
usb_uart->view, (GpioUsbUartModel * model) {
|
||||
UNUSED(model);
|
||||
usb_uart->callback = callback;
|
||||
usb_uart->context = context;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
void gpio_usb_uart_update_state(GpioUsbUart* instance, UsbUartConfig* cfg, UsbUartState* st) {
|
||||
furi_assert(instance);
|
||||
furi_assert(cfg);
|
||||
furi_assert(st);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (GpioUsbUartModel * model) {
|
||||
model->baudrate = st->baudrate_cur;
|
||||
model->vcp_port = cfg->vcp_ch;
|
||||
model->tx_pin = (cfg->uart_ch == 0) ? (13) : (15);
|
||||
model->rx_pin = (cfg->uart_ch == 0) ? (14) : (16);
|
||||
model->tx_active = (model->tx_cnt != st->tx_cnt);
|
||||
model->rx_active = (model->rx_cnt != st->rx_cnt);
|
||||
model->tx_cnt = st->tx_cnt;
|
||||
model->rx_cnt = st->rx_cnt;
|
||||
return true;
|
||||
});
|
||||
}
|
18
applications/main/gpio/views/gpio_usb_uart.h
Normal file
18
applications/main/gpio/views/gpio_usb_uart.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "../gpio_custom_event.h"
|
||||
#include "../usb_uart_bridge.h"
|
||||
|
||||
typedef struct GpioUsbUart GpioUsbUart;
|
||||
typedef void (*GpioUsbUartCallback)(GpioCustomEvent event, void* context);
|
||||
|
||||
GpioUsbUart* gpio_usb_uart_alloc();
|
||||
|
||||
void gpio_usb_uart_free(GpioUsbUart* usb_uart);
|
||||
|
||||
View* gpio_usb_uart_get_view(GpioUsbUart* usb_uart);
|
||||
|
||||
void gpio_usb_uart_set_callback(GpioUsbUart* usb_uart, GpioUsbUartCallback callback, void* context);
|
||||
|
||||
void gpio_usb_uart_update_state(GpioUsbUart* instance, UsbUartConfig* cfg, UsbUartState* st);
|
Reference in New Issue
Block a user