Skip to content

Commit b98c1c5

Browse files
authored
Update gps_uart.c
1 parent 20898f1 commit b98c1c5

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

gps_uart.c

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <string.h>
22

3-
#include <minmea.h>
3+
#include "minmea.h"
44
#include "gps_uart.h"
55

66
typedef enum {
@@ -10,25 +10,30 @@ typedef enum {
1010

1111
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
1212

13-
static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
14-
GpsUart* gps_uart = (GpsUart*)context;
15-
16-
if(ev == UartIrqEventRXNE) {
13+
static void gps_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent ev, void* context) {
14+
GpsUart* gps_uart = (GpsUart*)context;
15+
16+
if(ev == FuriHalSerialRxEventData) {
17+
uint8_t data = furi_hal_serial_async_rx(handle);
1718
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
1819
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
1920
}
2021
}
2122

22-
static void gps_uart_serial_init(GpsUart* gps_uart) {
23-
furi_hal_console_disable();
24-
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
25-
furi_hal_uart_set_br(FuriHalUartIdUSART1, gps_uart->baudrate);
23+
void gps_uart_serial_init(GpsUart* gps_uart) {
24+
furi_assert(!gps_uart->serial_handle);
25+
26+
gps_uart->serial_handle = furi_hal_serial_control_acquire(UART_CH);
27+
furi_assert(gps_uart->serial_handle);
28+
furi_hal_serial_init(gps_uart->serial_handle, gps_uart->baudrate);
29+
furi_hal_serial_async_rx_start(gps_uart->serial_handle, gps_uart_on_irq_cb, gps_uart, false);
2630
}
2731

2832
static void gps_uart_serial_deinit(GpsUart* gps_uart) {
29-
UNUSED(gps_uart);
30-
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
31-
furi_hal_console_enable();
33+
furi_assert(gps_uart->serial_handle);
34+
furi_hal_serial_deinit(gps_uart->serial_handle);
35+
furi_hal_serial_control_release(gps_uart->serial_handle);
36+
gps_uart->serial_handle = NULL;
3237
}
3338

3439
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {
@@ -103,11 +108,7 @@ static int32_t gps_uart_worker(void* context) {
103108
do {
104109
// receive serial bytes into rx_buf, starting at rx_offset from the start of the buffer
105110
// the maximum we can receive is RX_BUF_SIZE - 1 - rx_offset
106-
len = furi_stream_buffer_receive(
107-
gps_uart->rx_stream,
108-
gps_uart->rx_buf + rx_offset,
109-
RX_BUF_SIZE - 1 - rx_offset,
110-
0);
111+
len = furi_stream_buffer_receive(gps_uart->rx_stream, gps_uart->rx_buf + rx_offset, RX_BUF_SIZE - 1 - rx_offset, 0);
111112
if(len > 0) {
112113
// increase rx_offset by the number of bytes received, and null-terminate rx_buf
113114
rx_offset += len;
@@ -204,7 +205,7 @@ GpsUart* gps_uart_enable() {
204205
gps_uart->baudrate = gps_baudrates[current_gps_baudrate];
205206
gps_uart->changing_baudrate = false;
206207
gps_uart->backlight_on = false;
207-
gps_uart->speed_units = KNOTS;
208+
gps_uart->speed_units = KPH;
208209

209210
gps_uart_init_thread(gps_uart);
210211

0 commit comments

Comments
 (0)