ft32f0xx_dac.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_dac.c
  4. * @author FMD AE
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of DAC peripheral
  7. * @version V1.0.0
  8. * @data 2021-07-01
  9. ******************************************************************************
  10. */
  11. /* Includes ------------------------------------------------------------------*/
  12. #include "ft32f0xx_dac.h"
  13. /**
  14. *
  15. */
  16. void DAC_Ref_Config(uint32_t DAC_RefSel)
  17. {
  18. uint32_t tmpreg = 0;
  19. assert_param(IS_DAC_REF_SEL(DAC_RefSel));
  20. tmpreg = DAC->CTRL;
  21. tmpreg &= ~DAC_CTRL_REF_SEL;
  22. tmpreg |= DAC_RefSel;
  23. DAC->CTRL |= tmpreg;
  24. }
  25. /**
  26. * @Parame
  27. */
  28. void DAC_Cmd(FunctionalState NewState)
  29. {
  30. if(NewState != DISABLE)
  31. {
  32. DAC->CTRL |= DAC_CTRL_EN;
  33. }
  34. else
  35. {
  36. DAC->CTRL &= ~DAC_CTRL_EN;
  37. }
  38. }
  39. /**
  40. * @brief Set the specified data holding register value for DAC channel1.
  41. * @param DAC_Align: no use.
  42. * @param Data: Data to be loaded in the selected data DAC1DATA register. 7BIT
  43. * @retval None
  44. */
  45. void DAC_SetChannel1Data(uint32_t DAC_Align, uint8_t Data)
  46. {
  47. /* Check the parameters */
  48. assert_param(IS_DAC_DATA(Data));
  49. DAC->DATA1 = (uint32_t)Data;
  50. }
  51. void DAC_SetChannel2Data(uint32_t DAC_Align, uint8_t Data)
  52. {
  53. /* Check the parameters */
  54. assert_param(IS_DAC_DATA(Data));
  55. DAC->DATA2 = (uint32_t)Data;
  56. }
  57. /**
  58. * @Parame
  59. *
  60. */
  61. uint8_t DAC_Read_Reg(uint8_t DAC_Register)
  62. {
  63. __IO uint32_t tmp = 0;
  64. tmp = (uint32_t)DAC_BASE;
  65. tmp += DAC_Register;
  66. /* Return the selected register value */
  67. return (uint8_t)(*(__IO uint32_t *) tmp);
  68. }