acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

es7210.h (7083B)

      1 /*
      2  * ESPRESSIF MIT License
      3  *
      4  * Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
      5  *
      6  * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
      7  * it is free of charge, to any person obtaining a copy of this software and associated
      8  * documentation files (the "Software"), to deal in the Software without restriction, including
      9  * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
     11  * to do so, subject to the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be included in all copies or
     14  * substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
     18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
     19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
     20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     22  *
     23  */
     24 
     25 #ifndef _ES7210_H
     26 #define _ES7210_H
     27 
     28 #include "audio_hal.h"
     29 #include <Wire.h>
     30 
     31 typedef enum {
     32     ES7210_AD1_AD0_00 = 0x40,
     33     ES7210_AD1_AD0_01 = 0x41,
     34     ES7210_AD1_AD0_10 = 0x42,
     35     ES7210_AD1_AD0_11 = 0x43,
     36 } es7210_address_t;
     37 
     38 /* ES7210 address*/
     39 #define ES7210_ADDR                   ES7210_AD1_AD0_00
     40 
     41 #ifdef __cplusplus
     42 extern "C" {
     43 #endif
     44 
     45 #define  ES7210_RESET_REG00                 0x00        /* Reset control */
     46 #define  ES7210_CLOCK_OFF_REG01             0x01        /* Used to turn off the ADC clock */
     47 #define  ES7210_MAINCLK_REG02               0x02        /* Set ADC clock frequency division */
     48 #define  ES7210_MASTER_CLK_REG03            0x03        /* MCLK source $ SCLK division */
     49 #define  ES7210_LRCK_DIVH_REG04             0x04        /* lrck_divh */
     50 #define  ES7210_LRCK_DIVL_REG05             0x05        /* lrck_divl */
     51 #define  ES7210_POWER_DOWN_REG06            0x06        /* power down */
     52 #define  ES7210_OSR_REG07                   0x07
     53 #define  ES7210_MODE_CONFIG_REG08           0x08        /* Set master/slave & channels */
     54 #define  ES7210_TIME_CONTROL0_REG09         0x09        /* Set Chip intial state period*/
     55 #define  ES7210_TIME_CONTROL1_REG0A         0x0A        /* Set Power up state period */
     56 #define  ES7210_SDP_INTERFACE1_REG11        0x11        /* Set sample & fmt */
     57 #define  ES7210_SDP_INTERFACE2_REG12        0x12        /* Pins state */
     58 #define  ES7210_ADC_AUTOMUTE_REG13          0x13        /* Set mute */
     59 #define  ES7210_ADC34_MUTERANGE_REG14       0x14        /* Set mute range */
     60 #define  ES7210_ADC34_HPF2_REG20            0x20        /* HPF */
     61 #define  ES7210_ADC34_HPF1_REG21            0x21
     62 #define  ES7210_ADC12_HPF1_REG22            0x22
     63 #define  ES7210_ADC12_HPF2_REG23            0x23
     64 #define  ES7210_ANALOG_REG40                0x40        /* ANALOG Power */
     65 #define  ES7210_MIC12_BIAS_REG41            0x41
     66 #define  ES7210_MIC34_BIAS_REG42            0x42
     67 #define  ES7210_MIC1_GAIN_REG43             0x43
     68 #define  ES7210_MIC2_GAIN_REG44             0x44
     69 #define  ES7210_MIC3_GAIN_REG45             0x45
     70 #define  ES7210_MIC4_GAIN_REG46             0x46
     71 #define  ES7210_MIC1_POWER_REG47            0x47
     72 #define  ES7210_MIC2_POWER_REG48            0x48
     73 #define  ES7210_MIC3_POWER_REG49            0x49
     74 #define  ES7210_MIC4_POWER_REG4A            0x4A
     75 #define  ES7210_MIC12_POWER_REG4B           0x4B        /* MICBias & ADC & PGA Power */
     76 #define  ES7210_MIC34_POWER_REG4C           0x4C
     77 
     78 
     79 
     80 typedef enum {
     81     ES7210_INPUT_MIC1 = 0x01,
     82     ES7210_INPUT_MIC2 = 0x02,
     83     ES7210_INPUT_MIC3 = 0x04,
     84     ES7210_INPUT_MIC4 = 0x08
     85 } es7210_input_mics_t;
     86 
     87 typedef enum gain_value{
     88 	GAIN_0DB = 0,
     89 	GAIN_3DB,
     90 	GAIN_6DB,
     91 	GAIN_9DB,
     92 	GAIN_12DB,
     93 	GAIN_15DB,
     94 	GAIN_18DB,
     95 	GAIN_21DB,
     96 	GAIN_24DB,
     97 	GAIN_27DB,
     98 	GAIN_30DB,
     99 	GAIN_33DB,
    100 	GAIN_34_5DB,
    101 	GAIN_36DB,
    102 	GAIN_37_5DB,
    103 } es7210_gain_value_t;
    104 
    105 /*
    106  * @brief Initialize ES7210 ADC chip
    107  *
    108  * @param[in] codec_cfg:  configuration of ES7210
    109  *
    110  * @return
    111  *      - ESP_OK
    112  *      - ESP_FAIL
    113  */
    114 esp_err_t es7210_adc_init(TwoWire *tw, audio_hal_codec_config_t *codec_cfg);
    115 
    116 /**
    117  * @brief Deinitialize ES7210 ADC chip
    118  *
    119  * @return
    120  *     - ESP_OK
    121  *     - ESP_FAIL
    122  */
    123 esp_err_t es7210_adc_deinit();
    124 
    125 /**
    126  * @brief Configure ES7210 ADC mode and I2S interface
    127  *
    128  * @param[in] mode:  codec mode
    129  * @param[in] iface:  I2S config
    130  *
    131  * @return
    132  *     - ESP_FAIL Parameter error
    133  *     - ESP_OK   Success
    134  */
    135 esp_err_t es7210_adc_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);
    136 
    137 /**
    138  * @brief Control ES7210 ADC chip
    139  *
    140  * @param[in] mode:  codec mode
    141  * @param[in] ctrl_state:  start or stop progress
    142  *
    143  * @return
    144  *     - ESP_FAIL Parameter error
    145  *     - ESP_OK   Success
    146  */
    147 esp_err_t es7210_adc_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
    148 
    149 /**
    150  * @brief  Set gain of given mask
    151  *
    152  * @param[in] mic_mask Mask of MIC channel
    153  *
    154  * @param[in] gain:  gain
    155  *
    156  *       gain        :   value
    157  *       GAIN_0DB    :   1
    158  *       GAIN_3DB    :   2
    159  *       GAIN_6DB    :   3
    160  *           ·
    161  *           ·
    162  *           ·
    163  *       GAIN_30DB   :   10
    164  *       GAIN_33DB   :   11
    165  *       GAIN_34_5DB :   12
    166  *       GAIN_36DB   :   13
    167  *       GAIN_37_5DB :   14
    168  *
    169  * @return
    170  *     - ESP_OK
    171  *     - ESP_FAIL
    172  */
    173 esp_err_t es7210_adc_set_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t gain);
    174 
    175 /**
    176  * @brief  Set gain (Note: the enabled microphone sets the same gain)
    177  *
    178  * @param[in] gain:  gain
    179  *
    180  *       gain        :   value
    181  *       GAIN_0DB    :   1
    182  *       GAIN_3DB    :   2
    183  *       GAIN_6DB    :   3
    184  *           ·
    185  *           ·
    186  *           ·
    187  *       GAIN_30DB   :   10
    188  *       GAIN_33DB   :   11
    189  *       GAIN_34_5DB :   12
    190  *       GAIN_36DB   :   13
    191  *       GAIN_37_5DB :   14
    192  *
    193  * @return
    194  *     - ESP_OK
    195  *     - ESP_FAIL
    196  */
    197 esp_err_t es7210_adc_set_gain_all(es7210_gain_value_t gain);
    198 
    199 /**
    200  * @brief Get MIC gain
    201  *
    202  * @param mic_mask Selected MIC
    203  * @param gain Pointer to `es7210_gain_value_t`
    204  * @return
    205  *     - ESP_OK
    206  *     - ESP_FAIL
    207  */
    208 esp_err_t es7210_adc_get_gain(es7210_input_mics_t mic_mask, es7210_gain_value_t *gain);
    209 
    210 /**
    211  * @brief Set volume
    212  *
    213  * @param[in] volume:  volume
    214  *
    215  * @return
    216  *     - ESP_OK
    217  */
    218 esp_err_t es7210_adc_set_volume(int volume);
    219 
    220 /**
    221  * @brief Set ES7210 ADC mute status
    222  *
    223  * @return
    224  *     - ESP_FAIL
    225  *     - ESP_OK
    226  */
    227 esp_err_t es7210_set_mute(bool enable);
    228 
    229 /**
    230  * @brief Select ES7210 mic
    231  *
    232  * @param[in] mic:  mics
    233  *
    234  * @return
    235  *     - ESP_FAIL
    236  *     - ESP_OK
    237  */
    238 esp_err_t es7210_mic_select(es7210_input_mics_t mic);
    239 
    240 /**
    241  * @brief Read regs of ES7210
    242  *
    243  * @param[in] reg_addr:  reg_addr
    244  *
    245  * @return
    246  *     - ESP_FAIL
    247  *     - ESP_OK
    248  */
    249 int es7210_read_reg(uint8_t reg_addr);
    250 
    251 /**
    252  * @brief Read all regs of ES7210
    253  */
    254 void es7210_read_all(void);
    255 
    256 #ifdef __cplusplus
    257 }
    258 #endif
    259 
    260 #endif /* _ES7210_H_ */