mirror of https://github.com/arendst/Tasmota.git
commit
324e4e1084
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"build": {
|
||||
"arduino":{
|
||||
"ldscript": "esp32s3_out.ld",
|
||||
"memory_type": "qspi_opi"
|
||||
},
|
||||
"core": "esp32",
|
||||
"extra_flags": "-DBOARD_HAS_PSRAM -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 -DUSE_USB_SERIAL_CONSOLE -DESP32_16M -DESP32S3",
|
||||
"f_cpu": "240000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "dio",
|
||||
"mcu": "esp32s3",
|
||||
"variant": "esp32s3",
|
||||
"partitions": "partitions/esp32_partition_app2944k_fs10M.csv"
|
||||
},
|
||||
"connectivity": [
|
||||
"wifi",
|
||||
"bluetooth",
|
||||
"ethernet"
|
||||
],
|
||||
"debug": {
|
||||
"openocd_target": "esp32s3.cfg"
|
||||
},
|
||||
"frameworks": [
|
||||
"espidf",
|
||||
"arduino"
|
||||
],
|
||||
"name": "Espressif Generic ESP32-S3 16M Flash, Tasmota 2880k Code/OTA, 10M FS",
|
||||
"upload": {
|
||||
"flash_size": "16MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 16777216,
|
||||
"require_upload_port": true,
|
||||
"speed": 460800
|
||||
},
|
||||
"url": "https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/",
|
||||
"vendor": "Espressif"
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
AudioOutputI2S
|
||||
Base class for I2S interface port
|
||||
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -59,10 +59,13 @@ bool AudioOutputI2S::SetPinout()
|
|||
return false; // Not allowed
|
||||
|
||||
i2s_pin_config_t pins = {
|
||||
.mck_io_num = mclkPin,
|
||||
.bck_io_num = bclkPin,
|
||||
.ws_io_num = wclkPin,
|
||||
.data_out_num = doutPin,
|
||||
.data_in_num = I2S_PIN_NO_CHANGE};
|
||||
.data_in_num = dinPin
|
||||
};
|
||||
//.data_in_num = I2S_PIN_NO_CHANGE};
|
||||
i2s_set_pin((i2s_port_t)portNo, &pins);
|
||||
return true;
|
||||
#else
|
||||
|
@ -73,11 +76,15 @@ bool AudioOutputI2S::SetPinout()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout)
|
||||
bool AudioOutputI2S::SetPinout(int bclk, int wclk, int dout, int mclk, int din)
|
||||
{
|
||||
bclkPin = bclk;
|
||||
wclkPin = wclk;
|
||||
doutPin = dout;
|
||||
mclkPin = mclk;
|
||||
dinPin = din;
|
||||
|
||||
|
||||
if (i2sOn)
|
||||
return SetPinout();
|
||||
|
||||
|
@ -178,7 +185,7 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
#if CONFIG_IDF_TARGET_ESP32
|
||||
mode = (i2s_mode_t)(mode | I2S_MODE_DAC_BUILT_IN);
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
else if (output_mode == INTERNAL_PDM)
|
||||
|
@ -186,7 +193,7 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
#if CONFIG_IDF_TARGET_ESP32
|
||||
mode = (i2s_mode_t)(mode | I2S_MODE_PDM);
|
||||
#else
|
||||
return false;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -212,6 +219,14 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
#endif
|
||||
}
|
||||
|
||||
if (mclkPin != I2S_PIN_NO_CHANGE) {
|
||||
use_apll = false;
|
||||
}
|
||||
|
||||
if (dinPin != I2S_PIN_NO_CHANGE) {
|
||||
mode = (i2s_mode_t) (I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_RX);
|
||||
}
|
||||
|
||||
i2s_config_t i2s_config_dac = {
|
||||
.mode = mode,
|
||||
.sample_rate = 44100,
|
||||
|
@ -221,7 +236,12 @@ bool AudioOutputI2S::begin(bool txDAC)
|
|||
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // lowest interrupt priority
|
||||
.dma_buf_count = dma_buf_count,
|
||||
.dma_buf_len = 128,
|
||||
.use_apll = use_apll // Use audio PLL
|
||||
.use_apll = use_apll, // Use audio PLL
|
||||
.tx_desc_auto_clear = true,
|
||||
.fixed_mclk = 0,
|
||||
//.mclk_multiple = I2S_MCLK_MULTIPLE_DEFAULT,
|
||||
.mclk_multiple = I2S_MCLK_MULTIPLE_128,
|
||||
.bits_per_chan = I2S_BITS_PER_CHAN_16BIT,
|
||||
};
|
||||
audioLogger->printf("+%d %p\n", portNo, &i2s_config_dac);
|
||||
if (i2s_driver_install((i2s_port_t)portNo, &i2s_config_dac, 0, NULL) != ESP_OK)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
AudioOutputI2S
|
||||
Base class for an I2S output port
|
||||
|
||||
|
||||
Copyright (C) 2017 Earle F. Philhower, III
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
@ -19,15 +19,21 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP32
|
||||
#include <driver/i2s.h>
|
||||
#endif
|
||||
#include "AudioOutput.h"
|
||||
|
||||
#ifndef I2S_PIN_NO_CHANGE
|
||||
#define I2S_PIN_NO_CHANGE -1
|
||||
#endif
|
||||
|
||||
class AudioOutputI2S : public AudioOutput
|
||||
{
|
||||
public:
|
||||
#if defined(ESP32) || defined(ESP8266)
|
||||
AudioOutputI2S(int port=0, int output_mode=EXTERNAL_I2S, int dma_buf_count = 8, int use_apll=APLL_DISABLE);
|
||||
bool SetPinout(int bclkPin, int wclkPin, int doutPin);
|
||||
bool SetPinout(int bclkPin, int wclkPin, int doutPin, int mclk = I2S_PIN_NO_CHANGE, int din = I2S_PIN_NO_CHANGE);
|
||||
enum : int { APLL_AUTO = -1, APLL_ENABLE = 1, APLL_DISABLE = 0 };
|
||||
enum : int { EXTERNAL_I2S = 0, INTERNAL_DAC = 1, INTERNAL_PDM = 2 };
|
||||
#elif defined(ARDUINO_ARCH_RP2040)
|
||||
|
@ -41,10 +47,10 @@ class AudioOutputI2S : public AudioOutput
|
|||
virtual bool ConsumeSample(int16_t sample[2]) override;
|
||||
virtual void flush() override;
|
||||
virtual bool stop() override;
|
||||
|
||||
|
||||
bool begin(bool txDAC);
|
||||
bool SetOutputModeMono(bool mono); // Force mono output no matter the input
|
||||
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
|
||||
bool SetLsbJustified(bool lsbJustified); // Allow supporting non-I2S chips, e.g. PT8211
|
||||
|
||||
protected:
|
||||
bool SetPinout();
|
||||
|
@ -59,8 +65,10 @@ class AudioOutputI2S : public AudioOutput
|
|||
// We can restore the old values and free up these pins when in NoDAC mode
|
||||
uint32_t orig_bck;
|
||||
uint32_t orig_ws;
|
||||
|
||||
|
||||
uint8_t bclkPin;
|
||||
uint8_t wclkPin;
|
||||
uint8_t doutPin;
|
||||
uint8_t dinPin;
|
||||
uint8_t mclkPin;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "ES7243e",
|
||||
"description": "Audio codec",
|
||||
"keywords": "ESP32, MP3, AAC, WAV, MOD, FLAC, RTTTL, MIDI, I2S, DAC, Delta-Sigma, TTS",
|
||||
"version": "1.0.0",
|
||||
"frameworks": "Arduino"
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name=ES7243e
|
||||
version=1.0
|
||||
author=
|
||||
maintainer=
|
||||
sentence=Audio fcodec for ESP32
|
||||
paragraph=
|
||||
category=Signal Output
|
||||
url=
|
||||
architectures=esp32
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifdef ESP32
|
||||
|
||||
#include <Wire.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include "string.h"
|
||||
#include "esp_log.h"
|
||||
#include "es7243e.h"
|
||||
|
||||
|
||||
static const char *TAG = "DRV7243E";
|
||||
static TwoWire *es7243e_wire;
|
||||
|
||||
static esp_err_t es7243e_write_reg(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
//return i2c_bus_write_byte(i2c_handle, reg_addr, data);
|
||||
es7243e_wire->beginTransmission(ES7243_ADDR);
|
||||
es7243e_wire->write(reg_addr);
|
||||
es7243e_wire->write(data);
|
||||
es7243e_wire->endTransmission();
|
||||
return 0;
|
||||
}
|
||||
|
||||
esp_err_t es7243e_adc_init(TwoWire *tw, audio_hal_codec_config_t *codec_cfg)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
es7243e_wire = tw;
|
||||
|
||||
ret |= es7243e_write_reg(0x01, 0x3A);
|
||||
ret |= es7243e_write_reg(0x00, 0x80);
|
||||
ret |= es7243e_write_reg(0xF9, 0x00);
|
||||
ret |= es7243e_write_reg(0x04, 0x02);
|
||||
ret |= es7243e_write_reg(0x04, 0x01);
|
||||
ret |= es7243e_write_reg(0xF9, 0x01);
|
||||
ret |= es7243e_write_reg(0x00, 0x1E);
|
||||
ret |= es7243e_write_reg(0x01, 0x00);
|
||||
|
||||
ret |= es7243e_write_reg(0x02, 0x00);
|
||||
ret |= es7243e_write_reg(0x03, 0x20);
|
||||
ret |= es7243e_write_reg(0x04, 0x01);
|
||||
ret |= es7243e_write_reg(0x0D, 0x00);
|
||||
ret |= es7243e_write_reg(0x05, 0x00);
|
||||
ret |= es7243e_write_reg(0x06, 0x03); // SCLK=MCLK/4
|
||||
ret |= es7243e_write_reg(0x07, 0x00); // LRCK=MCLK/256
|
||||
ret |= es7243e_write_reg(0x08, 0xFF); // LRCK=MCLK/256
|
||||
|
||||
ret |= es7243e_write_reg(0x09, 0xCA);
|
||||
ret |= es7243e_write_reg(0x0A, 0x85);
|
||||
ret |= es7243e_write_reg(0x0B, 0x00);
|
||||
ret |= es7243e_write_reg(0x0E, 0xBF);
|
||||
ret |= es7243e_write_reg(0x0F, 0x80);
|
||||
ret |= es7243e_write_reg(0x14, 0x0C);
|
||||
ret |= es7243e_write_reg(0x15, 0x0C);
|
||||
ret |= es7243e_write_reg(0x17, 0x02);
|
||||
ret |= es7243e_write_reg(0x18, 0x26);
|
||||
ret |= es7243e_write_reg(0x19, 0x77);
|
||||
ret |= es7243e_write_reg(0x1A, 0xF4);
|
||||
ret |= es7243e_write_reg(0x1B, 0x66);
|
||||
ret |= es7243e_write_reg(0x1C, 0x44);
|
||||
ret |= es7243e_write_reg(0x1E, 0x00);
|
||||
ret |= es7243e_write_reg(0x1F, 0x0C);
|
||||
ret |= es7243e_write_reg(0x20, 0x1E); //PGA gain +30dB
|
||||
ret |= es7243e_write_reg(0x21, 0x1E); //PGA gain +30dB
|
||||
|
||||
ret |= es7243e_write_reg(0x00, 0x80); //Slave Mode
|
||||
ret |= es7243e_write_reg(0x01, 0x3A);
|
||||
ret |= es7243e_write_reg(0x16, 0x3F);
|
||||
ret |= es7243e_write_reg(0x16, 0x00);
|
||||
if (ret) {
|
||||
ESP_LOGE(TAG, "Es7243e initialize failed!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES7243E_H_
|
||||
#define _ES7243E_H_
|
||||
|
||||
#include "audio_hal.h"
|
||||
#include "esp_types.h"
|
||||
#include "esxxx_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ES7243_ADDR 0x10
|
||||
|
||||
/**
|
||||
* @brief Initialize ES7243E adc chip
|
||||
*
|
||||
* @param codec_cfg configuration of ES7243E
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es7243e_adc_init(TwoWire *tw, audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Set gain of given mask
|
||||
*
|
||||
* @param[in] mic_mask Mask of MIC channel
|
||||
*
|
||||
* @param[in] gain: gain
|
||||
*
|
||||
* gain : value
|
||||
* GAIN_0DB : 1
|
||||
* GAIN_3DB : 2
|
||||
* GAIN_6DB : 3
|
||||
* ·
|
||||
* ·
|
||||
* ·
|
||||
* GAIN_30DB : 10
|
||||
* GAIN_33DB : 11
|
||||
* GAIN_34_5DB : 12
|
||||
* GAIN_36DB : 13
|
||||
* GAIN_37_5DB : 14
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
// esp_err_t es7243_adc_set_gain(es7243_input_mics_t mic_mask, es7243_gain_value_t gain);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "ES8156",
|
||||
"description": "Audio codec",
|
||||
"keywords": "ESP8266, ESP32, MP3, AAC, WAV, MOD, FLAC, RTTTL, MIDI, I2S, DAC, Delta-Sigma, TTS",
|
||||
"version": "1.0.0",
|
||||
"frameworks": "Arduino"
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name=ES8156
|
||||
version=1.0
|
||||
author=
|
||||
maintainer=
|
||||
sentence=Audio fcodec for ESP8266, ESP32
|
||||
paragraph=
|
||||
category=Signal Output
|
||||
url=
|
||||
architectures=*
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _AUDIO_HAL_H_
|
||||
#define _AUDIO_HAL_H_
|
||||
|
||||
#define AUDIO_HAL_VOL_DEFAULT 60
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Select media hal codec mode
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_CODEC_MODE_ENCODE = 1, /*!< select adc */
|
||||
AUDIO_HAL_CODEC_MODE_DECODE, /*!< select dac */
|
||||
AUDIO_HAL_CODEC_MODE_BOTH, /*!< select both adc and dac */
|
||||
AUDIO_HAL_CODEC_MODE_LINE_IN, /*!< set adc channel */
|
||||
} audio_hal_codec_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Select adc channel for input mic signal
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_ADC_INPUT_LINE1 = 0x00, /*!< mic input to adc channel 1 */
|
||||
AUDIO_HAL_ADC_INPUT_LINE2, /*!< mic input to adc channel 2 */
|
||||
AUDIO_HAL_ADC_INPUT_ALL, /*!< mic input to both channels of adc */
|
||||
AUDIO_HAL_ADC_INPUT_DIFFERENCE, /*!< mic input to adc difference channel */
|
||||
} audio_hal_adc_input_t;
|
||||
|
||||
/**
|
||||
* @brief Select channel for dac output
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_DAC_OUTPUT_LINE1 = 0x00, /*!< dac output signal to channel 1 */
|
||||
AUDIO_HAL_DAC_OUTPUT_LINE2, /*!< dac output signal to channel 2 */
|
||||
AUDIO_HAL_DAC_OUTPUT_ALL, /*!< dac output signal to both channels */
|
||||
} audio_hal_dac_output_t;
|
||||
|
||||
/**
|
||||
* @brief Select operating mode i.e. start or stop for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_CTRL_STOP = 0x00, /*!< set stop mode */
|
||||
AUDIO_HAL_CTRL_START = 0x01, /*!< set start mode */
|
||||
} audio_hal_ctrl_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface operating mode i.e. master or slave for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_MODE_SLAVE = 0x00, /*!< set slave mode */
|
||||
AUDIO_HAL_MODE_MASTER = 0x01, /*!< set master mode */
|
||||
} audio_hal_iface_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface samples per second
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_08K_SAMPLES, /*!< set to 8k samples per second */
|
||||
AUDIO_HAL_11K_SAMPLES, /*!< set to 11.025k samples per second */
|
||||
AUDIO_HAL_16K_SAMPLES, /*!< set to 16k samples in per second */
|
||||
AUDIO_HAL_22K_SAMPLES, /*!< set to 22.050k samples per second */
|
||||
AUDIO_HAL_24K_SAMPLES, /*!< set to 24k samples in per second */
|
||||
AUDIO_HAL_32K_SAMPLES, /*!< set to 32k samples in per second */
|
||||
AUDIO_HAL_44K_SAMPLES, /*!< set to 44.1k samples per second */
|
||||
AUDIO_HAL_48K_SAMPLES, /*!< set to 48k samples per second */
|
||||
} audio_hal_iface_samples_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface number of bits per sample
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_BIT_LENGTH_16BITS = 1, /*!< set 16 bits per sample */
|
||||
AUDIO_HAL_BIT_LENGTH_24BITS, /*!< set 24 bits per sample */
|
||||
AUDIO_HAL_BIT_LENGTH_32BITS, /*!< set 32 bits per sample */
|
||||
} audio_hal_iface_bits_t;
|
||||
|
||||
/**
|
||||
* @brief Select I2S interface format for audio codec chip
|
||||
*/
|
||||
typedef enum {
|
||||
AUDIO_HAL_I2S_NORMAL = 0, /*!< set normal I2S format */
|
||||
AUDIO_HAL_I2S_LEFT, /*!< set all left format */
|
||||
AUDIO_HAL_I2S_RIGHT, /*!< set all right format */
|
||||
AUDIO_HAL_I2S_DSP, /*!< set dsp/pcm format */
|
||||
} audio_hal_iface_format_t;
|
||||
|
||||
/**
|
||||
* @brief I2s interface configuration for audio codec chip
|
||||
*/
|
||||
typedef struct {
|
||||
audio_hal_iface_mode_t mode; /*!< audio codec chip mode */
|
||||
audio_hal_iface_format_t fmt; /*!< I2S interface format */
|
||||
audio_hal_iface_samples_t samples; /*!< I2S interface samples per second */
|
||||
audio_hal_iface_bits_t bits; /*!< i2s interface number of bits per sample */
|
||||
} audio_hal_codec_i2s_iface_t;
|
||||
|
||||
/**
|
||||
* @brief Configure media hal for initialization of audio codec chip
|
||||
*/
|
||||
typedef struct {
|
||||
audio_hal_adc_input_t adc_input; /*!< set adc channel */
|
||||
audio_hal_dac_output_t dac_output; /*!< set dac channel */
|
||||
audio_hal_codec_mode_t codec_mode; /*!< select codec mode: adc, dac or both */
|
||||
audio_hal_codec_i2s_iface_t i2s_iface; /*!< set I2S interface configuration */
|
||||
} audio_hal_codec_config_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //__AUDIO_HAL_H__
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
#include <Wire.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include "string.h"
|
||||
#include "esp_log.h"
|
||||
#include "es8156.h"
|
||||
|
||||
/*
|
||||
typedef struct {
|
||||
int mck_io_num; //!< MCK in out pin
|
||||
int bck_io_num; //!< BCK in out pin
|
||||
int ws_io_num; //!< WS in out pin
|
||||
int data_out_num; //!< DATA out pin
|
||||
int data_in_num; //!< DATA in pin
|
||||
} i2s_pin_config_t;
|
||||
*/
|
||||
|
||||
static const char *TAG = "es8156";
|
||||
|
||||
static TwoWire *es8156_wire;
|
||||
|
||||
|
||||
static esp_err_t es8156_write_reg(uint8_t reg_addr, uint8_t data)
|
||||
{
|
||||
es8156_wire->beginTransmission(ES8156_ADDR);
|
||||
es8156_wire->write(reg_addr);
|
||||
es8156_wire->write(data);
|
||||
es8156_wire->endTransmission();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint8_t es8156_read_reg(uint8_t reg_addr)
|
||||
{
|
||||
uint8_t data;
|
||||
es8156_wire->beginTransmission(ES8156_ADDR);
|
||||
es8156_wire->write(reg_addr);
|
||||
es8156_wire->endTransmission(false);
|
||||
es8156_wire->requestFrom(ES8156_ADDR, (size_t)1);
|
||||
data = es8156_wire->read();
|
||||
//i2c_bus_read_byte(i2c_handle, reg_addr, &data);
|
||||
return data;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_init(TwoWire *tw, audio_hal_codec_config_t *cfg)
|
||||
{
|
||||
|
||||
es8156_wire = tw;
|
||||
esp_err_t ret_val = ESP_OK;
|
||||
//ret_val |= bsp_i2c_add_device(&i2c_handle, ES8156_ADDR);
|
||||
|
||||
uint8_t misc_ctrl_reg_val = 0x00;
|
||||
uint8_t dac_iface_reg_val = 0x00;
|
||||
|
||||
if (AUDIO_HAL_MODE_MASTER == cfg->i2s_iface.mode) {
|
||||
misc_ctrl_reg_val |= 0b00100000;
|
||||
} else {
|
||||
misc_ctrl_reg_val |= 0b00000000;
|
||||
}
|
||||
|
||||
switch (cfg->i2s_iface.bits) {
|
||||
case AUDIO_HAL_BIT_LENGTH_16BITS:
|
||||
dac_iface_reg_val |= 0b00110000;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_24BITS:
|
||||
dac_iface_reg_val |= 0b00000000;
|
||||
break;
|
||||
case AUDIO_HAL_BIT_LENGTH_32BITS:
|
||||
dac_iface_reg_val |= 0b01000000;
|
||||
break;
|
||||
default: /* Use 32 bit as default */
|
||||
dac_iface_reg_val |= 0b01000000;
|
||||
break;
|
||||
}
|
||||
|
||||
ret_val |= es8156_write_reg(0x09, misc_ctrl_reg_val); // MCLK from pad, Slave mode, power down DLL, enable pin pull up
|
||||
ret_val |= es8156_write_reg(0x11, dac_iface_reg_val); // DAC Interface Config
|
||||
ret_val |= es8156_write_reg(0x14, ES8156_VOL_MIN_3dB); // Set default volume to 0dB
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_deinit(void)
|
||||
{
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_set_voice_mute(bool enable)
|
||||
{
|
||||
int regv = es8156_read_reg(ES8156_DAC_MUTE_REG13);
|
||||
if (enable) {
|
||||
regv = regv | BIT(1) | BIT(2);
|
||||
} else {
|
||||
regv = regv & (~(BIT(1) | BIT(2))) ;
|
||||
}
|
||||
es8156_write_reg(ES8156_DAC_MUTE_REG13, regv);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_set_voice_volume(uint8_t volume)
|
||||
{
|
||||
if (volume > 100) {
|
||||
volume = 100;
|
||||
}
|
||||
uint8_t d = 0xBF - 60 + 6 * volume / 10;
|
||||
if (0 == volume) {
|
||||
d = 0;
|
||||
}
|
||||
return es8156_write_reg(ES8156_VOLUME_CONTROL_REG14, d);
|
||||
}
|
||||
|
||||
esp_err_t es8156_codec_get_voice_volume(uint8_t *volume)
|
||||
{
|
||||
*volume = es8156_read_reg(ES8156_VOLUME_CONTROL_REG14);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t es8156_config_fmt(es_i2s_fmt_t fmt)
|
||||
{
|
||||
ESP_LOGW(TAG, "Not support config format for es8156 now");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_err_t es8156_set_channel(uint8_t is_right)
|
||||
{
|
||||
uint8_t reg = es8156_read_reg(ES8156_DAC_SDP_REG11);
|
||||
if (is_right) {
|
||||
reg |= 0b00000100;
|
||||
} else {
|
||||
reg &= 0b11111011;
|
||||
}
|
||||
return es8156_write_reg(ES8156_DAC_SDP_REG11, reg);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2021 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ES8156_H
|
||||
#define _ES8156_H
|
||||
|
||||
#include "audio_hal.h"
|
||||
#include "esp_types.h"
|
||||
#include "esxxx_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define ES8156_ADDR (0x08)
|
||||
|
||||
/* ES8156 register space */
|
||||
/*
|
||||
* RESET Control
|
||||
*/
|
||||
#define ES8156_RESET_REG00 0x00
|
||||
/*
|
||||
* Clock Managerment
|
||||
*/
|
||||
#define ES8156_MAINCLOCK_CTL_REG01 0x01
|
||||
#define ES8156_SCLK_MODE_REG02 0x02
|
||||
#define ES8156_LRCLK_DIV_H_REG03 0x03
|
||||
#define ES8156_LRCLK_DIV_L_REG04 0x04
|
||||
#define ES8156_SCLK_DIV_REG05 0x05
|
||||
#define ES8156_NFS_CONFIG_REG06 0x06
|
||||
#define ES8156_MISC_CONTROL1_REG07 0x07
|
||||
#define ES8156_CLOCK_ON_OFF_REG08 0x08
|
||||
#define ES8156_MISC_CONTROL2_REG09 0x09
|
||||
#define ES8156_TIME_CONTROL1_REG0A 0x0a
|
||||
#define ES8156_TIME_CONTROL2_REG0B 0x0b
|
||||
/*
|
||||
* System Control
|
||||
*/
|
||||
#define ES8156_CHIP_STATUS_REG0C 0x0c
|
||||
#define ES8156_P2S_CONTROL_REG0D 0x0d
|
||||
#define ES8156_DAC_OSR_COUNTER_REG10 0x10
|
||||
/*
|
||||
* SDP Control
|
||||
*/
|
||||
#define ES8156_DAC_SDP_REG11 0x11
|
||||
#define ES8156_AUTOMUTE_SET_REG12 0x12
|
||||
#define ES8156_DAC_MUTE_REG13 0x13
|
||||
#define ES8156_VOLUME_CONTROL_REG14 0x14
|
||||
|
||||
/*
|
||||
* ALC Control
|
||||
*/
|
||||
#define ES8156_ALC_CONFIG1_REG15 0x15
|
||||
#define ES8156_ALC_CONFIG2_REG16 0x16
|
||||
#define ES8156_ALC_CONFIG3_REG17 0x17
|
||||
#define ES8156_MISC_CONTROL3_REG18 0x18
|
||||
#define ES8156_EQ_CONTROL1_REG19 0x19
|
||||
#define ES8156_EQ_CONTROL2_REG1A 0x1a
|
||||
/*
|
||||
* Analog System Control
|
||||
*/
|
||||
#define ES8156_ANALOG_SYS1_REG20 0x20
|
||||
#define ES8156_ANALOG_SYS2_REG21 0x21
|
||||
#define ES8156_ANALOG_SYS3_REG22 0x22
|
||||
#define ES8156_ANALOG_SYS4_REG23 0x23
|
||||
#define ES8156_ANALOG_LP_REG24 0x24
|
||||
#define ES8156_ANALOG_SYS5_REG25 0x25
|
||||
/*
|
||||
* Chip Information
|
||||
*/
|
||||
#define ES8156_I2C_PAGESEL_REGFC 0xFC
|
||||
#define ES8156_CHIPID1_REGFD 0xFD
|
||||
#define ES8156_CHIPID0_REGFE 0xFE
|
||||
#define ES8156_CHIP_VERSION_REGFF 0xFF
|
||||
|
||||
typedef enum {
|
||||
ES8156_VOL_MIN = 0x00, /*!< -95.5dB */
|
||||
ES8156_VOL_MIN_10dB = 0xAB, /*!< -10dB */
|
||||
ES8156_VOL_MIN_9dB = 0xAD, /*!< -9dB */
|
||||
ES8156_VOL_MIN_6dB = 0xB3, /*!< -6dB */
|
||||
ES8156_VOL_MIN_3dB = 0xB9, /*!< -3dB */
|
||||
ES8156_VOL_0dB = 0xBF, /*!< 0dB */
|
||||
ES8156_VOL_3dB = 0xC5, /*!< +3dB */
|
||||
ES8156_VOL_10dB = 0xD3, /*!< +10dB */
|
||||
ES8156_VOL_MAX = 0xFF, /*!< +32dB */
|
||||
} es8156_volume_t;
|
||||
|
||||
/*
|
||||
* @brief Initialize ES8156 codec chip
|
||||
*
|
||||
* @param codec_cfg configuration of ES8156
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_init(TwoWire *tw, audio_hal_codec_config_t *codec_cfg);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize ES8156 codec chip
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_deinit(void);
|
||||
|
||||
|
||||
esp_err_t es8156_config_fmt(es_i2s_fmt_t fmt);
|
||||
|
||||
/**
|
||||
* @brief Configure ES8156 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 es8156_codec_set_voice_mute(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Set voice volume
|
||||
*
|
||||
* @param volume: voice volume (0~100)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_set_voice_volume(uint8_t volume);
|
||||
|
||||
/**
|
||||
* @brief Get voice volume
|
||||
*
|
||||
* @param[out] *volume: voice volume (0~255)
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t es8156_codec_get_voice_volume(uint8_t *volume);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param is_right
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t es8156_set_channel(uint8_t is_right);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* ESPRESSIF MIT License
|
||||
*
|
||||
* Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
|
||||
*
|
||||
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
|
||||
* it is free of charge, to any person obtaining a copy of this software and associated
|
||||
* documentation files (the "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
|
||||
* to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ESXXX_COMMON_H_
|
||||
#define _ESXXX_COMMON_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
BIT_LENGTH_MIN = -1,
|
||||
BIT_LENGTH_16BITS = 0x03,
|
||||
BIT_LENGTH_18BITS = 0x02,
|
||||
BIT_LENGTH_20BITS = 0x01,
|
||||
BIT_LENGTH_24BITS = 0x00,
|
||||
BIT_LENGTH_32BITS = 0x04,
|
||||
BIT_LENGTH_MAX,
|
||||
} es_bits_length_t;
|
||||
|
||||
typedef enum {
|
||||
MCLK_DIV_MIN = -1,
|
||||
MCLK_DIV_1 = 1,
|
||||
MCLK_DIV_2 = 2,
|
||||
MCLK_DIV_3 = 3,
|
||||
MCLK_DIV_4 = 4,
|
||||
MCLK_DIV_6 = 5,
|
||||
MCLK_DIV_8 = 6,
|
||||
MCLK_DIV_9 = 7,
|
||||
MCLK_DIV_11 = 8,
|
||||
MCLK_DIV_12 = 9,
|
||||
MCLK_DIV_16 = 10,
|
||||
MCLK_DIV_18 = 11,
|
||||
MCLK_DIV_22 = 12,
|
||||
MCLK_DIV_24 = 13,
|
||||
MCLK_DIV_33 = 14,
|
||||
MCLK_DIV_36 = 15,
|
||||
MCLK_DIV_44 = 16,
|
||||
MCLK_DIV_48 = 17,
|
||||
MCLK_DIV_66 = 18,
|
||||
MCLK_DIV_72 = 19,
|
||||
MCLK_DIV_5 = 20,
|
||||
MCLK_DIV_10 = 21,
|
||||
MCLK_DIV_15 = 22,
|
||||
MCLK_DIV_17 = 23,
|
||||
MCLK_DIV_20 = 24,
|
||||
MCLK_DIV_25 = 25,
|
||||
MCLK_DIV_30 = 26,
|
||||
MCLK_DIV_32 = 27,
|
||||
MCLK_DIV_34 = 28,
|
||||
MCLK_DIV_7 = 29,
|
||||
MCLK_DIV_13 = 30,
|
||||
MCLK_DIV_14 = 31,
|
||||
MCLK_DIV_MAX,
|
||||
} es_sclk_div_t;
|
||||
|
||||
typedef enum {
|
||||
LCLK_DIV_MIN = -1,
|
||||
LCLK_DIV_128 = 0,
|
||||
LCLK_DIV_192 = 1,
|
||||
LCLK_DIV_256 = 2,
|
||||
LCLK_DIV_384 = 3,
|
||||
LCLK_DIV_512 = 4,
|
||||
LCLK_DIV_576 = 5,
|
||||
LCLK_DIV_768 = 6,
|
||||
LCLK_DIV_1024 = 7,
|
||||
LCLK_DIV_1152 = 8,
|
||||
LCLK_DIV_1408 = 9,
|
||||
LCLK_DIV_1536 = 10,
|
||||
LCLK_DIV_2112 = 11,
|
||||
LCLK_DIV_2304 = 12,
|
||||
|
||||
LCLK_DIV_125 = 16,
|
||||
LCLK_DIV_136 = 17,
|
||||
LCLK_DIV_250 = 18,
|
||||
LCLK_DIV_272 = 19,
|
||||
LCLK_DIV_375 = 20,
|
||||
LCLK_DIV_500 = 21,
|
||||
LCLK_DIV_544 = 22,
|
||||
LCLK_DIV_750 = 23,
|
||||
LCLK_DIV_1000 = 24,
|
||||
LCLK_DIV_1088 = 25,
|
||||
LCLK_DIV_1496 = 26,
|
||||
LCLK_DIV_1500 = 27,
|
||||
LCLK_DIV_MAX,
|
||||
} es_lclk_div_t;
|
||||
|
||||
typedef enum {
|
||||
D2SE_PGA_GAIN_MIN = -1,
|
||||
D2SE_PGA_GAIN_DIS = 0,
|
||||
D2SE_PGA_GAIN_EN = 1,
|
||||
D2SE_PGA_GAIN_MAX = 2,
|
||||
} es_d2se_pga_t;
|
||||
|
||||
typedef enum {
|
||||
ADC_INPUT_MIN = -1,
|
||||
ADC_INPUT_LINPUT1_RINPUT1 = 0x00,
|
||||
ADC_INPUT_MIC1 = 0x05,
|
||||
ADC_INPUT_MIC2 = 0x06,
|
||||
ADC_INPUT_LINPUT2_RINPUT2 = 0x50,
|
||||
ADC_INPUT_DIFFERENCE = 0xf0,
|
||||
ADC_INPUT_MAX,
|
||||
} es_adc_input_t;
|
||||
|
||||
typedef enum {
|
||||
DAC_OUTPUT_MIN = -1,
|
||||
DAC_OUTPUT_LOUT1 = 0x04,
|
||||
DAC_OUTPUT_LOUT2 = 0x08,
|
||||
DAC_OUTPUT_SPK = 0x09,
|
||||
DAC_OUTPUT_ROUT1 = 0x10,
|
||||
DAC_OUTPUT_ROUT2 = 0x20,
|
||||
DAC_OUTPUT_ALL = 0x3c,
|
||||
DAC_OUTPUT_MAX,
|
||||
} es_dac_output_t;
|
||||
|
||||
typedef enum {
|
||||
MIC_GAIN_MIN = -1,
|
||||
MIC_GAIN_0DB = 0,
|
||||
MIC_GAIN_3DB = 3,
|
||||
MIC_GAIN_6DB = 6,
|
||||
MIC_GAIN_9DB = 9,
|
||||
MIC_GAIN_12DB = 12,
|
||||
MIC_GAIN_15DB = 15,
|
||||
MIC_GAIN_18DB = 18,
|
||||
MIC_GAIN_21DB = 21,
|
||||
MIC_GAIN_24DB = 24,
|
||||
MIC_GAIN_MAX,
|
||||
} es_mic_gain_t;
|
||||
|
||||
typedef enum {
|
||||
ES_MODULE_MIN = -1,
|
||||
ES_MODULE_ADC = 0x01,
|
||||
ES_MODULE_DAC = 0x02,
|
||||
ES_MODULE_ADC_DAC = 0x03,
|
||||
ES_MODULE_LINE = 0x04,
|
||||
ES_MODULE_MAX
|
||||
} es_module_t;
|
||||
|
||||
typedef enum {
|
||||
ES_MODE_MIN = -1,
|
||||
ES_MODE_SLAVE = 0x00,
|
||||
ES_MODE_MASTER = 0x01,
|
||||
ES_MODE_MAX,
|
||||
} es_mode_t;
|
||||
|
||||
typedef enum {
|
||||
ES_I2S_MIN = -1,
|
||||
ES_I2S_NORMAL = 0,
|
||||
ES_I2S_LEFT = 1,
|
||||
ES_I2S_RIGHT = 2,
|
||||
ES_I2S_DSP = 3,
|
||||
ES_I2S_MAX
|
||||
} es_i2s_fmt_t;
|
||||
|
||||
/**
|
||||
* @brief Configure ES8388 clock
|
||||
*/
|
||||
typedef struct {
|
||||
es_sclk_div_t sclk_div; /*!< bits clock divide */
|
||||
es_lclk_div_t lclk_div; /*!< WS clock divide */
|
||||
} es_i2s_clock_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -62,6 +62,7 @@ uDisplay::uDisplay(char *lp) : Renderer(800, 600) {
|
|||
sa_mode = 16;
|
||||
saw_3 = 0xff;
|
||||
dim_op = 0xff;
|
||||
bpmode = 0;
|
||||
dsp_off = 0xff;
|
||||
dsp_on = 0xff;
|
||||
lutpsize = 0;
|
||||
|
@ -305,6 +306,9 @@ uDisplay::uDisplay(char *lp) : Renderer(800, 600) {
|
|||
rotmap_ymin = next_val(&lp1);
|
||||
rotmap_ymax = next_val(&lp1);
|
||||
break;
|
||||
case 'b':
|
||||
bpmode = next_val(&lp1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1344,7 +1348,7 @@ void uDisplay::DisplayOnff(int8_t on) {
|
|||
pwr_cbp(on);
|
||||
}
|
||||
|
||||
// udisp_bpwr(on);
|
||||
#define AW_PWMRES 1024
|
||||
|
||||
if (interface == _UDSP_I2C) {
|
||||
if (on) {
|
||||
|
@ -1357,10 +1361,17 @@ void uDisplay::DisplayOnff(int8_t on) {
|
|||
if (dsp_on != 0xff) spi_command_one(dsp_on);
|
||||
if (bpanel >= 0) {
|
||||
#ifdef ESP32
|
||||
analogWrite(bpanel, dimmer10_gamma);
|
||||
// ledcWrite(ESP32_PWM_CHANNEL, dimmer8_gamma);
|
||||
if (!bpmode) {
|
||||
analogWrite(bpanel, dimmer10_gamma);
|
||||
} else {
|
||||
analogWrite(bpanel, AW_PWMRES - dimmer10_gamma);
|
||||
}
|
||||
#else
|
||||
digitalWrite(bpanel, HIGH);
|
||||
if (!bpmode) {
|
||||
digitalWrite(bpanel, HIGH);
|
||||
} else {
|
||||
digitalWrite(bpanel, LOW);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1368,10 +1379,17 @@ void uDisplay::DisplayOnff(int8_t on) {
|
|||
if (dsp_off != 0xff) spi_command_one(dsp_off);
|
||||
if (bpanel >= 0) {
|
||||
#ifdef ESP32
|
||||
analogWrite(bpanel, 0);
|
||||
// ledcWrite(ESP32_PWM_CHANNEL, 0);
|
||||
if (!bpmode) {
|
||||
analogWrite(bpanel, 0);
|
||||
} else {
|
||||
analogWrite(bpanel, AW_PWMRES - 1);
|
||||
}
|
||||
#else
|
||||
digitalWrite(bpanel, LOW);
|
||||
if (!bpmode) {
|
||||
digitalWrite(bpanel, LOW);
|
||||
} else {
|
||||
digitalWrite(bpanel, HIGH);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -1417,7 +1435,12 @@ void uDisplay::dim10(uint8_t dim, uint16_t dim_gamma) { // dimmer with
|
|||
|
||||
#ifdef ESP32 // TODO should we also add a ESP8266 version for bpanel?
|
||||
if (bpanel >= 0) { // is the BaclPanel GPIO configured
|
||||
analogWrite(bpanel, dimmer10_gamma);
|
||||
if (!bpmode) {
|
||||
analogWrite(bpanel, dimmer10_gamma);
|
||||
} else {
|
||||
analogWrite(bpanel, AW_PWMRES - dimmer10_gamma);
|
||||
}
|
||||
|
||||
// ledcWrite(ESP32_PWM_CHANNEL, dimmer8_gamma);
|
||||
} else if (dim_cbp) {
|
||||
dim_cbp(dim);
|
||||
|
|
|
@ -176,6 +176,7 @@ class uDisplay : public Renderer {
|
|||
uint16_t bg_col;
|
||||
uint16_t gxs;
|
||||
uint16_t gys;
|
||||
int8_t bpmode;
|
||||
int8_t spi_cs;
|
||||
int8_t spi_clk;
|
||||
int8_t spi_mosi;
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
:H,ILI9342,320,240,16,SPI,2,*,*,*,*,*,*,*,80
|
||||
:S,2,1,3,0,100,100
|
||||
:I
|
||||
EF,3,03,80,02
|
||||
CF,3,00,C1,30
|
||||
ED,4,64,03,12,81
|
||||
E8,3,85,00,78
|
||||
CB,5,39,2C,00,34,02
|
||||
F7,1,20
|
||||
EA,2,00,00
|
||||
C0,1,23
|
||||
C1,1,10
|
||||
C5,2,3e,28
|
||||
C7,1,86
|
||||
36,1,48
|
||||
37,1,00
|
||||
3A,1,55
|
||||
B1,2,00,18
|
||||
B6,3,08,82,27
|
||||
F2,1,00
|
||||
26,1,01
|
||||
E0,0F,0F,31,2B,0C,0E,08,4E,F1,37,07,10,03,0E,09,00
|
||||
E1,0F,00,0E,14,03,11,07,31,C1,48,08,0F,0C,31,36,0F
|
||||
21,80
|
||||
11,80
|
||||
29,80
|
||||
:o,28
|
||||
:O,29
|
||||
:A,2A,2B,2C,16
|
||||
:R,36
|
||||
:0,48,00,00,00
|
||||
:1,28,00,00,01
|
||||
:2,88,00,00,02
|
||||
:3,E8,00,00,03
|
||||
:i,21,20
|
||||
:b,01
|
||||
#
|
|
@ -0,0 +1,56 @@
|
|||
|
||||
#ifdef ESP32
|
||||
#ifdef ESP32S3_BOX
|
||||
#include <driver/i2s.h>
|
||||
#include <es8156.h>
|
||||
#include <es7243e.h>
|
||||
|
||||
void S3boxAudioPower(uint8_t pwr) {
|
||||
pinMode(46 , OUTPUT);
|
||||
digitalWrite(46, pwr);
|
||||
}
|
||||
|
||||
uint32_t ES8156_init() {
|
||||
uint32_t ret_val = ESP_OK;
|
||||
|
||||
if (I2cSetDevice(ES8156_ADDR, 1)) {
|
||||
I2cSetActiveFound(ES8156_ADDR, "ES8156-I2C", 1);
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.i2s_iface = {
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
}
|
||||
};
|
||||
ret_val |= es8156_codec_init(&Wire1, &cfg);
|
||||
ret_val |= es8156_codec_set_voice_volume(75);
|
||||
}
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
uint32_t es7243e_init() {
|
||||
uint32_t ret_val = ESP_OK;
|
||||
|
||||
if (I2cSetDevice(ES7243_ADDR, 1)) {
|
||||
I2cSetActiveFound(ES7243_ADDR, "ES7243e-I2C", 1);
|
||||
}
|
||||
|
||||
audio_hal_codec_config_t cfg = {
|
||||
.i2s_iface = {
|
||||
.mode = AUDIO_HAL_MODE_SLAVE,
|
||||
.bits = AUDIO_HAL_BIT_LENGTH_16BITS,
|
||||
}
|
||||
};
|
||||
|
||||
ret_val |= es8156_codec_init(&Wire1, &cfg);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
void S3boxInit() {
|
||||
if (TasmotaGlobal.i2c_enabled_2) {
|
||||
ES8156_init();
|
||||
es7243e_init();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -17,7 +17,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if (defined(USE_I2S_AUDIO) || defined(USE_TTGO_WATCH) || defined(USE_M5STACK_CORE2))
|
||||
#if (defined(USE_I2S_AUDIO) || defined(USE_TTGO_WATCH) || defined(USE_M5STACK_CORE2) || defined(ESP32S3_BOX))
|
||||
/*********************************************************************************************\
|
||||
* I2S support using an external DAC or a speaker connected to GPIO03 using a transistor
|
||||
*
|
||||
|
@ -54,6 +54,10 @@
|
|||
#include "AudioFileSourceBuffer.h"
|
||||
#include "AudioGeneratorAAC.h"
|
||||
|
||||
#ifdef ESP32
|
||||
#include <driver/i2s.h>
|
||||
#endif
|
||||
|
||||
#undef AUDIO_PWR_ON
|
||||
#undef AUDIO_PWR_OFF
|
||||
#define AUDIO_PWR_ON
|
||||
|
@ -79,6 +83,24 @@
|
|||
#define DAC_IIS_DOUT 2
|
||||
#endif // USE_M5STACK_CORE2
|
||||
|
||||
|
||||
#ifdef ESP32S3_BOX
|
||||
#undef AUDIO_PWR_ON
|
||||
#undef AUDIO_PWR_OFF
|
||||
#define AUDIO_PWR_ON S3boxAudioPower(true);
|
||||
#define AUDIO_PWR_OFF S3boxAudioPower(false);
|
||||
|
||||
#undef DAC_IIS_BCK
|
||||
#undef DAC_IIS_WS
|
||||
#undef DAC_IIS_DOUT
|
||||
#define DAC_IIS_BCK 17
|
||||
#define DAC_IIS_WS 47
|
||||
#define DAC_IIS_DOUT 15
|
||||
#define DAC_IIS_DIN 16
|
||||
#define DAC_IIS_MCLK 2
|
||||
|
||||
#endif // ESP32S3_BOX
|
||||
|
||||
AudioGeneratorMP3 *mp3 = nullptr;
|
||||
AudioFileSourceFS *file;
|
||||
#ifdef USE_I2S_NO_DAC
|
||||
|
@ -264,8 +286,14 @@ void I2S_Init(void) {
|
|||
out = new AudioOutputI2S();
|
||||
#endif // USE_I2S_NO_DAC
|
||||
#ifdef ESP32
|
||||
#ifdef ESP32S3_BOX
|
||||
S3boxInit();
|
||||
out->SetPinout(DAC_IIS_BCK, DAC_IIS_WS, DAC_IIS_DOUT, DAC_IIS_MCLK, DAC_IIS_DIN);
|
||||
#else
|
||||
out->SetPinout(DAC_IIS_BCK, DAC_IIS_WS, DAC_IIS_DOUT);
|
||||
#endif
|
||||
#endif // ESP32
|
||||
|
||||
#else
|
||||
#ifdef USE_I2S_NO_DAC
|
||||
out = new AudioOutputI2SNoDAC();
|
||||
|
@ -307,8 +335,6 @@ void I2S_Init(void) {
|
|||
//#define MICSRATE 44100
|
||||
#define MICSRATE 16000
|
||||
|
||||
#include <driver/i2s.h>
|
||||
|
||||
uint32_t SpeakerMic(uint8_t spkr) {
|
||||
esp_err_t err = ESP_OK;
|
||||
|
||||
|
@ -469,6 +495,7 @@ void mp3_task(void *arg) {
|
|||
if (!mp3->loop()) {
|
||||
mp3->stop();
|
||||
mp3_delete();
|
||||
out->stop();
|
||||
if (mp3_task_h) {
|
||||
vTaskDelete(mp3_task_h);
|
||||
mp3_task_h = 0;
|
||||
|
@ -610,6 +637,10 @@ void Play_mp3(const char *path) {
|
|||
if (decoder || mp3) return;
|
||||
if (!out) return;
|
||||
|
||||
if (!ufsp->exists(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool I2S_Task;
|
||||
|
||||
AUDIO_PWR_ON
|
||||
|
@ -641,6 +672,7 @@ void Play_mp3(const char *path) {
|
|||
}
|
||||
OsWatchLoop();
|
||||
}
|
||||
out->stop();
|
||||
mp3_delete();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue