|
|
|
@@ -9,8 +9,6 @@ typedef enum {
|
|
|
|
|
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", "16,15"};
|
|
|
|
@@ -28,8 +26,14 @@ static const uint32_t baudrate_list[] = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool gpio_scene_usb_uart_cfg_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
|
UNUSED(context);
|
|
|
|
|
UNUSED(event);
|
|
|
|
|
GpioApp* app = context;
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
|
if(event.event == GpioUsbUartEventConfigSet) {
|
|
|
|
|
usb_uart_set_config(app->usb_uart_bridge, app->usb_uart_cfg);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -38,55 +42,59 @@ void line_ensure_flow_invariant(GpioApp* app) {
|
|
|
|
|
// selected. This function enforces that invariant by resetting flow_pins
|
|
|
|
|
// to None if it is configured to 16,15 when LPUART is selected.
|
|
|
|
|
|
|
|
|
|
uint8_t available_flow_pins = cfg_set->uart_ch == FuriHalUartIdLPUART1 ? 3 : 4;
|
|
|
|
|
uint8_t available_flow_pins = app->usb_uart_cfg->uart_ch == FuriHalUartIdLPUART1 ? 3 : 4;
|
|
|
|
|
VariableItem* item = app->var_item_flow;
|
|
|
|
|
variable_item_set_values_count(item, available_flow_pins);
|
|
|
|
|
|
|
|
|
|
if(cfg_set->flow_pins >= available_flow_pins) {
|
|
|
|
|
cfg_set->flow_pins = 0;
|
|
|
|
|
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
|
|
|
|
if(app->usb_uart_cfg->flow_pins >= available_flow_pins) {
|
|
|
|
|
app->usb_uart_cfg->flow_pins = 0;
|
|
|
|
|
|
|
|
|
|
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_set_current_value_index(item, app->usb_uart_cfg->flow_pins);
|
|
|
|
|
variable_item_set_current_value_text(item, flow_pins[app->usb_uart_cfg->flow_pins]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void line_vcp_cb(VariableItem* item) {
|
|
|
|
|
GpioApp* app = variable_item_get_context(item);
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
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);
|
|
|
|
|
app->usb_uart_cfg->vcp_ch = index;
|
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void line_port_cb(VariableItem* item) {
|
|
|
|
|
GpioApp* app = variable_item_get_context(item);
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
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;
|
|
|
|
|
app->usb_uart_cfg->uart_ch = FuriHalUartIdUSART1;
|
|
|
|
|
else if(index == 1)
|
|
|
|
|
cfg_set->uart_ch = FuriHalUartIdLPUART1;
|
|
|
|
|
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
|
|
|
|
app->usb_uart_cfg->uart_ch = FuriHalUartIdLPUART1;
|
|
|
|
|
|
|
|
|
|
line_ensure_flow_invariant(app);
|
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void line_flow_cb(VariableItem* item) {
|
|
|
|
|
GpioApp* app = variable_item_get_context(item);
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
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);
|
|
|
|
|
app->usb_uart_cfg->flow_pins = index;
|
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void line_baudrate_cb(VariableItem* item) {
|
|
|
|
|
GpioApp* app = variable_item_get_context(item);
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
|
|
|
|
|
|
char br_text[8];
|
|
|
|
@@ -94,28 +102,29 @@ static void line_baudrate_cb(VariableItem* item) {
|
|
|
|
|
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];
|
|
|
|
|
app->usb_uart_cfg->baudrate = baudrate_list[index - 1];
|
|
|
|
|
} else {
|
|
|
|
|
variable_item_set_current_value_text(item, baudrate_mode[index]);
|
|
|
|
|
cfg_set->baudrate = 0;
|
|
|
|
|
app->usb_uart_cfg->baudrate = 0;
|
|
|
|
|
}
|
|
|
|
|
cfg_set->baudrate_mode = index;
|
|
|
|
|
usb_uart_set_config(app->usb_uart_bridge, cfg_set);
|
|
|
|
|
app->usb_uart_cfg->baudrate_mode = index;
|
|
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gpio_scene_usb_uart_cfg_on_enter(void* context) {
|
|
|
|
|
GpioApp* app = context;
|
|
|
|
|
furi_assert(app);
|
|
|
|
|
VariableItemList* var_item_list = app->var_item_list;
|
|
|
|
|
|
|
|
|
|
cfg_set = malloc(sizeof(UsbUartConfig));
|
|
|
|
|
usb_uart_get_config(app->usb_uart_bridge, cfg_set);
|
|
|
|
|
app->usb_uart_cfg = malloc(sizeof(UsbUartConfig));
|
|
|
|
|
usb_uart_get_config(app->usb_uart_bridge, app->usb_uart_cfg);
|
|
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
variable_item_set_current_value_index(item, app->usb_uart_cfg->vcp_ch);
|
|
|
|
|
variable_item_set_current_value_text(item, vcp_ch[app->usb_uart_cfg->vcp_ch]);
|
|
|
|
|
|
|
|
|
|
item = variable_item_list_add(
|
|
|
|
|
var_item_list,
|
|
|
|
@@ -123,22 +132,23 @@ void gpio_scene_usb_uart_cfg_on_enter(void* context) {
|
|
|
|
|
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_index(item, app->usb_uart_cfg->baudrate_mode);
|
|
|
|
|
if(app->usb_uart_cfg->baudrate_mode > 0) {
|
|
|
|
|
snprintf(br_text, 7, "%lu", baudrate_list[app->usb_uart_cfg->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]);
|
|
|
|
|
variable_item_set_current_value_text(
|
|
|
|
|
item, baudrate_mode[app->usb_uart_cfg->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]);
|
|
|
|
|
variable_item_set_current_value_index(item, app->usb_uart_cfg->uart_ch);
|
|
|
|
|
variable_item_set_current_value_text(item, uart_ch[app->usb_uart_cfg->uart_ch]);
|
|
|
|
|
|
|
|
|
|
item = variable_item_list_add(
|
|
|
|
|
var_item_list, "RTS/DTR Pins", COUNT_OF(flow_pins), 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_set_current_value_index(item, app->usb_uart_cfg->flow_pins);
|
|
|
|
|
variable_item_set_current_value_text(item, flow_pins[app->usb_uart_cfg->flow_pins]);
|
|
|
|
|
app->var_item_flow = item;
|
|
|
|
|
line_ensure_flow_invariant(app);
|
|
|
|
|
|
|
|
|
@@ -155,5 +165,5 @@ void gpio_scene_usb_uart_cfg_on_exit(void* context) {
|
|
|
|
|
GpioAppViewUsbUartCfg,
|
|
|
|
|
variable_item_list_get_selected_item_index(app->var_item_list));
|
|
|
|
|
variable_item_list_reset(app->var_item_list);
|
|
|
|
|
free(cfg_set);
|
|
|
|
|
free(app->usb_uart_cfg);
|
|
|
|
|
}
|
|
|
|
|