apm32f0xx_comp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*!
  2. * @file apm32f0xx_comp.h
  3. *
  4. * @brief This file contains all the functions prototypes for the COMP firmware library
  5. *
  6. * @version V1.0.3
  7. *
  8. * @date 2022-09-20
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. /* Define to prevent recursive inclusion */
  26. #ifndef __APM32F0XX_COMP_H
  27. #define __APM32F0XX_COMP_H
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /* Includes */
  32. #include "apm32f0xx.h"
  33. /** @addtogroup APM32F0xx_StdPeriphDriver
  34. @{
  35. */
  36. /** @addtogroup COMP_Driver
  37. @{
  38. */
  39. /** @defgroup COMP_Macros Macros
  40. @{
  41. */
  42. /* Macros description */
  43. #define COMP_CSTS_COMP1OUT ((uint32_t)0x00004000) /*!< COMP1 output state */
  44. #define COMP_CSTS_COMP2OUT ((uint32_t)0x40000000) /*!< COMP2 output state */
  45. #define COMP_OUTPUTLEVEL_HIGH ((uint32_t)0x00004000) /*!< COMP output level vaild high */
  46. #define COMP_OUTPUTLEVEL_LOW ((uint32_t)0x00000000) /*!< COMP output level vaild low */
  47. /**@} end of group COMP_Macros */
  48. /** @defgroup COMP_Enumerations Enumerations
  49. @{
  50. */
  51. /**
  52. * @brief COMP_Selection
  53. */
  54. typedef enum
  55. {
  56. COMP_SELECT_COMP1 = ((uint32_t)0x00000000), /*!< COMP1 */
  57. COMP_SELECT_COMP2 = ((uint32_t)0x00000010) /*!< COMP2 */
  58. } COMP_SELECT_T;
  59. /**
  60. * @brief COMP_InvertingInput
  61. */
  62. typedef enum
  63. {
  64. COMP_INVERTING_INPUT_1_4VREFINT = 0x00, /*!< 1/4 of VREFINT */
  65. COMP_INVERTING_INPUT_1_2VREFINT = 0x01, /*!< 1/2 of VREFINT */
  66. COMP_INVERTING_INPUT_3_4VREFINT = 0x02, /*!< 3/4 of VREFINT */
  67. COMP_INVERTING_INPUT_VREFINT = 0x03, /*!< VREFINT */
  68. COMP_INVERTING_INPUT_DAC1 = 0x04, /*!< COMP1_INM4 (PA4 with DAC_OUT1 if enabled) */
  69. COMP_INVERTING_INPUT_DAC2 = 0x05, /*!< COMP1_INM5 (PA5 with DAC_OUT2 if present and enabled, only for APM32F072 and APM32F091 devices) */
  70. COMP_INVERTING_INPUT_IO = 0x06, /*!< COMP1_INM6 (PA0) */
  71. } COMP_INVERTING_INPUT_T;
  72. /**
  73. * @brief COMP_Output
  74. */
  75. typedef enum
  76. {
  77. COMP_OUTPUT_NONE = 0x00, /*!< no selection */
  78. COMP_OUTPUT_TIM1BKIN = 0x01, /*!< Timer 1 break input */
  79. COMP_OUTPUT_TIM1IC1 = 0x02, /*!< Timer 1 Input capture 1 */
  80. COMP_OUTPUT_TIM1OCREFCLR = 0x03, /*!< Timer 1 OCrefclear input */
  81. COMP_OUTPUT_TIM2IC4 = 0x04, /*!< Timer 2 input capture 4 */
  82. COMP_OUTPUT_TIM2OCREFCLR = 0x05, /*!< Timer 2 OCrefclear input */
  83. COMP_OUTPUT_TIM3IC1 = 0x06, /*!< Timer 3 input capture 1 */
  84. COMP_OUTPUT_TIM3OCREFCLR = 0x07, /*!< Timer 3 OCrefclear input */
  85. } COMP_OUTPUT_T;
  86. /**
  87. * @brief COMP_OutputPolarity
  88. */
  89. typedef enum
  90. {
  91. COMP_OUTPUTPOL_NONINVERTED, /*!< output is not inverted */
  92. COMP_OUTPUTPOL_INVERTED /*!< output is inverted */
  93. } COMP_OUTPUTPOL_T;
  94. /**
  95. * @brief COMP_Hysteresis
  96. */
  97. typedef enum
  98. {
  99. COMP_HYSTERRSIS_NO = 0x00, /*!< No hysteresis */
  100. COMP_HYSTERRSIS_LOW = 0x01, /*!< Low hysteresis */
  101. COMP_HYSTERRSIS_MEDIUM = 0x02, /*!< Medium hysteresis */
  102. COMP_HYSTERRSIS_HIGH = 0x03, /*!< High hysteresis */
  103. } COMP_HYSTERRSIS_T;
  104. /**
  105. * @brief COMP_Mode
  106. */
  107. typedef enum
  108. {
  109. COMP_MODE_HIGHSPEED = 0x00, /*!< High speed / full power */
  110. COMP_MODE_MEDIUMSPEED = 0x01, /*!< Medium speed / medium power */
  111. COMP_MODE_LOWPOWER = 0x02, /*!< Low speed / low-power */
  112. COMP_MODE_VERYLOW = 0x03 /*!< Very-low speed / ultra-low power */
  113. } COMP_MODE_T;
  114. /**@} end of group COMP_Enumerations*/
  115. /** @defgroup COMP_Structures Structures
  116. @{
  117. */
  118. /**
  119. * @brief OMP Config structure definition
  120. */
  121. typedef struct
  122. {
  123. COMP_INVERTING_INPUT_T invertingInput; /*!< Comparator inverting input selection */
  124. COMP_OUTPUT_T output; /*!< Comparator output selection */
  125. COMP_OUTPUTPOL_T outputPol; /*!< Comparator output polarity */
  126. COMP_HYSTERRSIS_T hysterrsis; /*!< Comparator hysteresis */
  127. COMP_MODE_T mode; /*!< Comparator mode */
  128. } COMP_Config_T;
  129. /**@} end of group COMP_Structures */
  130. /** @defgroup COMP_Variables Variables
  131. @{
  132. */
  133. /**@} end of group COMP_Variables */
  134. /** @defgroup COMP_Functions Functions
  135. @{
  136. */
  137. /* COMP configuration */
  138. void COMP_Reset(void);
  139. void COMP_Config(COMP_SELECT_T compSelect, COMP_Config_T* compConfig);
  140. void COMP_ConfigStructInit(COMP_Config_T* compConfig);
  141. void COMP_Enable(COMP_SELECT_T compSelect);
  142. void COMP_Disable(COMP_SELECT_T compSelect);
  143. void COMP_EnableSwitch(void);
  144. void COMP_DisableSwitch(void);
  145. uint32_t COMP_ReadOutPutLevel(COMP_SELECT_T compSelect);
  146. /* Window mode control */
  147. void COMP_EnableWindow(void);
  148. void COMP_DisnableWindow(void);
  149. /* COMP configuration locking */
  150. void COMP_ConfigLOCK(COMP_SELECT_T compSelect);
  151. #ifdef __cplusplus
  152. }
  153. #endif
  154. #endif /* __APM32F0XX_COMP_H */
  155. /**@} end of group COMP_Functions */
  156. /**@} end of group COMP_Driver */
  157. /**@} end of group APM32F0xx_StdPeriphDriver */