hc32f460_cmp.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_cmp.h
  11. **
  12. ** A detailed description is available at
  13. ** @link CmpGroup CMP @endlink
  14. **
  15. ** - 2018-10-22 CDT First version for Device Driver Library of CMP.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_CMP_H__
  19. #define __HC32F460_CMP_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_CMP_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup CmpGroup Comparator(CMP)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief CMP function enumeration
  43. ******************************************************************************/
  44. typedef enum en_cmp_func
  45. {
  46. CmpVcoutOutput = (1u << 12), ///< CMP vcout output enable function
  47. CmpOutpuInv = (1u << 13), ///< CMP output invert enable function
  48. CmpOutput = (1u << 14), ///< CMP output enable function
  49. } en_cmp_func_t;
  50. /**
  51. *******************************************************************************
  52. ** \brief CMP edge selection enumeration
  53. ******************************************************************************/
  54. typedef enum en_cmp_edge_sel
  55. {
  56. CmpNoneEdge = 0u, ///< None edge detection
  57. CmpRisingEdge = 1u, ///< Rising edge detection
  58. CmpFaillingEdge = 2u, ///< Falling edge detection
  59. CmpBothEdge = 3u, ///< Falling or Rising edge detection
  60. } en_cmp_edge_sel_t;
  61. /**
  62. *******************************************************************************
  63. ** \brief CMP filter sample clock division enumeration
  64. ******************************************************************************/
  65. typedef enum en_cmp_fltclk_div
  66. {
  67. CmpNoneFlt = 0u, ///< Unuse filter
  68. CmpFltPclk3Div1 = 1u, ///< PCLK3/1
  69. CmpFltPclk3Div2 = 2u, ///< PCLK3/2
  70. CmpFltPclk3Div4 = 3u, ///< PCLK3/4
  71. CmpFltPclk3Div8 = 4u, ///< PCLK3/8
  72. CmpFltPclk3Div16 = 5u, ///< PCLK3/16
  73. CmpFltPclk3Div32 = 6u, ///< PCLK3/32
  74. CmpFltPclk3Div64 = 7u, ///< PCLK3/64
  75. } en_cmp_fltclk_div_t;
  76. /**
  77. *******************************************************************************
  78. ** \brief CMP INP4 input enumeration
  79. ******************************************************************************/
  80. typedef enum en_cmp_inp4_sel
  81. {
  82. CmpInp4None = 0u, ///< None input
  83. CmpInp4PGAO = 1u, ///< PGAO output
  84. CmpInp4PGAO_BP = 2u, ///< PGAO_BP output
  85. CmpInp4CMP1_INP4 = 4u, ///< CMP1_INP4
  86. } en_cmp_inp4_sel_t;
  87. /**
  88. *******************************************************************************
  89. ** \brief CMP INP input enumeration
  90. ******************************************************************************/
  91. typedef enum en_cmp_inp_sel
  92. {
  93. CmpInpNone = 0u, ///< None input
  94. CmpInp1 = 1u, ///< INP1 input
  95. CmpInp2 = 2u, ///< INP2 input
  96. CmpInp1_Inp2 = 3u, ///< INP1 INP2 input
  97. CmpInp3 = 4u, ///< INP3 input
  98. CmpInp1_Inp3 = 5u, ///< INP1 INP3 input
  99. CmpInp2_Inp3 = 6u, ///< INP2 INP3 input
  100. CmpInp1_Inp2_Inp3 = 7u, ///< INP1 INP2 INP3 input
  101. CmpInp4 = 8u, ///< INP4 input
  102. CmpInp1_Inp4 = 9u, ///< INP1 INP4 input
  103. CmpInp2_Inp4 = 10u, ///< INP2 INP4 input
  104. CmpInp1_Inp2_Inp4 = 11u, ///< INP1 INP2 INP4 input
  105. CmpInp3_Inp4 = 12u, ///< INP3 INP4 input
  106. CmpInp1_Inp3_Inp4 = 13u, ///< INP1 INP3 INP4 input
  107. CmpInp2_Inp3_Inp4 = 14u, ///< INP2 INP3 INP4 input
  108. CmpInp1_Inp2_Inp3_Inp4 = 15u, ///< INP1 INP2 INP3 INP4 input
  109. } en_cmp_inp_sel_t;
  110. /**
  111. *******************************************************************************
  112. ** \brief CMP INM input enumeration
  113. ******************************************************************************/
  114. typedef enum en_cmp_inm_sel
  115. {
  116. CmpInmNone = 0u, ///< None input
  117. CmpInm1 = 1u, ///< INM1 input
  118. CmpInm2 = 2u, ///< INM2 input
  119. CmpInm3 = 4u, ///< INM3 input
  120. CmpInm4 = 8u, ///< INM4 input
  121. } en_cmp_inm_sel_t;
  122. /**
  123. *******************************************************************************
  124. ** \brief CMP INP State enumeration (read only)
  125. ******************************************************************************/
  126. typedef enum en_cmp_inp_state
  127. {
  128. CmpInpNoneState = 0u, ///< none input state
  129. CmpInp1State = 1u, ///< INP1 input state
  130. CmpInp2State = 2u, ///< INP2 input state
  131. CmpInp3State = 4u, ///< INP3 input state
  132. CmpInp4State = 8u, ///< INP4 input state
  133. } en_cmp_inp_state_t;
  134. /**
  135. *******************************************************************************
  136. ** \brief CMP Output State enumeration (read only)
  137. ******************************************************************************/
  138. typedef enum en_cmp_output_state
  139. {
  140. CmpOutputLow = 0u, ///< Compare output Low "0"
  141. CmpOutputHigh = 1u, ///< Compare output High "1"
  142. } en_cmp_output_state_t;
  143. /**
  144. *******************************************************************************
  145. ** \brief CMP input selection
  146. ******************************************************************************/
  147. typedef struct stc_cmp_input_sel
  148. {
  149. en_cmp_inm_sel_t enInmSel; ///< CMP INM sel
  150. en_cmp_inp_sel_t enInpSel; ///< CMP INP sel
  151. en_cmp_inp4_sel_t enInp4Sel; ///< CMP INP4 sel
  152. } stc_cmp_input_sel_t;
  153. /**
  154. ******************************************************************************
  155. ** \brief DAC channel
  156. ******************************************************************************/
  157. typedef enum en_cmp_dac_ch
  158. {
  159. CmpDac1 = 0u, ///< DAC1
  160. CmpDac2 = 1u, ///< DAC2
  161. } en_cmp_dac_ch_t;
  162. /**
  163. ******************************************************************************
  164. ** \brief ADC internal reference voltage path
  165. ******************************************************************************/
  166. typedef enum en_cmp_adc_int_ref_volt_path
  167. {
  168. CmpAdcRefVoltPathDac1 = (1u << 0u), ///< ADC internal reference voltage path: DAC1
  169. CmpAdcRefVoltPathDac2 = (1u << 1u), ///< ADC internal reference voltage path: DAC2
  170. CmpAdcRefVoltPathVref = (1u << 4u), ///< ADC internal reference voltage path: VREF
  171. } en_cmp_adc_int_ref_volt_path_t;
  172. /**
  173. *******************************************************************************
  174. ** \brief CMP initialization structure definition
  175. ******************************************************************************/
  176. typedef struct stc_cmp_init
  177. {
  178. en_cmp_edge_sel_t enEdgeSel; ///< CMP edge sel
  179. en_cmp_fltclk_div_t enFltClkDiv; ///< CMP FLTclock division
  180. en_functional_state_t enCmpOutputEn; ///< CMP Output enable
  181. en_functional_state_t enCmpVcoutOutputEn; ///< CMP output result enable
  182. en_functional_state_t enCmpInvEn; ///< CMP INV sel for output
  183. en_functional_state_t enCmpIntEN; ///< CMP interrupt enable
  184. } stc_cmp_init_t;
  185. /**
  186. *******************************************************************************
  187. ** \brief CMP DAC initialization structure definition
  188. ******************************************************************************/
  189. typedef struct stc_cmp_dac_init
  190. {
  191. uint8_t u8DacData; ///< CMP DAC Data register value
  192. en_functional_state_t enCmpDacEN; ///< CMP DAC enable
  193. } stc_cmp_dac_init_t;
  194. /*******************************************************************************
  195. * Global pre-processor symbols/macros ('#define')
  196. ******************************************************************************/
  197. /*******************************************************************************
  198. * Global variable definitions ('extern')
  199. ******************************************************************************/
  200. /*******************************************************************************
  201. Global function prototypes (definition in C source)
  202. ******************************************************************************/
  203. en_result_t CMP_Init(M4_CMP_TypeDef *CMPx, const stc_cmp_init_t *pstcInitCfg);
  204. en_result_t CMP_DeInit(M4_CMP_TypeDef *CMPx);
  205. en_result_t CMP_Cmd(M4_CMP_TypeDef *CMPx, en_functional_state_t enCmd);
  206. en_result_t CMP_IrqCmd(M4_CMP_TypeDef *CMPx, en_functional_state_t enCmd);
  207. en_result_t CMP_SetScanTime(M4_CMP_TypeDef *CMPx,
  208. uint8_t u8ScanStable,
  209. uint8_t u8ScanPeriod);
  210. en_result_t CMP_FuncCmd(M4_CMP_TypeDef *CMPx,
  211. en_cmp_func_t enFunc,
  212. en_functional_state_t enCmd);
  213. en_result_t CMP_StartScan(M4_CMP_TypeDef *CMPx);
  214. en_result_t CMP_StopScan(M4_CMP_TypeDef *CMPx);
  215. en_result_t CMP_SetFilterClkDiv(M4_CMP_TypeDef *CMPx,
  216. en_cmp_fltclk_div_t enFltClkDiv);
  217. en_cmp_fltclk_div_t CMP_GetFilterClkDiv(M4_CMP_TypeDef *CMPx);
  218. en_result_t CMP_SetEdgeSel(M4_CMP_TypeDef *CMPx,
  219. en_cmp_edge_sel_t enEdgeSel);
  220. en_cmp_edge_sel_t CMP_GetEdgeSel(M4_CMP_TypeDef *CMPx);
  221. en_result_t CMP_InputSel(M4_CMP_TypeDef *CMPx,
  222. const stc_cmp_input_sel_t *pstcInputSel);
  223. en_result_t CMP_SetInp(M4_CMP_TypeDef *CMPx, en_cmp_inp_sel_t enInputSel);
  224. en_cmp_inp_sel_t CMP_GetInp(M4_CMP_TypeDef *CMPx);
  225. en_result_t CMP_SetInm(M4_CMP_TypeDef *CMPx, en_cmp_inm_sel_t enInputSel);
  226. en_cmp_inm_sel_t CMP_GetInm(M4_CMP_TypeDef *CMPx);
  227. en_result_t CMP_SetInp4(M4_CMP_TypeDef *CMPx,en_cmp_inp4_sel_t enInputSel);
  228. en_cmp_inp4_sel_t CMP_GetInp4(M4_CMP_TypeDef *CMPx);
  229. en_cmp_output_state_t CMP_GetOutputState(M4_CMP_TypeDef *CMPx);
  230. en_cmp_inp_state_t CMP_GetInpState(M4_CMP_TypeDef *CMPx);
  231. en_result_t CMP_DAC_Init(en_cmp_dac_ch_t enCh,
  232. const stc_cmp_dac_init_t *pstcInitCfg);
  233. en_result_t CMP_DAC_DeInit(en_cmp_dac_ch_t enCh);
  234. en_result_t CMP_DAC_Cmd(en_cmp_dac_ch_t enCh, en_functional_state_t enCmd);
  235. en_result_t CMP_DAC_SetData(en_cmp_dac_ch_t enCh, uint8_t u8DacData);
  236. uint8_t CMP_DAC_GetData(en_cmp_dac_ch_t enCh);
  237. en_result_t CMP_ADC_SetRefVoltPath(en_cmp_adc_int_ref_volt_path_t enRefVoltPath);
  238. //@} // CmpGroup
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. #endif /* DDL_CMP_ENABLE */
  243. #endif /* __HC32F460_CMP_H__ */
  244. /*******************************************************************************
  245. * EOF (not truncated)
  246. ******************************************************************************/