Преглед изворни кода

update companions to newer fz sdk

Signed-off-by: Antonio Murdaca <antoniomurdaca@gmail.com>
Antonio Murdaca пре 1 година
родитељ
комит
5df3d5a079
3 измењених фајлова са 38 додато и 21 уклоњено
  1. 8 8
      application.fam
  2. 27 11
      uart_echo.c
  3. 3 2
      uart_echo.h

+ 8 - 8
application.fam

@@ -1,15 +1,15 @@
 App(
     appid="mayhem_nannycam",
-    name="[MAYHEM] Nanny Cam v0.1",
+    name="[MAYHEM] Nanny Cam",
     apptype=FlipperAppType.EXTERNAL,
     entry_point="uart_echo_app",
     cdefines=["APP_QRCODE"],
     requires=["gui"],
-    stack_size=8*1024,
+    stack_size=8 * 1024,
     order=1,
-	fap_icon="icon.png",
-  fap_category="GPIO",
-	fap_description="ESP32-CAM simple app to start a remote camera. [Unplug the USB cable to test with Mayhem]",
-	fap_author="eried",
-	fap_weburl="https://flipper.ried.cl"
-)
+    fap_icon="icon.png",
+    fap_category="GPIO/MAYHEM",
+    fap_description="ESP32-CAM simple app to start a remote camera. [Unplug the USB cable to test with Mayhem]",
+    fap_author="eried",
+    fap_weburl="https://flipper.ried.cl",
+)

+ 27 - 11
uart_echo.c

@@ -1,5 +1,7 @@
 #include "uart_echo.h"
 
+#include <expansion/expansion.h>
+
 static void uart_echo_view_draw_callback(Canvas* canvas, void* _model) {
     UartDumpModel* model = _model;
 
@@ -40,11 +42,13 @@ static uint32_t uart_echo_exit(void* context) {
     return VIEW_NONE;
 }
 
-static void uart_echo_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
+static void
+    uart_echo_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
     furi_assert(context);
     UartEchoApp* app = context;
 
-    if(ev == UartIrqEventRXNE) {
+    if(event == FuriHalSerialRxEventData) {
+        uint8_t data = furi_hal_serial_async_rx(handle);
         furi_stream_buffer_send(app->rx_stream, &data, 1, 0);
         furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
     }
@@ -108,7 +112,7 @@ static int32_t uart_echo_worker(void* context) {
                 uint8_t data[64];
                 length = furi_stream_buffer_receive(app->rx_stream, data, 64, 0);
                 if(length > 0 && app->initialized) {
-                    furi_hal_uart_tx(FuriHalUartIdUSART1, data, length);
+                    furi_hal_serial_tx(app->serial_handle, data, length);
                     with_view_model(
                         app->view,
                         UartDumpModel * model,
@@ -170,19 +174,19 @@ static UartEchoApp* uart_echo_app_alloc() {
     furi_thread_start(app->worker_thread);
 
     // Enable uart listener
-    furi_hal_console_disable();
-    furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400);
-    furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, uart_echo_on_irq_cb, app);
+    app->serial_handle = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
+    furi_check(app->serial_handle);
+    furi_hal_serial_init(app->serial_handle, 230400);
+    furi_hal_serial_async_rx_start(app->serial_handle, uart_echo_on_irq_cb, app, false);
 
     furi_hal_power_disable_external_3_3v();
     furi_hal_power_disable_otg();
     furi_delay_ms(200);
     furi_hal_power_enable_external_3_3v();
     furi_hal_power_enable_otg();
-    for(int i=0;i<2;i++)
-    {
-        furi_delay_ms(500); 
-        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[1]){'n'}, 1);
+    for(int i = 0; i < 2; i++) {
+        furi_delay_ms(500);
+        furi_hal_serial_tx(app->serial_handle, (uint8_t[1]){'n'}, 1);
     }
     furi_delay_ms(1);
     app->initialized = true;
@@ -192,7 +196,9 @@ static UartEchoApp* uart_echo_app_alloc() {
 static void uart_echo_app_free(UartEchoApp* app) {
     furi_assert(app);
 
-    furi_hal_console_enable(); // this will also clear IRQ callback so thread is no longer referenced
+    furi_hal_serial_async_rx_stop(app->serial_handle);
+    furi_hal_serial_deinit(app->serial_handle);
+    furi_hal_serial_control_release(app->serial_handle);
 
     furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
     furi_thread_join(app->worker_thread);
@@ -227,9 +233,19 @@ static void uart_echo_app_free(UartEchoApp* app) {
 
 int32_t uart_echo_app(void* p) {
     UNUSED(p);
+
+    // Disable expansion protocol to avoid interference with UART Handle
+    Expansion* expansion = furi_record_open(RECORD_EXPANSION);
+    expansion_disable(expansion);
+
     UartEchoApp* app = uart_echo_app_alloc();
     view_dispatcher_run(app->view_dispatcher);
     uart_echo_app_free(app);
     furi_hal_power_disable_otg();
+
+    // Return previous state of expansion
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
     return 0;
 }

+ 3 - 2
uart_echo.h

@@ -4,8 +4,8 @@
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
 #include <gui/elements.h>
-#include <furi_hal_uart.h>
-#include <furi_hal_console.h>
+#include <furi_hal_serial_control.h>
+#include <furi_hal_serial.h>
 #include <gui/view_dispatcher.h>
 #include <gui/modules/dialog_ex.h>
 
@@ -21,6 +21,7 @@ typedef struct {
     View* view;
     FuriThread* worker_thread;
     FuriStreamBuffer* rx_stream;
+    FuriHalSerialHandle* serial_handle;
     bool initialized;
 } UartEchoApp;