#include "device_dac_out.h"
#include "gd32f4xx.h"
#include "ptz_type_select.h"

#ifdef L6235D
/// @brief      DAC输出初始化 
/// @param[in]  none
/// @return     none 
/// @note       修改日志
///             LH于2022-05-26
void init_dac_out_module(void)
{
  //DAC时钟使能
  rcu_periph_clock_enable(RCU_DAC);
  //DAC输出引脚配置PA4--DAC0，PA5--DAC1
  gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_4);
  gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_5);
  
  dac_deinit();
  /* configure the DAC0 */
  dac_trigger_disable(DAC0);//非触发方式
  dac_wave_mode_config(DAC0, DAC_WAVE_DISABLE);
  dac_output_buffer_enable(DAC0);//输出缓冲区打开
  /* configure the DAC1 */
  dac_trigger_disable(DAC1);//非触发方式
  dac_wave_mode_config(DAC1, DAC_WAVE_DISABLE);
  dac_output_buffer_enable(DAC1);//输出缓冲区打开
  
  /* enable DAC0 and set data */
  dac_enable(DAC0);
  dac_data_set(DAC0, DAC_ALIGN_12B_R, 0);
  /* enable DAC1 and set data */
  dac_enable(DAC1);
  dac_data_set(DAC1, DAC_ALIGN_12B_R, 0);
}

/// @brief      水平电机DAC0输出 
/// @param[in]  data:输出数值，12位右对齐
/// @return     none 
/// @note       修改日志
///             LH于2022-05-26
void hori_dac0_data_out(unsigned short int data)
{
  uint16_t buff;
  buff = (uint16_t)data;
  dac_data_set(DAC0, DAC_ALIGN_12B_R, buff);
}

/// @brief      垂直电机DAC1输出 
/// @param[in]  data:输出数值，12位右对齐
/// @return     none 
/// @note       修改日志
///             LH于2022-05-26
void vert_dac1_data_out(unsigned short int data)
{
  uint16_t buff;
  buff = (uint16_t)data;
  dac_data_set(DAC1, DAC_ALIGN_12B_R, buff);
}


#endif


