dac.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "esp_err.h"
  3. #include <stdbool.h>
  4. typedef enum {
  5. DAC_POWER_ON = 0,
  6. DAC_POWER_STANDBY,
  7. DAC_POWER_OFF,
  8. } dac_power_mode_t;
  9. /**
  10. * DAC driver operations — each DAC driver provides one of these.
  11. * NULL function pointers are treated as no-ops.
  12. */
  13. typedef struct {
  14. esp_err_t (*init)(void *i2c_bus);
  15. esp_err_t (*deinit)(void);
  16. void (*set_volume)(float volume_db);
  17. void (*set_power_mode)(dac_power_mode_t mode);
  18. void (*on_i2s_started)(void);
  19. void (*enable_speaker)(bool enable);
  20. void (*enable_line_out)(bool enable);
  21. } dac_ops_t;
  22. /**
  23. * Register a DAC driver. Must be called before dac_init().
  24. */
  25. void dac_register(const dac_ops_t *ops);
  26. /**
  27. * Initialize the registered DAC driver.
  28. *
  29. * @param i2c_bus I2C master bus handle (may be NULL if the driver
  30. * does not use an externally-provided bus)
  31. */
  32. esp_err_t dac_init(void *i2c_bus);
  33. /**
  34. * Deinitialize the DAC
  35. */
  36. esp_err_t dac_deinit(void);
  37. /**
  38. * Set the DAC output volume (AirPlay dB scale: -30 to 0)
  39. */
  40. void dac_set_volume(float volume_db);
  41. /**
  42. * Set the DAC/amplifier power mode
  43. */
  44. void dac_set_power_mode(dac_power_mode_t mode);
  45. /**
  46. * Notify the DAC driver that the I2S master clock and bit clocks are active.
  47. */
  48. void dac_on_i2s_started(void);
  49. /**
  50. * Enable or disable the speaker output
  51. */
  52. void dac_enable_speaker(bool enable);
  53. /**
  54. * Enable or disable the line output
  55. */
  56. void dac_enable_line_out(bool enable);