stm8l15x_dac.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /**
  2. ******************************************************************************
  3. * @file stm8l15x_dac.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 DAC 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_DAC_H
  30. #define __STM8L15x_DAC_H
  31. /* Includes ------------------------------------------------------------------*/
  32. #include "stm8l15x.h"
  33. /** @addtogroup STM8L15x_StdPeriph_Driver
  34. * @{
  35. */
  36. /** @addtogroup DAC
  37. * @{
  38. */
  39. /* Exported types ------------------------------------------------------------*/
  40. /** @defgroup DAC_Exported_types
  41. * @{
  42. */
  43. /** @defgroup DAC_trigger_selection
  44. * @{
  45. */
  46. typedef enum
  47. {
  48. DAC_Trigger_None = ((uint8_t)0x30), /*!< DAC trigger None */
  49. DAC_Trigger_T4_TRGO = ((uint8_t)0x00), /*!< DAC trigger TIM4 TRGO */
  50. DAC_Trigger_T5_TRGO = ((uint8_t)0x08), /*!< DAC trigger TIM5 TRGO */
  51. DAC_Trigger_Ext = ((uint8_t)0x10), /*!< DAC trigger External Trigger (PE4) */
  52. DAC_Trigger_Software = ((uint8_t)0x38) /*!< DAC trigger software */
  53. }DAC_Trigger_TypeDef;
  54. #define IS_DAC_TRIGGER(TRIGGER) (((TRIGGER) == DAC_Trigger_None) || \
  55. ((TRIGGER) == DAC_Trigger_T4_TRGO) || \
  56. ((TRIGGER) == DAC_Trigger_T5_TRGO) || \
  57. ((TRIGGER) == DAC_Trigger_Ext) || \
  58. ((TRIGGER) == DAC_Trigger_Software))
  59. /**
  60. * @}
  61. */
  62. /** @defgroup DAC_data_alignment
  63. * @{
  64. */
  65. typedef enum
  66. {
  67. DAC_Align_12b_R = ((uint8_t)0x00), /*!< DAC alignment Right 12bit */
  68. DAC_Align_12b_L = ((uint8_t)0x04), /*!< DAC alignment Left 12bit */
  69. DAC_Align_8b_R = ((uint8_t)0x08) /*!< DAC alignment Right 8bit */
  70. }DAC_Align_TypeDef;
  71. #define IS_DAC_ALIGN(ALIGN) (((ALIGN) == DAC_Align_12b_R) || \
  72. ((ALIGN) == DAC_Align_12b_L) || \
  73. ((ALIGN) == DAC_Align_8b_R))
  74. /**
  75. * @}
  76. */
  77. /** @defgroup DAC_Channel_selection
  78. * @{
  79. */
  80. typedef enum
  81. {
  82. DAC_Channel_1 = ((uint8_t)0x00), /*!< DAC Channel 1 selection */
  83. DAC_Channel_2 = ((uint8_t)0x01) /*!< DAC Channel 2 selection */
  84. }DAC_Channel_TypeDef;
  85. #define IS_DAC_CHANNEL(CHANNEL) (((CHANNEL) == DAC_Channel_1) || \
  86. ((CHANNEL) == DAC_Channel_2))
  87. /**
  88. * @}
  89. */
  90. /** @defgroup DAC_wave_generation
  91. * @{
  92. */
  93. typedef enum
  94. {
  95. DAC_Wave_Noise = ((uint8_t)0x40), /*!< Noise Wave Generation */
  96. DAC_Wave_Triangle = ((uint8_t)0x80) /*!< Triangle Wave Generation */
  97. }DAC_Wave_TypeDef;
  98. #define IS_DAC_WAVE(WAVE) (((WAVE) == DAC_Wave_Noise) || \
  99. ((WAVE) == DAC_Wave_Triangle))
  100. /**
  101. * @}
  102. */
  103. /** @defgroup DAC_output_buffer
  104. * @{
  105. */
  106. typedef enum
  107. {
  108. DAC_OutputBuffer_Enable = ((uint8_t)0x00), /*!< DAC output buffer Enabled */
  109. DAC_OutputBuffer_Disable = ((uint8_t)0x02) /*!< DAC output buffer Disabled */
  110. }DAC_OutputBuffer_TypeDef;
  111. #define IS_DAC_OUTPUT_BUFFER_STATE(STATE) (((STATE) == DAC_OutputBuffer_Enable) || \
  112. ((STATE) == DAC_OutputBuffer_Disable))
  113. /**
  114. * @}
  115. */
  116. /** @defgroup DAC_interrupts_definition
  117. * @{
  118. */
  119. typedef enum
  120. {
  121. DAC_IT_DMAUDR = ((uint8_t)0x20) /*!< DMA Underrun Interrupt */
  122. }DAC_IT_TypeDef;
  123. #define IS_DAC_IT(IT) (((IT) == DAC_IT_DMAUDR))
  124. /**
  125. * @}
  126. */
  127. /** @defgroup DAC_flags_definition
  128. * @{
  129. */
  130. typedef enum
  131. {
  132. DAC_FLAG_DMAUDR = ((uint8_t)0x01) /*!< DMA Underrun flag */
  133. }DAC_FLAG_TypeDef;
  134. #define IS_DAC_GET_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
  135. #define IS_DAC_FLAG(FLAG) (((FLAG) == DAC_FLAG_DMAUDR))
  136. /**
  137. * @}
  138. */
  139. /** @defgroup DAC_lfsrunmask
  140. * @{
  141. */
  142. typedef enum
  143. {
  144. DAC_LFSRUnmask_Bit0 = ((uint8_t)0x00), /*!< Noise LFSR Unmask 1 LSB */
  145. DAC_LFSRUnmask_Bits1_0 = ((uint8_t)0x01), /*!< Noise LFSR Unmask 2 LSB */
  146. DAC_LFSRUnmask_Bits2_0 = ((uint8_t)0x02), /*!< Noise LFSR Unmask 3 LSB */
  147. DAC_LFSRUnmask_Bits3_0 = ((uint8_t)0x03), /*!< Noise LFSR Unmask 4 LSB */
  148. DAC_LFSRUnmask_Bits4_0 = ((uint8_t)0x04), /*!< Noise LFSR Unmask 5 LSB */
  149. DAC_LFSRUnmask_Bits5_0 = ((uint8_t)0x05), /*!< Noise LFSR Unmask 6 LSB */
  150. DAC_LFSRUnmask_Bits6_0 = ((uint8_t)0x06), /*!< Noise LFSR Unmask 7 LSB */
  151. DAC_LFSRUnmask_Bits7_0 = ((uint8_t)0x07), /*!< Noise LFSR Unmask 8 LSB */
  152. DAC_LFSRUnmask_Bits8_0 = ((uint8_t)0x08), /*!< Noise LFSR Unmask 9 LSB */
  153. DAC_LFSRUnmask_Bits9_0 = ((uint8_t)0x09), /*!< Noise LFSR Unmask 10 LSB */
  154. DAC_LFSRUnmask_Bits10_0 = ((uint8_t)0x0A), /*!< Noise LFSR Unmask 11 LSB */
  155. DAC_LFSRUnmask_Bits11_0 = ((uint8_t)0x0B) /*!< Noise LFSR Unmask 12 LSB */
  156. }DAC_LFSRUnmask_TypeDef;
  157. #define IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(VALUE) ((VALUE) <= 0x0F)
  158. /**
  159. * @}
  160. */
  161. /** @defgroup DAC_triangleamplitude
  162. * @{
  163. */
  164. typedef enum
  165. {
  166. DAC_TriangleAmplitude_1 = ((uint8_t)0x00), /*!< Triangle Amplitude = Vref.(1/4096)*/
  167. DAC_TriangleAmplitude_3 = ((uint8_t)0x01), /*!< Triangle Amplitude = Vref.(3/4096)*/
  168. DAC_TriangleAmplitude_7 = ((uint8_t)0x02), /*!< Triangle Amplitude = Vref.(7/4096)*/
  169. DAC_TriangleAmplitude_15 = ((uint8_t)0x03), /*!< Triangle Amplitude = Vref.(15/4096)*/
  170. DAC_TriangleAmplitude_31 = ((uint8_t)0x04), /*!< Triangle Amplitude = Vref.(31/4096)*/
  171. DAC_TriangleAmplitude_63 = ((uint8_t)0x05), /*!< Triangle Amplitude = Vref.(63/4096)*/
  172. DAC_TriangleAmplitude_127 = ((uint8_t)0x06), /*!< Triangle Amplitude = Vref.(127/4096)*/
  173. DAC_TriangleAmplitude_255 = ((uint8_t)0x07), /*!< Triangle Amplitude = Vref.(255/4096)*/
  174. DAC_TriangleAmplitude_511 = ((uint8_t)0x08), /*!< Triangle Amplitude = Vref.(511/4096)*/
  175. DAC_TriangleAmplitude_1023 = ((uint8_t)0x09), /*!< Triangle Amplitude = Vref.(1023/4096)*/
  176. DAC_TriangleAmplitude_2047 = ((uint8_t)0x0A), /*!< Triangle Amplitude = Vref.(2047/4096)*/
  177. DAC_TriangleAmplitude_4095 = ((uint8_t)0x0B) /*!< Triangle Amplitude = Vref.(4095/4096)*/
  178. }DAC_TriangleAmplitude_TypeDef;
  179. /**
  180. * @}
  181. */
  182. /**
  183. * @}
  184. */
  185. /* Exported constants --------------------------------------------------------*/
  186. /** @defgroup DAC_Exported_Constants
  187. * @{
  188. */
  189. /** @defgroup DAC_data
  190. * @{
  191. */
  192. #define IS_DAC_DATA_08R(DATA) ((DATA) <= 0x00FF)
  193. /**
  194. * @}
  195. */
  196. /** @defgroup DAC_Registers_Offset
  197. * @{
  198. */
  199. #define CR1_Offset ((uint8_t)0x00)
  200. #define CR2_Offset ((uint8_t)0x01)
  201. #define DCH1RDHRH_Offset ((uint8_t)0x20)
  202. #define CH1RDHRH_Offset ((uint8_t)0x08)
  203. #define CH2RDHRH_Offset ((uint8_t)0x14)
  204. /**
  205. * @}
  206. */
  207. /** @defgroup DAC_legacy
  208. * @{
  209. */
  210. #define DAC_TriangleWaveAmplitude DAC_SetTriangleWaveAmplitude
  211. #define DAC_NoiseWaveLFSR DAC_SetNoiseWaveLFSR
  212. /**
  213. * @}
  214. */
  215. /**
  216. * @}
  217. */
  218. /* Exported macro ------------------------------------------------------------*/
  219. /* Exported functions ------------------------------------------------------- */
  220. /* Function used to set the DAC configuration to the default reset state *****/
  221. void DAC_DeInit(void);
  222. /* DAC channels configuration: trigger, output buffer, data format functions */
  223. void DAC_Init(DAC_Channel_TypeDef DAC_Channel,
  224. DAC_Trigger_TypeDef DAC_Trigger,
  225. DAC_OutputBuffer_TypeDef DAC_OutputBuffer);
  226. void DAC_Cmd(DAC_Channel_TypeDef DAC_Channel, FunctionalState NewState);
  227. void DAC_SoftwareTriggerCmd(DAC_Channel_TypeDef DAC_Channel, FunctionalState NewState);
  228. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
  229. void DAC_WaveGenerationCmd(DAC_Channel_TypeDef DAC_Channel, DAC_Wave_TypeDef DAC_Wave, FunctionalState NewState);
  230. void DAC_SetNoiseWaveLFSR(DAC_Channel_TypeDef DAC_Channel, DAC_LFSRUnmask_TypeDef DAC_LFSRUnmask);
  231. void DAC_SetTriangleWaveAmplitude(DAC_Channel_TypeDef DAC_Channel, DAC_TriangleAmplitude_TypeDef DAC_TriangleAmplitude);
  232. void DAC_SetChannel1Data(DAC_Align_TypeDef DAC_Align, uint16_t DAC_Data);
  233. void DAC_SetChannel2Data(DAC_Align_TypeDef DAC_Align, uint16_t DAC_Data);
  234. void DAC_SetDualChannelData(DAC_Align_TypeDef DAC_Align, uint16_t DAC_Data2, uint16_t DAC_Data1);
  235. uint16_t DAC_GetDataOutputValue(DAC_Channel_TypeDef DAC_Channel);
  236. /* DMA management function ***************************************************/
  237. void DAC_DMACmd(DAC_Channel_TypeDef DAC_Channel, FunctionalState NewState);
  238. /* Interrupts and flags management functions **********************************/
  239. void DAC_ITConfig(DAC_Channel_TypeDef DAC_Channel, DAC_IT_TypeDef DAC_IT, FunctionalState NewState);
  240. FlagStatus DAC_GetFlagStatus(DAC_Channel_TypeDef DAC_Channel, DAC_FLAG_TypeDef DAC_FLAG);
  241. void DAC_ClearFlag(DAC_Channel_TypeDef DAC_Channel, DAC_FLAG_TypeDef DAC_FLAG);
  242. ITStatus DAC_GetITStatus(DAC_Channel_TypeDef DAC_Channel, DAC_IT_TypeDef DAC_IT);
  243. void DAC_ClearITPendingBit(DAC_Channel_TypeDef DAC_Channel, DAC_IT_TypeDef DAC_IT);
  244. #endif /*__STM8L15x_DAC_H */
  245. /**
  246. * @}
  247. */
  248. /**
  249. * @}
  250. */
  251. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/