1 /*
2  * Copyright (c) 2016 - 2023, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* This file is undergoing transition towards native Zephyr nrf USB driver. */
8 
9 /** @cond INTERNAL_HIDDEN */
10 
11 #ifndef NRF_USBD_COMMON_H__
12 #define NRF_USBD_COMMON_H__
13 
14 #include <nrfx.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * @defgroup nrf_usbd_common USBD driver
22  * @{
23  * @ingroup nrf_usbd
24  * @brief   Universal Serial Bus Device (USBD) peripheral driver.
25  */
26 
27 /**
28  * @brief Number of bytes in the endpoint.
29  */
30 #define NRF_USBD_COMMON_EPSIZE 64
31 
32 /**
33  * @brief Number of bytes for isochronous endpoints.
34  *
35  * Number of bytes for isochronous endpoints in total.
36  * This number would be shared between IN and OUT endpoint.
37  * It may be also assigned totaly to one endpoint.
38  * @sa nrf_usbd_isosplit_set
39  * @sa nrf_usbd_isosplit_get
40  */
41 #define NRF_USBD_COMMON_ISOSIZE 1023
42 
43 /**
44  * @name Macros for creating endpoint identifiers.
45  *
46  * Auxiliary macros for creating endpoint identifiers compatible with the USB specification.
47  * @{
48  */
49 
50 /**
51  * @brief Create identifier for IN endpoint.
52  *
53  * Simple macro to create IN endpoint identifier for given endpoint number.
54  *
55  * @param[in] n Endpoint number.
56  *
57  * @return Endpoint identifier that connects endpoint number and endpoint direction.
58  */
59 #define NRF_USBD_COMMON_EPIN(n)  ((nrf_usbd_common_ep_t)(0x80 | n))
60 /**
61  * @brief Create identifier for OUT endpoint.
62  *
63  * Simple macro to create OUT endpoint identifier for given endpoint number.
64  *
65  * @param[in] n Endpoint number.
66  *
67  * @return Endpoint identifier that connects endpoint number and endpoint direction.
68  */
69 #define NRF_USBD_COMMON_EPOUT(n) ((nrf_usbd_common_ep_t)(n))
70 /** @} */
71 
72 /**
73  * @brief Endpoint identifier.
74  *
75  * Endpoint identifier used in the driver.
76  * This endpoint number is consistent with USB 2.0 specification.
77  */
78 typedef enum {
79 	NRF_USBD_COMMON_EPOUT0 = 0x00, /**< Endpoint OUT 0 */
80 	NRF_USBD_COMMON_EPOUT1 = 0x01, /**< Endpoint OUT 1 */
81 	NRF_USBD_COMMON_EPOUT2 = 0x02, /**< Endpoint OUT 2 */
82 	NRF_USBD_COMMON_EPOUT3 = 0x03, /**< Endpoint OUT 3 */
83 	NRF_USBD_COMMON_EPOUT4 = 0x04, /**< Endpoint OUT 4 */
84 	NRF_USBD_COMMON_EPOUT5 = 0x05, /**< Endpoint OUT 5 */
85 	NRF_USBD_COMMON_EPOUT6 = 0x06, /**< Endpoint OUT 6 */
86 	NRF_USBD_COMMON_EPOUT7 = 0x07, /**< Endpoint OUT 7 */
87 	NRF_USBD_COMMON_EPOUT8 = 0x08, /**< Endpoint OUT 8 */
88 
89 	NRF_USBD_COMMON_EPIN0 = 0x80, /**< Endpoint IN 0 */
90 	NRF_USBD_COMMON_EPIN1 = 0x81, /**< Endpoint IN 1 */
91 	NRF_USBD_COMMON_EPIN2 = 0x82, /**< Endpoint IN 2 */
92 	NRF_USBD_COMMON_EPIN3 = 0x83, /**< Endpoint IN 3 */
93 	NRF_USBD_COMMON_EPIN4 = 0x84, /**< Endpoint IN 4 */
94 	NRF_USBD_COMMON_EPIN5 = 0x85, /**< Endpoint IN 5 */
95 	NRF_USBD_COMMON_EPIN6 = 0x86, /**< Endpoint IN 6 */
96 	NRF_USBD_COMMON_EPIN7 = 0x87, /**< Endpoint IN 7 */
97 	NRF_USBD_COMMON_EPIN8 = 0x88, /**< Endpoint IN 8 */
98 } nrf_usbd_common_ep_t;
99 
100 /**
101  * @brief Events generated by the driver.
102  *
103  * Enumeration of possible events that may be generated by the driver.
104  */
105 typedef enum {
106 	NRF_USBD_COMMON_EVT_SOF,        /**< Start Of Frame event on USB bus detected. */
107 	NRF_USBD_COMMON_EVT_RESET,      /**< Reset condition on USB bus detected. */
108 	NRF_USBD_COMMON_EVT_SUSPEND,    /**< This device should go to suspend mode now. */
109 	NRF_USBD_COMMON_EVT_RESUME,     /**< This device should resume from suspend now. */
110 	/** Wakeup request - the USBD peripheral is ready to generate
111 	 * WAKEUP signal after exiting low power mode.
112 	 */
113 	NRF_USBD_COMMON_EVT_WUREQ,
114 	NRF_USBD_COMMON_EVT_SETUP,      /**< Setup frame received and decoded. */
115 	/** For Rx (OUT: Host->Device):
116 	 *   1. The packet has been received but there is no buffer
117 	 * prepared for transfer already.
118 	 *   2. Whole transfer has been finished.
119 	 *
120 	 *   For Tx (IN: Device->Host):
121 	 *   The last packet from requested transfer has been transferred
122 	 * over USB bus and acknowledged.
123 	 */
124 	NRF_USBD_COMMON_EVT_EPTRANSFER,
125 	NRF_USBD_COMMON_EVT_CNT         /**< Number of defined events. */
126 } nrf_usbd_common_event_type_t;
127 
128 /**
129  * @brief Endpoint status codes.
130  *
131  * Status codes that may be returned by @ref nrf_usbd_common_ep_status_get or, except for
132  * @ref NRF_USBD_COMMON_EP_BUSY, reported together with @ref NRF_USBD_COMMON_EVT_EPTRANSFER.
133  */
134 typedef enum {
135 	/** No error occurred. */
136 	NRF_USBD_COMMON_EP_OK,
137 	/** Data received, no buffer prepared already - waiting for configured transfer. */
138 	NRF_USBD_COMMON_EP_WAITING,
139 	/** Received number of bytes cannot fit given buffer.
140 	 * This error would also be returned when next_transfer function
141 	 * has been defined but currently received data cannot fit completely
142 	 * in current buffer. No data split from single endpoint transmission
143 	 * is supported.
144 	 *
145 	 *   When this error is reported - data is left inside endpoint
146 	 * buffer. Clear endpoint or prepare new buffer and read it.
147 	 */
148 	NRF_USBD_COMMON_EP_OVERLOAD,
149 	/** EP0 transfer can be aborted when new setup comes.
150 	 * Any other transfer can be aborted by USB reset or driver stopping.
151 	 */
152 	NRF_USBD_COMMON_EP_ABORTED,
153 	/** Transfer is in progress. */
154 	NRF_USBD_COMMON_EP_BUSY,
155 } nrf_usbd_common_ep_status_t;
156 
157 /**
158  * @brief Event structure.
159  *
160  * Structure passed to event handler.
161  */
162 typedef struct {
163 	nrf_usbd_common_event_type_t type; /**< Event type. */
164 	union {
165 		struct {
166 			uint16_t framecnt; /**< Current value of frame counter. */
167 		} sof;                     /**< Data available for @ref NRF_USBD_COMMON_EVT_SOF. */
168 		struct {
169 			nrf_usbd_common_ep_t ep; /**< Endpoint number. */
170 		} isocrc;                  /**< Isochronouns channel endpoint number. */
171 		struct {
172 			nrf_usbd_common_ep_t ep;            /**< Endpoint number. */
173 			nrf_usbd_common_ep_status_t status; /**< Status for the endpoint. */
174 		} eptransfer;                         /**< Endpoint transfer status. */
175 	} data;                                       /**< Union to store event data. */
176 } nrf_usbd_common_evt_t;
177 
178 /**
179  * @brief USBD event callback function type.
180  *
181  * @param[in] p_event Event information structure.
182  */
183 typedef void (*nrf_usbd_common_event_handler_t)(nrf_usbd_common_evt_t const *p_event);
184 
185 /**
186  * @brief Universal data pointer.
187  *
188  * Universal data pointer that can be used for any type of transfer.
189  */
190 typedef union {
191 	void const *tx; /*!< Constant TX buffer pointer. */
192 	void *rx;       /*!< Writable RX buffer pointer. */
193 	uint32_t addr;  /*!< Numeric value used internally by the driver. */
194 } nrf_usbd_common_data_ptr_t;
195 
196 /**
197  * @brief Structure to be filled with information about the next transfer.
198  *
199  * This is used mainly for transfer feeders and consumers.
200  * It describes a single endpoint transfer and therefore the size of the buffer
201  * can never be higher than the endpoint size.
202  */
203 typedef struct {
204 	/** Union with available data pointers used by the driver. */
205 	nrf_usbd_common_data_ptr_t p_data;
206 	/** Size of the requested transfer. */
207 	size_t size;
208 } nrf_usbd_common_ep_transfer_t;
209 
210 /**
211  * @brief Flags for the current transfer.
212  *
213  * Flags configured for the transfer that can be merged using the bitwise 'or' operator (|).
214  */
215 typedef enum {
216 	NRF_USBD_COMMON_TRANSFER_ZLP_FLAG = 1U << 0, /*!< Add a zero-length packet. */
217 } nrf_usbd_common_transfer_flags_t;
218 
219 /**
220  * @brief Total transfer configuration.
221  *
222  * This structure is used to configure total transfer information.
223  * It is used by internal built-in feeders and consumers.
224  */
225 typedef struct {
226 	/** Union with available data pointers used by the driver. */
227 	nrf_usbd_common_data_ptr_t p_data;
228 	/** Total size of the requested transfer. */
229 	size_t size;
230 	/*!< Transfer flags. Use the @ref nrf_usbd_common_transfer_flags_t values. */
231 	uint32_t flags;
232 } nrf_usbd_common_transfer_t;
233 
234 /**
235  * @brief Auxiliary macro for declaring IN transfer description with optional flags.
236  *
237  * The base macro for creating transfers with any configuration option.
238  *
239  * @param name     Instance name.
240  * @param tx_buff  Buffer to transfer.
241  * @param tx_size  Transfer size.
242  * @param tx_flags Flags for the transfer (see @ref nrf_usbd_common_transfer_flags_t).
243  *
244  * @return Configured variable with total transfer description.
245  */
246 #define NRF_USBD_COMMON_TRANSFER_IN(name, tx_buff, tx_size, tx_flags)                 \
247 	const nrf_usbd_common_transfer_t name = {                                     \
248 		.p_data = {.tx = (tx_buff)}, .size = (tx_size), .flags = (tx_flags)}
249 
250 /**
251  * @brief Helper macro for declaring OUT transfer item (@ref nrf_usbd_common_transfer_t).
252  *
253  * @param name    Instance name.
254  * @param rx_buff Buffer to transfer.
255  * @param rx_size Transfer size.
256  */
257 #define NRF_USBD_COMMON_TRANSFER_OUT(name, rx_buff, rx_size)                          \
258 	const nrf_usbd_common_transfer_t name = {                                     \
259 		.p_data = {.rx = (rx_buff)}, .size = (rx_size), .flags = 0}
260 
261 /**
262  * @brief Setup packet structure.
263  *
264  * Structure that contains interpreted SETUP packet as described in USB specification.
265  */
266 typedef struct {
267 	uint8_t bmRequestType; /*!< byte 0 */
268 	uint8_t bRequest;      /*!< byte 1 */
269 	uint16_t wValue;       /*!< byte 2, 3 */
270 	uint16_t wIndex;       /*!< byte 4, 5 */
271 	uint16_t wLength;      /*!< byte 6, 7 */
272 } nrf_usbd_common_setup_t;
273 
274 /**
275  * @brief Driver initialization.
276  *
277  * @param[in] event_handler Event handler provided by the user. Cannot be null.
278  *
279  * @retval NRFX_SUCCESS             Initialization successful.
280  * @retval NRFX_ERROR_INVALID_STATE Driver was already initialized.
281  */
282 nrfx_err_t nrf_usbd_common_init(nrf_usbd_common_event_handler_t event_handler);
283 
284 /**
285  * @brief Driver deinitialization.
286  */
287 void nrf_usbd_common_uninit(void);
288 
289 /**
290  * @brief Enable the USBD port.
291  *
292  * After calling this function USBD peripheral would be enabled.
293  * The USB LDO would be enabled.
294  * Enabled USBD peripheral would request HFCLK.
295  * This function does not enable external oscillator, so if it is not enabled by other part of the
296  * program after enabling USBD driver HFINT would be used for the USBD peripheral.
297  * It is perfectly fine until USBD is started. See @ref nrf_usbd_common_start.
298  *
299  * In normal situation this function should be called in reaction to USBDETECTED
300  * event from POWER peripheral.
301  *
302  * Interrupts and USB pins pull-up would stay disabled until @ref nrf_usbd_common_start
303  * function is called.
304  */
305 void nrf_usbd_common_enable(void);
306 
307 /**
308  * @brief Disable the USBD port.
309  *
310  * After calling this function USBD peripheral would be disabled.
311  * No events would be detected or processed by the driver.
312  * Clock for the peripheral would be disconnected.
313  */
314 void nrf_usbd_common_disable(void);
315 
316 /**
317  * @brief Start USB functionality.
318  *
319  * After calling this function USBD peripheral should be fully functional
320  * and all new incoming events / interrupts would be processed by the driver.
321  *
322  * Also only after calling this function host sees new connected device.
323  *
324  * Call this function when USBD power LDO regulator is ready - on USBPWRRDY event
325  * from POWER peripheral.
326  *
327  * Before USBD interrupts are enabled, external HFXO is requested.
328  *
329  * @param enable_sof The flag that is used to enable SOF processing.
330  *                   If it is false, SOF interrupt is left disabled and will not be generated.
331  *                   This improves power saving if SOF is not required.
332  *
333  * @note If the isochronous endpoints are going to be used,
334  *       it is required to enable the SOF.
335  *       In other case any isochronous endpoint would stay busy
336  *       after first transmission.
337  */
338 void nrf_usbd_common_start(bool enable_sof);
339 
340 /**
341  * @brief Check if driver is initialized.
342  *
343  * @retval false Driver is not initialized.
344  * @retval true Driver is initialized.
345  */
346 bool nrf_usbd_common_is_initialized(void);
347 
348 /**
349  * @brief Check if driver is enabled.
350  *
351  * @retval false Driver is disabled.
352  * @retval true  Driver is enabled.
353  */
354 bool nrf_usbd_common_is_enabled(void);
355 
356 /**
357  * @brief Check if driver is started.
358  *
359  * @retval false Driver is not started.
360  * @retval true Driver is started (fully functional).
361  * @note The USBD peripheral interrupt state is checked.
362  */
363 bool nrf_usbd_common_is_started(void);
364 
365 /**
366  * @brief Suspend USBD operation.
367  *
368  * The USBD peripheral is forced to go into the low power mode.
369  * The function has to be called in the reaction to @ref NRF_USBD_COMMON_EVT_SUSPEND event
370  * when the firmware is ready.
371  *
372  * After successful call of this function most of the USBD registers would be unavailable.
373  *
374  * @note Check returned value for the feedback if suspending was successful.
375  *
376  * @retval true  USBD peripheral successfully suspended.
377  * @retval false USBD peripheral was not suspended due to resume detection.
378  */
379 bool nrf_usbd_common_suspend(void);
380 
381 /**
382  * @brief Start wake up procedure.
383  *
384  * The USBD peripheral is forced to quit the low power mode.
385  * After calling this function all the USBD registers would be available.
386  *
387  * The hardware starts measuring time when wake up is possible.
388  * This may take 0-5&nbsp;ms depending on how long the SUSPEND state was kept on the USB line.
389 
390  * When NRF_USBD_COMMON_EVT_WUREQ event is generated it means that Wake Up signaling has just been
391  * started on the USB lines.
392  *
393  * @note Do not expect only @ref NRF_USBD_COMMON_EVT_WUREQ event.
394  *       There always may appear @ref NRF_USBD_COMMON_EVT_RESUME event.
395  * @note NRF_USBD_COMMON_EVT_WUREQ event means that Remote WakeUp signal
396  *       has just begun to be generated.
397  *       This may take up to 20&nbsp;ms for the bus to become active.
398  *
399  * @retval true WakeUp procedure started.
400  * @retval false No WakeUp procedure started - bus is already active.
401  */
402 bool nrf_usbd_common_wakeup_req(void);
403 
404 /**
405  * @brief Check if USBD is in SUSPEND mode.
406  *
407  * @note This is the information about peripheral itself, not about the bus state.
408  *
409  * @retval true  USBD peripheral is suspended.
410  * @retval false USBD peripheral is active.
411  */
412 bool nrf_usbd_common_suspend_check(void);
413 
414 /**
415  * @brief Check the bus state.
416  *
417  * This function checks if the bus state is suspended.
418  *
419  * @note The value returned by this function changes on SUSPEND and RESUME event processing.
420  *
421  * @retval true  USBD bus is suspended.
422  * @retval false USBD bus is active.
423  */
424 bool nrf_usbd_common_bus_suspend_check(void);
425 
426 /**
427  * @brief Force the bus state to active
428  */
429 void nrf_usbd_common_force_bus_wakeup(void);
430 
431 /**
432  * @brief Configure packet size that should be supported by the endpoint.
433  *
434  * The real endpoint buffer size is always the same.
435  * This value sets max packet size that would be transmitted over the endpoint.
436  * This is required by the driver.
437  *
438  * @param[in] ep   Endpoint number.
439  * @param[in] size Required maximum packet size.
440  *
441  * @note Endpoint size is always set to @ref NRF_USBD_COMMON_EPSIZE
442  *       or @ref NRF_USBD_COMMON_ISOSIZE / 2
443  *       when @ref nrf_usbd_common_ep_enable function is called.
444  */
445 void nrf_usbd_common_ep_max_packet_size_set(nrf_usbd_common_ep_t ep, uint16_t size);
446 
447 /**
448  * @brief Get configured endpoint packet size.
449  *
450  * Function to get configured endpoint size on the buffer.
451  *
452  * @param[in] ep Endpoint number.
453  *
454  * @return Maximum pocket size configured on selected endpoint.
455  */
456 uint16_t nrf_usbd_common_ep_max_packet_size_get(nrf_usbd_common_ep_t ep);
457 
458 /**
459  * @brief Check if the selected endpoint is enabled.
460  *
461  * @param[in] ep Endpoint number to check.
462  *
463  * @retval true  Endpoint is enabled.
464  * @retval false Endpoint is disabled.
465  */
466 bool nrf_usbd_common_ep_enable_check(nrf_usbd_common_ep_t ep);
467 
468 /**
469  * @brief Enable selected endpoint.
470  *
471  * This function enables endpoint itself and its interrupts.
472  *
473  * @param[in] ep Endpoint number to enable.
474  *
475  * @note
476  * Max packet size is set to endpoint default maximum value.
477  *
478  * @sa nrf_usbd_common_ep_max_packet_size_set
479  */
480 void nrf_usbd_common_ep_enable(nrf_usbd_common_ep_t ep);
481 
482 /**
483  * @brief Disable selected endpoint.
484  *
485  * This function disables endpoint itself and its interrupts.
486  *
487  * @param[in] ep Endpoint number to disable.
488  */
489 void nrf_usbd_common_ep_disable(nrf_usbd_common_ep_t ep);
490 
491 /**
492  * @brief Start sending data over endpoint.
493  *
494  * Function initializes endpoint transmission.
495  * This is asynchronous function - it finishes immediately after configuration
496  * for transmission is prepared.
497  *
498  * @note Data buffer pointed by p_data have to be kept active till
499  *       @ref NRF_USBD_COMMON_EVT_EPTRANSFER event is generated.
500  *
501  * @param[in] ep         Endpoint number.
502  *                       For IN endpoint sending would be initiated.
503  *                       For OUT endpoint receiving would be initiated.
504  * @param[in] p_transfer Transfer parameters.
505  *
506  * @retval NRFX_SUCCESS             Transfer queued or started.
507  * @retval NRFX_ERROR_BUSY          Selected endpoint is pending.
508  * @retval NRFX_ERROR_INVALID_ADDR  Unexpected transfer on EPIN0 or EPOUT0.
509  */
510 nrfx_err_t nrf_usbd_common_ep_transfer(nrf_usbd_common_ep_t ep,
511 				       nrf_usbd_common_transfer_t const *p_transfer);
512 
513 /**
514  * @brief Get the information about last finished or current transfer.
515  *
516  * Function returns the status of the last buffer set for transfer on selected endpoint.
517  * The status considers last buffer set by @ref nrf_usbd_common_ep_transfer function or
518  * by transfer callback function.
519  *
520  * @param[in]  ep     Endpoint number.
521  * @param[out] p_size Information about the current/last transfer size.
522  *
523  * @return Endpoint status.
524  *
525  * @sa nrf_usbd_common_ep_status_t
526  */
527 nrf_usbd_common_ep_status_t nrf_usbd_common_ep_status_get(nrf_usbd_common_ep_t ep, size_t *p_size);
528 
529 /**
530  * @brief Get number of received bytes.
531  *
532  * Get the number of received bytes.
533  * The function behavior is undefined when called on IN endpoint.
534  *
535  * @param[in] ep Endpoint number.
536  *
537  * @return Number of received bytes.
538  */
539 size_t nrf_usbd_common_epout_size_get(nrf_usbd_common_ep_t ep);
540 
541 /**
542  * @brief Check if endpoint buffer is ready or is under USB IP control.
543  *
544  * Function to test if endpoint is busy.
545  * Endpoint that is busy cannot be accessed by MCU.
546  * It means that:
547  * - OUT (TX) endpoint: Last uploaded data is still in endpoint and is waiting
548  *                      to be received by the host.
549  * - IN  (RX) endpoint: Endpoint is ready to receive data from the host
550  *                      and the endpoint does not have any data.
551  * When endpoint is not busy:
552  * - OUT (TX) endpoint: New data can be uploaded.
553  * - IN  (RX) endpoint: New data can be downloaded using @ref nrf_usbd_common_ep_transfer
554  *                      function.
555  *
556  * @param[in] ep Endpoint number.
557  *
558  * @retval false Endpoint is not busy.
559  * @retval true  Endpoint is busy.
560  */
561 bool nrf_usbd_common_ep_is_busy(nrf_usbd_common_ep_t ep);
562 
563 /**
564  * @brief Stall endpoint
565  *
566  * Stall endpoit to send error information during next transfer request from
567  * the host.
568  *
569  * @note To stall endpoint it is safer to use @ref nrf_usbd_common_setup_stall
570  * @note Stalled endpoint would not be cleared when DMA transfer finishes.
571  *
572  * @param[in] ep Endpoint number to stall.
573  */
574 void nrf_usbd_common_ep_stall(nrf_usbd_common_ep_t ep);
575 
576 /**
577  * @brief Clear stall flag on endpoint.
578  *
579  * This function clears endpoint that is stalled.
580  * @note
581  * If it is OUT endpoint (receiving) it would be also prepared for reception.
582  * It means that busy flag would be set.
583  * @note
584  * In endpoint (transmitting) would not be cleared - it gives possibility to
585  * write new data before transmitting.
586  *
587  * @param[in] ep Endpoint number.
588  */
589 void nrf_usbd_common_ep_stall_clear(nrf_usbd_common_ep_t ep);
590 
591 /**
592  * @brief Check if endpoint is stalled.
593  *
594  * This function gets stall state of selected endpoint.
595  *
596  * @param[in] ep Endpoint number to check.
597  *
598  * @retval false Endpoint is not stalled.
599  * @retval true  Endpoint is stalled.
600  */
601 bool nrf_usbd_common_ep_stall_check(nrf_usbd_common_ep_t ep);
602 
603 /**
604  * @brief Clear current endpoint data toggle.
605  *
606  * @param[in] ep Endpoint number to clear.
607  */
608 void nrf_usbd_common_ep_dtoggle_clear(nrf_usbd_common_ep_t ep);
609 
610 /**
611  * @brief Get parsed setup data.
612  *
613  * Function fills the parsed setup data structure.
614  *
615  * @param[out] p_setup Pointer to data structure that would be filled by
616  *                     parsed data.
617  */
618 void nrf_usbd_common_setup_get(nrf_usbd_common_setup_t *p_setup);
619 
620 /**
621  * @brief Clear the control endpoint for packet reception during DATA stage.
622  *
623  * This function may be called if any more data in control write transfer is expected.
624  * Clears only OUT endpoint to be able to take another OUT data token.
625  * It does not allow STATUS stage.
626  * @sa nrf_usbd_common_setup_clear
627  */
628 void nrf_usbd_common_setup_data_clear(void);
629 
630 /**
631  * @brief Clear setup endpoint.
632  *
633  * This function acknowledges setup when SETUP command was received and processed.
634  * It has to be called if no data respond for the SETUP command is sent.
635  */
636 void nrf_usbd_common_setup_clear(void);
637 
638 /**
639  * @brief Stall setup endpoint.
640  *
641  * Mark an error on setup endpoint.
642  */
643 void nrf_usbd_common_setup_stall(void);
644 
645 /**
646  * @brief Abort pending transfer on selected endpoint.
647  *
648  * @param[in] ep Endpoint number.
649  */
650 void nrf_usbd_common_ep_abort(nrf_usbd_common_ep_t ep);
651 
652 /**
653  * @brief Get the information about expected transfer SETUP data direction.
654  *
655  * Function returns the information about last expected transfer direction.
656  *
657  * @retval NRF_USBD_COMMON_EPOUT0 Expecting OUT (Host->Device) direction or no data.
658  * @retval NRF_USBD_COMMON_EPIN0  Expecting IN (Device->Host) direction.
659  */
660 nrf_usbd_common_ep_t nrf_usbd_common_last_setup_dir_get(void);
661 
662 /**
663  * @brief Drop transfer on OUT endpoint.
664  *
665  * @param[in] ep  OUT endpoint ID.
666  */
667 void nrf_usbd_common_transfer_out_drop(nrf_usbd_common_ep_t ep);
668 
669 /** @} */
670 
671 void nrf_usbd_common_irq_handler(void);
672 
673 #ifdef __cplusplus
674 }
675 #endif
676 
677 #endif /* NRF_USBD_COMMON_H__ */
678 
679 /** @endcond */
680