Sfoglia il codice sorgente

Merge gps_nmea from https://github.com/ezod/flipperzero-gps

Willy-JL 1 anno fa
parent
commit
ad684b5833
4 ha cambiato i file con 54 aggiunte e 30 eliminazioni
  1. 38 16
      gps_nmea/README.md
  2. 5 6
      gps_nmea/gps.c
  3. 7 4
      gps_nmea/gps_uart.c
  4. 4 4
      gps_nmea/gps_uart.h

+ 38 - 16
gps_nmea/README.md

@@ -1,9 +1,21 @@
 # GPS for Flipper Zero
 
-A simple Flipper Zero application for NMEA 0183 serial GPS modules, such as the
-- Adafruit Ultimate GPS Breakout.
+[![FAP Build](https://github.com/ezod/flipperzero-gps/actions/workflows/build.yml/badge.svg)](https://github.com/ezod/flipperzero-gps/actions/workflows/build.yml)
 
-Heavy lifting (NMEA parsing) provided by minmea.
+A simple Flipper Zero application for NMEA 0183 serial GPS modules.
+
+![ui](ui.png)
+
+Heavy lifting (NMEA parsing) provided by [minmea].
+
+## Installation
+
+1. Navigate to the [FAP Build](https://github.com/ezod/flipperzero-gps/actions/workflows/build.yml)
+   GitHub action workflow, and select the most recent run.
+2. The FAP is built for both the `dev` and `release` channels of the official
+   firmware. Download the artifact corresponding to your firmware version.
+3. Extract `gps_nmea.fap` from the ZIP file to `apps/GPIO` on your Flipper
+   Zero SD card.
 
 ## Usage
 
@@ -11,7 +23,7 @@ This is a single-screen app, and a few interactions are provided via the
 hardware buttons:
 
 - Long press the up button to change the **baud rate**. The default baud rate
-  is 9600, but 19200, 38400, 57600, and 115200 baud are also supported.
+  is 9600, but 4800, 19200, 38400, 57600, and 115200 baud are also supported.
 - Long press the right button to change **speed units** from knots to
   kilometers per hour.
 - Press the OK button to set the **backlight** to always on mode. Press it
@@ -23,14 +35,15 @@ hardware buttons:
 Connect the GPS module to power and the USART using GPIO pins 9 (3.3V), 11
 (GND), 13 (TX), and 14 (RX), as appropriate.
 
+![wiring](wiring.png)
 
-See the tutorial video - https://www.youtube.com/watch?v=5vSGFzEBp-k from
-Lab401 by RocketGod - https://github.com/RocketGod-git for a visual guide to
+See the [tutorial video](https://www.youtube.com/watch?v=5vSGFzEBp-k) from
+Lab401 by [RocketGod](https://github.com/RocketGod-git) for a visual guide to
 the hardware setup.
 
-## Confirmed Compatible Modules
+### Confirmed Compatible Modules
 
-* Adafruit Ultimate GPS Breakout
+* [Adafruit Ultimate GPS Breakout]
 * ATGM336H
 * Beitian BN-180
 * Beitian BN-220
@@ -42,17 +55,26 @@ the hardware setup.
 * Beitian BE-280
 * Beitian BN-280ZF
 * Beitian BN-357ZF
+* Fastrax UP500
+* [mRo GPS u-Blox Neo-M8N]
 * Royaltek RBT-2100LP
-* u-blox NEO-6M
-* u-blox NEO-7M
-* Uputronics u-blox MAX-M8C Pico
+* [u-Blox NEO-6M]
+* [u-Blox NEO-7M]
+* [Uputronics u-blox MAX-M8C Pico]
 
 If you have verified this application working with a module not listed here,
 please submit a PR adding it to the list.
 
-## Links
+## Building
+
+This application can be compiled using [uFBT]. Run `ufbt` in the root directory
+of the repository.
 
-Original repo link - https://github.com/ezod/flipperzero-gps
-Adafruit Ultimate GPS Breakout: https://www.adafruit.com/product/746
-minmea: https://github.com/kosma/minmea
-u-blox NEO-6M: https://www.u-blox.com/en/product/neo-6-series
+[Adafruit Ultimate GPS Breakout]: https://www.adafruit.com/product/746
+[minmea]: https://github.com/kosma/minmea
+[mRo GPS u-Blox Neo-M8N]: https://store.mrobotics.io/product-p/m10034-solo.htm
+[qFlipper]: https://flipperzero.one/update
+[u-Blox NEO-6M]: https://www.u-blox.com/en/product/neo-6-series
+[u-Blox NEO-7M]: https://www.u-blox.com/en/product/neo-7-series
+[uFBT]: https://github.com/flipperdevices/flipperzero-ufbt
+[Uputronics u-blox MAX-M8C Pico]: https://store.uputronics.com/index.php?route=product/product&product_id=72

+ 5 - 6
gps_nmea/gps.c

@@ -2,6 +2,7 @@
 #include "constants.h"
 
 #include <furi.h>
+#include <furi_hal_power.h>
 #include <gui/gui.h>
 #include <string.h>
 #include <expansion/expansion.h>
@@ -38,7 +39,7 @@ static void render_callback(Canvas* const canvas, void* context) {
             32,
             AlignCenter,
             AlignBottom,
-            gps_uart->backlight_enabled ? "Backlight enabled" : "Backlight disabled");
+            gps_uart->backlight_on ? "Backlight enabled" : "Backlight disabled");
         break;
     case CHANGE_DEEPSLEEP:
         canvas_set_font(canvas, FontPrimary);
@@ -182,16 +183,16 @@ int32_t gps_app(void* p) {
                         processing = false;
                         break;
                     case InputKeyOk:
-                        if(!gps_uart->backlight_enabled) {
+                        if(!gps_uart->backlight_on) {
                             notification_message_block(
                                 gps_uart->notifications, &sequence_display_backlight_enforce_on);
-                            gps_uart->backlight_enabled = true;
+                            gps_uart->backlight_on = true;
                         } else {
                             notification_message_block(
                                 gps_uart->notifications, &sequence_display_backlight_enforce_auto);
                             notification_message(
                                 gps_uart->notifications, &sequence_display_backlight_off);
-                            gps_uart->backlight_enabled = false;
+                            gps_uart->backlight_on = false;
                         }
 
                         gps_uart->view_state = CHANGE_BACKLIGHT;
@@ -217,7 +218,6 @@ int32_t gps_app(void* p) {
 
                         gps_uart_init_thread(gps_uart);
                         gps_uart->view_state = CHANGE_BAUDRATE;
-
                         furi_mutex_release(gps_uart->mutex);
                         view_port_update(view_port);
                         furi_delay_ms(1000);
@@ -259,7 +259,6 @@ int32_t gps_app(void* p) {
                 }
             }
         }
-
         if(gps_uart->view_state == NORMAL) {
             furi_mutex_release(gps_uart->mutex);
             view_port_update(view_port);

+ 7 - 4
gps_nmea/gps_uart.c

@@ -11,10 +11,10 @@ typedef enum {
 #define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
 
 static void
-    gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
+    gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent ev, void* context) {
     GpsUart* gps_uart = (GpsUart*)context;
 
-    if(event == 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);
@@ -22,6 +22,8 @@ static void
 }
 
 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_check(gps_uart->serial_handle);
     furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate);
@@ -32,10 +34,11 @@ static void gps_uart_serial_init(GpsUart* gps_uart) {
 }
 
 static void gps_uart_serial_deinit(GpsUart* gps_uart) {
-    UNUSED(gps_uart);
+    furi_assert(gps_uart->serial_handle);
     furi_hal_serial_async_rx_stop(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) {
@@ -209,8 +212,8 @@ GpsUart* gps_uart_enable() {
     gps_uart->notifications = furi_record_open(RECORD_NOTIFICATION);
 
     gps_uart->baudrate = gps_baudrates[current_gps_baudrate];
+    gps_uart->backlight_on = false;
     gps_uart->speed_units = KNOTS;
-    gps_uart->backlight_enabled = false;
     gps_uart->deep_sleep_enabled = false;
     gps_uart->view_state = NORMAL;
 

+ 4 - 4
gps_nmea/gps_uart.h

@@ -5,9 +5,8 @@
 
 #include <momentum/momentum.h>
 
-#define UART_CH (momentum_settings.uart_nmea_channel)
-
 #define RX_BUF_SIZE 1024
+#define UART_CH (momentum_settings.uart_nmea_channel)
 
 static const int gps_baudrates[6] = {4800, 9600, 19200, 38400, 57600, 115200};
 static int current_gps_baudrate = 1;
@@ -42,15 +41,16 @@ typedef struct {
     FuriThread* thread;
     FuriStreamBuffer* rx_stream;
     uint8_t rx_buf[RX_BUF_SIZE];
-    FuriHalSerialHandle* serial_handle;
 
     NotificationApp* notifications;
     uint32_t baudrate;
-    bool backlight_enabled;
+    bool backlight_on;
     bool deep_sleep_enabled;
     SpeedUnit speed_units;
     ViewState view_state;
 
+    FuriHalSerialHandle* serial_handle;
+
     GpsStatus status;
 } GpsUart;