MX 2 лет назад
Родитель
Сommit
32f5911b54
3 измененных файлов с 18 добавлено и 12 удалено
  1. 2 0
      wifi_deauther_app_i.h
  2. 15 11
      wifi_deauther_uart.c
  3. 1 1
      wifi_deauther_uart.h

+ 2 - 0
wifi_deauther_app_i.h

@@ -12,6 +12,8 @@
 #include <gui/modules/text_input.h>
 #include <gui/modules/variable_item_list.h>
 
+#define UART_CH (FuriHalSerialIdUsart)
+
 #define NUM_MENU_ITEMS (11)
 
 #define WIFI_deauther_TEXT_BOX_STORE_SIZE (4096)

+ 15 - 11
wifi_deauther_uart.c

@@ -4,16 +4,15 @@
 #include <FreeRTOS.h>
 #include <stream_buffer.h>
 
-#define UART_CH (FuriHalUartIdUSART1)
 #define BAUDRATE (115200)
 
 struct WifideautherUart {
     WifideautherApp* app;
-    FuriHalUartId channel;
     FuriThread* rx_thread;
     FuriStreamBuffer* rx_stream;
     uint8_t rx_buf[RX_BUF_SIZE + 1];
     void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context);
+    FuriHalSerialHandle* serial_handle;
 };
 
 typedef enum {
@@ -30,10 +29,14 @@ void wifi_deauther_uart_set_handle_rx_data_cb(
 
 #define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
 
-void wifi_deauther_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
+void wifi_deauther_uart_on_irq_cb(
+    FuriHalSerialHandle* handle,
+    FuriHalSerialRxEvent event,
+    void* context) {
     WifideautherUart* uart = (WifideautherUart*)context;
 
-    if(ev == UartIrqEventRXNE) {
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
         furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
         furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
     }
@@ -60,8 +63,8 @@ static int32_t uart_worker(void* context) {
     return 0;
 }
 
-void wifi_deauther_uart_tx(uint8_t* data, size_t len) {
-    furi_hal_uart_tx(UART_CH, data, len);
+void wifi_deauther_uart_tx(WifideautherUart* uart, uint8_t* data, size_t len) {
+    furi_hal_serial_tx(uart->serial_handle, data, len);
 }
 
 WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app) {
@@ -77,9 +80,10 @@ WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app) {
 
     furi_thread_start(uart->rx_thread);
 
-    furi_hal_console_disable();
-    furi_hal_uart_set_br(UART_CH, BAUDRATE);
-    furi_hal_uart_set_irq_cb(UART_CH, wifi_deauther_uart_on_irq_cb, uart);
+    uart->serial_handle = furi_hal_serial_control_acquire(UART_CH);
+    furi_check(uart->serial_handle);
+    furi_hal_serial_init(uart->serial_handle, BAUDRATE);
+    furi_hal_serial_async_rx_start(uart->serial_handle, wifi_deauther_uart_on_irq_cb, uart, false);
 
     return uart;
 }
@@ -91,8 +95,8 @@ void wifi_deauther_uart_free(WifideautherUart* uart) {
     furi_thread_join(uart->rx_thread);
     furi_thread_free(uart->rx_thread);
 
-    furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
-    furi_hal_console_enable();
+    furi_hal_serial_deinit(uart->serial_handle);
+    furi_hal_serial_control_release(uart->serial_handle);
 
     free(uart);
 }

+ 1 - 1
wifi_deauther_uart.h

@@ -9,6 +9,6 @@ typedef struct WifideautherUart WifideautherUart;
 void wifi_deauther_uart_set_handle_rx_data_cb(
     WifideautherUart* uart,
     void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context));
-void wifi_deauther_uart_tx(uint8_t* data, size_t len);
+void wifi_deauther_uart_tx(WifideautherUart* uart, uint8_t* data, size_t len);
 WifideautherUart* wifi_deauther_uart_init(WifideautherApp* app);
 void wifi_deauther_uart_free(WifideautherUart* uart);