From e3c3edcc7e3c8ffea3475aee62acd590fa9a92c4 Mon Sep 17 00:00:00 2001 From: Georgii Surkov Date: Sun, 17 Nov 2024 21:01:15 +0000 Subject: [PATCH 1/3] Add send break support --- applications/main/gpio/usb_uart_bridge.c | 13 ++++++++++++- applications/services/cli/cli_vcp.c | 1 + targets/f18/api_symbols.csv | 3 ++- targets/f7/api_symbols.csv | 3 ++- targets/f7/furi_hal/furi_hal_serial.c | 10 ++++++++++ targets/f7/furi_hal/furi_hal_serial.h | 6 ++++++ targets/f7/furi_hal/furi_hal_usb_cdc.c | 13 ++++++++++--- targets/f7/furi_hal/furi_hal_usb_cdc.h | 1 + 8 files changed, 44 insertions(+), 6 deletions(-) diff --git a/applications/main/gpio/usb_uart_bridge.c b/applications/main/gpio/usb_uart_bridge.c index f6e68b109..f3a9775a6 100644 --- a/applications/main/gpio/usb_uart_bridge.c +++ b/applications/main/gpio/usb_uart_bridge.c @@ -35,7 +35,7 @@ typedef enum { WorkerEvtLineCfgSet = (1 << 6), WorkerEvtCtrlLineSet = (1 << 7), - + WorkerEvtSendBreak = (1 << 8), } WorkerEvtFlags; #define WORKER_ALL_RX_EVENTS \ @@ -69,6 +69,7 @@ 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, @@ -76,6 +77,7 @@ static const CdcCallbacks cdc_cb = { vcp_state_callback, vcp_on_cdc_control_line, vcp_on_line_config, + vcp_on_cdc_break, }; /* USB UART worker */ @@ -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); @@ -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)); diff --git a/applications/services/cli/cli_vcp.c b/applications/services/cli/cli_vcp.c index cdabaaa05..83f4f8214 100644 --- a/applications/services/cli/cli_vcp.c +++ b/applications/services/cli/cli_vcp.c @@ -57,6 +57,7 @@ static CdcCallbacks cdc_cb = { vcp_state_callback, vcp_on_cdc_control_line, NULL, + NULL, }; static CliVcp* vcp = NULL; diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index b5d51a0dd..79610d0bb 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -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,, @@ -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" diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index ee81f76a9..7da0c727f 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -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/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, @@ -1635,6 +1635,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" diff --git a/targets/f7/furi_hal/furi_hal_serial.c b/targets/f7/furi_hal/furi_hal_serial.c index 5ddb0785f..3f6b575a6 100644 --- a/targets/f7/furi_hal/furi_hal_serial.c +++ b/targets/f7/furi_hal/furi_hal_serial.c @@ -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); + } +} diff --git a/targets/f7/furi_hal/furi_hal_serial.h b/targets/f7/furi_hal/furi_hal_serial.h index 00010d83c..6dad8ec31 100644 --- a/targets/f7/furi_hal/furi_hal_serial.h +++ b/targets/f7/furi_hal/furi_hal_serial.h @@ -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 diff --git a/targets/f7/furi_hal/furi_hal_usb_cdc.c b/targets/f7/furi_hal/furi_hal_usb_cdc.c index cfedb5e76..3408789dd 100644 --- a/targets/f7/furi_hal/furi_hal_usb_cdc.c +++ b/targets/f7/furi_hal/furi_hal_usb_cdc.c @@ -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 = { @@ -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 = { @@ -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 = { @@ -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; } diff --git a/targets/f7/furi_hal/furi_hal_usb_cdc.h b/targets/f7/furi_hal/furi_hal_usb_cdc.h index 89b68991b..995e9009a 100644 --- a/targets/f7/furi_hal/furi_hal_usb_cdc.h +++ b/targets/f7/furi_hal/furi_hal_usb_cdc.h @@ -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); From 07426b6df22ebd0e845d24c94f5d942266dcc158 Mon Sep 17 00:00:00 2001 From: Georgii Surkov Date: Mon, 18 Nov 2024 11:29:54 +0000 Subject: [PATCH 2/3] Add SendBreak event to waiting mask --- applications/main/gpio/usb_uart_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/main/gpio/usb_uart_bridge.c b/applications/main/gpio/usb_uart_bridge.c index f3a9775a6..0d2c63b3c 100644 --- a/applications/main/gpio/usb_uart_bridge.c +++ b/applications/main/gpio/usb_uart_bridge.c @@ -40,7 +40,7 @@ typedef enum { #define WORKER_ALL_RX_EVENTS \ (WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \ - WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete) + WorkerEvtCtrlLineSet | WorkerEvtCdcTxComplete | WorkerEvtSendBreak) #define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtCdcRx) struct UsbUartBridge { From 7e0f292615298b597ef7f7a97ca6ab22e759920e Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Tue, 26 Nov 2024 05:46:32 +0300 Subject: [PATCH 3/3] upd changelog --- CHANGELOG.md | 116 ++------------------------------------------------- 1 file changed, 3 insertions(+), 113 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d263bb8ba..b5058c114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,119 +1,9 @@ ## Main changes -- Current API: 78.1 -- SubGHz: - - Frequency analyzer fixes and improvements: - - **Enforce int module** (like in OFW) usage due to lack of required hardware on external boards (PathIsolate (+rf switch for multiple paths)) and incorrect usage and/or understanding the purpose of frequency analyzer app by users, it should be used only to get frequency of the remote placed around 1-10cm around flipper's left corner - - **Fix possible GSM mobile towers signal interference** by limiting upper frequency to 920mhz max - - Fix buttons logic, **fix crash** - - Protocol improvements: - - **Keeloq: Monarch full support, with add manually option** (thanks @ashphx !) - - **Princeton support for second button encoding type** (8bit) - - GangQi fix serial check and remove broken check from UI - - Hollarm add more button codes (thanks to @mishamyte for captures) - - Misc: - - Add extra settings to disable GPIO pins control used for external modules amplifiers and/or LEDs (in radio settings menu with debug ON) -- NFC: - - Read Ultralight block by block (**fix password protected MFUL reading issue**) (by @mishamyte | PR #825 #826) - - **Update NDEF parser** (SLIX and MFC support) (by @luu176 and @jaylikesbunda and @Willy-JL) - - OFW PR 3822: **MIFARE Classic Key Recovery Improvements** (by @noproto) - - OFW PR 3930: NFC Emulation freeze fix (by @RebornedBrain) - - OFW: H World Hotel Chain Room Key Parser - - OFW: Parser for Tianjin Railway Transit - - New keys in system dict -- Infrared: - - **Add LEDs universal remote** (DB by @amec0e) - - Update universal remote assets (by @amec0e | PR #813 #816) -- JS: - - OFW: JS modules & SDK -> **Breaking API change** - - **Backporting custom features** (read about most of the changes after other changes section) (by @xMasterX and @Willy-JL) - - Add i2c & SPI module (by @jamisonderek) -* OFW: FuriHal, drivers: rework gauge initialization routine -> **Downgrade to older releases may break battery UI percent indicator, upgrade to this or newer version to restore** -* OFW: heap: increased size -> **More free RAM!!** -* OFW: New layout for BadUSB (es-LA) -* OFW: Require PIN on boot +- Current API: 78.2 +* OFW: merged gsurkov/vcp_break_support branch for usb uart bridge (WIP!!!) * Apps: **Check out more Apps updates and fixes by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev) ## Other changes -* SubGHz: Freq analyzer - Fix duplicated frequency lists and use user config for nearest frequency selector too -* SubGHz: Code cleanup and fix for rare dupicated (Data) field cases -* OFW: NFC TRT Parser: Additional checks to prevent false positives -* OFW PR 3992: Loader: Fix BusFault in handling of OOM (by @Willy-JL) -* OFW PR 3885: NFC: Add API to enforce ISO15693 mode (by @aaronjamt) -* OFW: NFC: iso14443_4a improvements (by @RebornedBrain) -* OFW: NFC: Plantain parser improvements (by @assasinfil) & fixes (by @mxcdoam) -* OFW: NFC: Moscow social card parser (by @assasinfil) -* OFW: fix: npm deps -* OFW: 目覚め時計 (Added alarm option and clock settings) -* OFW: JS: Backport and more additions & fixes -* OFW: nfc: add Caltrain zones for Clipper -* OFW: Update unit tests docs -* OFW: Fix JS memory corruption (in gpio module) -* OFW: Full-fledged JS SDK + npm packages -* OFW: FurEventLoop: add support for FuriEventFlag, simplify API -* OFW: lib: digital_signal: digital_sequence: add furi_hal.h wrapped in ifdefs -* OFW: Add warning about stealth mode in vibro CLI -* OFW: Small fixes in the wifi devboard docs -* OFW: BadUSB - Improve ChromeOS and GNOME demo scripts -* OFW: Small JS fixes -* OFW: Canvas: extended icon draw. -* OFW: Fixes Mouse Clicker Should have a "0" value setting for "as fast as possible" -* OFW: Wi-Fi Devboard documentation rework -* OFW: Furi: A Lot of Fixes -* OFW PR 3933: furi_hal_random: Wait for ready state and no errors before sampling (by @n1kolasM) -* OFW: nfc/clipper: Update BART station codes -* OFW: FuriThread: Improve state callbacks -* OFW: Documentation: update and cleanup -* OFW: Improve bit_buffer.h docs -* OFW: Prevent idle priority threads from potentially starving the FreeRTOS idle task -* OFW: IR universal remote additions -* OFW: Fix EM4100 T5577 writing block order (was already done in UL) -* OFW: kerel typo -* OFW: Folder rename fails -* OFW: Put errno into TCB -* OFW: Fix USB-UART bridge exit screen stopping the bridge prematurely -**More details on JS changes** (js changelog written by @Willy-JL , thanks!): -- Our custom JS SDK can be found on npm now: https://www.npmjs.com/org/darkflippers -- Non-exhaustive list of changes to help you fix your scripts: - - `badusb`: - - `setup()`: `mfr_name`, `prod_name`, `layout_path` parameters renamed to `mfrName`, `prodName`, `layoutPath` - - effort required to update old scripts using badusb: very minimal - - `dialog`: - - removed, now replaced by `gui/dialog` and `gui/file_picker` (see below) - - `event_loop`: - - new module, allows timer functionality, callbacks and event-driven programming, used heavily alongside gpio and gui modules - - `gpio`: - - fully overhauled, now you `get()` pin instances and perform actions on them like `.init()` - - now supports interrupts, callbacks and more cool things - - effort required to update old scripts using gpio: moderate - - `gui`: - - new module, fully overhauled, replaces dialog, keyboard, submenu, textbox modules - - higher barrier to entry than older modules (requires usage of `event_loop` and `gui.viewDispatcher`), but much more flexible, powerful and easier to extend - - includes all previously available js gui functionality (except `widget`), and also adds `gui/loading` and `gui/empty_screen` views - - currently `gui/file_picker` works different than other new view objects, it is a simple `.pickFile()` synchronous function, but this [may change later](https://github.com/flipperdevices/flipperzero-firmware/pull/3961#discussion_r1805579153) - - effort required to update old scripts using gui: extensive - - `keyboard`: - - removed, now replaced by `gui/text_input` and `gui/byte_input` (see above) - - `math`: - - `is_equal()` renamed to `isEqual()` - - `storage`: - - fully overhauled, now you `openFile()`s and perform actions on them like `.read()` - - now supports many more operations including different open modes, directories and much more - - effort required to update old scripts using storage: moderate - - `submenu`: - - removed, now replaced by `gui/submenu` (see above) - - `textbox`: - - removed, now replace by `gui/text_box` (see above) - - `widget`: - - only gui functionality not ported to new gui module, remains unchanged for now but likely to be ported later on - - globals: - - `__filepath` and `__dirpath` renamed to `__filename` and `__dirname` like in nodejs - - `to_string()` renamed and moved to number class as `n.toString()`, now supports optional base parameter - - `to_hex_string()` removed, now use `n.toString(16)` - - `parse_int()` renamed to `parseInt()`, now supports optional base parameter - - `to_upper_case()` and `to_lower_case()` renamed and moved to string class as `s.toUpperCase()` and `s.toLowerCase()` - - effort required to update old scripts using these: minimal - - Added type definitions (typescript files for type checking in IDE, Flipper does not run typescript) - - Documentation is incomplete and deprecated, from now on you should refer to type definitions (`applications/system/js_app/types`), those will always be correct - - Type definitions for extra modules we have that OFW doesn't will come later +* No changes yet :(

#### Known NFC post-refactor regressions list: - Mifare Mini clones reading is broken (original mini working fine) (OFW)