hpm_dac_drv.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_DAC_DRV_H
  8. #define HPM_DAC_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_dac_regs.h"
  11. #include "hpm_soc_feature.h"
  12. /* The range of DAC output value setting is from 0.0 to 10000.0, which is mapped to 0 to 100 in percentage. */
  13. #define DAC_OUTPUT(PERCENT) (PERCENT / 10000.0f * (DAC_SOC_MAX_DATA + 1))
  14. #define DAC_AHB_ERROR_EVENT DAC_IRQ_EN_AHB_ERROR_MASK
  15. #define DAC_FIFO_EMPTY_EVENT DAC_IRQ_EN_FIFO_EMPTY_MASK
  16. #define DAC_BUF1_COMPLETE_EVENT DAC_IRQ_EN_BUF1_CMPT_MASK
  17. #define DAC_BUF0_COMPLETE_EVENT DAC_IRQ_EN_BUF0_CMPT_MASK
  18. typedef enum {
  19. dac_mode_direct = 0,
  20. dac_mode_step,
  21. dac_mode_buffer
  22. } dac_mode_t;
  23. typedef enum {
  24. dac_ana_div_2 = 0,
  25. dac_ana_div_4,
  26. dac_ana_div_6,
  27. dac_ana_div_8
  28. } dac_ana_div_t;
  29. typedef struct {
  30. bool sync_mode;
  31. uint8_t dac_mode;
  32. uint8_t ana_div;
  33. } dac_config_t;
  34. typedef enum {
  35. dac_step_up = 0,
  36. dac_step_down
  37. } dac_step_direction_t;
  38. typedef enum {
  39. dac_round_mode_oneshot = 0,
  40. dac_round_mode_loop
  41. } dac_round_mode_t;
  42. typedef struct {
  43. uint16_t start_point;
  44. uint16_t end_point;
  45. uint8_t round_mode;
  46. uint8_t up_down;
  47. uint8_t step_num;
  48. } dac_step_config_t;
  49. typedef enum {
  50. dac_data_stru_2_point = 0,
  51. dac_data_stru_1_point
  52. } dac_data_structure_t;
  53. typedef enum {
  54. dac_burst_single = 0,
  55. dac_burst_incr4 = 3,
  56. dac_burst_incr8 = 5
  57. } dac_burst_type_t;
  58. typedef struct {
  59. uint32_t start_addr;
  60. uint8_t stop;
  61. uint16_t len;
  62. } dac_buffer_t;
  63. typedef struct {
  64. uint8_t buf_data_mode;
  65. uint8_t burst;
  66. dac_buffer_t buf0;
  67. dac_buffer_t buf1;
  68. } dac_buffer_config_t;
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. void dac_get_default_config(dac_config_t *config);
  73. hpm_stat_t dac_init(DAC_Type *ptr, dac_config_t *config);
  74. hpm_stat_t dac_set_direct_config(DAC_Type *ptr, uint16_t data);
  75. hpm_stat_t dac_set_step_config(DAC_Type *ptr, uint8_t step_cfg_idx, dac_step_config_t *config);
  76. hpm_stat_t dac_set_buffer_config(DAC_Type *ptr, dac_buffer_config_t *config);
  77. hpm_stat_t dac_set_output_frequency(DAC_Type *ptr, uint32_t dac_input_freq, uint32_t dac_output_freq);
  78. hpm_stat_t dac_set_step_sw_trigger(DAC_Type *ptr, uint8_t step_sw_trig_idx);
  79. void dac_set_buffer_sw_trigger(DAC_Type *ptr);
  80. void dac_set_hw_trigger_enable(DAC_Type *ptr, bool enable);
  81. hpm_stat_t dac_external_dma_request_enable(DAC_Type *ptr, uint8_t buf_idx, bool enable);
  82. void dac_set_buffer_dma_reset(DAC_Type *ptr);
  83. void dac_enable_conversion(DAC_Type *ptr, bool enable);
  84. void dac_enable_interrupts(DAC_Type *ptr, uint32_t mask);
  85. uint32_t dac_get_status_flags(DAC_Type *ptr);
  86. void dac_set_status_flags(DAC_Type *ptr, uint32_t mask);
  87. uint8_t dac_get_current_buffer_index(DAC_Type *ptr);
  88. uint16_t dac_get_current_buffer_offset(DAC_Type *ptr);
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif