nrf_usbd.h 50 KB

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