es8311.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * ES8311.h -- ES8311 ALSA SoC Audio Codec
  3. *
  4. * Authors:
  5. *
  6. * Based on ES8374.h by David Yang
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef _ES8311_H
  13. #define _ES8311_H
  14. #include "driver/i2c.h"
  15. #include "esxxx_common.h"
  16. /*
  17. * ES8311_REGISTER NAME_REG_REGISTER ADDRESS
  18. */
  19. #define ES8311_RESET_REG00 0x00 /*reset digital,csm,clock manager etc.*/
  20. /*
  21. * Clock Scheme Register definition
  22. */
  23. #define ES8311_CLK_MANAGER_REG01 0x01 /* select clk src for mclk, enable clock for codec */
  24. #define ES8311_CLK_MANAGER_REG02 0x02 /* clk divider and clk multiplier */
  25. #define ES8311_CLK_MANAGER_REG03 0x03 /* adc fsmode and osr */
  26. #define ES8311_CLK_MANAGER_REG04 0x04 /* dac osr */
  27. #define ES8311_CLK_MANAGER_REG05 0x05 /* clk divier for adc and dac */
  28. #define ES8311_CLK_MANAGER_REG06 0x06 /* bclk inverter and divider */
  29. #define ES8311_CLK_MANAGER_REG07 0x07 /* tri-state, lrck divider */
  30. #define ES8311_CLK_MANAGER_REG08 0x08 /* lrck divider */
  31. #define ES8311_SDPIN_REG09 0x09 /* dac serial digital port */
  32. #define ES8311_SDPOUT_REG0A 0x0A /* adc serial digital port */
  33. #define ES8311_SYSTEM_REG0B 0x0B /* system */
  34. #define ES8311_SYSTEM_REG0C 0x0C /* system */
  35. #define ES8311_SYSTEM_REG0D 0x0D /* system, power up/down */
  36. #define ES8311_SYSTEM_REG0E 0x0E /* system, power up/down */
  37. #define ES8311_SYSTEM_REG0F 0x0F /* system, low power */
  38. #define ES8311_SYSTEM_REG10 0x10 /* system */
  39. #define ES8311_SYSTEM_REG11 0x11 /* system */
  40. #define ES8311_SYSTEM_REG12 0x12 /* system, Enable DAC */
  41. #define ES8311_SYSTEM_REG13 0x13 /* system */
  42. #define ES8311_SYSTEM_REG14 0x14 /* system, select DMIC, select analog pga gain */
  43. #define ES8311_ADC_REG15 0x15 /* ADC, adc ramp rate, dmic sense */
  44. #define ES8311_ADC_REG16 0x16 /* ADC */
  45. #define ES8311_ADC_REG17 0x17 /* ADC, volume */
  46. #define ES8311_ADC_REG18 0x18 /* ADC, alc enable and winsize */
  47. #define ES8311_ADC_REG19 0x19 /* ADC, alc maxlevel */
  48. #define ES8311_ADC_REG1A 0x1A /* ADC, alc automute */
  49. #define ES8311_ADC_REG1B 0x1B /* ADC, alc automute, adc hpf s1 */
  50. #define ES8311_ADC_REG1C 0x1C /* ADC, equalizer, hpf s2 */
  51. #define ES8311_DAC_REG31 0x31 /* DAC, mute */
  52. #define ES8311_DAC_REG32 0x32 /* DAC, volume */
  53. #define ES8311_DAC_REG33 0x33 /* DAC, offset */
  54. #define ES8311_DAC_REG34 0x34 /* DAC, drc enable, drc winsize */
  55. #define ES8311_DAC_REG35 0x35 /* DAC, drc maxlevel, minilevel */
  56. #define ES8311_DAC_REG37 0x37 /* DAC, ramprate */
  57. #define ES8311_GPIO_REG44 0x44 /* GPIO, dac2adc for test */
  58. #define ES8311_GP_REG45 0x45 /* GP CONTROL */
  59. #define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
  60. #define ES8311_CHD2_REGFE 0xFE /* CHIP ID2 */
  61. #define ES8311_CHVER_REGFF 0xFF /* VERSION */
  62. #define ES8311_CHD1_REGFD 0xFD /* CHIP ID1 */
  63. #define ES8311_MAX_REGISTER 0xFF
  64. typedef struct {
  65. ESCodecMode esMode;
  66. i2c_port_t i2c_port_num;
  67. i2c_config_t i2c_cfg;
  68. DacOutput dacOutput;
  69. AdcInput adcInput;
  70. } Es8311Config;
  71. #define AUDIO_CODEC_ES8311_DEFAULT(){ \
  72. .esMode = ES_MODE_SLAVE, \
  73. .i2c_port_num = I2C_NUM_0, \
  74. .i2c_cfg = { \
  75. .mode = I2C_MODE_MASTER, \
  76. .sda_io_num = IIC_DATA, \
  77. .scl_io_num = IIC_CLK, \
  78. .sda_pullup_en = GPIO_PULLUP_ENABLE,\
  79. .scl_pullup_en = GPIO_PULLUP_ENABLE,\
  80. .master.clk_speed = 100000\
  81. }, \
  82. .adcInput = ADC_INPUT_LINPUT1_RINPUT1,\
  83. .dacOutput = DAC_OUTPUT_LOUT1 | DAC_OUTPUT_LOUT2 | DAC_OUTPUT_ROUT1 | DAC_OUTPUT_ROUT2,\
  84. };
  85. int Es8311Init(Es8311Config *cfg);
  86. void Es8311Uninit();
  87. esp_err_t Es8311GetRef(bool flag);
  88. esp_err_t Es7243Init(void);
  89. int Es7243ReadReg(uint8_t regAdd);
  90. int Es8311ConfigFmt(ESCodecModule mode, ESCodecI2SFmt fmt);
  91. int Es8311I2sConfigClock(ESCodecI2sClock cfg);
  92. int Es8311SetBitsPerSample(ESCodecModule mode, BitsLength bitPerSample);
  93. int Es8311Start(ESCodecModule mode);
  94. int Es8311Stop(ESCodecModule mode);
  95. int Es8311SetVoiceVolume(int volume);
  96. int Es8311GetVoiceVolume(int *volume);
  97. int Es8311SetVoiceMute(int enable);
  98. int Es8311GetVoiceMute(int *mute);
  99. int Es8311SetMicGain(MicGain gain);
  100. int Es8311ConfigAdcInput(AdcInput input);
  101. int Es8311ConfigDacOutput(DacOutput output);
  102. int ES8311WriteReg(uint8_t regAdd, uint8_t data);
  103. void Es8311ReadAll();
  104. int Es8311ReadReg(uint8_t regAdd);
  105. #endif