123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- extern "C" {
- typedef enum
- {
- APP_UART_FLOW_CONTROL_DISABLED,
- APP_UART_FLOW_CONTROL_ENABLED,
- } app_uart_flow_control_t;
- typedef struct
- {
- uint32_t rx_pin_no;
- uint32_t tx_pin_no;
- uint32_t rts_pin_no;
- uint32_t cts_pin_no;
- app_uart_flow_control_t flow_control;
- bool use_parity;
- uint32_t baud_rate;
- } app_uart_comm_params_t;
- typedef struct
- {
- uint8_t * rx_buf;
- uint32_t rx_buf_size;
- uint8_t * tx_buf;
- uint32_t tx_buf_size;
- } app_uart_buffers_t;
- typedef enum
- {
- APP_UART_DATA_READY,
- APP_UART_FIFO_ERROR,
- APP_UART_COMMUNICATION_ERROR,
- APP_UART_TX_EMPTY,
- APP_UART_DATA,
- } app_uart_evt_type_t;
- typedef struct
- {
- app_uart_evt_type_t evt_type;
- union
- {
- uint32_t error_communication;
- uint32_t error_code;
- uint8_t value;
- } data;
- } app_uart_evt_t;
- typedef void (* app_uart_event_handler_t) (app_uart_evt_t * p_app_uart_event);
- do \
- { \
- app_uart_buffers_t buffers; \
- static uint8_t rx_buf[RX_BUF_SIZE]; \
- static uint8_t tx_buf[TX_BUF_SIZE]; \
- \
- buffers.rx_buf = rx_buf; \
- buffers.rx_buf_size = sizeof (rx_buf); \
- buffers.tx_buf = tx_buf; \
- buffers.tx_buf_size = sizeof (tx_buf); \
- ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO); \
- } while (0)
- do \
- { \
- ERR_CODE = app_uart_init(P_COMM_PARAMS, NULL, EVT_HANDLER, IRQ_PRIO); \
- } while (0)
- uint32_t app_uart_init(const app_uart_comm_params_t * p_comm_params,
- app_uart_buffers_t * p_buffers,
- app_uart_event_handler_t error_handler,
- app_irq_priority_t irq_priority);
- uint32_t app_uart_get(uint8_t * p_byte);
- uint32_t app_uart_put(uint8_t byte);
- uint32_t app_uart_flush(void);
- uint32_t app_uart_close(void);
- }
|