Skip to content

Commit

Permalink
Update xdrv_42_i2s.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Aug 2, 2024
1 parent 15eef92 commit 0fc3f0a
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions tasmota/Plugins/xdrv_42_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,6 @@
#include "module.h"
#include "module_defines.h"

#define I2S_REV 1 << 16 | 4


PUSH_OPTIONS

MODULE_DESCRIPTOR("I2SAUDIO", MODULE_TYPE_DRIVER, I2S_REV, "", 0, "", 0, "", 0, "", 0)

// all functions must be declared MUDULE_PART
MODULE_PART int32_t I2SAudio_Init();
MODULE_PART void I2S_PlayWave(void);
MODULE_PART void I2SAudio_Deinit();
MODULE_PART int32_t mod_func_execute(uint32_t sel);
MODULE_END


typedef struct {
uint16_t dummy;
} MODULE_MEMORY;

int32_t I2SAudio_Init() {
ALLOCMEM

initialized = true;
return 0;
}

// RIFF header
typedef struct {
Expand Down Expand Up @@ -84,9 +59,34 @@ typedef struct {
wav_data_t Data;
} wav_header_t;


typedef struct {
uint16_t dummy;
} MODULE_MEMORY;

#define I2S_REV 1 << 16 | 4

PUSH_OPTIONS

MODULE_DESCRIPTOR("I2SAUDIO", MODULE_TYPE_DRIVER, I2S_REV, "", 0, "", 0, "", 0, "", 0)

// all functions must be declared MUDULE_PART
MODULE_PART int32_t I2SAudio_Init();
MODULE_PART void I2S_PlayWave(void);
MODULE_PART void I2SAudio_Deinit();
MODULE_PART int32_t mod_func_execute(uint32_t sel);
MODULE_END

const char S_JSON_FNF[] PROGMEM = "{\"File %s not found\"}";
const char S_JSON_ILLF[] PROGMEM = "{\"Illegal File format\"}";

int32_t I2SAudio_Init() {
ALLOCMEM

initialized = true;
return 0;
}

void I2S_PlayWave(void) {
SETREGS

Expand All @@ -104,8 +104,6 @@ void I2S_PlayWave(void) {

int16_t buffer[512];

uint32_t fsize = fsize(wf);

// check for RIFF
fread((char*)buffer, 1, sizeof(wav_header_t), wf);

Expand All @@ -117,14 +115,10 @@ void I2S_PlayWave(void) {
return;
}

// read rest of header we assume 1 channel 8 khz
fsize -= sizeof(wav_header_t);

i2s_begin();

i2s_set_rate(wh->Fmt.SampleRate);

//while (fpos(wf) < fsize) {
while (1) {
uint32_t bytesread = fread((char*)buffer, 1, sizeof(buffer), wf);
if (!bytesread) {
Expand Down

0 comments on commit 0fc3f0a

Please sign in to comment.