Skip to content

Commit

Permalink
update i2s
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Aug 3, 2024
1 parent 0fc3f0a commit b3f70c7
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 58 deletions.
16 changes: 8 additions & 8 deletions lib/libesp32/berry/generate/be_const_bytes.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* extern binary arrays */
extern const binstance_arg3 be_const_instance_;
extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010002FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD;
16 changes: 8 additions & 8 deletions lib/libesp32/berry/generate/be_const_bytes_def.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* binary arrays */
be_define_const_bytes_empty();
be_define_const_bytes(00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010002000300040005FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x05, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010002FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000020003000F0011FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x0F, 0x00, 0x11, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000050007000A000B000D000E0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00070008000F400B400CFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x0B, 0x40, 0x0C, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001000200080009FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0x00, 0x09, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x08, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00, 0x0A, 0x00, 0x0F, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(FFF8FFF9FFFAFFFBFFFCFFFD, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x0B, 0x00, 0x0C, 0x00, 0x0D, 0x00, 0x0E, 0x00, 0x0F, 0x00, 0x17, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
be_define_const_bytes(0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x08, 0x00, 0x0F, 0x40, 0x01, 0x40, 0x0A, 0xFF, 0xF8, 0xFF, 0xF9, 0xFF, 0xFA, 0xFF, 0xFB, 0xFF, 0xFC, 0xFF, 0xFD);
17 changes: 13 additions & 4 deletions tasmota/Plugins/module_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ extern void AddLog(uint32_t loglevel, PGM_P formatP, ...);
#define jfile_size(A) (( uint32_t (*)(void*)) jt[160])(A)
#define jfile_getpos(A) (( uint32_t (*)(void*)) jt[161])(A)
#define jOsWatchLoop() (( void (*)(void)) jt[162])
#define double_dispatch(A,B,C) (( double (*)(uint32_t,double,double)) jt[163])(A,B,C)


//tmod_udp,
//tmod_i2s,
Expand Down Expand Up @@ -769,10 +771,17 @@ typedef struct {
#define fpos(A) jfile_getpos(A)
#define OsWatchLoop jOsWatchLoop

#define i2s_begin(A) ji2s(0,0,0,0,0,0)
#define i2s_end(A) ji2s(1,0,0,0,0,0)
#define i2s_set_rate(A) ji2s(2,A,0,0,0,0)
#define i2s_write_sample(A) ji2s(5,A,0,0,0,0)
#define i2s_begin(A,B,C) (void*)ji2s(0,0,A,B,C,0)
#define i2s_end(A) ji2s(1,(uint32_t)A,0,0,0,0)
#define i2s_set_rate(A,B) ji2s(2,(uint32_t)A,B,0,0,0)
#define i2s_write_sample(A,B) ji2s(5,(uint32_t)A,B,0,0,0)
#define i2s_write_samples(A,B,C) ji2s(3,(uint32_t)A,(uint32_t)B,C,0,0)


#define dadd(A,B) double_dispatch(0,A,B)
#define dsub(A,B) double_dispatch(1,A,B)
#define dmul(A,B) double_dispatch(2,A,B)
#define ddiv(A,B) double_dispatch(3,A,B)


#define CharToFloat jCharToFloat
Expand Down
59 changes: 51 additions & 8 deletions tasmota/Plugins/xdrv_42_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,33 @@ typedef struct {


typedef struct {
uint16_t dummy;
uint8_t dout_pin;
uint8_t bck_pin;
uint8_t ws_pin;
uint8_t gain_div;
void *i2sp;
} MODULE_MEMORY;

#define dout_pin mem->dout_pin
#define bck_pin mem->bck_pin
#define ws_pin mem->ws_pin
#define i2sp mem->i2sp
#define gain_div mem->gain_div

#define I2S_REV 1 << 16 | 4

PUSH_OPTIONS

#ifdef ESP8266
MODULE_DESCRIPTOR("I2SAUDIO", MODULE_TYPE_DRIVER, I2S_REV, "", 0, "", 0, "", 0, "", 0)
#else
MODULE_DESCRIPTOR("I2SAUDIO", MODULE_TYPE_DRIVER, I2S_REV, "DOUT", 17, "BCK", 10, "WS", 18, "", 0)
#endif

// all functions must be declared MUDULE_PART
MODULE_PART int32_t I2SAudio_Init();
MODULE_PART void I2S_PlayWave(void);
MODULE_PART void SetGain(void);
MODULE_PART void I2SAudio_Deinit();
MODULE_PART int32_t mod_func_execute(uint32_t sel);
MODULE_END
Expand All @@ -83,6 +98,13 @@ const char S_JSON_ILLF[] PROGMEM = "{\"Illegal File format\"}";
int32_t I2SAudio_Init() {
ALLOCMEM

dout_pin = mp->ms[0].value;
bck_pin = mp->ms[1].value;
ws_pin = mp->ms[2].value;


gain_div = 2;

initialized = true;
return 0;
}
Expand Down Expand Up @@ -115,22 +137,23 @@ void I2S_PlayWave(void) {
return;
}

i2s_begin();
i2sp = i2s_begin(dout_pin, bck_pin, ws_pin);

i2s_set_rate(wh->Fmt.SampleRate);
i2s_set_rate(i2sp, wh->Fmt.SampleRate);

while (1) {
uint32_t bytesread = fread((char*)buffer, 1, sizeof(buffer), wf);
if (!bytesread) {
break;
}
for (uint32_t i = 0; i < bytesread / 2; i++) {
i2s_write_sample(buffer[i]);
OsWatchLoop();
buffer[i] /= gain_div;
}
i2s_write_samples(i2sp, buffer, bytesread / 2);
OsWatchLoop();
}

i2s_end();
i2s_end(i2sp);

fclose(wf);

Expand All @@ -139,12 +162,32 @@ void I2S_PlayWave(void) {
return;
}

void SetGain(void) {
SETREGS
uint8_t gain;

if (XdrvMailbox->data_len > 0) {
char *cp = XdrvMailbox->data;
while (*cp == ' ') cp++;
gain = strtol(cp, &cp, 10);
if (gain > 100) {
gain = 100;
}
if (gain < 1) {
gain = 1;
}
gain_div = 100 / gain;
} else {
gain = 100 / gain_div;
}
ResponseCmndNumber(gain);

}

const char I2S_Commands[] PROGMEM =
"I2S|" // Prefix
"pw";
void (*const I2S_Command[])(void) PROGMEM = {&I2S_PlayWave};
"pw|gain";
void (*const I2S_Command[])(void) PROGMEM = {&I2S_PlayWave,&SetGain};

void I2SAudio_Deinit() {
SETREGS
Expand Down
129 changes: 99 additions & 30 deletions tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ int32_t tmod_file_seek(class File *fp, uint32_t pos, uint32_t mode);
int32_t tmod_file_read(class File *fp, uint8_t *buff, uint32_t size);
int32_t tmod_file_write(class File *fp, uint8_t *buff, uint32_t size);
uint32_t tmod_file_size(class File *fp);
uint32_t tmod_file_pos(class File *fp);
void tmod_AddLogData(uint32_t loglevel, const char* log_data);
char *Plugin_Get_SensorNames(char *type, uint32_t index);
char *tmod_Run_Scripter(char *sect);
double tmod_double_dispatch(uint32_t sel, double a, double b);

extern "C" {
extern void (* const MODULE_JUMPTABLE[])(void);
Expand Down Expand Up @@ -372,10 +374,33 @@ void (* const MODULE_JUMPTABLE[])(void) PROGMEM = {
JMPTBL&tmod_Run_Scripter,
JMPTBL&tmod_file_size,
JMPTBL&tmod_file_pos,
JMPTBL&OsWatchLoop
JMPTBL&OsWatchLoop,
JMPTBL&tmod_double_dispatch
};

#define USE_DOUBLE_DISPATCH


double tmod_double_dispatch(uint32_t sel, double a, double b) {
double result = 0;
#ifdef USE_DOUBLE_DISPATCH
switch (sel) {
case 0:
result = a + b;
break;
case 1:
result = a - b;
break;
case 2:
result = a * b;
break;
case 3:
result = a / b;
break;
}
#endif
return result;
}
char *tmod_Run_Scripter(char *sect) {
uint8_t meter_script = Run_Scripter(sect, -2, 0);
if (meter_script != 99) {
Expand Down Expand Up @@ -412,74 +437,118 @@ uint32_t tmod_dummy() {
#endif

uint32_t tmod_i2s(uint32_t sel, uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4, uint32_t p5) {
#ifdef ESP32
i2s_chan_handle_t tx_handle = (i2s_chan_handle_t)p1;
#endif

switch (sel) {
case 0:
#ifdef ESP8266
// return i2s_rxtx_begin(p2, p3);
i2s_begin();
return 0;
#else
#if ESP_IDF_VERSION_MAJOR >= 5
return 0;
#else
return i2s_driver_install((i2s_port_t)p1, (i2s_config_t*)p2, p3, (void*)p4);
#endif
#ifdef ESP32
{
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
/* Allocate a new TX channel and get the handle of this channel */
i2s_new_channel(&chan_cfg, &tx_handle, NULL);

i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(8000),
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_MONO),
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED,
.bclk = (gpio_num_t)p3,
.ws = (gpio_num_t)p4,
.dout = (gpio_num_t)p2,
.din = I2S_GPIO_UNUSED,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false,
},
},
};
/* Initialize the channel */
i2s_channel_init_std_mode(tx_handle, &std_cfg);
/* Before writing data, start the TX channel first */
i2s_channel_enable(tx_handle);
AddLog(LOG_LEVEL_INFO,PSTR("I2S Init %d - %d - %d"), p2, p3, p4);
return (uint32_t)tx_handle;
}

#endif
break;
case 1:
#ifdef ESP8266
i2s_end();
#else
#if ESP_IDF_VERSION_MAJOR >= 5
#else
i2s_driver_uninstall((i2s_port_t)p1);
#endif
#ifdef ESP32
{
i2s_channel_disable(tx_handle);
i2s_del_channel(tx_handle);
AddLog(LOG_LEVEL_INFO,PSTR("I2S Exit"));
}
#endif
break;
case 2:
#ifdef ESP8266
i2s_set_rate(p1);
#else
#if ESP_IDF_VERSION_MAJOR >= 5
#else
i2s_set_clk((i2s_port_t)p1, p2, p3, (i2s_channel_t)p4);
i2s_set_rate(p2);
#endif
#ifdef ESP32
{
const i2s_std_clk_config_t clk_cfg = {
.sample_rate_hz = p2,
.clk_src = I2S_CLK_SRC_DEFAULT
};
//i2s_channel_disable(tx_handle);
//i2s_channel_reconfig_std_clock(tx_handle, &clk_cfg);
//i2s_channel_enable(tx_handle);
AddLog(LOG_LEVEL_INFO,PSTR("I2S Setrate %d"), p2);
}
#endif
break;
case 3:
// write samples
#ifdef ESP8266
{
/*
int16_t *left = (int16_t*)p2;
int16_t *right = (int16_t*)p2 + 2;
for (uint32_t cnt = 0; cnt < (p3 >> 2); cnt++) {
i2s_write_lr(*left++, *right++);
}
*(uint32_t*)p4 = p3;
*/
int16_t *swp = (int16_t*)p2;
for (uint32_t cnt = 0; cnt < p3; cnt++) {
i2s_write_sample(*swp++);
}
}
break;
#else
#if ESP_IDF_VERSION_MAJOR >= 5
#else
//i2s_write(audio_i2s.i2s_port, (const uint8_t*)packet_buffer, len, &bytes_written, 0);
return i2s_write((i2s_port_t)p1, (const uint8_t*)p2, p3, (size_t*)p4, p5);
#endif
#endif
#ifdef ESP32
i2s_channel_write(tx_handle, (uint8_t *)p2, p3 * 2, nullptr, 100);
#endif
//i2s_set_pin
break;
case 4:
// read samples
#ifdef ESP8266
return i2s_read_sample((int16_t *)p2, (int16_t *)p3, p4);
#else
#if ESP_IDF_VERSION_MAJOR >= 5
break;
#else
return i2s_read((i2s_port_t)p1, (char *)p2, p3, (size_t*)p4, p5);
#endif

#ifdef ESP32
#endif
break;
case 5:
// write one sample
#ifdef ESP8266
i2s_write_sample(p1);
i2s_write_sample(p2);
#endif // ESP8266
#ifdef ESP32
int16_t src_buf = p2;
i2s_channel_write(tx_handle, &src_buf, 2, nullptr, 5);
break;
#endif // ESP32
}
return 0;
}
Expand Down

0 comments on commit b3f70c7

Please sign in to comment.