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