stm8l15x_comp.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_comp.h
  4. * @author MCD Application Team
  5. * @version V1.6.1
  6. * @date 30-September-2014
  7. * @brief This file contains all the functions prototypes for the COMP firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM8L15x_COMP_H
  30. #define __STM8L15x_COMP_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup COMP
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @defgroup COMP_Exported_Types
  41. * @{
  42. */
  43. /** @defgroup COMP_Selection
  44. * @{
  45. */
  46. typedef enum
  47. {
  48. COMP_Selection_COMP1 = ((uint8_t)0x01), /*!< Selection of Comparator 1. */
  49. COMP_Selection_COMP2 = ((uint8_t)0x02) /*!< Selection of Comparator 2. */
  50. }COMP_Selection_TypeDef;
  51. #define IS_COMP_ALL_PERIPH(PERIPH) (((PERIPH) == COMP_Selection_COMP1) || \
  52. ((PERIPH) == COMP_Selection_COMP2))
  53. /**
  54. * @}
  55. */
  56. /** @defgroup COMP_Edge
  57. * @{
  58. */
  59. typedef enum
  60. {
  61. COMP_Edge_Falling = ((uint8_t)0x01), /*!< Falling edge selection. */
  62. COMP_Edge_Rising = ((uint8_t)0x02), /*!< Rising edge selection. */
  63. COMP_Edge_Rising_Falling = ((uint8_t)0x03) /*!< Rising and Falling edge selection. */
  64. }COMP_Edge_TypeDef;
  65. #define IS_COMP_EDGE(EDGE) (((EDGE) == COMP_Edge_Falling) || \
  66. ((EDGE) == COMP_Edge_Rising) || \
  67. ((EDGE) == COMP_Edge_Rising_Falling))
  68. /**
  69. * @}
  70. */
  71. /** @defgroup COMP_Inverting_Input_Selection
  72. * @{
  73. */
  74. typedef enum
  75. {
  76. COMP_InvertingInput_IO = ((uint8_t)0x08), /*!< Input/Output on comparator inverting input enable.*/
  77. COMP_InvertingInput_VREFINT = ((uint8_t)0x10), /*!< VREFINT on comparator inverting input enable. */
  78. COMP_InvertingInput_3_4VREFINT = ((uint8_t)0x18), /*!< 3/4 VREFINT on comparator inverting input enable. */
  79. COMP_InvertingInput_1_2VREFINT = ((uint8_t)0x20), /*!< 1/2 VREFINT on comparator inverting input enable. */
  80. COMP_InvertingInput_1_4VREFINT = ((uint8_t)0x28), /*!< 1/4 VREFINT on comparator inverting input enable. */
  81. COMP_InvertingInput_DAC1 = ((uint8_t)0x30), /*!< DAC1 output on comparator inverting input enable. */
  82. COMP_InvertingInput_DAC2 = ((uint8_t)0x38) /*!< DAC2 output on comparator inverting input enable. */
  83. }COMP_InvertingInput_Typedef;
  84. #define IS_COMP_INVERTING_INPUT(INPUT) (((INPUT) == COMP_InvertingInput_IO) || \
  85. ((INPUT) == COMP_InvertingInput_VREFINT) || \
  86. ((INPUT) == COMP_InvertingInput_3_4VREFINT) || \
  87. ((INPUT) == COMP_InvertingInput_1_2VREFINT) || \
  88. ((INPUT) == COMP_InvertingInput_1_4VREFINT) || \
  89. ((INPUT) == COMP_InvertingInput_DAC1) || \
  90. ((INPUT) == COMP_InvertingInput_DAC2))
  91. /**
  92. * @}
  93. */
  94. /** @defgroup COMP2_Output_Selection
  95. * @{
  96. */
  97. typedef enum
  98. {
  99. COMP_OutputSelect_TIM2IC2 = ((uint8_t)0x00), /*!< COMP2 output connected to TIM2 Input Capture 2 */
  100. COMP_OutputSelect_TIM3IC2 = ((uint8_t)0x40), /*!< COMP2 output connected to TIM3 Input Capture 2 */
  101. COMP_OutputSelect_TIM1BRK = ((uint8_t)0x80), /*!< COMP2 output connected to TIM1 Break Input */
  102. COMP_OutputSelect_TIM1OCREFCLR = ((uint8_t)0xC0) /*!< COMP2 output connected to TIM1 OCREF Clear */
  103. }COMP_OutputSelect_Typedef;
  104. #define IS_COMP_OUTPUT(OUTPUT) (((OUTPUT) == COMP_OutputSelect_TIM2IC2) || \
  105. ((OUTPUT) == COMP_OutputSelect_TIM3IC2) || \
  106. ((OUTPUT) == COMP_OutputSelect_TIM1BRK) || \
  107. ((OUTPUT) == COMP_OutputSelect_TIM1OCREFCLR))
  108. /**
  109. * @}
  110. */
  111. /** @defgroup COMP_Speed
  112. * @{
  113. */
  114. typedef enum
  115. {
  116. COMP_Speed_Slow = ((uint8_t)0x00), /*!< Comparator speed: slow */
  117. COMP_Speed_Fast = ((uint8_t)0x04) /*!< Comparator speed: fast */
  118. }COMP_Speed_TypeDef;
  119. #define IS_COMP_SPEED(SPEED) (((SPEED) == COMP_Speed_Slow) || \
  120. ((SPEED) == COMP_Speed_Fast))
  121. /**
  122. * @}
  123. */
  124. /** @defgroup COMP_Trigger_Group
  125. * @{
  126. */
  127. typedef enum
  128. {
  129. COMP_TriggerGroup_InvertingInput = ((uint8_t)0x01), /*!< Trigger on comparator 2 inverting input */
  130. COMP_TriggerGroup_NonInvertingInput = ((uint8_t)0x02), /*!< Trigger on comparator 2 non inverting input */
  131. COMP_TriggerGroup_VREFINTOutput = ((uint8_t)0x03), /*!< Trigger on VREFINT output */
  132. COMP_TriggerGroup_DACOutput = ((uint8_t)0x04) /*!< Trigger on DAC output */
  133. }COMP_TriggerGroup_TypeDef;
  134. #define IS_COMP_TRIGGERGROUP(TRIGGERGROUP) (((TRIGGERGROUP) == COMP_TriggerGroup_NonInvertingInput) || \
  135. ((TRIGGERGROUP) == COMP_TriggerGroup_InvertingInput) || \
  136. ((TRIGGERGROUP) == COMP_TriggerGroup_VREFINTOutput) || \
  137. ((TRIGGERGROUP) == COMP_TriggerGroup_DACOutput)
  138. /**
  139. * @}
  140. */
  141. /** @defgroup COMP_Trigger_Pin
  142. * @{
  143. */
  144. typedef enum
  145. {
  146. COMP_TriggerPin_0 = ((uint8_t)0x01), /*!< PE5 for the non inverting input Trigger Group
  147. PC3 for the inverting input Trigger Group
  148. PB6 for the DAC output Trigger Group
  149. PC2 for the VREFINT output Trigger Group
  150. */
  151. COMP_TriggerPin_1 = ((uint8_t)0x02), /*!< PD0 for the non inverting input Trigger Group
  152. PC4 for the inverting input Trigger Group
  153. PB5 for the DAC output Trigger Group
  154. PD7 for the VREFINT output Trigger Group
  155. */
  156. COMP_TriggerPin_2 = ((uint8_t)0x04) /*!< PD1 for the non inverting input Trigger Group
  157. PC7 for the inverting input Trigger Group
  158. PB4 for the DAC output Trigger Group
  159. PD6 for the VREFINT output Trigger Group */
  160. }COMP_TriggerPin_TypeDef;
  161. #define IS_COMP_TRIGGERPIN(TRIGGERPIN) ((((uint8_t)(TRIGGERPIN) & (uint8_t)0xF8) == (uint8_t) 0x00) && \
  162. ((TRIGGERPIN) != (uint8_t)0x00))
  163. /**
  164. * @}
  165. */
  166. /** @defgroup COMP_Output_Level
  167. * @{
  168. */
  169. typedef enum
  170. {
  171. COMP_OutputLevel_Low = ((uint8_t)0x00), /*!< Comparator output level is low */
  172. COMP_OutputLevel_High = ((uint8_t)0x01) /*!< Comparator output level is high */
  173. }COMP_OutputLevel_TypeDef;
  174. /**
  175. * @}
  176. */
  177. /**
  178. * @}
  179. */
  180. /* Exported constants --------------------------------------------------------*/
  181. /* Exported macros -----------------------------------------------------------*/
  182. /* Exported functions --------------------------------------------------------*/
  183. /* Function used to set the CLK configuration to the default reset state ******/
  184. void COMP_DeInit(void);
  185. /* Initialization and Configuration functions ****************************/
  186. void COMP_Init(COMP_InvertingInput_Typedef COMP_InvertingInput, COMP_OutputSelect_Typedef COMP_OutputSelect,
  187. COMP_Speed_TypeDef COMP_Speed);
  188. void COMP_VrefintToCOMP1Connect(FunctionalState NewState);
  189. void COMP_EdgeConfig(COMP_Selection_TypeDef COMP_Selection, COMP_Edge_TypeDef COMP_Edge);
  190. COMP_OutputLevel_TypeDef COMP_GetOutputLevel(COMP_Selection_TypeDef COMP_Selection);
  191. /* Window mode control function ***********************************************/
  192. void COMP_WindowCmd(FunctionalState NewState);
  193. /* Internal Reference Voltage (VREFINT) output function ***********************/
  194. void COMP_VrefintOutputCmd(FunctionalState NewState);
  195. /* Comparator channels trigger configuration functions ************************/
  196. void COMP_SchmittTriggerCmd(FunctionalState NewState);
  197. void COMP_TriggerConfig(COMP_TriggerGroup_TypeDef COMP_TriggerGroup,
  198. COMP_TriggerPin_TypeDef COMP_TriggerPin,
  199. FunctionalState NewState);
  200. /* Interrupts and flags management functions **********************************/
  201. void COMP_ITConfig(COMP_Selection_TypeDef COMP_Selection, FunctionalState NewState);
  202. FlagStatus COMP_GetFlagStatus(COMP_Selection_TypeDef COMP_Selection);
  203. void COMP_ClearFlag(COMP_Selection_TypeDef COMP_Selection);
  204. ITStatus COMP_GetITStatus(COMP_Selection_TypeDef COMP_Selection);
  205. void COMP_ClearITPendingBit(COMP_Selection_TypeDef COMP_Selection);
  206. /**
  207. * @}
  208. */
  209. #endif /* __STM8L15x_COMP_H */
  210. /**
  211. * @}
  212. */
  213. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/