123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- #ifndef NRFX_UART_H__
- #define NRFX_UART_H__
- #include <nrfx.h>
- #include <hal/nrf_uart.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- typedef struct
- {
- NRF_UART_Type * p_reg;
- uint8_t drv_inst_idx;
- } nrfx_uart_t;
- #ifndef __NRFX_DOXYGEN__
- enum {
- #if NRFX_CHECK(NRFX_UART0_ENABLED)
- NRFX_UART0_INST_IDX,
- #endif
- NRFX_UART_ENABLED_COUNT
- };
- #endif
- #define NRFX_UART_INSTANCE(id) \
- { \
- .p_reg = NRFX_CONCAT_2(NRF_UART, id), \
- .drv_inst_idx = NRFX_CONCAT_3(NRFX_UART, id, _INST_IDX), \
- }
- typedef enum
- {
- NRFX_UART_EVT_TX_DONE,
- NRFX_UART_EVT_RX_DONE,
- NRFX_UART_EVT_ERROR,
- } nrfx_uart_evt_type_t;
- typedef struct
- {
- uint32_t pseltxd;
- uint32_t pselrxd;
- uint32_t pselcts;
- uint32_t pselrts;
- void * p_context;
- nrf_uart_hwfc_t hwfc;
- nrf_uart_parity_t parity;
- nrf_uart_baudrate_t baudrate;
- uint8_t interrupt_priority;
- } nrfx_uart_config_t;
- #define NRFX_UART_DEFAULT_CONFIG \
- { \
- .pseltxd = NRF_UART_PSEL_DISCONNECTED, \
- .pselrxd = NRF_UART_PSEL_DISCONNECTED, \
- .pselcts = NRF_UART_PSEL_DISCONNECTED, \
- .pselrts = NRF_UART_PSEL_DISCONNECTED, \
- .p_context = NULL, \
- .hwfc = (nrf_uart_hwfc_t)NRFX_UART_DEFAULT_CONFIG_HWFC, \
- .parity = (nrf_uart_parity_t)NRFX_UART_DEFAULT_CONFIG_PARITY, \
- .baudrate = (nrf_uart_baudrate_t)NRFX_UART_DEFAULT_CONFIG_BAUDRATE, \
- .interrupt_priority = NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY, \
- }
- typedef struct
- {
- uint8_t * p_data;
- uint32_t bytes;
- } nrfx_uart_xfer_evt_t;
- typedef struct
- {
- nrfx_uart_xfer_evt_t rxtx;
- uint32_t error_mask;
- } nrfx_uart_error_evt_t;
- typedef struct
- {
- nrfx_uart_evt_type_t type;
- union
- {
- nrfx_uart_xfer_evt_t rxtx;
- nrfx_uart_error_evt_t error;
- } data;
- } nrfx_uart_event_t;
- typedef void (*nrfx_uart_event_handler_t)(nrfx_uart_event_t const * p_event,
- void * p_context);
- nrfx_err_t nrfx_uart_init(nrfx_uart_t const * p_instance,
- nrfx_uart_config_t const * p_config,
- nrfx_uart_event_handler_t event_handler);
- void nrfx_uart_uninit(nrfx_uart_t const * p_instance);
- __STATIC_INLINE uint32_t nrfx_uart_task_address_get(nrfx_uart_t const * p_instance,
- nrf_uart_task_t task);
- __STATIC_INLINE uint32_t nrfx_uart_event_address_get(nrfx_uart_t const * p_instance,
- nrf_uart_event_t event);
- nrfx_err_t nrfx_uart_tx(nrfx_uart_t const * p_instance,
- uint8_t const * p_data,
- size_t length);
- bool nrfx_uart_tx_in_progress(nrfx_uart_t const * p_instance);
- void nrfx_uart_tx_abort(nrfx_uart_t const * p_instance);
- nrfx_err_t nrfx_uart_rx(nrfx_uart_t const * p_instance,
- uint8_t * p_data,
- size_t length);
- bool nrfx_uart_rx_ready(nrfx_uart_t const * p_instance);
- void nrfx_uart_rx_enable(nrfx_uart_t const * p_instance);
- void nrfx_uart_rx_disable(nrfx_uart_t const * p_instance);
- void nrfx_uart_rx_abort(nrfx_uart_t const * p_instance);
- uint32_t nrfx_uart_errorsrc_get(nrfx_uart_t const * p_instance);
- #ifndef SUPPRESS_INLINE_IMPLEMENTATION
- __STATIC_INLINE uint32_t nrfx_uart_task_address_get(nrfx_uart_t const * p_instance,
- nrf_uart_task_t task)
- {
- return nrf_uart_task_address_get(p_instance->p_reg, task);
- }
- __STATIC_INLINE uint32_t nrfx_uart_event_address_get(nrfx_uart_t const * p_instance,
- nrf_uart_event_t event)
- {
- return nrf_uart_event_address_get(p_instance->p_reg, event);
- }
- #endif
- void nrfx_uart_0_irq_handler(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|