Skip to content

Commit

Permalink
plugin tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
gemu2015 committed Aug 4, 2024
1 parent e3dc591 commit 7f5833e
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 28 deletions.
12 changes: 6 additions & 6 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_0000FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD;
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_00030005000A000F00110012FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001FFF8FFF9FFFAFFFBFFFCFFFD;
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_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020008FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000010007FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_00000001000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000200030004FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100020003000400050006000700080009000A000F001100120013FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_000000050007000A000B000C000D000E000F0017FFF8FFF9FFFAFFFBFFFCFFFD;
extern const binstance_arg3 be_const_instance_0000000100070008000F4001400AFFF8FFF9FFFAFFFBFFFCFFFD;
12 changes: 6 additions & 6 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(0000FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 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(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(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(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(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(000000010007FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x07, 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(00030004FFF8FFF9FFFAFFFBFFFCFFFD, 0x00, 0x03, 0x00, 0x04, 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(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(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(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(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(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);
6 changes: 4 additions & 2 deletions tasmota/Plugins/module_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ extern void AddLog(uint32_t loglevel, PGM_P formatP, ...);
#define jstrtol(A,B,C) (( int32_t (*)(char *,char **,size_t )) jt[153])(A,B,C)
#define judp(A,B,C,D) (( uint32_t (*)(void *,uint32_t,uint32_t,uint32_t )) jt[154])(A,B,C,D)
#define ji2s(A,B,C,D,E,F) (( uint32_t (*)(uint32_t,uint32_t,uint32_t,uint32_t,uint32_t,uint32_t )) jt[155])(A,B,C,D,E,F)
#define jtaskc(A,B,C,D,E,F,G) (( uint32_t (*)(void (*)(void*),const char *,uint32_t,void *,uint32_t,void *,uint32_t )) jt[156])(A,B,C,D,E,F,G)
#define jtaskc(A) (( uint32_t (*)(TASKPARS* )) jt[156])(A)
#define jtaskd(A) (( uint32_t (*)(uint32_t)) jt[157])(A)
#define jPlugin_Get_SensorNames(A,B) (( char *(*)(char *,uint32_t)) jt[158])(A,B)
#define GetScriptSection(A) (( char *(*)(char *)) jt[159])(A)
Expand Down Expand Up @@ -772,7 +772,9 @@ typedef struct {
#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 xTaskCreatePinnedToCore(A,B,C,D,E,F,G) jtaskc(A, B, C, D, E, F, G)

#define xTaskCreatePinnedToCore(A) jtaskc(A)
#define vTaskDelete(A) jtaskd(A)

#define dadd(A,B) double_dispatch(0,A,B)
#define dsub(A,B) double_dispatch(1,A,B)
Expand Down
10 changes: 10 additions & 0 deletions tasmota/Plugins/modules_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ typedef union {
};
} MOD_FLAGS;

typedef struct {
void (*pvTaskCode)(void*);
const char *constpcName;
uint32_t usStackDepth;
void *constpvParameters;
uint32_t uxPriority;
void *constpvCreatedTask;
uint32_t xCoreID;
} TASKPARS;

typedef struct {
void *mod_addr;
void (* const *jt)(void);
Expand Down
65 changes: 54 additions & 11 deletions tasmota/Plugins/xdrv_42_i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,27 @@ typedef struct {
} wav_header_t;


#ifdef ESP32
#define USE_I2S_TASK
#endif

typedef struct {
uint8_t dout_pin;
uint8_t bck_pin;
uint8_t ws_pin;
uint8_t gain_div;
void *i2sp;
uint8_t busy;
} 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 busy mem->busy



#define I2S_REV 1 << 16 | 4

Expand All @@ -95,7 +103,7 @@ MODULE_END

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

const char tname[] PROGMEM = "I2STASK";

int32_t I2SAudio_Init() {
ALLOCMEM
Expand All @@ -107,26 +115,51 @@ int32_t I2SAudio_Init() {

gain_div = 2;

busy = false;

initialized = true;
return 0;
}


//#define USE_I2S_TASK

#ifdef USE_I2S_TASK
void I2sTask(void *path) {
SETREGS
File_p *wf;
wf = fopen((char*)path, 'r');

int16_t buffer[512];
// skip header
fread((char*)&buffer, 1, sizeof(wav_header_t), wf);

while (1) {
AddLog(LOG_LEVEL_INFO, PSTR("task"));
delay(1000);
uint32_t bytesread = fread((char*)buffer, 1, sizeof(buffer), wf);
if (!bytesread) {
break;
}
for (uint32_t i = 0; i < bytesread / 2; i++) {
buffer[i] /= gain_div;
}
i2s_write_samples(i2sp, buffer, bytesread / 2);
}

i2s_end(i2sp);

fclose(wf);

busy = false;

vTaskDelete(0);
}
#endif

void I2S_PlayWave(void) {
SETREGS

if (busy) {
return;
}

char *cp = XdrvMailbox->data;
while (*cp == ' ') cp++;

Expand All @@ -149,19 +182,27 @@ void I2S_PlayWave(void) {
Response_P(GSTR(S_JSON_ILLF));
return;
}

i2sp = i2s_begin(dout_pin, bck_pin, ws_pin);
i2s_set_rate(i2sp, wh.Fmt.SampleRate);

busy = true;

#ifdef USE_I2S_TASK
fclose(wf);

xTaskCreatePinnedToCore(GVOID(I2sTask), PSTR("I2STASK"), 8192, (void*)cp, 3, NULL, 1);
TASKPARS tp;
tp.pvTaskCode = GVOID(I2sTask);
tp.constpcName = GSTR(tname);
tp.usStackDepth = ICONST(8192);
tp.constpvParameters = cp;
tp.uxPriority = 3;
tp.constpvCreatedTask = nullptr;
tp.xCoreID = 1;
int32_t err = xTaskCreatePinnedToCore(&tp);
#else

int16_t buffer[512];

i2sp = i2s_begin(dout_pin, bck_pin, ws_pin);

i2s_set_rate(i2sp, wh.Fmt.SampleRate);

while (1) {
uint32_t bytesread = fread((char*)buffer, 1, sizeof(buffer), wf);
if (!bytesread) {
Expand All @@ -177,6 +218,8 @@ void I2S_PlayWave(void) {
i2s_end(i2sp);

fclose(wf);

busy = false;
#endif

ResponseCmndDone();
Expand Down
12 changes: 9 additions & 3 deletions tasmota/tasmota_xdrv_driver/xdrv_123_plugins.ino
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ 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);
uint32_t tmod_task_create(TASKPARS *tp);

extern "C" {
extern void (* const MODULE_JUMPTABLE[])(void);
Expand Down Expand Up @@ -410,9 +411,14 @@ char *tmod_Run_Scripter(char *sect) {
}

#ifdef ESP32
//uint32_t tmod_task_create(TaskFunction_t pvTaskCode, const char *constpcName, const uint32_t usStackDepth, void *constpvParameters, UBaseType_t uxPriority, TaskHandle_t *constpvCreatedTask, const BaseType_t xCoreID) {
uint32_t tmod_task_create(uint32_t pvTaskCode, const char *constpcName, const uint32_t usStackDepth, void *constpvParameters, uint32_t uxPriority, void *constpvCreatedTask, uint32_t xCoreID) {
return (uint32_t) xTaskCreatePinnedToCore((TaskFunction_t)pvTaskCode, constpcName, usStackDepth, constpvParameters, (UBaseType_t)uxPriority, (TaskHandle_t*)constpvCreatedTask, (const BaseType_t)xCoreID);
uint32_t tmod_task_create(TASKPARS *tp) {
uint32_t result;
char *cp = copyStr(tp->constpcName);
AddLog(LOG_LEVEL_INFO,PSTR("task Init %s - %d"), cp, tp->usStackDepth);

result = xTaskCreatePinnedToCore(tp->pvTaskCode, cp, tp->usStackDepth, tp->constpvParameters, (UBaseType_t)tp->uxPriority, (TaskHandle_t*)tp->constpvCreatedTask, (const BaseType_t)tp->xCoreID);
free(cp);
return result;
}
uint32_t tmod_task_delete(uint32_t xTaskToDelete) {
vTaskDelete((TaskHandle_t)xTaskToDelete);
Expand Down

0 comments on commit 7f5833e

Please sign in to comment.