1 /*
2 * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from this
17 * software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #ifndef NRF_USBD_H__
33 #define NRF_USBD_H__
34
35 #include <nrfx.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42 * @defgroup nrf_usbd_hal USBD HAL
43 * @{
44 * @ingroup nrf_usbd
45 * @brief Hardware access layer for managing the Universal Serial Bus Device (USBD)
46 * peripheral.
47 */
48
49 /**
50 * @brief USBD tasks
51 */
52 typedef enum
53 {
54 /*lint -save -e30*/
55 NRF_USBD_TASK_STARTEPIN0 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[0] ), /**< Captures the EPIN[0].PTR, EPIN[0].MAXCNT and EPIN[0].CONFIG registers values, and enables control endpoint IN 0 to respond to traffic from host */
56 NRF_USBD_TASK_STARTEPIN1 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[1] ), /**< Captures the EPIN[1].PTR, EPIN[1].MAXCNT and EPIN[1].CONFIG registers values, and enables data endpoint IN 1 to respond to traffic from host */
57 NRF_USBD_TASK_STARTEPIN2 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[2] ), /**< Captures the EPIN[2].PTR, EPIN[2].MAXCNT and EPIN[2].CONFIG registers values, and enables data endpoint IN 2 to respond to traffic from host */
58 NRF_USBD_TASK_STARTEPIN3 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[3] ), /**< Captures the EPIN[3].PTR, EPIN[3].MAXCNT and EPIN[3].CONFIG registers values, and enables data endpoint IN 3 to respond to traffic from host */
59 NRF_USBD_TASK_STARTEPIN4 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[4] ), /**< Captures the EPIN[4].PTR, EPIN[4].MAXCNT and EPIN[4].CONFIG registers values, and enables data endpoint IN 4 to respond to traffic from host */
60 NRF_USBD_TASK_STARTEPIN5 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[5] ), /**< Captures the EPIN[5].PTR, EPIN[5].MAXCNT and EPIN[5].CONFIG registers values, and enables data endpoint IN 5 to respond to traffic from host */
61 NRF_USBD_TASK_STARTEPIN6 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[6] ), /**< Captures the EPIN[6].PTR, EPIN[6].MAXCNT and EPIN[6].CONFIG registers values, and enables data endpoint IN 6 to respond to traffic from host */
62 NRF_USBD_TASK_STARTEPIN7 = offsetof(NRF_USBD_Type, TASKS_STARTEPIN[7] ), /**< Captures the EPIN[7].PTR, EPIN[7].MAXCNT and EPIN[7].CONFIG registers values, and enables data endpoint IN 7 to respond to traffic from host */
63 NRF_USBD_TASK_STARTISOIN = offsetof(NRF_USBD_Type, TASKS_STARTISOIN ), /**< Captures the ISOIN.PTR, ISOIN.MAXCNT and ISOIN.CONFIG registers values, and enables sending data on iso endpoint 8 */
64 NRF_USBD_TASK_STARTEPOUT0 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[0]), /**< Captures the EPOUT[0].PTR, EPOUT[0].MAXCNT and EPOUT[0].CONFIG registers values, and enables control endpoint 0 to respond to traffic from host */
65 NRF_USBD_TASK_STARTEPOUT1 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[1]), /**< Captures the EPOUT[1].PTR, EPOUT[1].MAXCNT and EPOUT[1].CONFIG registers values, and enables data endpoint 1 to respond to traffic from host */
66 NRF_USBD_TASK_STARTEPOUT2 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[2]), /**< Captures the EPOUT[2].PTR, EPOUT[2].MAXCNT and EPOUT[2].CONFIG registers values, and enables data endpoint 2 to respond to traffic from host */
67 NRF_USBD_TASK_STARTEPOUT3 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[3]), /**< Captures the EPOUT[3].PTR, EPOUT[3].MAXCNT and EPOUT[3].CONFIG registers values, and enables data endpoint 3 to respond to traffic from host */
68 NRF_USBD_TASK_STARTEPOUT4 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[4]), /**< Captures the EPOUT[4].PTR, EPOUT[4].MAXCNT and EPOUT[4].CONFIG registers values, and enables data endpoint 4 to respond to traffic from host */
69 NRF_USBD_TASK_STARTEPOUT5 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[5]), /**< Captures the EPOUT[5].PTR, EPOUT[5].MAXCNT and EPOUT[5].CONFIG registers values, and enables data endpoint 5 to respond to traffic from host */
70 NRF_USBD_TASK_STARTEPOUT6 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[6]), /**< Captures the EPOUT[6].PTR, EPOUT[6].MAXCNT and EPOUT[6].CONFIG registers values, and enables data endpoint 6 to respond to traffic from host */
71 NRF_USBD_TASK_STARTEPOUT7 = offsetof(NRF_USBD_Type, TASKS_STARTEPOUT[7]), /**< Captures the EPOUT[7].PTR, EPOUT[7].MAXCNT and EPOUT[7].CONFIG registers values, and enables data endpoint 7 to respond to traffic from host */
72 NRF_USBD_TASK_STARTISOOUT = offsetof(NRF_USBD_Type, TASKS_STARTISOOUT ), /**< Captures the ISOOUT.PTR, ISOOUT.MAXCNT and ISOOUT.CONFIG registers values, and enables receiving of data on iso endpoint 8 */
73 NRF_USBD_TASK_EP0RCVOUT = offsetof(NRF_USBD_Type, TASKS_EP0RCVOUT ), /**< Allows OUT data stage on control endpoint 0 */
74 NRF_USBD_TASK_EP0STATUS = offsetof(NRF_USBD_Type, TASKS_EP0STATUS ), /**< Allows status stage on control endpoint 0 */
75 NRF_USBD_TASK_EP0STALL = offsetof(NRF_USBD_Type, TASKS_EP0STALL ), /**< STALLs data and status stage on control endpoint 0 */
76 NRF_USBD_TASK_DRIVEDPDM = offsetof(NRF_USBD_Type, TASKS_DPDMDRIVE ), /**< Forces D+ and D-lines to the state defined in the DPDMVALUE register */
77 NRF_USBD_TASK_NODRIVEDPDM = offsetof(NRF_USBD_Type, TASKS_DPDMNODRIVE ), /**< Stops forcing D+ and D- lines to any state (USB engine takes control) */
78 /*lint -restore*/
79 }nrf_usbd_task_t;
80
81 /**
82 * @brief USBD events
83 */
84 typedef enum
85 {
86 /*lint -save -e30*/
87 NRF_USBD_EVENT_USBRESET = offsetof(NRF_USBD_Type, EVENTS_USBRESET ), /**< Signals that a USB reset condition has been detected on the USB lines */
88 NRF_USBD_EVENT_STARTED = offsetof(NRF_USBD_Type, EVENTS_STARTED ), /**< Confirms that the EPIN[n].PTR, EPIN[n].MAXCNT, EPIN[n].CONFIG, or EPOUT[n].PTR, EPOUT[n].MAXCNT and EPOUT[n].CONFIG registers have been captured on all endpoints reported in the EPSTATUS register */
89 NRF_USBD_EVENT_ENDEPIN0 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[0] ), /**< The whole EPIN[0] buffer has been consumed. The RAM buffer can be accessed safely by software. */
90 NRF_USBD_EVENT_ENDEPIN1 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[1] ), /**< The whole EPIN[1] buffer has been consumed. The RAM buffer can be accessed safely by software. */
91 NRF_USBD_EVENT_ENDEPIN2 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[2] ), /**< The whole EPIN[2] buffer has been consumed. The RAM buffer can be accessed safely by software. */
92 NRF_USBD_EVENT_ENDEPIN3 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[3] ), /**< The whole EPIN[3] buffer has been consumed. The RAM buffer can be accessed safely by software. */
93 NRF_USBD_EVENT_ENDEPIN4 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[4] ), /**< The whole EPIN[4] buffer has been consumed. The RAM buffer can be accessed safely by software. */
94 NRF_USBD_EVENT_ENDEPIN5 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[5] ), /**< The whole EPIN[5] buffer has been consumed. The RAM buffer can be accessed safely by software. */
95 NRF_USBD_EVENT_ENDEPIN6 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[6] ), /**< The whole EPIN[6] buffer has been consumed. The RAM buffer can be accessed safely by software. */
96 NRF_USBD_EVENT_ENDEPIN7 = offsetof(NRF_USBD_Type, EVENTS_ENDEPIN[7] ), /**< The whole EPIN[7] buffer has been consumed. The RAM buffer can be accessed safely by software. */
97 NRF_USBD_EVENT_EP0DATADONE = offsetof(NRF_USBD_Type, EVENTS_EP0DATADONE), /**< An acknowledged data transfer has taken place on the control endpoint */
98 NRF_USBD_EVENT_ENDISOIN0 = offsetof(NRF_USBD_Type, EVENTS_ENDISOIN ), /**< The whole ISOIN buffer has been consumed. The RAM buffer can be accessed safely by software. */
99 NRF_USBD_EVENT_ENDEPOUT0 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[0]), /**< The whole EPOUT[0] buffer has been consumed. The RAM buffer can be accessed safely by software. */
100 NRF_USBD_EVENT_ENDEPOUT1 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[1]), /**< The whole EPOUT[1] buffer has been consumed. The RAM buffer can be accessed safely by software. */
101 NRF_USBD_EVENT_ENDEPOUT2 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[2]), /**< The whole EPOUT[2] buffer has been consumed. The RAM buffer can be accessed safely by software. */
102 NRF_USBD_EVENT_ENDEPOUT3 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[3]), /**< The whole EPOUT[3] buffer has been consumed. The RAM buffer can be accessed safely by software. */
103 NRF_USBD_EVENT_ENDEPOUT4 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[4]), /**< The whole EPOUT[4] buffer has been consumed. The RAM buffer can be accessed safely by software. */
104 NRF_USBD_EVENT_ENDEPOUT5 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[5]), /**< The whole EPOUT[5] buffer has been consumed. The RAM buffer can be accessed safely by software. */
105 NRF_USBD_EVENT_ENDEPOUT6 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[6]), /**< The whole EPOUT[6] buffer has been consumed. The RAM buffer can be accessed safely by software. */
106 NRF_USBD_EVENT_ENDEPOUT7 = offsetof(NRF_USBD_Type, EVENTS_ENDEPOUT[7]), /**< The whole EPOUT[7] buffer has been consumed. The RAM buffer can be accessed safely by software. */
107 NRF_USBD_EVENT_ENDISOOUT0 = offsetof(NRF_USBD_Type, EVENTS_ENDISOOUT ), /**< The whole ISOOUT buffer has been consumed. The RAM buffer can be accessed safely by software. */
108 NRF_USBD_EVENT_SOF = offsetof(NRF_USBD_Type, EVENTS_SOF ), /**< Signals that a SOF (start of frame) condition has been detected on the USB lines */
109 NRF_USBD_EVENT_USBEVENT = offsetof(NRF_USBD_Type, EVENTS_USBEVENT ), /**< An event or an error not covered by specific events has occurred, check EVENTCAUSE register to find the cause */
110 NRF_USBD_EVENT_EP0SETUP = offsetof(NRF_USBD_Type, EVENTS_EP0SETUP ), /**< A valid SETUP token has been received (and acknowledged) on the control endpoint */
111 NRF_USBD_EVENT_DATAEP = offsetof(NRF_USBD_Type, EVENTS_EPDATA ), /**< A data transfer has occurred on a data endpoint, indicated by the EPDATASTATUS register */
112 /*lint -restore*/
113 }nrf_usbd_event_t;
114
115 /**
116 * @brief USBD shorts
117 */
118 typedef enum
119 {
120 NRF_USBD_SHORT_EP0DATADONE_STARTEPIN0_MASK = USBD_SHORTS_EP0DATADONE_STARTEPIN0_Msk , /**< Shortcut between EP0DATADONE event and STARTEPIN0 task */
121 NRF_USBD_SHORT_EP0DATADONE_STARTEPOUT0_MASK = USBD_SHORTS_EP0DATADONE_STARTEPOUT0_Msk, /**< Shortcut between EP0DATADONE event and STARTEPOUT0 task */
122 NRF_USBD_SHORT_EP0DATADONE_EP0STATUS_MASK = USBD_SHORTS_EP0DATADONE_EP0STATUS_Msk , /**< Shortcut between EP0DATADONE event and EP0STATUS task */
123 NRF_USBD_SHORT_ENDEPOUT0_EP0STATUS_MASK = USBD_SHORTS_ENDEPOUT0_EP0STATUS_Msk , /**< Shortcut between ENDEPOUT[0] event and EP0STATUS task */
124 NRF_USBD_SHORT_ENDEPOUT0_EP0RCVOUT_MASK = USBD_SHORTS_ENDEPOUT0_EP0RCVOUT_Msk , /**< Shortcut between ENDEPOUT[0] event and EP0RCVOUT task */
125 }nrf_usbd_short_mask_t;
126
127 /**
128 * @brief USBD interrupts
129 */
130 typedef enum
131 {
132 NRF_USBD_INT_USBRESET_MASK = USBD_INTEN_USBRESET_Msk , /**< Enable or disable interrupt for USBRESET event */
133 NRF_USBD_INT_STARTED_MASK = USBD_INTEN_STARTED_Msk , /**< Enable or disable interrupt for STARTED event */
134 NRF_USBD_INT_ENDEPIN0_MASK = USBD_INTEN_ENDEPIN0_Msk , /**< Enable or disable interrupt for ENDEPIN[0] event */
135 NRF_USBD_INT_ENDEPIN1_MASK = USBD_INTEN_ENDEPIN1_Msk , /**< Enable or disable interrupt for ENDEPIN[1] event */
136 NRF_USBD_INT_ENDEPIN2_MASK = USBD_INTEN_ENDEPIN2_Msk , /**< Enable or disable interrupt for ENDEPIN[2] event */
137 NRF_USBD_INT_ENDEPIN3_MASK = USBD_INTEN_ENDEPIN3_Msk , /**< Enable or disable interrupt for ENDEPIN[3] event */
138 NRF_USBD_INT_ENDEPIN4_MASK = USBD_INTEN_ENDEPIN4_Msk , /**< Enable or disable interrupt for ENDEPIN[4] event */
139 NRF_USBD_INT_ENDEPIN5_MASK = USBD_INTEN_ENDEPIN5_Msk , /**< Enable or disable interrupt for ENDEPIN[5] event */
140 NRF_USBD_INT_ENDEPIN6_MASK = USBD_INTEN_ENDEPIN6_Msk , /**< Enable or disable interrupt for ENDEPIN[6] event */
141 NRF_USBD_INT_ENDEPIN7_MASK = USBD_INTEN_ENDEPIN7_Msk , /**< Enable or disable interrupt for ENDEPIN[7] event */
142 NRF_USBD_INT_EP0DATADONE_MASK = USBD_INTEN_EP0DATADONE_Msk, /**< Enable or disable interrupt for EP0DATADONE event */
143 NRF_USBD_INT_ENDISOIN0_MASK = USBD_INTEN_ENDISOIN_Msk , /**< Enable or disable interrupt for ENDISOIN[0] event */
144 NRF_USBD_INT_ENDEPOUT0_MASK = USBD_INTEN_ENDEPOUT0_Msk , /**< Enable or disable interrupt for ENDEPOUT[0] event */
145 NRF_USBD_INT_ENDEPOUT1_MASK = USBD_INTEN_ENDEPOUT1_Msk , /**< Enable or disable interrupt for ENDEPOUT[1] event */
146 NRF_USBD_INT_ENDEPOUT2_MASK = USBD_INTEN_ENDEPOUT2_Msk , /**< Enable or disable interrupt for ENDEPOUT[2] event */
147 NRF_USBD_INT_ENDEPOUT3_MASK = USBD_INTEN_ENDEPOUT3_Msk , /**< Enable or disable interrupt for ENDEPOUT[3] event */
148 NRF_USBD_INT_ENDEPOUT4_MASK = USBD_INTEN_ENDEPOUT4_Msk , /**< Enable or disable interrupt for ENDEPOUT[4] event */
149 NRF_USBD_INT_ENDEPOUT5_MASK = USBD_INTEN_ENDEPOUT5_Msk , /**< Enable or disable interrupt for ENDEPOUT[5] event */
150 NRF_USBD_INT_ENDEPOUT6_MASK = USBD_INTEN_ENDEPOUT6_Msk , /**< Enable or disable interrupt for ENDEPOUT[6] event */
151 NRF_USBD_INT_ENDEPOUT7_MASK = USBD_INTEN_ENDEPOUT7_Msk , /**< Enable or disable interrupt for ENDEPOUT[7] event */
152 NRF_USBD_INT_ENDISOOUT0_MASK = USBD_INTEN_ENDISOOUT_Msk , /**< Enable or disable interrupt for ENDISOOUT[0] event */
153 NRF_USBD_INT_SOF_MASK = USBD_INTEN_SOF_Msk , /**< Enable or disable interrupt for SOF event */
154 NRF_USBD_INT_USBEVENT_MASK = USBD_INTEN_USBEVENT_Msk , /**< Enable or disable interrupt for USBEVENT event */
155 NRF_USBD_INT_EP0SETUP_MASK = USBD_INTEN_EP0SETUP_Msk , /**< Enable or disable interrupt for EP0SETUP event */
156 NRF_USBD_INT_DATAEP_MASK = USBD_INTEN_EPDATA_Msk , /**< Enable or disable interrupt for EPDATA event */
157 }nrf_usbd_int_mask_t;
158
159
160 /**
161 * @brief Function for activating a specific USBD task.
162 *
163 * @param task Task.
164 */
165 __STATIC_INLINE void nrf_usbd_task_trigger(nrf_usbd_task_t task);
166
167 /**
168 * @brief Function for returning the address of a specific USBD task register.
169 *
170 * @param task Task.
171 *
172 * @return Task address.
173 */
174 __STATIC_INLINE uint32_t nrf_usbd_task_address_get(nrf_usbd_task_t task);
175
176 /**
177 * @brief Function for clearing a specific event.
178 *
179 * @param event Event.
180 */
181 __STATIC_INLINE void nrf_usbd_event_clear(nrf_usbd_event_t event);
182
183 /**
184 * @brief Function for returning the state of a specific event.
185 *
186 * @param event Event.
187 *
188 * @retval true If the event is set.
189 * @retval false If the event is not set.
190 */
191 __STATIC_INLINE bool nrf_usbd_event_check(nrf_usbd_event_t event);
192
193 /**
194 * @brief Function for getting and clearing the state of specific event
195 *
196 * This function checks the state of the event and clears it.
197 *
198 * @param event Event.
199 *
200 * @retval true If the event was set.
201 * @retval false If the event was not set.
202 */
203 __STATIC_INLINE bool nrf_usbd_event_get_and_clear(nrf_usbd_event_t event);
204
205 /**
206 * @brief Function for returning the address of a specific USBD event register.
207 *
208 * @param event Event.
209 *
210 * @return Address.
211 */
212 __STATIC_INLINE uint32_t nrf_usbd_event_address_get(nrf_usbd_event_t event);
213
214 /**
215 * @brief Function for setting a shortcut.
216 *
217 * @param short_mask Shortcuts mask.
218 */
219 __STATIC_INLINE void nrf_usbd_shorts_enable(uint32_t short_mask);
220
221 /**
222 * @brief Function for clearing shortcuts.
223 *
224 * @param short_mask Shortcuts mask.
225 */
226 __STATIC_INLINE void nrf_usbd_shorts_disable(uint32_t short_mask);
227
228 /**
229 * @brief Get the shorts mask
230 *
231 * Function returns shorts register.
232 *
233 * @return Flags of currently enabled shortcuts
234 */
235 __STATIC_INLINE uint32_t nrf_usbd_shorts_get(void);
236
237 /**
238 * @brief Function for enabling selected interrupts.
239 *
240 * @param int_mask Interrupts mask.
241 */
242 __STATIC_INLINE void nrf_usbd_int_enable(uint32_t int_mask);
243
244 /**
245 * @brief Function for retrieving the state of selected interrupts.
246 *
247 * @param int_mask Interrupts mask.
248 *
249 * @retval true If any of selected interrupts is enabled.
250 * @retval false If none of selected interrupts is enabled.
251 */
252 __STATIC_INLINE bool nrf_usbd_int_enable_check(uint32_t int_mask);
253
254 /**
255 * @brief Function for retrieving the information about enabled interrupts.
256 *
257 * @return The flags of enabled interrupts.
258 */
259 __STATIC_INLINE uint32_t nrf_usbd_int_enable_get(void);
260
261 /**
262 * @brief Function for disabling selected interrupts.
263 *
264 * @param int_mask Interrupts mask.
265 */
266 __STATIC_INLINE void nrf_usbd_int_disable(uint32_t int_mask);
267
268
269 /** @} */ /* End of nrf_usbd_hal */
270
271
272 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
273
274 /* ------------------------------------------------------------------------------------------------
275 * Internal functions
276 */
277
278 /**
279 * @internal
280 * @brief Internal function for getting task/event register address
281 *
282 * @oaram offset Offset of the register from the instance beginning
283 *
284 * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
285 * @return Pointer to the register
286 */
nrf_usbd_getRegPtr(uint32_t offset)287 __STATIC_INLINE volatile uint32_t* nrf_usbd_getRegPtr(uint32_t offset)
288 {
289 return (volatile uint32_t*)(((uint8_t *)NRF_USBD) + (uint32_t)offset);
290 }
291
292 /**
293 * @internal
294 * @brief Internal function for getting task/event register address - constant version
295 *
296 * @oaram offset Offset of the register from the instance beginning
297 *
298 * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
299 * @return Pointer to the register
300 */
nrf_usbd_getRegPtr_c(uint32_t offset)301 __STATIC_INLINE volatile const uint32_t* nrf_usbd_getRegPtr_c(uint32_t offset)
302 {
303 return (volatile const uint32_t*)(((uint8_t *)NRF_USBD) + (uint32_t)offset);
304 }
305
306 /* ------------------------------------------------------------------------------------------------
307 * Interface functions definitions
308 */
309
nrf_usbd_task_trigger(nrf_usbd_task_t task)310 void nrf_usbd_task_trigger(nrf_usbd_task_t task)
311 {
312 *(nrf_usbd_getRegPtr((uint32_t)task)) = 1UL;
313 __ISB();
314 __DSB();
315 }
316
nrf_usbd_task_address_get(nrf_usbd_task_t task)317 uint32_t nrf_usbd_task_address_get(nrf_usbd_task_t task)
318 {
319 return (uint32_t)nrf_usbd_getRegPtr_c((uint32_t)task);
320 }
321
nrf_usbd_event_clear(nrf_usbd_event_t event)322 void nrf_usbd_event_clear(nrf_usbd_event_t event)
323 {
324 *(nrf_usbd_getRegPtr((uint32_t)event)) = 0UL;
325 __ISB();
326 __DSB();
327 }
328
nrf_usbd_event_check(nrf_usbd_event_t event)329 bool nrf_usbd_event_check(nrf_usbd_event_t event)
330 {
331 return (bool)*nrf_usbd_getRegPtr_c((uint32_t)event);
332 }
333
nrf_usbd_event_get_and_clear(nrf_usbd_event_t event)334 bool nrf_usbd_event_get_and_clear(nrf_usbd_event_t event)
335 {
336 bool ret = nrf_usbd_event_check(event);
337 if (ret)
338 {
339 nrf_usbd_event_clear(event);
340 }
341 return ret;
342 }
343
nrf_usbd_event_address_get(nrf_usbd_event_t event)344 uint32_t nrf_usbd_event_address_get(nrf_usbd_event_t event)
345 {
346 return (uint32_t)nrf_usbd_getRegPtr_c((uint32_t)event);
347 }
348
nrf_usbd_shorts_enable(uint32_t short_mask)349 void nrf_usbd_shorts_enable(uint32_t short_mask)
350 {
351 NRF_USBD->SHORTS |= short_mask;
352 }
353
nrf_usbd_shorts_disable(uint32_t short_mask)354 void nrf_usbd_shorts_disable(uint32_t short_mask)
355 {
356 if (~0U == short_mask)
357 {
358 /* Optimized version for "disable all" */
359 NRF_USBD->SHORTS = 0;
360 }
361 else
362 {
363 NRF_USBD->SHORTS &= ~short_mask;
364 }
365 }
366
nrf_usbd_shorts_get(void)367 uint32_t nrf_usbd_shorts_get(void)
368 {
369 return NRF_USBD->SHORTS;
370 }
371
nrf_usbd_int_enable(uint32_t int_mask)372 void nrf_usbd_int_enable(uint32_t int_mask)
373 {
374 NRF_USBD->INTENSET = int_mask;
375 }
376
nrf_usbd_int_enable_check(uint32_t int_mask)377 bool nrf_usbd_int_enable_check(uint32_t int_mask)
378 {
379 return !!(NRF_USBD->INTENSET & int_mask);
380 }
381
nrf_usbd_int_enable_get(void)382 uint32_t nrf_usbd_int_enable_get(void)
383 {
384 return NRF_USBD->INTENSET;
385 }
386
nrf_usbd_int_disable(uint32_t int_mask)387 void nrf_usbd_int_disable(uint32_t int_mask)
388 {
389 NRF_USBD->INTENCLR = int_mask;
390 }
391
392 #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
393
394 /* ------------------------------------------------------------------------------------------------
395 * End of automatically generated part
396 * ------------------------------------------------------------------------------------------------
397 */
398 /**
399 * @addtogroup nrf_usbd_hal
400 * @{
401 */
402
403 /**
404 * @brief Frame counter size
405 *
406 * The number of counts that can be fitted into frame counter
407 */
408 #define NRF_USBD_FRAMECNTR_SIZE \
409 ( (USBD_FRAMECNTR_FRAMECNTR_Msk >> USBD_FRAMECNTR_FRAMECNTR_Pos) + 1UL )
410 #ifndef USBD_FRAMECNTR_FRAMECNTR_Msk
411 #error USBD_FRAMECNTR_FRAMECNTR_Msk should be changed into USBD_FRAMECNTR_FRAMECNTR_Msk
412 #endif
413
414 /**
415 * @brief First isochronous endpoint number
416 *
417 * The number of the first isochronous endpoint
418 */
419 #define NRF_USBD_EPISO_FIRST 8
420
421 /**
422 * @brief Total number of IN endpoints
423 *
424 * Total number of IN endpoint (including ISOCHRONOUS).
425 */
426 #define NRF_USBD_EPIN_CNT 9
427
428 /**
429 * @brief Total number of OUT endpoints
430 *
431 * Total number of OUT endpoint (including ISOCHRONOUS).
432 */
433 #define NRF_USBD_EPOUT_CNT 9
434
435 /**
436 * @brief Mask of the direction bit in endpoint number
437 */
438 #define NRF_USBD_EP_DIR_Msk (1U << 7)
439
440 /**
441 * @brief The value of direction bit for IN endpoint direction
442 */
443 #define NRF_USBD_EP_DIR_IN (1U << 7)
444
445 /**
446 * @brief The value of direction bit for OUT endpoint direction
447 */
448 #define NRF_USBD_EP_DIR_OUT (0U << 7)
449
450 /**
451 * @brief Macro for making IN endpoint identifier from endpoint number
452 *
453 * Macro that sets direction bit to make IN endpoint
454 * @param[in] epnr Endpoint number
455 * @return IN Endpoint identifier
456 */
457 #define NRF_USBD_EPIN(epnr) (((uint8_t)(epnr)) | NRF_USBD_EP_DIR_IN)
458
459 /**
460 * @brief Macro for making OUT endpoint identifier from endpoint number
461 *
462 * Macro that sets direction bit to make OUT endpoint
463 * @param[in] epnr Endpoint number
464 * @return OUT Endpoint identifier
465 */
466 #define NRF_USBD_EPOUT(epnr) (((uint8_t)(epnr)) | NRF_USBD_EP_DIR_OUT)
467
468 /**
469 * @brief Macro for extracting the endpoint number from endpoint identifier
470 *
471 * Macro that strips out the information about endpoint direction.
472 * @param[in] ep Endpoint identifier
473 * @return Endpoint number
474 */
475 #define NRF_USBD_EP_NR_GET(ep) ((uint8_t)(((uint8_t)(ep)) & 0xFU))
476
477 /**
478 * @brief Macro for checking endpoint direction
479 *
480 * This macro checks if given endpoint has IN direction
481 * @param ep Endpoint identifier
482 * @retval true If the endpoint direction is IN
483 * @retval false If the endpoint direction is OUT
484 */
485 #define NRF_USBD_EPIN_CHECK(ep) ( (((uint8_t)(ep)) & NRF_USBD_EP_DIR_Msk) == NRF_USBD_EP_DIR_IN )
486
487 /**
488 * @brief Macro for checking endpoint direction
489 *
490 * This macro checks if given endpoint has OUT direction
491 * @param ep Endpoint identifier
492 * @retval true If the endpoint direction is OUT
493 * @retval false If the endpoint direction is IN
494 */
495 #define NRF_USBD_EPOUT_CHECK(ep) ( (((uint8_t)(ep)) & NRF_USBD_EP_DIR_Msk) == NRF_USBD_EP_DIR_OUT )
496
497 /**
498 * @brief Macro for checking if endpoint is isochronous
499 *
500 * @param ep It can be endpoint identifier or just endpoint number to check
501 * @retval true The endpoint is isochronous type
502 * @retval false The endpoint is bulk of interrupt type
503 */
504 #define NRF_USBD_EPISO_CHECK(ep) (NRF_USBD_EP_NR_GET(ep) >= NRF_USBD_EPISO_FIRST)
505
506 /**
507 * @brief Macro for checking if given number is valid endpoint number
508 *
509 * @param ep Endpoint number to check
510 * @retval true The endpoint is valid
511 * @retval false The endpoint is not valid
512 */
513 #define NRF_USBD_EP_VALIDATE(ep) ( \
514 (NRF_USBD_EPIN_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPIN_CNT)) \
515 || \
516 (NRF_USBD_EPOUT_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRF_USBD_EPOUT_CNT)) \
517 )
518
519 /**
520 * @brief Not isochronous data frame received
521 *
522 * Special value returned by @ref nrf_usbd_episoout_size_get function that means that
523 * data frame was not received at all.
524 * This allows differentiate between situations when zero size data comes or no data comes at all
525 * on isochronous endpoint.
526 */
527 #define NRF_USBD_EPISOOUT_NO_DATA ((size_t)(-1))
528
529 /**
530 * @brief EVENTCAUSE register bit masks
531 */
532 typedef enum
533 {
534 NRF_USBD_EVENTCAUSE_ISOOUTCRC_MASK = USBD_EVENTCAUSE_ISOOUTCRC_Msk, /**< CRC error was detected on isochronous OUT endpoint 8. */
535 NRF_USBD_EVENTCAUSE_SUSPEND_MASK = USBD_EVENTCAUSE_SUSPEND_Msk, /**< Signals that the USB lines have been seen idle long enough for the device to enter suspend. */
536 NRF_USBD_EVENTCAUSE_RESUME_MASK = USBD_EVENTCAUSE_RESUME_Msk, /**< Signals that a RESUME condition (K state or activity restart) has been detected on the USB lines. */
537 NRF_USBD_EVENTCAUSE_WUREQ_MASK = USBD_EVENTCAUSE_USBWUALLOWED_Msk, /**< The USBD peripheral has exited Low Power mode */
538 NRF_USBD_EVENTCAUSE_READY_MASK = USBD_EVENTCAUSE_READY_Msk, /**< MAC is ready for normal operation, rised few us after USBD enabling */
539 }nrf_usbd_eventcause_mask_t;
540
541 /**
542 * @brief DPDMVALUE register
543 */
544 typedef enum
545 {
546 /**Generate Resume signal. Signal is generated for 50 us or 5 ms,
547 * depending on bus state */
548 NRF_USBD_DPDMVALUE_RESUME = USBD_DPDMVALUE_STATE_Resume,
549 /** D+ Forced high, D- forced low (J state) */
550 NRF_USBD_DPDMVALUE_J = USBD_DPDMVALUE_STATE_J,
551 /** D+ Forced low, D- forced high (K state) */
552 NRF_USBD_DPMVALUE_K = USBD_DPDMVALUE_STATE_K
553 }nrf_usbd_dpdmvalue_t;
554
555 /**
556 * @brief Dtoggle value or operation
557 */
558 typedef enum
559 {
560 NRF_USBD_DTOGGLE_NOP = USBD_DTOGGLE_VALUE_Nop, /**< No operation - do not change current data toggle on selected endpoint */
561 NRF_USBD_DTOGGLE_DATA0 = USBD_DTOGGLE_VALUE_Data0,/**< Data toggle is DATA0 on selected endpoint */
562 NRF_USBD_DTOGGLE_DATA1 = USBD_DTOGGLE_VALUE_Data1 /**< Data toggle is DATA1 on selected endpoint */
563 }nrf_usbd_dtoggle_t;
564
565 /**
566 * @brief EPSTATUS bit masks
567 */
568 typedef enum
569 {
570 NRF_USBD_EPSTATUS_EPIN0_MASK = USBD_EPSTATUS_EPIN0_Msk,
571 NRF_USBD_EPSTATUS_EPIN1_MASK = USBD_EPSTATUS_EPIN1_Msk,
572 NRF_USBD_EPSTATUS_EPIN2_MASK = USBD_EPSTATUS_EPIN2_Msk,
573 NRF_USBD_EPSTATUS_EPIN3_MASK = USBD_EPSTATUS_EPIN3_Msk,
574 NRF_USBD_EPSTATUS_EPIN4_MASK = USBD_EPSTATUS_EPIN4_Msk,
575 NRF_USBD_EPSTATUS_EPIN5_MASK = USBD_EPSTATUS_EPIN5_Msk,
576 NRF_USBD_EPSTATUS_EPIN6_MASK = USBD_EPSTATUS_EPIN6_Msk,
577 NRF_USBD_EPSTATUS_EPIN7_MASK = USBD_EPSTATUS_EPIN7_Msk,
578
579 NRF_USBD_EPSTATUS_EPOUT0_MASK = USBD_EPSTATUS_EPOUT0_Msk,
580 NRF_USBD_EPSTATUS_EPOUT1_MASK = USBD_EPSTATUS_EPOUT1_Msk,
581 NRF_USBD_EPSTATUS_EPOUT2_MASK = USBD_EPSTATUS_EPOUT2_Msk,
582 NRF_USBD_EPSTATUS_EPOUT3_MASK = USBD_EPSTATUS_EPOUT3_Msk,
583 NRF_USBD_EPSTATUS_EPOUT4_MASK = USBD_EPSTATUS_EPOUT4_Msk,
584 NRF_USBD_EPSTATUS_EPOUT5_MASK = USBD_EPSTATUS_EPOUT5_Msk,
585 NRF_USBD_EPSTATUS_EPOUT6_MASK = USBD_EPSTATUS_EPOUT6_Msk,
586 NRF_USBD_EPSTATUS_EPOUT7_MASK = USBD_EPSTATUS_EPOUT7_Msk,
587 }nrf_usbd_epstatus_mask_t;
588
589 /**
590 * @brief DATAEPSTATUS bit masks
591 */
592 typedef enum
593 {
594 NRF_USBD_EPDATASTATUS_EPIN1_MASK = USBD_EPDATASTATUS_EPIN1_Msk,
595 NRF_USBD_EPDATASTATUS_EPIN2_MASK = USBD_EPDATASTATUS_EPIN2_Msk,
596 NRF_USBD_EPDATASTATUS_EPIN3_MASK = USBD_EPDATASTATUS_EPIN3_Msk,
597 NRF_USBD_EPDATASTATUS_EPIN4_MASK = USBD_EPDATASTATUS_EPIN4_Msk,
598 NRF_USBD_EPDATASTATUS_EPIN5_MASK = USBD_EPDATASTATUS_EPIN5_Msk,
599 NRF_USBD_EPDATASTATUS_EPIN6_MASK = USBD_EPDATASTATUS_EPIN6_Msk,
600 NRF_USBD_EPDATASTATUS_EPIN7_MASK = USBD_EPDATASTATUS_EPIN7_Msk,
601
602 NRF_USBD_EPDATASTATUS_EPOUT1_MASK = USBD_EPDATASTATUS_EPOUT1_Msk,
603 NRF_USBD_EPDATASTATUS_EPOUT2_MASK = USBD_EPDATASTATUS_EPOUT2_Msk,
604 NRF_USBD_EPDATASTATUS_EPOUT3_MASK = USBD_EPDATASTATUS_EPOUT3_Msk,
605 NRF_USBD_EPDATASTATUS_EPOUT4_MASK = USBD_EPDATASTATUS_EPOUT4_Msk,
606 NRF_USBD_EPDATASTATUS_EPOUT5_MASK = USBD_EPDATASTATUS_EPOUT5_Msk,
607 NRF_USBD_EPDATASTATUS_EPOUT6_MASK = USBD_EPDATASTATUS_EPOUT6_Msk,
608 NRF_USBD_EPDATASTATUS_EPOUT7_MASK = USBD_EPDATASTATUS_EPOUT7_Msk,
609 }nrf_usbd_dataepstatus_mask_t;
610
611 /**
612 * @brief ISOSPLIT configurations
613 */
614 typedef enum
615 {
616 NRF_USBD_ISOSPLIT_ONEDIR = USBD_ISOSPLIT_SPLIT_OneDir, /**< Full buffer dedicated to either iso IN or OUT */
617 NRF_USBD_ISOSPLIT_HALF = USBD_ISOSPLIT_SPLIT_HalfIN, /**< Buffer divided in half */
618 }nrf_usbd_isosplit_t;
619
620 /**
621 * @brief ISOINCONFIG configurations
622 */
623 typedef enum
624 {
625 NRF_USBD_ISOINCONFIG_NORESP = USBD_ISOINCONFIG_RESPONSE_NoResp, /**< Endpoint does not respond to an ISO IN token when no data is ready */
626 NRF_USBD_ISOINCONFIG_ZERODATA = USBD_ISOINCONFIG_RESPONSE_ZeroData, /**< Endpoint responds with a zero-length data packet to an ISO IN token when no data is ready */
627 }nrf_usbd_isoinconfig_t;
628
629 /**
630 * @brief Function for enabling USBD
631 */
632 __STATIC_INLINE void nrf_usbd_enable(void);
633
634 /**
635 * @brief Function for disabling USBD
636 */
637 __STATIC_INLINE void nrf_usbd_disable(void);
638
639 /**
640 * @brief Function for getting EVENTCAUSE register
641 *
642 * @return Flag values defined in @ref nrf_usbd_eventcause_mask_t
643 */
644 __STATIC_INLINE uint32_t nrf_usbd_eventcause_get(void);
645
646 /**
647 * @brief Function for clearing EVENTCAUSE flags
648 *
649 * @param flags Flags defined in @ref nrf_usbd_eventcause_mask_t
650 */
651 __STATIC_INLINE void nrf_usbd_eventcause_clear(uint32_t flags);
652
653 /**
654 * @brief Function for getting EVENTCAUSE register and clear flags that are set
655 *
656 * The safest way to return current EVENTCAUSE register.
657 * All the flags that are returned would be cleared inside EVENTCAUSE register.
658 *
659 * @return Flag values defined in @ref nrf_usbd_eventcause_mask_t
660 */
661 __STATIC_INLINE uint32_t nrf_usbd_eventcause_get_and_clear(void);
662
663 /**
664 * @brief Function for getting HALTEDEPIN register value
665 *
666 * @param ep Endpoint number with IN/OUT flag
667 *
668 * @return The value of HALTEDEPIN or HALTEDOUT register for selected endpoint
669 *
670 * @note
671 * Use this function for the response for GetStatus() request to endpoint.
672 * To check if endpoint is stalled in the code use @ref nrf_usbd_ep_is_stall.
673 */
674 __STATIC_INLINE uint32_t nrf_usbd_haltedep(uint8_t ep);
675
676 /**
677 * @brief Function for checking if selected endpoint is stalled
678 *
679 * Function to be used as a syntax sweeter for @ref nrf_usbd_haltedep.
680 *
681 * Also as the isochronous endpoint cannot be halted - it returns always false
682 * if isochronous endpoint is checked.
683 *
684 * @param ep Endpoint number with IN/OUT flag
685 *
686 * @return The information if the enepoint is halted.
687 */
688 __STATIC_INLINE bool nrf_usbd_ep_is_stall(uint8_t ep);
689
690 /**
691 * @brief Function for getting EPSTATUS register value
692 *
693 * @return Flag values defined in @ref nrf_usbd_epstatus_mask_t
694 */
695 __STATIC_INLINE uint32_t nrf_usbd_epstatus_get(void);
696
697 /**
698 * @brief Function for clearing EPSTATUS register value
699 *
700 * @param flags Flags defined in @ref nrf_usbd_epstatus_mask_t
701 */
702 __STATIC_INLINE void nrf_usbd_epstatus_clear(uint32_t flags);
703
704 /**
705 * @brief Function for getting and clearing EPSTATUS register value
706 *
707 * Function clears all flags in register set before returning its value.
708 * @return Flag values defined in @ref nrf_usbd_epstatus_mask_t
709 */
710 __STATIC_INLINE uint32_t nrf_usbd_epstatus_get_and_clear(void);
711
712 /**
713 * @brief Function for getting DATAEPSTATUS register value
714 *
715 * @return Flag values defined in @ref nrf_usbd_dataepstatus_mask_t
716 */
717 __STATIC_INLINE uint32_t nrf_usbd_epdatastatus_get(void);
718
719 /**
720 * @brief Function for clearing DATAEPSTATUS register value
721 *
722 * @param flags Flags defined in @ref nrf_usbd_dataepstatus_mask_t
723 */
724 __STATIC_INLINE void nrf_usbd_epdatastatus_clear(uint32_t flags);
725
726 /**
727 * @brief Function for getting and clearing DATAEPSTATUS register value
728 *
729 * Function clears all flags in register set before returning its value.
730 * @return Flag values defined in @ref nrf_usbd_dataepstatus_mask_t
731 */
732 __STATIC_INLINE uint32_t nrf_usbd_epdatastatus_get_and_clear(void);
733
734 /**
735 * @name Setup command frame functions
736 *
737 * Functions for setup command frame parts access
738 * @{
739 */
740 /**
741 * @brief Function for reading BMREQUESTTYPE - part of SETUP packet
742 *
743 * @return the value of BREQUESTTYPE on last received SETUP frame
744 */
745 __STATIC_INLINE uint8_t nrf_usbd_setup_bmrequesttype_get(void);
746
747 /**
748 * @brief Function for reading BMREQUEST - part of SETUP packet
749 *
750 * @return the value of BREQUEST on last received SETUP frame
751 */
752 __STATIC_INLINE uint8_t nrf_usbd_setup_brequest_get(void);
753
754 /**
755 * @brief Function for reading WVALUE - part of SETUP packet
756 *
757 * @return the value of WVALUE on last received SETUP frame
758 */
759 __STATIC_INLINE uint16_t nrf_usbd_setup_wvalue_get(void);
760
761 /**
762 * @brief Function for reading WINDEX - part of SETUP packet
763 *
764 * @return the value of WINDEX on last received SETUP frame
765 */
766 __STATIC_INLINE uint16_t nrf_usbd_setup_windex_get(void);
767
768 /**
769 * @brief Function for reading WLENGTH - part of SETUP packet
770 *
771 * @return the value of WLENGTH on last received SETUP frame
772 */
773 __STATIC_INLINE uint16_t nrf_usbd_setup_wlength_get(void);
774 /** @} */
775
776 /**
777 * @brief Function for getting number of received bytes on selected endpoint
778 *
779 * @param ep Endpoint identifier.
780 *
781 * @return Number of received bytes.
782 *
783 * @note This function may be used on Bulk/Interrupt and Isochronous endpoints.
784 * @note For the function that returns different value for ISOOUT zero transfer or no transfer at all,
785 * see @ref nrf_usbd_episoout_size_get function. This function would return 0 for both cases.
786 */
787 __STATIC_INLINE size_t nrf_usbd_epout_size_get(uint8_t ep);
788
789 /**
790 * @brief Function for getting number of received bytes on isochronous endpoint.
791 *
792 * @param ep Endpoint identifier, has to be isochronous out endpoint.
793 *
794 * @return Number of bytes received or @ref NRF_USBD_EPISOOUT_NO_DATA
795 */
796 __STATIC_INLINE size_t nrf_usbd_episoout_size_get(uint8_t ep);
797
798 /**
799 * @brief Function for clearing out endpoint to accept any new incoming traffic
800 *
801 * @param ep ep Endpoint identifier. Only OUT Interrupt/Bulk endpoints are accepted.
802 */
803 __STATIC_INLINE void nrf_usbd_epout_clear(uint8_t ep);
804
805 /**
806 * @brief Function for enabling USB pullup
807 */
808 __STATIC_INLINE void nrf_usbd_pullup_enable(void);
809
810 /**
811 * @brief Function for disabling USB pullup
812 */
813 __STATIC_INLINE void nrf_usbd_pullup_disable(void);
814
815 /**
816 * @brief Function for returning current USB pullup state
817 *
818 * @retval true USB pullup is enabled
819 * @retval false USB pullup is disabled
820 */
821 __STATIC_INLINE bool nrf_usbd_pullup_check(void);
822
823 /**
824 * @brief Function for configuring the value to be forced on the bus on DRIVEDPDM task
825 *
826 * Selected state would be forced on the bus when @ref NRF_USBD_TASK_DRIVEDPDM is set.
827 * The state would be removed from the bus on @ref NRF_USBD_TASK_NODRIVEDPDM and
828 * the control would be returned to the USBD peripheral.
829 * @param val State to be set
830 */
831 __STATIC_INLINE void nrf_usbd_dpdmvalue_set(nrf_usbd_dpdmvalue_t val);
832
833 /**
834 * @brief Function for setting data toggle
835 *
836 * Configuration of current state of data toggling
837 * @param ep Endpoint number with the information about its direction
838 * @param op Operation to execute
839 */
840 __STATIC_INLINE void nrf_usbd_dtoggle_set(uint8_t ep, nrf_usbd_dtoggle_t op);
841
842 /**
843 * @brief Function for getting data toggle
844 *
845 * Get the current state of data toggling
846 * @param ep Endpoint number to return the information about current data toggling
847 * @retval NRF_USBD_DTOGGLE_DATA0 Data toggle is DATA0 on selected endpoint
848 * @retval NRF_USBD_DTOGGLE_DATA1 Data toggle is DATA1 on selected endpoint
849 */
850 __STATIC_INLINE nrf_usbd_dtoggle_t nrf_usbd_dtoggle_get(uint8_t ep);
851
852 /**
853 * @brief Function for checking if endpoint is enabled
854 *
855 * @param ep Endpoint id to check
856 *
857 * @retval true Endpoint is enabled
858 * @retval false Endpoint is disabled
859 */
860 __STATIC_INLINE bool nrf_usbd_ep_enable_check(uint8_t ep);
861
862 /**
863 * @brief Function for enabling selected endpoint
864 *
865 * Enabled endpoint responds for the tokens on the USB bus
866 *
867 * @param ep Endpoint id to enable
868 */
869 __STATIC_INLINE void nrf_usbd_ep_enable(uint8_t ep);
870
871 /**
872 * @brief Function for disabling selected endpoint
873 *
874 * Disabled endpoint does not respond for the tokens on the USB bus
875 *
876 * @param ep Endpoint id to disable
877 */
878 __STATIC_INLINE void nrf_usbd_ep_disable(uint8_t ep);
879
880 /**
881 * @brief Function for disabling all endpoints
882 *
883 * Auxiliary function to simply disable all aviable endpoints.
884 * It lefts only EP0 IN and OUT enabled.
885 */
886 __STATIC_INLINE void nrf_usbd_ep_all_disable(void);
887
888 /**
889 * @brief Function for stalling selected endpoint
890 *
891 * @param ep Endpoint identifier
892 * @note This function cannot be called on isochronous endpoint
893 */
894 __STATIC_INLINE void nrf_usbd_ep_stall(uint8_t ep);
895
896 /**
897 * @brief Function for unstalling selected endpoint
898 *
899 * @param ep Endpoint identifier
900 * @note This function cannot be called on isochronous endpoint
901 */
902 __STATIC_INLINE void nrf_usbd_ep_unstall(uint8_t ep);
903
904 /**
905 * @brief Function for configuration of isochronous buffer splitting
906 *
907 * Configure isochronous buffer splitting between IN and OUT endpoints.
908 *
909 * @param split Required configuration
910 */
911 __STATIC_INLINE void nrf_usbd_isosplit_set(nrf_usbd_isosplit_t split);
912
913 /**
914 * @brief Function for getting the isochronous buffer splitting configuration
915 *
916 * Get the current isochronous buffer splitting configuration.
917 *
918 * @return Current configuration
919 */
920 __STATIC_INLINE nrf_usbd_isosplit_t nrf_usbd_isosplit_get(void);
921
922 /**
923 * @brief Function for getting current frame counter
924 *
925 * @return Current frame counter
926 */
927 __STATIC_INLINE uint32_t nrf_usbd_framecntr_get(void);
928
929 /**
930 * @brief Function for entering into low power mode
931 *
932 * After this function is called the clock source from the USBD is disconnected internally.
933 * After this function is called most of the USBD registers cannot be accessed anymore.
934 *
935 * @sa nrf_usbd_lowpower_disable
936 * @sa nrf_usbd_lowpower_check
937 */
938 __STATIC_INLINE void nrf_usbd_lowpower_enable(void);
939
940 /**
941 * @brief Function for exiting from low power mode
942 *
943 * After this function is called the clock source for the USBD is connected internally.
944 * The @ref NRF_USBD_EVENTCAUSE_WUREQ_MASK event would be generated and
945 * then the USBD registers may be accessed.
946 *
947 * @sa nrf_usbd_lowpower_enable
948 * @sa nrf_usbd_lowpower_check
949 */
950 __STATIC_INLINE void nrf_usbd_lowpower_disable(void);
951
952 /**
953 * @brief Function for checking the state of the low power mode
954 *
955 * @retval true USBD is in low power mode
956 * @retval false USBD is not in low power mode
957 */
958 __STATIC_INLINE bool nrf_usbd_lowpower_check(void);
959
960 /**
961 * @brief Function for configuring ISO IN endpoint response to an IN token when no data is ready to be sent.
962 *
963 * @param config Required configuration
964 */
965 __STATIC_INLINE void nrf_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config);
966
967 /**
968 * @brief Function for getting the cofiguration of ISO IN endpoint response to an IN token when no data is ready to be sent.
969 *
970 * @return Current configuration
971 */
972 __STATIC_INLINE nrf_usbd_isoinconfig_t nrf_usbd_isoinconfig_get(void);
973
974 /**
975 * @brief Function for configuring EasyDMA channel
976 *
977 * Configures EasyDMA for the transfer.
978 *
979 * @param ep Endpoint identifier (with direction)
980 * @param ptr Pointer to the data
981 * @param maxcnt Number of bytes to transfer
982 */
983 __STATIC_INLINE void nrf_usbd_ep_easydma_set(uint8_t ep, uint32_t ptr, uint32_t maxcnt);
984
985 /**
986 * @brief Function for getting number of transferred bytes
987 *
988 * Get number of transferred bytes in the last transaction
989 *
990 * @param ep Endpoint identifier
991 *
992 * @return The content of the AMOUNT register
993 */
994 __STATIC_INLINE uint32_t nrf_usbd_ep_amount_get(uint8_t ep);
995
996
997 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
998
nrf_usbd_enable(void)999 void nrf_usbd_enable(void)
1000 {
1001 #ifdef NRF_FPGA_IMPLEMENTATION
1002 *(volatile uint32_t *)0x400005F4 = 3;
1003 __ISB();
1004 __DSB();
1005 *(volatile uint32_t *)0x400005F0 = 3;
1006 __ISB();
1007 __DSB();
1008 #endif
1009
1010 NRF_USBD->ENABLE = USBD_ENABLE_ENABLE_Enabled << USBD_ENABLE_ENABLE_Pos;
1011 __ISB();
1012 __DSB();
1013 }
1014
nrf_usbd_disable(void)1015 void nrf_usbd_disable(void)
1016 {
1017 NRF_USBD->ENABLE = USBD_ENABLE_ENABLE_Disabled << USBD_ENABLE_ENABLE_Pos;
1018 __ISB();
1019 __DSB();
1020 }
1021
nrf_usbd_eventcause_get(void)1022 uint32_t nrf_usbd_eventcause_get(void)
1023 {
1024 return NRF_USBD->EVENTCAUSE;
1025 }
1026
nrf_usbd_eventcause_clear(uint32_t flags)1027 void nrf_usbd_eventcause_clear(uint32_t flags)
1028 {
1029 NRF_USBD->EVENTCAUSE = flags;
1030 __ISB();
1031 __DSB();
1032 }
1033
nrf_usbd_eventcause_get_and_clear(void)1034 uint32_t nrf_usbd_eventcause_get_and_clear(void)
1035 {
1036 uint32_t ret;
1037 ret = nrf_usbd_eventcause_get();
1038 nrf_usbd_eventcause_clear(ret);
1039 __ISB();
1040 __DSB();
1041 return ret;
1042 }
1043
nrf_usbd_haltedep(uint8_t ep)1044 uint32_t nrf_usbd_haltedep(uint8_t ep)
1045 {
1046 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1047 if (NRF_USBD_EPIN_CHECK(ep))
1048 {
1049 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->HALTED.EPIN));
1050 return NRF_USBD->HALTED.EPIN[epnr];
1051 }
1052 else
1053 {
1054 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->HALTED.EPOUT));
1055 return NRF_USBD->HALTED.EPOUT[epnr];
1056 }
1057 }
1058
nrf_usbd_ep_is_stall(uint8_t ep)1059 bool nrf_usbd_ep_is_stall(uint8_t ep)
1060 {
1061 if (NRF_USBD_EPISO_CHECK(ep))
1062 return false;
1063 return USBD_HALTED_EPOUT_GETSTATUS_Halted == nrf_usbd_haltedep(ep);
1064 }
1065
nrf_usbd_epstatus_get(void)1066 uint32_t nrf_usbd_epstatus_get(void)
1067 {
1068 return NRF_USBD->EPSTATUS;
1069 }
1070
nrf_usbd_epstatus_clear(uint32_t flags)1071 void nrf_usbd_epstatus_clear(uint32_t flags)
1072 {
1073 NRF_USBD->EPSTATUS = flags;
1074 __ISB();
1075 __DSB();
1076 }
1077
nrf_usbd_epstatus_get_and_clear(void)1078 uint32_t nrf_usbd_epstatus_get_and_clear(void)
1079 {
1080 uint32_t ret;
1081 ret = nrf_usbd_epstatus_get();
1082 nrf_usbd_epstatus_clear(ret);
1083 return ret;
1084 }
1085
nrf_usbd_epdatastatus_get(void)1086 uint32_t nrf_usbd_epdatastatus_get(void)
1087 {
1088 return NRF_USBD->EPDATASTATUS;
1089 }
1090
nrf_usbd_epdatastatus_clear(uint32_t flags)1091 void nrf_usbd_epdatastatus_clear(uint32_t flags)
1092 {
1093 NRF_USBD->EPDATASTATUS = flags;
1094 __ISB();
1095 __DSB();
1096 }
1097
nrf_usbd_epdatastatus_get_and_clear(void)1098 uint32_t nrf_usbd_epdatastatus_get_and_clear(void)
1099 {
1100 uint32_t ret;
1101 ret = nrf_usbd_epdatastatus_get();
1102 nrf_usbd_epdatastatus_clear(ret);
1103 return ret;
1104 }
1105
nrf_usbd_setup_bmrequesttype_get(void)1106 uint8_t nrf_usbd_setup_bmrequesttype_get(void)
1107 {
1108 return (uint8_t)(NRF_USBD->BMREQUESTTYPE);
1109 }
1110
nrf_usbd_setup_brequest_get(void)1111 uint8_t nrf_usbd_setup_brequest_get(void)
1112 {
1113 return (uint8_t)(NRF_USBD->BREQUEST);
1114 }
1115
nrf_usbd_setup_wvalue_get(void)1116 uint16_t nrf_usbd_setup_wvalue_get(void)
1117 {
1118 const uint16_t val = NRF_USBD->WVALUEL;
1119 return (uint16_t)(val | ((NRF_USBD->WVALUEH) << 8));
1120 }
1121
nrf_usbd_setup_windex_get(void)1122 uint16_t nrf_usbd_setup_windex_get(void)
1123 {
1124 const uint16_t val = NRF_USBD->WINDEXL;
1125 return (uint16_t)(val | ((NRF_USBD->WINDEXH) << 8));
1126 }
1127
nrf_usbd_setup_wlength_get(void)1128 uint16_t nrf_usbd_setup_wlength_get(void)
1129 {
1130 const uint16_t val = NRF_USBD->WLENGTHL;
1131 return (uint16_t)(val | ((NRF_USBD->WLENGTHH) << 8));
1132 }
1133
nrf_usbd_epout_size_get(uint8_t ep)1134 size_t nrf_usbd_epout_size_get(uint8_t ep)
1135 {
1136 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1137 NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep));
1138 if (NRF_USBD_EPISO_CHECK(ep))
1139 {
1140 size_t size_isoout = NRF_USBD->SIZE.ISOOUT;
1141 if ((size_isoout & USBD_SIZE_ISOOUT_ZERO_Msk) == (USBD_SIZE_ISOOUT_ZERO_ZeroData << USBD_SIZE_ISOOUT_ZERO_Pos))
1142 {
1143 size_isoout = 0;
1144 }
1145 return size_isoout;
1146 }
1147
1148 NRFX_ASSERT(NRF_USBD_EP_NR_GET(ep) < NRFX_ARRAY_SIZE(NRF_USBD->SIZE.EPOUT));
1149 return NRF_USBD->SIZE.EPOUT[NRF_USBD_EP_NR_GET(ep)];
1150 }
1151
nrf_usbd_episoout_size_get(uint8_t ep)1152 size_t nrf_usbd_episoout_size_get(uint8_t ep)
1153 {
1154 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1155 NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep));
1156 NRFX_ASSERT(NRF_USBD_EPISO_CHECK(ep));
1157
1158 size_t size_isoout = NRF_USBD->SIZE.ISOOUT;
1159 if (size_isoout == 0)
1160 {
1161 size_isoout = NRF_USBD_EPISOOUT_NO_DATA;
1162 }
1163 else if ((size_isoout & USBD_SIZE_ISOOUT_ZERO_Msk) == (USBD_SIZE_ISOOUT_ZERO_ZeroData << USBD_SIZE_ISOOUT_ZERO_Pos))
1164 {
1165 size_isoout = 0;
1166 }
1167 return size_isoout;
1168 }
1169
nrf_usbd_epout_clear(uint8_t ep)1170 void nrf_usbd_epout_clear(uint8_t ep)
1171 {
1172 NRFX_ASSERT(NRF_USBD_EPOUT_CHECK(ep) && (NRF_USBD_EP_NR_GET(ep) < NRFX_ARRAY_SIZE(NRF_USBD->SIZE.EPOUT)));
1173 NRF_USBD->SIZE.EPOUT[NRF_USBD_EP_NR_GET(ep)] = 0;
1174 __ISB();
1175 __DSB();
1176 }
1177
nrf_usbd_pullup_enable(void)1178 void nrf_usbd_pullup_enable(void)
1179 {
1180 NRF_USBD->USBPULLUP = USBD_USBPULLUP_CONNECT_Enabled << USBD_USBPULLUP_CONNECT_Pos;
1181 __ISB();
1182 __DSB();
1183 }
1184
nrf_usbd_pullup_disable(void)1185 void nrf_usbd_pullup_disable(void)
1186 {
1187 NRF_USBD->USBPULLUP = USBD_USBPULLUP_CONNECT_Disabled << USBD_USBPULLUP_CONNECT_Pos;
1188 __ISB();
1189 __DSB();
1190 }
1191
nrf_usbd_pullup_check(void)1192 bool nrf_usbd_pullup_check(void)
1193 {
1194 return NRF_USBD->USBPULLUP == (USBD_USBPULLUP_CONNECT_Enabled << USBD_USBPULLUP_CONNECT_Pos);
1195 }
1196
nrf_usbd_dpdmvalue_set(nrf_usbd_dpdmvalue_t val)1197 void nrf_usbd_dpdmvalue_set(nrf_usbd_dpdmvalue_t val)
1198 {
1199 NRF_USBD->DPDMVALUE = ((uint32_t)val) << USBD_DPDMVALUE_STATE_Pos;
1200 }
1201
nrf_usbd_dtoggle_set(uint8_t ep,nrf_usbd_dtoggle_t op)1202 void nrf_usbd_dtoggle_set(uint8_t ep, nrf_usbd_dtoggle_t op)
1203 {
1204 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1205 NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep));
1206 NRF_USBD->DTOGGLE = ep | (NRF_USBD_DTOGGLE_NOP << USBD_DTOGGLE_VALUE_Pos);
1207 __DSB();
1208 NRF_USBD->DTOGGLE = ep | (op << USBD_DTOGGLE_VALUE_Pos);
1209 __ISB();
1210 __DSB();
1211 }
1212
nrf_usbd_dtoggle_get(uint8_t ep)1213 nrf_usbd_dtoggle_t nrf_usbd_dtoggle_get(uint8_t ep)
1214 {
1215 uint32_t retval;
1216 /* Select the endpoint to read */
1217 NRF_USBD->DTOGGLE = ep | (NRF_USBD_DTOGGLE_NOP << USBD_DTOGGLE_VALUE_Pos);
1218 retval = ((NRF_USBD->DTOGGLE) & USBD_DTOGGLE_VALUE_Msk) >> USBD_DTOGGLE_VALUE_Pos;
1219 return (nrf_usbd_dtoggle_t)retval;
1220 }
1221
nrf_usbd_ep_enable_check(uint8_t ep)1222 bool nrf_usbd_ep_enable_check(uint8_t ep)
1223 {
1224 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1225 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1226
1227 if (NRF_USBD_EPIN_CHECK(ep))
1228 {
1229 return 0 != (NRF_USBD->EPINEN & (1UL << epnr));
1230 }
1231 else
1232 {
1233 return 0 != (NRF_USBD->EPOUTEN & (1UL << epnr));
1234 }
1235 }
1236
nrf_usbd_ep_enable(uint8_t ep)1237 void nrf_usbd_ep_enable(uint8_t ep)
1238 {
1239 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1240 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1241
1242 if (NRF_USBD_EPIN_CHECK(ep))
1243 {
1244 NRF_USBD->EPINEN |= 1UL << epnr;
1245 }
1246 else
1247 {
1248 NRF_USBD->EPOUTEN |= 1UL << epnr;
1249 }
1250 __ISB();
1251 __DSB();
1252 }
1253
nrf_usbd_ep_disable(uint8_t ep)1254 void nrf_usbd_ep_disable(uint8_t ep)
1255 {
1256 NRFX_ASSERT(NRF_USBD_EP_VALIDATE(ep));
1257 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1258
1259 if (NRF_USBD_EPIN_CHECK(ep))
1260 {
1261 NRF_USBD->EPINEN &= ~(1UL << epnr);
1262 }
1263 else
1264 {
1265 NRF_USBD->EPOUTEN &= ~(1UL << epnr);
1266 }
1267 __ISB();
1268 __DSB();
1269 }
1270
nrf_usbd_ep_all_disable(void)1271 void nrf_usbd_ep_all_disable(void)
1272 {
1273 NRF_USBD->EPINEN = USBD_EPINEN_IN0_Enable << USBD_EPINEN_IN0_Pos;
1274 NRF_USBD->EPOUTEN = USBD_EPOUTEN_OUT0_Enable << USBD_EPOUTEN_OUT0_Pos;
1275 __ISB();
1276 __DSB();
1277 }
1278
nrf_usbd_ep_stall(uint8_t ep)1279 void nrf_usbd_ep_stall(uint8_t ep)
1280 {
1281 NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep));
1282 NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_Stall << USBD_EPSTALL_STALL_Pos) | ep;
1283 __ISB();
1284 __DSB();
1285 }
1286
nrf_usbd_ep_unstall(uint8_t ep)1287 void nrf_usbd_ep_unstall(uint8_t ep)
1288 {
1289 NRFX_ASSERT(!NRF_USBD_EPISO_CHECK(ep));
1290 NRF_USBD->EPSTALL = (USBD_EPSTALL_STALL_UnStall << USBD_EPSTALL_STALL_Pos) | ep;
1291 __ISB();
1292 __DSB();
1293 }
1294
nrf_usbd_isosplit_set(nrf_usbd_isosplit_t split)1295 void nrf_usbd_isosplit_set(nrf_usbd_isosplit_t split)
1296 {
1297 NRF_USBD->ISOSPLIT = split << USBD_ISOSPLIT_SPLIT_Pos;
1298 }
1299
nrf_usbd_isosplit_get(void)1300 nrf_usbd_isosplit_t nrf_usbd_isosplit_get(void)
1301 {
1302 return (nrf_usbd_isosplit_t)
1303 (((NRF_USBD->ISOSPLIT) & USBD_ISOSPLIT_SPLIT_Msk) >> USBD_ISOSPLIT_SPLIT_Pos);
1304 }
1305
nrf_usbd_framecntr_get(void)1306 uint32_t nrf_usbd_framecntr_get(void)
1307 {
1308 return NRF_USBD->FRAMECNTR;
1309 }
1310
nrf_usbd_lowpower_enable(void)1311 void nrf_usbd_lowpower_enable(void)
1312 {
1313 NRF_USBD->LOWPOWER = USBD_LOWPOWER_LOWPOWER_LowPower << USBD_LOWPOWER_LOWPOWER_Pos;
1314 }
1315
nrf_usbd_lowpower_disable(void)1316 void nrf_usbd_lowpower_disable(void)
1317 {
1318 NRF_USBD->LOWPOWER = USBD_LOWPOWER_LOWPOWER_ForceNormal << USBD_LOWPOWER_LOWPOWER_Pos;
1319 }
1320
nrf_usbd_lowpower_check(void)1321 bool nrf_usbd_lowpower_check(void)
1322 {
1323 return (NRF_USBD->LOWPOWER != (USBD_LOWPOWER_LOWPOWER_ForceNormal << USBD_LOWPOWER_LOWPOWER_Pos));
1324 }
1325
nrf_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config)1326 void nrf_usbd_isoinconfig_set(nrf_usbd_isoinconfig_t config)
1327 {
1328 NRF_USBD->ISOINCONFIG = ((uint32_t)config) << USBD_ISOINCONFIG_RESPONSE_Pos;
1329 }
1330
nrf_usbd_isoinconfig_get(void)1331 nrf_usbd_isoinconfig_t nrf_usbd_isoinconfig_get(void)
1332 {
1333 return (nrf_usbd_isoinconfig_t)
1334 (((NRF_USBD->ISOINCONFIG) & USBD_ISOINCONFIG_RESPONSE_Msk) >> USBD_ISOINCONFIG_RESPONSE_Pos);
1335 }
1336
nrf_usbd_ep_easydma_set(uint8_t ep,uint32_t ptr,uint32_t maxcnt)1337 void nrf_usbd_ep_easydma_set(uint8_t ep, uint32_t ptr, uint32_t maxcnt)
1338 {
1339 if (NRF_USBD_EPIN_CHECK(ep))
1340 {
1341 if (NRF_USBD_EPISO_CHECK(ep))
1342 {
1343 NRF_USBD->ISOIN.PTR = ptr;
1344 NRF_USBD->ISOIN.MAXCNT = maxcnt;
1345 }
1346 else
1347 {
1348 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1349 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPIN));
1350 NRF_USBD->EPIN[epnr].PTR = ptr;
1351 NRF_USBD->EPIN[epnr].MAXCNT = maxcnt;
1352 }
1353 }
1354 else
1355 {
1356 if (NRF_USBD_EPISO_CHECK(ep))
1357 {
1358 NRF_USBD->ISOOUT.PTR = ptr;
1359 NRF_USBD->ISOOUT.MAXCNT = maxcnt;
1360 }
1361 else
1362 {
1363 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1364 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT));
1365 NRF_USBD->EPOUT[epnr].PTR = ptr;
1366 NRF_USBD->EPOUT[epnr].MAXCNT = maxcnt;
1367 }
1368 }
1369 }
1370
nrf_usbd_ep_amount_get(uint8_t ep)1371 uint32_t nrf_usbd_ep_amount_get(uint8_t ep)
1372 {
1373 uint32_t ret;
1374
1375 if (NRF_USBD_EPIN_CHECK(ep))
1376 {
1377 if (NRF_USBD_EPISO_CHECK(ep))
1378 {
1379 ret = NRF_USBD->ISOIN.AMOUNT;
1380 }
1381 else
1382 {
1383 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1384 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT));
1385 ret = NRF_USBD->EPIN[epnr].AMOUNT;
1386 }
1387 }
1388 else
1389 {
1390 if (NRF_USBD_EPISO_CHECK(ep))
1391 {
1392 ret = NRF_USBD->ISOOUT.AMOUNT;
1393 }
1394 else
1395 {
1396 uint8_t epnr = NRF_USBD_EP_NR_GET(ep);
1397 NRFX_ASSERT(epnr < NRFX_ARRAY_SIZE(NRF_USBD->EPOUT));
1398 ret = NRF_USBD->EPOUT[epnr].AMOUNT;
1399 }
1400 }
1401
1402 return ret;
1403 }
1404
1405 #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
1406
1407 /** @} */
1408
1409 #ifdef __cplusplus
1410 }
1411 #endif
1412
1413 #endif /* NRF_USBD_H__ */
1414