2
2
3
3
#define TAG "SeaderUART"
4
4
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 ) {
6
10
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
+ };
10
21
furi_thread_flags_set (furi_thread_get_id (seader_uart -> thread ), WorkerEvtRxDone );
11
22
}
12
23
}
@@ -20,21 +31,21 @@ void seader_uart_disable(SeaderUartBridge* seader_uart) {
20
31
}
21
32
22
33
void 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
+
29
39
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);
32
42
}
33
43
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 );
36
46
furi_hal_serial_deinit (seader_uart -> serial_handle );
37
47
furi_hal_serial_control_release (seader_uart -> serial_handle );
48
+ seader_uart -> serial_handle = NULL ;
38
49
}
39
50
40
51
void seader_uart_set_baudrate (SeaderUartBridge * seader_uart , uint32_t baudrate ) {
@@ -108,7 +119,7 @@ int32_t seader_uart_worker(void* context) {
108
119
cmd_len = 0 ;
109
120
break ;
110
121
}
111
- if (events & WorkerEvtRxDone ) {
122
+ if (events & ( WorkerEvtRxDone | WorkerEvtSamTxComplete ) ) {
112
123
size_t len = furi_stream_buffer_receive (
113
124
seader_uart -> rx_stream , seader_uart -> rx_buf , SEADER_UART_RX_BUF_SIZE , 0 );
114
125
if (len > 0 ) {
@@ -134,7 +145,7 @@ int32_t seader_uart_worker(void* context) {
134
145
}
135
146
}
136
147
}
137
- seader_uart_serial_deinit (seader_uart , seader_uart -> cfg . uart_ch );
148
+ seader_uart_serial_deinit (seader_uart );
138
149
139
150
furi_thread_flags_set (furi_thread_get_id (seader_uart -> tx_thread ), WorkerEvtTxStop );
140
151
furi_thread_join (seader_uart -> tx_thread );
0 commit comments