n32g45x_opamp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_opamp.h
  29. * @author Nations
  30. * @version v1.0.1
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __N32G45X_OPAMPMP_H__
  35. #define __N32G45X_OPAMPMP_H__
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #include "n32g45x.h"
  40. #include <stdbool.h>
  41. /** @addtogroup N32G45X_StdPeriph_Driver
  42. * @{
  43. */
  44. /** @addtogroup OPAMP
  45. * @{
  46. */
  47. /** @addtogroup OPAMP_Exported_Constants
  48. * @{
  49. */
  50. typedef enum
  51. {
  52. OPAMP1 = 0,
  53. OPAMP2 = 4,
  54. OPAMP3 = 8,
  55. OPAMP4 = 12,
  56. } OPAMPX;
  57. // OPAMP_CS
  58. typedef enum
  59. {
  60. OPAMP1_CS_VPSSEL_PA1 = (0x00L << 19),
  61. OPAMP1_CS_VPSSEL_PA3 = (0x01L << 19),
  62. OPAMP1_CS_VPSSEL_DAC2_PA5 = (0x02L << 19),
  63. OPAMP1_CS_VPSSEL_PA7 = (0x03L << 19),
  64. OPAMP2_CS_VPSSEL_PA7 = (0x00L << 19),
  65. OPAMP2_CS_VPSSEL_PB0 = (0x01L << 19),
  66. OPAMP2_CS_VPSSEL_PE8 = (0x02L << 19),
  67. OPAMP3_CS_VPSSEL_PC9 = (0x00L << 19),
  68. OPAMP3_CS_VPSSEL_PA1 = (0x01L << 19),
  69. OPAMP3_CS_VPSSEL_DAC2_PA5 = (0x02L << 19),
  70. OPAMP3_CS_VPSSEL_PC3 = (0x03L << 19),
  71. OPAMP4_CS_VPSSEL_PC3 = (0x00L << 19),
  72. OPAMP4_CS_VPSSEL_DAC1_PA4 = (0x01L << 19),
  73. OPAMP4_CS_VPSSEL_PC5 = (0x02L << 19),
  74. } OPAMP_CS_VPSSEL;
  75. typedef enum
  76. {
  77. OPAMP1_CS_VMSSEL_PA3 = (0x00L << 17),
  78. OPAMP1_CS_VMSSEL_PA2 = (0x01L << 17),
  79. OPAMPx_CS_VMSSEL_FLOAT = (0x03L << 17),
  80. OPAMP2_CS_VMSSEL_PA2 = (0x00L << 17),
  81. OPAMP2_CS_VMSSEL_PA5 = (0x01L << 17),
  82. OPAMP3_CS_VMSSEL_PC4 = (0x00L << 17),
  83. OPAMP3_CS_VMSSEL_PB10 = (0x01L << 17),
  84. OPAMP4_CS_VMSSEL_PB10 = (0x00L << 17),
  85. OPAMP4_CS_VMSSEL_PC9 = (0x01L << 17),
  86. OPAMP4_CS_VMSSEL_PD8 = (0x02L << 17),
  87. } OPAMP_CS_VMSSEL;
  88. typedef enum
  89. {
  90. OPAMP1_CS_VPSEL_PA1 = (0x00L << 8),
  91. OPAMP1_CS_VPSEL_PA3 = (0x01L << 8),
  92. OPAMP1_CS_VPSEL_DAC2_PA5 = (0x02L << 8),
  93. OPAMP1_CS_VPSEL_PA7 = (0x03L << 8),
  94. OPAMP2_CS_VPSEL_PA7 = (0x00L << 8),
  95. OPAMP2_CS_VPSEL_PB0 = (0x01L << 8),
  96. OPAMP2_CS_VPSEL_PE8 = (0x02L << 8),
  97. OPAMP3_CS_VPSEL_PC9 = (0x00L << 8),
  98. OPAMP3_CS_VPSEL_PA1 = (0x01L << 8),
  99. OPAMP3_CS_VPSEL_DAC2_PA5 = (0x02L << 8),
  100. OPAMP3_CS_VPSEL_PC3 = (0x03L << 8),
  101. OPAMP4_CS_VPSEL_PC3 = (0x00L << 8),
  102. OPAMP4_CS_VPSEL_DAC1_PA4 = (0x01L << 8),
  103. OPAMP4_CS_VPSEL_PC5 = (0x02L << 8),
  104. } OPAMP_CS_VPSEL;
  105. typedef enum
  106. {
  107. OPAMP1_CS_VMSEL_PA3 = (0x00L << 6),
  108. OPAMP1_CS_VMSEL_PA2 = (0x01L << 6),
  109. OPAMPx_CS_VMSEL_FLOAT = (0x03L << 6),
  110. OPAMP2_CS_VMSEL_PA2 = (0x00L << 6),
  111. OPAMP2_CS_VMSEL_PA5 = (0x01L << 6),
  112. OPAMP3_CS_VMSEL_PC4 = (0x00L << 6),
  113. OPAMP3_CS_VMSEL_PB10 = (0x01L << 6),
  114. OPAMP4_CS_VMSEL_PB10 = (0x00L << 6),
  115. OPAMP4_CS_VMSEL_PC9 = (0x01L << 6),
  116. OPAMP4_CS_VMSEL_PD8 = (0x02L << 6),
  117. } OPAMP_CS_VMSEL;
  118. typedef enum
  119. {
  120. OPAMP_CS_PGA_GAIN_2 = (0x00 << 3),
  121. OPAMP_CS_PGA_GAIN_4 = (0x01 << 3),
  122. OPAMP_CS_PGA_GAIN_8 = (0x02 << 3),
  123. OPAMP_CS_PGA_GAIN_16 = (0x03 << 3),
  124. OPAMP_CS_PGA_GAIN_32 = (0x04 << 3),
  125. } OPAMP_CS_PGA_GAIN;
  126. typedef enum
  127. {
  128. OPAMP_CS_EXT_OPAMP = (0x00 << 1),
  129. OPAMP_CS_PGA_EN = (0x02 << 1),
  130. OPAMP_CS_FOLLOW = (0x03 << 1),
  131. } OPAMP_CS_MOD;
  132. // bit mask
  133. #define OPAMP_CS_EN_MASK (0x01L << 0)
  134. #define OPAMP_CS_MOD_MASK (0x03L << 1)
  135. #define OPAMP_CS_PGA_GAIN_MASK (0x07L << 3)
  136. #define OPAMP_CS_VMSEL_MASK (0x03L << 6)
  137. #define OPAMP_CS_VPSEL_MASK (0x07L << 8)
  138. #define OPAMP_CS_CALON_MASK (0x01L << 11)
  139. #define OPAMP_CS_TSTREF_MASK (0x01L << 13)
  140. #define OPAMP_CS_CALOUT_MASK (0x01L << 14)
  141. #define OPAMP_CS_RANGE_MASK (0x01L << 15)
  142. #define OPAMP_CS_TCMEN_MASK (0x01L << 16)
  143. #define OPAMP_CS_VMSEL_SECOND_MASK (0x03L << 17)
  144. #define OPAMP_CS_VPSEL_SECOND_MASK (0x07L << 19)
  145. /** @addtogroup OPAMP_LOCK
  146. * @{
  147. */
  148. #define OPAMP_LOCK_1 0x01L
  149. #define OPAMP_LOCK_2 0x02L
  150. #define OPAMP_LOCK_3 0x04L
  151. #define OPAMP_LOCK_4 0x08L
  152. /**
  153. * @}
  154. */
  155. /**
  156. * @}
  157. */
  158. /**
  159. * @brief OPAMP Init structure definition
  160. */
  161. typedef struct
  162. {
  163. FunctionalState TimeAutoMuxEn; /*call ENABLE or DISABLE */
  164. FunctionalState HighVolRangeEn; /*call ENABLE or DISABLE ,low range VDDA < 2.4V,high range VDDA >= 2.4V*/
  165. OPAMP_CS_PGA_GAIN Gain; /*see @EM_PGA_GAIN */
  166. OPAMP_CS_MOD Mod; /*see @EM_OPAMP_MOD*/
  167. } OPAMP_InitType;
  168. /** @addtogroup OPAMP_Exported_Functions
  169. * @{
  170. */
  171. void OPAMP_DeInit(void);
  172. void OPAMP_StructInit(OPAMP_InitType* OPAMP_InitStruct);
  173. void OPAMP_Init(OPAMPX OPAMPx, OPAMP_InitType* OPAMP_InitStruct);
  174. void OPAMP_Enable(OPAMPX OPAMPx, FunctionalState en);
  175. void OPAMP_SetPgaGain(OPAMPX OPAMPx, OPAMP_CS_PGA_GAIN Gain);
  176. void OPAMP_SetVpSecondSel(OPAMPX OPAMPx, OPAMP_CS_VPSSEL VpSSel);
  177. void OPAMP_SetVmSecondSel(OPAMPX OPAMPx, OPAMP_CS_VMSSEL VmSSel);
  178. void OPAMP_SetVpSel(OPAMPX OPAMPx, OPAMP_CS_VPSEL VpSel);
  179. void OPAMP_SetVmSel(OPAMPX OPAMPx, OPAMP_CS_VMSEL VmSel);
  180. bool OPAMP_IsCalOutHigh(OPAMPX OPAMPx);
  181. void OPAMP_CalibrationEnable(OPAMPX OPAMPx, FunctionalState en);
  182. void OPAMP_SetLock(uint32_t Lock); // see @OPAMP_LOCK
  183. /**
  184. * @}
  185. */
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif /*__N32G45X_ADC_H */
  190. /**
  191. * @}
  192. */
  193. /**
  194. * @}
  195. */