Skip to content

Commit

Permalink
Merge remote-tracking branch 'ul/dev' into mntm-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Nov 27, 2024
2 parents a7e9e39 + 7e0f292 commit 1373f91
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- UL: NFC Magic: Added possibility to write 7b MFC to Gen1 tags (by @mishamyte)

### Fixed:
- Nothing
- OFW: GPIO: Merged gsurkov/vcp_break_support branch for usb uart bridge (WIP!!!)

### Removed:
- Nothing
15 changes: 13 additions & 2 deletions applications/main/gpio/usb_uart_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ typedef enum {

WorkerEvtLineCfgSet = (1 << 6),
WorkerEvtCtrlLineSet = (1 << 7),

WorkerEvtSendBreak = (1 << 8),
} WorkerEvtFlags;

#define WORKER_ALL_RX_EVENTS \
(WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \
WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete)
WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete | WorkerEvtSendBreak)
#define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtCdcRx)

struct UsbUartBridge {
Expand Down Expand Up @@ -69,13 +69,15 @@ static void vcp_on_cdc_rx(void* context);
static void vcp_state_callback(void* context, uint8_t state);
static void vcp_on_cdc_control_line(void* context, uint8_t state);
static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config);
static void vcp_on_cdc_break(void* context, uint16_t duration);

static const CdcCallbacks cdc_cb = {
vcp_on_cdc_tx_complete,
vcp_on_cdc_rx,
vcp_state_callback,
vcp_on_cdc_control_line,
vcp_on_line_config,
vcp_on_cdc_break,
};

/* USB UART worker */
Expand Down Expand Up @@ -287,6 +289,9 @@ static int32_t usb_uart_worker(void* context) {
if(events & WorkerEvtCtrlLineSet) {
usb_uart_update_ctrl_lines(usb_uart);
}
if(events & WorkerEvtSendBreak) {
furi_hal_serial_send_break(usb_uart->serial_handle);
}
}
usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
usb_uart_serial_deinit(usb_uart);
Expand Down Expand Up @@ -377,6 +382,12 @@ static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtLineCfgSet);
}

static void vcp_on_cdc_break(void* context, uint16_t duration) {
UNUSED(duration);
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtSendBreak);
}

UsbUartBridge* usb_uart_enable(UsbUartConfig* cfg) {
UsbUartBridge* usb_uart = malloc(sizeof(UsbUartBridge));

Expand Down
1 change: 1 addition & 0 deletions applications/services/cli/cli_vcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static CdcCallbacks cdc_cb = {
vcp_state_callback,
vcp_on_cdc_control_line,
NULL,
NULL,
};

static CliVcp* vcp = NULL;
Expand Down
3 changes: 2 additions & 1 deletion targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,78.1,,
Version,+,78.2,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -1446,6 +1446,7 @@ Function,+,furi_hal_serial_get_gpio_pin,const GpioPin*,"FuriHalSerialHandle*, Fu
Function,+,furi_hal_serial_init,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_is_baud_rate_supported,_Bool,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_resume,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_send_break,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_set_br,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_suspend,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_tx,void,"FuriHalSerialHandle*, const uint8_t*, size_t"
Expand Down
3 changes: 2 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,78.1,,
Version,+,78.2,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/main/archive/helpers/archive_helpers_ext.h,,
Header,+,applications/main/subghz/subghz_fap.h,,
Expand Down Expand Up @@ -1691,6 +1691,7 @@ Function,+,furi_hal_serial_get_gpio_pin,const GpioPin*,"FuriHalSerialHandle*, Fu
Function,+,furi_hal_serial_init,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_is_baud_rate_supported,_Bool,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_resume,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_send_break,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_set_br,void,"FuriHalSerialHandle*, uint32_t"
Function,+,furi_hal_serial_suspend,void,FuriHalSerialHandle*
Function,+,furi_hal_serial_tx,void,"FuriHalSerialHandle*, const uint8_t*, size_t"
Expand Down
10 changes: 10 additions & 0 deletions targets/f7/furi_hal/furi_hal_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,3 +950,13 @@ const GpioPin*

return furi_hal_serial_config[handle->id].gpio[direction];
}

void furi_hal_serial_send_break(FuriHalSerialHandle* handle) {
furi_check(handle);

if(handle->id == FuriHalSerialIdUsart) {
LL_USART_RequestBreakSending(USART1);
} else {
LL_LPUART_RequestBreakSending(LPUART1);
}
}
6 changes: 6 additions & 0 deletions targets/f7/furi_hal/furi_hal_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ void furi_hal_serial_dma_rx_stop(FuriHalSerialHandle* handle);
*/
size_t furi_hal_serial_dma_rx(FuriHalSerialHandle* handle, uint8_t* data, size_t len);

/** Send a break sequence (low level for the whole character duration)
*
* @param handle Serial handle
*/
void furi_hal_serial_send_break(FuriHalSerialHandle* handle);

#ifdef __cplusplus
}
#endif
13 changes: 10 additions & 3 deletions targets/f7/furi_hal/furi_hal_usb_cdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static const struct CdcConfigDescriptorSingle cdc_cfg_desc_single = {
.bFunctionLength = sizeof(struct usb_cdc_acm_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_ACM,
.bmCapabilities = 0,
.bmCapabilities = USB_CDC_CAP_BRK,
},
.cdc_union =
{
Expand Down Expand Up @@ -235,7 +235,7 @@ static const struct CdcConfigDescriptorDual
.bFunctionLength = sizeof(struct usb_cdc_acm_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_ACM,
.bmCapabilities = 0,
.bmCapabilities = USB_CDC_CAP_BRK,
},
.cdc_union =
{
Expand Down Expand Up @@ -330,7 +330,7 @@ static const struct CdcConfigDescriptorDual
.bFunctionLength = sizeof(struct usb_cdc_acm_desc),
.bDescriptorType = USB_DTYPE_CS_INTERFACE,
.bDescriptorSubType = USB_DTYPE_CDC_ACM,
.bmCapabilities = 0,
.bmCapabilities = USB_CDC_CAP_BRK,
},
.cdc_union =
{
Expand Down Expand Up @@ -680,6 +680,13 @@ static usbd_respond cdc_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_cal
dev->status.data_ptr = &cdc_config[if_num];
dev->status.data_count = sizeof(cdc_config[0]);
return usbd_ack;
case USB_CDC_SEND_BREAK:
if(callbacks[if_num] != NULL) {
if(callbacks[if_num]->break_callback != NULL) {
callbacks[if_num]->break_callback(cb_ctx[if_num], req->wValue);
}
}
return usbd_ack;
default:
return usbd_fail;
}
Expand Down
1 change: 1 addition & 0 deletions targets/f7/furi_hal/furi_hal_usb_cdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
void (*state_callback)(void* context, uint8_t state);
void (*ctrl_line_callback)(void* context, uint8_t state);
void (*config_callback)(void* context, struct usb_cdc_line_coding* config);
void (*break_callback)(void* context, uint16_t duration);
} CdcCallbacks;

void furi_hal_cdc_set_callbacks(uint8_t if_num, CdcCallbacks* cb, void* context);
Expand Down

0 comments on commit 1373f91

Please sign in to comment.