1 /*
2  * Copyright (c) 2018 - 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_NFCT_H__
35 #define NRF_NFCT_H__
36 
37 #include <nrfx.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * @defgroup nrf_nfct_hal NFCT HAL
45  * @{
46  * @ingroup nrf_nfct
47  *
48  * @brief Hardware access layer (HAL) for the Near Field Communication Tag (NFCT) peripheral.
49  */
50 
51 #define NRF_NFCT_CRC_SIZE 2                 /**< CRC size in bytes. */
52 #define NRF_NFCT_DISABLE_ALL_INT 0xFFFFFFFF /**< Value to disable all interrupts. */
53 
54 /**
55  * @brief This value can be used as a parameter for the @ref nrf_nfct_mod_ctrl_pin_set
56  *        function to specify that a given NFCT signal (MODULATION CONTROL)
57  *        must not be connected to a physical pin.
58  */
59 #define NRF_NFCT_MOD_CTRL_PIN_NOT_CONNECTED  0xFFFFFFFF
60 
61 /** @brief Maximum possible value of NFCT max frame delay. */
62 #define NRF_NFCT_FRAME_DELAY_MAX_MAX_VALUE  NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk
63 
64 #if defined(NFCT_NFCID1_THIRDLAST_S_Pos) || defined(__NRFX_DOXYGEN__)
65 /** @brief Symbol indicating whether NFCID1 register uses new layout. */
66 #define NRF_NFCID1_HAS_NEW_LAYOUT 1
67 #else
68 #define NRF_NFCID1_HAS_NEW_LAYOUT 0
69 #endif
70 
71 #if defined(NFCT_TASKS_STOPTX_TASKS_STOPTX_Msk) || defined(__NRFX_DOXYGEN__)
72 /** @brief Symbol indicating whether NFCT STOPTX event is present. */
73 #define NRF_NFCT_HAS_STOPTX_TASK 1
74 #else
75 #define NRF_NFCT_HAS_STOPTX_TASK 0
76 #endif
77 
78 #if defined(NFCT_MODULATIONPSEL_PIN_Msk) || defined(__NRFX_DOXYGEN__)
79 /** @brief Symbol indicating whether pin select for modulation control register is present. */
80 #define NRF_NFCT_HAS_MODULATION_PSEL_REG 1
81 #else
82 #define NRF_NFCT_HAS_MODULATION_PSEL_REG 0
83 #endif
84 
85 #if defined(NFCT_MODULATIONCTRL_MODULATIONCTRL_Msk) || defined(__NRFX_DOXYGEN__)
86 /** @brief Symbol indicating whether modulation output select register is present. */
87 #define NRF_NFCT_HAS_MODULATION_CTRL_REG 1
88 #else
89 #define NRF_NFCT_HAS_MODULATION_CTRL_REG 0
90 #endif
91 
92 #if defined(NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) || defined(__NRFX_DOXYGEN__)
93 /** @brief Symbol indicating whether current operating state of NFC tag register is present. */
94 #define NRF_NFCT_HAS_TAG_STATE_REG 1
95 #else
96 #define NRF_NFCT_HAS_TAG_STATE_REG 0
97 #endif
98 
99 #if defined(NFCT_SLEEPSTATE_SLEEPSTATE_Msk) || defined(__NRFX_DOXYGEN__)
100 /** @brief Symbol indicating whether sleep state during automatic collision resolution is present. */
101 #define NRF_NFCT_HAS_SLEEP_STATE_REG 1
102 #else
103 #define NRF_NFCT_HAS_SLEEP_STATE_REG 0
104 #endif
105 
106 #if defined (NFCT_AUTOCOLRESCONFIG_MODE_Msk) || defined(__NRFX_DOXYGEN__)
107 /** @brief Symbol indicating whether automatic collision resolution control register is present. */
108 #define NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG 1
109 #else
110 #define NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG 0
111 #endif
112 
113 #if defined(NFCT_PADCONFIG_ENABLE_Msk) || defined(__NRFX_DOXYGEN__)
114 /** @brief Symbol indicating whether NFC pad configuration register is present. */
115 #define NRF_NFCT_HAS_PAD_CONFIG_REG 1
116 #else
117 #define NRF_NFCT_HAS_PAD_CONFIG_REG 0
118 #endif
119 
120 #if defined(NFCT_BIASCFG_TRIMIBPSR_Msk) || defined(NFCT_BIASCFG_COARSEIBPSR_Msk) ||  \
121     defined(NFCT_BIASCFG_REFERENCEVOLTAGE_Msk) || defined(NFCT_BIASCFG_SPARE_Msk) || \
122     defined(__NRFX_DOXYGEN__)
123 /** @brief Symbol indicating whether NFC bias configuration trim register is present. */
124 #define NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG 1
125 #else
126 #define NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG 0
127 #endif
128 /** @brief NFCT tasks. */
129 typedef enum
130 {
131     NRF_NFCT_TASK_ACTIVATE     = offsetof(NRF_NFCT_Type, TASKS_ACTIVATE),     /**< Activate the NFCT peripheral for the incoming and outgoing frames, change state to activated. */
132     NRF_NFCT_TASK_DISABLE      = offsetof(NRF_NFCT_Type, TASKS_DISABLE),      /**< Disable the NFCT peripheral. */
133     NRF_NFCT_TASK_SENSE        = offsetof(NRF_NFCT_Type, TASKS_SENSE),        /**< Enable the NFC sense field mode, change state to sense mode. */
134     NRF_NFCT_TASK_STARTTX      = offsetof(NRF_NFCT_Type, TASKS_STARTTX),      /**< Start the transmission of an outgoing frame, change state to transmit. */
135 #if NRF_NFCT_HAS_STOPTX_TASK
136     NRF_NFCT_TASK_STOPTX       = offsetof(NRF_NFCT_Type, TASKS_STOPTX),       /**< Stop an issued transmission of a frame. */
137 #endif
138     NRF_NFCT_TASK_ENABLERXDATA = offsetof(NRF_NFCT_Type, TASKS_ENABLERXDATA), /**< Initialize EasyDMA for receive. */
139     NRF_NFCT_TASK_GOIDLE       = offsetof(NRF_NFCT_Type, TASKS_GOIDLE),       /**< Force state machine to the IDLE state. */
140     NRF_NFCT_TASK_GOSLEEP      = offsetof(NRF_NFCT_Type, TASKS_GOSLEEP),      /**< Force state machine to the SLEEP_A state. */
141 } nrf_nfct_task_t;
142 
143 /** @brief NFCT events. */
144 typedef enum
145 {
146     NRF_NFCT_EVENT_READY             = offsetof(NRF_NFCT_Type, EVENTS_READY),             /**< The NFCT peripheral is ready to receive and send frames. */
147     NRF_NFCT_EVENT_FIELDDETECTED     = offsetof(NRF_NFCT_Type, EVENTS_FIELDDETECTED),     /**< Remote NFC field is detected. */
148     NRF_NFCT_EVENT_FIELDLOST         = offsetof(NRF_NFCT_Type, EVENTS_FIELDLOST),         /**< Remote NFC field is lost. */
149     NRF_NFCT_EVENT_TXFRAMESTART      = offsetof(NRF_NFCT_Type, EVENTS_TXFRAMESTART),      /**< The start of the first symbol of a transmitted frame. */
150     NRF_NFCT_EVENT_TXFRAMEEND        = offsetof(NRF_NFCT_Type, EVENTS_TXFRAMEEND),        /**< The end of the last transmitted on-air symbol of a frame. */
151     NRF_NFCT_EVENT_RXFRAMESTART      = offsetof(NRF_NFCT_Type, EVENTS_RXFRAMESTART),      /**< The end of the first symbol of a received frame. */
152     NRF_NFCT_EVENT_RXFRAMEEND        = offsetof(NRF_NFCT_Type, EVENTS_RXFRAMEEND),        /**< Received data was checked (CRC, parity) and transferred to RAM, and EasyDMA ended accessing the RX buffer. */
153     NRF_NFCT_EVENT_ERROR             = offsetof(NRF_NFCT_Type, EVENTS_ERROR),             /**< NFC error reported. The ERRORSTATUS register contains details on the source of the error. */
154     NRF_NFCT_EVENT_RXERROR           = offsetof(NRF_NFCT_Type, EVENTS_RXERROR),           /**< NFC RX frame error reported. The FRAMESTATUS.RX register contains details on the source of the error. */
155     NRF_NFCT_EVENT_ENDRX             = offsetof(NRF_NFCT_Type, EVENTS_ENDRX),             /**< RX buffer (as defined by PACKETPTR and MAXLEN) in Data RAM full. */
156     NRF_NFCT_EVENT_ENDTX             = offsetof(NRF_NFCT_Type, EVENTS_ENDTX),             /**< Transmission of data in RAM ended, and EasyDMA ended accessing the TX buffer. */
157     NRF_NFCT_EVENT_AUTOCOLRESSTARTED = offsetof(NRF_NFCT_Type, EVENTS_AUTOCOLRESSTARTED), /**< Auto collision resolution process started. */
158     NRF_NFCT_EVENT_COLLISION         = offsetof(NRF_NFCT_Type, EVENTS_COLLISION),         /**< NFC auto collision resolution error reported. */
159     NRF_NFCT_EVENT_SELECTED          = offsetof(NRF_NFCT_Type, EVENTS_SELECTED),          /**< NFC auto collision resolution successfully completed. */
160     NRF_NFCT_EVENT_STARTED           = offsetof(NRF_NFCT_Type, EVENTS_STARTED),           /**< EasyDMA is ready to receive or send frames. */
161 } nrf_nfct_event_t;
162 
163 /** @brief NFCT shortcuts. */
164 typedef enum
165 {
166     NRF_NFCT_SHORT_FIELDDETECTED_ACTIVATE_MASK  = NFCT_SHORTS_FIELDDETECTED_ACTIVATE_Msk,  /**< Shortcut between the FIELDDETECTED event and the ACTIVATE task. */
167     NRF_NFCT_SHORT_FIELDLOST_SENSE_MASK         = NFCT_SHORTS_FIELDLOST_SENSE_Msk,         /**< Shortcut between the FIELDLOST event and the SENSE task. */
168 #if defined(NFCT_SHORTS_TXFRAMEEND_ENABLERXDATA_Msk) || defined(__NRFX_DOXYGEN__)
169     NRF_NFCT_SHORT_TXFRAMEEND_ENABLERXDATA_MASK = NFCT_SHORTS_TXFRAMEEND_ENABLERXDATA_Msk, /**< Shortcut between the TXFRAMEEND event and the ENABLERXDATA task. */
170 #endif
171 } nrf_nfct_short_mask_t;
172 
173 /** @brief NFCT interrupts. */
174 typedef enum
175 {
176     NRF_NFCT_INT_READY_MASK             = NFCT_INTEN_READY_Msk,             /**< Interrupt on READY event. */
177     NRF_NFCT_INT_FIELDDETECTED_MASK     = NFCT_INTEN_FIELDDETECTED_Msk,     /**< Interrupt on FIELDDETECTED event. */
178     NRF_NFCT_INT_FIELDLOST_MASK         = NFCT_INTEN_FIELDLOST_Msk,         /**< Interrupt on FIELDLOST event. */
179     NRF_NFCT_INT_TXFRAMESTART_MASK      = NFCT_INTEN_TXFRAMESTART_Msk,      /**< Interrupt on TXFRAMESTART event. */
180     NRF_NFCT_INT_TXFRAMEEND_MASK        = NFCT_INTEN_TXFRAMEEND_Msk,        /**< Interrupt on TXFRAMEEND event. */
181     NRF_NFCT_INT_RXFRAMESTART_MASK      = NFCT_INTEN_RXFRAMESTART_Msk,      /**< Interrupt on RXFRAMESTART event. */
182     NRF_NFCT_INT_RXFRAMEEND_MASK        = NFCT_INTEN_RXFRAMEEND_Msk,        /**< Interrupt on RXFRAMEEND event. */
183     NRF_NFCT_INT_ERROR_MASK             = NFCT_INTEN_ERROR_Msk,             /**< Interrupt on ERROR event. */
184     NRF_NFCT_INT_RXERROR_MASK           = NFCT_INTEN_RXERROR_Msk,           /**< Interrupt on RXERROR event. */
185     NRF_NFCT_INT_ENDRX_MASK             = NFCT_INTEN_ENDRX_Msk,             /**< Interrupt on ENDRX event. */
186     NRF_NFCT_INT_ENDTX_MASK             = NFCT_INTEN_ENDTX_Msk,             /**< Interrupt on ENDTX event. */
187     NRF_NFCT_INT_AUTOCOLRESSTARTED_MASK = NFCT_INTEN_AUTOCOLRESSTARTED_Msk, /**< Interrupt on AUTOCOLRESSTARTED event. */
188     NRF_NFCT_INT_COLLISION_MASK         = NFCT_INTEN_COLLISION_Msk,         /**< Interrupt on COLLISION event. */
189     NRF_NFCT_INT_SELECTED_MASK          = NFCT_INTEN_SELECTED_Msk,          /**< Interrupt on SELECTED event. */
190     NRF_NFCT_INT_STARTED_MASK           = NFCT_INTEN_STARTED_Msk,           /**< Interrupt on STARTED event. */
191 } nrf_nfct_int_mask_t;
192 
193 /** @brief NFC error status bit masks. */
194 typedef enum
195 {
196     NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK = NFCT_ERRORSTATUS_FRAMEDELAYTIMEOUT_Msk, /**< Timeout of the Frame Delay Timer (no frame transmission started in the FDT window). */
197 #if defined(NFCT_ERRORSTATUS_NFCFIELDTOOSTRONG_Msk) || defined(__NRFX_DOXYGEN__)
198     NRF_NFCT_ERROR_NFCFIELDTOOSTRONG_MASK = NFCT_ERRORSTATUS_NFCFIELDTOOSTRONG_Msk, /**< Field level is too high at maximum load resistance. */
199 #endif
200 #if defined(NFCT_ERRORSTATUS_NFCFIELDTOOWEAK_Msk) || defined(__NRFX_DOXYGEN__)
201     NRF_NFCT_ERROR_NFCFIELDTOOWEAK_MASK = NFCT_ERRORSTATUS_NFCFIELDTOOWEAK_Msk,     /**< Field level is too low at minimum load resistance. */
202 #endif
203 } nrf_nfct_error_status_t;
204 
205 /** @brief NFC received frame status bit masks. */
206 typedef enum
207 {
208     NRF_NFCT_RX_FRAME_STATUS_CRC_MASK     = NFCT_FRAMESTATUS_RX_CRCERROR_Msk,     /**< CRC status mask. */
209     NRF_NFCT_RX_FRAME_STATUS_PARITY_MASK  = NFCT_FRAMESTATUS_RX_PARITYSTATUS_Msk, /**< Parity status mask. */
210     NRF_NFCT_RX_FRAME_STATUS_OVERRUN_MASK = NFCT_FRAMESTATUS_RX_OVERRUN_Msk,      /**< Overrun status mask. */
211 } nrf_nfct_rx_frame_status_t;
212 
213 #if NRF_NFCT_HAS_TAG_STATE_REG
214 /** @brief NFC tag state. */
215 typedef enum
216 {
217     NRF_NFCT_TAG_STATE_DISABLED    = NFCT_NFCTAGSTATE_NFCTAGSTATE_Disabled,   /**< Disabled or sensing NFC field. */
218     NRF_NFCT_TAG_STATE_RAMP_UP     = NFCT_NFCTAGSTATE_NFCTAGSTATE_RampUp,     /**< Ramping up. */
219     NRF_NFCT_TAG_STATE_IDLE        = NFCT_NFCTAGSTATE_NFCTAGSTATE_Idle,       /**< Idle. */
220     NRF_NFCT_TAG_STATE_RECEIVE     = NFCT_NFCTAGSTATE_NFCTAGSTATE_Receive,    /**< Receiving data. */
221     NRF_NFCT_TAG_STATE_FRAME_DELAY = NFCT_NFCTAGSTATE_NFCTAGSTATE_FrameDelay, /**< Counting Frame Delay Time since the last symbol of the last received frame. */
222     NRF_NFCT_TAG_STATE_TRANSMIT    = NFCT_NFCTAGSTATE_NFCTAGSTATE_Transmit    /**< Transmitting data. */
223 } nrf_nfct_tag_state_t;
224 #endif // NRF_NFCT_HAS_TAG_STATE_REG
225 
226 #if NRF_NFCT_HAS_SLEEP_STATE_REG
227 /**
228  * @brief NFC tag sleep state.
229  *
230  * @details Shows the sleep state during automatic collision resolution
231  *          according to the NFC Forum Activity Technical Specification v2.0.
232  */
233 typedef enum
234 {
235     NRF_NFCT_SLEEP_STATE_IDLE    = NFCT_SLEEPSTATE_SLEEPSTATE_Idle,  /**< 'IDLE' state. */
236     NRF_NFCT_SLEEP_STATE_SLEEP_A = NFCT_SLEEPSTATE_SLEEPSTATE_SleepA /**< 'SLEEP_A' state. */
237 } nrf_nfct_sleep_state_t;
238 #endif // NRF_NFCT_HAS_SLEEP_STATE_REG
239 
240 /** @brief NFC field state bit masks. */
241 typedef enum
242 {
243     NRF_NFCT_FIELD_STATE_PRESENT_MASK = NFCT_FIELDPRESENT_FIELDPRESENT_Msk, /**< Field presence mask. */
244     NRF_NFCT_FIELD_STATE_LOCK_MASK    = NFCT_FIELDPRESENT_LOCKDETECT_Msk    /**< Field lock mask. */
245 } nrf_nfct_field_state_t;
246 
247 /** @brief NFC frame delay mode for data transmission. */
248 typedef enum
249 {
250     NRF_NFCT_FRAME_DELAY_MODE_FREERUN    = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_FreeRun,   /**< Frame transmission starts when @ref NRF_NFCT_TASK_STARTTX is set (delay timer is not used). */
251     NRF_NFCT_FRAME_DELAY_MODE_WINDOW     = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_Window,    /**< Frame transmission starts in a window between FRAMEDELAYMIN and FRAMEDELAYMAX. */
252     NRF_NFCT_FRAME_DELAY_MODE_EXACTVAL   = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_ExactVal,  /**< Frame transmission starts when the delay timer reaches FRAMEDELAYMAX. */
253     NRF_NFCT_FRAME_DELAY_MODE_WINDOWGRID = NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_WindowGrid /**< Frame transmission starts in a bit grid between FRAMEDELAYMIN and FRAMEDELAYMAX. */
254 } nrf_nfct_frame_delay_mode_t;
255 
256 /** @brief Bit masks for NFC transmission frame configuration. */
257 typedef enum
258 {
259     NRF_NFCT_TX_FRAME_CONFIG_PARITY        = NFCT_TXD_FRAMECONFIG_PARITY_Msk,      /**< Indicates whether parity is added in the transmitted frames. */
260     NRF_NFCT_TX_FRAME_CONFIG_DISCARD_START = NFCT_TXD_FRAMECONFIG_DISCARDMODE_Msk, /**< Indicates whether unused bits are discarded at the start or at the end of the transmitted frames. */
261     NRF_NFCT_TX_FRAME_CONFIG_SOF           = NFCT_TXD_FRAMECONFIG_SOF_Msk,         /**< Indicates whether SoF symbol is added in the transmitted frames. */
262     NRF_NFCT_TX_FRAME_CONFIG_CRC16         = NFCT_TXD_FRAMECONFIG_CRCMODETX_Msk    /**< Indicates whether CRC is added in the transmitted frames. */
263 } nrf_nfct_tx_frame_config_t;
264 
265 /** @brief Bit masks for NFC reception frame configuration. */
266 typedef enum
267 {
268     NRF_NFCT_RX_FRAME_CONFIG_PARITY = NFCT_RXD_FRAMECONFIG_PARITY_Msk,   /**< Indicates whether parity is expected in the received frames. */
269     NRF_NFCT_RX_FRAME_CONFIG_SOF    = NFCT_RXD_FRAMECONFIG_SOF_Msk,      /**< Indicates whether SoF symbol is expected in the received frames. */
270     NRF_NFCT_RX_FRAME_CONFIG_CRC16  = NFCT_RXD_FRAMECONFIG_CRCMODERX_Msk /**< Indicates whether CRC is expected and checked in the received frames. */
271 } nrf_nfct_rx_frame_config_t;
272 
273 /**
274  * @brief 'NFCI1 size' NFC field configuration for the SENS_RES frame according to the NFC Forum
275  *        Digital Protocol Technical Specification.
276  */
277 typedef enum
278 {
279     NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE =
280         NFCT_SENSRES_NFCIDSIZE_NFCID1Single << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Single size NFCID1 (4 bytes). */
281     NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE =
282         NFCT_SENSRES_NFCIDSIZE_NFCID1Double << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Double size NFCID1 (7 bytes). */
283     NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE =
284         NFCT_SENSRES_NFCIDSIZE_NFCID1Triple << NFCT_SENSRES_NFCIDSIZE_Pos, /**< Triple size NFCID1 (10 bytes). */
285     NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT =
286         NFCT_SENSRES_NFCIDSIZE_Msk                                         /**< Default size. Use this option to leave NFCID1 size unchanged. */
287 } nrf_nfct_sensres_nfcid1_size_t;
288 
289 /** @brief Bias trim configuration. */
290 typedef struct
291 {
292     uint8_t trim_ibpsr;        /**< Fine trim IBPSR 4 µA bias current. */
293     uint8_t coarse_ibpsr;      /**< Coarse trim IBPSR 4 µA. */
294     uint8_t reference_volatge; /**< Reference voltage level. */
295     uint8_t spare;             /**< Spare. */
296 } nrf_nfct_bias_config_t;
297 
298 /**
299  * @brief 'Bit frame SDD' NFC field configuration for the SENS_RES frame according to the NFC
300  *         Forum Digital Protocol Technical Specification.
301  */
302 typedef enum
303 {
304     NRF_NFCT_SENSRES_BIT_FRAME_SDD_00000 =
305         NFCT_SENSRES_BITFRAMESDD_SDD00000 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00000. */
306     NRF_NFCT_SENSRES_BIT_FRAME_SDD_00001 =
307         NFCT_SENSRES_BITFRAMESDD_SDD00001 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00001. */
308     NRF_NFCT_SENSRES_BIT_FRAME_SDD_00010 =
309         NFCT_SENSRES_BITFRAMESDD_SDD00010 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00010. */
310     NRF_NFCT_SENSRES_BIT_FRAME_SDD_00100 =
311         NFCT_SENSRES_BITFRAMESDD_SDD00100 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 00100. */
312     NRF_NFCT_SENSRES_BIT_FRAME_SDD_01000 =
313         NFCT_SENSRES_BITFRAMESDD_SDD01000 << NFCT_SENSRES_BITFRAMESDD_Pos, /**< SDD pattern 01000. */
314     NRF_NFCT_SENSRES_BIT_FRAME_SDD_10000 =
315         NFCT_SENSRES_BITFRAMESDD_SDD10000 << NFCT_SENSRES_BITFRAMESDD_Pos  /**< SDD pattern 10000. */
316 } nrf_nfct_sensres_bit_frame_sdd_t;
317 
318 /**
319  * @brief 'Platofrm Config' NFC field configuration for the SENS_RES frame according to the NFC
320  *        Forum Digital Protocol Technical Specification.
321  */
322 typedef enum
323 {
324     /**< SENS_RES 'Platform Config' field (b4-b1) value for Type 1 Tag platform. */
325     NRF_NFCT_SENSRES_PLATFORM_CONFIG_T1T   = 6 << NFCT_SENSRES_PLATFCONFIG_Pos,
326     /**< SENS_RES 'Platform Config' field (b7-b6) value for any platform except Type 1 Tag platform. */
327     NRF_NFCT_SENSRES_PLATFORM_CONFIG_OTHER = 0 << NFCT_SENSRES_PLATFCONFIG_Pos
328 } nrf_nfct_sensres_platform_config_t;
329 
330 /**
331  * @brief Protocol NFC field (bits b7 and b6) configuration for the SEL_RES frame according to
332  *        the NFC Forum Digital Protocol Technical Specification.
333  */
334 typedef enum
335 {
336     NRF_NFCT_SELRES_PROTOCOL_T2T         = 0,  /**< Type 2 Tag platform. */
337     NRF_NFCT_SELRES_PROTOCOL_T4AT        = 1,  /**< Type 4A Tag platform. */
338     NRF_NFCT_SELRES_PROTOCOL_NFCDEP      = 2,  /**< NFC-DEP Protocol. */
339     NRF_NFCT_SELRES_PROTOCOL_NFCDEP_T4AT = 3,  /**< NFC-DEP Protocol and Type 4A Tag platform). */
340 } nrf_nfct_selres_protocol_t;
341 
342 #if NRF_NFCT_HAS_MODULATION_CTRL_REG
343 /** @brief Modulation output configuration. */
344 typedef enum
345 {
346     NRF_NFCT_MODULATION_CTRL_INVALID       = NFCT_MODULATIONCTRL_MODULATIONCTRL_Invalid,             /**< Invalid configuration. Defaults to the same behavior as NRF_NFCT_MODULATION_CTRL_INTERNAL. */
347     NRF_NFCT_MODULATION_CTRL_INTERNAL      = NFCT_MODULATIONCTRL_MODULATIONCTRL_Internal,            /**< Use internal modulator only. */
348     NRF_NFCT_MODULATION_CTRL_GPIO          = NFCT_MODULATIONCTRL_MODULATIONCTRL_ModToGpio,           /**< Transmit output digital modulation signal to a GPIO pin. */
349     NRF_NFCT_MODULATION_CTRL_INTERNAL_GPIO = NFCT_MODULATIONCTRL_MODULATIONCTRL_InternalAndModToGpio /**< Use internal modulator and transmit output digital modulation signal to a GPIO pin. */
350 } nrf_nfct_modulation_ctrl_t;
351 #endif // NRF_NFCT_HAS_MODULATION_CTRL_REG
352 
353 /**
354  * @brief Function for activating a specific NFCT task.
355  *
356  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
357  * @param[in] task  Task to be activated.
358  */
359 NRF_STATIC_INLINE void nrf_nfct_task_trigger(NRF_NFCT_Type * p_reg, nrf_nfct_task_t task);
360 
361 /**
362  * @brief Function for returning the address of a specific NFCT task register.
363  *
364  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
365  * @param[in] task  Task.
366  *
367  * @return Task address.
368  */
369 NRF_STATIC_INLINE uint32_t nrf_nfct_task_address_get(NRF_NFCT_Type const * p_reg,
370                                                      nrf_nfct_task_t       task);
371 
372 /**
373  * @brief Function for clearing a specific event.
374  *
375  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
376  * @param[in] event Event.
377  */
378 NRF_STATIC_INLINE void nrf_nfct_event_clear(NRF_NFCT_Type * p_reg, nrf_nfct_event_t event);
379 
380 /**
381  * @brief Function for retrieving the state of the NFCT event.
382  *
383  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
384  * @param[in] event Event to be checked.
385  *
386  * @retval true  The event has been generated.
387  * @retval false The event has not been generated.
388  */
389 NRF_STATIC_INLINE bool nrf_nfct_event_check(NRF_NFCT_Type const * p_reg, nrf_nfct_event_t event);
390 
391 /**
392  * @brief Function for returning the address of a specific NFCT event register.
393  *
394  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
395  * @param[in] event Event.
396  *
397  * @return Address.
398  */
399 NRF_STATIC_INLINE uint32_t nrf_nfct_event_address_get(NRF_NFCT_Type const * p_reg,
400                                                       nrf_nfct_event_t      event);
401 
402 /**
403  * @brief Function for enabling selected shortcuts.
404  *
405  * @param[in] p_reg      Pointer to the structure of registers of the peripheral.
406  * @param[in] short_mask Mask of shortcuts.
407  */
408 NRF_STATIC_INLINE void nrf_nfct_shorts_enable(NRF_NFCT_Type * p_reg, uint32_t short_mask);
409 
410 /**
411  * @brief Function for disabling selected shortcuts.
412  *
413  * @param[in] p_reg      Pointer to the structure of registers of the peripheral.
414  * @param[in] short_mask Mask of shortcuts.
415  */
416 NRF_STATIC_INLINE void nrf_nfct_shorts_disable(NRF_NFCT_Type * p_reg, uint32_t short_mask);
417 
418 /**
419  * @brief Function for retrieving the enabled shortcuts.
420  *
421  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
422  *
423  * @return Flags of the currently enabled shortcuts.
424  */
425 NRF_STATIC_INLINE uint32_t nrf_nfct_shorts_get(NRF_NFCT_Type const * p_reg);
426 
427 /**
428  * @brief Function for setting shortcuts.
429  *
430  * @param[in] p_reg      Pointer to the structure of registers of the peripheral.
431  * @param[in] short_mask Shortcut mask.
432  */
433 NRF_STATIC_INLINE void nrf_nfct_shorts_set(NRF_NFCT_Type * p_reg, uint32_t short_mask);
434 
435 /**
436  * @brief Function for enabling the selected interrupts.
437  *
438  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
439  * @param[in] mask  Mask of interrupts to be enabled.
440  *                  Use @ref nrf_nfct_int_mask_t values for bit masking.
441  */
442 NRF_STATIC_INLINE void nrf_nfct_int_enable(NRF_NFCT_Type * p_reg, uint32_t mask);
443 
444 /**
445  * @brief Function for checking if the specified interrupts are enabled.
446  *
447  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
448  * @param[in] mask  Mask of interrupts to be checked.
449  *                  Use @ref nrf_nfct_int_mask_t values for bit masking.
450  *
451  * @return Mask of enabled interrupts.
452  */
453 NRF_STATIC_INLINE uint32_t nrf_nfct_int_enable_check(NRF_NFCT_Type const * p_reg, uint32_t mask);
454 
455 /**
456  * @brief Function for retrieving the information about enabled interrupts.
457  *
458  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
459  *
460  * @return The flags of the enabled interrupts.
461  */
462 NRF_STATIC_INLINE uint32_t nrf_nfct_int_enable_get(NRF_NFCT_Type const * p_reg);
463 
464 /**
465  * @brief Function for disabling the selected interrupts.
466  *
467  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
468  * @param[in] mask  Mask of interrupts to be disabled.
469  *                  Use @ref nrf_nfct_int_mask_t values for bit masking.
470  */
471 NRF_STATIC_INLINE void nrf_nfct_int_disable(NRF_NFCT_Type * p_reg, uint32_t mask);
472 
473 #if NRF_NFCT_HAS_MODULATION_PSEL_REG
474 /**
475  * @brief Function for configuring the NFCT modulation control pin.
476  *
477  * If a given signal is not needed, pass the @ref NRF_NFCT_MOD_CTRL_PIN_NOT_CONNECTED
478  * value instead of its pin number.
479  *
480  * @param[in] p_reg        Pointer to the structure of registers of the peripheral.
481  * @param[in] mod_ctrl_pin Modulation control pin.
482  */
483 NRF_STATIC_INLINE void nrf_nfct_mod_ctrl_pin_set(NRF_NFCT_Type * p_reg, uint32_t mod_ctrl_pin);
484 
485 /**
486  * @brief Function for getting the modulation control pin selection.
487  *
488  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
489  *
490  * @return Modulation control pin selection.
491  */
492 NRF_STATIC_INLINE uint32_t nrf_nfct_mod_ctrl_pin_get(NRF_NFCT_Type const * p_reg);
493 #endif // NRF_NFCT_HAS_MODULATION_PSEL_REG
494 
495 #if NRF_NFCT_HAS_MODULATION_CTRL_REG
496 /**
497  * @brief Function for setting the modulation output. It enables the
498  *        output to a GPIO pin which can be connected to a second external.
499  *
500  * @param[in] p_reg    Pointer to the structure of registers of the peripheral.
501  * @param[in] mod_ctrl Modulation control field configuration.
502  */
503 NRF_STATIC_INLINE void nrf_nfct_modulation_output_set(NRF_NFCT_Type *            p_reg,
504                                                       nrf_nfct_modulation_ctrl_t mod_ctrl);
505 
506 /**
507  * @brief Function for getting the modulation output configuration.
508  *
509  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
510  *
511  * @return The configured modulation output.
512  */
513 NRF_STATIC_INLINE
514 nrf_nfct_modulation_ctrl_t nrf_nfct_modulation_output_get(NRF_NFCT_Type const * p_reg);
515 #endif // NRF_NFCT_HAS_MODULATION_CTRL_REG
516 
517 /**
518  * @brief Function for getting the NFCT error status.
519  *
520  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
521  *
522  * @return The NFCT error status flags, defined in @ref nrf_nfct_error_status_t.
523  */
524 NRF_STATIC_INLINE uint32_t nrf_nfct_error_status_get(NRF_NFCT_Type const * p_reg);
525 
526 /**
527  * @brief Function for clearing the NFCT error status.
528  *
529  * @param[in] p_reg      Pointer to the structure of registers of the peripheral.
530  * @param[in] error_flag Error flags to be cleared, defined in @ref nrf_nfct_error_status_t.
531  */
532 NRF_STATIC_INLINE void nrf_nfct_error_status_clear(NRF_NFCT_Type * p_reg, uint32_t error_flag);
533 
534 /**
535  * @brief Function for getting the NFC frame reception status.
536  *
537  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
538  *
539  * @return The flags of the NFC frame reception status, defined in @ref nrf_nfct_rx_frame_status_t.
540  */
541 NRF_STATIC_INLINE uint32_t nrf_nfct_rx_frame_status_get(NRF_NFCT_Type const * p_reg);
542 
543 /**
544  * @brief Function for clearing the NFC frame reception status.
545  *
546  * @param[in] p_reg             Pointer to the structure of registers of the peripheral.
547  * @param[in] framestatus_flags Status flags to be cleared,
548  *                              defined in @ref nrf_nfct_rx_frame_status_t.
549  */
550 NRF_STATIC_INLINE void nrf_nfct_rx_frame_status_clear(NRF_NFCT_Type * p_reg,
551                                                       uint32_t        framestatus_flags);
552 
553 #if NRF_NFCT_HAS_TAG_STATE_REG
554 /**
555  * @brief Function for getting the NFC tag state.
556  *
557  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
558  *
559  * @retval NRF_NFCT_TAG_STATE_DISABLED    NFC tag is disabled.
560  * @retval NRF_NFCT_TAG_STATE_RAMP_UP     NFC tag is ramping up.
561  * @retval NRF_NFCT_TAG_STATE_IDLE        NFC tag is activated and idle.
562  * @retval NRF_NFCT_TAG_STATE_RECEIVE     NFC tag is receiving data.
563  * @retval NRF_NFCT_TAG_STATE_FRAME_DELAY Frame Delay Timer of the NFC tag is counting ticks
564  *                                        since the last symbol of the last received frame.
565  * @retval NRF_NFCT_TAG_STATE_TRANSMIT    NFC tag is transmitting data.
566  */
567 NRF_STATIC_INLINE nrf_nfct_tag_state_t nrf_nfct_tag_state_get(NRF_NFCT_Type const * p_reg);
568 #endif // NRF_NFCT_HAS_TAG_STATE_REG
569 
570 #if NRF_NFCT_HAS_SLEEP_STATE_REG
571 /**
572  * @brief Function for getting the NFC tag sleep state during the automatic collision resolution.
573  *
574  * @details The returned value is the last state before the autimatic collision resolution started.
575  *
576  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
577  *
578  * @retval NRF_NFCT_SLEEP_STATE_IDLE    NFC tag was in IDLE state before the automatic
579  *                                      collision resolution started.
580  * @retval NRF_NFCT_SLEEP_STATE_SLEEP_A NFC tag was in SLEEP_A state before the automatic
581  *                                      collision resolution started.
582  */
583 NRF_STATIC_INLINE nrf_nfct_sleep_state_t nrf_nfct_sleep_state_get(NRF_NFCT_Type const * p_reg);
584 #endif // NRF_NFCT_HAS_SLEEP_STATE_REG
585 
586 /**
587  * @brief Function for getting the status of the external NFC field detection.
588  *
589  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
590  *
591  * @return The NFC field detection status. Status bits can be checked by using
592  *         @ref nrf_nfct_field_state_t.
593  */
594 NRF_STATIC_INLINE uint8_t nrf_nfct_field_status_get(NRF_NFCT_Type const * p_reg);
595 
596 /**
597  * @brief Function for getting the minimum Frame Delay Time value.
598  *
599  * @details This is the minimum value for Frame Delay Timer. It controls the shortest time between
600  *          the last symbol of the last received frame and the start of the transmission of a new
601  *          TX frame.
602  *
603  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
604  *
605  * @return The minimum Frame Delay Time value in 13.56-MHz clock ticks.
606  */
607 NRF_STATIC_INLINE uint16_t nrf_nfct_frame_delay_min_get(NRF_NFCT_Type const * p_reg);
608 
609 /**
610  * @brief Function for setting the minimum Frame Delay Time value.
611  *
612  * @details This is the minimum value for Frame Delay Timer. It controls the shortest time between
613  *          the last symbol of the last received frame and the start of the transmission of a new
614  *          TX frame.
615  *
616  * @param[in] p_reg           Pointer to the structure of registers of the peripheral.
617  * @param[in] frame_delay_min Minimum Frame Delay Time value in 13.56-MHz clock ticks.
618  */
619 NRF_STATIC_INLINE void nrf_nfct_frame_delay_min_set(NRF_NFCT_Type * p_reg,
620                                                     uint16_t        frame_delay_min);
621 
622 /**
623  * @brief Function for getting the maximum Frame Delay Time value.
624  *
625  * @details This is the maximum value for Frame Delay Timer. It controls the longest time between
626  *          the last symbol of the last received frame and the start of the transmission of a new
627  *          TX frame. If no transmission starts before the Frame Delay Timer timeout,
628  *          @ref NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK is set.
629  *
630  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
631  *
632  * @return The maximum Frame Delay Time value in 13.56-MHz clock ticks.
633  */
634 NRF_STATIC_INLINE uint32_t nrf_nfct_frame_delay_max_get(NRF_NFCT_Type const * p_reg);
635 
636 /**
637  * @brief Function for setting the maximum Frame Delay Time value.
638  *
639  * @details This is the maximum value for Frame Delay Timer. It controls the longest time between
640  *          the last symbol of the last received frame and the start of the transmission of a new
641  *          TX frame. If no transmission starts before the Frame Delay Timer timeout,
642  *          @ref NRF_NFCT_ERROR_FRAMEDELAYTIMEOUT_MASK is set.
643  *
644  * @param[in] p_reg           Pointer to the structure of registers of the peripheral.
645  * @param[in] frame_delay_max Maximum Frame Delay Time value in 13.56-MHz clock ticks.
646  */
647 NRF_STATIC_INLINE void nrf_nfct_frame_delay_max_set(NRF_NFCT_Type * p_reg,
648                                                     uint32_t        frame_delay_max);
649 
650 /**
651  * @brief Function for getting the Frame Delay Mode configuration.
652  *
653  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
654  *
655  * @return The configured Frame Delay Mode.
656  */
657 NRF_STATIC_INLINE
658 nrf_nfct_frame_delay_mode_t nrf_nfct_frame_delay_mode_get(NRF_NFCT_Type const * p_reg);
659 
660 /**
661  * @brief Function for setting the NFC Frame Delay Mode configuration.
662  *
663  * @param[in] p_reg            Pointer to the structure of registers of the peripheral.
664  * @param[in] frame_delay_mode Frame Delay Mode configuration.
665  */
666 NRF_STATIC_INLINE void nrf_nfct_frame_delay_mode_set(NRF_NFCT_Type *             p_reg,
667                                                      nrf_nfct_frame_delay_mode_t frame_delay_mode);
668 
669 /**
670  * @brief Function for getting the pointer to the NFCT RX/TX buffer.
671  *
672  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
673  *
674  * @return The configured pointer to the receive or transmit buffer.
675  */
676 NRF_STATIC_INLINE uint8_t * nrf_nfct_rxtx_buffer_get(NRF_NFCT_Type const * p_reg);
677 
678 /**
679  * @brief Function for setting the the NFCT RX/TX buffer (address and maximum length).
680  *
681  * @note Buffer for the NFC RX/TX data is used by EasyDMA and must be located in RAM.
682  *
683  * @param[in] p_reg        Pointer to the structure of registers of the peripheral.
684  * @param[in] p_rxtx_buf   Pointer to the receive or transmit buffer.
685  * @param[in] max_txrx_len Maximum receive or transmit length in bytes
686  *                         (size of the RAM buffer for EasyDMA).
687  */
688 NRF_STATIC_INLINE void nrf_nfct_rxtx_buffer_set(NRF_NFCT_Type * p_reg,
689                                                 uint8_t *       p_rxtx_buf,
690                                                 uint16_t        max_txrx_len);
691 
692 /**
693  * @brief Function for getting the NFCT RX/TX maximum buffer length.
694  *
695  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
696  *
697  * @return The configured maximum receive or transmit length in bytes (size of the RX/TX
698  *         buffer for EasyDMA).
699  */
700 NRF_STATIC_INLINE uint16_t nrf_nfct_max_rxtx_length_get(NRF_NFCT_Type const * p_reg);
701 
702 /**
703  * @brief Function for getting the flags for NFC frame transmission configuration.
704  *
705  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
706  *
707  * @return The flags of the NFCT frame transmission configuration, defined in
708  *         @ref nrf_nfct_tx_frame_config_t.
709  */
710 NRF_STATIC_INLINE uint8_t nrf_nfct_tx_frame_config_get(NRF_NFCT_Type const * p_reg);
711 
712 /**
713  * @brief Function for setting up the flags of the NFC frame transmission configuration.
714  *
715  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
716  * @param[in] flags Flags for NFCT TX configuration. Use @ref nrf_nfct_tx_frame_config_t for
717  *                  setting.
718  */
719 NRF_STATIC_INLINE void nrf_nfct_tx_frame_config_set(NRF_NFCT_Type * p_reg, uint8_t flags);
720 
721 /**
722  * @brief Function for getting the length of the configured transmission frame.
723  *
724  * @note NFC frames do not have to consist of full bytes only, therefore data amount
725  *       for transmission is configured in number of bits.
726  *
727  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
728  *
729  * @return Number of bits to be sent excluding CRC, parity, SoF, and EoF.
730  */
731 NRF_STATIC_INLINE uint16_t nrf_nfct_tx_bits_get(NRF_NFCT_Type const * p_reg);
732 
733 /**
734  * @brief Function for setting up the NFC frame transmission.
735  *
736  * @details Set the number of TX bits excluding CRC, parity, SoF, and EoF.
737  *
738  * @note Source of data for transmission is set by using @ref nrf_nfct_rxtx_buffer_set.
739  * @note NFC frames do not have to consist of full bytes only, therefore data amount
740  *       for transmission is configured in number of bits.
741  *
742  * @param[in] p_reg   Pointer to the structure of registers of the peripheral.
743  * @param[in] tx_bits Overall number of bits to be sent.
744  */
745 NRF_STATIC_INLINE void nrf_nfct_tx_bits_set(NRF_NFCT_Type * p_reg, uint16_t tx_bits);
746 
747 /**
748  * @brief Function for getting the flags of the NFC frame reception configuration.
749  *
750  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
751  *
752  * @return The flags for NFCT frame reception configuration, defined in
753  *         @ref nrf_nfct_rx_frame_config_t.
754  */
755 NRF_STATIC_INLINE uint8_t nrf_nfct_rx_frame_config_get(NRF_NFCT_Type const * p_reg);
756 
757 /**
758  * @brief Function for setting up the NFC frame reception.
759  *
760  * @note Destination for the received data is set using @ref nrf_nfct_rxtx_buffer_set.
761  *
762  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
763  * @param[in] flags NFCT RX configuration flags. Use @ref nrf_nfct_rx_frame_config_t for setting
764  *                  the desired configuration.
765  */
766 NRF_STATIC_INLINE void nrf_nfct_rx_frame_config_set(NRF_NFCT_Type * p_reg, uint8_t flags);
767 
768 /**
769  * @brief Function for getting the number of bits received from the NFC poller.
770  *
771  * @param[in] p_reg        Pointer to the structure of registers of the peripheral.
772  * @param[in] crc_excluded Flag for excluding CRC size from calculation.
773  *
774  * @return Number of received bits including or excluding CRC, and excluding parity
775  *         and SoF/EoF framing.
776  */
777 NRF_STATIC_INLINE uint16_t nrf_nfct_rx_bits_get(NRF_NFCT_Type const * p_reg, bool crc_excluded);
778 
779 /**
780  * @brief Function for getting the NFCID1 (NFC tag identifier).
781  *
782  * @note This function always returns the full configuration of the NFCID1 setting (10 bytes),
783  *       regardless of the NFCID1 size. The NFCID1 size can be configured using
784  *       @ref nrf_nfct_sensres_nfcid1_size_set or @ref nrf_nfct_nfcid1_set.
785  *
786  * @param[in]  p_reg        Pointer to the structure of registers of the peripheral.
787  * @param[out] p_nfcid1_buf Pointer to a buffer for the NDFCID1 parameter.
788  *                          The NFCID1 values are in little endian order,
789  *                          that is: |NFCID1_3RD_LAST|NFCID1_2ND_LAST|NFCID1_LAST|.
790  *
791  * @return Configured NFCID1 length
792  */
793 NRF_STATIC_INLINE
794 nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_get(NRF_NFCT_Type const * p_reg,
795                                                    uint8_t *             p_nfcid1_buf);
796 
797 /**
798  * @brief Function for setting the NFCID1 (NFC tag identifier).
799  *
800  * @note This function also configures the NFCIDSIZE field in the SENSRES
801  *       register of the NFCT peripheral.
802  *
803  * @param[in] p_reg        Pointer to the structure of registers of the peripheral.
804  * @param[in] p_nfcid1_buf Pointer to the buffer with NDFCID1 bytes.
805  * @param[in] nfcid1_size  Size of the NFCID1 in bytes.
806  */
807 NRF_STATIC_INLINE void nrf_nfct_nfcid1_set(NRF_NFCT_Type *                p_reg,
808                                            uint8_t const *                p_nfcid1_buf,
809                                            nrf_nfct_sensres_nfcid1_size_t nfcid1_size);
810 
811 #if NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG
812 /**
813  * @brief Function for getting the setting for the automatic collision resolution.
814  *
815  * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum
816  *          Digital Protocol Technical Specification 2.0, section 6.
817  *
818  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
819  *
820  * @retval true  If automatic collision resolution is enabled.
821  * @retval false If automatic collision resolution is disabled.
822  */
823 NRF_STATIC_INLINE bool nrf_nfct_autocolres_is_enabled(NRF_NFCT_Type const * p_reg);
824 
825 /**
826  * @brief Function for enabling the automatic collision resolution.
827  *
828  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
829  *
830  * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum
831  *          Digital Protocol Technical Specification 2.0, section 6.
832  */
833 NRF_STATIC_INLINE void nrf_nfct_autocolres_enable(NRF_NFCT_Type * p_reg);
834 
835 /**
836  * @brief Function for disabling the automatic collision resolution.
837  *
838  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
839  *
840  * @details The automatic collision resolution mechanism as defined in ISO 14443-3 and NFC Forum
841  *          Digital Protocol Technical Specification 2.0, section 6.
842  */
843 NRF_STATIC_INLINE void nrf_nfct_autocolres_disable(NRF_NFCT_Type * p_reg);
844 #endif // NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG
845 
846 /**
847  * @brief Function for getting the NFCID1 size from the SENS_RES frame configuration.
848  *
849  * @details The SENS_RES frame is handled automatically by the NFCT hardware.
850  *
851  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
852  *
853  * @return NFCID1 (tag identifier) size.
854  */
855 NRF_STATIC_INLINE
856 nrf_nfct_sensres_nfcid1_size_t nrf_nfct_sensres_nfcid1_size_get(NRF_NFCT_Type const * p_reg);
857 
858 /**
859  * @brief Function for setting the NFCID1 (tag identifier) size.field in the SENS_RES frame
860  *        configuration.
861  *
862  * @note The SENS_RES frame is handled automatically by the NFCT hardware.
863  *
864  * @param[in] p_reg       Pointer to the structure of registers of the peripheral.
865  * @param[in] nfcid1_size NFCID1 (tag identifier) size.
866  *
867  * @sa nrf_nfct_nfcid1_set()
868  */
869 NRF_STATIC_INLINE
870 void nrf_nfct_sensres_nfcid1_size_set(NRF_NFCT_Type *                p_reg,
871                                       nrf_nfct_sensres_nfcid1_size_t nfcid1_size);
872 
873 /**
874  * @brief Function for getting the Bit Frame SDD field from the SENS_RES frame configuration.
875  *
876  * @details The SENS_RES frame is handled automatically by the NFCT hardware.
877  *
878  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
879  *
880  * @return The Bit Frame SDD field configuration.
881  */
882 NRF_STATIC_INLINE
883 nrf_nfct_sensres_bit_frame_sdd_t nrf_nfct_sensres_bit_frame_sdd_get(NRF_NFCT_Type const * p_reg);
884 
885 /**
886  * @brief Function for setting the Bit Frame SDD field in the SENS_RES frame configuration.
887  *
888  * @note The SENS_RES frame is handled automatically by the NFCT hardware.
889  *
890  * @param[in] p_reg         Pointer to the structure of registers of the peripheral.
891  * @param[in] bit_frame_sdd The Bit Frame SDD field configuration.
892  */
893 NRF_STATIC_INLINE
894 void nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_Type *                  p_reg,
895                                         nrf_nfct_sensres_bit_frame_sdd_t bit_frame_sdd);
896 
897 /**
898  * @brief Function for getting the Platform Config field from the SENS_RES frame configuration.
899  *
900  * @details The SENS_RES frame is handled automatically by the NFCT hardware.
901  *
902  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
903  *
904  * @return The Platform Config field configuration.
905  */
906 NRF_STATIC_INLINE nrf_nfct_sensres_platform_config_t
907 nrf_nfct_sensres_platform_config_get(NRF_NFCT_Type const * p_reg);
908 
909 /**
910  * @brief Function for setting the Platform Config field in the SENS_RES frame configuration.
911  *
912  * @note The SENS_RES frame is handled automatically by the NFCT hardware.
913  *
914  * @param[in] p_reg           Pointer to the structure of registers of the peripheral.
915  * @param[in] platform_config The Platform Config field configuration.
916  */
917 NRF_STATIC_INLINE
918 void nrf_nfct_sensres_platform_config_set(NRF_NFCT_Type *                    p_reg,
919                                           nrf_nfct_sensres_platform_config_t platform_config);
920 
921 /**
922  * @brief Function for checking the CASCADE bit of the SEL_RES frame.
923  *
924  * @details The CASCADE bit in the SEL_RES register is handled automatically by the NFCT hardware
925  *          and indicates the status of the NFCID1 read operation to the NFC poller according to
926  *          the NFC Forum Digital Protocol Speficiation 2.0, section 6.8.2.
927  *
928  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
929  *
930  * @retval true  If NFCID1 read procedure is not complete.
931  * @retval false If NFCID1 read procedure is complete.
932  */
933 NRF_STATIC_INLINE bool nrf_nfct_selres_cascade_check(NRF_NFCT_Type const * p_reg);
934 
935 /**
936  * @brief Function for getting the Protocol field in the SEL_RES frame.
937  *
938  * @details The SEL_RES frame is handled automatically by the NFCT hardware.
939  *
940  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
941  *
942  * @return Value of the Protocol field in the SEL_RES frame.
943  */
944 NRF_STATIC_INLINE
945 nrf_nfct_selres_protocol_t nrf_nfct_selres_protocol_get(NRF_NFCT_Type const * p_reg);
946 
947 /**
948  * @brief Function for setting the Protocol field in the SEL_RES frame configuration.
949  *
950  * @details The SEL_RES frame is handled automatically by the NFCT hardware.
951  *
952  * @param[in] p_reg            Pointer to the structure of registers of the peripheral.
953  * @param[in] sel_res_protocol Value of the Protocol field in the SEL_RES frame.
954  */
955 NRF_STATIC_INLINE void nrf_nfct_selres_protocol_set(NRF_NFCT_Type *            p_reg,
956                                                     nrf_nfct_selres_protocol_t sel_res_protocol);
957 
958 /**
959  * @brief Function for getting the SEL_RES frame configuration.
960  *
961  * @details The SEL_RES frame is handled automatically by the NFCT hardware.
962  *
963  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
964  *
965  * @return SEL_RES frame configuration.
966  */
967 NRF_STATIC_INLINE uint32_t nrf_nfct_selres_get(NRF_NFCT_Type const * p_reg);
968 
969 /**
970  * @brief Function for setting the SEL_RES frame configuration.
971  *
972  * @details The SEL_RES frame is handled automatically by the NFCT hardware.
973  *
974  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
975  * @param[in] selres SEL_RES frame configuration.
976  */
977 NRF_STATIC_INLINE void nrf_nfct_selres_set(NRF_NFCT_Type * p_reg, uint32_t selres);
978 
979 #if NRF_NFCT_HAS_PAD_CONFIG_REG
980 /**
981  * @brief Function for enabling or disabling the NFC pad configuration.
982  *
983  * @details When the NFC pads are enabled, they are configured as the NFC
984  *          antenna pins, and the NFC pins protection mechanism is enabled.
985  *          When the NFC pads are disabled, they are configured as GPIO pins.
986  *
987  * @param[in] p_reg  Pointer to the structure of registers of the peripheral.
988  * @param[in] enable True if the NFC pads are to be enabled, false otherwise.
989  */
990 NRF_STATIC_INLINE void nrf_nfct_pad_config_enable_set(NRF_NFCT_Type * p_reg, bool enable);
991 
992 /**
993  * @brief Function for checking the NFC pads configuration.
994  *
995  * @details When the NFC pads are enabled, they are configured as the NFC
996  *          antenna pins, and the NFC pins protection mechanism is enabled.
997  *          When the NFC pads are disabled, they are configured as GPIO pins.
998  *
999  * @param[in] p_reg Pointer to the structure of registers of the peripheral.
1000  *
1001  * @retval true  NFC pads are enabled.
1002  * @retval false NFC pads are disabled.
1003  */
1004 NRF_STATIC_INLINE bool nrf_nfct_pad_config_enable_check(NRF_NFCT_Type const * p_reg);
1005 #endif // NRF_NFCT_HAS_PAD_CONFIG_REG
1006 
1007 #if NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG
1008 /**
1009  * @brief Function for setting the bias configuration.
1010  *
1011  * @param[in] p_reg         Pointer to the structure of registers of the peripheral.
1012  * @param[in] p_bias_config Pointer to the structure of bias configuration parameters.
1013  */
1014 NRF_STATIC_INLINE void nrf_nfct_bias_config_set(NRF_NFCT_Type *                p_reg,
1015                                                 nrf_nfct_bias_config_t const * p_bias_config);
1016 
1017 /**
1018  * @brief Function for getting the bias configuration.
1019  *
1020  * @param[in] p_reg         Pointer to the structure of registers of the peripheral.
1021  * @param[in] p_bias_config Pointer to the structure to be filled with bias configuration parameters.
1022  */
1023 NRF_STATIC_INLINE void nrf_nfct_bias_config_get(NRF_NFCT_Type const *    p_reg,
1024                                                 nrf_nfct_bias_config_t * p_bias_config);
1025 #endif // NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG
1026 
1027 #ifndef NRF_DECLARE_ONLY
nrf_nfct_task_trigger(NRF_NFCT_Type * p_reg,nrf_nfct_task_t task)1028 NRF_STATIC_INLINE void nrf_nfct_task_trigger(NRF_NFCT_Type * p_reg, nrf_nfct_task_t task)
1029 {
1030     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 1UL;
1031 }
1032 
nrf_nfct_task_address_get(NRF_NFCT_Type const * p_reg,nrf_nfct_task_t task)1033 NRF_STATIC_INLINE uint32_t nrf_nfct_task_address_get(NRF_NFCT_Type const * p_reg,
1034                                                      nrf_nfct_task_t       task)
1035 {
1036     return nrf_task_event_address_get(p_reg, task);
1037 }
1038 
nrf_nfct_event_clear(NRF_NFCT_Type * p_reg,nrf_nfct_event_t event)1039 NRF_STATIC_INLINE void nrf_nfct_event_clear(NRF_NFCT_Type * p_reg, nrf_nfct_event_t event)
1040 {
1041     *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0UL;
1042     nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
1043 }
1044 
nrf_nfct_event_check(NRF_NFCT_Type const * p_reg,nrf_nfct_event_t event)1045 NRF_STATIC_INLINE bool nrf_nfct_event_check(NRF_NFCT_Type const * p_reg, nrf_nfct_event_t event)
1046 {
1047     return nrf_event_check(p_reg, event);
1048 }
1049 
nrf_nfct_event_address_get(NRF_NFCT_Type const * p_reg,nrf_nfct_event_t event)1050 NRF_STATIC_INLINE uint32_t nrf_nfct_event_address_get(NRF_NFCT_Type const * p_reg,
1051                                                       nrf_nfct_event_t      event)
1052 {
1053     return nrf_task_event_address_get(p_reg, event);
1054 }
1055 
nrf_nfct_shorts_enable(NRF_NFCT_Type * p_reg,uint32_t short_mask)1056 NRF_STATIC_INLINE void nrf_nfct_shorts_enable(NRF_NFCT_Type * p_reg, uint32_t short_mask)
1057 {
1058     p_reg->SHORTS |= short_mask;
1059 }
1060 
nrf_nfct_shorts_disable(NRF_NFCT_Type * p_reg,uint32_t short_mask)1061 NRF_STATIC_INLINE void nrf_nfct_shorts_disable(NRF_NFCT_Type * p_reg, uint32_t short_mask)
1062 {
1063     p_reg->SHORTS &= ~short_mask;
1064 }
1065 
nrf_nfct_shorts_get(NRF_NFCT_Type const * p_reg)1066 NRF_STATIC_INLINE uint32_t nrf_nfct_shorts_get(NRF_NFCT_Type const * p_reg)
1067 {
1068     return p_reg->SHORTS;
1069 }
1070 
nrf_nfct_shorts_set(NRF_NFCT_Type * p_reg,uint32_t short_mask)1071 NRF_STATIC_INLINE void nrf_nfct_shorts_set(NRF_NFCT_Type * p_reg, uint32_t short_mask)
1072 {
1073     p_reg->SHORTS = short_mask;
1074 }
1075 
nrf_nfct_int_enable(NRF_NFCT_Type * p_reg,uint32_t mask)1076 NRF_STATIC_INLINE void nrf_nfct_int_enable(NRF_NFCT_Type * p_reg, uint32_t mask)
1077 {
1078     p_reg->INTENSET = mask;
1079 }
1080 
nrf_nfct_int_enable_check(NRF_NFCT_Type const * p_reg,uint32_t mask)1081 NRF_STATIC_INLINE uint32_t nrf_nfct_int_enable_check(NRF_NFCT_Type const * p_reg, uint32_t mask)
1082 {
1083     return p_reg->INTENSET & mask;
1084 }
1085 
nrf_nfct_int_enable_get(NRF_NFCT_Type const * p_reg)1086 NRF_STATIC_INLINE uint32_t nrf_nfct_int_enable_get(NRF_NFCT_Type const * p_reg)
1087 {
1088     return p_reg->INTENSET;
1089 }
1090 
nrf_nfct_int_disable(NRF_NFCT_Type * p_reg,uint32_t mask)1091 NRF_STATIC_INLINE void nrf_nfct_int_disable(NRF_NFCT_Type * p_reg, uint32_t mask)
1092 {
1093     p_reg->INTENCLR = mask;
1094 }
1095 
1096 #if NRF_NFCT_HAS_MODULATION_PSEL_REG
nrf_nfct_mod_ctrl_pin_set(NRF_NFCT_Type * p_reg,uint32_t mod_ctrl_pin)1097 NRF_STATIC_INLINE void nrf_nfct_mod_ctrl_pin_set(NRF_NFCT_Type * p_reg, uint32_t mod_ctrl_pin)
1098 {
1099     p_reg->MODULATIONPSEL = mod_ctrl_pin;
1100 }
1101 
nrf_nfct_mod_ctrl_pin_get(NRF_NFCT_Type const * p_reg)1102 NRF_STATIC_INLINE uint32_t nrf_nfct_mod_ctrl_pin_get(NRF_NFCT_Type const * p_reg)
1103 {
1104     return p_reg->MODULATIONPSEL;
1105 }
1106 #endif // NRF_NFCT_HAS_MODULATION_PSEL_REG
1107 
1108 #if NRF_NFCT_HAS_MODULATION_CTRL_REG
nrf_nfct_modulation_output_set(NRF_NFCT_Type * p_reg,nrf_nfct_modulation_ctrl_t mod_ctrl)1109 NRF_STATIC_INLINE void nrf_nfct_modulation_output_set(NRF_NFCT_Type *            p_reg,
1110                                                       nrf_nfct_modulation_ctrl_t mod_ctrl)
1111 {
1112     p_reg->MODULATIONCTRL = (uint32_t)mod_ctrl;
1113 }
1114 
1115 NRF_STATIC_INLINE
nrf_nfct_modulation_output_get(NRF_NFCT_Type const * p_reg)1116 nrf_nfct_modulation_ctrl_t nrf_nfct_modulation_output_get(NRF_NFCT_Type const * p_reg)
1117 {
1118     return (nrf_nfct_modulation_ctrl_t)(p_reg->MODULATIONCTRL &
1119                                         NFCT_MODULATIONCTRL_MODULATIONCTRL_Msk);
1120 }
1121 #endif // NRF_NFCT_HAS_MODULATION_CTRL_REG
1122 
nrf_nfct_error_status_get(NRF_NFCT_Type const * p_reg)1123 NRF_STATIC_INLINE uint32_t nrf_nfct_error_status_get(NRF_NFCT_Type const * p_reg)
1124 {
1125     return p_reg->ERRORSTATUS;
1126 }
1127 
nrf_nfct_error_status_clear(NRF_NFCT_Type * p_reg,uint32_t error_flags)1128 NRF_STATIC_INLINE void nrf_nfct_error_status_clear(NRF_NFCT_Type * p_reg, uint32_t error_flags)
1129 {
1130     p_reg->ERRORSTATUS = error_flags;
1131 }
1132 
nrf_nfct_rx_frame_status_get(NRF_NFCT_Type const * p_reg)1133 NRF_STATIC_INLINE uint32_t nrf_nfct_rx_frame_status_get(NRF_NFCT_Type const * p_reg)
1134 {
1135     return p_reg->FRAMESTATUS.RX;
1136 }
1137 
nrf_nfct_rx_frame_status_clear(NRF_NFCT_Type * p_reg,uint32_t framestatus_flags)1138 NRF_STATIC_INLINE void nrf_nfct_rx_frame_status_clear(NRF_NFCT_Type * p_reg,
1139                                                       uint32_t        framestatus_flags)
1140 {
1141     p_reg->FRAMESTATUS.RX = framestatus_flags;
1142 }
1143 
1144 #if NRF_NFCT_HAS_TAG_STATE_REG
nrf_nfct_tag_state_get(NRF_NFCT_Type const * p_reg)1145 NRF_STATIC_INLINE nrf_nfct_tag_state_t nrf_nfct_tag_state_get(NRF_NFCT_Type const * p_reg)
1146 {
1147     return (nrf_nfct_tag_state_t)((p_reg->NFCTAGSTATE & NFCT_NFCTAGSTATE_NFCTAGSTATE_Msk) >>
1148                                   NFCT_NFCTAGSTATE_NFCTAGSTATE_Pos);
1149 }
1150 #endif // NRF_NFCT_HAS_TAG_STATE_REG
1151 
1152 #if NRF_NFCT_HAS_SLEEP_STATE_REG
nrf_nfct_sleep_state_get(NRF_NFCT_Type const * p_reg)1153 NRF_STATIC_INLINE nrf_nfct_sleep_state_t nrf_nfct_sleep_state_get(NRF_NFCT_Type const * p_reg)
1154 {
1155     return (nrf_nfct_sleep_state_t)((p_reg->SLEEPSTATE & NFCT_SLEEPSTATE_SLEEPSTATE_Msk) >>
1156                                     NFCT_SLEEPSTATE_SLEEPSTATE_Pos);
1157 }
1158 #endif // NRF_NFCT_HAS_SLEEP_STATE_REG
1159 
nrf_nfct_field_status_get(NRF_NFCT_Type const * p_reg)1160 NRF_STATIC_INLINE uint8_t nrf_nfct_field_status_get(NRF_NFCT_Type const * p_reg)
1161 {
1162     return (uint8_t)(p_reg->FIELDPRESENT);
1163 }
1164 
nrf_nfct_frame_delay_min_get(NRF_NFCT_Type const * p_reg)1165 NRF_STATIC_INLINE uint16_t nrf_nfct_frame_delay_min_get(NRF_NFCT_Type const * p_reg)
1166 {
1167     return (uint16_t)((p_reg->FRAMEDELAYMIN & NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Msk) >>
1168                       NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Pos);
1169 }
1170 
nrf_nfct_frame_delay_min_set(NRF_NFCT_Type * p_reg,uint16_t frame_delay_min)1171 NRF_STATIC_INLINE void nrf_nfct_frame_delay_min_set(NRF_NFCT_Type * p_reg, uint16_t frame_delay_min)
1172 {
1173     p_reg->FRAMEDELAYMIN =
1174         ((uint32_t)frame_delay_min << NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Pos) &
1175         NFCT_FRAMEDELAYMIN_FRAMEDELAYMIN_Msk;
1176 }
1177 
nrf_nfct_frame_delay_max_get(NRF_NFCT_Type const * p_reg)1178 NRF_STATIC_INLINE uint32_t nrf_nfct_frame_delay_max_get(NRF_NFCT_Type const * p_reg)
1179 {
1180     return (p_reg->FRAMEDELAYMAX & NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk) >>
1181            NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Pos;
1182 }
1183 
nrf_nfct_frame_delay_max_set(NRF_NFCT_Type * p_reg,uint32_t frame_delay_max)1184 NRF_STATIC_INLINE void nrf_nfct_frame_delay_max_set(NRF_NFCT_Type * p_reg, uint32_t frame_delay_max)
1185 {
1186     p_reg->FRAMEDELAYMAX =
1187         ((uint32_t)frame_delay_max << NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Pos) &
1188         NFCT_FRAMEDELAYMAX_FRAMEDELAYMAX_Msk;
1189 }
1190 
1191 NRF_STATIC_INLINE
nrf_nfct_frame_delay_mode_get(NRF_NFCT_Type const * p_reg)1192 nrf_nfct_frame_delay_mode_t nrf_nfct_frame_delay_mode_get(NRF_NFCT_Type const * p_reg)
1193 {
1194     return (nrf_nfct_frame_delay_mode_t)(p_reg->FRAMEDELAYMODE &
1195                                          NFCT_FRAMEDELAYMODE_FRAMEDELAYMODE_Msk);
1196 }
1197 
nrf_nfct_frame_delay_mode_set(NRF_NFCT_Type * p_reg,nrf_nfct_frame_delay_mode_t frame_delay_mode)1198 NRF_STATIC_INLINE void nrf_nfct_frame_delay_mode_set(NRF_NFCT_Type *             p_reg,
1199                                                      nrf_nfct_frame_delay_mode_t frame_delay_mode)
1200 {
1201     p_reg->FRAMEDELAYMODE = (uint32_t)frame_delay_mode;
1202 }
1203 
nrf_nfct_rxtx_buffer_get(NRF_NFCT_Type const * p_reg)1204 NRF_STATIC_INLINE uint8_t * nrf_nfct_rxtx_buffer_get(NRF_NFCT_Type const * p_reg)
1205 {
1206     return (uint8_t *)(p_reg->PACKETPTR);
1207 }
1208 
nrf_nfct_rxtx_buffer_set(NRF_NFCT_Type * p_reg,uint8_t * p_rxtx_buf,uint16_t max_txrx_len)1209 NRF_STATIC_INLINE void nrf_nfct_rxtx_buffer_set(NRF_NFCT_Type * p_reg,
1210                                                 uint8_t *       p_rxtx_buf,
1211                                                 uint16_t        max_txrx_len)
1212 {
1213     p_reg->PACKETPTR = (uint32_t)p_rxtx_buf;
1214     p_reg->MAXLEN    = ((uint32_t)max_txrx_len << NFCT_MAXLEN_MAXLEN_Pos) & NFCT_MAXLEN_MAXLEN_Msk;
1215 }
1216 
nrf_nfct_max_rxtx_length_get(NRF_NFCT_Type const * p_reg)1217 NRF_STATIC_INLINE uint16_t nrf_nfct_max_rxtx_length_get(NRF_NFCT_Type const * p_reg)
1218 {
1219     return (uint16_t)((p_reg->MAXLEN & NFCT_MAXLEN_MAXLEN_Msk) >> NFCT_MAXLEN_MAXLEN_Pos);
1220 }
1221 
nrf_nfct_tx_frame_config_get(NRF_NFCT_Type const * p_reg)1222 NRF_STATIC_INLINE uint8_t nrf_nfct_tx_frame_config_get(NRF_NFCT_Type const * p_reg)
1223 {
1224     return (uint8_t)(p_reg->TXD.FRAMECONFIG);
1225 }
1226 
nrf_nfct_tx_frame_config_set(NRF_NFCT_Type * p_reg,uint8_t flags)1227 NRF_STATIC_INLINE void nrf_nfct_tx_frame_config_set(NRF_NFCT_Type * p_reg, uint8_t flags)
1228 {
1229     p_reg->TXD.FRAMECONFIG = flags;
1230 }
1231 
nrf_nfct_tx_bits_get(NRF_NFCT_Type const * p_reg)1232 NRF_STATIC_INLINE uint16_t nrf_nfct_tx_bits_get(NRF_NFCT_Type const * p_reg)
1233 {
1234     return (uint16_t)(p_reg->TXD.AMOUNT & (NFCT_TXD_AMOUNT_TXDATABITS_Msk |
1235                                            NFCT_TXD_AMOUNT_TXDATABYTES_Msk));
1236 }
1237 
nrf_nfct_tx_bits_set(NRF_NFCT_Type * p_reg,uint16_t tx_bits)1238 NRF_STATIC_INLINE void nrf_nfct_tx_bits_set(NRF_NFCT_Type * p_reg, uint16_t tx_bits)
1239 {
1240     p_reg->TXD.AMOUNT = (tx_bits & (NFCT_TXD_AMOUNT_TXDATABITS_Msk |
1241                                     NFCT_TXD_AMOUNT_TXDATABYTES_Msk));
1242 }
1243 
nrf_nfct_rx_frame_config_get(NRF_NFCT_Type const * p_reg)1244 NRF_STATIC_INLINE uint8_t nrf_nfct_rx_frame_config_get(NRF_NFCT_Type const * p_reg)
1245 {
1246     return (uint8_t)(p_reg->RXD.FRAMECONFIG);
1247 }
1248 
nrf_nfct_rx_frame_config_set(NRF_NFCT_Type * p_reg,uint8_t flags)1249 NRF_STATIC_INLINE void nrf_nfct_rx_frame_config_set(NRF_NFCT_Type * p_reg, uint8_t flags)
1250 {
1251     p_reg->RXD.FRAMECONFIG = flags;
1252 }
1253 
nrf_nfct_rx_bits_get(NRF_NFCT_Type const * p_reg,bool crc_excluded)1254 NRF_STATIC_INLINE uint16_t nrf_nfct_rx_bits_get(NRF_NFCT_Type const * p_reg, bool crc_excluded)
1255 {
1256     uint16_t rx_bits = p_reg->RXD.AMOUNT & (NFCT_RXD_AMOUNT_RXDATABITS_Msk |
1257                                             NFCT_RXD_AMOUNT_RXDATABYTES_Msk);
1258     return (uint16_t)(rx_bits - (crc_excluded ? (8u * NRF_NFCT_CRC_SIZE) : 0));
1259 }
1260 
1261 NRF_STATIC_INLINE
nrf_nfct_nfcid1_get(NRF_NFCT_Type const * p_reg,uint8_t * p_nfcid1_buf)1262 nrf_nfct_sensres_nfcid1_size_t nrf_nfct_nfcid1_get(NRF_NFCT_Type const * p_reg,
1263                                                    uint8_t *             p_nfcid1_buf)
1264 {
1265 #if NRF_NFCID1_HAS_NEW_LAYOUT
1266     uint32_t nfcid1_last = p_reg->NFCID1.LAST;
1267 #else
1268     uint32_t nfcid1_last = p_reg->NFCID1_LAST;
1269 #endif
1270     nrf_nfct_sensres_nfcid1_size_t size =
1271         (nrf_nfct_sensres_nfcid1_size_t)(p_reg->SENSRES & NFCT_SENSRES_NFCIDSIZE_Msk);
1272 
1273     if (size != NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE)
1274     {
1275 #if NRF_NFCID1_HAS_NEW_LAYOUT
1276         uint32_t nfcid1_2nd_last = p_reg->NFCID1.SECONDLAST;
1277 #else
1278         uint32_t nfcid1_2nd_last = p_reg->NFCID1_2ND_LAST;
1279 #endif
1280 
1281         if (size == NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE)
1282         {
1283 #if NRF_NFCID1_HAS_NEW_LAYOUT
1284             uint32_t nfcid1_3rd_last = p_reg->NFCID1.THIRDLAST;
1285 #else
1286             uint32_t nfcid1_3rd_last = p_reg->NFCID1_3RD_LAST;
1287 #endif
1288 
1289             *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 16UL);
1290             *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 8UL);
1291             *p_nfcid1_buf++ = (uint8_t)(nfcid1_3rd_last >> 0UL);
1292         }
1293 
1294         *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 16UL);
1295         *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 8UL);
1296         *p_nfcid1_buf++ = (uint8_t)(nfcid1_2nd_last >> 0UL);
1297     }
1298 
1299     *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 24UL);
1300     *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 16UL);
1301     *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 8UL);
1302     *p_nfcid1_buf++ = (uint8_t)(nfcid1_last >> 0UL);
1303 
1304     return size;
1305 }
1306 
nrf_nfct_nfcid1_set(NRF_NFCT_Type * p_reg,uint8_t const * p_nfcid1_buf,nrf_nfct_sensres_nfcid1_size_t nfcid1_size)1307 NRF_STATIC_INLINE void nrf_nfct_nfcid1_set(NRF_NFCT_Type *                p_reg,
1308                                            uint8_t const *                p_nfcid1_buf,
1309                                            nrf_nfct_sensres_nfcid1_size_t nfcid1_size)
1310 {
1311     nrf_nfct_sensres_nfcid1_size_t size = (nfcid1_size == NRF_NFCT_SENSRES_NFCID1_SIZE_DEFAULT) ?
1312         NRF_NFCT_SENSRES_NFCID1_SIZE_DOUBLE : nfcid1_size;
1313 
1314     if (size != NRF_NFCT_SENSRES_NFCID1_SIZE_SINGLE)
1315     {
1316         if (size == NRF_NFCT_SENSRES_NFCID1_SIZE_TRIPLE)
1317         {
1318 #if NRF_NFCID1_HAS_NEW_LAYOUT
1319             p_reg->NFCID1.THIRDLAST =
1320 #else
1321             p_reg->NFCID1_3RD_LAST =
1322 #endif
1323                                         ((uint32_t)p_nfcid1_buf[0] << 16UL) |
1324                                         ((uint32_t)p_nfcid1_buf[1] << 8UL)  |
1325                                         ((uint32_t)p_nfcid1_buf[2] << 0UL);
1326             p_nfcid1_buf += 3UL;
1327         }
1328 #if NRF_NFCID1_HAS_NEW_LAYOUT
1329         p_reg->NFCID1.SECONDLAST =
1330 #else
1331         p_reg->NFCID1_2ND_LAST =
1332 #endif
1333                                     ((uint32_t)p_nfcid1_buf[0] << 16UL) |
1334                                     ((uint32_t)p_nfcid1_buf[1] << 8UL)  |
1335                                     ((uint32_t)p_nfcid1_buf[2] << 0UL);
1336         p_nfcid1_buf += 3UL;
1337     }
1338 
1339 #if NRF_NFCID1_HAS_NEW_LAYOUT
1340     p_reg->NFCID1.LAST =
1341 #else
1342     p_reg->NFCID1_LAST =
1343 #endif
1344                             ((uint32_t)p_nfcid1_buf[0] << 24UL) |
1345                             ((uint32_t)p_nfcid1_buf[1] << 16UL) |
1346                             ((uint32_t)p_nfcid1_buf[2] << 8UL)  |
1347                             ((uint32_t)p_nfcid1_buf[3] << 0UL);
1348 
1349     p_reg->SENSRES = ((p_reg->SENSRES & ~NFCT_SENSRES_NFCIDSIZE_Msk) |
1350                          (uint32_t)size);
1351 }
1352 
1353 #if NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG
nrf_nfct_autocolres_is_enabled(NRF_NFCT_Type const * p_reg)1354 NRF_STATIC_INLINE bool nrf_nfct_autocolres_is_enabled(NRF_NFCT_Type const * p_reg)
1355 {
1356     return (p_reg->AUTOCOLRESCONFIG & NFCT_AUTOCOLRESCONFIG_MODE_Msk) ==
1357            (NFCT_AUTOCOLRESCONFIG_MODE_Enabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos);
1358 }
1359 
nrf_nfct_autocolres_enable(NRF_NFCT_Type * p_reg)1360 NRF_STATIC_INLINE void nrf_nfct_autocolres_enable(NRF_NFCT_Type * p_reg)
1361 {
1362     p_reg->AUTOCOLRESCONFIG =
1363         (p_reg->AUTOCOLRESCONFIG & ~NFCT_AUTOCOLRESCONFIG_MODE_Msk) |
1364         (NFCT_AUTOCOLRESCONFIG_MODE_Enabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos);
1365 }
1366 
nrf_nfct_autocolres_disable(NRF_NFCT_Type * p_reg)1367 NRF_STATIC_INLINE void nrf_nfct_autocolres_disable(NRF_NFCT_Type * p_reg)
1368 {
1369     p_reg->AUTOCOLRESCONFIG =
1370         (p_reg->AUTOCOLRESCONFIG & ~NFCT_AUTOCOLRESCONFIG_MODE_Msk) |
1371         (NFCT_AUTOCOLRESCONFIG_MODE_Disabled << NFCT_AUTOCOLRESCONFIG_MODE_Pos);
1372 }
1373 #endif // NRF_NFCT_HAS_AUTOCOLRES_CONFIG_REG
1374 
1375 NRF_STATIC_INLINE
nrf_nfct_sensres_nfcid1_size_get(NRF_NFCT_Type const * p_reg)1376 nrf_nfct_sensres_nfcid1_size_t nrf_nfct_sensres_nfcid1_size_get(NRF_NFCT_Type const * p_reg)
1377 {
1378     return (nrf_nfct_sensres_nfcid1_size_t)(p_reg->SENSRES & NFCT_SENSRES_NFCIDSIZE_Msk);
1379 }
1380 
nrf_nfct_sensres_nfcid1_size_set(NRF_NFCT_Type * p_reg,nrf_nfct_sensres_nfcid1_size_t nfcid1_size)1381 NRF_STATIC_INLINE void nrf_nfct_sensres_nfcid1_size_set(NRF_NFCT_Type *                p_reg,
1382                                                         nrf_nfct_sensres_nfcid1_size_t nfcid1_size)
1383 {
1384     p_reg->SENSRES = ((p_reg->SENSRES & ~(NFCT_SENSRES_NFCIDSIZE_Msk)) |
1385                          (uint32_t)nfcid1_size);
1386 }
1387 
1388 NRF_STATIC_INLINE
nrf_nfct_sensres_bit_frame_sdd_get(NRF_NFCT_Type const * p_reg)1389 nrf_nfct_sensres_bit_frame_sdd_t nrf_nfct_sensres_bit_frame_sdd_get(NRF_NFCT_Type const * p_reg)
1390 {
1391     return (nrf_nfct_sensres_bit_frame_sdd_t)(p_reg->SENSRES & NFCT_SENSRES_BITFRAMESDD_Msk);
1392 }
1393 
1394 NRF_STATIC_INLINE
nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_Type * p_reg,nrf_nfct_sensres_bit_frame_sdd_t bit_frame_sdd)1395 void nrf_nfct_sensres_bit_frame_sdd_set(NRF_NFCT_Type *                  p_reg,
1396                                         nrf_nfct_sensres_bit_frame_sdd_t bit_frame_sdd)
1397 {
1398     p_reg->SENSRES = ((p_reg->SENSRES & ~(NFCT_SENSRES_BITFRAMESDD_Msk)) | (uint32_t)bit_frame_sdd);
1399 }
1400 
1401 NRF_STATIC_INLINE
nrf_nfct_sensres_platform_config_get(NRF_NFCT_Type const * p_reg)1402 nrf_nfct_sensres_platform_config_t nrf_nfct_sensres_platform_config_get(NRF_NFCT_Type const * p_reg)
1403 {
1404     return (nrf_nfct_sensres_platform_config_t)(p_reg->SENSRES & NFCT_SENSRES_PLATFCONFIG_Msk);
1405 }
1406 
1407 NRF_STATIC_INLINE
nrf_nfct_sensres_platform_config_set(NRF_NFCT_Type * p_reg,nrf_nfct_sensres_platform_config_t platform_config)1408 void nrf_nfct_sensres_platform_config_set(NRF_NFCT_Type *                    p_reg,
1409                                           nrf_nfct_sensres_platform_config_t platform_config)
1410 {
1411     p_reg->SENSRES = ((p_reg->SENSRES & ~(NFCT_SENSRES_PLATFCONFIG_Msk)) |
1412                       (uint32_t)platform_config);
1413 }
1414 
nrf_nfct_selres_cascade_check(NRF_NFCT_Type const * p_reg)1415 NRF_STATIC_INLINE bool nrf_nfct_selres_cascade_check(NRF_NFCT_Type const * p_reg)
1416 {
1417     return (bool)(p_reg->SELRES & NFCT_SELRES_CASCADE_Msk);
1418 }
1419 
1420 NRF_STATIC_INLINE
nrf_nfct_selres_protocol_get(NRF_NFCT_Type const * p_reg)1421 nrf_nfct_selres_protocol_t nrf_nfct_selres_protocol_get(NRF_NFCT_Type const * p_reg)
1422 {
1423     return (nrf_nfct_selres_protocol_t)((p_reg->SELRES & NFCT_SELRES_PROTOCOL_Msk) >>
1424                                         NFCT_SELRES_PROTOCOL_Pos);
1425 }
1426 
nrf_nfct_selres_protocol_set(NRF_NFCT_Type * p_reg,nrf_nfct_selres_protocol_t sel_res_protocol)1427 NRF_STATIC_INLINE void nrf_nfct_selres_protocol_set(NRF_NFCT_Type *            p_reg,
1428                                                     nrf_nfct_selres_protocol_t sel_res_protocol)
1429 {
1430     p_reg->SELRES = (p_reg->SELRES & ~NFCT_SELRES_PROTOCOL_Msk) |
1431                     ((uint32_t)sel_res_protocol << NFCT_SELRES_PROTOCOL_Pos);
1432 }
1433 
nrf_nfct_selres_get(NRF_NFCT_Type const * p_reg)1434 NRF_STATIC_INLINE uint32_t nrf_nfct_selres_get(NRF_NFCT_Type const * p_reg)
1435 {
1436     return p_reg->SELRES;
1437 }
1438 
nrf_nfct_selres_set(NRF_NFCT_Type * p_reg,uint32_t selres)1439 NRF_STATIC_INLINE void nrf_nfct_selres_set(NRF_NFCT_Type * p_reg, uint32_t selres)
1440 {
1441     p_reg->SELRES = (p_reg->SELRES & NFCT_SELRES_CASCADE_Msk) | (selres & ~NFCT_SELRES_CASCADE_Msk);
1442 }
1443 
1444 #if NRF_NFCT_HAS_PAD_CONFIG_REG
nrf_nfct_pad_config_enable_set(NRF_NFCT_Type * p_reg,bool enable)1445 NRF_STATIC_INLINE void nrf_nfct_pad_config_enable_set(NRF_NFCT_Type * p_reg, bool enable)
1446 {
1447     p_reg->PADCONFIG = (enable ?
1448                         NFCT_PADCONFIG_ENABLE_Enabled :
1449                         NFCT_PADCONFIG_ENABLE_Disabled) <<
1450                        NFCT_PADCONFIG_ENABLE_Pos;
1451 }
1452 
nrf_nfct_pad_config_enable_check(NRF_NFCT_Type const * p_reg)1453 NRF_STATIC_INLINE bool nrf_nfct_pad_config_enable_check(NRF_NFCT_Type const * p_reg)
1454 {
1455     return (bool)(((p_reg->PADCONFIG & NFCT_PADCONFIG_ENABLE_Msk) >> NFCT_PADCONFIG_ENABLE_Pos));
1456 }
1457 #endif // NRF_NFCT_HAS_PAD_CONFIG_REG
1458 
1459 #if NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG
nrf_nfct_bias_config_set(NRF_NFCT_Type * p_reg,nrf_nfct_bias_config_t const * p_bias_config)1460 NRF_STATIC_INLINE void nrf_nfct_bias_config_set(NRF_NFCT_Type *                p_reg,
1461                                                 nrf_nfct_bias_config_t const * p_bias_config)
1462 {
1463     NRFX_ASSERT(p_bias_config != NULL);
1464 
1465     p_reg->BIASCFG = (((p_bias_config->trim_ibpsr <<
1466                         NFCT_BIASCFG_TRIMIBPSR_Pos) &
1467                        NFCT_BIASCFG_TRIMIBPSR_Msk) |
1468                       ((p_bias_config->coarse_ibpsr <<
1469                         NFCT_BIASCFG_COARSEIBPSR_Pos) &
1470                        NFCT_BIASCFG_COARSEIBPSR_Msk) |
1471                       ((p_bias_config->reference_volatge <<
1472                         NFCT_BIASCFG_REFERENCEVOLTAGE_Pos) &
1473                        NFCT_BIASCFG_REFERENCEVOLTAGE_Msk) |
1474                       ((p_bias_config->spare <<
1475                         NFCT_BIASCFG_SPARE_Pos) &
1476                        NFCT_BIASCFG_SPARE_Msk));
1477 }
1478 
nrf_nfct_bias_config_get(NRF_NFCT_Type const * p_reg,nrf_nfct_bias_config_t * p_bias_config)1479 NRF_STATIC_INLINE void nrf_nfct_bias_config_get(NRF_NFCT_Type const *    p_reg,
1480                                                 nrf_nfct_bias_config_t * p_bias_config)
1481 {
1482     NRFX_ASSERT(p_bias_config != NULL);
1483 
1484     p_bias_config->trim_ibpsr = (p_reg->BIASCFG & NFCT_BIASCFG_TRIMIBPSR_Msk)
1485                                 >> NFCT_BIASCFG_TRIMIBPSR_Pos;
1486 
1487     p_bias_config->coarse_ibpsr = (p_reg->BIASCFG & NFCT_BIASCFG_COARSEIBPSR_Msk)
1488                                   >> NFCT_BIASCFG_COARSEIBPSR_Pos;
1489 
1490     p_bias_config->reference_volatge = (p_reg->BIASCFG & NFCT_BIASCFG_REFERENCEVOLTAGE_Msk)
1491                                        >> NFCT_BIASCFG_REFERENCEVOLTAGE_Pos;
1492 
1493     p_bias_config->spare = (p_reg->BIASCFG & NFCT_BIASCFG_SPARE_Msk)
1494                            >> NFCT_BIASCFG_SPARE_Pos;
1495 }
1496 #endif // NRF_NFCT_HAS_BIAS_CONFIG_TRIM_REG
1497 
1498 #endif /* NRF_DECLARE_ONLY */
1499 
1500 /** @} */
1501 
1502 #ifdef __cplusplus
1503 }
1504 #endif
1505 
1506 #endif /* NRF_NFCT_H__ */
1507