hpm_adc16_drv.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /*
  2. * Copyright (c) 2021-2024 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_ADC16_DRV_H
  8. #define HPM_ADC16_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_adc16_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /**
  13. * @brief ADC16 driver APIs
  14. * @defgroup adc16_interface ADC16 driver APIs
  15. * @ingroup adc_interfaces
  16. * @{
  17. */
  18. /** @brief Define ADC16 validity check for the channel number */
  19. #if defined (ADC16_SOC_TEMP_CH_EN) && ADC16_SOC_TEMP_CH_EN
  20. #define ADC16_IS_CHANNEL_INVALID(CH) (CH > ADC16_SOC_MAX_CH_NUM && CH != ADC16_SOC_TEMP_CH_NUM)
  21. #else
  22. #define ADC16_IS_CHANNEL_INVALID(CH) (CH > ADC16_SOC_MAX_CH_NUM)
  23. #endif
  24. /** @brief Define ADC16 validity check for the channel sample cycle */
  25. #define ADC16_IS_CHANNEL_SAMPLE_CYCLE_INVALID(CYC) (CYC == 0)
  26. /** @brief Define ADC16 validity check for the trigger number */
  27. #define ADC16_IS_TRIG_CH_INVLAID(CH) (CH > ADC_SOC_MAX_TRIG_CH_NUM)
  28. /** @brief Define ADC16 validity check for the trigger length */
  29. #define ADC16_IS_TRIG_LEN_INVLAID(TRIG_LEN) (TRIG_LEN > ADC_SOC_MAX_TRIG_CH_LEN)
  30. /** @brief Define ADC16 validity check for the sequence length */
  31. #define ADC16_IS_SEQ_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_SEQ_MAX_LEN))
  32. /** @brief Define ADC16 validity check for the DMA buffer length in the sequence mode */
  33. #define ADC16_IS_SEQ_DMA_BUFF_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_SEQ_MAX_DMA_BUFF_LEN_IN_4BYTES))
  34. /** @brief Define ADC16 validity check for the DMA buffer length in the preemption mode */
  35. #define ADC16_IS_PMT_DMA_BUFF_LEN_INVLAID(LEN) ((LEN == 0) || (LEN > ADC_SOC_PMT_MAX_DMA_BUFF_LEN_IN_4BYTES))
  36. /** @brief Define ADC16 resolutions. */
  37. typedef enum {
  38. adc16_res_8_bits = 9,
  39. adc16_res_10_bits = 11,
  40. adc16_res_12_bits = 14,
  41. adc16_res_16_bits = 21
  42. } adc16_resolution_t;
  43. /** @brief Define ADC16 conversion modes. */
  44. typedef enum {
  45. adc16_conv_mode_oneshot = 0,
  46. adc16_conv_mode_period,
  47. adc16_conv_mode_sequence,
  48. adc16_conv_mode_preemption
  49. } adc16_conversion_mode_t;
  50. /** @brief Define ADC16 Clock Divider */
  51. typedef enum {
  52. adc16_clock_divider_1 = 1,
  53. adc16_clock_divider_2,
  54. adc16_clock_divider_3,
  55. adc16_clock_divider_4,
  56. adc16_clock_divider_5,
  57. adc16_clock_divider_6,
  58. adc16_clock_divider_7,
  59. adc16_clock_divider_8,
  60. adc16_clock_divider_9,
  61. adc16_clock_divider_10,
  62. adc16_clock_divider_11,
  63. adc16_clock_divider_12,
  64. adc16_clock_divider_13,
  65. adc16_clock_divider_14,
  66. adc16_clock_divider_15,
  67. adc16_clock_divider_16,
  68. } adc16_clock_divider_t;
  69. /** @brief Define ADC16 irq events. */
  70. typedef enum {
  71. /** This mask indicates that a trigger conversion is complete. */
  72. adc16_event_trig_complete = ADC16_INT_STS_TRIG_CMPT_MASK,
  73. /** This mask indicates that a conflict caused by software-triggered conversions. */
  74. adc16_event_trig_sw_conflict = ADC16_INT_STS_TRIG_SW_CFLCT_MASK,
  75. /** This mask indicates that a conflict caused by hardware-triggered conversions. */
  76. adc16_event_trig_hw_conflict = ADC16_INT_STS_TRIG_HW_CFLCT_MASK,
  77. /** This mask indicates that a conflict caused when bus reading from different channels. */
  78. adc16_event_read_conflict = ADC16_INT_STS_READ_CFLCT_MASK,
  79. /** This mask indicates that a conflict caused by sequence-triggered conversions. */
  80. adc16_event_seq_sw_conflict = ADC16_INT_STS_SEQ_SW_CFLCT_MASK,
  81. /** This mask indicates that a conflict caused by hardware-triggered conversions. */
  82. adc16_event_seq_hw_conflict = ADC16_INT_STS_SEQ_HW_CFLCT_MASK,
  83. /** This mask indicates that DMA is stopped currently. */
  84. adc16_event_seq_dma_abort = ADC16_INT_STS_SEQ_DMAABT_MASK,
  85. /** This mask indicates that all of the configured conversion(s) in a queue is(are) complete. */
  86. adc16_event_seq_full_complete = ADC16_INT_STS_SEQ_CMPT_MASK,
  87. /** This mask indicates that one of the configured conversion(s) in a queue is complete. */
  88. adc16_event_seq_single_complete = ADC16_INT_STS_SEQ_CVC_MASK,
  89. /** This mask indicates that DMA FIFO is full currently. */
  90. adc16_event_dma_fifo_full = ADC16_INT_STS_DMA_FIFO_FULL_MASK
  91. } adc16_irq_event_t;
  92. /** @brief ADC16 common configuration struct. */
  93. typedef struct {
  94. uint8_t res;
  95. uint8_t conv_mode;
  96. uint32_t adc_clk_div;
  97. bool port3_realtime;
  98. bool wait_dis;
  99. bool sel_sync_ahb;
  100. bool adc_ahb_en;
  101. } adc16_config_t;
  102. /** @brief ADC16 channel configuration struct. */
  103. typedef struct {
  104. uint8_t ch;
  105. uint16_t thshdh;
  106. uint16_t thshdl;
  107. bool wdog_int_en;
  108. uint8_t sample_cycle_shift;
  109. uint32_t sample_cycle;
  110. } adc16_channel_config_t;
  111. /** @brief ADC16 channel configuration struct. */
  112. typedef struct {
  113. uint8_t ch;
  114. uint16_t thshdh;
  115. uint16_t thshdl;
  116. } adc16_channel_threshold_t;
  117. /** @brief ADC16 DMA configuration struct. */
  118. typedef struct {
  119. uint32_t *start_addr;
  120. uint32_t buff_len_in_4bytes;
  121. uint32_t stop_pos;
  122. bool stop_en;
  123. } adc16_dma_config_t;
  124. /** @brief ADC16 DMA configuration struct for the sequence mode. */
  125. #if defined(ADC_SOC_IP_VERSION) && (ADC_SOC_IP_VERSION < 2)
  126. typedef struct {
  127. uint32_t result :16;
  128. uint32_t seq_num :4;
  129. uint32_t :4;
  130. uint32_t adc_ch :5;
  131. uint32_t :2;
  132. uint32_t cycle_bit :1;
  133. } adc16_seq_dma_data_t;
  134. #else
  135. typedef struct {
  136. uint32_t result :16;
  137. uint32_t seq_num :4;
  138. uint32_t adc_ch :5;
  139. uint32_t :6;
  140. uint32_t cycle_bit :1;
  141. } adc16_seq_dma_data_t;
  142. #endif
  143. /** @brief ADC16 DMA configuration struct for the preemption mode. */
  144. #if defined(ADC_SOC_IP_VERSION) && (ADC_SOC_IP_VERSION < 2)
  145. typedef struct {
  146. uint32_t result :16;
  147. uint32_t seq_num :2;
  148. uint32_t :2;
  149. uint32_t trig_ch :4;
  150. uint32_t adc_ch :5;
  151. uint32_t :2;
  152. uint32_t cycle_bit :1;
  153. } adc16_pmt_dma_data_t;
  154. #else
  155. typedef struct {
  156. uint32_t result :16;
  157. uint32_t :4;
  158. uint32_t adc_ch :5;
  159. uint32_t trig_ch :4;
  160. uint32_t seq_num :2;
  161. uint32_t cycle_bit :1;
  162. } adc16_pmt_dma_data_t;
  163. #endif
  164. /** @brief ADC16 configuration struct for the period mode. */
  165. typedef struct {
  166. uint8_t ch;
  167. uint8_t prescale;
  168. uint8_t period_count;
  169. } adc16_prd_config_t;
  170. /** @brief ADC16 queue configuration struct for the sequence mode. */
  171. typedef struct {
  172. bool seq_int_en;
  173. uint8_t ch;
  174. } adc16_seq_queue_config_t;
  175. /** @brief ADC16 configuration struct for the sequence mode. */
  176. typedef struct {
  177. adc16_seq_queue_config_t queue[ADC_SOC_SEQ_MAX_LEN];
  178. bool restart_en;
  179. bool cont_en;
  180. bool sw_trig_en;
  181. bool hw_trig_en;
  182. uint8_t seq_len;
  183. } adc16_seq_config_t;
  184. /** @brief ADC16 trigger configuration struct for the preemption mode. */
  185. typedef struct {
  186. bool inten[ADC_SOC_MAX_TRIG_CH_LEN];
  187. uint8_t adc_ch[ADC_SOC_MAX_TRIG_CH_LEN];
  188. uint8_t trig_ch;
  189. uint8_t trig_len;
  190. } adc16_pmt_config_t;
  191. #ifdef __cplusplus
  192. extern "C" {
  193. #endif
  194. /**
  195. * @name Initialization and Deinitialization
  196. * @{
  197. */
  198. /**
  199. * @brief Get a default configuration for an ADC16 instance.
  200. *
  201. * @param[out] config A pointer to the configuration struct of @ref adc16_config_t.
  202. *
  203. */
  204. void adc16_get_default_config(adc16_config_t *config);
  205. /**
  206. * @brief Get a default configuration for an ADC16 Channel.
  207. *
  208. * @param[out] config A pointer to the configuration struct of @ref adc16_channel_config_t.
  209. */
  210. void adc16_get_channel_default_config(adc16_channel_config_t *config);
  211. /**
  212. * @brief De-initialize an ADC16 instance.
  213. *
  214. * @param[in] ptr An ADC16 peripheral base address.
  215. * @return A result of de-initializing an ADC16 instance.
  216. * @retval status_success De-initialize an ADC16 instance successfully. Please refer to @ref hpm_stat_t.
  217. * @retval status_invalid_argument De-initialize an ADC16 instance unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  218. */
  219. hpm_stat_t adc16_deinit(ADC16_Type *ptr);
  220. /**
  221. * @brief Initialize an ADC16 instance.
  222. *
  223. * @param[in] ptr An ADC16 peripheral base address.
  224. * @param[in] config A pointer to the configuration struct of @ref adc16_config_t.
  225. * @return A result of initializing an ADC16 instance.
  226. * @retval status_success Initialize an ADC16 instance successfully. Please refer to @ref hpm_stat_t.
  227. * @retval status_invalid_argument Initialize an ADC16 instance unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  228. */
  229. hpm_stat_t adc16_init(ADC16_Type *ptr, adc16_config_t *config);
  230. /**
  231. * @brief Initialize an ADC16 channel
  232. *
  233. * @param[in] ptr An ADC16 peripheral base address.
  234. * @param[in] config A pointer to the configuration struct of @ref adc16_channel_config_t.
  235. * @return A result of initializing an ADC16 channel.
  236. * @retval status_success Initialize an ADC16 channel successfully. Please refer to @ref hpm_stat_t.
  237. * @retval status_invalid_argument Initialize an ADC16 channel unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  238. */
  239. hpm_stat_t adc16_init_channel(ADC16_Type *ptr, adc16_channel_config_t *config);
  240. /**
  241. * @brief Get thresholds of an ADC16 channel
  242. *
  243. * @param[in] ptr An ADC16 peripheral base address.
  244. * @param[in] ch An ADC16 channel number
  245. * @param[out] config A pointer to the structure of channel threshold
  246. * @return A result of getting thresholds of an ADC16 channel .
  247. * @retval status_success Initialize an ADC16 channel successfully. Please refer to @ref hpm_stat_t.
  248. * @retval status_invalid_argument Initialize an ADC16 channel unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  249. */
  250. hpm_stat_t adc16_get_channel_threshold(ADC16_Type *ptr, uint8_t ch, adc16_channel_threshold_t *config);
  251. #if defined (ADC_SOC_BUSMODE_ENABLE_CTRL_SUPPORT) && ADC_SOC_BUSMODE_ENABLE_CTRL_SUPPORT
  252. /**
  253. * @brief Enable oneshot mode (bus mode)
  254. *
  255. * @param[in] ptr An ADC16 peripheral base address.
  256. */
  257. void adc16_enable_oneshot_mode(ADC16_Type *ptr);
  258. /**
  259. * @brief Disable oneshot mode (bus mode)
  260. *
  261. * @param[in] ptr An ADC16 peripheral base address.
  262. */
  263. void adc16_disable_oneshot_mode(ADC16_Type *ptr);
  264. #endif
  265. /**
  266. * @brief Configure the the period mode for an ADC16 instance.
  267. *
  268. * @param[in] ptr An ADC16 peripheral base address.
  269. * @param[in] config A pointer to the configuration struct of @ref adc16_prd_config_t.
  270. * @return A result of configuring the the period mode for an ADC16 instance.
  271. * @retval status_success Configure the the period mode successfully. Please refer to @ref hpm_stat_t.
  272. * @retval status_invalid_argument Configure the the period mode unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  273. */
  274. hpm_stat_t adc16_set_prd_config(ADC16_Type *ptr, adc16_prd_config_t *config);
  275. /**
  276. * @brief Configure the sequence mode for an ADC16 instance.
  277. *
  278. * @param[in] ptr An ADC16 peripheral base address.
  279. * @param[in] config A pointer to configuration struct of @ref adc16_seq_config_t.
  280. * @return A result of configuring the sequence mode for an ADC16 instance.
  281. * @retval status_success Configure the sequence mode successfully. Please refer to @ref hpm_stat_t.
  282. * @retval status_invalid_argument Configure the sequence mode unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  283. */
  284. hpm_stat_t adc16_set_seq_config(ADC16_Type *ptr, adc16_seq_config_t *config);
  285. /**
  286. * @brief Configure the preemption mode for an ADC16 instance.
  287. *
  288. * @param[in] ptr An ADC16 peripheral base address.
  289. * @param[in] config A pointer to configuration struct of @ref adc16_pmt_config_t.
  290. * @return A result of configuring the preemption mode for an ADC16 instance.
  291. * @retval status_success Configure the preemption mode successfully. Please refer to @ref hpm_stat_t.
  292. * @retval status_invalid_argument Configure the preemption mode unsuccessfully due to passing one or more invalid arguments. Please refer to @ref hpm_stat_t.
  293. */
  294. hpm_stat_t adc16_set_pmt_config(ADC16_Type *ptr, adc16_pmt_config_t *config);
  295. /**
  296. * @brief Set the queue enable control.
  297. *
  298. * @param[in] ptr An ADC16 peripheral base address.
  299. * @param[in] trig_ch An ADC16 peripheral trigger channel.
  300. * @param[in] enable Set true to enable and false to disable.
  301. * @return A result of setting queue enable in preemption.
  302. * @retval status_success Get the result of an ADC16 conversion in oneshot mode successfully.
  303. * @retval status_invalid_argument Get the result of an ADC16 conversion in oneshot mode unsuccessfully due to passing invalid arguments.
  304. */
  305. hpm_stat_t adc16_set_pmt_queue_enable(ADC16_Type *ptr, uint8_t trig_ch, bool enable);
  306. /** @} */
  307. /**
  308. * @name Enablement Control
  309. * @{
  310. */
  311. /**
  312. * @brief Enable the hw trigger control for the sequence mode.
  313. *
  314. * @param[in] ptr An ADC16 peripheral base address.
  315. *
  316. */
  317. static inline void adc16_seq_enable_hw_trigger(ADC16_Type *ptr)
  318. {
  319. ptr->SEQ_CFG0 |= ADC16_SEQ_CFG0_HW_TRIG_EN_MASK;
  320. }
  321. /**
  322. * @brief Disable the hw trigger control for the sequence mode.
  323. *
  324. * @param[in] ptr An ADC16 peripheral base address.
  325. *
  326. */
  327. static inline void adc16_seq_disable_hw_trigger(ADC16_Type *ptr)
  328. {
  329. ptr->SEQ_CFG0 &= ~ADC16_SEQ_CFG0_HW_TRIG_EN_MASK;
  330. }
  331. /** @} */
  332. /**
  333. * @name DMA Control
  334. * @{
  335. */
  336. /**
  337. * @brief Configure the stop position offset in the specified memory of DMA write operation for the sequence mode.
  338. *
  339. * @param[in] ptr An ADC16 peripheral base address.
  340. * @param[in] stop_pos A stop position offset.
  341. */
  342. static inline void adc16_set_seq_stop_pos(ADC16_Type *ptr, uint16_t stop_pos)
  343. {
  344. ptr->SEQ_DMA_CFG = (ptr->SEQ_DMA_CFG & ~ADC16_SEQ_DMA_CFG_STOP_POS_MASK)
  345. | ADC16_SEQ_DMA_CFG_STOP_POS_SET(stop_pos);
  346. }
  347. /**
  348. * @brief Configure the start address of DMA write operation for the preemption mode.
  349. *
  350. * @param[in] ptr An ADC16 peripheral base address.
  351. * @param[in] addr A start address of DMA write operation.
  352. */
  353. static inline void adc16_init_pmt_dma(ADC16_Type *ptr, uint32_t addr)
  354. {
  355. ptr->TRG_DMA_ADDR = addr & ADC16_TRG_DMA_ADDR_TRG_DMA_ADDR_MASK;
  356. }
  357. /**
  358. * @brief Configure the start address of DMA write operation for the sequence mode.
  359. *
  360. * @param[in] ptr An ADC16 peripheral base address.
  361. * @param[in] config A pointer to configuration struct of @ref adc16_dma_config_t.
  362. * @return An implementation result of DMA initializing for the sequence mode
  363. * @retval status_success ADC16 initialize in sequence mode successfully. Please refert to @ref hpm_stat_t.
  364. * @retval status_invalid_argument ADC16 initialize in sequence mode unsuccessfully due to passing invalid arguments. Please refert to @ref hpm_stat_t.
  365. */
  366. hpm_stat_t adc16_init_seq_dma(ADC16_Type *ptr, adc16_dma_config_t *config);
  367. /** @} */
  368. /**
  369. * @name Status
  370. * @{
  371. */
  372. /**
  373. * @brief Get all ADC16 status flags.
  374. *
  375. * @param[in] ptr An ADC16 peripheral base address.
  376. * @return A mask indicating all corresponding interrupt statuses.
  377. * @retval A mask. Please refer to @ref adc16_irq_event_t.
  378. */
  379. static inline uint32_t adc16_get_status_flags(ADC16_Type *ptr)
  380. {
  381. return ptr->INT_STS;
  382. }
  383. /**
  384. * @brief Set value of the WAIT_DIS bit. The ADC does not block access to the associated peripheral bus
  385. * until the ADC has completed its conversion.
  386. *
  387. * @param[in] ptr An ADC16 peripheral base address.
  388. * @deprecated This API will be removed from V2.0.x
  389. */
  390. static inline void adc16_disable_busywait(ADC16_Type *ptr)
  391. {
  392. ptr->BUF_CFG0 |= ADC16_BUF_CFG0_WAIT_DIS_SET(1);
  393. }
  394. /**
  395. * @brief Set value of the WAIT_DIS bit. ADC blocks access to the associated peripheral bus
  396. * until the ADC completes the conversion.
  397. *
  398. * @param[in] ptr An ADC16 peripheral base address.
  399. * @deprecated This API will be removed from V2.0.x
  400. */
  401. static inline void adc16_enable_busywait(ADC16_Type *ptr)
  402. {
  403. ptr->BUF_CFG0 &= ~ADC16_BUF_CFG0_WAIT_DIS_MASK;
  404. }
  405. /**
  406. * @brief Set nonblocking read in oneshot mode.
  407. * @note An ADC does not block access to the associated peripheral whether it completes a conversion or not.
  408. *
  409. * @param[in] ptr An ADC16 peripheral base address.
  410. */
  411. static inline void adc16_set_nonblocking_read(ADC16_Type *ptr)
  412. {
  413. ptr->BUF_CFG0 |= ADC16_BUF_CFG0_WAIT_DIS_MASK;
  414. }
  415. /**
  416. * @brief Set blocking read in oneshot mode.
  417. * @note An ADC blocks access to the associated peripheral bus until it completes a conversion.
  418. *
  419. * @param[in] ptr An ADC16 peripheral base address.
  420. */
  421. static inline void adc16_set_blocking_read(ADC16_Type *ptr)
  422. {
  423. ptr->BUF_CFG0 &= ~ADC16_BUF_CFG0_WAIT_DIS_MASK;
  424. }
  425. /**
  426. * @brief Judge whether the current setting is none-blocking mode or not.
  427. *
  428. * @param[in] ptr An ADC16 peripheral base address.
  429. * @return A result indicating the status of bus waiting.
  430. * @retval True means that nonblocking reading.
  431. * @retval False means that blocking reading.
  432. *
  433. */
  434. static inline bool adc16_is_nonblocking_mode(ADC16_Type *ptr)
  435. {
  436. return (ADC16_BUF_CFG0_WAIT_DIS_GET(ptr->BUF_CFG0) ? true : false);
  437. }
  438. /**
  439. * @brief Get the status of a conversion validity.
  440. *
  441. * @param[in] ptr An ADC16 peripheral base address.
  442. * @param[in] ch An ADC16 peripheral channel.
  443. * @return Status indicating the validity of the current conversion result.
  444. *
  445. * @note This function is only used when the WAIT_DIS bit in the BUF_RESULT register is 1.
  446. */
  447. static inline bool adc16_get_conv_valid_status(ADC16_Type *ptr, uint8_t ch)
  448. {
  449. return ADC16_BUS_RESULT_VALID_GET(ptr->BUS_RESULT[ch]);
  450. }
  451. /**
  452. * @brief Clear the status flags.
  453. *
  454. *
  455. * @param[in] ptr An ADC16 peripheral base address.
  456. * @param[in] mask A mask that means the specified flags to be cleared. Please refer to @ref adc16_irq_event_t.
  457. *
  458. * @note Only the specified flags can be cleared by writing the INT_STS register.
  459. */
  460. static inline void adc16_clear_status_flags(ADC16_Type *ptr, uint32_t mask)
  461. {
  462. ptr->INT_STS = mask;
  463. }
  464. /** @} */
  465. /**
  466. * @name Interrupts
  467. * @{
  468. */
  469. /**
  470. * @brief Enable interrupts.
  471. *
  472. * @param[in] ptr An ADC16 peripheral base address.
  473. * @param[in] mask A mask indicating the specified ADC interrupt events. Please refer to @ref adc16_irq_event_t.
  474. */
  475. static inline void adc16_enable_interrupts(ADC16_Type *ptr, uint32_t mask)
  476. {
  477. ptr->INT_EN |= mask;
  478. }
  479. /**
  480. * @brief Disable interrupts.
  481. *
  482. * @param[in] ptr An ADC16 peripheral base address.
  483. * @param[in] mask A mask indicating the specified interrupt events. Please refer to @ref adc16_irq_event_t.
  484. */
  485. static inline void adc16_disable_interrupts(ADC16_Type *ptr, uint32_t mask)
  486. {
  487. ptr->INT_EN &= ~mask;
  488. }
  489. /** @} */
  490. /**
  491. * @name Trigger and Conversion
  492. * @{
  493. */
  494. /**
  495. * @brief Trigger ADC conversions by software in sequence mode
  496. *
  497. * @param[in] ptr An ADC16 peripheral base address.
  498. * @return An implementation result of getting an ADC16 software trigger.
  499. * @retval status_success ADC16 software triggers successfully. Please refer to @ref hpm_stat_t.
  500. * @retval status_fail ADC16 software triggers unsuccessfully. Please refer to @ref hpm_stat_t.
  501. */
  502. hpm_stat_t adc16_trigger_seq_by_sw(ADC16_Type *ptr);
  503. /**
  504. * @brief Trigger ADC conversions by software in preemption mode
  505. *
  506. * @param[in] ptr An ADC16 peripheral base address.
  507. * @param[in] trig_ch A trigger channel number(e.g. TRIG0A,TRIG0B,TRIG0C...).
  508. * @return An implementation result of getting an ADC16 software trigger.
  509. * @retval status_success ADC16 software triggers successfully. Please refer to @ref hpm_stat_t.
  510. * @retval status_fail ADC16 software triggers unsuccessfully. Please refer to @ref hpm_stat_t.
  511. */
  512. hpm_stat_t adc16_trigger_pmt_by_sw(ADC16_Type *ptr, uint8_t trig_ch);
  513. /**
  514. * @brief Get the result in oneshot mode.
  515. *
  516. * @param[in] ptr An ADC16 peripheral base address.
  517. * @param[in] ch An ADC16 peripheral channel.
  518. * @param[out] result A pointer to an ADC16 conversion result.
  519. * @return An implementation result of getting an ADC16 conversion result in oneshot mode.
  520. * @retval status_success Get the result of an ADC16 conversion in oneshot mode successfully. Please refer to @ref hpm_stat_t.
  521. * @retval status_invalid_argument Get the result of an ADC16 conversion in oneshot mode unsuccessfully due to passing invalid arguments. Please refer to @ref hpm_stat_t.
  522. */
  523. hpm_stat_t adc16_get_oneshot_result(ADC16_Type *ptr, uint8_t ch, uint16_t *result);
  524. /**
  525. * @brief Get the result in the period mode.
  526. *
  527. * @param[in] ptr An ADC16 peripheral base address.
  528. * @param[in] ch An ADC16 peripheral channel.
  529. * @param[out] result A pointer to a specified ADC16 conversion result
  530. * @return An implementation of getting an ADC16 conversion result in the period mode.
  531. * @retval status_success Get the result of an ADC16 conversion in the period mode successfully. Please refer to @ref hpm_stat_t.
  532. * @retval status_invalid_argument Get the result of an ADC16 conversion in the period mode unsuccessfully due to passing invalid arguments. Please refer to @ref hpm_stat_t.
  533. */
  534. hpm_stat_t adc16_get_prd_result(ADC16_Type *ptr, uint8_t ch, uint16_t *result);
  535. #if defined(ADC16_SOC_TEMP_CH_EN) && ADC16_SOC_TEMP_CH_EN
  536. /**
  537. * @brief Enable the temperature sensor
  538. *
  539. * @param[in] ptr An ADC16 peripheral base address.
  540. */
  541. void adc16_enable_temp_sensor(ADC16_Type *ptr);
  542. /**
  543. * @brief Disable the temperature sensor
  544. *
  545. * @param[in] ptr An ADC16 peripheral base address.
  546. */
  547. void adc16_disable_temp_sensor(ADC16_Type *ptr);
  548. #endif
  549. /**
  550. * @brief enable the transmission of adc data to the motor sensor unit.
  551. *
  552. * @param[in] ptr An ADC16 peripheral base address.
  553. */
  554. #if defined(HPM_IP_FEATURE_ADC16_HAS_MOT_EN) && HPM_IP_FEATURE_ADC16_HAS_MOT_EN
  555. static inline void adc16_enable_motor(ADC16_Type *ptr)
  556. {
  557. ptr->ANA_CTRL0 |= ADC16_ANA_CTRL0_MOTO_EN_MASK;
  558. }
  559. #endif
  560. /** @} */
  561. #ifdef __cplusplus
  562. }
  563. #endif
  564. /** @} */
  565. #endif /* HPM_ADC16_DRV_H */