Przeglądaj źródła

update companions to newer fz sdk

Signed-off-by: Antonio Murdaca <antoniomurdaca@gmail.com>
Antonio Murdaca 1 rok temu
rodzic
commit
ecc4103664
3 zmienionych plików z 39 dodań i 22 usunięć
  1. 8 8
      application.fam
  2. 28 12
      uart_echo.c
  3. 3 2
      uart_echo.h

+ 8 - 8
application.fam

@@ -1,15 +1,15 @@
 App(
 App(
     appid="mayhem_motion",
     appid="mayhem_motion",
-    name="[MAYHEM] Motion detection v0.1",
+    name="[MAYHEM] Motion detection",
     apptype=FlipperAppType.EXTERNAL,
     apptype=FlipperAppType.EXTERNAL,
     entry_point="uart_echo_app",
     entry_point="uart_echo_app",
     cdefines=["APP_QRCODE"],
     cdefines=["APP_QRCODE"],
     requires=["gui"],
     requires=["gui"],
-    stack_size=8*1024,
+    stack_size=8 * 1024,
     order=1,
     order=1,
-	fap_icon="icon.png",
-  fap_category="GPIO",
-	fap_description="ESP32-CAM Motion detection. It generates a beep when motion is detected. Can be extended to trigger more stuff in the code. [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 Motion detection. It generates a beep when motion is detected. Can be extended to trigger more stuff in the code. [Unplug the USB cable to test with Mayhem]",
+    fap_author="eried",
+    fap_weburl="https://flipper.ried.cl",
+)

+ 28 - 12
uart_echo.c

@@ -1,5 +1,7 @@
 #include "uart_echo.h"
 #include "uart_echo.h"
 
 
+#include <expansion/expansion.h>
+
 static void uart_echo_view_draw_callback(Canvas* canvas, void* _model) {
 static void uart_echo_view_draw_callback(Canvas* canvas, void* _model) {
     UartDumpModel* model = _model;
     UartDumpModel* model = _model;
 
 
@@ -40,11 +42,13 @@ static uint32_t uart_echo_exit(void* context) {
     return VIEW_NONE;
     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);
     furi_assert(context);
     UartEchoApp* app = 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_stream_buffer_send(app->rx_stream, &data, 1, 0);
         furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
         furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
     }
     }
@@ -52,7 +56,7 @@ static void uart_echo_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
 
 
 static void uart_echo_push_to_list(UartDumpModel* model, void* context, const char data) {
 static void uart_echo_push_to_list(UartDumpModel* model, void* context, const char data) {
     // Alarm sound
     // Alarm sound
-    if(data == '!'){
+    if(data == '!') {
         UartEchoApp* app = context;
         UartEchoApp* app = context;
         notification_message(app->notification, &sequence_alarm);
         notification_message(app->notification, &sequence_alarm);
     }
     }
@@ -114,7 +118,7 @@ static int32_t uart_echo_worker(void* context) {
                 uint8_t data[64];
                 uint8_t data[64];
                 length = furi_stream_buffer_receive(app->rx_stream, data, 64, 0);
                 length = furi_stream_buffer_receive(app->rx_stream, data, 64, 0);
                 if(length > 0 && app->initialized) {
                 if(length > 0 && app->initialized) {
-                    furi_hal_uart_tx(FuriHalUartIdUSART1, data, length);
+                    furi_hal_serial_tx(app->serial_handle, data, length);
                     with_view_model(
                     with_view_model(
                         app->view,
                         app->view,
                         UartDumpModel * model,
                         UartDumpModel * model,
@@ -176,19 +180,19 @@ static UartEchoApp* uart_echo_app_alloc() {
     furi_thread_start(app->worker_thread);
     furi_thread_start(app->worker_thread);
 
 
     // Enable uart listener
     // 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_external_3_3v();
     furi_hal_power_disable_otg();
     furi_hal_power_disable_otg();
     furi_delay_ms(200);
     furi_delay_ms(200);
     furi_hal_power_enable_external_3_3v();
     furi_hal_power_enable_external_3_3v();
     furi_hal_power_enable_otg();
     furi_hal_power_enable_otg();
-    for(int i=0;i<2;i++)
-    {
-        furi_delay_ms(500); 
-        furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[1]){'m'}, 1);
+    for(int i = 0; i < 2; i++) {
+        furi_delay_ms(500);
+        furi_hal_serial_tx(app->serial_handle, (uint8_t[1]){'m'}, 1);
     }
     }
     furi_delay_ms(1);
     furi_delay_ms(1);
     app->initialized = true;
     app->initialized = true;
@@ -198,7 +202,9 @@ static UartEchoApp* uart_echo_app_alloc() {
 static void uart_echo_app_free(UartEchoApp* app) {
 static void uart_echo_app_free(UartEchoApp* app) {
     furi_assert(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_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
     furi_thread_join(app->worker_thread);
     furi_thread_join(app->worker_thread);
@@ -233,9 +239,19 @@ static void uart_echo_app_free(UartEchoApp* app) {
 
 
 int32_t uart_echo_app(void* p) {
 int32_t uart_echo_app(void* p) {
     UNUSED(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();
     UartEchoApp* app = uart_echo_app_alloc();
     view_dispatcher_run(app->view_dispatcher);
     view_dispatcher_run(app->view_dispatcher);
     uart_echo_app_free(app);
     uart_echo_app_free(app);
     furi_hal_power_disable_otg();
     furi_hal_power_disable_otg();
+
+    // Return previous state of expansion
+    expansion_enable(expansion);
+    furi_record_close(RECORD_EXPANSION);
+
     return 0;
     return 0;
 }
 }

+ 3 - 2
uart_echo.h

@@ -4,8 +4,8 @@
 #include <notification/notification.h>
 #include <notification/notification.h>
 #include <notification/notification_messages.h>
 #include <notification/notification_messages.h>
 #include <gui/elements.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/view_dispatcher.h>
 #include <gui/modules/dialog_ex.h>
 #include <gui/modules/dialog_ex.h>
 
 
@@ -38,6 +38,7 @@ typedef struct {
     View* view;
     View* view;
     FuriThread* worker_thread;
     FuriThread* worker_thread;
     FuriStreamBuffer* rx_stream;
     FuriStreamBuffer* rx_stream;
+    FuriHalSerialHandle* serial_handle;
     bool initialized;
     bool initialized;
 } UartEchoApp;
 } UartEchoApp;