Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
RebornedBrain committed Dec 26, 2023
2 parents 5625160 + c9e3f20 commit 0d0efd9
Show file tree
Hide file tree
Showing 23 changed files with 283 additions and 133 deletions.
17 changes: 17 additions & 0 deletions applications/main/gpio/scenes/gpio_scene_usb_uart_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ static const uint32_t baudrate_list[] = {
460800,
921600,
};
static const char* software_de_re[] = {"None", "4"};

bool gpio_scene_usb_uart_cfg_on_event(void* context, SceneManagerEvent event) {
GpioApp* app = context;
Expand Down Expand Up @@ -84,6 +85,17 @@ static void line_port_cb(VariableItem* item) {
view_dispatcher_send_custom_event(app->view_dispatcher, GpioUsbUartEventConfigSet);
}

static void line_software_de_re_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, software_de_re[index]);

app->usb_uart_cfg->software_de_re = index;
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);
Expand Down Expand Up @@ -155,6 +167,11 @@ void gpio_scene_usb_uart_cfg_on_enter(void* context) {
app->var_item_flow = item;
line_ensure_flow_invariant(app);

item = variable_item_list_add(
var_item_list, "DE/RE Pin", COUNT_OF(software_de_re), line_software_de_re_cb, app);
variable_item_set_current_value_index(item, app->usb_uart_cfg->software_de_re);
variable_item_set_current_value_text(item, software_de_re[app->usb_uart_cfg->software_de_re]);

variable_item_list_set_selected_item(
var_item_list, scene_manager_get_scene_state(app->scene_manager, GpioAppViewUsbUartCfg));

Expand Down
35 changes: 35 additions & 0 deletions applications/main/gpio/usb_uart_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
#include <furi_hal.h>
#include <furi_hal_usb_cdc.h>

//TODO: FL-3276 port to new USART API
#include <stm32wbxx_ll_lpuart.h>
#include <stm32wbxx_ll_usart.h>

#define USB_CDC_PKT_LEN CDC_DATA_SZ
#define USB_UART_RX_BUF_SIZE (USB_CDC_PKT_LEN * 5)

#define USB_CDC_BIT_DTR (1 << 0)
#define USB_CDC_BIT_RTS (1 << 1)
#define USB_USART_DE_RE_PIN &gpio_ext_pa4

static const GpioPin* flow_pins[][2] = {
{&gpio_ext_pa7, &gpio_ext_pa6}, // 2, 3
Expand Down Expand Up @@ -247,6 +252,17 @@ static int32_t usb_uart_worker(void* context) {
usb_uart->cfg.flow_pins = usb_uart->cfg_new.flow_pins;
events |= WorkerEvtCtrlLineSet;
}
if(usb_uart->cfg.software_de_re != usb_uart->cfg_new.software_de_re) {
usb_uart->cfg.software_de_re = usb_uart->cfg_new.software_de_re;
if(usb_uart->cfg.software_de_re != 0) {
furi_hal_gpio_write(USB_USART_DE_RE_PIN, true);
furi_hal_gpio_init(
USB_USART_DE_RE_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedMedium);
} else {
furi_hal_gpio_init(
USB_USART_DE_RE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
}
api_lock_unlock(usb_uart->cfg_lock);
}
if(events & WorkerEvtLineCfgSet) {
Expand All @@ -260,6 +276,8 @@ static int32_t usb_uart_worker(void* context) {
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
usb_uart_serial_deinit(usb_uart, usb_uart->cfg.uart_ch);

furi_hal_gpio_init(USB_USART_DE_RE_PIN, GpioModeAnalog, GpioPullNo, GpioSpeedLow);

if(usb_uart->cfg.flow_pins != 0) {
furi_hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeAnalog);
furi_hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
Expand Down Expand Up @@ -298,7 +316,24 @@ static int32_t usb_uart_tx_thread(void* context) {

if(len > 0) {
usb_uart->st.tx_cnt += len;

if(usb_uart->cfg.software_de_re != 0)
furi_hal_gpio_write(USB_USART_DE_RE_PIN, false);

furi_hal_uart_tx(usb_uart->cfg.uart_ch, data, len);

if(usb_uart->cfg.software_de_re != 0) {
//TODO: FL-3276 port to new USART API
if(usb_uart->cfg.uart_ch == FuriHalUartIdUSART1) {
while(!LL_USART_IsActiveFlag_TC(USART1))
;
} else if(usb_uart->cfg.uart_ch == FuriHalUartIdLPUART1) {
while(!LL_LPUART_IsActiveFlag_TC(LPUART1))
;
}

furi_hal_gpio_write(USB_USART_DE_RE_PIN, true);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions applications/main/gpio/usb_uart_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ typedef struct {
uint8_t flow_pins;
uint8_t baudrate_mode;
uint32_t baudrate;
uint8_t software_de_re;
} UsbUartConfig;

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/nfc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ bool nfc_load_file(NfcApp* instance, FuriString* path, bool show_dialog) {
nfc_supported_cards_load_cache(instance->nfc_supported_cards);

FuriString* load_path = furi_string_alloc();
if(nfc_has_shadow_file_internal(instance, path)) {
if(nfc_has_shadow_file_internal(instance, path)) { //-V1051
nfc_set_shadow_file_path(path, load_path);
} else if(furi_string_end_with(path, NFC_APP_SHADOW_EXTENSION)) {
size_t path_len = furi_string_size(path);
Expand Down
126 changes: 75 additions & 51 deletions applications/services/rpc/rpc_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,41 @@
#include <flipper.pb.h>
#include <gui.pb.h>

// Contract assertion
_Static_assert(InputKeyMAX == 6, "InputKeyMAX");
_Static_assert(InputTypeMAX == 5, "InputTypeMAX");

_Static_assert(InputKeyUp == (int32_t)PB_Gui_InputKey_UP, "InputKeyUp != PB_Gui_InputKey_UP");
_Static_assert(
InputKeyDown == (int32_t)PB_Gui_InputKey_DOWN,
"InputKeyDown != PB_Gui_InputKey_DOWN");
_Static_assert(
InputKeyRight == (int32_t)PB_Gui_InputKey_RIGHT,
"InputKeyRight != PB_Gui_InputKey_RIGHT");
_Static_assert(
InputKeyLeft == (int32_t)PB_Gui_InputKey_LEFT,
"InputKeyLeft != PB_Gui_InputKey_LEFT");
_Static_assert(InputKeyOk == (int32_t)PB_Gui_InputKey_OK, "InputKeyOk != PB_Gui_InputKey_OK");
_Static_assert(
InputKeyBack == (int32_t)PB_Gui_InputKey_BACK,
"InputKeyBack != PB_Gui_InputKey_BACK");

_Static_assert(
InputTypePress == (int32_t)PB_Gui_InputType_PRESS,
"InputTypePress != PB_Gui_InputType_PRESS");
_Static_assert(
InputTypeRelease == (int32_t)PB_Gui_InputType_RELEASE,
"InputTypeRelease != PB_Gui_InputType_RELEASE");
_Static_assert(
InputTypeShort == (int32_t)PB_Gui_InputType_SHORT,
"InputTypeShort != PB_Gui_InputType_SHORT");
_Static_assert(
InputTypeLong == (int32_t)PB_Gui_InputType_LONG,
"InputTypeLong != PB_Gui_InputType_LONG");
_Static_assert(
InputTypeRepeat == (int32_t)PB_Gui_InputType_REPEAT,
"InputTypeRepeat != PB_Gui_InputType_REPEAT");

#define TAG "RpcGui"

typedef enum {
Expand Down Expand Up @@ -168,63 +203,20 @@ static void
RpcSession* session = rpc_gui->session;
furi_assert(session);

InputEvent event;

bool invalid = false;

switch(request->content.gui_send_input_event_request.key) {
case PB_Gui_InputKey_UP:
event.key = InputKeyUp;
break;
case PB_Gui_InputKey_DOWN:
event.key = InputKeyDown;
break;
case PB_Gui_InputKey_RIGHT:
event.key = InputKeyRight;
break;
case PB_Gui_InputKey_LEFT:
event.key = InputKeyLeft;
break;
case PB_Gui_InputKey_OK:
event.key = InputKeyOk;
break;
case PB_Gui_InputKey_BACK:
event.key = InputKeyBack;
break;
default:
// Invalid key
invalid = true;
break;
}
bool is_valid = (request->content.gui_send_input_event_request.key < (int32_t)InputKeyMAX) &&
(request->content.gui_send_input_event_request.type < (int32_t)InputTypeMAX);

switch(request->content.gui_send_input_event_request.type) {
case PB_Gui_InputType_PRESS:
event.type = InputTypePress;
break;
case PB_Gui_InputType_RELEASE:
event.type = InputTypeRelease;
break;
case PB_Gui_InputType_SHORT:
event.type = InputTypeShort;
break;
case PB_Gui_InputType_LONG:
event.type = InputTypeLong;
break;
case PB_Gui_InputType_REPEAT:
event.type = InputTypeRepeat;
break;
default:
// Invalid type
invalid = true;
break;
}

if(invalid) {
if(!is_valid) {
rpc_send_and_release_empty(
session, request->command_id, PB_CommandStatus_ERROR_INVALID_PARAMETERS);
return;
}

InputEvent event = {
.key = (int32_t)request->content.gui_send_input_event_request.key,
.type = (int32_t)request->content.gui_send_input_event_request.type,
};

// Event sequence shenanigans
event.sequence_source = INPUT_SEQUENCE_SOURCE_SOFTWARE;
if(event.type == InputTypePress) {
Expand Down Expand Up @@ -264,6 +256,29 @@ static void rpc_system_gui_virtual_display_render_callback(Canvas* canvas, void*
canvas_draw_xbm(canvas, 0, 0, canvas->width, canvas->height, rpc_gui->virtual_display_buffer);
}

static void rpc_system_gui_virtual_display_input_callback(InputEvent* event, void* context) {
furi_assert(event);
furi_assert(event->key < InputKeyMAX);
furi_assert(event->type < InputTypeMAX);
furi_assert(context);

RpcGuiSystem* rpc_gui = context;
RpcSession* session = rpc_gui->session;

FURI_LOG_D(TAG, "VirtulDisplay: SendInputEvent");

PB_Main rpc_message = {
.command_id = 0,
.command_status = PB_CommandStatus_OK,
.has_next = false,
.which_content = PB_Main_gui_send_input_event_request_tag,
.content.gui_send_input_event_request.key = (int32_t)event->key,
.content.gui_send_input_event_request.type = (int32_t)event->type,
};

rpc_send_and_release(session, &rpc_message);
}

static void rpc_system_gui_start_virtual_display_process(const PB_Main* request, void* context) {
furi_assert(request);
furi_assert(context);
Expand Down Expand Up @@ -300,6 +315,15 @@ static void rpc_system_gui_start_virtual_display_process(const PB_Main* request,
rpc_gui->virtual_display_view_port,
rpc_system_gui_virtual_display_render_callback,
rpc_gui);

if(request->content.gui_start_virtual_display_request.send_input) {
FURI_LOG_D(TAG, "VirtulDisplay: input forwarding requested");
view_port_input_callback_set(
rpc_gui->virtual_display_view_port,
rpc_system_gui_virtual_display_input_callback,
rpc_gui);
}

gui_add_view_port(rpc_gui->gui, rpc_gui->virtual_display_view_port, GuiLayerFullscreen);

rpc_send_and_release_empty(session, request->command_id, PB_CommandStatus_OK);
Expand Down
Loading

0 comments on commit 0d0efd9

Please sign in to comment.