nrf_saadc.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. /**
  2. * Copyright (c) 2015 - 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_SAADC_H_
  41. #define NRF_SAADC_H_
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_saadc_hal SAADC HAL
  48. * @{
  49. * @ingroup nrf_saadc
  50. * @brief Hardware access layer for managing the SAADC peripheral.
  51. */
  52. /** @brief Number of available SAADC channels. */
  53. #define NRF_SAADC_CHANNEL_COUNT 8
  54. /** @brief Resolution of the analog-to-digital converter. */
  55. typedef enum
  56. {
  57. NRF_SAADC_RESOLUTION_8BIT = SAADC_RESOLUTION_VAL_8bit, ///< 8 bit resolution.
  58. NRF_SAADC_RESOLUTION_10BIT = SAADC_RESOLUTION_VAL_10bit, ///< 10 bit resolution.
  59. NRF_SAADC_RESOLUTION_12BIT = SAADC_RESOLUTION_VAL_12bit, ///< 12 bit resolution.
  60. NRF_SAADC_RESOLUTION_14BIT = SAADC_RESOLUTION_VAL_14bit ///< 14 bit resolution.
  61. } nrf_saadc_resolution_t;
  62. /** @brief Input selection for the analog-to-digital converter. */
  63. typedef enum
  64. {
  65. NRF_SAADC_INPUT_DISABLED = SAADC_CH_PSELP_PSELP_NC, ///< Not connected.
  66. NRF_SAADC_INPUT_AIN0 = SAADC_CH_PSELP_PSELP_AnalogInput0, ///< Analog input 0 (AIN0).
  67. NRF_SAADC_INPUT_AIN1 = SAADC_CH_PSELP_PSELP_AnalogInput1, ///< Analog input 1 (AIN1).
  68. NRF_SAADC_INPUT_AIN2 = SAADC_CH_PSELP_PSELP_AnalogInput2, ///< Analog input 2 (AIN2).
  69. NRF_SAADC_INPUT_AIN3 = SAADC_CH_PSELP_PSELP_AnalogInput3, ///< Analog input 3 (AIN3).
  70. NRF_SAADC_INPUT_AIN4 = SAADC_CH_PSELP_PSELP_AnalogInput4, ///< Analog input 4 (AIN4).
  71. NRF_SAADC_INPUT_AIN5 = SAADC_CH_PSELP_PSELP_AnalogInput5, ///< Analog input 5 (AIN5).
  72. NRF_SAADC_INPUT_AIN6 = SAADC_CH_PSELP_PSELP_AnalogInput6, ///< Analog input 6 (AIN6).
  73. NRF_SAADC_INPUT_AIN7 = SAADC_CH_PSELP_PSELP_AnalogInput7, ///< Analog input 7 (AIN7).
  74. NRF_SAADC_INPUT_VDD = SAADC_CH_PSELP_PSELP_VDD, ///< VDD as input.
  75. #if defined(SAADC_CH_PSELP_PSELP_VDDHDIV5) || defined(__NRFX_DOXYGEN__)
  76. NRF_SAADC_INPUT_VDDHDIV5 = SAADC_CH_PSELP_PSELP_VDDHDIV5 ///< VDDH/5 as input.
  77. #endif
  78. } nrf_saadc_input_t;
  79. /** @brief Analog-to-digital converter oversampling mode. */
  80. typedef enum
  81. {
  82. NRF_SAADC_OVERSAMPLE_DISABLED = SAADC_OVERSAMPLE_OVERSAMPLE_Bypass, ///< No oversampling.
  83. NRF_SAADC_OVERSAMPLE_2X = SAADC_OVERSAMPLE_OVERSAMPLE_Over2x, ///< Oversample 2x.
  84. NRF_SAADC_OVERSAMPLE_4X = SAADC_OVERSAMPLE_OVERSAMPLE_Over4x, ///< Oversample 4x.
  85. NRF_SAADC_OVERSAMPLE_8X = SAADC_OVERSAMPLE_OVERSAMPLE_Over8x, ///< Oversample 8x.
  86. NRF_SAADC_OVERSAMPLE_16X = SAADC_OVERSAMPLE_OVERSAMPLE_Over16x, ///< Oversample 16x.
  87. NRF_SAADC_OVERSAMPLE_32X = SAADC_OVERSAMPLE_OVERSAMPLE_Over32x, ///< Oversample 32x.
  88. NRF_SAADC_OVERSAMPLE_64X = SAADC_OVERSAMPLE_OVERSAMPLE_Over64x, ///< Oversample 64x.
  89. NRF_SAADC_OVERSAMPLE_128X = SAADC_OVERSAMPLE_OVERSAMPLE_Over128x, ///< Oversample 128x.
  90. NRF_SAADC_OVERSAMPLE_256X = SAADC_OVERSAMPLE_OVERSAMPLE_Over256x ///< Oversample 256x.
  91. } nrf_saadc_oversample_t;
  92. /** @brief Analog-to-digital converter channel resistor control. */
  93. typedef enum
  94. {
  95. NRF_SAADC_RESISTOR_DISABLED = SAADC_CH_CONFIG_RESP_Bypass, ///< Bypass resistor ladder.
  96. NRF_SAADC_RESISTOR_PULLDOWN = SAADC_CH_CONFIG_RESP_Pulldown, ///< Pull-down to GND.
  97. NRF_SAADC_RESISTOR_PULLUP = SAADC_CH_CONFIG_RESP_Pullup, ///< Pull-up to VDD.
  98. NRF_SAADC_RESISTOR_VDD1_2 = SAADC_CH_CONFIG_RESP_VDD1_2 ///< Set input at VDD/2.
  99. } nrf_saadc_resistor_t;
  100. /** @brief Gain factor of the analog-to-digital converter input. */
  101. typedef enum
  102. {
  103. NRF_SAADC_GAIN1_6 = SAADC_CH_CONFIG_GAIN_Gain1_6, ///< Gain factor 1/6.
  104. NRF_SAADC_GAIN1_5 = SAADC_CH_CONFIG_GAIN_Gain1_5, ///< Gain factor 1/5.
  105. NRF_SAADC_GAIN1_4 = SAADC_CH_CONFIG_GAIN_Gain1_4, ///< Gain factor 1/4.
  106. NRF_SAADC_GAIN1_3 = SAADC_CH_CONFIG_GAIN_Gain1_3, ///< Gain factor 1/3.
  107. NRF_SAADC_GAIN1_2 = SAADC_CH_CONFIG_GAIN_Gain1_2, ///< Gain factor 1/2.
  108. NRF_SAADC_GAIN1 = SAADC_CH_CONFIG_GAIN_Gain1, ///< Gain factor 1.
  109. NRF_SAADC_GAIN2 = SAADC_CH_CONFIG_GAIN_Gain2, ///< Gain factor 2.
  110. NRF_SAADC_GAIN4 = SAADC_CH_CONFIG_GAIN_Gain4, ///< Gain factor 4.
  111. } nrf_saadc_gain_t;
  112. /** @brief Reference selection for the analog-to-digital converter. */
  113. typedef enum
  114. {
  115. NRF_SAADC_REFERENCE_INTERNAL = SAADC_CH_CONFIG_REFSEL_Internal, ///< Internal reference (0.6 V).
  116. NRF_SAADC_REFERENCE_VDD4 = SAADC_CH_CONFIG_REFSEL_VDD1_4 ///< VDD/4 as reference.
  117. } nrf_saadc_reference_t;
  118. /** @brief Analog-to-digital converter acquisition time. */
  119. typedef enum
  120. {
  121. NRF_SAADC_ACQTIME_3US = SAADC_CH_CONFIG_TACQ_3us, ///< 3 us.
  122. NRF_SAADC_ACQTIME_5US = SAADC_CH_CONFIG_TACQ_5us, ///< 5 us.
  123. NRF_SAADC_ACQTIME_10US = SAADC_CH_CONFIG_TACQ_10us, ///< 10 us.
  124. NRF_SAADC_ACQTIME_15US = SAADC_CH_CONFIG_TACQ_15us, ///< 15 us.
  125. NRF_SAADC_ACQTIME_20US = SAADC_CH_CONFIG_TACQ_20us, ///< 20 us.
  126. NRF_SAADC_ACQTIME_40US = SAADC_CH_CONFIG_TACQ_40us ///< 40 us.
  127. } nrf_saadc_acqtime_t;
  128. /** @brief Analog-to-digital converter channel mode. */
  129. typedef enum
  130. {
  131. NRF_SAADC_MODE_SINGLE_ENDED = SAADC_CH_CONFIG_MODE_SE, ///< Single-ended mode. PSELN will be ignored, negative input to ADC shorted to GND.
  132. NRF_SAADC_MODE_DIFFERENTIAL = SAADC_CH_CONFIG_MODE_Diff ///< Differential mode.
  133. } nrf_saadc_mode_t;
  134. /** @brief Analog-to-digital converter channel burst mode. */
  135. typedef enum
  136. {
  137. NRF_SAADC_BURST_DISABLED = SAADC_CH_CONFIG_BURST_Disabled, ///< Burst mode is disabled (normal operation).
  138. NRF_SAADC_BURST_ENABLED = SAADC_CH_CONFIG_BURST_Enabled ///< Burst mode is enabled. SAADC takes 2^OVERSAMPLE number of samples as fast as it can, and sends the average to Data RAM.
  139. } nrf_saadc_burst_t;
  140. /** @brief Analog-to-digital converter tasks. */
  141. typedef enum
  142. {
  143. NRF_SAADC_TASK_START = offsetof(NRF_SAADC_Type, TASKS_START), ///< Start the ADC and prepare the result buffer in RAM.
  144. NRF_SAADC_TASK_SAMPLE = offsetof(NRF_SAADC_Type, TASKS_SAMPLE), ///< Take one ADC sample. If scan is enabled, all channels are sampled.
  145. NRF_SAADC_TASK_STOP = offsetof(NRF_SAADC_Type, TASKS_STOP), ///< Stop the ADC and terminate any ongoing conversion.
  146. NRF_SAADC_TASK_CALIBRATEOFFSET = offsetof(NRF_SAADC_Type, TASKS_CALIBRATEOFFSET), ///< Starts offset auto-calibration.
  147. } nrf_saadc_task_t;
  148. /** @brief Analog-to-digital converter events. */
  149. typedef enum
  150. {
  151. NRF_SAADC_EVENT_STARTED = offsetof(NRF_SAADC_Type, EVENTS_STARTED), ///< The ADC has started.
  152. NRF_SAADC_EVENT_END = offsetof(NRF_SAADC_Type, EVENTS_END), ///< The ADC has filled up the result buffer.
  153. NRF_SAADC_EVENT_DONE = offsetof(NRF_SAADC_Type, EVENTS_DONE), ///< A conversion task has been completed.
  154. NRF_SAADC_EVENT_RESULTDONE = offsetof(NRF_SAADC_Type, EVENTS_RESULTDONE), ///< A result is ready to get transferred to RAM.
  155. NRF_SAADC_EVENT_CALIBRATEDONE = offsetof(NRF_SAADC_Type, EVENTS_CALIBRATEDONE), ///< Calibration is complete.
  156. NRF_SAADC_EVENT_STOPPED = offsetof(NRF_SAADC_Type, EVENTS_STOPPED), ///< The ADC has stopped.
  157. NRF_SAADC_EVENT_CH0_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITH), ///< Last result is equal or above CH[0].LIMIT.HIGH.
  158. NRF_SAADC_EVENT_CH0_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[0].LIMITL), ///< Last result is equal or below CH[0].LIMIT.LOW.
  159. NRF_SAADC_EVENT_CH1_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITH), ///< Last result is equal or above CH[1].LIMIT.HIGH.
  160. NRF_SAADC_EVENT_CH1_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[1].LIMITL), ///< Last result is equal or below CH[1].LIMIT.LOW.
  161. NRF_SAADC_EVENT_CH2_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITH), ///< Last result is equal or above CH[2].LIMIT.HIGH.
  162. NRF_SAADC_EVENT_CH2_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[2].LIMITL), ///< Last result is equal or below CH[2].LIMIT.LOW.
  163. NRF_SAADC_EVENT_CH3_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITH), ///< Last result is equal or above CH[3].LIMIT.HIGH.
  164. NRF_SAADC_EVENT_CH3_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[3].LIMITL), ///< Last result is equal or below CH[3].LIMIT.LOW.
  165. NRF_SAADC_EVENT_CH4_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITH), ///< Last result is equal or above CH[4].LIMIT.HIGH.
  166. NRF_SAADC_EVENT_CH4_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[4].LIMITL), ///< Last result is equal or below CH[4].LIMIT.LOW.
  167. NRF_SAADC_EVENT_CH5_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITH), ///< Last result is equal or above CH[5].LIMIT.HIGH.
  168. NRF_SAADC_EVENT_CH5_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[5].LIMITL), ///< Last result is equal or below CH[5].LIMIT.LOW.
  169. NRF_SAADC_EVENT_CH6_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITH), ///< Last result is equal or above CH[6].LIMIT.HIGH.
  170. NRF_SAADC_EVENT_CH6_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[6].LIMITL), ///< Last result is equal or below CH[6].LIMIT.LOW.
  171. NRF_SAADC_EVENT_CH7_LIMITH = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITH), ///< Last result is equal or above CH[7].LIMIT.HIGH.
  172. NRF_SAADC_EVENT_CH7_LIMITL = offsetof(NRF_SAADC_Type, EVENTS_CH[7].LIMITL) ///< Last result is equal or below CH[7].LIMIT.LOW.
  173. } nrf_saadc_event_t;
  174. /** @brief Analog-to-digital converter interrupt masks. */
  175. typedef enum
  176. {
  177. NRF_SAADC_INT_STARTED = SAADC_INTENSET_STARTED_Msk, ///< Interrupt on EVENTS_STARTED event.
  178. NRF_SAADC_INT_END = SAADC_INTENSET_END_Msk, ///< Interrupt on EVENTS_END event.
  179. NRF_SAADC_INT_DONE = SAADC_INTENSET_DONE_Msk, ///< Interrupt on EVENTS_DONE event.
  180. NRF_SAADC_INT_RESULTDONE = SAADC_INTENSET_RESULTDONE_Msk, ///< Interrupt on EVENTS_RESULTDONE event.
  181. NRF_SAADC_INT_CALIBRATEDONE = SAADC_INTENSET_CALIBRATEDONE_Msk, ///< Interrupt on EVENTS_CALIBRATEDONE event.
  182. NRF_SAADC_INT_STOPPED = SAADC_INTENSET_STOPPED_Msk, ///< Interrupt on EVENTS_STOPPED event.
  183. NRF_SAADC_INT_CH0LIMITH = SAADC_INTENSET_CH0LIMITH_Msk, ///< Interrupt on EVENTS_CH[0].LIMITH event.
  184. NRF_SAADC_INT_CH0LIMITL = SAADC_INTENSET_CH0LIMITL_Msk, ///< Interrupt on EVENTS_CH[0].LIMITL event.
  185. NRF_SAADC_INT_CH1LIMITH = SAADC_INTENSET_CH1LIMITH_Msk, ///< Interrupt on EVENTS_CH[1].LIMITH event.
  186. NRF_SAADC_INT_CH1LIMITL = SAADC_INTENSET_CH1LIMITL_Msk, ///< Interrupt on EVENTS_CH[1].LIMITL event.
  187. NRF_SAADC_INT_CH2LIMITH = SAADC_INTENSET_CH2LIMITH_Msk, ///< Interrupt on EVENTS_CH[2].LIMITH event.
  188. NRF_SAADC_INT_CH2LIMITL = SAADC_INTENSET_CH2LIMITL_Msk, ///< Interrupt on EVENTS_CH[2].LIMITL event.
  189. NRF_SAADC_INT_CH3LIMITH = SAADC_INTENSET_CH3LIMITH_Msk, ///< Interrupt on EVENTS_CH[3].LIMITH event.
  190. NRF_SAADC_INT_CH3LIMITL = SAADC_INTENSET_CH3LIMITL_Msk, ///< Interrupt on EVENTS_CH[3].LIMITL event.
  191. NRF_SAADC_INT_CH4LIMITH = SAADC_INTENSET_CH4LIMITH_Msk, ///< Interrupt on EVENTS_CH[4].LIMITH event.
  192. NRF_SAADC_INT_CH4LIMITL = SAADC_INTENSET_CH4LIMITL_Msk, ///< Interrupt on EVENTS_CH[4].LIMITL event.
  193. NRF_SAADC_INT_CH5LIMITH = SAADC_INTENSET_CH5LIMITH_Msk, ///< Interrupt on EVENTS_CH[5].LIMITH event.
  194. NRF_SAADC_INT_CH5LIMITL = SAADC_INTENSET_CH5LIMITL_Msk, ///< Interrupt on EVENTS_CH[5].LIMITL event.
  195. NRF_SAADC_INT_CH6LIMITH = SAADC_INTENSET_CH6LIMITH_Msk, ///< Interrupt on EVENTS_CH[6].LIMITH event.
  196. NRF_SAADC_INT_CH6LIMITL = SAADC_INTENSET_CH6LIMITL_Msk, ///< Interrupt on EVENTS_CH[6].LIMITL event.
  197. NRF_SAADC_INT_CH7LIMITH = SAADC_INTENSET_CH7LIMITH_Msk, ///< Interrupt on EVENTS_CH[7].LIMITH event.
  198. NRF_SAADC_INT_CH7LIMITL = SAADC_INTENSET_CH7LIMITL_Msk, ///< Interrupt on EVENTS_CH[7].LIMITL event.
  199. NRF_SAADC_INT_ALL = 0x7FFFFFFFUL ///< Mask of all interrupts.
  200. } nrf_saadc_int_mask_t;
  201. /** @brief Analog-to-digital converter value limit type. */
  202. typedef enum
  203. {
  204. NRF_SAADC_LIMIT_LOW = 0, ///< Low limit type.
  205. NRF_SAADC_LIMIT_HIGH = 1 ///< High limit type.
  206. } nrf_saadc_limit_t;
  207. /** @brief Type of a single ADC conversion result. */
  208. typedef int16_t nrf_saadc_value_t;
  209. /** @brief Analog-to-digital converter configuration structure. */
  210. typedef struct
  211. {
  212. nrf_saadc_resolution_t resolution; ///< Resolution of samples.
  213. nrf_saadc_oversample_t oversample; ///< Oversampling configuration.
  214. nrf_saadc_value_t * buffer; ///< Pointer to sample buffer.
  215. uint32_t buffer_size; ///< Size of the sample buffer.
  216. } nrf_saadc_config_t;
  217. /** @brief Analog-to-digital converter channel configuration structure. */
  218. typedef struct
  219. {
  220. nrf_saadc_resistor_t resistor_p; ///< Resistor value on positive input.
  221. nrf_saadc_resistor_t resistor_n; ///< Resistor value on negative input.
  222. nrf_saadc_gain_t gain; ///< Gain control value.
  223. nrf_saadc_reference_t reference; ///< Reference control value.
  224. nrf_saadc_acqtime_t acq_time; ///< Acquisition time.
  225. nrf_saadc_mode_t mode; ///< SAADC mode. Single-ended or differential.
  226. nrf_saadc_burst_t burst; ///< Burst mode configuration.
  227. nrf_saadc_input_t pin_p; ///< Input positive pin selection.
  228. nrf_saadc_input_t pin_n; ///< Input negative pin selection.
  229. } nrf_saadc_channel_config_t;
  230. /**
  231. * @brief Function for triggering the specified SAADC task.
  232. *
  233. * @param[in] task SAADC task.
  234. */
  235. __STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t task);
  236. /**
  237. * @brief Function for getting the address of the specified SAADC task register.
  238. *
  239. * @param[in] task SAADC task.
  240. *
  241. * @return Address of the specified SAADC task.
  242. */
  243. __STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t task);
  244. /**
  245. * @brief Function for retrieving the state of the UARTE event.
  246. *
  247. * @param[in] event Event to be checked.
  248. *
  249. * @retval true The event has been generated.
  250. * @retval false The event has not been generated.
  251. */
  252. __STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t event);
  253. /**
  254. * @brief Function for clearing the specific SAADC event.
  255. *
  256. * @param[in] event SAADC event.
  257. */
  258. __STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t event);
  259. /**
  260. * @brief Function for getting the address of the specified SAADC event register.
  261. *
  262. * @param[in] event SAADC event.
  263. *
  264. * @return Address of the specified SAADC event.
  265. */
  266. __STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t event);
  267. #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  268. /**
  269. * @brief Function for setting the subscribe configuration for a given
  270. * SAADC task.
  271. *
  272. * @param[in] task Task for which to set the configuration.
  273. * @param[in] channel Channel through which to subscribe events.
  274. */
  275. __STATIC_INLINE void nrf_saadc_subscribe_set(nrf_saadc_task_t task,
  276. uint8_t channel);
  277. /**
  278. * @brief Function for clearing the subscribe configuration for a given
  279. * SAADC task.
  280. *
  281. * @param[in] task Task for which to clear the configuration.
  282. */
  283. __STATIC_INLINE void nrf_saadc_subscribe_clear(nrf_saadc_task_t task);
  284. /**
  285. * @brief Function for setting the publish configuration for a given
  286. * SAADC event.
  287. *
  288. * @param[in] event Event for which to set the configuration.
  289. * @param[in] channel Channel through which to publish the event.
  290. */
  291. __STATIC_INLINE void nrf_saadc_publish_set(nrf_saadc_event_t event,
  292. uint8_t channel);
  293. /**
  294. * @brief Function for clearing the publish configuration for a given
  295. * SAADC event.
  296. *
  297. * @param[in] event Event for which to clear the configuration.
  298. */
  299. __STATIC_INLINE void nrf_saadc_publish_clear(nrf_saadc_event_t event);
  300. #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  301. /**
  302. * @brief Function for getting the address of the SAADC limit event register,
  303. * as specified by the channel and the limit type.
  304. *
  305. * @param[in] channel Channel number.
  306. * @param[in] limit_type Low limit or high limit.
  307. *
  308. * @return Address of the specified SAADC limit event.
  309. */
  310. __STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel,
  311. nrf_saadc_limit_t limit_type);
  312. /**
  313. * @brief Function for getting the SAADC channel monitoring limit events.
  314. *
  315. * @param[in] channel Channel number.
  316. * @param[in] limit_type Low limit or high limit.
  317. *
  318. * @return The SAADC channel monitoring limit event.
  319. */
  320. __STATIC_INLINE nrf_saadc_event_t nrf_saadc_limit_event_get(uint8_t channel,
  321. nrf_saadc_limit_t limit_type);
  322. /**
  323. * @brief Function for configuring the input pins for the specified SAADC channel.
  324. *
  325. * @param[in] channel Channel number.
  326. * @param[in] pselp Positive input.
  327. * @param[in] pseln Negative input. Set to NRF_SAADC_INPUT_DISABLED in single ended mode.
  328. */
  329. __STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel,
  330. nrf_saadc_input_t pselp,
  331. nrf_saadc_input_t pseln);
  332. /**
  333. * @brief Function for configuring the positive input pin for the specified SAADC channel.
  334. *
  335. * @param[in] channel Channel number.
  336. * @param[in] pselp Positive input.
  337. */
  338. __STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel,
  339. nrf_saadc_input_t pselp);
  340. /**
  341. * @brief Function for setting the SAADC channel monitoring limits.
  342. *
  343. * @param[in] channel Channel number.
  344. * @param[in] low Low limit.
  345. * @param[in] high High limit.
  346. */
  347. __STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high);
  348. /**
  349. * @brief Function for setting the configuration of SAADC interrupts.
  350. *
  351. * @param[in] mask Interrupts configuration to be set.
  352. */
  353. __STATIC_INLINE void nrf_saadc_int_set(uint32_t mask);
  354. /**
  355. * @brief Function for enabling specified SAADC interrupts.
  356. *
  357. * @param[in] saadc_int_mask Interrupt(s) to be enabled.
  358. */
  359. __STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask);
  360. /**
  361. * @brief Function for retrieving the state of specified SAADC interrupts.
  362. *
  363. * @param[in] saadc_int_mask Interrupt(s) to be checked.
  364. *
  365. * @retval true All specified interrupts are enabled.
  366. * @retval false At least one of the given interrupts is not enabled.
  367. */
  368. __STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask);
  369. /**
  370. * @brief Function for disabling specified interrupts.
  371. *
  372. * @param saadc_int_mask Interrupt(s) to be disabled.
  373. */
  374. __STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask);
  375. /**
  376. * @brief Function for generating masks for SAADC channel limit interrupts.
  377. *
  378. * @param[in] channel SAADC channel number.
  379. * @param[in] limit_type Limit type.
  380. *
  381. * @return Interrupt mask.
  382. */
  383. __STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type);
  384. /**
  385. * @brief Function for checking whether the SAADC is busy.
  386. *
  387. * This function checks whether the analog-to-digital converter is busy with a conversion.
  388. *
  389. * @retval true The SAADC is busy.
  390. * @retval false The SAADC is not busy.
  391. */
  392. __STATIC_INLINE bool nrf_saadc_busy_check(void);
  393. /**
  394. * @brief Function for enabling the SAADC.
  395. *
  396. * The analog-to-digital converter must be enabled before use.
  397. */
  398. __STATIC_INLINE void nrf_saadc_enable(void);
  399. /**
  400. * @brief Function for disabling the SAADC.
  401. */
  402. __STATIC_INLINE void nrf_saadc_disable(void);
  403. /**
  404. * @brief Function for checking if the SAADC is enabled.
  405. *
  406. * @retval true The SAADC is enabled.
  407. * @retval false The SAADC is not enabled.
  408. */
  409. __STATIC_INLINE bool nrf_saadc_enable_check(void);
  410. /**
  411. * @brief Function for initializing the SAADC result buffer.
  412. *
  413. * @param[in] p_buffer Pointer to the result buffer.
  414. * @param[in] size Size of the buffer (in 16-bit samples).
  415. */
  416. __STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * p_buffer,
  417. uint32_t size);
  418. /**
  419. * @brief Function for setting the SAADC result buffer pointer.
  420. *
  421. * @param[in] p_buffer Pointer to the result buffer.
  422. */
  423. __STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer);
  424. /**
  425. * @brief Function for getting the SAADC result buffer pointer.
  426. *
  427. * @return Pointer to the result buffer.
  428. */
  429. __STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void);
  430. /**
  431. * @brief Function for getting the number of samples written to the result
  432. * buffer since the previous START task.
  433. *
  434. * @returns Number of 16-bit samples written to the buffer.
  435. */
  436. __STATIC_INLINE uint16_t nrf_saadc_amount_get(void);
  437. /**
  438. * @brief Function for setting the SAADC sample resolution.
  439. *
  440. * @param[in] resolution Bit resolution.
  441. */
  442. __STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution);
  443. /**
  444. * @brief Function for getting the SAADC sample resolution.
  445. *
  446. * @return Sample resolution.
  447. */
  448. __STATIC_INLINE nrf_saadc_resolution_t nrf_saadc_resolution_get(void);
  449. /**
  450. * @brief Function for configuring the oversampling feature.
  451. *
  452. * @param[in] oversample Oversampling mode.
  453. */
  454. __STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample);
  455. /**
  456. * @brief Function for getting the oversampling feature configuration.
  457. *
  458. * @return Oversampling configuration.
  459. */
  460. __STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void);
  461. /**
  462. * @brief Function for getting the sample count needed for one averaged result for a given
  463. * oversampling configuration.
  464. *
  465. * @param[in] oversample Oversampling configuration.
  466. *
  467. * @return Sample count.
  468. */
  469. __STATIC_INLINE uint32_t nrf_saadc_oversample_sample_count_get(nrf_saadc_oversample_t oversample);
  470. /**
  471. * @brief Function for enabling the continuous sampling.
  472. *
  473. * This function configures the SAADC internal timer to automatically take new samples at a fixed
  474. * sample rate. Trigger the START task to begin continuous sampling. To stop the sampling, trigger
  475. * the STOP task.
  476. *
  477. * @note The internal timer can only be used when a single input channel is enabled.
  478. *
  479. * @param[in] cc Capture and compare value. Sample rate is 16 MHz/cc. Valid CC range is
  480. * from 80 to 2047.
  481. */
  482. __STATIC_INLINE void nrf_saadc_continuous_mode_enable(uint16_t cc);
  483. /**
  484. * @brief Function for checking if the continuous sampling is enabled.
  485. *
  486. * @retval true The continuous sampling is enabled.
  487. * @retval false The continuous sampling is disabled.
  488. */
  489. __STATIC_INLINE bool nrf_saadc_continuous_mode_enable_check(void);
  490. /**
  491. * @brief Function for disabling the continuous sampling.
  492. *
  493. * New samples can still be acquired by manually triggering the SAMPLE task or by PPI.
  494. */
  495. __STATIC_INLINE void nrf_saadc_continuous_mode_disable(void);
  496. /**
  497. * @brief Function for initializing the SAADC channel.
  498. *
  499. * @param[in] channel Channel number.
  500. * @param[in] config Pointer to the channel configuration structure.
  501. */
  502. __STATIC_INLINE void nrf_saadc_channel_init(uint8_t channel,
  503. nrf_saadc_channel_config_t const * const config);
  504. /**
  505. * @brief Function for configuring the burst mode for the specified channel.
  506. *
  507. * @param[in] channel Channel number.
  508. * @param[in] burst Burst mode setting.
  509. */
  510. __STATIC_INLINE void nrf_saadc_burst_set(uint8_t channel,
  511. nrf_saadc_burst_t burst);
  512. /**
  513. * @brief Function for getting the minimum value of the conversion result.
  514. *
  515. * The minimum value of the conversion result depends on the configured resolution.
  516. *
  517. * @param[in] resolution Bit resolution.
  518. *
  519. * @return Minimum value of the conversion result.
  520. */
  521. __STATIC_INLINE nrf_saadc_value_t nrf_saadc_value_min_get(nrf_saadc_resolution_t resolution);
  522. /**
  523. * @brief Function for getting the maximum value of the conversion result.
  524. *
  525. * The maximum value of the conversion result depends on the configured resolution.
  526. *
  527. * @param[in] resolution Bit resolution.
  528. *
  529. * @return Maximum value of the conversion result.
  530. */
  531. __STATIC_INLINE nrf_saadc_value_t nrf_saadc_value_max_get(nrf_saadc_resolution_t resolution);
  532. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  533. __STATIC_INLINE void nrf_saadc_task_trigger(nrf_saadc_task_t task)
  534. {
  535. *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)task)) = 0x1UL;
  536. }
  537. __STATIC_INLINE uint32_t nrf_saadc_task_address_get(nrf_saadc_task_t task)
  538. {
  539. return (uint32_t)((uint8_t *)NRF_SAADC + (uint32_t)task);
  540. }
  541. __STATIC_INLINE bool nrf_saadc_event_check(nrf_saadc_event_t event)
  542. {
  543. return (bool)*(volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)event);
  544. }
  545. __STATIC_INLINE void nrf_saadc_event_clear(nrf_saadc_event_t event)
  546. {
  547. *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)event)) = 0x0UL;
  548. #if __CORTEX_M == 0x04
  549. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_SAADC + (uint32_t)event));
  550. (void)dummy;
  551. #endif
  552. }
  553. __STATIC_INLINE uint32_t nrf_saadc_event_address_get(nrf_saadc_event_t event)
  554. {
  555. return (uint32_t )((uint8_t *)NRF_SAADC + (uint32_t)event);
  556. }
  557. #if defined(DPPI_PRESENT)
  558. __STATIC_INLINE void nrf_saadc_subscribe_set(nrf_saadc_task_t task,
  559. uint8_t channel)
  560. {
  561. *((volatile uint32_t *) ((uint8_t *) NRF_SAADC + (uint32_t) task + 0x80uL)) =
  562. ((uint32_t)channel | SAADC_SUBSCRIBE_START_EN_Msk);
  563. }
  564. __STATIC_INLINE void nrf_saadc_subscribe_clear(nrf_saadc_task_t task)
  565. {
  566. *((volatile uint32_t *) ((uint8_t *) NRF_SAADC + (uint32_t) task + 0x80uL)) = 0;
  567. }
  568. __STATIC_INLINE void nrf_saadc_publish_set(nrf_saadc_event_t event,
  569. uint8_t channel)
  570. {
  571. *((volatile uint32_t *) ((uint8_t *) NRF_SAADC + (uint32_t) event + 0x80uL)) =
  572. ((uint32_t)channel | SAADC_PUBLISH_STARTED_EN_Msk);
  573. }
  574. __STATIC_INLINE void nrf_saadc_publish_clear(nrf_saadc_event_t event)
  575. {
  576. *((volatile uint32_t *) ((uint8_t *) NRF_SAADC + (uint32_t) event + 0x80uL)) = 0;
  577. }
  578. #endif // defined(DPPI_PRESENT)
  579. __STATIC_INLINE volatile uint32_t * nrf_saadc_event_limit_address_get(uint8_t channel,
  580. nrf_saadc_limit_t limit_type)
  581. {
  582. NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT);
  583. if (limit_type == NRF_SAADC_LIMIT_HIGH)
  584. {
  585. return &NRF_SAADC->EVENTS_CH[channel].LIMITH;
  586. }
  587. else
  588. {
  589. return &NRF_SAADC->EVENTS_CH[channel].LIMITL;
  590. }
  591. }
  592. __STATIC_INLINE nrf_saadc_event_t nrf_saadc_limit_event_get(uint8_t channel,
  593. nrf_saadc_limit_t limit_type)
  594. {
  595. if (limit_type == NRF_SAADC_LIMIT_HIGH)
  596. {
  597. return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITH +
  598. (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITH - NRF_SAADC_EVENT_CH0_LIMITH)
  599. * (uint32_t) channel );
  600. }
  601. else
  602. {
  603. return (nrf_saadc_event_t)( (uint32_t) NRF_SAADC_EVENT_CH0_LIMITL +
  604. (uint32_t) (NRF_SAADC_EVENT_CH1_LIMITL - NRF_SAADC_EVENT_CH0_LIMITL)
  605. * (uint32_t) channel );
  606. }
  607. }
  608. __STATIC_INLINE void nrf_saadc_channel_input_set(uint8_t channel,
  609. nrf_saadc_input_t pselp,
  610. nrf_saadc_input_t pseln)
  611. {
  612. NRF_SAADC->CH[channel].PSELN = pseln;
  613. NRF_SAADC->CH[channel].PSELP = pselp;
  614. }
  615. __STATIC_INLINE void nrf_saadc_channel_pos_input_set(uint8_t channel,
  616. nrf_saadc_input_t pselp)
  617. {
  618. NRF_SAADC->CH[channel].PSELP = pselp;
  619. }
  620. __STATIC_INLINE void nrf_saadc_channel_limits_set(uint8_t channel, int16_t low, int16_t high)
  621. {
  622. NRF_SAADC->CH[channel].LIMIT = (
  623. (((uint32_t) low << SAADC_CH_LIMIT_LOW_Pos) & SAADC_CH_LIMIT_LOW_Msk)
  624. | (((uint32_t) high << SAADC_CH_LIMIT_HIGH_Pos) & SAADC_CH_LIMIT_HIGH_Msk));
  625. }
  626. __STATIC_INLINE void nrf_saadc_int_set(uint32_t mask)
  627. {
  628. NRF_SAADC->INTEN = mask;
  629. }
  630. __STATIC_INLINE void nrf_saadc_int_enable(uint32_t saadc_int_mask)
  631. {
  632. NRF_SAADC->INTENSET = saadc_int_mask;
  633. }
  634. __STATIC_INLINE bool nrf_saadc_int_enable_check(uint32_t saadc_int_mask)
  635. {
  636. return (bool)(NRF_SAADC->INTENSET & saadc_int_mask);
  637. }
  638. __STATIC_INLINE void nrf_saadc_int_disable(uint32_t saadc_int_mask)
  639. {
  640. NRF_SAADC->INTENCLR = saadc_int_mask;
  641. }
  642. __STATIC_INLINE uint32_t nrf_saadc_limit_int_get(uint8_t channel, nrf_saadc_limit_t limit_type)
  643. {
  644. NRFX_ASSERT(channel < NRF_SAADC_CHANNEL_COUNT);
  645. uint32_t mask = (limit_type == NRF_SAADC_LIMIT_LOW) ?
  646. NRF_SAADC_INT_CH0LIMITL : NRF_SAADC_INT_CH0LIMITH;
  647. return mask << (channel * 2);
  648. }
  649. __STATIC_INLINE bool nrf_saadc_busy_check(void)
  650. {
  651. //return ((NRF_SAADC->STATUS & SAADC_STATUS_STATUS_Msk) == SAADC_STATUS_STATUS_Msk);
  652. //simplified for performance
  653. return NRF_SAADC->STATUS;
  654. }
  655. __STATIC_INLINE void nrf_saadc_enable(void)
  656. {
  657. NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Enabled << SAADC_ENABLE_ENABLE_Pos);
  658. }
  659. __STATIC_INLINE void nrf_saadc_disable(void)
  660. {
  661. NRF_SAADC->ENABLE = (SAADC_ENABLE_ENABLE_Disabled << SAADC_ENABLE_ENABLE_Pos);
  662. }
  663. __STATIC_INLINE bool nrf_saadc_enable_check(void)
  664. {
  665. //simplified for performance
  666. return NRF_SAADC->ENABLE;
  667. }
  668. __STATIC_INLINE void nrf_saadc_buffer_init(nrf_saadc_value_t * p_buffer,
  669. uint32_t size)
  670. {
  671. NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer;
  672. NRF_SAADC->RESULT.MAXCNT = size;
  673. }
  674. __STATIC_INLINE void nrf_saadc_buffer_pointer_set(nrf_saadc_value_t * p_buffer)
  675. {
  676. NRF_SAADC->RESULT.PTR = (uint32_t)p_buffer;
  677. }
  678. __STATIC_INLINE nrf_saadc_value_t * nrf_saadc_buffer_pointer_get(void)
  679. {
  680. return (nrf_saadc_value_t *)NRF_SAADC->RESULT.PTR;
  681. }
  682. __STATIC_INLINE uint16_t nrf_saadc_amount_get(void)
  683. {
  684. return NRF_SAADC->RESULT.AMOUNT;
  685. }
  686. __STATIC_INLINE void nrf_saadc_resolution_set(nrf_saadc_resolution_t resolution)
  687. {
  688. NRF_SAADC->RESOLUTION = resolution;
  689. }
  690. __STATIC_INLINE nrf_saadc_resolution_t nrf_saadc_resolution_get(void)
  691. {
  692. return (nrf_saadc_resolution_t)NRF_SAADC->RESOLUTION;
  693. }
  694. __STATIC_INLINE uint32_t nrf_saadc_oversample_sample_count_get(nrf_saadc_oversample_t oversample)
  695. {
  696. return (1 << (uint32_t)oversample);
  697. }
  698. __STATIC_INLINE void nrf_saadc_oversample_set(nrf_saadc_oversample_t oversample)
  699. {
  700. NRF_SAADC->OVERSAMPLE = oversample;
  701. }
  702. __STATIC_INLINE nrf_saadc_oversample_t nrf_saadc_oversample_get(void)
  703. {
  704. return (nrf_saadc_oversample_t)NRF_SAADC->OVERSAMPLE;
  705. }
  706. __STATIC_INLINE void nrf_saadc_continuous_mode_enable(uint16_t cc)
  707. {
  708. NRFX_ASSERT((cc >= 80) && (cc <= 2047));
  709. NRF_SAADC->SAMPLERATE = (SAADC_SAMPLERATE_MODE_Timers << SAADC_SAMPLERATE_MODE_Pos)
  710. | ((uint32_t)cc << SAADC_SAMPLERATE_CC_Pos);
  711. }
  712. __STATIC_INLINE bool nrf_saadc_continuous_mode_enable_check(void)
  713. {
  714. return (bool)((NRF_SAADC->SAMPLERATE & SAADC_SAMPLERATE_MODE_Msk)
  715. == (SAADC_SAMPLERATE_MODE_Timers << SAADC_SAMPLERATE_MODE_Pos));
  716. }
  717. __STATIC_INLINE void nrf_saadc_continuous_mode_disable(void)
  718. {
  719. NRF_SAADC->SAMPLERATE = SAADC_SAMPLERATE_MODE_Task << SAADC_SAMPLERATE_MODE_Pos;
  720. }
  721. __STATIC_INLINE void nrf_saadc_channel_init(uint8_t channel,
  722. nrf_saadc_channel_config_t const * const config)
  723. {
  724. NRF_SAADC->CH[channel].CONFIG =
  725. ((config->resistor_p << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk)
  726. | ((config->resistor_n << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk)
  727. | ((config->gain << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk)
  728. | ((config->reference << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
  729. | ((config->acq_time << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk)
  730. | ((config->mode << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk)
  731. | ((config->burst << SAADC_CH_CONFIG_BURST_Pos) & SAADC_CH_CONFIG_BURST_Msk);
  732. nrf_saadc_channel_input_set(channel, config->pin_p, config->pin_n);
  733. }
  734. __STATIC_INLINE void nrf_saadc_burst_set(uint8_t channel,
  735. nrf_saadc_burst_t burst)
  736. {
  737. NRF_SAADC->CH[channel].CONFIG =
  738. (NRF_SAADC->CH[channel].CONFIG & ~SAADC_CH_CONFIG_BURST_Msk) |
  739. (burst << SAADC_CH_CONFIG_BURST_Pos);
  740. }
  741. __STATIC_INLINE nrf_saadc_value_t nrf_saadc_value_min_get(nrf_saadc_resolution_t resolution)
  742. {
  743. uint8_t res_bits = 0;
  744. switch (resolution)
  745. {
  746. case NRF_SAADC_RESOLUTION_8BIT:
  747. res_bits = 8;
  748. break;
  749. case NRF_SAADC_RESOLUTION_10BIT:
  750. res_bits = 10;
  751. break;
  752. case NRF_SAADC_RESOLUTION_12BIT:
  753. res_bits = 12;
  754. break;
  755. case NRF_SAADC_RESOLUTION_14BIT:
  756. res_bits = 14;
  757. break;
  758. default:
  759. NRFX_ASSERT(false);
  760. }
  761. return (nrf_saadc_value_t)(-(1 << res_bits));
  762. }
  763. __STATIC_INLINE nrf_saadc_value_t nrf_saadc_value_max_get(nrf_saadc_resolution_t resolution)
  764. {
  765. uint8_t res_bits = 0;
  766. switch (resolution)
  767. {
  768. case NRF_SAADC_RESOLUTION_8BIT:
  769. res_bits = 8;
  770. break;
  771. case NRF_SAADC_RESOLUTION_10BIT:
  772. res_bits = 10;
  773. break;
  774. case NRF_SAADC_RESOLUTION_12BIT:
  775. res_bits = 12;
  776. break;
  777. case NRF_SAADC_RESOLUTION_14BIT:
  778. res_bits = 14;
  779. break;
  780. default:
  781. NRFX_ASSERT(false);
  782. }
  783. return (nrf_saadc_value_t)((1 << res_bits) - 1);
  784. }
  785. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  786. /** @} */
  787. #ifdef __cplusplus
  788. }
  789. #endif
  790. #endif // NRF_SAADC_H_