ES8388AudioSink.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef ES8388AUDIOSINK_H
  2. #define ES8388AUDIOSINK_H
  3. #include "driver/i2s.h"
  4. #include <driver/i2c.h>
  5. #include <vector>
  6. #include <iostream>
  7. #include "BufferedAudioSink.h"
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdint.h>
  11. #include <sys/unistd.h>
  12. #include <sys/stat.h>
  13. #include "esp_err.h"
  14. #include "esp_log.h"
  15. #define ES8388_ADDR 0x20
  16. #define ACK_CHECK_EN 0x1
  17. /* ES8388 register */
  18. #define ES8388_CONTROL1 0x00
  19. #define ES8388_CONTROL2 0x01
  20. #define ES8388_CHIPPOWER 0x02
  21. #define ES8388_ADCPOWER 0x03
  22. #define ES8388_DACPOWER 0x04
  23. #define ES8388_CHIPLOPOW1 0x05
  24. #define ES8388_CHIPLOPOW2 0x06
  25. #define ES8388_ANAVOLMANAG 0x07
  26. #define ES8388_MASTERMODE 0x08
  27. /* ADC */
  28. #define ES8388_ADCCONTROL1 0x09
  29. #define ES8388_ADCCONTROL2 0x0a
  30. #define ES8388_ADCCONTROL3 0x0b
  31. #define ES8388_ADCCONTROL4 0x0c
  32. #define ES8388_ADCCONTROL5 0x0d
  33. #define ES8388_ADCCONTROL6 0x0e
  34. #define ES8388_ADCCONTROL7 0x0f
  35. #define ES8388_ADCCONTROL8 0x10
  36. #define ES8388_ADCCONTROL9 0x11
  37. #define ES8388_ADCCONTROL10 0x12
  38. #define ES8388_ADCCONTROL11 0x13
  39. #define ES8388_ADCCONTROL12 0x14
  40. #define ES8388_ADCCONTROL13 0x15
  41. #define ES8388_ADCCONTROL14 0x16
  42. /* DAC */
  43. #define ES8388_DACCONTROL1 0x17
  44. #define ES8388_DACCONTROL2 0x18
  45. #define ES8388_DACCONTROL3 0x19
  46. #define ES8388_DACCONTROL4 0x1a
  47. #define ES8388_DACCONTROL5 0x1b
  48. #define ES8388_DACCONTROL6 0x1c
  49. #define ES8388_DACCONTROL7 0x1d
  50. #define ES8388_DACCONTROL8 0x1e
  51. #define ES8388_DACCONTROL9 0x1f
  52. #define ES8388_DACCONTROL10 0x20
  53. #define ES8388_DACCONTROL11 0x21
  54. #define ES8388_DACCONTROL12 0x22
  55. #define ES8388_DACCONTROL13 0x23
  56. #define ES8388_DACCONTROL14 0x24
  57. #define ES8388_DACCONTROL15 0x25
  58. #define ES8388_DACCONTROL16 0x26
  59. #define ES8388_DACCONTROL17 0x27
  60. #define ES8388_DACCONTROL18 0x28
  61. #define ES8388_DACCONTROL19 0x29
  62. #define ES8388_DACCONTROL20 0x2a
  63. #define ES8388_DACCONTROL21 0x2b
  64. #define ES8388_DACCONTROL22 0x2c
  65. #define ES8388_DACCONTROL23 0x2d
  66. #define ES8388_DACCONTROL24 0x2e
  67. #define ES8388_DACCONTROL25 0x2f
  68. #define ES8388_DACCONTROL26 0x30
  69. #define ES8388_DACCONTROL27 0x31
  70. #define ES8388_DACCONTROL28 0x32
  71. #define ES8388_DACCONTROL29 0x33
  72. #define ES8388_DACCONTROL30 0x34
  73. class ES8388AudioSink : public BufferedAudioSink
  74. {
  75. public:
  76. ES8388AudioSink();
  77. ~ES8388AudioSink();
  78. bool begin(int sda = -1, int scl = -1, uint32_t frequency = 400000U);
  79. enum ES8388_OUT
  80. {
  81. ES_MAIN, // this is the DAC output volume (both outputs)
  82. ES_OUT1, // this is the additional gain for OUT1
  83. ES_OUT2 // this is the additional gain for OUT2
  84. };
  85. void mute(const ES8388_OUT out, const bool muted);
  86. void volume(const ES8388_OUT out, const uint8_t vol);
  87. void writeReg(uint8_t reg_add, uint8_t data);
  88. private:
  89. i2c_config_t i2c_config;
  90. i2c_port_t i2c_port = 0;
  91. };
  92. #endif