Skip to content

Commit

Permalink
sync to lattest esp-adf
Browse files Browse the repository at this point in the history
  • Loading branch information
d3v1c3nv11 committed Mar 11, 2020
1 parent 2805bda commit 8e2d363
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 299 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ https://www.olimex.com/Products/IoT/ESP32/ESP32-ADF/open-source-hardware
![ESP32-ADF](https://olimex.files.wordpress.com/2019/08/esp32-adf-sip1.jpg?w=535)

# Get ESP-ADF

Install requared packages:

```bash
sudo apt-get install git wget flex bison gperf python python-pip python-setuptools python-serial python-click python-cryptography python-future python-pyparsing python-pyelftools cmake ninja-build ccache libffi-dev libssl-dev
```

Download and install esp-adf:

```bash
cd ~/
git clone https://github.com/espressif/esp-adf.git
git clone --recursive https://github.com/espressif/esp-adf.git
cd esp-adf
git checkout tags/v2.0-beta1-55-g9bcaec2
git submodule update --init
export ADF_PATH=~/esp-adf
export ADF_PATH=$PWD
cd esp-idf
./install.sh
. ./export.sh
```


## Usage

Prepare the audio board:
Expand All @@ -28,6 +38,8 @@ Prepare the audio board:

Load the example:
```bash
mkdir ~/espwork
cd ~/espwork
git clone --recursive https://github.com/d3v1c3nv11/sip_phone_example.git
cd sip_phone_example
git submodule update --init
Expand Down
1 change: 1 addition & 0 deletions components/audio_board/olimex_esp32_adf_b/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "esp_log.h"
#include "board.h"
#include "board_def.h"
#include "audio_mem.h"

#include "periph_sdcard.h"
Expand Down
7 changes: 5 additions & 2 deletions components/audio_board/olimex_esp32_adf_b/board_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef _AUDIO_BOARD_DEFINITION_H_
#define _AUDIO_BOARD_DEFINITION_H_

extern int orientation;

// === Screen orientation constants ===
#define PORTRAIT 0
#define LANDSCAPE 1
Expand All @@ -46,7 +46,8 @@ extern int orientation;
#define HEADPHONE_DETCET -1 //GPIO_NUM_19
#define PA_ENABLE_GPIO -1 //GPIO_NUM_21

#define GREEN_LED_GPIO GPIO_NUM_22
#define GREEN_LED_GPIO GPIO_NUM_22
#define IR_RED_RXD GPIO_NUM_4

#define SPI_PORT HSPI_HOST
#define DISP_SPI_MOSI 2
Expand All @@ -59,6 +60,8 @@ extern int orientation;
#define I2C_SDA 18
#define I2C_SCL 23

#define UARTTX GPIO_NUM_12
#define UARTRX 34
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config

spi_device_interface_config->spics_io_num = GPIO_NUM_21;

ESP_LOGW(TAG, "SPI interface is not supported");
ESP_LOGW(TAG, "SPI interface is supported by UEXT");
return ESP_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion components/audio_board/olimex_esp32_adf_c/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "esp_log.h"
#include "board.h"
#include "board_def.h"
#include "audio_mem.h"

#include "periph_sdcard.h"
Expand Down Expand Up @@ -127,4 +128,3 @@ esp_err_t audio_board_deinit(audio_board_handle_t audio_board)
board_handle = NULL;
return ret;
}

7 changes: 5 additions & 2 deletions components/audio_board/olimex_esp32_adf_c/board_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#define SDCARD_OPEN_FILE_NUM_MAX 5
#define SDCARD_INTR_GPIO -1 //GPIO_NUM_34


#define BUTTON_REC_ID GPIO_NUM_36
#define BUTTON_MODE_ID GPIO_NUM_39
#define BUTTON_SET_ID TOUCH_PAD_NUM9
Expand All @@ -47,7 +46,8 @@
#define HEADPHONE_DETCET -1 //GPIO_NUM_19
#define PA_ENABLE_GPIO -1 //GPIO_NUM_21

#define GREEN_LED_GPIO GPIO_NUM_2
#define GREEN_LED_GPIO GPIO_NUM_2
#define IR_RED_RXD GPIO_NUM_22

#define SPI_PORT HSPI_HOST
#define DISP_SPI_MOSI 13
Expand All @@ -58,7 +58,10 @@
#define ILI9341_BCKL -1
#define I2C_PORT I2C_NUM_0
#define I2C_SDA 18
#define I2C_SCL 23

#define UARTTX GPIO_NUM_19
#define UARTRX 34
#define AUDIO_CODEC_DEFAULT_CONFIG(){ \
.adc_input = AUDIO_HAL_ADC_INPUT_LINE1, \
.dac_output = AUDIO_HAL_DAC_OUTPUT_ALL, \
Expand Down
33 changes: 23 additions & 10 deletions components/audio_hal/audio_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,6 @@ esp_err_t audio_hal_config_iface(audio_hal_handle_t audio_hal, audio_hal_codec_m
return ret;
}

esp_err_t audio_hal_set_mute(audio_hal_handle_t audio_hal, bool mute)
{
esp_err_t ret;
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
mutex_lock(audio_hal->audio_hal_lock);
ret = audio_hal->audio_codec_set_mute(mute);
mutex_unlock(audio_hal->audio_hal_lock);
return ret;
}

esp_err_t audio_hal_set_volume(audio_hal_handle_t audio_hal, int volume)
{
esp_err_t ret;
Expand All @@ -134,3 +124,26 @@ esp_err_t audio_hal_get_volume(audio_hal_handle_t audio_hal, int *volume)
mutex_unlock(audio_hal->audio_hal_lock);
return ret;
}

esp_err_t audio_hal_write_reg(audio_hal_handle_t audio_hal,int reg_add, int data)
{
esp_err_t ret;
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
mutex_lock(audio_hal->audio_hal_lock);
ret = audio_hal->audio_codec_write_reg(reg_add, data);
mutex_unlock(audio_hal->audio_hal_lock);
return ret;
}

esp_err_t audio_hal_read_reg(audio_hal_handle_t audio_hal, int reg_add, int *data)
{
esp_err_t ret;
uint8_t reg = 0;
uint8_t ddata = 0;
AUDIO_HAL_CHECK_NULL(audio_hal, "audio_hal handle is null", -1);
mutex_lock(audio_hal->audio_hal_lock);
ret = audio_hal->audio_codec_read_reg(reg_add, ddata);
*data = ddata;
mutex_unlock(audio_hal->audio_hal_lock);
return ret;
}
7 changes: 0 additions & 7 deletions components/audio_hal/driver/es7243/es7243.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ audio_hal_func_t AUDIO_CODEC_ES7243_DEFAULT_HANDLE = {
.audio_codec_deinitialize = es7243_adc_deinit,
.audio_codec_ctrl = es7243_adc_ctrl_state,
.audio_codec_config_iface = es7243_adc_config_i2s,
.audio_codec_set_mute = es7243_adc_set_voice_mute,
.audio_codec_set_volume = es7243_adc_set_voice_volume,
.audio_codec_get_volume = es7243_adc_get_voice_volume,
};
Expand Down Expand Up @@ -122,12 +121,6 @@ esp_err_t es7243_adc_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s
return ESP_OK;
}

esp_err_t es7243_adc_set_voice_mute(bool mute)
{
/* Not implemented yet */
return ESP_OK;
}

esp_err_t es7243_adc_set_voice_volume(int volume)
{
esp_err_t ret = ESP_OK;
Expand Down
11 changes: 0 additions & 11 deletions components/audio_hal/driver/es7243/es7243.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ esp_err_t es7243_adc_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ct
*/
esp_err_t es7243_adc_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);

/**
* @brief Set mute
*
* @param mute true, false
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es7243_adc_set_voice_mute(bool mute);

/**
* @brief Set adc gain
*
Expand Down
3 changes: 1 addition & 2 deletions components/audio_hal/driver/es8311/es8311.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ audio_hal_func_t AUDIO_CODEC_ES8311_DEFAULT_HANDLE = {
.audio_codec_deinitialize = es8311_codec_deinit,
.audio_codec_ctrl = es8311_codec_ctrl_state,
.audio_codec_config_iface = es8311_codec_config_i2s,
.audio_codec_set_mute = es8311_set_voice_mute,
.audio_codec_set_volume = es8311_codec_set_voice_volume,
.audio_codec_get_volume = es8311_codec_get_voice_volume,
};
Expand Down Expand Up @@ -713,7 +712,7 @@ int es8311_codec_get_voice_volume(int *volume)
return res;
}

esp_err_t es8311_set_voice_mute(bool enable)
int es8311_set_voice_mute(int enable)
{
int res = 0;
ESP_LOGD(TAG, "Es8311SetVoiceMute volume:%d", enable);
Expand Down
13 changes: 1 addition & 12 deletions components/audio_hal/driver/es8311/es8311.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef enum {
* @brief Initialize ES8311 codec chip
*
* @param codec_cfg configuration of ES8311
*
*
* @return
* - ESP_OK
* - ESP_FAIL
Expand Down Expand Up @@ -155,17 +155,6 @@ esp_err_t es8311_codec_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t
*/
esp_err_t es8311_codec_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);

/**
* @brief Configure ES8311 DAC mute or not. Basically you can use this function to mute the output or unmute
*
* @param enable enable(1) or disable(0)
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8311_set_voice_mute(bool enable);

/**
* @brief Set voice volume
*
Expand Down
3 changes: 1 addition & 2 deletions components/audio_hal/driver/es8374/es8374.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ audio_hal_func_t AUDIO_CODEC_ES8374_DEFAULT_HANDLE = {
.audio_codec_deinitialize = es8374_codec_deinit,
.audio_codec_ctrl = es8374_codec_ctrl_state,
.audio_codec_config_iface = es8374_codec_config_i2s,
.audio_codec_set_mute = es8374_set_voice_mute,
.audio_codec_set_volume = es8374_codec_set_voice_volume,
.audio_codec_get_volume = es8374_codec_get_voice_volume,
};
Expand Down Expand Up @@ -142,7 +141,7 @@ void es8374_read_all()
}
}

esp_err_t es8374_set_voice_mute(bool enable)
int es8374_set_voice_mute(int enable)
{
int res = 0;
uint8_t reg = 0;
Expand Down
2 changes: 1 addition & 1 deletion components/audio_hal/driver/es8374/es8374.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ esp_err_t es8374_codec_get_voice_volume(int *volume);
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_set_voice_mute(bool enable);
esp_err_t es8374_set_voice_mute(int enable);

/**
* @brief Get ES8374 DAC mute status
Expand Down
26 changes: 12 additions & 14 deletions components/audio_hal/driver/es8388/es8388.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
#include "es8388.h"
#include "board_pins_config.h"

#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
#include "headphone_detect.h"
#endif

static const char *ES_TAG = "ES8388_DRIVER";

#define ES_ASSERT(a, format, b, ...) \
Expand All @@ -52,9 +48,10 @@ audio_hal_func_t AUDIO_CODEC_ES8388_DEFAULT_HANDLE = {
.audio_codec_deinitialize = es8388_deinit,
.audio_codec_ctrl = es8388_ctrl_state,
.audio_codec_config_iface = es8388_config_i2s,
.audio_codec_set_mute = es8388_set_voice_mute,
.audio_codec_set_volume = es8388_set_voice_volume,
.audio_codec_get_volume = es8388_get_voice_volume,
.audio_codec_write_reg = es8388_write_reg,
.audio_codec_read_reg = es8388_read_reg,
};

static int es_write_reg(uint8_t slave_add, uint8_t reg_add, uint8_t data)
Expand Down Expand Up @@ -94,6 +91,7 @@ static int es_read_reg(uint8_t reg_add, uint8_t *pData)
i2c_cmd_link_delete(cmd);

ES_ASSERT(res, "es_read_reg error", -1);
// printf("es8388 read byte 0x%02x: 0x%02x\r\n",reg_add,data);
*pData = data;
return res;
}
Expand All @@ -116,7 +114,10 @@ void es8388_read_all()
ets_printf("%x: %x\n", i, reg);
}
}

int es8388_read_reg(uint8_t reg_add, uint8_t *data)
{
return es_read_reg(reg_add, &data);
}
int es8388_write_reg(uint8_t reg_add, uint8_t data)
{
return es_write_reg(ES8388_ADDR, reg_add, data);
Expand Down Expand Up @@ -262,11 +263,6 @@ esp_err_t es8388_deinit(void)
{
int res = 0;
res = es_write_reg(ES8388_ADDR, ES8388_CHIPPOWER, 0xFF); //reset and stop es8388
i2c_driver_delete(I2C_NUM_0);
#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
headphone_detect_deinit();
#endif

return res;
}

Expand All @@ -279,6 +275,7 @@ esp_err_t es8388_init(audio_hal_codec_config_t *cfg)
{
int res = 0;
#ifdef CONFIG_ESP_LYRAT_V4_3_BOARD
#include "headphone_detect.h"
headphone_detect_init(get_headphone_detect_gpio());
#endif

Expand Down Expand Up @@ -383,7 +380,6 @@ int es8388_set_voice_volume(int volume)
res |= es_write_reg(ES8388_ADDR, ES8388_DACCONTROL27, volume);
return res;
}

/**
*
* @return
Expand Down Expand Up @@ -435,15 +431,15 @@ int es8388_set_bits_per_sample(es_module_t mode, es_bits_length_t bits_length)
}

/**
* @brief Configure ES8388 DAC mute or not. Basically you can use this function to mute the output or unmute
* @brief Configure ES8388 DAC mute or not. Basicly you can use this function to mute the output or don't
*
* @param enable: enable or disable
*
* @return
* - (-1) Parameter error
* - (0) Success
*/
int es8388_set_voice_mute(bool enable)
int es8388_set_voice_mute(int enable)
{
int res;
uint8_t reg = 0;
Expand Down Expand Up @@ -562,6 +558,7 @@ int es8388_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *

void es8388_pa_power(bool enable)
{
/*
gpio_config_t io_conf;
memset(&io_conf, 0, sizeof(io_conf));
io_conf.intr_type = GPIO_PIN_INTR_DISABLE;
Expand All @@ -575,4 +572,5 @@ void es8388_pa_power(bool enable)
} else {
gpio_set_level(get_pa_enable_gpio(), 0);
}
* */
}
Loading

0 comments on commit 8e2d363

Please sign in to comment.