nrf_qdec.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /**
  2. * Copyright (c) 2014 - 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_QDEC_H__
  41. #define NRF_QDEC_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_qdec_hal QDEC HAL
  48. * @{
  49. * @ingroup nrf_qdec
  50. * @brief Hardware access layer for managing the Quadrature Decoder (QDEC) peripheral.
  51. */
  52. /**
  53. * @brief This value can be provided as a parameter for the @ref nrf_qdec_pio_assign
  54. * function call to specify that a LED signal shall not be use by the QDEC and
  55. * connected to a physical pin.
  56. */
  57. #define NRF_QDEC_LED_NOT_CONNECTED 0xFFFFFFFF
  58. /**
  59. * @enum nrf_qdec_task_t
  60. * @brief QDEC tasks.
  61. */
  62. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  63. {
  64. NRF_QDEC_TASK_START = offsetof(NRF_QDEC_Type, TASKS_START), /**< Starting the quadrature decoder. */
  65. NRF_QDEC_TASK_STOP = offsetof(NRF_QDEC_Type, TASKS_STOP), /**< Stopping the quadrature decoder. */
  66. NRF_QDEC_TASK_READCLRACC = offsetof(NRF_QDEC_Type, TASKS_READCLRACC) /**< Reading and clearing ACC and ACCDBL registers. */
  67. } nrf_qdec_task_t;
  68. /**
  69. * @enum nrf_qdec_event_t
  70. * @brief QDEC events.
  71. */
  72. typedef enum
  73. {
  74. NRF_QDEC_EVENT_SAMPLERDY = offsetof(NRF_QDEC_Type, EVENTS_SAMPLERDY), /**< Event generated for every new sample. */
  75. NRF_QDEC_EVENT_REPORTRDY = offsetof(NRF_QDEC_Type, EVENTS_REPORTRDY), /**< Event generated for every new report. */
  76. NRF_QDEC_EVENT_ACCOF = offsetof(NRF_QDEC_Type, EVENTS_ACCOF) /**< Event generated for every accumulator overflow. */
  77. } nrf_qdec_event_t; /*lint -restore */
  78. /**
  79. * @enum nrf_qdec_short_mask_t
  80. * @brief QDEC shortcuts.
  81. */
  82. typedef enum
  83. {
  84. NRF_QDEC_SHORT_REPORTRDY_READCLRACC_MASK = QDEC_SHORTS_REPORTRDY_READCLRACC_Msk, /**< Shortcut between REPORTRDY event and READCLRACC task. */
  85. NRF_QDEC_SHORT_SAMPLERDY_STOP_MASK = QDEC_SHORTS_SAMPLERDY_STOP_Msk /**< Shortcut between SAMPLERDY event and STOP task. */
  86. } nrf_qdec_short_mask_t;
  87. /**
  88. * @enum nrf_qdec_int_mask_t
  89. * @brief QDEC interrupts.
  90. */
  91. typedef enum
  92. {
  93. NRF_QDEC_INT_SAMPLERDY_MASK = QDEC_INTENSET_SAMPLERDY_Msk, /**< Mask for enabling or disabling an interrupt on SAMPLERDY event. */
  94. NRF_QDEC_INT_REPORTRDY_MASK = QDEC_INTENSET_REPORTRDY_Msk, /**< Mask for enabling or disabling an interrupt on REPORTRDY event. */
  95. NRF_QDEC_INT_ACCOF_MASK = QDEC_INTENSET_ACCOF_Msk /**< Mask for enabling or disabling an interrupt on ACCOF event. */
  96. } nrf_qdec_int_mask_t;
  97. /**
  98. * @enum nrf_qdec_enable_t
  99. * @brief States of the enable bit.
  100. */
  101. typedef enum
  102. {
  103. NRF_QDEC_DISABLE = QDEC_ENABLE_ENABLE_Disabled, /**< Mask for disabling the QDEC periperal. When disabled, the QDEC decoder pins are not active. */
  104. NRF_QDEC_ENABLE = QDEC_ENABLE_ENABLE_Enabled /**< Mask for enabling the QDEC periperal. When enabled, the QDEC pins are active. */
  105. } nrf_qdec_enable_t;
  106. /**
  107. * @enum nrf_qdec_dbfen_t
  108. * @brief States of the debounce filter enable bit.
  109. */
  110. typedef enum
  111. {
  112. NRF_QDEC_DBFEN_DISABLE = QDEC_DBFEN_DBFEN_Disabled, /**< Mask for disabling the debounce filter. */
  113. NRF_QDEC_DBFEN_ENABLE = QDEC_DBFEN_DBFEN_Enabled /**< Mask for enabling the debounce filter. */
  114. } nrf_qdec_dbfen_t;
  115. /**
  116. * @enum nrf_qdec_ledpol_t
  117. * @brief Active LED polarity.
  118. */
  119. typedef enum
  120. {
  121. NRF_QDEC_LEPOL_ACTIVE_LOW = QDEC_LEDPOL_LEDPOL_ActiveLow, /**< QDEC LED active on output pin low. */
  122. NRF_QDEC_LEPOL_ACTIVE_HIGH = QDEC_LEDPOL_LEDPOL_ActiveHigh /**< QDEC LED active on output pin high. */
  123. } nrf_qdec_ledpol_t;
  124. /**
  125. * @enum nrf_qdec_sampleper_t
  126. * @brief Available sampling periods.
  127. */
  128. typedef enum
  129. {
  130. NRF_QDEC_SAMPLEPER_128us = QDEC_SAMPLEPER_SAMPLEPER_128us, /**< QDEC sampling period 128 microseconds. */
  131. NRF_QDEC_SAMPLEPER_256us = QDEC_SAMPLEPER_SAMPLEPER_256us, /**< QDEC sampling period 256 microseconds. */
  132. NRF_QDEC_SAMPLEPER_512us = QDEC_SAMPLEPER_SAMPLEPER_512us, /**< QDEC sampling period 512 microseconds. */
  133. NRF_QDEC_SAMPLEPER_1024us = QDEC_SAMPLEPER_SAMPLEPER_1024us, /**< QDEC sampling period 1024 microseconds. */
  134. NRF_QDEC_SAMPLEPER_2048us = QDEC_SAMPLEPER_SAMPLEPER_2048us, /**< QDEC sampling period 2048 microseconds. */
  135. NRF_QDEC_SAMPLEPER_4096us = QDEC_SAMPLEPER_SAMPLEPER_4096us, /**< QDEC sampling period 4096 microseconds. */
  136. NRF_QDEC_SAMPLEPER_8192us = QDEC_SAMPLEPER_SAMPLEPER_8192us, /**< QDEC sampling period 8192 microseconds. */
  137. NRF_QDEC_SAMPLEPER_16384us = QDEC_SAMPLEPER_SAMPLEPER_16384us /**< QDEC sampling period 16384 microseconds. */
  138. } nrf_qdec_sampleper_t;
  139. /**
  140. * @enum nrf_qdec_reportper_t
  141. * @brief Available report periods.
  142. */
  143. typedef enum
  144. {
  145. NRF_QDEC_REPORTPER_10 = QDEC_REPORTPER_REPORTPER_10Smpl, /**< QDEC report period 10 samples. */
  146. NRF_QDEC_REPORTPER_40 = QDEC_REPORTPER_REPORTPER_40Smpl, /**< QDEC report period 40 samples. */
  147. NRF_QDEC_REPORTPER_80 = QDEC_REPORTPER_REPORTPER_80Smpl, /**< QDEC report period 80 samples. */
  148. NRF_QDEC_REPORTPER_120 = QDEC_REPORTPER_REPORTPER_120Smpl, /**< QDEC report period 120 samples. */
  149. NRF_QDEC_REPORTPER_160 = QDEC_REPORTPER_REPORTPER_160Smpl, /**< QDEC report period 160 samples. */
  150. NRF_QDEC_REPORTPER_200 = QDEC_REPORTPER_REPORTPER_200Smpl, /**< QDEC report period 200 samples. */
  151. NRF_QDEC_REPORTPER_240 = QDEC_REPORTPER_REPORTPER_240Smpl, /**< QDEC report period 240 samples. */
  152. NRF_QDEC_REPORTPER_280 = QDEC_REPORTPER_REPORTPER_280Smpl, /**< QDEC report period 280 samples. */
  153. NRF_QDEC_REPORTPER_DISABLED /**< QDEC reporting disabled. */
  154. } nrf_qdec_reportper_t;
  155. /**
  156. * @brief Function for enabling QDEC.
  157. */
  158. __STATIC_INLINE void nrf_qdec_enable(void);
  159. /**
  160. * @brief Function for disabling QDEC.
  161. */
  162. __STATIC_INLINE void nrf_qdec_disable(void);
  163. /**
  164. * @brief Function for returning the enable state of QDEC.
  165. * @return State of the register.
  166. */
  167. __STATIC_INLINE uint32_t nrf_qdec_enable_get(void);
  168. /**
  169. * @brief Function for enabling QDEC interrupts by mask.
  170. * @param[in] qdec_int_mask Sources of the interrupts to enable.
  171. */
  172. __STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask);
  173. /**
  174. * @brief Function for disabling QDEC interrupts by mask.
  175. * @param[in] qdec_int_mask Sources of the interrupts to disable.
  176. *
  177. */
  178. __STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask);
  179. /**
  180. * @brief Function for getting the enabled interrupts of the QDEC.
  181. */
  182. __STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask);
  183. /**
  184. * @brief Function for enabling the debouncing filter of the QED.
  185. */
  186. __STATIC_INLINE void nrf_qdec_dbfen_enable(void);
  187. /**
  188. * @brief Function for disabling the debouncing filter of the QED.
  189. */
  190. __STATIC_INLINE void nrf_qdec_dbfen_disable(void);
  191. /**
  192. * @brief Function for getting the state of the QDEC's debouncing filter.
  193. * @retval NRF_QDEC_DBFEN_DISABLE If the debouncing filter is disabled.
  194. * @retval NRF_QDEC_DBFEN_ENABLE If the debouncing filter is enabled.
  195. */
  196. __STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void);
  197. /**
  198. * @brief Function for assigning QDEC pins.
  199. * @param[in] psela Pin number.
  200. * @param[in] pselb Pin number.
  201. * @param[in] pselled Pin number.
  202. */
  203. __STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled);
  204. /**
  205. * @brief Function for setting a specific QDEC task.
  206. * @param[in] qdec_task QDEC task to be set.
  207. */
  208. __STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t qdec_task);
  209. /**
  210. * @brief Function for retrieving the address of a QDEC task register.
  211. * @param[in] qdec_task QDEC task.
  212. */
  213. __STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t qdec_task);
  214. /**
  215. * @brief Function for clearing a specific QDEC event.
  216. * @param[in] qdec_event QDEC event to clear.
  217. */
  218. __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event);
  219. /**
  220. * @brief Function for retrieving the state of a specific QDEC event.
  221. * @return State of the QDEC event.
  222. */
  223. __STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t qdec_event);
  224. /**
  225. * @brief Function for retrieving the address of a specific QDEC event register.
  226. * @param[in] qdec_event QDEC event.
  227. * @return Address of the specified QDEC event.
  228. */
  229. __STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t qdec_event);
  230. /**
  231. * @brief Function for setting QDEC shortcuts.
  232. * @param[in] qdec_short_mask QDEC shortcut by mask.
  233. */
  234. __STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t qdec_short_mask);
  235. /**
  236. * @brief Function for clearing shortcuts of the QDEC by mask.
  237. * @param[in] qdec_short_mask QDEC shortcute to be cleared.
  238. */
  239. __STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t qdec_short_mask);
  240. /**
  241. * @brief Function for retrieving the value of QDEC's SAMPLEPER register.
  242. * @return Value of the SAMPLEPER register.
  243. */
  244. __STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void);
  245. /**
  246. * @brief Function for converting the value of QDEC's SAMPLE PERIOD to microseconds.
  247. * @retval sampling period in microseconds.
  248. */
  249. __STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper);
  250. /**
  251. * @brief Function for setting the value of QDEC's SAMPLEPER register.
  252. * @param[in] sample_per Sampling period.
  253. */
  254. __STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per);
  255. /**
  256. * @brief Function for retrieving the value of QDEC's SAMPLE register.
  257. * @return Value of the SAMPLE register.
  258. */
  259. __STATIC_INLINE int32_t nrf_qdec_sample_get(void);
  260. /**
  261. * @brief Function for retrieving the value of QDEC's ACC register.
  262. * @return Value of the ACC register.
  263. */
  264. __STATIC_INLINE int32_t nrf_qdec_acc_get(void);
  265. /**
  266. * @brief Function for retrieving the value of QDEC's ACCREAD register.
  267. * @return Value of the ACCREAD register.
  268. */
  269. __STATIC_INLINE int32_t nrf_qdec_accread_get(void);
  270. /**
  271. * @brief Function for retrieving the value of QDEC's ACCDBL register.
  272. * @return Value of the ACCDBL register.
  273. */
  274. __STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void);
  275. /**
  276. * @brief Function for retrieving the value of QDEC's ACCDBLREAD register.
  277. * @return Value of the ACCDBLREAD register.
  278. */
  279. __STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void);
  280. /**
  281. * @brief Function for setting how long the LED is switched on before sampling.
  282. * @param[in] time_us Time (in microseconds) how long the LED is switched on before sampling.
  283. */
  284. __STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us);
  285. /**
  286. * @brief Function for retrieving how long the LED is switched on before sampling.
  287. * @retval time_us Time (in microseconds) how long the LED is switched on before sampling.
  288. */
  289. __STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void);
  290. /**
  291. * @brief Function for setting the report period (in samples).
  292. * @param[in] reportper Number of samples.
  293. */
  294. __STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper);
  295. /**
  296. * @brief Function for retrieving the report period.
  297. * @retval reportper Number of samples as encoded in the register.
  298. */
  299. __STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void);
  300. /**
  301. * @brief Function for retrieving the value of QDEC's SAMPLEPER register.
  302. * @param [in] reportper Reportper to be converted to amount of samples per report.
  303. */
  304. __STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper);
  305. /**
  306. * @brief Function for setting the active level for the LED.
  307. * @param[in] pol Active level for the LED.
  308. */
  309. __STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol);
  310. /**
  311. * @brief Function for retrieving the active level for the LED.
  312. * @return Active level for the LED.
  313. */
  314. __STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void);
  315. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  316. __STATIC_INLINE void nrf_qdec_enable(void)
  317. {
  318. NRF_QDEC->ENABLE = NRF_QDEC_ENABLE;
  319. }
  320. __STATIC_INLINE void nrf_qdec_disable(void)
  321. {
  322. NRF_QDEC->ENABLE = NRF_QDEC_DISABLE;
  323. }
  324. __STATIC_INLINE uint32_t nrf_qdec_enable_get(void)
  325. {
  326. return NRF_QDEC->ENABLE;
  327. }
  328. __STATIC_INLINE void nrf_qdec_int_enable(uint32_t qdec_int_mask)
  329. {
  330. NRF_QDEC->INTENSET = qdec_int_mask; // writing 0 has no effect
  331. }
  332. __STATIC_INLINE void nrf_qdec_int_disable(uint32_t qdec_int_mask)
  333. {
  334. NRF_QDEC->INTENCLR = qdec_int_mask; // writing 0 has no effect
  335. }
  336. __STATIC_INLINE uint32_t nrf_qdec_int_enable_check(nrf_qdec_int_mask_t qdec_int_mask)
  337. {
  338. return NRF_QDEC->INTENSET & qdec_int_mask; // when read this register will return the value of INTEN.
  339. }
  340. __STATIC_INLINE void nrf_qdec_dbfen_enable(void)
  341. {
  342. NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_ENABLE;
  343. }
  344. __STATIC_INLINE void nrf_qdec_dbfen_disable(void)
  345. {
  346. NRF_QDEC->DBFEN = NRF_QDEC_DBFEN_DISABLE;
  347. }
  348. __STATIC_INLINE uint32_t nrf_qdec_dbfen_get(void)
  349. {
  350. return NRF_QDEC->DBFEN;
  351. }
  352. __STATIC_INLINE void nrf_qdec_pio_assign( uint32_t psela, uint32_t pselb, uint32_t pselled)
  353. {
  354. #if defined(QDEC_PSEL_A_CONNECT_Pos)
  355. NRF_QDEC->PSEL.A = psela;
  356. #else
  357. NRF_QDEC->PSELA = psela;
  358. #endif
  359. #if defined(QDEC_PSEL_B_CONNECT_Pos)
  360. NRF_QDEC->PSEL.B = pselb;
  361. #else
  362. NRF_QDEC->PSELB = pselb;
  363. #endif
  364. #if defined(QDEC_PSEL_LED_CONNECT_Pos)
  365. NRF_QDEC->PSEL.LED = pselled;
  366. #else
  367. NRF_QDEC->PSELLED = pselled;
  368. #endif
  369. }
  370. __STATIC_INLINE void nrf_qdec_task_trigger(nrf_qdec_task_t qdec_task)
  371. {
  372. *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task) ) = 1;
  373. }
  374. __STATIC_INLINE uint32_t * nrf_qdec_task_address_get(nrf_qdec_task_t qdec_task)
  375. {
  376. return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_task);
  377. }
  378. __STATIC_INLINE void nrf_qdec_event_clear(nrf_qdec_event_t qdec_event)
  379. {
  380. *( (volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event) ) = 0;
  381. #if __CORTEX_M == 0x04
  382. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_QDEC + qdec_event));
  383. (void)dummy;
  384. #endif
  385. }
  386. __STATIC_INLINE uint32_t nrf_qdec_event_check(nrf_qdec_event_t qdec_event)
  387. {
  388. return *(volatile uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event);
  389. }
  390. __STATIC_INLINE uint32_t * nrf_qdec_event_address_get(nrf_qdec_event_t qdec_event)
  391. {
  392. return (uint32_t *)( (uint8_t *)NRF_QDEC + qdec_event);
  393. }
  394. __STATIC_INLINE void nrf_qdec_shorts_enable(uint32_t qdec_short_mask)
  395. {
  396. NRF_QDEC->SHORTS |= qdec_short_mask;
  397. }
  398. __STATIC_INLINE void nrf_qdec_shorts_disable(uint32_t qdec_short_mask)
  399. {
  400. NRF_QDEC->SHORTS &= ~qdec_short_mask;
  401. }
  402. __STATIC_INLINE int32_t nrf_qdec_sampleper_reg_get(void)
  403. {
  404. return NRF_QDEC->SAMPLEPER;
  405. }
  406. __STATIC_INLINE uint32_t nrf_qdec_sampleper_to_value(uint32_t sampleper)
  407. {
  408. return (1 << (7 + sampleper));
  409. }
  410. __STATIC_INLINE void nrf_qdec_sampleper_set(nrf_qdec_sampleper_t sample_per)
  411. {
  412. NRF_QDEC->SAMPLEPER = sample_per;
  413. }
  414. __STATIC_INLINE int32_t nrf_qdec_sample_get(void)
  415. {
  416. return NRF_QDEC->SAMPLE;
  417. }
  418. __STATIC_INLINE int32_t nrf_qdec_acc_get(void)
  419. {
  420. return NRF_QDEC->ACC;
  421. }
  422. __STATIC_INLINE int32_t nrf_qdec_accread_get(void)
  423. {
  424. return NRF_QDEC->ACCREAD;
  425. }
  426. __STATIC_INLINE uint32_t nrf_qdec_accdbl_get(void)
  427. {
  428. return NRF_QDEC->ACCDBL;
  429. }
  430. __STATIC_INLINE uint32_t nrf_qdec_accdblread_get(void)
  431. {
  432. return NRF_QDEC->ACCDBLREAD;
  433. }
  434. __STATIC_INLINE void nrf_qdec_ledpre_set(uint32_t time_us)
  435. {
  436. NRF_QDEC->LEDPRE = time_us;
  437. }
  438. __STATIC_INLINE uint32_t nrf_qdec_ledpre_get(void)
  439. {
  440. return NRF_QDEC->LEDPRE;
  441. }
  442. __STATIC_INLINE void nrf_qdec_reportper_set(nrf_qdec_reportper_t reportper)
  443. {
  444. NRF_QDEC->REPORTPER = reportper;
  445. }
  446. __STATIC_INLINE uint32_t nrf_qdec_reportper_reg_get(void)
  447. {
  448. return NRF_QDEC->REPORTPER;
  449. }
  450. __STATIC_INLINE uint32_t nrf_qdec_reportper_to_value(uint32_t reportper)
  451. {
  452. return (reportper == NRF_QDEC_REPORTPER_10) ? 10 : reportper * 40;
  453. }
  454. __STATIC_INLINE void nrf_qdec_ledpol_set(nrf_qdec_ledpol_t pol)
  455. {
  456. NRF_QDEC->LEDPOL = pol;
  457. }
  458. __STATIC_INLINE uint32_t nrf_qdec_ledpol_get(void)
  459. {
  460. return NRF_QDEC->LEDPOL;
  461. }
  462. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  463. /** @} */
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif // NRF_QDEC_H__