mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
refactor core2, i2s
This commit is contained in:
parent
a13c85c45e
commit
62649f238e
@ -94,7 +94,7 @@ uint32_t retryms = 0;
|
||||
|
||||
#ifdef SAY_TIME
|
||||
AudioGeneratorTalkie *talkie = nullptr;
|
||||
#endif
|
||||
#endif // SAY_TIME
|
||||
|
||||
//! MAX98357A + INMP441 DOUBLE I2S BOARD
|
||||
#ifdef ESP8266
|
||||
@ -111,22 +111,22 @@ AudioGeneratorTalkie *talkie = nullptr;
|
||||
#ifndef DAC_IIS_BCK
|
||||
#undef DAC_IIS_BCK
|
||||
#define DAC_IIS_BCK 26
|
||||
#endif
|
||||
#endif // DAC_IIS_BCK
|
||||
|
||||
#ifndef DAC_IIS_WS
|
||||
#undef DAC_IIS_WS
|
||||
#define DAC_IIS_WS 25
|
||||
#endif
|
||||
#endif // DAC_IIS_WS
|
||||
|
||||
#ifndef DAC_IIS_DOUT
|
||||
#undef DAC_IIS_DOUT
|
||||
#define DAC_IIS_DOUT 33
|
||||
#endif
|
||||
#endif // DAC_IIS_DOUT
|
||||
|
||||
#ifndef DAC_IIS_DIN
|
||||
#undef DAC_IIS_DIN
|
||||
#define DAC_IIS_DIN 34
|
||||
#endif
|
||||
#endif // DAC_IIS_DIN
|
||||
|
||||
#endif // ESP32
|
||||
|
||||
@ -229,7 +229,7 @@ void sayTime(int hour, int minutes, AudioGeneratorTalkie *talkie) {
|
||||
out->stop();
|
||||
AUDIO_PWR_OFF
|
||||
}
|
||||
#endif
|
||||
#endif // SAY_TIME
|
||||
|
||||
// should be in settings
|
||||
uint8_t is2_volume;
|
||||
@ -382,7 +382,7 @@ uint32_t i2s_record(char *path, uint32_t secs) {
|
||||
//AddLog_P(LOG_LEVEL_INFO, PSTR("rectime: %d ms"), millis()-stime);
|
||||
SpeakerMic(MODE_SPK);
|
||||
// save to path
|
||||
SaveWav(mic_path, mic_buff, mic_size);
|
||||
SaveWav(path, mic_buff, mic_size);
|
||||
free(mic_buff);
|
||||
return 0;
|
||||
}
|
||||
@ -393,7 +393,8 @@ static const uint8_t wavHTemplate[] PROGMEM = { // Hardcoded simple WAV header w
|
||||
0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff };
|
||||
|
||||
bool SaveWav(char *path, uint8_t *buff, uint32_t size) {
|
||||
File fwp = ufsp->open(path, FILE_WRITE);
|
||||
File fwp = ufsp->open(path, "w");
|
||||
if (!fwp) return false;
|
||||
uint8_t wavHeader[sizeof(wavHTemplate)];
|
||||
memcpy_P(wavHeader, wavHTemplate, sizeof(wavHTemplate));
|
||||
|
||||
@ -446,7 +447,7 @@ void mp3_task(void *arg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // ESP32
|
||||
|
||||
#ifdef USE_WEBRADIO
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *str) {
|
||||
@ -541,6 +542,23 @@ void Cmd_WebRadio(void) {
|
||||
|
||||
}
|
||||
|
||||
#ifdef USE_M5STACK_CORE2
|
||||
void Cmd_MicRec(void) {
|
||||
if (XdrvMailbox.data_len > 0) {
|
||||
uint16 time = 10;
|
||||
char *cp = strchr(XdrvMailbox.data, ':');
|
||||
if (cp) {
|
||||
time = atoi(cp + 1);
|
||||
*cp = 0;
|
||||
}
|
||||
if (time<10) time = 10;
|
||||
if (time>30) time = 30;
|
||||
i2s_record(XdrvMailbox.data, time);
|
||||
ResponseCmndChar(XdrvMailbox.data);
|
||||
}
|
||||
}
|
||||
#endif // USE_M5STACK_CORE2
|
||||
|
||||
const char HTTP_WEBRADIO[] PROGMEM =
|
||||
"{s}" "I2S_WR-Title" "{m}%s{e}";
|
||||
|
||||
@ -626,8 +644,11 @@ const char kI2SAudio_Commands[] PROGMEM = "I2S|"
|
||||
"|Play"
|
||||
#ifdef USE_WEBRADIO
|
||||
"|WR"
|
||||
#endif
|
||||
#endif
|
||||
#endif // USE_WEBRADIO
|
||||
#ifdef USE_M5STACK_CORE2
|
||||
"|REC"
|
||||
#endif // USE_M5STACK_CORE2
|
||||
#endif // ESP32
|
||||
;
|
||||
|
||||
void (* const I2SAudio_Command[])(void) PROGMEM = {
|
||||
@ -636,8 +657,11 @@ void (* const I2SAudio_Command[])(void) PROGMEM = {
|
||||
,&Cmd_Play
|
||||
#ifdef USE_WEBRADIO
|
||||
,&Cmd_WebRadio
|
||||
#endif
|
||||
#endif
|
||||
#endif // USE_WEBRADIO
|
||||
#ifdef USE_M5STACK_CORE2
|
||||
,&Cmd_MicRec
|
||||
#endif // USE_M5STACK_CORE2
|
||||
#endif // ESP32
|
||||
};
|
||||
|
||||
|
||||
@ -669,7 +693,7 @@ void Cmd_Say(void) {
|
||||
void Cmd_Time(void) {
|
||||
#ifdef SAY_TIME
|
||||
sayTime(RtcTime.hour, RtcTime.minute, talkie);
|
||||
#endif
|
||||
#endif // SAY_TIME
|
||||
ResponseCmndDone();
|
||||
}
|
||||
|
||||
@ -692,8 +716,8 @@ bool Xdrv42(uint8_t function) {
|
||||
case FUNC_WEB_SENSOR:
|
||||
I2S_WR_Show();
|
||||
break;
|
||||
#endif
|
||||
#endif
|
||||
#endif // USE_WEBRADIO
|
||||
#endif // USE_WEBSERVER
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ struct CORE2_globs {
|
||||
uint8_t wakeup_hour;
|
||||
uint8_t wakeup_minute;
|
||||
uint8_t shutdowndelay;
|
||||
bool timesynced;
|
||||
} core2_globs;
|
||||
|
||||
struct CORE2_ADC {
|
||||
@ -262,44 +261,6 @@ uint16_t voltage = 2200;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void SetRtc(void) {
|
||||
RTC_TimeTypeDef RTCtime;
|
||||
RTCtime.Hours = RtcTime.hour;
|
||||
RTCtime.Minutes = RtcTime.minute;
|
||||
RTCtime.Seconds = RtcTime.second;
|
||||
core2_globs.Rtc.SetTime(&RTCtime);
|
||||
|
||||
RTC_DateTypeDef RTCdate;
|
||||
RTCdate.WeekDay = RtcTime.day_of_week;
|
||||
RTCdate.Month = RtcTime.month;
|
||||
RTCdate.Date = RtcTime.day_of_month;
|
||||
RTCdate.Year = RtcTime.year;
|
||||
core2_globs.Rtc.SetDate(&RTCdate);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// needed for sd card time
|
||||
void Sync_RTOS_TIME(void) {
|
||||
|
||||
if (Rtc.local_time < START_VALID_TIME || core2_globs.timesynced) return;
|
||||
|
||||
core2_globs.timesynced = 1;
|
||||
// Set freertos time for sd card
|
||||
|
||||
struct timeval tv;
|
||||
//tv.tv_sec = Rtc.utc_time;
|
||||
tv.tv_sec = Rtc.local_time;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
//struct timezone tz;
|
||||
//tz.tz_minuteswest = 0;
|
||||
//tz.tz_dsttime = 0;
|
||||
//settimeofday(&tv, &tz);
|
||||
|
||||
settimeofday(&tv, NULL);
|
||||
}
|
||||
|
||||
void GetRtc(void) {
|
||||
RTC_TimeTypeDef RTCtime;
|
||||
@ -372,8 +333,6 @@ void CORE2_EverySecond(void) {
|
||||
CORE2_DoShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
Sync_RTOS_TIME();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user