From 967c9116c8afb88d04dc623385d34da233ce3079 Mon Sep 17 00:00:00 2001 From: Haisenteck <142255985+haisenteck@users.noreply.github.com> Date: Fri, 12 Jan 2024 00:40:37 +0100 Subject: [PATCH 1/7] Update README.md Add to list Fastrax UP500 Module --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 45139b45a6c..ba0561229c0 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ the hardware setup. * [u-blox NEO-6M] * [u-blox NEO-7M] * [Uputronics u-blox MAX-M8C Pico] +* Fastrax UP500 If you have verified this application working with a module not listed here, please submit a PR adding it to the list. From 20898f1e3d8ca8fed1677b4b3b7276a9e92ef7ac Mon Sep 17 00:00:00 2001 From: Haisenteck <142255985+haisenteck@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:58:06 +0100 Subject: [PATCH 2/7] Update gps.c --- gps.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/gps.c b/gps.c index c23175e1d54..0ccfb652b1a 100644 --- a/gps.c +++ b/gps.c @@ -2,6 +2,7 @@ #include "constants.h" #include +#include #include #include @@ -41,14 +42,14 @@ static void render_callback(Canvas* const canvas, void* context) { switch(gps_uart->speed_units) { case KPH: - snprintf(buffer, 64, "%.2f km", (double)(gps_uart->status.speed * KNOTS_TO_KPH)); + snprintf(buffer, 64, "%.2f Km/h", (double)(gps_uart->status.speed * KNOTS_TO_KPH)); break; case MPH: - snprintf(buffer, 64, "%.2f mi", (double)(gps_uart->status.speed * KNOTS_TO_MPH)); + snprintf(buffer, 64, "%.2f Mi/h", (double)(gps_uart->status.speed * KNOTS_TO_MPH)); break; case KNOTS: default: - snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed); + snprintf(buffer, 64, "%.2f Kn", (double)gps_uart->status.speed); break; } @@ -94,6 +95,14 @@ int32_t gps_app(void* p) { FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + uint8_t attempts = 0; + bool otg_was_enabled = furi_hal_power_is_otg_enabled(); + while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) { + furi_hal_power_enable_otg(); + furi_delay_ms(10); + } + furi_delay_ms(200); + GpsUart* gps_uart = gps_uart_enable(); gps_uart->mutex = furi_mutex_alloc(FuriMutexTypeNormal); @@ -159,6 +168,8 @@ int32_t gps_app(void* p) { gps_uart_init_thread(gps_uart); gps_uart->changing_baudrate = true; + furi_mutex_release(gps_uart->mutex); + view_port_update(view_port); break; case InputKeyRight: gps_uart->speed_units++; @@ -175,11 +186,10 @@ int32_t gps_app(void* p) { } } } - - view_port_update(view_port); - furi_mutex_release(gps_uart->mutex); - - if(gps_uart->changing_baudrate) { + if(!gps_uart->changing_baudrate) { + furi_mutex_release(gps_uart->mutex); + view_port_update(view_port); + } else { furi_delay_ms(1000); gps_uart->changing_baudrate = false; } @@ -194,5 +204,9 @@ int32_t gps_app(void* p) { furi_mutex_free(gps_uart->mutex); gps_uart_disable(gps_uart); + if(furi_hal_power_is_otg_enabled() && !otg_was_enabled) { + furi_hal_power_disable_otg(); + } + return 0; } From b98c1c5480cec71b601373aca1d561e9d0c19206 Mon Sep 17 00:00:00 2001 From: Haisenteck <142255985+haisenteck@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:58:41 +0100 Subject: [PATCH 3/7] Update gps_uart.c --- gps_uart.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/gps_uart.c b/gps_uart.c index 58d42443012..6596bed2c59 100644 --- a/gps_uart.c +++ b/gps_uart.c @@ -1,6 +1,6 @@ #include -#include +#include "minmea.h" #include "gps_uart.h" typedef enum { @@ -10,25 +10,30 @@ typedef enum { #define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone) -static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) { - GpsUart* gps_uart = (GpsUart*)context; - - if(ev == UartIrqEventRXNE) { +static void gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent ev, void* context) { + GpsUart* gps_uart = (GpsUart*)context; + + if(ev == FuriHalSerialRxEventData) { + uint8_t data = furi_hal_serial_async_rx(handle); furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0); furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone); } } -static void gps_uart_serial_init(GpsUart* gps_uart) { - furi_hal_console_disable(); - furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart); - furi_hal_uart_set_br(FuriHalUartIdUSART1, gps_uart->baudrate); +void gps_uart_serial_init(GpsUart* gps_uart) { + furi_assert(!gps_uart->serial_handle); + + gps_uart->serial_handle = furi_hal_serial_control_acquire(UART_CH); + furi_assert(gps_uart->serial_handle); + furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate); + furi_hal_serial_async_rx_start(gps_uart->serial_handle, gps_uart_on_irq_cb, gps_uart, false); } static void gps_uart_serial_deinit(GpsUart* gps_uart) { - UNUSED(gps_uart); - furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL); - furi_hal_console_enable(); + furi_assert(gps_uart->serial_handle); + furi_hal_serial_deinit(gps_uart->serial_handle); + furi_hal_serial_control_release(gps_uart->serial_handle); + gps_uart->serial_handle = NULL; } static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) { @@ -103,11 +108,7 @@ static int32_t gps_uart_worker(void* context) { do { // receive serial bytes into rx_buf, starting at rx_offset from the start of the buffer // the maximum we can receive is RX_BUF_SIZE - 1 - rx_offset - len = furi_stream_buffer_receive( - gps_uart->rx_stream, - gps_uart->rx_buf + rx_offset, - RX_BUF_SIZE - 1 - rx_offset, - 0); + len = furi_stream_buffer_receive(gps_uart->rx_stream, gps_uart->rx_buf + rx_offset, RX_BUF_SIZE - 1 - rx_offset, 0); if(len > 0) { // increase rx_offset by the number of bytes received, and null-terminate rx_buf rx_offset += len; @@ -204,7 +205,7 @@ GpsUart* gps_uart_enable() { gps_uart->baudrate = gps_baudrates[current_gps_baudrate]; gps_uart->changing_baudrate = false; gps_uart->backlight_on = false; - gps_uart->speed_units = KNOTS; + gps_uart->speed_units = KPH; gps_uart_init_thread(gps_uart); From f66db0ee73a72e80b053e9bcea1fea30e5f89368 Mon Sep 17 00:00:00 2001 From: Haisenteck <142255985+haisenteck@users.noreply.github.com> Date: Sat, 27 Jan 2024 21:59:36 +0100 Subject: [PATCH 4/7] Update gps_uart.h --- gps_uart.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gps_uart.h b/gps_uart.h index a5a456460b2..ec01db0cbef 100644 --- a/gps_uart.h +++ b/gps_uart.h @@ -4,6 +4,7 @@ #include #define RX_BUF_SIZE 1024 +#define UART_CH (FuriHalSerialIdUsart) static const int gps_baudrates[6] = {4800, 9600, 19200, 38400, 57600, 115200}; static int current_gps_baudrate = 1; @@ -36,6 +37,8 @@ typedef struct { bool changing_baudrate; bool backlight_on; SpeedUnit speed_units; + + FuriHalSerialHandle* serial_handle; GpsStatus status; } GpsUart; From 6bc5c3d9c39fe585f278d06e5266c0ede9418f9e Mon Sep 17 00:00:00 2001 From: Aaron Mavrinac Date: Mon, 26 Feb 2024 10:46:10 -0500 Subject: [PATCH 5/7] Apply all suggestions from code review. --- gps.c | 21 +++++++++++++-------- gps_uart.c | 14 +++++++------- gps_uart.h | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/gps.c b/gps.c index 0ccfb652b1a..c47d53770a5 100644 --- a/gps.c +++ b/gps.c @@ -42,14 +42,14 @@ static void render_callback(Canvas* const canvas, void* context) { switch(gps_uart->speed_units) { case KPH: - snprintf(buffer, 64, "%.2f Km/h", (double)(gps_uart->status.speed * KNOTS_TO_KPH)); + snprintf(buffer, 64, "%.2f kph", (double)(gps_uart->status.speed * KNOTS_TO_KPH)); break; case MPH: - snprintf(buffer, 64, "%.2f Mi/h", (double)(gps_uart->status.speed * KNOTS_TO_MPH)); + snprintf(buffer, 64, "%.2f mph", (double)(gps_uart->status.speed * KNOTS_TO_MPH)); break; case KNOTS: default: - snprintf(buffer, 64, "%.2f Kn", (double)gps_uart->status.speed); + snprintf(buffer, 64, "%.2f kn", (double)gps_uart->status.speed); break; } @@ -95,13 +95,18 @@ int32_t gps_app(void* p) { FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); - uint8_t attempts = 0; bool otg_was_enabled = furi_hal_power_is_otg_enabled(); - while(!furi_hal_power_is_otg_enabled() && attempts++ < 5) { - furi_hal_power_enable_otg(); - furi_delay_ms(10); + uint8_t attempts = 5; + while(--attempts > 0) { + if(furi_hal_power_enable_otg()) break; } - furi_delay_ms(200); + if(attempts == 0) { + if(furi_hal_power_get_usb_voltage() < 4.5f) { + FURI_LOG_E( + TAG, + "Error power otg enable. BQ2589 check otg fault = %d", + furi_hal_power_check_otg_fault() ? 1 : 0); + } GpsUart* gps_uart = gps_uart_enable(); diff --git a/gps_uart.c b/gps_uart.c index 6596bed2c59..6580f447dbd 100644 --- a/gps_uart.c +++ b/gps_uart.c @@ -1,6 +1,6 @@ #include -#include "minmea.h" +#include #include "gps_uart.h" typedef enum { @@ -11,21 +11,21 @@ typedef enum { #define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone) static void gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent ev, void* context) { - GpsUart* gps_uart = (GpsUart*)context; + GpsUart* gps_uart = (GpsUart*)context; - if(ev == FuriHalSerialRxEventData) { + if(ev == FuriHalSerialRxEventData) { uint8_t data = furi_hal_serial_async_rx(handle); furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0); furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone); } } -void gps_uart_serial_init(GpsUart* gps_uart) { +static void gps_uart_serial_init(GpsUart* gps_uart) { furi_assert(!gps_uart->serial_handle); gps_uart->serial_handle = furi_hal_serial_control_acquire(UART_CH); - furi_assert(gps_uart->serial_handle); - furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate); + furi_assert(gps_uart->serial_handle); + furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate); furi_hal_serial_async_rx_start(gps_uart->serial_handle, gps_uart_on_irq_cb, gps_uart, false); } @@ -205,7 +205,7 @@ GpsUart* gps_uart_enable() { gps_uart->baudrate = gps_baudrates[current_gps_baudrate]; gps_uart->changing_baudrate = false; gps_uart->backlight_on = false; - gps_uart->speed_units = KPH; + gps_uart->speed_units = KNOTS; gps_uart_init_thread(gps_uart); diff --git a/gps_uart.h b/gps_uart.h index ec01db0cbef..497a77ab639 100644 --- a/gps_uart.h +++ b/gps_uart.h @@ -38,7 +38,7 @@ typedef struct { bool backlight_on; SpeedUnit speed_units; - FuriHalSerialHandle* serial_handle; + FuriHalSerialHandle* serial_handle; GpsStatus status; } GpsUart; From 38f6f63d0943999ee34027e8fd6c37a567eea8a6 Mon Sep 17 00:00:00 2001 From: Aaron Mavrinac Date: Mon, 26 Feb 2024 10:51:24 -0500 Subject: [PATCH 6/7] Fix undeclared identifier. --- gps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gps.c b/gps.c index c47d53770a5..0db150309f8 100644 --- a/gps.c +++ b/gps.c @@ -103,7 +103,7 @@ int32_t gps_app(void* p) { if(attempts == 0) { if(furi_hal_power_get_usb_voltage() < 4.5f) { FURI_LOG_E( - TAG, + "GPS", "Error power otg enable. BQ2589 check otg fault = %d", furi_hal_power_check_otg_fault() ? 1 : 0); } From 76d832f0b9cbcb4a3359b0139b1f7eaada2b606b Mon Sep 17 00:00:00 2001 From: Aaron Mavrinac Date: Mon, 26 Feb 2024 10:53:56 -0500 Subject: [PATCH 7/7] Fix missing brace. --- gps.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gps.c b/gps.c index 0db150309f8..b202324177a 100644 --- a/gps.c +++ b/gps.c @@ -107,6 +107,7 @@ int32_t gps_app(void* p) { "Error power otg enable. BQ2589 check otg fault = %d", furi_hal_power_check_otg_fault() ? 1 : 0); } + } GpsUart* gps_uart = gps_uart_enable();