nrf_qdec.h 17 KB

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