MX 2 лет назад
Родитель
Сommit
6bd16403df
2 измененных файлов с 25 добавлено и 28 удалено
  1. 2 0
      FlipperZeroWiFiModuleDefines.h
  2. 23 28
      wifi_scanner.c

+ 2 - 0
FlipperZeroWiFiModuleDefines.h

@@ -15,3 +15,5 @@
 #define FLIPPERZERO_SERIAL_BAUD 115200
 #define FLIPPERZERO_SERIAL_BAUD 115200
 
 
 #define NA 0
 #define NA 0
+
+#define UART_CH (FuriHalSerialIdUsart)

+ 23 - 28
wifi_scanner.c

@@ -1,8 +1,8 @@
 #include <furi.h>
 #include <furi.h>
-#include <furi_hal_console.h>
 #include <furi_hal_gpio.h>
 #include <furi_hal_gpio.h>
 #include <furi_hal_power.h>
 #include <furi_hal_power.h>
-#include <furi_hal_uart.h>
+#include <furi_hal_serial_control.h>
+#include <furi_hal_serial.h>
 #include <gui/canvas_i.h>
 #include <gui/canvas_i.h>
 #include <gui/gui.h>
 #include <gui/gui.h>
 #include <input/input.h>
 #include <input/input.h>
@@ -26,8 +26,6 @@
 #define WIFI_APP_LOG_E(format, ...)
 #define WIFI_APP_LOG_E(format, ...)
 #endif // WIFI_APP_DEBUG
 #endif // WIFI_APP_DEBUG
 
 
-#define DISABLE_CONSOLE !WIFI_APP_DEBUG
-
 #define ENABLE_MODULE_POWER 1
 #define ENABLE_MODULE_POWER 1
 #define ENABLE_MODULE_DETECTION 1
 #define ENABLE_MODULE_DETECTION 1
 
 
@@ -86,6 +84,7 @@ typedef struct SWiFiScannerApp {
     FuriThread* m_worker_thread;
     FuriThread* m_worker_thread;
     NotificationApp* m_notification;
     NotificationApp* m_notification;
     FuriStreamBuffer* m_rx_stream;
     FuriStreamBuffer* m_rx_stream;
+    FuriHalSerialHandle* serial_handle;
 
 
     bool m_wifiModuleInitialized;
     bool m_wifiModuleInitialized;
     bool m_wifiModuleAttached;
     bool m_wifiModuleAttached;
@@ -643,14 +642,16 @@ static void wifi_module_input_callback(InputEvent* input_event, FuriMessageQueue
     furi_message_queue_put(event_queue, &event, FuriWaitForever);
     furi_message_queue_put(event_queue, &event, FuriWaitForever);
 }
 }
 
 
-static void uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
+static void
+    uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
     furi_assert(context);
     furi_assert(context);
 
 
     SWiFiScannerApp* app = context;
     SWiFiScannerApp* app = context;
 
 
     WIFI_APP_LOG_I("uart_echo_on_irq_cb");
     WIFI_APP_LOG_I("uart_echo_on_irq_cb");
 
 
-    if(ev == UartIrqEventRXNE) {
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
         WIFI_APP_LOG_I("ev == UartIrqEventRXNE");
         WIFI_APP_LOG_I("ev == UartIrqEventRXNE");
         furi_stream_buffer_send(app->m_rx_stream, &data, 1, 0);
         furi_stream_buffer_send(app->m_rx_stream, &data, 1, 0);
         furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventRx);
         furi_thread_flags_set(furi_thread_get_id(app->m_worker_thread), WorkerEventRx);
@@ -808,11 +809,7 @@ typedef enum ESerialCommand {
     ESerialCommand_Restart
     ESerialCommand_Restart
 } ESerialCommand;
 } ESerialCommand;
 
 
-void send_serial_command(ESerialCommand command) {
-#if !DISABLE_CONSOLE
-    return;
-#endif
-
+void send_serial_command(SWiFiScannerApp* app, ESerialCommand command) {
     uint8_t data[1] = {0};
     uint8_t data[1] = {0};
 
 
     switch(command) {
     switch(command) {
@@ -835,7 +832,7 @@ void send_serial_command(ESerialCommand command) {
         return;
         return;
     };
     };
 
 
-    furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
+    furi_hal_serial_tx(app->serial_handle, data, 1);
 }
 }
 
 
 int32_t wifi_scanner_app(void* p) {
 int32_t wifi_scanner_app(void* p) {
@@ -905,15 +902,14 @@ int32_t wifi_scanner_app(void* p) {
     WIFI_APP_LOG_I("UART thread allocated");
     WIFI_APP_LOG_I("UART thread allocated");
 
 
     // Enable uart listener
     // Enable uart listener
-#if DISABLE_CONSOLE
-    furi_hal_console_disable();
-#endif
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, FLIPPERZERO_SERIAL_BAUD);
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_on_irq_cb, app);
+    app->serial_handle = furi_hal_serial_control_acquire(UART_CH);
+    furi_check(app->serial_handle);
+    furi_hal_serial_init(app->serial_handle, FLIPPERZERO_SERIAL_BAUD);
+    furi_hal_serial_async_rx_start(app->serial_handle, uart_on_irq_cb, app, false);
     WIFI_APP_LOG_I("UART Listener created");
     WIFI_APP_LOG_I("UART Listener created");
 
 
     // Because we assume that module was on before we launched the app. We need to ensure that module will be in initial state on app start
     // Because we assume that module was on before we launched the app. We need to ensure that module will be in initial state on app start
-    send_serial_command(ESerialCommand_Restart);
+    send_serial_command(app, ESerialCommand_Restart);
 
 
     SPluginEvent event;
     SPluginEvent event;
     for(bool processing = true; processing;) {
     for(bool processing = true; processing;) {
@@ -947,20 +943,20 @@ int32_t wifi_scanner_app(void* p) {
                         case InputKeyLeft:
                         case InputKeyLeft:
                             if(event.m_input.type == InputTypeShort) {
                             if(event.m_input.type == InputTypeShort) {
                                 WIFI_APP_LOG_I("Previous");
                                 WIFI_APP_LOG_I("Previous");
-                                send_serial_command(ESerialCommand_Previous);
+                                send_serial_command(app, ESerialCommand_Previous);
                             } else if(event.m_input.type == InputTypeRepeat) {
                             } else if(event.m_input.type == InputTypeRepeat) {
                                 WIFI_APP_LOG_I("Previous Repeat");
                                 WIFI_APP_LOG_I("Previous Repeat");
-                                send_serial_command(ESerialCommand_Previous);
+                                send_serial_command(app, ESerialCommand_Previous);
                             }
                             }
                             break;
                             break;
                         case InputKeyDown:
                         case InputKeyDown:
                         case InputKeyRight:
                         case InputKeyRight:
                             if(event.m_input.type == InputTypeShort) {
                             if(event.m_input.type == InputTypeShort) {
                                 WIFI_APP_LOG_I("Next");
                                 WIFI_APP_LOG_I("Next");
-                                send_serial_command(ESerialCommand_Next);
+                                send_serial_command(app, ESerialCommand_Next);
                             } else if(event.m_input.type == InputTypeRepeat) {
                             } else if(event.m_input.type == InputTypeRepeat) {
                                 WIFI_APP_LOG_I("Next Repeat");
                                 WIFI_APP_LOG_I("Next Repeat");
-                                send_serial_command(ESerialCommand_Next);
+                                send_serial_command(app, ESerialCommand_Next);
                             }
                             }
                             break;
                             break;
                         default:
                         default:
@@ -973,18 +969,18 @@ int32_t wifi_scanner_app(void* p) {
                         if(event.m_input.type == InputTypeShort) {
                         if(event.m_input.type == InputTypeShort) {
                             if(app->m_context == ScanMode) {
                             if(app->m_context == ScanMode) {
                                 WIFI_APP_LOG_I("Monitor Mode");
                                 WIFI_APP_LOG_I("Monitor Mode");
-                                send_serial_command(ESerialCommand_MonitorMode);
+                                send_serial_command(app, ESerialCommand_MonitorMode);
                             }
                             }
                         } else if(event.m_input.type == InputTypeLong) {
                         } else if(event.m_input.type == InputTypeLong) {
                             WIFI_APP_LOG_I("Scan");
                             WIFI_APP_LOG_I("Scan");
-                            send_serial_command(ESerialCommand_Scan);
+                            send_serial_command(app, ESerialCommand_Scan);
                         }
                         }
                         break;
                         break;
                     case InputKeyBack:
                     case InputKeyBack:
                         if(event.m_input.type == InputTypeShort) {
                         if(event.m_input.type == InputTypeShort) {
                             switch(app->m_context) {
                             switch(app->m_context) {
                             case MonitorMode:
                             case MonitorMode:
-                                send_serial_command(ESerialCommand_Scan);
+                                send_serial_command(app, ESerialCommand_Scan);
                                 break;
                                 break;
                             case ScanMode:
                             case ScanMode:
                                 processing = false;
                                 processing = false;
@@ -1034,9 +1030,8 @@ int32_t wifi_scanner_app(void* p) {
     // Reset GPIO pins to default state
     // Reset GPIO pins to default state
     furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
     furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
 
 
-#if DISABLE_CONSOLE
-    furi_hal_console_enable();
-#endif
+    furi_hal_serial_deinit(app->serial_handle);
+    furi_hal_serial_control_release(app->serial_handle);
 
 
     view_port_enabled_set(view_port, false);
     view_port_enabled_set(view_port, false);