VT Library  0.2
C:/Users/joni/Code/projects/nrf_vt/nrf_vt/nrf_vt_uart_frontend.h
1 
48 #ifndef NRF_VT_UART_H__
49 #define NRF_VT_UART_H__
50 
51 #include <nrfx.h>
52 #include <hal/nrf_uart.h>
53 
54 #ifndef NRF_VT_REPLACE_NRFX_DRIVER
55 #define NRF_VT_REPLACE_NRFX_DRIVER 1
56 #endif
57 
58 #if NRF_VT_REPLACE_NRFX_DRIVER
59 #include "nrfx_uart.h"
60 #include "nrfx_uarte.h"
61 
62 #define nrf_vt_uart_t nrfx_uart_t
63 
64 #define NRF_VT_UART_EVT_TX_DONE NRFX_UART_EVT_TX_DONE
65 #define NRF_VT_UART_EVT_RX_DONE NRFX_UART_EVT_RX_DONE
66 #define NRF_VT_UART_EVT_ERROR NRFX_UART_EVT_ERROR
67 
68 #define nrf_vt_uart_evt_type_t nrfx_uart_evt_type_t
69 #define nrf_vt_uart_config_t nrfx_uart_config_t
70 #define nrf_vt_uart_xfer_evt_t nrfx_uart_xfer_evt_t
71 #define nrf_vt_uart_error_evt_t nrfx_uart_error_evt_t
72 #define nrf_vt_uart_event_t nrfx_uart_event_t
73 #define nrf_vt_uart_event_handler_t nrfx_uart_event_handler_t
74 
75 #define nrf_vt_uart_init nrfx_uart_init
76 #define nrf_vt_uart_uninit nrfx_uart_uninit
77 #define nrf_vt_uart_tx nrfx_uart_tx
78 #define nrf_vt_uart_tx_in_progress nrfx_uart_tx_in_progress
79 #define nrf_vt_uart_tx_abort nrfx_uart_tx_abort
80 #define nrf_vt_uart_rx nrfx_uart_rx
81 #define nrf_vt_uart_rx_ready nrfx_uart_rx_ready
82 #define nrf_vt_uart_rx_enable nrfx_uart_rx_enable
83 #define nrf_vt_uart_rx_disable nrfx_uart_rx_disable
84 #define nrf_vt_uart_rx_abort nrfx_uart_rx_abort
85 #define nrf_vt_uart_errorsrc_get nrfx_uart_errorsrc_get
86 
87 #else
88 
95 /*
96  THE BELOW DEFINITIONS HAVE BEEN COPIED FROM nrfx_uart.h AND NAMES HAVE BEEN ALTERED
97 */
98 
102 typedef struct
103 {
104  NRF_UART_Type * p_reg;
105  uint8_t drv_inst_idx;
106 } nrf_vt_uart_t;
107 
111 typedef enum
112 {
113  NRF_VT_UART_EVT_TX_DONE,
114  NRF_VT_UART_EVT_RX_DONE,
115  NRF_VT_UART_EVT_ERROR,
116 } nrf_vt_uart_evt_type_t;
117 
121 typedef struct
122 {
123  uint32_t pseltxd;
124  uint32_t pselrxd;
125  uint32_t pselcts;
126  uint32_t pselrts;
127  void * p_context;
128  nrf_uart_hwfc_t hwfc;
129  nrf_uart_parity_t parity;
130  uint32_t baudrate;// nrf_uart_baudrate_t baudrate; ///< Baudrate.
131  uint8_t interrupt_priority;
132 } nrf_vt_uart_config_t;
133 
137 #define NRF_VT_UART_DEFAULT_CONFIG \
138 { \
139  .pseltxd = NRF_UART_PSEL_DISCONNECTED, \
140  .pselrxd = NRF_UART_PSEL_DISCONNECTED, \
141  .pselcts = NRF_UART_PSEL_DISCONNECTED, \
142  .pselrts = NRF_UART_PSEL_DISCONNECTED, \
143  .p_context = NULL, \
144  .hwfc = (nrf_uart_hwfc_t)NRFX_UART_DEFAULT_CONFIG_HWFC, \
145  .parity = (nrf_uart_parity_t)NRFX_UART_DEFAULT_CONFIG_PARITY, \
146  .baudrate = (nrf_uart_baudrate_t)NRFX_UART_DEFAULT_CONFIG_BAUDRATE, \
147  .interrupt_priority = NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY, \
148 }
149 
153 typedef struct
154 {
155  uint8_t * p_data;
156  uint32_t bytes;
157 } nrf_vt_uart_xfer_evt_t;
158 
162 typedef struct
163 {
164  nrf_vt_uart_xfer_evt_t rxtx;
165  uint32_t error_mask;
166 } nrf_vt_uart_error_evt_t;
167 
171 typedef struct
172 {
173  nrf_vt_uart_evt_type_t type;
174  union
175  {
176  nrf_vt_uart_xfer_evt_t rxtx;
177  nrf_vt_uart_error_evt_t error;
178  } data;
179 } nrf_vt_uart_event_t;
180 
188 typedef void (*nrf_vt_uart_event_handler_t)(nrf_vt_uart_event_t const * p_event,
189  void * p_context);
190 
208 nrfx_err_t nrf_vt_uart_init(nrf_vt_uart_t const * p_instance,
209  nrf_vt_uart_config_t const * p_config,
210  nrf_vt_uart_event_handler_t event_handler);
211 
216 void nrf_vt_uart_uninit(nrf_vt_uart_t const * p_instance);
217 
236 nrfx_err_t nrf_vt_uart_tx(nrf_vt_uart_t const * p_instance,
237  uint8_t const * p_data,
238  size_t length);
239 
248 bool nrf_vt_uart_tx_in_progress(nrf_vt_uart_t const * p_instance);
249 
258 void nrf_vt_uart_tx_abort(nrf_vt_uart_t const * p_instance);
259 
285 nrfx_err_t nrf_vt_uart_rx(nrf_vt_uart_t const * p_instance,
286  uint8_t * p_data,
287  size_t length);
288 
289 
290 
299 bool nrf_vt_uart_rx_ready(nrf_vt_uart_t const * p_instance);
300 
310 void nrf_vt_uart_rx_enable(nrf_vt_uart_t const * p_instance);
311 
320 void nrf_vt_uart_rx_disable(nrf_vt_uart_t const * p_instance);
321 
330 void nrf_vt_uart_rx_abort(nrf_vt_uart_t const * p_instance);
331 
341 uint32_t nrf_vt_uart_errorsrc_get(nrf_vt_uart_t const * p_instance);
342 
343 #endif // NRF_VT_REPLACE_NRFX_DRIVER
344 
347 #endif // NRF_VT_UART_H__