Skip to content

Commit

Permalink
builds against RC
Browse files Browse the repository at this point in the history
  • Loading branch information
bettse committed Jan 20, 2024
1 parent bb274e7 commit 9aca17b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
10 changes: 5 additions & 5 deletions seader_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

#define WORKER_ALL_RX_EVENTS \
(WorkerEvtStop | WorkerEvtRxDone | WorkerEvtCfgChange | WorkerEvtLineCfgSet | \
WorkerEvtCtrlLineSet)
WorkerEvtCtrlLineSet | WorkerEvtSamTxComplete)
#define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtSamRx)

#define SEADER_TEXT_STORE_SIZE 128
Expand All @@ -75,12 +75,12 @@ typedef enum {

WorkerEvtTxStop = (1 << 2),
WorkerEvtSamRx = (1 << 3),
WorkerEvtSamTxComplete = (1 << 4),

WorkerEvtCfgChange = (1 << 4),

WorkerEvtLineCfgSet = (1 << 5),
WorkerEvtCtrlLineSet = (1 << 6),
WorkerEvtCfgChange = (1 << 5),

WorkerEvtLineCfgSet = (1 << 6),
WorkerEvtCtrlLineSet = (1 << 7),
} WorkerEvtFlags;

struct Seader {
Expand Down
29 changes: 22 additions & 7 deletions uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@

#define TAG "SeaderUART"

void seader_uart_on_irq_cb(uint8_t data, void* context) {
static void seader_uart_on_irq_rx_dma_cb(
FuriHalSerialHandle* handle,
FuriHalSerialRxEvent ev,
size_t size,
void* context) {
SeaderUartBridge* seader_uart = (SeaderUartBridge*)context;
furi_stream_buffer_send(seader_uart->rx_stream, &data, 1, 0);
furi_thread_flags_set(furi_thread_get_id(seader_uart->thread), WorkerEvtRxDone);
if(ev & (FuriHalSerialRxEventData | FuriHalSerialRxEventIdle)) {
uint8_t data[FURI_HAL_SERIAL_DMA_BUFFER_SIZE] = {0};
while(size) {
size_t ret = furi_hal_serial_dma_rx(
handle,
data,
(size > FURI_HAL_SERIAL_DMA_BUFFER_SIZE) ? FURI_HAL_SERIAL_DMA_BUFFER_SIZE : size);
furi_stream_buffer_send(seader_uart->rx_stream, data, ret, 0);
size -= ret;
};
furi_thread_flags_set(furi_thread_get_id(seader_uart->thread), WorkerEvtRxDone);
}
}

void seader_uart_disable(SeaderUartBridge* seader_uart) {
Expand All @@ -23,14 +37,15 @@ void seader_uart_serial_init(SeaderUartBridge* seader_uart, uint8_t uart_ch) {
furi_assert(seader_uart->serial_handle);

furi_hal_serial_init(seader_uart->serial_handle, 115200);
furi_hal_serial_set_rx_callback(seader_uart->serial_handle, seader_uart_on_irq_cb, seader_uart);
furi_hal_serial_dma_rx_start(
seader_uart->serial_handle, seader_uart_on_irq_rx_dma_cb, seader_uart, false);
}

void seader_uart_serial_deinit(SeaderUartBridge* seader_uart) {
UNUSED(seader_uart);
furi_hal_serial_set_rx_callback(seader_uart->serial_handle, NULL, NULL);
furi_assert(seader_uart->serial_handle);
furi_hal_serial_deinit(seader_uart->serial_handle);
furi_hal_serial_control_release(seader_uart->serial_handle);
seader_uart->serial_handle = NULL;
}

void seader_uart_set_baudrate(SeaderUartBridge* seader_uart, uint32_t baudrate) {
Expand Down Expand Up @@ -104,7 +119,7 @@ int32_t seader_uart_worker(void* context) {
cmd_len = 0;
break;
}
if(events & WorkerEvtRxDone) {
if(events & (WorkerEvtRxDone | WorkerEvtSamTxComplete)) {
size_t len = furi_stream_buffer_receive(
seader_uart->rx_stream, seader_uart->rx_buf, SEADER_UART_RX_BUF_SIZE, 0);
if(len > 0) {
Expand Down

0 comments on commit 9aca17b

Please sign in to comment.