ch32v30x_dac.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v30x_dac.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2021/06/06
  6. * Description : This file contains all the functions prototypes for the
  7. * DAC firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V30x_DAC_H
  14. #define __CH32V30x_DAC_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ch32v30x.h"
  19. /* DAC Init structure definition */
  20. typedef struct
  21. {
  22. uint32_t DAC_Trigger; /* Specifies the external trigger for the selected DAC channel.
  23. This parameter can be a value of @ref DAC_trigger_selection */
  24. uint32_t DAC_WaveGeneration; /* Specifies whether DAC channel noise waves or triangle waves
  25. are generated, or whether no wave is generated.
  26. This parameter can be a value of @ref DAC_wave_generation */
  27. uint32_t DAC_LFSRUnmask_TriangleAmplitude; /* Specifies the LFSR mask for noise wave generation or
  28. the maximum amplitude triangle generation for the DAC channel.
  29. This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */
  30. uint32_t DAC_OutputBuffer; /* Specifies whether the DAC channel output buffer is enabled or disabled.
  31. This parameter can be a value of @ref DAC_output_buffer */
  32. }DAC_InitTypeDef;
  33. /* DAC_trigger_selection */
  34. #define DAC_Trigger_None ((uint32_t)0x00000000) /* Conversion is automatic once the DAC1_DHRxxxx register
  35. has been loaded, and not by external trigger */
  36. #define DAC_Trigger_T6_TRGO ((uint32_t)0x00000004) /* TIM6 TRGO selected as external conversion trigger for DAC channel */
  37. #define DAC_Trigger_T8_TRGO ((uint32_t)0x0000000C) /* TIM8 TRGO selected as external conversion trigger for DAC channel
  38. only in High-density devices*/
  39. #define DAC_Trigger_T7_TRGO ((uint32_t)0x00000014) /* TIM7 TRGO selected as external conversion trigger for DAC channel */
  40. #define DAC_Trigger_T5_TRGO ((uint32_t)0x0000001C) /* TIM5 TRGO selected as external conversion trigger for DAC channel */
  41. #define DAC_Trigger_T2_TRGO ((uint32_t)0x00000024) /* TIM2 TRGO selected as external conversion trigger for DAC channel */
  42. #define DAC_Trigger_T4_TRGO ((uint32_t)0x0000002C) /* TIM4 TRGO selected as external conversion trigger for DAC channel */
  43. #define DAC_Trigger_Ext_IT9 ((uint32_t)0x00000034) /* EXTI Line9 event selected as external conversion trigger for DAC channel */
  44. #define DAC_Trigger_Software ((uint32_t)0x0000003C) /* Conversion started by software trigger for DAC channel */
  45. /* DAC_wave_generation */
  46. #define DAC_WaveGeneration_None ((uint32_t)0x00000000)
  47. #define DAC_WaveGeneration_Noise ((uint32_t)0x00000040)
  48. #define DAC_WaveGeneration_Triangle ((uint32_t)0x00000080)
  49. /* DAC_lfsrunmask_triangleamplitude */
  50. #define DAC_LFSRUnmask_Bit0 ((uint32_t)0x00000000) /* Unmask DAC channel LFSR bit0 for noise wave generation */
  51. #define DAC_LFSRUnmask_Bits1_0 ((uint32_t)0x00000100) /* Unmask DAC channel LFSR bit[1:0] for noise wave generation */
  52. #define DAC_LFSRUnmask_Bits2_0 ((uint32_t)0x00000200) /* Unmask DAC channel LFSR bit[2:0] for noise wave generation */
  53. #define DAC_LFSRUnmask_Bits3_0 ((uint32_t)0x00000300) /* Unmask DAC channel LFSR bit[3:0] for noise wave generation */
  54. #define DAC_LFSRUnmask_Bits4_0 ((uint32_t)0x00000400) /* Unmask DAC channel LFSR bit[4:0] for noise wave generation */
  55. #define DAC_LFSRUnmask_Bits5_0 ((uint32_t)0x00000500) /* Unmask DAC channel LFSR bit[5:0] for noise wave generation */
  56. #define DAC_LFSRUnmask_Bits6_0 ((uint32_t)0x00000600) /* Unmask DAC channel LFSR bit[6:0] for noise wave generation */
  57. #define DAC_LFSRUnmask_Bits7_0 ((uint32_t)0x00000700) /* Unmask DAC channel LFSR bit[7:0] for noise wave generation */
  58. #define DAC_LFSRUnmask_Bits8_0 ((uint32_t)0x00000800) /* Unmask DAC channel LFSR bit[8:0] for noise wave generation */
  59. #define DAC_LFSRUnmask_Bits9_0 ((uint32_t)0x00000900) /* Unmask DAC channel LFSR bit[9:0] for noise wave generation */
  60. #define DAC_LFSRUnmask_Bits10_0 ((uint32_t)0x00000A00) /* Unmask DAC channel LFSR bit[10:0] for noise wave generation */
  61. #define DAC_LFSRUnmask_Bits11_0 ((uint32_t)0x00000B00) /* Unmask DAC channel LFSR bit[11:0] for noise wave generation */
  62. #define DAC_TriangleAmplitude_1 ((uint32_t)0x00000000) /* Select max triangle amplitude of 1 */
  63. #define DAC_TriangleAmplitude_3 ((uint32_t)0x00000100) /* Select max triangle amplitude of 3 */
  64. #define DAC_TriangleAmplitude_7 ((uint32_t)0x00000200) /* Select max triangle amplitude of 7 */
  65. #define DAC_TriangleAmplitude_15 ((uint32_t)0x00000300) /* Select max triangle amplitude of 15 */
  66. #define DAC_TriangleAmplitude_31 ((uint32_t)0x00000400) /* Select max triangle amplitude of 31 */
  67. #define DAC_TriangleAmplitude_63 ((uint32_t)0x00000500) /* Select max triangle amplitude of 63 */
  68. #define DAC_TriangleAmplitude_127 ((uint32_t)0x00000600) /* Select max triangle amplitude of 127 */
  69. #define DAC_TriangleAmplitude_255 ((uint32_t)0x00000700) /* Select max triangle amplitude of 255 */
  70. #define DAC_TriangleAmplitude_511 ((uint32_t)0x00000800) /* Select max triangle amplitude of 511 */
  71. #define DAC_TriangleAmplitude_1023 ((uint32_t)0x00000900) /* Select max triangle amplitude of 1023 */
  72. #define DAC_TriangleAmplitude_2047 ((uint32_t)0x00000A00) /* Select max triangle amplitude of 2047 */
  73. #define DAC_TriangleAmplitude_4095 ((uint32_t)0x00000B00) /* Select max triangle amplitude of 4095 */
  74. /* DAC_output_buffer */
  75. #define DAC_OutputBuffer_Enable ((uint32_t)0x00000000)
  76. #define DAC_OutputBuffer_Disable ((uint32_t)0x00000002)
  77. /* DAC_Channel_selection */
  78. #define DAC_Channel_1 ((uint32_t)0x00000000)
  79. #define DAC_Channel_2 ((uint32_t)0x00000010)
  80. /* DAC_data_alignment */
  81. #define DAC_Align_12b_R ((uint32_t)0x00000000)
  82. #define DAC_Align_12b_L ((uint32_t)0x00000004)
  83. #define DAC_Align_8b_R ((uint32_t)0x00000008)
  84. /* DAC_wave_generation */
  85. #define DAC_Wave_Noise ((uint32_t)0x00000040)
  86. #define DAC_Wave_Triangle ((uint32_t)0x00000080)
  87. void DAC_DeInit(void);
  88. void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);
  89. void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct);
  90. void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState);
  91. void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState);
  92. void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState);
  93. void DAC_DualSoftwareTriggerCmd(FunctionalState NewState);
  94. void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState);
  95. void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data);
  96. void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data);
  97. void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1);
  98. uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel);
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif