nrf_usbd.h 50 KB

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