uart_i.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include <stdlib.h> // malloc
  3. #include <stdint.h> // uint32_t
  4. #include <stdarg.h> // __VA_ARGS__
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <furi.h>
  8. #include <furi_hal.h>
  9. #define SEOS_UART_RX_BUF_SIZE (256)
  10. #define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone | WorkerEvtDevTxComplete)
  11. #define WORKER_ALL_TX_EVENTS (WorkerEvtTxStop | WorkerEvtDevRx)
  12. typedef size_t (*SeosUartReceiveCallback)(void* context, uint8_t* buffer, size_t len);
  13. typedef enum {
  14. WorkerEvtStop = (1 << 0),
  15. WorkerEvtRxDone = (1 << 1),
  16. WorkerEvtTxStop = (1 << 2),
  17. WorkerEvtDevRx = (1 << 3),
  18. WorkerEvtDevTxComplete = (1 << 4),
  19. } WorkerEvtFlags;
  20. typedef struct {
  21. uint8_t uart_ch;
  22. uint8_t flow_pins;
  23. uint8_t baudrate_mode;
  24. uint32_t baudrate;
  25. } SeosUartConfig;
  26. struct SeosUart {
  27. SeosUartConfig cfg;
  28. SeosUartConfig cfg_new;
  29. FuriThread* thread;
  30. FuriThread* tx_thread;
  31. FuriStreamBuffer* rx_stream;
  32. FuriHalSerialHandle* serial_handle;
  33. FuriSemaphore* tx_sem;
  34. uint8_t rx_buf[SEOS_UART_RX_BUF_SIZE];
  35. uint8_t tx_buf[SEOS_UART_RX_BUF_SIZE];
  36. size_t tx_len;
  37. SeosUartReceiveCallback receive_callback;
  38. void* receive_callback_context;
  39. };
  40. typedef struct SeosUart SeosUart;