Skip to content

Commit

Permalink
Update UART code to use new stream buffer API. Closes #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
ezod committed Oct 7, 2022
1 parent 75940c7 commit 47fadfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 5 additions & 7 deletions gps_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ typedef enum {

static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
GpsUart* gps_uart = (GpsUart*)context;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;

if(ev == UartIrqEventRXNE) {
xStreamBufferSendFromISR(gps_uart->rx_stream, &data, 1, &xHigherPriorityTaskWoken);
furi_stream_buffer_send(gps_uart->rx_stream, &data, 1, 0);
furi_thread_flags_set(furi_thread_get_id(gps_uart->thread), WorkerEvtRxDone);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}

Expand Down Expand Up @@ -52,7 +50,7 @@ static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line)
static int32_t gps_uart_worker(void* context) {
GpsUart* gps_uart = (GpsUart*)context;

gps_uart->rx_stream = xStreamBufferCreate(RX_BUF_SIZE * 5, 1);
gps_uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE * 5, 1);
size_t rx_offset = 0;

gps_uart_serial_init(gps_uart);
Expand All @@ -65,8 +63,8 @@ static int32_t gps_uart_worker(void* context) {
if(events & WorkerEvtRxDone) {
size_t len = 0;
do {
len = xStreamBufferReceive(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) {
rx_offset += len;
gps_uart->rx_buf[rx_offset] = '\0';
Expand Down Expand Up @@ -97,7 +95,7 @@ static int32_t gps_uart_worker(void* context) {

gps_uart_serial_deinit(gps_uart);

vStreamBufferDelete(gps_uart->rx_stream);
furi_stream_buffer_free(gps_uart->rx_stream);

return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions gps_uart.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <furi_hal.h>
#include <stream_buffer.h>

#define GPS_BAUDRATE 9600
#define RX_BUF_SIZE 1024
Expand All @@ -13,7 +12,7 @@ typedef struct {

typedef struct {
FuriThread* thread;
StreamBufferHandle_t rx_stream;
FuriStreamBuffer* rx_stream;
uint8_t rx_buf[RX_BUF_SIZE];

GpsStatus status;
Expand Down

0 comments on commit 47fadfc

Please sign in to comment.