1 /*
2  * Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *    list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  *    contributors may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef NRF_UART_H__
33 #define NRF_UART_H__
34 
35 #include <nrfx.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup nrf_uart_hal UART HAL
43  * @{
44  * @ingroup nrf_uart
45  * @brief   Hardware access layer for managing the UART peripheral.
46  */
47 
48 /** @brief Pin disconnected value. */
49 #define NRF_UART_PSEL_DISCONNECTED 0xFFFFFFFF
50 
51 /** @brief UART tasks. */
52 typedef enum
53 {
54     NRF_UART_TASK_STARTRX = offsetof(NRF_UART_Type, TASKS_STARTRX), /**< Task for starting reception. */
55     NRF_UART_TASK_STOPRX  = offsetof(NRF_UART_Type, TASKS_STOPRX),  /**< Task for stopping reception. */
56     NRF_UART_TASK_STARTTX = offsetof(NRF_UART_Type, TASKS_STARTTX), /**< Task for starting transmission. */
57     NRF_UART_TASK_STOPTX  = offsetof(NRF_UART_Type, TASKS_STOPTX),  /**< Task for stopping transmission. */
58     NRF_UART_TASK_SUSPEND = offsetof(NRF_UART_Type, TASKS_SUSPEND), /**< Task for suspending UART. */
59 } nrf_uart_task_t;
60 
61 /** @brief UART events. */
62 typedef enum
63 {
64     NRF_UART_EVENT_CTS    = offsetof(NRF_UART_Type, EVENTS_CTS),   /**< Event from CTS line activation. */
65     NRF_UART_EVENT_NCTS   = offsetof(NRF_UART_Type, EVENTS_NCTS),  /**< Event from CTS line deactivation. */
66     NRF_UART_EVENT_RXDRDY = offsetof(NRF_UART_Type, EVENTS_RXDRDY),/**< Event from data ready in RXD. */
67     NRF_UART_EVENT_TXDRDY = offsetof(NRF_UART_Type, EVENTS_TXDRDY),/**< Event from data sent from TXD. */
68     NRF_UART_EVENT_ERROR  = offsetof(NRF_UART_Type, EVENTS_ERROR), /**< Event from error detection. */
69     NRF_UART_EVENT_RXTO   = offsetof(NRF_UART_Type, EVENTS_RXTO)   /**< Event from receiver timeout. */
70 } nrf_uart_event_t;
71 
72 /** @brief UART interrupts. */
73 typedef enum
74 {
75     NRF_UART_INT_MASK_CTS    = UART_INTENCLR_CTS_Msk,    /**< CTS line activation interrupt. */
76     NRF_UART_INT_MASK_NCTS   = UART_INTENCLR_NCTS_Msk,   /**< CTS line deactivation interrupt. */
77     NRF_UART_INT_MASK_RXDRDY = UART_INTENCLR_RXDRDY_Msk, /**< Data ready in RXD interrupt. */
78     NRF_UART_INT_MASK_TXDRDY = UART_INTENCLR_TXDRDY_Msk, /**< Data sent from TXD interrupt. */
79     NRF_UART_INT_MASK_ERROR  = UART_INTENCLR_ERROR_Msk,  /**< Error detection interrupt. */
80     NRF_UART_INT_MASK_RXTO   = UART_INTENCLR_RXTO_Msk    /**< Receiver timeout interrupt. */
81 } nrf_uart_int_mask_t;
82 
83 /** @brief Baudrates supported by UART. */
84 typedef enum
85 {
86     NRF_UART_BAUDRATE_1200    = UART_BAUDRATE_BAUDRATE_Baud1200,   /**< 1200 baud. */
87     NRF_UART_BAUDRATE_2400    = UART_BAUDRATE_BAUDRATE_Baud2400,   /**< 2400 baud. */
88     NRF_UART_BAUDRATE_4800    = UART_BAUDRATE_BAUDRATE_Baud4800,   /**< 4800 baud. */
89     NRF_UART_BAUDRATE_9600    = UART_BAUDRATE_BAUDRATE_Baud9600,   /**< 9600 baud. */
90     NRF_UART_BAUDRATE_14400   = UART_BAUDRATE_BAUDRATE_Baud14400,  /**< 14400 baud. */
91     NRF_UART_BAUDRATE_19200   = UART_BAUDRATE_BAUDRATE_Baud19200,  /**< 19200 baud. */
92     NRF_UART_BAUDRATE_28800   = UART_BAUDRATE_BAUDRATE_Baud28800,  /**< 28800 baud. */
93     NRF_UART_BAUDRATE_31250   = UART_BAUDRATE_BAUDRATE_Baud31250,  /**< 31250 baud. */
94     NRF_UART_BAUDRATE_38400   = UART_BAUDRATE_BAUDRATE_Baud38400,  /**< 38400 baud. */
95     NRF_UART_BAUDRATE_56000   = UART_BAUDRATE_BAUDRATE_Baud56000,  /**< 56000 baud. */
96     NRF_UART_BAUDRATE_57600   = UART_BAUDRATE_BAUDRATE_Baud57600,  /**< 57600 baud. */
97     NRF_UART_BAUDRATE_76800   = UART_BAUDRATE_BAUDRATE_Baud76800,  /**< 76800 baud. */
98     NRF_UART_BAUDRATE_115200  = UART_BAUDRATE_BAUDRATE_Baud115200, /**< 115200 baud. */
99     NRF_UART_BAUDRATE_230400  = UART_BAUDRATE_BAUDRATE_Baud230400, /**< 230400 baud. */
100     NRF_UART_BAUDRATE_250000  = UART_BAUDRATE_BAUDRATE_Baud250000, /**< 250000 baud. */
101     NRF_UART_BAUDRATE_460800  = UART_BAUDRATE_BAUDRATE_Baud460800, /**< 460800 baud. */
102     NRF_UART_BAUDRATE_921600  = UART_BAUDRATE_BAUDRATE_Baud921600, /**< 921600 baud. */
103     NRF_UART_BAUDRATE_1000000 = UART_BAUDRATE_BAUDRATE_Baud1M,     /**< 1000000 baud. */
104 } nrf_uart_baudrate_t;
105 
106 /** @brief Types of UART error masks. */
107 typedef enum
108 {
109     NRF_UART_ERROR_OVERRUN_MASK = UART_ERRORSRC_OVERRUN_Msk,   /**< Overrun error. */
110     NRF_UART_ERROR_PARITY_MASK  = UART_ERRORSRC_PARITY_Msk,    /**< Parity error. */
111     NRF_UART_ERROR_FRAMING_MASK = UART_ERRORSRC_FRAMING_Msk,   /**< Framing error. */
112     NRF_UART_ERROR_BREAK_MASK   = UART_ERRORSRC_BREAK_Msk,     /**< Break error. */
113 } nrf_uart_error_mask_t;
114 
115 /** @brief Types of UART parity modes. */
116 typedef enum
117 {
118     NRF_UART_PARITY_EXCLUDED = UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos, /**< Parity excluded. */
119     NRF_UART_PARITY_INCLUDED = UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos, /**< Parity included. */
120 } nrf_uart_parity_t;
121 
122 /** @brief Types of UART flow control modes. */
123 typedef enum
124 {
125     NRF_UART_HWFC_DISABLED = UART_CONFIG_HWFC_Disabled, /**< Hardware flow control disabled. */
126     NRF_UART_HWFC_ENABLED  = UART_CONFIG_HWFC_Enabled,  /**< Hardware flow control enabled. */
127 } nrf_uart_hwfc_t;
128 
129 #if defined(UART_CONFIG_STOP_Msk) || defined(__NRFX_DOXYGEN__)
130 /** @brief Types of UART stop bit modes. */
131 typedef enum
132 {
133     NRF_UART_STOP_ONE = UART_CONFIG_STOP_One << UART_CONFIG_STOP_Pos, ///< One stop bit.
134     NRF_UART_STOP_TWO = UART_CONFIG_STOP_Two << UART_CONFIG_STOP_Pos  ///< Two stop bits.
135 } nrf_uart_stop_t;
136 #endif
137 
138 #if defined(UART_CONFIG_PARITYTYPE_Msk) || defined(__NRFX_DOXYGEN__)
139 /** @brief Types of UART parity types. */
140 typedef enum
141 {
142     NRF_UART_PARITYTYPE_EVEN = UART_CONFIG_PARITYTYPE_Even << UART_CONFIG_PARITYTYPE_Pos, /**< Parity even. */
143     NRF_UART_PARITYTYPE_ODD  = UART_CONFIG_PARITYTYPE_Odd << UART_CONFIG_PARITYTYPE_Pos,  /**< Parity odd. */
144 } nrf_uart_paritytype_t;
145 #endif
146 
147 /** @brief Structure for UART transmission configuration. */
148 typedef struct
149 {
150     nrf_uart_hwfc_t       hwfc;       ///< Flow control configuration.
151     nrf_uart_parity_t     parity;     ///< Parity configuration.
152 #if defined(UART_CONFIG_STOP_Msk) || defined(__NRFX_DOXYGEN__)
153     nrf_uart_stop_t       stop;       ///< Stop bits.
154 #endif
155 #if defined(UART_CONFIG_PARITYTYPE_Msk) || defined(__NRFX_DOXYGEN__)
156     nrf_uart_paritytype_t paritytype; ///< Parity type.
157 #endif
158 } nrf_uart_config_t;
159 
160 /**
161  * @brief Function for clearing the specified UART event.
162  *
163  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
164  * @param[in] event Event to clear.
165  */
166 NRF_STATIC_INLINE void nrf_uart_event_clear(NRF_UART_Type * p_reg, nrf_uart_event_t event);
167 
168 /**
169  * @brief Function for retrieving the state of the UART event.
170  *
171  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
172  * @param[in] event Event to be checked.
173  *
174  * @retval true  The event has been generated.
175  * @retval false The event has not been generated.
176  */
177 NRF_STATIC_INLINE bool nrf_uart_event_check(NRF_UART_Type const * p_reg, nrf_uart_event_t event);
178 
179 /**
180  * @brief Function for returning the address of the specified UART event register.
181  *
182  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
183  * @param[in] event Desired event.
184  *
185  * @return Address of the specified event register.
186  */
187 NRF_STATIC_INLINE uint32_t nrf_uart_event_address_get(NRF_UART_Type const * p_reg,
188                                                       nrf_uart_event_t      event);
189 
190 /**
191  * @brief Function for enabling the specified interrupt.
192  *
193  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
194  * @param[in] mask  Mask of interrupts to be enabled.
195  */
196 NRF_STATIC_INLINE void nrf_uart_int_enable(NRF_UART_Type * p_reg, uint32_t mask);
197 
198 /**
199  * @brief Function for checking if the specified interrupts are enabled.
200  *
201  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
202  * @param[in] mask  Mask of interrupts to be checked.
203  *
204  * @return Mask of enabled interrupts.
205  */
206 NRF_STATIC_INLINE uint32_t nrf_uart_int_enable_check(NRF_UART_Type const * p_reg, uint32_t mask);
207 
208 /**
209  * @brief Function for disabling the specified interrupts.
210  *
211  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
212  * @param[in] mask  Mask of interrupts to be disabled.
213  */
214 NRF_STATIC_INLINE void nrf_uart_int_disable(NRF_UART_Type * p_reg, uint32_t mask);
215 
216 /**
217  * @brief Function for getting error source mask. Function is clearing error source flags after reading.
218  *
219  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
220  *
221  * @return Mask with error source flags.
222  */
223 NRF_STATIC_INLINE uint32_t nrf_uart_errorsrc_get_and_clear(NRF_UART_Type * p_reg);
224 
225 /**
226  * @brief Function for enabling UART.
227  *
228  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
229  */
230 NRF_STATIC_INLINE void nrf_uart_enable(NRF_UART_Type * p_reg);
231 
232 /**
233  * @brief Function for disabling UART.
234  *
235  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
236  */
237 NRF_STATIC_INLINE void nrf_uart_disable(NRF_UART_Type * p_reg);
238 
239 /**
240  * @brief Function for configuring TX/RX pins.
241  *
242  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
243  * @param[in] pseltxd TXD pin number.
244  * @param[in] pselrxd RXD pin number.
245  */
246 NRF_STATIC_INLINE void nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg,
247                                               uint32_t        pseltxd,
248                                               uint32_t        pselrxd);
249 
250 /**
251  * @brief Function for disconnecting TX/RX pins.
252  *
253  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
254  */
255 NRF_STATIC_INLINE void nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg);
256 
257 /**
258  * @brief Function for getting TX pin selection.
259  *
260  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
261  *
262  * @return TX pin selection.
263  */
264 NRF_STATIC_INLINE uint32_t nrf_uart_tx_pin_get(NRF_UART_Type const * p_reg);
265 
266 /**
267  * @brief Function for getting RX pin selection.
268  *
269  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
270  *
271  * @return RX pin selection.
272  */
273 NRF_STATIC_INLINE uint32_t nrf_uart_rx_pin_get(NRF_UART_Type const * p_reg);
274 
275 /**
276  * @brief Function for getting RTS pin selection.
277  *
278  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
279  *
280  * @return RTS pin selection.
281  */
282 NRF_STATIC_INLINE uint32_t nrf_uart_rts_pin_get(NRF_UART_Type const * p_reg);
283 
284 /**
285  * @brief Function for getting CTS pin selection.
286  *
287  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
288  *
289  * @return CTS pin selection.
290  */
291 NRF_STATIC_INLINE uint32_t nrf_uart_cts_pin_get(NRF_UART_Type const * p_reg);
292 
293 /**
294  * @brief Function for configuring flow control pins.
295  *
296  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
297  * @param[in] pselrts RTS pin number.
298  * @param[in] pselcts CTS pin number.
299  */
300 NRF_STATIC_INLINE void nrf_uart_hwfc_pins_set(NRF_UART_Type * p_reg,
301                                               uint32_t        pselrts,
302                                               uint32_t        pselcts);
303 
304 /**
305  * @brief Function for disconnecting flow control pins.
306  *
307  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
308  */
309 NRF_STATIC_INLINE void nrf_uart_hwfc_pins_disconnect(NRF_UART_Type * p_reg);
310 
311 /**
312  * @brief Function for reading RX data.
313  *
314  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
315  *
316  * @return Received byte.
317  */
318 NRF_STATIC_INLINE uint8_t nrf_uart_rxd_get(NRF_UART_Type const * p_reg);
319 
320 /**
321  * @brief Function for setting Tx data.
322  *
323  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
324  * @param[in] txd   Byte.
325  */
326 NRF_STATIC_INLINE void nrf_uart_txd_set(NRF_UART_Type * p_reg, uint8_t txd);
327 
328 /**
329  * @brief Function for starting an UART task.
330  *
331  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
332  * @param[in] task  Task.
333  */
334 NRF_STATIC_INLINE void nrf_uart_task_trigger(NRF_UART_Type * p_reg, nrf_uart_task_t task);
335 
336 /**
337  * @brief Function for returning the address of the specified task register.
338  *
339  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
340  * @param[in] task  Task.
341  *
342  * @return Task address.
343  */
344 NRF_STATIC_INLINE uint32_t nrf_uart_task_address_get(NRF_UART_Type const * p_reg,
345                                                      nrf_uart_task_t       task);
346 
347 /**
348  * @brief Function for configuring UART.
349  *
350  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
351  * @param[in] p_cfg Pointer to UART settings structure.
352  */
353 NRF_STATIC_INLINE void nrf_uart_configure(NRF_UART_Type           * p_reg,
354                                           nrf_uart_config_t const * p_cfg);
355 
356 /**
357  * @brief Function for setting UART baud rate.
358  *
359  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
360  * @param[in] baudrate Baud rate.
361  */
362 NRF_STATIC_INLINE void nrf_uart_baudrate_set(NRF_UART_Type * p_reg, nrf_uart_baudrate_t baudrate);
363 
364 
365 #ifndef NRF_DECLARE_ONLY
366 
nrf_uart_event_clear(NRF_UART_Type * p_reg,nrf_uart_event_t event)367 NRF_STATIC_INLINE void nrf_uart_event_clear(NRF_UART_Type * p_reg, nrf_uart_event_t event)
368 {
369     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
370     nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
371 }
372 
nrf_uart_event_check(NRF_UART_Type const * p_reg,nrf_uart_event_t event)373 NRF_STATIC_INLINE bool nrf_uart_event_check(NRF_UART_Type const * p_reg, nrf_uart_event_t event)
374 {
375     return (bool)*(volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event);
376 }
377 
nrf_uart_event_address_get(NRF_UART_Type const * p_reg,nrf_uart_event_t event)378 NRF_STATIC_INLINE uint32_t nrf_uart_event_address_get(NRF_UART_Type const * p_reg,
379                                                       nrf_uart_event_t      event)
380 {
381     return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
382 }
383 
nrf_uart_int_enable(NRF_UART_Type * p_reg,uint32_t mask)384 NRF_STATIC_INLINE void nrf_uart_int_enable(NRF_UART_Type * p_reg, uint32_t mask)
385 {
386     p_reg->INTENSET = mask;
387 }
388 
nrf_uart_int_enable_check(NRF_UART_Type const * p_reg,uint32_t mask)389 NRF_STATIC_INLINE uint32_t nrf_uart_int_enable_check(NRF_UART_Type const * p_reg, uint32_t mask)
390 {
391     return p_reg->INTENSET & mask;
392 }
393 
nrf_uart_int_disable(NRF_UART_Type * p_reg,uint32_t mask)394 NRF_STATIC_INLINE void nrf_uart_int_disable(NRF_UART_Type * p_reg, uint32_t mask)
395 {
396     p_reg->INTENCLR = mask;
397 }
398 
nrf_uart_errorsrc_get_and_clear(NRF_UART_Type * p_reg)399 NRF_STATIC_INLINE uint32_t nrf_uart_errorsrc_get_and_clear(NRF_UART_Type * p_reg)
400 {
401     uint32_t errsrc_mask = p_reg->ERRORSRC;
402     p_reg->ERRORSRC = errsrc_mask;
403     return errsrc_mask;
404 }
405 
nrf_uart_enable(NRF_UART_Type * p_reg)406 NRF_STATIC_INLINE void nrf_uart_enable(NRF_UART_Type * p_reg)
407 {
408     p_reg->ENABLE = UART_ENABLE_ENABLE_Enabled;
409 }
410 
nrf_uart_disable(NRF_UART_Type * p_reg)411 NRF_STATIC_INLINE void nrf_uart_disable(NRF_UART_Type * p_reg)
412 {
413     p_reg->ENABLE = UART_ENABLE_ENABLE_Disabled;
414 }
415 
nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg,uint32_t pseltxd,uint32_t pselrxd)416 NRF_STATIC_INLINE void nrf_uart_txrx_pins_set(NRF_UART_Type * p_reg,
417                                               uint32_t        pseltxd,
418                                               uint32_t        pselrxd)
419 {
420 #if defined(UART_PSEL_RXD_CONNECT_Pos)
421     p_reg->PSEL.RXD = pselrxd;
422 #else
423     p_reg->PSELRXD = pselrxd;
424 #endif
425 #if defined(UART_PSEL_TXD_CONNECT_Pos)
426     p_reg->PSEL.TXD = pseltxd;
427 #else
428     p_reg->PSELTXD = pseltxd;
429 #endif
430 }
431 
nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg)432 NRF_STATIC_INLINE void nrf_uart_txrx_pins_disconnect(NRF_UART_Type * p_reg)
433 {
434     nrf_uart_txrx_pins_set(p_reg, NRF_UART_PSEL_DISCONNECTED, NRF_UART_PSEL_DISCONNECTED);
435 }
436 
nrf_uart_tx_pin_get(NRF_UART_Type const * p_reg)437 NRF_STATIC_INLINE uint32_t nrf_uart_tx_pin_get(NRF_UART_Type const * p_reg)
438 {
439 #if defined(UART_PSEL_TXD_CONNECT_Pos)
440     return p_reg->PSEL.TXD;
441 #else
442     return p_reg->PSELTXD;
443 #endif
444 }
445 
nrf_uart_rx_pin_get(NRF_UART_Type const * p_reg)446 NRF_STATIC_INLINE uint32_t nrf_uart_rx_pin_get(NRF_UART_Type const * p_reg)
447 {
448 #if defined(UART_PSEL_RXD_CONNECT_Pos)
449     return p_reg->PSEL.RXD;
450 #else
451     return p_reg->PSELRXD;
452 #endif
453 }
454 
nrf_uart_rts_pin_get(NRF_UART_Type const * p_reg)455 NRF_STATIC_INLINE uint32_t nrf_uart_rts_pin_get(NRF_UART_Type const * p_reg)
456 {
457 #if defined(UART_PSEL_RTS_CONNECT_Pos)
458     return p_reg->PSEL.RTS;
459 #else
460     return p_reg->PSELRTS;
461 #endif
462 }
463 
nrf_uart_cts_pin_get(NRF_UART_Type const * p_reg)464 NRF_STATIC_INLINE uint32_t nrf_uart_cts_pin_get(NRF_UART_Type const * p_reg)
465 {
466 #if defined(UART_PSEL_RTS_CONNECT_Pos)
467     return p_reg->PSEL.CTS;
468 #else
469     return p_reg->PSELCTS;
470 #endif
471 }
472 
nrf_uart_hwfc_pins_set(NRF_UART_Type * p_reg,uint32_t pselrts,uint32_t pselcts)473 NRF_STATIC_INLINE void nrf_uart_hwfc_pins_set(NRF_UART_Type * p_reg,
474                                               uint32_t        pselrts,
475                                               uint32_t        pselcts)
476 {
477 #if defined(UART_PSEL_RTS_CONNECT_Pos)
478     p_reg->PSEL.RTS = pselrts;
479 #else
480     p_reg->PSELRTS = pselrts;
481 #endif
482 
483 #if defined(UART_PSEL_RTS_CONNECT_Pos)
484     p_reg->PSEL.CTS = pselcts;
485 #else
486     p_reg->PSELCTS = pselcts;
487 #endif
488 }
489 
nrf_uart_hwfc_pins_disconnect(NRF_UART_Type * p_reg)490 NRF_STATIC_INLINE void nrf_uart_hwfc_pins_disconnect(NRF_UART_Type * p_reg)
491 {
492     nrf_uart_hwfc_pins_set(p_reg, NRF_UART_PSEL_DISCONNECTED, NRF_UART_PSEL_DISCONNECTED);
493 }
494 
nrf_uart_rxd_get(NRF_UART_Type const * p_reg)495 NRF_STATIC_INLINE uint8_t nrf_uart_rxd_get(NRF_UART_Type const * p_reg)
496 {
497     return p_reg->RXD;
498 }
499 
nrf_uart_txd_set(NRF_UART_Type * p_reg,uint8_t txd)500 NRF_STATIC_INLINE void nrf_uart_txd_set(NRF_UART_Type * p_reg, uint8_t txd)
501 {
502     p_reg->TXD = txd;
503 }
504 
nrf_uart_task_trigger(NRF_UART_Type * p_reg,nrf_uart_task_t task)505 NRF_STATIC_INLINE void nrf_uart_task_trigger(NRF_UART_Type * p_reg, nrf_uart_task_t task)
506 {
507     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
508 }
509 
nrf_uart_task_address_get(NRF_UART_Type const * p_reg,nrf_uart_task_t task)510 NRF_STATIC_INLINE uint32_t nrf_uart_task_address_get(NRF_UART_Type const * p_reg,
511                                                      nrf_uart_task_t       task)
512 {
513     return (uint32_t)p_reg + (uint32_t)task;
514 }
515 
nrf_uart_configure(NRF_UART_Type * p_reg,nrf_uart_config_t const * p_cfg)516 NRF_STATIC_INLINE void nrf_uart_configure(NRF_UART_Type           * p_reg,
517                                           nrf_uart_config_t const * p_cfg)
518 {
519     p_reg->CONFIG = (uint32_t)p_cfg->parity
520 #if defined(UART_CONFIG_STOP_Msk)
521                     | (uint32_t)p_cfg->stop
522 #endif
523 #if defined(UART_CONFIG_PARITYTYPE_Msk)
524                     | (uint32_t)p_cfg->paritytype
525 #endif
526                     | (uint32_t)p_cfg->hwfc;
527 }
528 
nrf_uart_baudrate_set(NRF_UART_Type * p_reg,nrf_uart_baudrate_t baudrate)529 NRF_STATIC_INLINE void nrf_uart_baudrate_set(NRF_UART_Type * p_reg, nrf_uart_baudrate_t baudrate)
530 {
531     p_reg->BAUDRATE = baudrate;
532 }
533 #endif // NRF_DECLARE_ONLY
534 
535 /** @} */
536 
537 #ifdef __cplusplus
538 }
539 #endif
540 
541 #endif // NRF_UART_H__
542