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

audio_hal.h (5143B)

      1 /*
      2  * ESPRESSIF MIT License
      3  *
      4  * Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE 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 _AUDIO_HAL_H_
     26 #define _AUDIO_HAL_H_
     27 
     28 #define AUDIO_HAL_VOL_DEFAULT 60
     29 
     30 #ifdef __cplusplus
     31 extern "C" {
     32 #endif
     33 
     34 /**
     35  * @brief Select media hal codec mode
     36  */
     37 typedef enum {
     38     AUDIO_HAL_CODEC_MODE_ENCODE = 1,  /*!< select adc */
     39     AUDIO_HAL_CODEC_MODE_DECODE,      /*!< select dac */
     40     AUDIO_HAL_CODEC_MODE_BOTH,        /*!< select both adc and dac */
     41     AUDIO_HAL_CODEC_MODE_LINE_IN,     /*!< set adc channel */
     42 } audio_hal_codec_mode_t;
     43 
     44 /**
     45  * @brief Select adc channel for input mic signal
     46  */
     47 typedef enum {
     48     AUDIO_HAL_ADC_INPUT_LINE1 = 0x00,  /*!< mic input to adc channel 1 */
     49     AUDIO_HAL_ADC_INPUT_LINE2,         /*!< mic input to adc channel 2 */
     50     AUDIO_HAL_ADC_INPUT_ALL,           /*!< mic input to both channels of adc */
     51     AUDIO_HAL_ADC_INPUT_DIFFERENCE,    /*!< mic input to adc difference channel */
     52 } audio_hal_adc_input_t;
     53 
     54 /**
     55  * @brief Select channel for dac output
     56  */
     57 typedef enum {
     58     AUDIO_HAL_DAC_OUTPUT_LINE1 = 0x00,  /*!< dac output signal to channel 1 */
     59     AUDIO_HAL_DAC_OUTPUT_LINE2,         /*!< dac output signal to channel 2 */
     60     AUDIO_HAL_DAC_OUTPUT_ALL,           /*!< dac output signal to both channels */
     61 } audio_hal_dac_output_t;
     62 
     63 /**
     64  * @brief Select operating mode i.e. start or stop for audio codec chip
     65  */
     66 typedef enum {
     67     AUDIO_HAL_CTRL_STOP  = 0x00,  /*!< set stop mode */
     68     AUDIO_HAL_CTRL_START = 0x01,  /*!< set start mode */
     69 } audio_hal_ctrl_t;
     70 
     71 /**
     72  * @brief Select I2S interface operating mode i.e. master or slave for audio codec chip
     73  */
     74 typedef enum {
     75     AUDIO_HAL_MODE_SLAVE = 0x00,   /*!< set slave mode */
     76     AUDIO_HAL_MODE_MASTER = 0x01,  /*!< set master mode */
     77 } audio_hal_iface_mode_t;
     78 
     79 /**
     80  * @brief Select I2S interface samples per second
     81  */
     82 typedef enum {
     83     AUDIO_HAL_08K_SAMPLES,   /*!< set to  8k samples per second */
     84     AUDIO_HAL_11K_SAMPLES,   /*!< set to 11.025k samples per second */
     85     AUDIO_HAL_16K_SAMPLES,   /*!< set to 16k samples in per second */
     86     AUDIO_HAL_22K_SAMPLES,   /*!< set to 22.050k samples per second */
     87     AUDIO_HAL_24K_SAMPLES,   /*!< set to 24k samples in per second */
     88     AUDIO_HAL_32K_SAMPLES,   /*!< set to 32k samples in per second */
     89     AUDIO_HAL_44K_SAMPLES,   /*!< set to 44.1k samples per second */
     90     AUDIO_HAL_48K_SAMPLES,   /*!< set to 48k samples per second */
     91 } audio_hal_iface_samples_t;
     92 
     93 /**
     94  * @brief Select I2S interface number of bits per sample
     95  */
     96 typedef enum {
     97     AUDIO_HAL_BIT_LENGTH_16BITS = 1,   /*!< set 16 bits per sample */
     98     AUDIO_HAL_BIT_LENGTH_24BITS,       /*!< set 24 bits per sample */
     99     AUDIO_HAL_BIT_LENGTH_32BITS,       /*!< set 32 bits per sample */
    100 } audio_hal_iface_bits_t;
    101 
    102 /**
    103  * @brief Select I2S interface format for audio codec chip
    104  */
    105 typedef enum {
    106     AUDIO_HAL_I2S_NORMAL = 0,  /*!< set normal I2S format */
    107     AUDIO_HAL_I2S_LEFT,        /*!< set all left format */
    108     AUDIO_HAL_I2S_RIGHT,       /*!< set all right format */
    109     AUDIO_HAL_I2S_DSP,         /*!< set dsp/pcm format */
    110 } audio_hal_iface_format_t;
    111 
    112 /**
    113  * @brief I2s interface configuration for audio codec chip
    114  */
    115 typedef struct {
    116     audio_hal_iface_mode_t mode;        /*!< audio codec chip mode */
    117     audio_hal_iface_format_t fmt;       /*!< I2S interface format */
    118     audio_hal_iface_samples_t samples;  /*!< I2S interface samples per second */
    119     audio_hal_iface_bits_t bits;        /*!< i2s interface number of bits per sample */
    120 } audio_hal_codec_i2s_iface_t;
    121 
    122 /**
    123  * @brief Configure media hal for initialization of audio codec chip
    124  */
    125 typedef struct {
    126     audio_hal_adc_input_t adc_input;       /*!< set adc channel */
    127     audio_hal_dac_output_t dac_output;     /*!< set dac channel */
    128     audio_hal_codec_mode_t codec_mode;     /*!< select codec mode: adc, dac or both */
    129     audio_hal_codec_i2s_iface_t i2s_iface; /*!< set I2S interface configuration */
    130 } audio_hal_codec_config_t;
    131 
    132 #ifdef __cplusplus
    133 }
    134 #endif
    135 
    136 #endif //__AUDIO_HAL_H__