22
33#define TAG "SeaderUART"
44
5- void seader_uart_on_irq_cb (FuriHalSerialHandle * handle , FuriHalSerialRxEvent event , void * context ) {
5+ static void seader_uart_on_irq_rx_dma_cb (
6+ FuriHalSerialHandle * handle ,
7+ FuriHalSerialRxEvent ev ,
8+ size_t size ,
9+ void * context ) {
610 SeaderUartBridge * seader_uart = (SeaderUartBridge * )context ;
7- if (event == FuriHalSerialRxEventData ) {
8- uint8_t data = furi_hal_serial_async_rx (handle );
9- furi_stream_buffer_send (seader_uart -> rx_stream , & data , 1 , 0 );
11+ if (ev & (FuriHalSerialRxEventData | FuriHalSerialRxEventIdle )) {
12+ uint8_t data [FURI_HAL_SERIAL_DMA_BUFFER_SIZE ] = {0 };
13+ while (size ) {
14+ size_t ret = furi_hal_serial_dma_rx (
15+ handle ,
16+ data ,
17+ (size > FURI_HAL_SERIAL_DMA_BUFFER_SIZE ) ? FURI_HAL_SERIAL_DMA_BUFFER_SIZE : size );
18+ furi_stream_buffer_send (seader_uart -> rx_stream , data , ret , 0 );
19+ size -= ret ;
20+ };
1021 furi_thread_flags_set (furi_thread_get_id (seader_uart -> thread ), WorkerEvtRxDone );
1122 }
1223}
@@ -20,21 +31,21 @@ void seader_uart_disable(SeaderUartBridge* seader_uart) {
2031}
2132
2233void seader_uart_serial_init (SeaderUartBridge * seader_uart , uint8_t uart_ch ) {
23- uint8_t uart_channel = FuriHalSerialIdUsart ;
24- if (uart_ch == FuriHalSerialIdLpuart ) {
25- uart_channel = FuriHalSerialIdLpuart ;
26- }
27- seader_uart -> serial_handle = furi_hal_serial_control_acquire (uart_channel );
28- furi_check (seader_uart -> serial_handle );
34+ furi_assert (!seader_uart -> serial_handle );
35+
36+ seader_uart -> serial_handle = furi_hal_serial_control_acquire (uart_ch );
37+ furi_assert (seader_uart -> serial_handle );
38+
2939 furi_hal_serial_init (seader_uart -> serial_handle , 115200 );
30- furi_hal_serial_async_rx_start (
31- seader_uart -> serial_handle , seader_uart_on_irq_cb , seader_uart , false);
40+ furi_hal_serial_dma_rx_start (
41+ seader_uart -> serial_handle , seader_uart_on_irq_rx_dma_cb , seader_uart , false);
3242}
3343
34- void seader_uart_serial_deinit (SeaderUartBridge * seader_uart , uint8_t uart_ch ) {
35- UNUSED ( uart_ch );
44+ void seader_uart_serial_deinit (SeaderUartBridge * seader_uart ) {
45+ furi_assert ( seader_uart -> serial_handle );
3646 furi_hal_serial_deinit (seader_uart -> serial_handle );
3747 furi_hal_serial_control_release (seader_uart -> serial_handle );
48+ seader_uart -> serial_handle = NULL ;
3849}
3950
4051void seader_uart_set_baudrate (SeaderUartBridge * seader_uart , uint32_t baudrate ) {
@@ -108,7 +119,7 @@ int32_t seader_uart_worker(void* context) {
108119 cmd_len = 0 ;
109120 break ;
110121 }
111- if (events & WorkerEvtRxDone ) {
122+ if (events & ( WorkerEvtRxDone | WorkerEvtSamTxComplete ) ) {
112123 size_t len = furi_stream_buffer_receive (
113124 seader_uart -> rx_stream , seader_uart -> rx_buf , SEADER_UART_RX_BUF_SIZE , 0 );
114125 if (len > 0 ) {
@@ -134,7 +145,7 @@ int32_t seader_uart_worker(void* context) {
134145 }
135146 }
136147 }
137- seader_uart_serial_deinit (seader_uart , seader_uart -> cfg . uart_ch );
148+ seader_uart_serial_deinit (seader_uart );
138149
139150 furi_thread_flags_set (furi_thread_get_id (seader_uart -> tx_thread ), WorkerEvtTxStop );
140151 furi_thread_join (seader_uart -> tx_thread );
0 commit comments