2021-10-21 18:12:20 +00:00
|
|
|
#include "../gpio_app_i.h"
|
2021-11-21 15:17:43 +00:00
|
|
|
#include "../usb_uart_bridge.h"
|
2021-10-21 18:12:20 +00:00
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
typedef struct {
|
|
|
|
UsbUartConfig cfg;
|
|
|
|
UsbUartState state;
|
|
|
|
} SceneUsbUartBridge;
|
2021-10-26 18:41:56 +00:00
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
static SceneUsbUartBridge* scene_usb_uart;
|
2021-10-21 18:12:20 +00:00
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
void gpio_scene_usb_uart_callback(GpioCustomEvent event, void* context) {
|
2021-10-21 18:12:20 +00:00
|
|
|
furi_assert(context);
|
|
|
|
GpioApp* app = context;
|
2021-11-21 15:17:43 +00:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, event);
|
2021-10-21 18:12:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gpio_scene_usb_uart_on_enter(void* context) {
|
|
|
|
GpioApp* app = context;
|
2021-11-21 15:17:43 +00:00
|
|
|
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUart);
|
|
|
|
if(prev_state == 0) {
|
2022-02-18 19:53:46 +00:00
|
|
|
scene_usb_uart = malloc(sizeof(SceneUsbUartBridge));
|
2023-08-29 04:39:34 +00:00
|
|
|
scene_usb_uart->cfg.vcp_ch = 0;
|
2021-11-21 15:17:43 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-10-21 18:12:20 +00:00
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
usb_uart_get_config(app->usb_uart_bridge, &scene_usb_uart->cfg);
|
|
|
|
usb_uart_get_state(app->usb_uart_bridge, &scene_usb_uart->state);
|
2021-11-04 19:33:28 +00:00
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
gpio_usb_uart_set_callback(app->gpio_usb_uart, gpio_scene_usb_uart_callback, app);
|
2022-03-24 15:45:03 +00:00
|
|
|
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 0);
|
2021-10-21 18:12:20 +00:00
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewUsbUart);
|
2022-04-29 14:21:12 +00:00
|
|
|
notification_message(app->notifications, &sequence_display_backlight_enforce_on);
|
2021-10-21 18:12:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-21 15:17:43 +00:00
|
|
|
bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
GpioApp* app = context;
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-03-24 15:45:03 +00:00
|
|
|
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1);
|
|
|
|
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
|
2021-11-21 15:17:43 +00:00
|
|
|
return true;
|
2023-09-21 08:06:45 +00:00
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm);
|
|
|
|
return true;
|
2021-11-21 15:17:43 +00:00
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
2021-10-21 18:12:20 +00:00
|
|
|
void gpio_scene_usb_uart_on_exit(void* context) {
|
|
|
|
GpioApp* app = context;
|
2022-03-24 15:45:03 +00:00
|
|
|
uint32_t prev_state = scene_manager_get_scene_state(app->scene_manager, GpioSceneUsbUart);
|
2021-11-21 15:17:43 +00:00
|
|
|
if(prev_state == 0) {
|
|
|
|
usb_uart_disable(app->usb_uart_bridge);
|
|
|
|
free(scene_usb_uart);
|
|
|
|
}
|
2022-04-29 14:21:12 +00:00
|
|
|
notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
|
2021-10-26 18:41:56 +00:00
|
|
|
}
|