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