gd32f1x0_opa.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*!
  2. \file gd32f1x0_opa.h
  3. \brief definitions for the OPA
  4. \version 2014-12-26, V1.0.0, platform GD32F1x0(x=3,5)
  5. \version 2016-01-15, V2.0.0, platform GD32F1x0(x=3,5,7,9)
  6. \version 2016-04-30, V3.0.0, firmware update for GD32F1x0(x=3,5,7,9)
  7. \version 2017-06-19, V3.1.0, firmware update for GD32F1x0(x=3,5,7,9)
  8. \version 2019-11-20, V3.2.0, firmware update for GD32F1x0(x=3,5,7,9)
  9. */
  10. /*
  11. Copyright (c) 2019, GigaDevice Semiconductor Inc.
  12. Redistribution and use in source and binary forms, with or without modification,
  13. are permitted provided that the following conditions are met:
  14. 1. Redistributions of source code must retain the above copyright notice, this
  15. list of conditions and the following disclaimer.
  16. 2. Redistributions in binary form must reproduce the above copyright notice,
  17. this list of conditions and the following disclaimer in the documentation
  18. and/or other materials provided with the distribution.
  19. 3. Neither the name of the copyright holder nor the names of its contributors
  20. may be used to endorse or promote products derived from this software without
  21. specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  31. OF SUCH DAMAGE.
  32. */
  33. #ifdef GD32F170_190
  34. #ifndef GD32F1X0_OPA_H
  35. #define GD32F1X0_OPA_H
  36. #include "gd32f1x0.h"
  37. /* OPAx(x=0,1,2) definitions */
  38. #define OPA OPA_BASE
  39. #define OPA0 ((uint32_t)0)
  40. #define OPA1 ((uint32_t)1)
  41. #define OPA2 ((uint32_t)2)
  42. /* registers definitions */
  43. #define OPA_CTL REG32(OPA + 0x00000000U) /*!< OPA control register */
  44. #define OPA_BT REG32(OPA + 0x00000004U) /*!< OPA bias trimming register for normal mode */
  45. #define OPA_LPBT REG32(OPA + 0x00000008U) /*!< OPA bias trimming register for low power mode */
  46. /* bits definitions */
  47. /* OPA_CLT */
  48. #define OPA_CTL_OPA0PD BIT(0) /*!< OPA0 power down */
  49. #define OPA_CTL_T3OPA0 BIT(1) /*!< T3 switch enable for OPA0 */
  50. #define OPA_CTL_S1OPA0 BIT(2) /*!< S1 switch enable for OPA0 */
  51. #define OPA_CTL_S2OPA0 BIT(3) /*!< S2 switch enable for OPA0 */
  52. #define OPA_CTL_S3OPA0 BIT(4) /*!< S3 switch enable for OPA0 */
  53. #define OPA_CTL_OPA0CAL_L BIT(5) /*!< OPA1 offset calibration for P diff */
  54. #define OPA_CTL_OPA0CAL_H BIT(6) /*!< OPA1 offset calibration for N diff */
  55. #define OPA_CTL_OPA0LPM BIT(7) /*!< OPA0 low power mode */
  56. #define OPA_CTL_OPA1PD BIT(8) /*!< OPA1 power down */
  57. #define OPA_CTL_T3OPA1 BIT(9) /*!< T3 switch enable for OPA1 */
  58. #define OPA_CTL_S1OPA1 BIT(10) /*!< S1 switch enable for OPA1 */
  59. #define OPA_CTL_S2OPA1 BIT(11) /*!< S2 switch enable for OPA1 */
  60. #define OPA_CTL_S3OPA1 BIT(12) /*!< S3 switch enable for OPA1 */
  61. #define OPA_CTL_OPA1CAL_L BIT(13) /*!< OPA1 offset calibration for P diff */
  62. #define OPA_CTL_OPA1CAL_H BIT(14) /*!< OPA1 offset calibration for N diff */
  63. #define OPA_CTL_OPA1LPM BIT(15) /*!< OPA1 low power mode */
  64. #define OPA_CTL_OPA2PD BIT(16) /*!< OPA2 power down */
  65. #define OPA_CTL_T3OPA2 BIT(17) /*!< T3 switch enable for OPA2 */
  66. #define OPA_CTL_S1OPA2 BIT(18) /*!< S1 switch enable for OPA2 */
  67. #define OPA_CTL_S2OPA2 BIT(19) /*!< S2 switch enable for OPA2 */
  68. #define OPA_CTL_S3OPA2 BIT(20) /*!< S3 switch enable for OPA2 */
  69. #define OPA_CTL_OPA2CAL_L BIT(21) /*!< OPA2 offset calibration for P diff */
  70. #define OPA_CTL_OPA2CAL_H BIT(22) /*!< OPA2 offset calibration for N diff */
  71. #define OPA_CTL_OPA2LPM BIT(23) /*!< OPA2 low power mode */
  72. #define OPA_CTL_S4OPA1 BIT(27) /*!< S4 switch enable for OPA2 */
  73. #define OPA_CTL_OPA_RANGE BIT(28) /*!< Power supply range */
  74. #define OPA_CTL_OPA0CALOUT BIT(29) /*!< OPA0 calibration output */
  75. #define OPA_CTL_OPA1CALOUT BIT(30) /*!< OPA1 calibration output */
  76. #define OPA_CTL_OPA2CALOUT BIT(31) /*!< OPA2 calibration output */
  77. /* OPA_BT */
  78. #define OPA_BT_OA0_TRIM_LOW BITS(0,4) /*!< OPA0, normal mode 5-bit bias trim value for PMOS pairs */
  79. #define OPA_BT_OA0_TRIM_HIGH BITS(5,9) /*!< OPA0, normal mode 5-bit bias trim value for NMOS pairs */
  80. #define OPA_BT_OA1_TRIM_LOW BITS(10,14) /*!< OPA1, normal mode 5-bit bias trim value for PMOS pairs */
  81. #define OPA_BT_OA1_TRIM_HIGH BITS(15,19) /*!< OPA1, normal mode 5-bit bias trim value for NMOS pairs */
  82. #define OPA_BT_OA2_TRIM_LOW BITS(20,24) /*!< OPA2, normal mode 5-bit bias trim value for PMOS pairs*/
  83. #define OPA_BT_OA2_TRIM_HIGH BITS(25,29) /*!< OPA2, normal mode 5-bit bias trim value for NMOS pairs */
  84. #define OPA_BT_OT_USER BIT(31) /*!< OPA trimming mode */
  85. /* OPA_LPBT */
  86. #define OPA_LPBT_OA0_TRIM_LOW BITS(0,4) /*!< OPA0, low-power mode 5-bit bias trim value for PMOS pairs */
  87. #define OPA_LPBT_OA0_TRIM_HIGH BITS(5,9) /*!< OPA0, low-power mode 5-bit bias trim value for NMOS pairs */
  88. #define OPA_LPBT_OA1_TRIM_LOW BITS(10,14) /*!< OPA1, low-power mode 5-bit bias trim value for PMOS pairs */
  89. #define OPA_LPBT_OA1_TRIM_HIGH BITS(15,19) /*!< OPA1, low-power mode 5-bit bias trim value for NMOS pairs */
  90. #define OPA_LPBT_OA2_TRIM_LOW BITS(20,24) /*!< OPA2, low-power mode 5-bit bias trim value for PMOS pairs */
  91. #define OPA_LPBT_OA2_TRIM_HIGH BITS(25,29) /*!< OPA2, low-power mode 5-bit bias trim value for NMOS pairs */
  92. /* constants definitions */
  93. /* opa switch definitions */
  94. #define OPA_T3OPA0 OPA_CTL_T3OPA0 /*!< T3 switch enable for OPA0 */
  95. #define OPA_S1OPA0 OPA_CTL_S1OPA0 /*!< S1 switch enable for OPA0 */
  96. #define OPA_S2OPA0 OPA_CTL_S2OPA0 /*!< S2 switch enable for OPA0 */
  97. #define OPA_S3OPA0 OPA_CTL_S3OPA0 /*!< S3 switch enable for OPA0 */
  98. #define OPA_T3OPA1 OPA_CTL_S3OPA1 /*!< T3 switch enable for OPA1 */
  99. #define OPA_S1OPA1 OPA_CTL_S1OPA1 /*!< S1 switch enable for OPA1 */
  100. #define OPA_S2OPA1 OPA_CTL_S2OPA1 /*!< S2 switch enable for OPA1 */
  101. #define OPA_S3OPA1 OPA_CTL_S3OPA1 /*!< S3 switch enable for OPA1 */
  102. #define OPA_S4OPA1 OPA_CTL_S4OPA1 /*!< S4 switch enable for OPA1 */
  103. #define OPA_T3OPA2 OPA_CTL_T3OPA2 /*!< T3 switch enable for OPA2 */
  104. #define OPA_S1OPA2 OPA_CTL_S1OPA2 /*!< S1 switch enable for OPA2 */
  105. #define OPA_S2OPA2 OPA_CTL_S2OPA2 /*!< S2 switch enable for OPA2 */
  106. #define OPA_S3OPA2 OPA_CTL_S3OPA2 /*!< S3 switch enable for OPA2 */
  107. /* opa trimming mode */
  108. #define OPA_BT_TRIM_FACTORY ((uint32_t)0x00000000) /*!< factory trimming */
  109. #define OPA_BT_TRIM_USER OPA_BT_OT_USER /*!< user trimming */
  110. /* opa input */
  111. #define OPA_INPUT_N ((uint32_t)0x00000040) /*!< NMOS input */
  112. #define OPA_INPUT_P ((uint32_t)0x00000020) /*!< PMOS input */
  113. /* opa power range */
  114. #define OPA_POWRANGE_LOW ((uint32_t)0x00000000) /*!< low power range is selected (VDDA is lower than 3.3V) */
  115. #define OPA_POWRANGE_HIGH OPA_CTL_OPA_RANGE /*!< high power range is selected (VDDA is higher than 3.3V) */
  116. /* function declarations */
  117. /* initialization functions */
  118. /* deinit opa */
  119. void opa_deinit(void);
  120. /* enable opa */
  121. void opa_enable(uint32_t opa_periph);
  122. /* disable opa */
  123. void opa_disable(uint32_t opa_periph);
  124. /* enable opa switch */
  125. void opa_switch_enable(uint32_t opax_swy);
  126. /* disable opa switch */
  127. void opa_switch_disable(uint32_t opax_swy);
  128. /* function configuration */
  129. /* enable opa low_power mode */
  130. void opa_low_power_enable(uint32_t opa_periph);
  131. /* dis opa low_power mode */
  132. void opa_low_power_disable(uint32_t opa_periph);
  133. /* set opa power range */
  134. void opa_power_range_config(uint32_t powerrange);
  135. /* set opa bias trimming mode */
  136. void opa_trim_mode_set(uint32_t opa_trimmode);
  137. /* set opa bias trimming value normal mode */
  138. void opa_trim_value_config(uint32_t opa_periph,uint32_t opa_input,uint32_t opa_trimvalue);
  139. /* set opa bias trimming value low power mode */
  140. void opa_trim_value_lp_config(uint32_t opa_periph,uint32_t opa_input,uint32_t opa_trimvalue);
  141. /* flag & interrupt functions */
  142. /* get opa calibration flag */
  143. FlagStatus opa_cal_out_get(uint32_t opa_periph);
  144. #endif /* GD32F1X0_OPA_H */
  145. #endif /* GD32F170_190 */