Skip to content

Commit

Permalink
Update to the new serial API
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Feb 2, 2024
1 parent ec646d1 commit 2561c07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
20 changes: 12 additions & 8 deletions airmon_pms.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,29 @@ typedef enum {

#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)

static void airmon_pms_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
static void airmon_pms_uart_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
UNUSED(handle);

AirmonPmsContext* pms_context = context;

if(ev == UartIrqEventRXNE) {
if(event & FuriHalSerialRxEventData) {
uint8_t data = furi_hal_serial_async_rx(handle);
furi_stream_buffer_send(pms_context->rx_stream, &data, 1, 0);
furi_thread_flags_set(furi_thread_get_id(pms_context->thread), WorkerEvtRxDone);
}

}

static void airmon_pms_serial_init(AirmonPmsContext* pms_context) {
furi_hal_console_disable();
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, airmon_pms_uart_on_irq_cb, pms_context);
furi_hal_uart_set_br(FuriHalUartIdUSART1, PMS_BAUDRATE);
pms_context->serial = furi_hal_serial_control_acquire(FuriHalSerialIdUsart);
furi_check(pms_context->serial);
furi_hal_serial_init(pms_context->serial, PMS_BAUDRATE);
furi_hal_serial_async_rx_start(pms_context->serial, airmon_pms_uart_on_irq_cb, pms_context, true);
}

static void airmon_pms_serial_deinit(AirmonPmsContext* pms_context) {
UNUSED(pms_context);
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
furi_hal_console_enable();
furi_hal_serial_deinit(pms_context->serial);
furi_hal_serial_control_release(pms_context->serial);
}

bool airmon_pms_frame_valid(AirmonPmsContext* pms_context, size_t frame_len) {
Expand Down
1 change: 1 addition & 0 deletions airmon_pms.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct {
FuriMutex* mutex;
FuriThread* thread;
FuriStreamBuffer* rx_stream;
FuriHalSerialHandle* serial;
uint8_t rx_buf[RX_BUF_SIZE];

uint32_t pms_data_timestamp;
Expand Down

0 comments on commit 2561c07

Please sign in to comment.