ch32v00X_opa.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v00X_opa.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2024/01/01
  6. * Description : This file contains all the functions prototypes for the
  7. * OPA firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V00X_OPA_H
  14. #define __CH32V00X_OPA_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ch32v00X.h"
  19. /* OPA_PSEL_POLL_enumeration */
  20. typedef enum
  21. {
  22. CHP_OPA_POLL_OFF = 0,
  23. CHP_OPA_POLL_ON,
  24. } OPA_PSEL_POLL_TypeDef;
  25. /* OPA_PSEL_POLL_NUM_enumeration */
  26. typedef enum
  27. {
  28. CHP_POLL_NUM_1 = 0,
  29. CHP_POLL_NUM_2,
  30. CHP_POLL_NUM_3
  31. } OPA_PSEL_POLL_NUM_TypeDef;
  32. /* OPA_RST_EN_enumeration */
  33. typedef enum
  34. {
  35. RST_OPA_OFF = 0,
  36. RST_OPA_ON,
  37. } OPA_RST_EN_TypeDef;
  38. /* OPA_SETUP_CFG_enumeration */
  39. typedef enum
  40. {
  41. OPA_SETUP_CFG_0 = 0,
  42. OPA_SETUP_CFG_1,
  43. OPA_SETUP_CFG_2 = 3,
  44. } OPA_SETUP_CFG_TypeDef;
  45. /* OPA_POLL_AUTO_enumeration */
  46. typedef enum
  47. {
  48. OPA_POLL_AUTO_OFF = 0,
  49. OPA_POLL_AUTO_ON,
  50. } OPA_POLL_AUTO_TypeDef;
  51. /* OPA_OUT_IE_enumeration */
  52. typedef enum
  53. {
  54. OUT_IE_OFF= 0,
  55. OUT_IE_ON,
  56. } OPA_OUT_IE_TypeDef;
  57. /* OPA_NMI_IE_enumeration */
  58. typedef enum
  59. {
  60. NMI_IE_OFF = 0,
  61. NMI_IE_ON,
  62. } OPA_NMI_IE_TypeDef;
  63. /* OPA_POLL_CH1_definition */
  64. typedef enum
  65. {
  66. OPA_POLL_CH1_PA2 = 0,
  67. OPA_POLL_CH1_PD7,
  68. OPA_POLL_CH1_PD3,
  69. OPA_POLL_CH1_PD1
  70. } OPA_POLL_CH1_TypeDef;
  71. /* OPA_POLL_CH2_definition */
  72. typedef enum
  73. {
  74. OPA_POLL_CH2_PA2 = 0,
  75. OPA_POLL_CH2_PD7,
  76. OPA_POLL_CH2_PD3,
  77. OPA_POLL_CH2_PD1
  78. } OPA_POLL_CH2_TypeDef;
  79. /* OPA_POLL_CH3_definition */
  80. typedef enum
  81. {
  82. OPA_POLL_CH3_PA2 = 0,
  83. OPA_POLL_CH3_PD7,
  84. OPA_POLL_CH3_PD3,
  85. OPA_POLL_CH3_PD1
  86. } OPA_POLL_CH3_TypeDef;
  87. /* OPA_POLL_SEL_enumeration */
  88. typedef enum
  89. {
  90. OPA_POLL_SEL_SOFT = 0,
  91. OPA_POLL_SEL_TIM1_CH4,
  92. OPA_POLL_SEL_TIM2_CH4,
  93. OPA_POLL_SEL_TIM3_CH1,
  94. OPA_POLL_SEL_TIM3_CH2
  95. } OPA_POLL_SEL_TypeDef;
  96. /* OPA_out_channel_enumeration */
  97. typedef enum
  98. {
  99. OUT_IO_OUT0 = 0,
  100. OUT_IO_OUT1,
  101. OUT_CMP2_ONLY = 3
  102. } OPA_Mode_TypeDef;
  103. /* OPA_PSEL_enumeration */
  104. typedef enum
  105. {
  106. CHP0 = 0,
  107. CHP1,
  108. CHP2,
  109. CHP3,
  110. } OPA_PSEL_TypeDef;
  111. /* OPA_NSEL_enumeration */
  112. typedef enum
  113. {
  114. CHN0 = 0,
  115. CHN1,
  116. CHN_PGA_4xIN = 3,
  117. CHN_PGA_8xIN,
  118. CHN_PGA_16xIN,
  119. CHN_PGA_32xIN,
  120. CHN_OFF,
  121. } OPA_NSEL_TypeDef;
  122. /* OPA_FB_enumeration */
  123. typedef enum
  124. {
  125. FB_OFF = 0,
  126. FB_ON
  127. } OPA_FB_TypeDef;
  128. /* OPA_PGADIF_enumeration */
  129. typedef enum
  130. {
  131. PGADIF_OFF = 0,
  132. PGADIF_ON
  133. } OPA_PGADIF_TypeDef;
  134. /* OPA_PGA_VBEN_enumeration */
  135. typedef enum
  136. {
  137. PGA_VBEN_OFF = 0,
  138. PGA_VBEN_ON,
  139. } OPA_PGA_VBEN_TypeDef;
  140. /* OPA_PGA_VBSEL_enumeration */
  141. typedef enum
  142. {
  143. PGA_VBSEL_VDD_DIV2 = 0,
  144. PGA_VBSEL_VDD_DIV4,
  145. } OPA_PGA_VBSEL_TypeDef;
  146. /* OPA_VBCMPSEL_enumeration */
  147. typedef enum
  148. {
  149. VBCMPSEL_Mode_0 = 0,
  150. VBCMPSEL_Mode_1,
  151. VBCMPSEL_Mode_2,
  152. VBCMPSEL_OFF
  153. } OPA_VBCMPSEL_TypeDef;
  154. /* OPA_HIGH_SPEED_enumeration */
  155. typedef enum
  156. {
  157. HS_OFF = 0,
  158. HS_ON
  159. } OPA_HIGH_SPEED_TypeDef;
  160. /* OPA Init Structure definition */
  161. typedef struct
  162. {
  163. OPA_PSEL_POLL_TypeDef PSEL_POLL;/* Specifies the positive channel poll of OPA */
  164. OPA_PSEL_POLL_NUM_TypeDef POLL_NUM; /* Specifies the number of OPA poll */
  165. OPA_RST_EN_TypeDef RST_EN; /* Specifies the reset source of OPA */
  166. OPA_SETUP_CFG_TypeDef SETUP_CFG;/* Specifies the ADC conversion interval for the OPA */
  167. OPA_POLL_AUTO_TypeDef POLL_AT; /* specifies auto Poll of OPA */
  168. OPA_OUT_IE_TypeDef OUT_IE; /* Specifies the out interrupt of OPA */
  169. OPA_NMI_IE_TypeDef NMI_IE; /* Specifies the out NMI interrupt of OPA */
  170. OPA_POLL_CH1_TypeDef POLL_CH1; /* Specifies the poll channel 1 of OPA */
  171. OPA_POLL_CH2_TypeDef POLL_CH2; /* Specifies the poll channel 2 of OPA */
  172. OPA_POLL_CH3_TypeDef POLL_CH3; /* Specifies the poll channel 3 of OPA */
  173. OPA_POLL_SEL_TypeDef POLL_SEL; /* specifies Poll Trigger Event of OPA */
  174. OPA_Mode_TypeDef Mode; /* Specifies the mode of OPA */
  175. OPA_PSEL_TypeDef PSEL; /* Specifies the positive channel of OPA */
  176. OPA_NSEL_TypeDef NSEL; /* Specifies the negative channel of OPA */
  177. OPA_FB_TypeDef FB; /* Specifies the internal feedback resistor of OPA */
  178. OPA_PGADIF_TypeDef PGADIF; /* OPA with NSEL1 for use as a PGA */
  179. OPA_PGA_VBEN_TypeDef PGA_VBEN; /* Enable PGA mode positive reference voltage */
  180. OPA_PGA_VBSEL_TypeDef PGA_VBSEL;/* Specifies the positive reference voltage for PGA mode */
  181. OPA_VBCMPSEL_TypeDef VBCMPSEL; /* Specifies the CMP2 negative reference voltage */
  182. OPA_HIGH_SPEED_TypeDef OPA_HS; /* specifies high speed mode enable of OPA */
  183. } OPA_InitTypeDef;
  184. /* CMP_member_enumeration */
  185. typedef enum
  186. {
  187. CMP1 = 0,
  188. CMP2
  189. } CMP_Num_TypeDef;
  190. /* CMP_PSEL_POLL_enumeration */
  191. typedef enum
  192. {
  193. CHP_CMP1_POLL_OFF = 0,
  194. CHP_CMP1_POLL_ON,
  195. } CMP_PSEL_POLL_TypeDef;
  196. /* OPA_PSEL_POLL_NUM_enumeration */
  197. typedef enum
  198. {
  199. CMP_POLL_NUM_1 = 0,
  200. CMP_POLL_NUM_2,
  201. CMP_POLL_NUM_3
  202. } CMP_PSEL_POLL_NUM_TypeDef;
  203. /* CMP_OUT_IE_enumeration */
  204. typedef enum
  205. {
  206. CMP_OUT_IE_OFF= 0,
  207. CMP_OUT_IE_ON
  208. } CMP_OUT_IE_TypeDef;
  209. /* CMP_CNT_IE_enumeration */
  210. typedef enum
  211. {
  212. CMP_CNT_IE_OFF = 0,
  213. CMP_CNT_IE_ON,
  214. } CMP_CNT_IE_TypeDef;
  215. /* CMP_POLL_CH1_definition */
  216. typedef enum
  217. {
  218. CMP_POLL_CH1_PC5 = 0,
  219. CMP_POLL_CH1_PB3,
  220. CMP_POLL_CH1_PD2
  221. } CMP_POLL_CH1_TypeDef;
  222. /* CMP_POLL_CH2_definition */
  223. typedef enum
  224. {
  225. CMP_POLL_CH2_PC5 = 0,
  226. CMP_POLL_CH2_PB3,
  227. CMP_POLL_CH2_PD2
  228. } CMP_POLL_CH2_TypeDef;
  229. /* CMP_POLL_CH3_definition */
  230. typedef enum
  231. {
  232. CMP_POLL_CH3_PC5 = 0,
  233. CMP_POLL_CH3_PB3,
  234. CMP_POLL_CH3_PD2
  235. } CMP_POLL_CH3_TypeDef;
  236. /* CMP_out_mode_enumeration */
  237. typedef enum
  238. {
  239. OUT_IO0 = 0,
  240. OUT_IO_TIM1_CH4,
  241. OUT_IO_TIM2_CH4
  242. } CMP_OutMode_TypeDef;
  243. /* CMP_NSEL_enumeration */
  244. typedef enum
  245. {
  246. CMP_CHN0 = 0,
  247. CMP_CHN1,
  248. CMP_CHN2
  249. } CMP_NSEL_TypeDef;
  250. /* CMP_PSEL_enumeration */
  251. typedef enum
  252. {
  253. CMP_CHP0 = 0,
  254. CMP_CHP1,
  255. CMP_CHP2
  256. } CMP_PSEL_TypeDef;
  257. /* CMP_HYEN_enumeration */
  258. typedef enum
  259. {
  260. CMP_HYEN_OFF = 0,
  261. CMP_HYEN_ON,
  262. } CMP_HYEN_TypeDef;
  263. /* CMP_RMID_enumeration */
  264. typedef enum
  265. {
  266. CMP_RMID_OFF = 0,
  267. CMP_RMID_ON
  268. } CMP_RMID_TypeDef;
  269. /* CMP1 Init Structure definition */
  270. typedef struct
  271. {
  272. uint16_t CMP_POLL_Interval; /* CMP polling interval = (CMP_POLL_Interval+1)*1us
  273. This parameter must range from 0 to 0x1FF.*/
  274. CMP_PSEL_POLL_TypeDef PSEL_POLL; /* Specifies the positive channel poll of CMP */
  275. CMP_PSEL_POLL_NUM_TypeDef POLL_NUM; /* Specifies the poll members of CMP */
  276. CMP_OUT_IE_TypeDef OUT_IE; /* Specifies the out interrupt of CMP */
  277. CMP_CNT_IE_TypeDef CNT_IE; /* Specifies the interrupt at the end of the CMP1 polling interval */
  278. CMP_POLL_CH1_TypeDef POLL_CH1; /* Specifies the poll channel 1 of CMP */
  279. CMP_POLL_CH2_TypeDef POLL_CH2; /* Specifies the poll channel 2 of CMP */
  280. CMP_POLL_CH3_TypeDef POLL_CH3; /* Specifies the poll channel 3 of CMP */
  281. CMP_OutMode_TypeDef CMP_Out_Mode; /* Specifies the out mode of CMP */
  282. CMP_NSEL_TypeDef NSEL; /* Specifies the negative channel of CMP */
  283. CMP_PSEL_TypeDef PSEL; /* Specifies the positive channel of CMP */
  284. CMP_HYEN_TypeDef HYEN; /* Specifies the hysteresis comparator of CMP */
  285. CMP_RMID_TypeDef RMID; /* Specifies the virtual center point of the CMP1 positive input channel */
  286. } CMP1_InitTypeDef;
  287. /* CMP_FILT_Length_definition */
  288. #define CMP_FILT_Len_0 ((uint32_t)0x00000000)
  289. #define CMP_FILT_Len_1 ((uint32_t)0x02000000)
  290. /* TIM1_brake_source_definition */
  291. #define TIM1_Brake_Source_IO ((uint32_t)0x00000000)
  292. #define TIM1_Brake_Source_CMP1 ((uint32_t)0x04000000)
  293. #define TIM1_Brake_Source_CMP2 ((uint32_t)0x08000000)
  294. #define TIM1_Brake_Source_OPA ((uint32_t)0x0C000000)
  295. /* CMP_OUT_POLL_FLAG */
  296. #define CMP_FLAG_OUT_POLL_CH_1 ((uint32_t)0x00001000)
  297. #define CMP_FLAG_OUT_POLL_CH_2 ((uint32_t)0x00002000)
  298. #define CMP_FLAG_OUT_POLL_CH_3 ((uint32_t)0x00004000)
  299. #define CMP_FLAG_POLL_END ((uint32_t)0x00008000)
  300. /* OPA_OUT_POLL_FLAG */
  301. #define OPA_FLAG_OUT_POLL_CH_1 ((uint32_t)0x00001000)
  302. #define OPA_FLAG_OUT_POLL_CH_2 ((uint32_t)0x00002000)
  303. #define OPA_FLAG_OUT_POLL_CH_3 ((uint32_t)0x00004000)
  304. void OPA_Unlock(void);
  305. void OPA_Lock(void);
  306. void OPA_CMP_POLL_Lock(void);
  307. void OPA_CMP_Unlock(void);
  308. void OPA_CMP_Lock(void);
  309. void OPA_Init(OPA_InitTypeDef *OPA_InitStruct);
  310. void OPA_StructInit(OPA_InitTypeDef *OPA_InitStruct);
  311. void OPA_CMP1_Init(CMP1_InitTypeDef *CMP_InitStruct);
  312. void OPA_CMP1_StructInit(CMP1_InitTypeDef *CMP_InitStruct);
  313. void OPA_Cmd(FunctionalState NewState);
  314. void OPA_CMP_Cmd(CMP_Num_TypeDef CMP_NUM, FunctionalState NewState);
  315. void OPA_SystemReset_Cmd(FunctionalState NewState);
  316. void OPA_CMP_SystemReset_Cmd(CMP_Num_TypeDef CMP_NUM, FunctionalState NewState);
  317. void OPA_CMP_FILT_Cmd(FunctionalState NewState);
  318. void OPA_CMP_FILT_LEN_Config(uint32_t FILT_Len);
  319. void OPA_CMP_TIM1_BKINConfig(uint32_t Brake_Source);
  320. FlagStatus OPA_GetFlagStatus(uint32_t OPA_FLAG);
  321. FlagStatus OPA_CMP_GetFlagStatus(uint32_t CMP_FLAG);
  322. void OPA_ClearFlag(uint32_t OPA_FLAG);
  323. void OPA_CMP_ClearFlag(uint32_t CMP_FLAG);
  324. void OPA_SoftwareStartPollCmd(FunctionalState NewState);
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. #endif