stm8s_adc2.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. ******************************************************************************
  3. * @file stm8s_adc2.h
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all the prototypes/macros for the ADC2 peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Define to prevent recursive inclusion -------------------------------------*/
  28. #ifndef __STM8S_ADC2_H
  29. #define __STM8S_ADC2_H
  30. /* Includes ------------------------------------------------------------------*/
  31. #include "stm8s.h"
  32. /* Exported types ------------------------------------------------------------*/
  33. /** @addtogroup ADC2_Exported_Types
  34. * @{
  35. */
  36. /**
  37. * @brief ADC2 clock prescaler selection
  38. */
  39. typedef enum {
  40. ADC2_PRESSEL_FCPU_D2 = (uint8_t)0x00, /**< Prescaler selection fADC2 = fcpu/2 */
  41. ADC2_PRESSEL_FCPU_D3 = (uint8_t)0x10, /**< Prescaler selection fADC2 = fcpu/3 */
  42. ADC2_PRESSEL_FCPU_D4 = (uint8_t)0x20, /**< Prescaler selection fADC2 = fcpu/4 */
  43. ADC2_PRESSEL_FCPU_D6 = (uint8_t)0x30, /**< Prescaler selection fADC2 = fcpu/6 */
  44. ADC2_PRESSEL_FCPU_D8 = (uint8_t)0x40, /**< Prescaler selection fADC2 = fcpu/8 */
  45. ADC2_PRESSEL_FCPU_D10 = (uint8_t)0x50, /**< Prescaler selection fADC2 = fcpu/10 */
  46. ADC2_PRESSEL_FCPU_D12 = (uint8_t)0x60, /**< Prescaler selection fADC2 = fcpu/12 */
  47. ADC2_PRESSEL_FCPU_D18 = (uint8_t)0x70 /**< Prescaler selection fADC2 = fcpu/18 */
  48. } ADC2_PresSel_TypeDef;
  49. /**
  50. * @brief ADC2 External conversion trigger event selection
  51. */
  52. typedef enum {
  53. ADC2_EXTTRIG_TIM = (uint8_t)0x00, /**< Conversion from Internal TIM TRGO event */
  54. ADC2_EXTTRIG_GPIO = (uint8_t)0x01 /**< Conversion from External interrupt on ADC_ETR pin*/
  55. } ADC2_ExtTrig_TypeDef;
  56. /**
  57. * @brief ADC2 data alignment
  58. */
  59. typedef enum {
  60. ADC2_ALIGN_LEFT = (uint8_t)0x00, /**< Data alignment left */
  61. ADC2_ALIGN_RIGHT = (uint8_t)0x08 /**< Data alignment right */
  62. } ADC2_Align_TypeDef;
  63. /**
  64. * @brief ADC2 schmitt Trigger
  65. */
  66. typedef enum {
  67. ADC2_SCHMITTTRIG_CHANNEL0 = (uint8_t)0x00, /**< Schmitt trigger disable on AIN0 */
  68. ADC2_SCHMITTTRIG_CHANNEL1 = (uint8_t)0x01, /**< Schmitt trigger disable on AIN1 */
  69. ADC2_SCHMITTTRIG_CHANNEL2 = (uint8_t)0x02, /**< Schmitt trigger disable on AIN2 */
  70. ADC2_SCHMITTTRIG_CHANNEL3 = (uint8_t)0x03, /**< Schmitt trigger disable on AIN3 */
  71. ADC2_SCHMITTTRIG_CHANNEL4 = (uint8_t)0x04, /**< Schmitt trigger disable on AIN4 */
  72. ADC2_SCHMITTTRIG_CHANNEL5 = (uint8_t)0x05, /**< Schmitt trigger disable on AIN5 */
  73. ADC2_SCHMITTTRIG_CHANNEL6 = (uint8_t)0x06, /**< Schmitt trigger disable on AIN6 */
  74. ADC2_SCHMITTTRIG_CHANNEL7 = (uint8_t)0x07, /**< Schmitt trigger disable on AIN7 */
  75. ADC2_SCHMITTTRIG_CHANNEL8 = (uint8_t)0x08, /**< Schmitt trigger disable on AIN8 */
  76. ADC2_SCHMITTTRIG_CHANNEL9 = (uint8_t)0x09, /**< Schmitt trigger disable on AIN9 */
  77. ADC2_SCHMITTTRIG_CHANNEL10 = (uint8_t)0x0A, /**< Schmitt trigger disable on AIN10 */
  78. ADC2_SCHMITTTRIG_CHANNEL11 = (uint8_t)0x0B, /**< Schmitt trigger disable on AIN11 */
  79. ADC2_SCHMITTTRIG_CHANNEL12 = (uint8_t)0x0C, /**< Schmitt trigger disable on AIN12 */
  80. ADC2_SCHMITTTRIG_CHANNEL13 = (uint8_t)0x0D, /**< Schmitt trigger disable on AIN13 */
  81. ADC2_SCHMITTTRIG_CHANNEL14 = (uint8_t)0x0E, /**< Schmitt trigger disable on AIN14 */
  82. ADC2_SCHMITTTRIG_CHANNEL15 = (uint8_t)0x0F, /**< Schmitt trigger disable on AIN15 */
  83. ADC2_SCHMITTTRIG_ALL = (uint8_t)0x1F /**< Schmitt trigger disable on all channels */
  84. } ADC2_SchmittTrigg_TypeDef;
  85. /**
  86. * @brief ADC2 conversion mode selection
  87. */
  88. typedef enum {
  89. ADC2_CONVERSIONMODE_SINGLE = (uint8_t)0x00, /**< Single conversion mode */
  90. ADC2_CONVERSIONMODE_CONTINUOUS = (uint8_t)0x01 /**< Continuous conversion mode */
  91. } ADC2_ConvMode_TypeDef;
  92. /**
  93. * @brief ADC2 analog channel selection
  94. */
  95. typedef enum {
  96. ADC2_CHANNEL_0 = (uint8_t)0x00, /**< Analog channel 0 */
  97. ADC2_CHANNEL_1 = (uint8_t)0x01, /**< Analog channel 1 */
  98. ADC2_CHANNEL_2 = (uint8_t)0x02, /**< Analog channel 2 */
  99. ADC2_CHANNEL_3 = (uint8_t)0x03, /**< Analog channel 3 */
  100. ADC2_CHANNEL_4 = (uint8_t)0x04, /**< Analog channel 4 */
  101. ADC2_CHANNEL_5 = (uint8_t)0x05, /**< Analog channel 5 */
  102. ADC2_CHANNEL_6 = (uint8_t)0x06, /**< Analog channel 6 */
  103. ADC2_CHANNEL_7 = (uint8_t)0x07, /**< Analog channel 7 */
  104. ADC2_CHANNEL_8 = (uint8_t)0x08, /**< Analog channel 8 */
  105. ADC2_CHANNEL_9 = (uint8_t)0x09, /**< Analog channel 9 */
  106. ADC2_CHANNEL_10 = (uint8_t)0x0A, /**< Analog channel 10 */
  107. ADC2_CHANNEL_11 = (uint8_t)0x0B, /**< Analog channel 11 */
  108. ADC2_CHANNEL_12 = (uint8_t)0x0C, /**< Analog channel 12 */
  109. ADC2_CHANNEL_13 = (uint8_t)0x0D, /**< Analog channel 13 */
  110. ADC2_CHANNEL_14 = (uint8_t)0x0E, /**< Analog channel 14 */
  111. ADC2_CHANNEL_15 = (uint8_t)0x0F /**< Analog channel 15 */
  112. } ADC2_Channel_TypeDef;
  113. /**
  114. * @}
  115. */
  116. /* Exported constants --------------------------------------------------------*/
  117. /* Exported macros ------------------------------------------------------------*/
  118. /* Private macros ------------------------------------------------------------*/
  119. /** @addtogroup ADC2_Private_Macros
  120. * @brief Macros used by the assert function to check the different functions parameters.
  121. * @{
  122. */
  123. /**
  124. * @brief Macro used by the assert function to check the different prescaler's values.
  125. */
  126. #define IS_ADC2_PRESSEL_OK(PRESCALER) (((PRESCALER) == ADC2_PRESSEL_FCPU_D2) || \
  127. ((PRESCALER) == ADC2_PRESSEL_FCPU_D3) || \
  128. ((PRESCALER) == ADC2_PRESSEL_FCPU_D4) || \
  129. ((PRESCALER) == ADC2_PRESSEL_FCPU_D6) || \
  130. ((PRESCALER) == ADC2_PRESSEL_FCPU_D8) || \
  131. ((PRESCALER) == ADC2_PRESSEL_FCPU_D10) || \
  132. ((PRESCALER) == ADC2_PRESSEL_FCPU_D12) || \
  133. ((PRESCALER) == ADC2_PRESSEL_FCPU_D18))
  134. /**
  135. * @brief Macro used by the assert function to check the different external trigger values.
  136. */
  137. #define IS_ADC2_EXTTRIG_OK(EXTRIG) (((EXTRIG) == ADC2_EXTTRIG_TIM) || \
  138. ((EXTRIG) == ADC2_EXTTRIG_GPIO))
  139. /**
  140. * @brief Macro used by the assert function to check the different alignment modes.
  141. */
  142. #define IS_ADC2_ALIGN_OK(ALIGN) (((ALIGN) == ADC2_ALIGN_LEFT) || \
  143. ((ALIGN) == ADC2_ALIGN_RIGHT))
  144. /**
  145. * @brief Macro used by the assert function to check the different schmitt trigger values.
  146. */
  147. #define IS_ADC2_SCHMITTTRIG_OK(SCHMITTTRIG) (((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL0) || \
  148. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL1) || \
  149. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL2) || \
  150. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL3) || \
  151. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL4) || \
  152. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL5) || \
  153. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL6) || \
  154. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL7) || \
  155. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL8) || \
  156. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL9) || \
  157. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL10) || \
  158. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL11) || \
  159. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL12) || \
  160. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL13) || \
  161. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL14) || \
  162. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_CHANNEL15) || \
  163. ((SCHMITTTRIG) == ADC2_SCHMITTTRIG_ALL))
  164. /**
  165. * @brief Macro used by the assert function to check the different conversion modes.
  166. */
  167. #define IS_ADC2_CONVERSIONMODE_OK(MODE) (((MODE) == ADC2_CONVERSIONMODE_SINGLE) || \
  168. ((MODE) == ADC2_CONVERSIONMODE_CONTINUOUS))
  169. /**
  170. * @brief Macro used by the assert function to check the different channels values.
  171. */
  172. #define IS_ADC2_CHANNEL_OK(CHANNEL) (((CHANNEL) == ADC2_CHANNEL_0) || \
  173. ((CHANNEL) == ADC2_CHANNEL_1) || \
  174. ((CHANNEL) == ADC2_CHANNEL_2) || \
  175. ((CHANNEL) == ADC2_CHANNEL_3) || \
  176. ((CHANNEL) == ADC2_CHANNEL_4) || \
  177. ((CHANNEL) == ADC2_CHANNEL_5) || \
  178. ((CHANNEL) == ADC2_CHANNEL_6) || \
  179. ((CHANNEL) == ADC2_CHANNEL_7) || \
  180. ((CHANNEL) == ADC2_CHANNEL_8) || \
  181. ((CHANNEL) == ADC2_CHANNEL_9) || \
  182. ((CHANNEL) == ADC2_CHANNEL_10) || \
  183. ((CHANNEL) == ADC2_CHANNEL_11) || \
  184. ((CHANNEL) == ADC2_CHANNEL_12) || \
  185. ((CHANNEL) == ADC2_CHANNEL_13) || \
  186. ((CHANNEL) == ADC2_CHANNEL_14) || \
  187. ((CHANNEL) == ADC2_CHANNEL_15))
  188. /**
  189. * @}
  190. */
  191. /* Exported functions ------------------------------------------------------- */
  192. /** @addtogroup ADC2_Exported_Functions
  193. * @{
  194. */
  195. void ADC2_DeInit(void);
  196. void ADC2_Init(ADC2_ConvMode_TypeDef ADC2_ConversionMode,
  197. ADC2_Channel_TypeDef ADC2_Channel,
  198. ADC2_PresSel_TypeDef ADC2_PrescalerSelection,
  199. ADC2_ExtTrig_TypeDef ADC2_ExtTrigger,
  200. FunctionalState ADC2_ExtTriggerState,
  201. ADC2_Align_TypeDef ADC2_Align,
  202. ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel,
  203. FunctionalState ADC2_SchmittTriggerState);
  204. void ADC2_Cmd(FunctionalState NewState);
  205. void ADC2_ITConfig(FunctionalState NewState);
  206. void ADC2_PrescalerConfig(ADC2_PresSel_TypeDef ADC2_Prescaler);
  207. void ADC2_SchmittTriggerConfig(ADC2_SchmittTrigg_TypeDef ADC2_SchmittTriggerChannel,
  208. FunctionalState NewState);
  209. void ADC2_ConversionConfig(ADC2_ConvMode_TypeDef ADC2_ConversionMode,
  210. ADC2_Channel_TypeDef ADC2_Channel,
  211. ADC2_Align_TypeDef ADC2_Align);
  212. void ADC2_ExternalTriggerConfig(ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, FunctionalState NewState);
  213. void ADC2_StartConversion(void);
  214. uint16_t ADC2_GetConversionValue(void);
  215. FlagStatus ADC2_GetFlagStatus(void);
  216. void ADC2_ClearFlag(void);
  217. ITStatus ADC2_GetITStatus(void);
  218. void ADC2_ClearITPendingBit(void);
  219. /**
  220. * @}
  221. */
  222. #endif /* __STM8S_ADC2_H */
  223. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/