8000 Yj/feat support dnesp32 s3 box es8311 by shiliu-yang · Pull Request #181 · tuya/TuyaOpen · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Yj/feat support dnesp32 s3 box es8311 #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 78 additions & 16 deletions boards/ESP32/DNESP32S3-BOX/DNESP32S3-BOX.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,88 @@

#include "tal_api.h"

#if USE_8311
#include "tdd_audio_8311_codec.h"
#else
#include "tdd_audio_atk_no_codec.h"
#endif

#include "board_config.h"
#include "lcd_st7789_80.h"
#include "board_com_api.h"

#include "xl9555.h"

#include "tdd_audio_8311_codec.h"
#include "tdd_audio_atk_no_codec.h"

/***********************************************************
************************macro define************************
***********************************************************/

/***********************************************************
***********************typedef define***********************
***********************************************************/
typedef struct {
uint8_t is_es8311; // 1-ES8311, 0-NS4168
} DNSESP32S3_BOX_CONFIG_T;

/***********************************************************
***********************variable define**********************
***********************************************************/
static DNSESP32S3_BOX_CONFIG_T sg_dnesp32s3_box = {0};

/***********************************************************
***********************function define**********************
***********************************************************/
static OPERATE_RET __io_expander_init(void)
{
OPERATE_RET rt = OPRT_OK;

rt = xl9555_init();
if (rt != OPRT_OK) {
PR_ERR("xl9555_init failed: %d", rt);
return rt;
}

uint32_t pin_out_mask = 0;
pin_out_mask |= EX_IO_BEEP;
pin_out_mask |= EX_IO_CTP_RST;
pin_out_mask |= EX_IO_LCD_BL;
pin_out_mask |= EX_IO_LED_R;
pin_out_mask |= EX_IO_1_2;
pin_out_mask |= EX_IO_1_3;
pin_out_mask |= EX_IO_1_4;
pin_out_mask |= EX_IO_1_5;
pin_out_mask |= EX_IO_1_6;
pin_out_mask |= EX_IO_1_7;
rt = xl9555_set_dir(pin_out_mask, 0); // Set output direction
if (rt != OPRT_OK) {
PR_ERR("xl9555_set_dir out failed: %d", rt);
return rt;
}
uint32_t pin_in_mask = ~pin_out_mask;
rt = xl9555_set_dir(pin_in_mask, 1); // Set input direction
if (rt != OPRT_OK) {
PR_ERR("xl9555_set_dir in failed: %d", rt);
return rt;
}

return OPRT_OK;
}

static OPERATE_RET __board_register_audio(void)
{
OPERATE_RET rt = OPRT_OK;

#if defined(AUDIO_CODEC_NAME)
xl9555_set_dir(EX_IO_SPK_CTRL, 1);
uint32_t read_level = 0;
xl9555_get_level(EX_IO_SPK_CTRL, &read_level);
PR_DEBUG("Speaker control level: 0x%04x", read_level);
if (EX_IO_SPK_CTRL & read_level) {
sg_dnesp32s3_box.is_es8311 = 1; // ES8311 codec
PR_DEBUG("ES8311 codec is enabled");
} else {
sg_dnesp32s3_box.is_es8311 = 0; // NS4168 codec
PR_DEBUG("NS4168 codec is enabled");
}

#if USE_8311
TDD_AUDIO_8311_CODEC_T cfg = {0};
#else
TDD_AUDIO_ATK_NO_CODEC_T cfg = {0};
#endif

cfg.i2c_id = I2C_NUM;
cfg.i2c_scl_io = I2C_SCL_IO;
Expand All @@ -63,13 +109,18 @@ static OPERATE_RET __board_register_audio(void)
cfg.dma_frame_num = AUDIO_CODEC_DMA_FRAME_NUM;
cfg.default_volume = 80;

#if USE_8311
TUYA_CALL_ERR_RETURN(tdd_audio_8311_codec_register(AUDIO_CODEC_NAME, cfg));
#else
TUYA_CALL_ERR_RETURN(tdd_audio_atk_no_codec_register(AUDIO_CODEC_NAME, cfg));
#endif
if (sg_dnesp32s3_box.is_es8311) {
TUYA_CALL_ERR_RETURN(tdd_audio_8311_codec_register(AUDIO_CODEC_NAME, cfg));
} else {
TDD_AUDIO_ATK_NO_CODEC_T NS4168_cfg = {0};
memcpy(&NS4168_cfg, &cfg, sizeof(TDD_AUDIO_ATK_NO_CODEC_T));
TUYA_CALL_ERR_RETURN(tdd_audio_atk_no_codec_register(AUDIO_CODEC_NAME, NS4168_cfg));
}

xl9555_set_dir(EX_IO_SPK_CTRL, 0);
xl9555_set_level(EX_IO_SPK_CTRL, 1); // Enable speaker
#endif

return rt;
}

Expand All @@ -82,14 +133,25 @@ OPERATE_RET board_register_hardware(void)
{
OPERATE_RET rt = OPRT_OK;

TUYA_CALL_ERR_LOG(__io_expander_init());

TUYA_CALL_ERR_LOG(__board_register_audio());

return rt;
}

int board_display_init(void)
{
return lcd_st7789_80_init();
int rt = lcd_st7789_80_init();
if (rt != OPRT_OK) {
PR_ERR("lcd_st7789_80_init failed: %d", rt);
return rt;
}

xl9555_set_dir(EX_IO_LCD_BL, 0);
xl9555_set_level(EX_IO_LCD_BL, 1); // Enable LCD backlight

return 0;
}

void *board_display_get_panel_io_handle(void)
Expand Down
32 changes: 29 additions & 3 deletions boards/ESP32/DNESP32S3-BOX/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ extern "C" {
/***********************************************************
************************macro define************************
***********************************************************/
/* Example configurations */
#define USE_8311 (0) // 1-ES8311 0-NS4168

#define I2S_INPUT_SAMPLE_RATE (16000)
#define I2S_OUTPUT_SAMPLE_RATE (16000)

Expand Down Expand Up @@ -63,6 +60,35 @@ extern "C" {
#define DISPLAY_WIDTH 320
#define DISPLAY_HEIGHT 240

/* io expander start */
#define IO_EXPANDER_TYPE_UNKNOWN 0
#define IO_EXPANDER_TYPE_TCA9554 1
#define IO_EXPANDER_TYPE_XL9555 2

#define BOARD_IO_EXPANDER_TYPE IO_EXPANDER_TYPE_XL9555

#define IO_EXPANDER_XL9555_ADDR_000 (0x20)
#define IO_EXPANDER_XL9555_ADDR IO_EXPANDER_XL9555_ADDR_000

#define EX_IO_AP_INT (0x0001 << 0)
#define EX_IO_QMA_INT (0x0001 << 1)
#define EX_IO_BEEP (0x0001 << 2)
#define EX_IO_KEY_1 (0x0001 << 3)
#define EX_IO_KEY_0 (0x0001 << 4)
#define EX_IO_SPK_CTRL (0x0001 << 5)
#define EX_IO_CTP_RST (0x0001 << 6)
#define EX_IO_LCD_BL (0x0001 << 7)
#define EX_IO_LED_R (0x0001 << 8)
#define EX_IO_CTP_INT (0x0001 << 9)
#define EX_IO_1_2 (0x0001 << 10)
#define EX_IO_1_3 (0x0001 << 11)
#define EX_IO_1_4 (0x0001 << 12)
#define EX_IO_1_5 (0x0001 << 13)
#define EX_IO_1_6 (0x0001 << 14)
#define EX_IO_1_7 (0x0001 << 15)

/* io expander end */

/* display */
#define DISPLAY_TYPE_UNKNOWN 0
#define DISPLAY_TYPE_OLED_SSD1306 1
Expand Down
44 changes: 27 additions & 17 deletions boards/ESP32/DNESP32S3/board_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,33 @@ extern "C" {
#define AUDIO_CODEC_DMA_FRAME_NUM (240)
#define AUDIO_CODEC_ES8388_ADDR (0x20)

/* XL9555 Extended IO */
#define SPK_EN_IO 0x0004 /* Speaker enable IO pin */
#define BEEP_IO 0x0008
#define AP_INT_IO 0x0001
#define QMA_INT_IO 0x0002
#define OV_PWDN_IO 0x0010
#define OV_RESET_IO 0x0020
#define GBC_LED_IO 0x0040
#define GBC_KEY_IO 0x0080
#define LCD_BL_IO 0x0100
#define CT_RST_IO 0x0200
#define SLCD_RST_IO 0x0400
#define SLCD_PWR_IO 0x0800
#define KEY3_IO 0x1000
#define KEY2_IO 0x2000
#define KEY1_IO 0x4000
#define KEY0_IO 0x8000
/* io expander start */
#define IO_EXPANDER_TYPE_UNKNOWN 0
#define IO_EXPANDER_TYPE_TCA9554 1
#define IO_EXPANDER_TYPE_XL9555 2

#define BOARD_IO_EXPANDER_TYPE IO_EXPANDER_TYPE_XL9555

#define IO_EXPANDER_XL9555_ADDR_000 (0x20)
#define IO_EXPANDER_XL9555_ADDR IO_EXPANDER_XL9555_ADDR_000

#define EX_IO_AP_INT (0x0001 << 0)
#define EX_IO_QMA_INT (0x0001 << 1)
#define EX_IO_SPK_EN (0x0001 << 2)
#define EX_IO_BEEP (0x0001 << 3)
#define EX_IO_OV_PWDN (0x0001 << 4)
#define EX_IO_OV_RESET (0x0001 << 5)
#define EX_IO_GBC_LED (0x0001 << 6)
#define EX_IO_GBC_KEY (0x0001 << 7)
#define EX_IO_LCD_BL (0x0001 << 8)
#define EX_IO_CTP_RST (0x0001 << 9)
#define EX_IO_SLCD_RST (0x0001 << 10)
#define EX_IO_SLCD_PWR (0x0001 << 11)
#define EX_IO_KEY_3 (0x0001 << 12)
#define EX_IO_KEY_2 (0x0001 << 13)
#define EX_IO_KEY_1 (0x0001 << 14)
#define EX_IO_KEY_0 (0x0001 << 15)
/* io expander end */

/* display */
#define DISPLAY_TYPE_UNKNOWN 0
Expand Down
53 changes: 43 additions & 10 deletions boards/ESP32/DNESP32S3/dnesp32s3.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@

#include "tdd_audio_codec_bus.h"
#include "tdd_audio_es8388_codec.h"
#include "tdd_xl9555_io.h"

#include "lcd_st7789_spi.h"
#include "board_com_api.h"

#include "xl9555.h"

/***********************************************************
************************macro define************************
***********************************************************/
Expand All @@ -35,6 +36,42 @@ static TDD_AUDIO_I2S_RX_HANDLE i2s_rx_handle = NULL;
/***********************************************************
***********************function define**********************
***********************************************************/
static OPERATE_RET __io_expander_init(void)
{
OPERATE_RET rt = OPRT_OK;

rt = xl9555_init();
if (rt != OPRT_OK) {
PR_ERR("xl9555_init failed: %d", rt);
return rt;
}

uint32_t pin_out_mask = 0;
pin_out_mask |= EX_IO_SPK_EN;
pin_out_mask |= EX_IO_BEEP;
pin_out_mask |= EX_IO_OV_PWDN;
pin_out_mask |= EX_IO_OV_RESET;
pin_out_mask |= EX_IO_GBC_LED;
pin_out_mask |= EX_IO_GBC_KEY;
pin_out_mask |= EX_IO_LCD_BL;
pin_out_mask |= EX_IO_CTP_RST;
pin_out_mask |= EX_IO_SLCD_RST;
pin_out_mask |= EX_IO_SLCD_PWR;
rt = xl9555_set_dir(pin_out_mask, 0); // Set output direction
if (rt != OPRT_OK) {
PR_ERR("xl9555_set_dir out failed: %d", rt);
return rt;
}
uint32_t pin_in_mask = ~pin_out_mask;
rt = xl9555_set_dir(pin_in_mask, 1); // Set input direction
if (rt != OPRT_OK) {
PR_ERR("xl9555_set_dir in failed: %d", rt);
return rt;
}

return OPRT_OK;
}

static OPERATE_RET __board_register_audio(void)
{
OPERATE_RET rt = OPRT_OK;
Expand All @@ -58,14 +95,6 @@ static OPERATE_RET __board_register_audio(void)
tdd_audio_codec_bus_i2c_new(bus_cfg, &i2c_bus_handle);
tdd_audio_codec_bus_i2s_new(bus_cfg, &i2s_tx_handle, &i2s_rx_handle);

/* P10, P11, P12, P13, and P14 are inputs, other pins are outputs --> 0001 1111 0000 0000 Note: 0 is output, 1 is
* input */
tdd_xl9555_io_init(i2c_bus_handle, 0xF003);
/* Turn off buzzer */
tdd_xl9555_io_set(BEEP_IO, 1);
/* Turn on Speaker */
tdd_xl9555_io_set(SPK_EN_IO, 0);

TDD_AUDIO_ES8388_CODEC_T codec = {
.i2c_id = I2C_NUM,
.i2c_handle = i2c_bus_handle,
Expand All @@ -78,8 +107,10 @@ static OPERATE_RET __board_register_audio(void)
.pa_pin = -1, /* The speaker power is controlled by XL9555. */
.default_volume = 80,
};

TUYA_CALL_ERR_RETURN(tdd_audio_es8388_codec_register(AUDIO_CODEC_NAME, codec));

xl9555_set_dir(EX_IO_SPK_EN, 0);
xl9555_set_level(EX_IO_SPK_EN, 0); // Enable speaker
#endif

return rt;
Expand All @@ -94,6 +125,8 @@ OPERATE_RET board_register_hardware(void)
{
OPERATE_RET rt = OPRT_OK;

TUYA_CALL_ERR_LOG(__io_expander_init());

TUYA_CALL_ERR_LOG(__board_register_audio());

return rt;
Expand Down
3 changes: 1 addition & 2 deletions boards/ESP32/common/audio/tdd_audio_8311_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ OPERATE_RET codec_8311_init(TUYA_I2S_NUM_E i2s_num, const TDD_AUDIO_8311_CODEC_T
void *i2c_master_handle = NULL;
i2c_port_t i2c_port = (i2c_port_t)(i2s_config->i2c_id);
uint8_t es8311_addr = i2s_config->es8311_addr;
bool use_mclk = true;
pa_pin_ = i2s_config->gpio_output_pa;
input_sample_rate_ = i2s_config->mic_sample_rate;
output_sample_rate_ = i2s_config->spk_sample_rate;
Expand Down 6688 Expand Up @@ -247,7 +246,7 @@ OPERATE_RET codec_8311_init(TUYA_I2S_NUM_E i2s_num, const TDD_AUDIO_8311_CODEC_T
es8311_cfg.gpio_if = gpio_if_;
es8311_cfg.codec_mode = ESP_CODEC_DEV_WORK_MODE_BOTH;
es8311_cfg.pa_pin = pa_pin_;
es8311_cfg.use_mclk = use_mclk;
es8311_cfg.use_mclk = ((i2s_config->i2s_mck_io != -1) ? true : false);
es8311_cfg.hw_gain.pa_voltage = 5.0;
es8311_cfg.hw_gain.codec_dac_voltage = 3.3;
codec_if_ = es8311_codec_new(&es8311_cfg);
Expand Down
Loading
0