|
|
@@ -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);
|
|
|
}
|
|
|
@@ -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) {
|
|
|
// Alarm sound
|
|
|
- if(data == '!'){
|
|
|
+ if(data == '!') {
|
|
|
UartEchoApp* app = context;
|
|
|
notification_message(app->notification, &sequence_alarm);
|
|
|
}
|
|
|
@@ -114,7 +118,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,
|
|
|
@@ -176,19 +180,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]){'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);
|
|
|
app->initialized = true;
|
|
|
@@ -198,7 +202,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);
|
|
|
@@ -233,9 +239,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;
|
|
|
}
|