Prep for ESP32-C3 ph2

This commit is contained in:
Theo Arends 2020-11-28 16:39:15 +01:00
parent 0c95f2ec8e
commit 17e6890809
12 changed files with 149 additions and 68 deletions

View File

@ -648,9 +648,10 @@ String GetDeviceHardware(void)
} else {
strcpy_P(buff, PSTR("ESP8266EX"));
}
#else
#endif // ESP8266
#ifdef ESP32
strcpy_P(buff, PSTR("ESP32"));
#endif
#endif // ESP32
return String(buff);
}
@ -916,13 +917,14 @@ void SetSerialBegin(void) {
Serial.flush();
#ifdef ESP8266
Serial.begin(TasmotaGlobal.baudrate, (SerialConfig)pgm_read_byte(kTasmotaSerialConfig + Settings.serial_config));
#else // ESP32
#endif // ESP8266
#ifdef ESP32
delay(10); // Allow time to cleanup queues - if not used hangs ESP32
Serial.end();
delay(10); // Allow time to cleanup queues - if not used hangs ESP32
uint32_t config = pgm_read_dword(kTasmotaSerialConfig + Settings.serial_config);
Serial.begin(TasmotaGlobal.baudrate, config);
#endif
#endif // ESP32
}
void SetSerialConfig(uint32_t serial_config) {
@ -1391,9 +1393,10 @@ void TemplateGpios(myio *gp)
} else {
#ifdef ESP8266
GetInternalTemplate(&src, Settings.module, 1);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
memcpy_P(&src, &kModules.gp, sizeof(mycfgio));
#endif // ESP8266 - ESP32
#endif // ESP32
}
// 11 85 00 85 85 00 00 00 15 38 85 00 00 81
@ -1420,9 +1423,10 @@ gpio_flag ModuleFlag(void)
} else {
#ifdef ESP8266
GetInternalTemplate(&flag, Settings.module, 2);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
memcpy_P(&flag, &kModules.flag, sizeof(gpio_flag));
#endif // ESP8266 - ESP32
#endif // ESP32
}
return flag;
@ -1436,9 +1440,10 @@ void ModuleDefault(uint32_t module)
SettingsUpdateText(SET_TEMPLATE_NAME, GetTextIndexed(name, sizeof(name), module, kModuleNames));
#ifdef ESP8266
GetInternalTemplate(&Settings.user_template, module, 3);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
memcpy_P(&Settings.user_template, &kModules, sizeof(mytmplt));
#endif // ESP8266 - ESP32
#endif // ESP32
}
void SetModuleType(void)
@ -2104,9 +2109,10 @@ uint32_t HwRandom(void) {
#if ESP8266
// https://web.archive.org/web/20160922031242/http://esp8266-re.foogod.com/wiki/Random_Number_Generator
#define _RAND_ADDR 0x3FF20E44UL
#else // ESP32
#endif // ESP8266
#ifdef ESP32
#define _RAND_ADDR 0x3FF75144UL
#endif
#endif // ESP32
static uint32_t last_ccount = 0;
uint32_t ccount;
uint32_t result = 0;

View File

@ -91,12 +91,13 @@ bool UdpConnect(void)
udp_response_mutex = false;
udp_connected = true;
}
#else // ESP32
#endif // ESP8266
#ifdef ESP32
if (PortUdp.beginMulticast(WiFi.localIP(), IPAddress(239,255,255,250), 1900)) {
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_REJOINED));
udp_response_mutex = false;
udp_connected = true;
#endif
#endif // ESP32
}
if (!udp_connected) { // if connection failed
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_JOIN_FAILED));
@ -118,13 +119,14 @@ void PollUdp(void)
packet->buf[packet->len] = 0; // add NULL at the end of the packer
char * packet_buffer = (char*) &packet->buf;
int32_t len = packet->len;
#else // ESP32
#endif // ESP8266
#ifdef ESP32
while (PortUdp.parsePacket()) {
char packet_buffer[UDP_BUFFER_SIZE]; // buffer to hold incoming UDP/SSDP packet
int32_t len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1);
packet_buffer[len] = 0;
#endif
#endif // ESP32
AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet (%d)"), len);
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("\n%s"), packet_buffer);

View File

@ -84,9 +84,10 @@ const uint8_t MAX_GROUP_TOPICS = 4; // Max number of Group Topics
const uint8_t MAX_DEV_GROUP_NAMES = 4; // Max number of Device Group names
#ifdef ESP8266
const uint8_t MAX_ADCS = 1; // Max number of ESP8266 ADC pins
#else
#endif // ESP8266
#ifdef ESP32
const uint8_t MAX_ADCS = 8; // Max number of ESP32 ADC pins (ADC2 pins are unusable with Wifi enabled)
#endif
#endif // ESP32
const uint8_t MAX_HUE_DEVICES = 15; // Max number of Philips Hue device per emulation
const uint8_t MAX_ROTARIES = 2; // Max number of Rotary Encoders
@ -303,9 +304,10 @@ enum SettingsTextIndex { SET_OTAURL,
SET_TELEGRAM_TOKEN, SET_TELEGRAM_CHATID,
#ifdef ESP8266
SET_ADC_PARAM1,
#else // ESP32
#endif // ESP8266
#ifdef ESP32
SET_ADC_PARAM1, SET_ADC_PARAM2, SET_ADC_PARAM3, SET_ADC_PARAM4, SET_ADC_PARAM5, SET_ADC_PARAM6, SET_ADC_PARAM7, SET_ADC_PARAM8, // MAX_ADCS
#endif
#endif // ESP32
SET_SWITCH_TXT1, SET_SWITCH_TXT2, SET_SWITCH_TXT3, SET_SWITCH_TXT4, SET_SWITCH_TXT5, SET_SWITCH_TXT6, SET_SWITCH_TXT7, SET_SWITCH_TXT8, // MAX_SWITCHES
SET_SHD_PARAM,
SET_MAX };
@ -359,7 +361,8 @@ const SerConfu8 kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#else // ESP32
#endif // ESP8266
#ifdef ESP32
const uint32_t kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5N1, SERIAL_6N1, SERIAL_7N1, SERIAL_8N1,
SERIAL_5N2, SERIAL_6N2, SERIAL_7N2, SERIAL_8N2,
@ -368,7 +371,7 @@ const uint32_t kTasmotaSerialConfig[] PROGMEM = {
SERIAL_5O1, SERIAL_6O1, SERIAL_7O1, SERIAL_8O1,
SERIAL_5O2, SERIAL_6O2, SERIAL_7O2, SERIAL_8O2
};
#endif
#endif // ESP32
enum TuyaSupportedFunctions { TUYA_MCU_FUNC_NONE,
TUYA_MCU_FUNC_SWT1 = 1, TUYA_MCU_FUNC_SWT2, TUYA_MCU_FUNC_SWT3, TUYA_MCU_FUNC_SWT4,

View File

@ -720,7 +720,8 @@ typedef struct MYTMPLT8266 {
uint8_t flag;
} mytmplt8266; // 12 bytes
#else // ESP32
#endif // ESP8266
#ifdef ESP32
#define MAX_GPIO_PIN 40 // Number of supported GPIO
#define MIN_FLASH_PINS 4 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11)
@ -730,7 +731,7 @@ typedef struct MYTMPLT8266 {
// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839
const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOflashcFLFLolIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOAOAOIAIAIAIAIAIA";
#endif // ESP8266 or ESP32
#endif // ESP32
//********************************************************************************************
@ -2633,7 +2634,8 @@ const mytmplt8285 kModules8285[TMP_MAXMODULE_8266 - TMP_WEMOS] PROGMEM = {
}
};
#else // ESP32
#endif // ESP8266
#ifdef ESP32
/********************************************************************************************/
// Supported hardware modules

View File

@ -868,9 +868,10 @@ const WebServerDispatch_t WebServerDispatch[] PROGMEM = {
void WebServer_on(const char * prefix, void (*func)(void), uint8_t method = HTTP_ANY) {
#ifdef ESP8266
Webserver->on((const __FlashStringHelper *) prefix, (HTTPMethod) method, func);
#else
#endif // ESP8266
#ifdef ESP32
Webserver->on(prefix, (HTTPMethod) method, func);
#endif
#endif // ESP32
}
void StartWebserver(int type, IPAddress ipweb)
@ -2436,9 +2437,10 @@ void HandleInformation(void)
WSContentSend_P(PSTR("}1" D_UPTIME "}2%s"), GetUptime().c_str());
#ifdef ESP8266
WSContentSend_P(PSTR("}1" D_FLASH_WRITE_COUNT "}2%d at 0x%X"), Settings.save_flag, GetSettingsAddress());
#else
#endif // ESP8266
#ifdef ESP32
WSContentSend_P(PSTR("}1" D_FLASH_WRITE_COUNT "}2%d"), Settings.save_flag);
#endif
#endif // ESP32
WSContentSend_P(PSTR("}1" D_BOOT_COUNT "}2%d"), Settings.bootcount);
WSContentSend_P(PSTR("}1" D_RESTART_REASON "}2%s"), GetResetReason().c_str());
uint32_t maxfn = (TasmotaGlobal.devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : TasmotaGlobal.devices_present;
@ -2780,9 +2782,10 @@ void HandleUploadLoop(void)
#ifdef USE_ZIGBEE_EZSP
#ifdef ESP8266
else if ((SONOFF_ZB_BRIDGE == TasmotaGlobal.module_type) && (0xEB == upload.buf[0])) { // Check if this is a Zigbee bridge FW file
#else // ESP32
#endif // ESP8266
#ifdef ESP32
else if (PinUsed(GPIO_ZIGBEE_RX) && PinUsed(GPIO_ZIGBEE_TX) && (0xEB == upload.buf[0])) { // Check if this is a Zigbee bridge FW file
#endif // ESP8266 or ESP32
#endif // ESP32
// Read complete file into ESP8266 flash
// Current files are about 200k
Web.upload_error = ZigbeeUploadStep1Init(); // 1

View File

@ -1379,9 +1379,10 @@ void LightInit(void)
if (PinUsed(GPIO_PWM1, i)) {
#ifdef ESP8266
pinMode(Pin(GPIO_PWM1, i), OUTPUT);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
analogAttach(Pin(GPIO_PWM1, i), i);
#endif
#endif // ESP32
}
}
if (PinUsed(GPIO_ARIRFRCV)) {

View File

@ -87,12 +87,13 @@ const static uint8_t* z_dev_start = z_spi_start + 0x0800; // 0x402FF800 - 2
const static size_t z_spi_len = 0x1000; // 4kb blocks
const static size_t z_block_offset = 0x0800;
const static size_t z_block_len = 0x0800; // 2kb
#else // ESP32
#endif // ESP8266
#ifdef ESP32
uint8_t* z_dev_start;
const static size_t z_spi_len = 0x1000; // 4kb blocks
const static size_t z_block_offset = 0x0000; // No offset needed
const static size_t z_block_len = 0x1000; // 4kb
#endif
#endif // ESP32
// Each entry consumes 8 bytes
class Z_Flashentry {
@ -364,9 +365,10 @@ void saveZigbeeDevices(void) {
// copy the flash into RAM to make local change, and write back the whole buffer
#ifdef ESP8266
ESP.flashRead(z_spi_start_sector * SPI_FLASH_SEC_SIZE, (uint32_t*) spi_buffer, SPI_FLASH_SEC_SIZE);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
ZigbeeRead(&spi_buffer, z_spi_len);
#endif // ESP8266 - ESP32
#endif // ESP32
Z_Flashentry *flashdata = (Z_Flashentry*)(spi_buffer + z_block_offset);
flashdata->name = ZIGB_NAME2; // v2
@ -381,10 +383,11 @@ void saveZigbeeDevices(void) {
ESP.flashWrite(z_spi_start_sector * SPI_FLASH_SEC_SIZE, (uint32_t*) spi_buffer, SPI_FLASH_SEC_SIZE);
}
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee Devices Data store in Flash (0x%08X - %d bytes)"), z_dev_start, buf_len);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
ZigbeeWrite(&spi_buffer, z_spi_len);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee Devices Data saved in %s (%d bytes)"), PSTR("Flash"), buf_len);
#endif // ESP8266 - ESP32
#endif // ESP32
free(spi_buffer);
}
@ -414,10 +417,11 @@ void eraseZigbeeDevices(void) {
free(spi_buffer);
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee Devices Data erased in %s"), PSTR("Flash"));
#else // ESP32
#endif // ESP8266
#ifdef ESP32
ZigbeeErase();
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_ZIGBEE "Zigbee Devices Data erased (%d bytes)"), z_block_len);
#endif // ESP8266 - ESP32
#endif // ESP32
}
#endif // USE_ZIGBEE

View File

@ -71,9 +71,10 @@ void ZigbeeInit(void)
uint32_t esp_id = ESP_getChipId();
#ifdef ESP8266
uint32_t flash_id = ESP.getFlashChipId();
#else // ESP32
#endif // ESP8266
#ifdef ESP32
uint32_t flash_id = 0;
#endif // ESP8266 or ESP32
#endif // ESP32
uint16_t pan_id = (mac64 & 0x3FFF);
if (0x0000 == pan_id) { pan_id = 0x0001; } // avoid extreme values
@ -1152,7 +1153,7 @@ void CmndZbLight(void) {
}
Z_attribute_list attr_list;
device.jsonLightState(attr_list);
device.jsonPublishAttrList(PSTR(D_PRFX_ZB D_CMND_ZIGBEE_LIGHT), attr_list); // publish as ZbReceived
ResponseCmndDone();

View File

@ -73,10 +73,11 @@ void DeepSleepReInit(void)
RtcRebootReset();
#ifdef ESP8266
ESP.deepSleep(100 * RtcSettings.deepsleep_slip * (DEEPSLEEP_MAX_CYCLE < RtcSettings.ultradeepsleep ? DEEPSLEEP_MAX_CYCLE : RtcSettings.ultradeepsleep), WAKE_RF_DEFAULT);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
esp_sleep_enable_timer_wakeup(100 * RtcSettings.deepsleep_slip * (DEEPSLEEP_MAX_CYCLE < RtcSettings.ultradeepsleep ? DEEPSLEEP_MAX_CYCLE : RtcSettings.ultradeepsleep));
esp_deep_sleep_start();
#endif // ESP8266 or ESP32
#endif // ESP32
yield();
// Sleeping
}
@ -143,10 +144,11 @@ void DeepSleepStart(void)
RtcSettingsSave();
#ifdef ESP8266
ESP.deepSleep(100 * RtcSettings.deepsleep_slip * deepsleep_sleeptime);
#else // ESP32
#endif // ESP8266
#ifdef ESP32
esp_sleep_enable_timer_wakeup(100 * RtcSettings.deepsleep_slip * deepsleep_sleeptime);
esp_deep_sleep_start();
#endif // ESP8266 or ESP32
#endif // ESP32
yield();
}

View File

@ -133,9 +133,10 @@ extern "C" {
struct icmp_echo_hdr *iecho;
#ifdef ESP8266
ping_target.addr = ping->ip;
#else
#endif // ESP8266
#ifdef ESP32
ping_target.u_addr.ip4.addr = ping->ip;
#endif
#endif // ESP32
iecho = (struct icmp_echo_hdr *) p->payload;
t_ping_prepare_echo(iecho, ping_size, ping);
@ -172,9 +173,10 @@ extern "C" {
static uint8_t ICACHE_FLASH_ATTR t_ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) {
#ifdef ESP8266
Ping_t *ping = t_ping_find(addr->addr);
#else
#endif // ESP8266
#ifdef ESP32
Ping_t *ping = t_ping_find(addr->u_addr.ip4.addr);
#endif
#endif // ESP32
if (nullptr == ping) { // unknown source address
return 0; // don't eat the packet and ignore it
@ -249,7 +251,7 @@ extern "C" {
uint32_t ip = ipfull;
if (0xFFFFFFFF == ip) { return -2; } // invalid address
// check if pings are already ongoing for this IP
if (t_ping_find(ip)) {
return -1;

View File

@ -58,11 +58,12 @@ void *mp3ram = NULL;
#ifdef ESP8266
const int preallocateBufferSize = 5*1024;
const int preallocateCodecSize = 29192; // MP3 codec max mem needed
#else
#endif // ESP8266
#ifdef ESP32
const int preallocateBufferSize = 16*1024;
const int preallocateCodecSize = 29192; // MP3 codec max mem needed
//const int preallocateCodecSize = 85332; // AAC+SBR codec max mem needed
#endif
#endif // ESP32
#ifdef USE_WEBRADIO
AudioFileSourceICYStream *ifile = NULL;
@ -80,6 +81,14 @@ AudioGeneratorTalkie *talkie = nullptr;
#endif
//! MAX98357A + INMP441 DOUBLE I2S BOARD
#ifdef ESP8266
#undef TWATCH_DAC_IIS_BCK
#undef TWATCH_DAC_IIS_WS
#undef TWATCH_DAC_IIS_DOUT
#define TWATCH_DAC_IIS_BCK 15
#define TWATCH_DAC_IIS_WS 2
#define TWATCH_DAC_IIS_DOUT 3
#endif // ESP8266
#ifdef ESP32
#undef TWATCH_DAC_IIS_BCK
#undef TWATCH_DAC_IIS_WS
@ -87,15 +96,7 @@ AudioGeneratorTalkie *talkie = nullptr;
#define TWATCH_DAC_IIS_BCK 26
#define TWATCH_DAC_IIS_WS 25
#define TWATCH_DAC_IIS_DOUT 33
#else
#undef TWATCH_DAC_IIS_BCK
#undef TWATCH_DAC_IIS_WS
#undef TWATCH_DAC_IIS_DOUT
#define TWATCH_DAC_IIS_BCK 15
#define TWATCH_DAC_IIS_WS 2
#define TWATCH_DAC_IIS_DOUT 3
#endif
#endif // ESP32
#ifdef SAY_TIME
long timezone = 2;
@ -203,7 +204,7 @@ void I2S_Init(void) {
out = new AudioOutputI2S();
#ifdef ESP32
out->SetPinout(TWATCH_DAC_IIS_BCK, TWATCH_DAC_IIS_WS, TWATCH_DAC_IIS_DOUT);
#endif
#endif // ESP32
#else
out = new AudioOutputI2S(0, 1);
#endif

View File

@ -205,7 +205,8 @@ void DebugFreeMem(void)
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, FreeStack %d (%s)"), ESP.getFreeHeap(), 4 * (sp - g_pcont->stack), XdrvMailbox.data);
}
#else // ESP32
#endif // ESP8266
#ifdef ESP32
void DebugFreeMem(void)
{
@ -281,6 +282,58 @@ void DebugRtcDump(char* parms)
/*******************************************************************************************/
void DebugDump(uint32_t start, uint32_t size) {
uint32_t CFG_COLS = 32;
uint32_t idx;
uint32_t maxrow;
uint32_t row;
uint32_t col;
char *p;
uint8_t *buffer = (uint8_t *)&start;
maxrow = ((start + size + CFG_COLS) / CFG_COLS);
uint32_t srow = 0;
uint32_t mrow = maxrow;
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
if (0 == mrow) { // Default only 8 lines
mrow = 8;
}
if (srow > maxrow) {
srow = maxrow - mrow;
}
if (mrow < (maxrow - srow)) {
maxrow = srow + mrow;
}
for (row = srow; row < maxrow; row++) {
idx = row * CFG_COLS;
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%03X:"), idx);
for (col = 0; col < CFG_COLS; col++) {
if (!(col%4)) {
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
}
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s %02X"), TasmotaGlobal.log_data, buffer[idx + col]);
}
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s |"), TasmotaGlobal.log_data);
for (col = 0; col < CFG_COLS; col++) {
// if (!(col%4)) {
// snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s "), TasmotaGlobal.log_data);
// }
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s%c"), TasmotaGlobal.log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
}
snprintf_P(TasmotaGlobal.log_data, sizeof(TasmotaGlobal.log_data), PSTR("%s|"), TasmotaGlobal.log_data);
AddLog(LOG_LEVEL_INFO);
delay(1);
}
}
void DebugCfgDump(char* parms)
{
#define CFG_COLS 16
@ -468,9 +521,10 @@ void CmndSerBufSize(void)
}
#ifdef ESP8266
ResponseCmndNumber(Serial.getRxBufferSize());
#else
#endif // ESP8266
#ifdef ESP32
ResponseCmndDone();
#endif
#endif // ESP32
}
void CmndFreemem(void)