Provide ESP32 base module support

This commit is contained in:
Theo Arends 2020-04-17 16:17:01 +02:00
parent 39440e56c2
commit 09599bb4a1
4 changed files with 81 additions and 67 deletions

View File

@ -100,7 +100,7 @@ uint32_t ResetReason(void)
REASON_EXT_SYS_RST = 6 // "External System" external system reset
*/
#ifdef ESP8266
return resetInfo.reason; // Returns Tasmota reason codes
return resetInfo.reason;
#else
return ESP_ResetInfoReason();
#endif
@ -1131,7 +1131,11 @@ void ModuleGpios(myio *gp)
if (USER_MODULE == Settings.module) {
memcpy(&src, &Settings.user_template.gp, sizeof(mycfgio));
} else {
#ifdef ESP8266
memcpy_P(&src, &kModules[Settings.module].gp, sizeof(mycfgio));
#else // ESP32
memcpy_P(&src, &kModules.gp, sizeof(mycfgio));
#endif // ESP8266 - ESP32
}
// 11 85 00 85 85 00 00 00 15 38 85 00 00 81
@ -1142,10 +1146,9 @@ void ModuleGpios(myio *gp)
#ifdef ESP8266
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
#endif // ESP8266
#ifdef ESP32
#else // ESP32
if (6 == i) { j = 12; }
#endif // ESP32
#endif // ESP8266 - ESP32
dest[j] = src[i];
j++;
}
@ -1158,11 +1161,24 @@ gpio_flag ModuleFlag(void)
{
gpio_flag flag;
#ifdef ESP8266
if (USER_MODULE == Settings.module) {
flag = Settings.user_template.flag;
} else {
memcpy_P(&flag, &kModules[Settings.module].flag, sizeof(gpio_flag));
}
#else // ESP32
if (USER_MODULE == Settings.module) {
/*
gpio_flag gpio_adc0;
memcpy_P(&gpio_adc0, &Settings.user_template.gp + ADC0_PIN - MIN_FLASH_PINS, sizeof(gpio_flag));
flag = Settings.user_template.flag.data + gpio_adc0.data;
*/
memcpy_P(&flag, &Settings.user_template.gp + ADC0_PIN - MIN_FLASH_PINS, sizeof(gpio_flag));
} else {
memcpy_P(&flag, &kModules.gp + ADC0_PIN - MIN_FLASH_PINS, sizeof(gpio_flag));
}
#endif // ESP8266 - ESP32
return flag;
}
@ -1173,7 +1189,11 @@ void ModuleDefault(uint32_t module)
Settings.user_template_base = module;
char name[TOPSZ];
SettingsUpdateText(SET_TEMPLATE_NAME, GetTextIndexed(name, sizeof(name), module, kModuleNames));
#ifdef ESP8266
memcpy_P(&Settings.user_template, &kModules[module], sizeof(mytmplt));
#else // ESP32
memcpy_P(&Settings.user_template, &kModules, sizeof(mytmplt));
#endif // ESP8266 - ESP32
}
void SetModuleType(void)

View File

@ -1117,10 +1117,9 @@ void CmndTemplate(void)
#ifdef ESP8266
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
#endif // ESP8266
#ifdef ESP32
#else // ESP32
if (6 == i) { j = 12; }
#endif // ESP32
#endif // ESP8266 - ESP32
if (my_module.io[j] > GPIO_NONE) {
Settings.user_template.gp.io[i] = my_module.io[j];
}

View File

@ -45,58 +45,61 @@
/********************************************************************************************/
// Supported hardware modules
enum SupportedModules {
WEMOS,
MAXMODULE
};
WEMOS, ESP32_CAM_AITHINKER,
MAXMODULE};
const char kModuleNames[] PROGMEM = "ESP32-DevKit";
const char kModuleNames[] PROGMEM =
"ESP32-DevKit|ESP32 Cam AiThinker";
// Default module settings
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = { WEMOS };
const uint8_t kModuleNiceList[MAXMODULE] PROGMEM = {
WEMOS,
ESP32_CAM_AITHINKER
};
const mytmplt kModules[MAXMODULE] PROGMEM = {
{ // WEMOS - Espressif ESP32-DevKitC - Any ESP32 device like WeMos and NodeMCU hardware (ESP32)
GPIO_USER, //0 (I)O GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK
GPIO_USER, //1 IO TXD0 GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2
GPIO_USER, //2 IO GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0
GPIO_USER, //3 IO RXD0 GPIO3, U0RXD, CLK_OUT2
GPIO_USER, //4 IO GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER
GPIO_USER, //5 IO GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK
//6 IO GPIO6, Flash CLK
//7 IO GPIO7, Flash D0
//8 IO GPIO8, Flash D1
//9 IO GPIO9, Flash D2
//10 IO GPIO10, Flash D3
//11 IO GPIO11, Flash CMD
GPIO_USER, //12 (I)O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3 (If driven High, flash voltage (VDD_SDIO) is 1.8V not default 3.3V. Has internal pull-down, so unconnected = Low = 3.3V. May prevent flashing and/or booting if 3.3V flash is connected and pulled high. See ESP32 datasheet for more details.)
GPIO_USER, //13 IO GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER
GPIO_USER, //14 IO GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2
GPIO_USER, //15 (I)O GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3 (If driven Low, silences boot messages from normal boot. Has internal pull-up, so unconnected = High = normal output.)
GPIO_USER, //16 IO GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT
GPIO_USER, //17 IO GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180
GPIO_USER, //18 IO GPIO18, VSPICLK, HS1_DATA7
GPIO_USER, //19 IO GPIO19, VSPIQ, U0CTS, EMAC_TXD0
0, //20
GPIO_USER, //21 IO GPIO21, VSPIHD, EMAC_TX_EN
GPIO_USER, //22 IO LED GPIO22, VSPIWP, U0RTS, EMAC_TXD1
GPIO_USER, //23 IO GPIO23, VSPID, HS1_STROBE
0, //24
GPIO_USER, //25 IO GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0
GPIO_USER, //26 IO GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1
GPIO_USER, //27 IO GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV
0, //28
0, //29
0, //30
0, //31
GPIO_USER, //32 IO GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9
GPIO_USER, //33 IO GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8
GPIO_USER, //34 I NO PULLUP GPIO34, ADC1_CH6, RTC_GPIO4
GPIO_USER, //35 I NO PULLUP GPIO35, ADC1_CH7, RTC_GPIO5
GPIO_USER, //36 I NO PULLUP GPIO36, SENSOR_VP, ADC_H, ADC1_CH0, RTC_GPIO0
0, //37 NO PULLUP
0, //38 NO PULLUP
GPIO_USER //39 I NO PULLUP GPIO39, SENSOR_VN, ADC1_CH3, ADC_H, RTC_GPIO3
}
const mytmplt kModules PROGMEM =
{ // WEMOS - Espressif ESP32-DevKitC - Any ESP32 device like WeMos and NodeMCU hardware (ESP32)
GPIO_USER, //0 (I)O GPIO0, ADC2_CH1, TOUCH1, RTC_GPIO11, CLK_OUT1, EMAC_TX_CLK
GPIO_USER, //1 IO TXD0 GPIO1, U0TXD, CLK_OUT3, EMAC_RXD2
GPIO_USER, //2 IO GPIO2, ADC2_CH2, TOUCH2, RTC_GPIO12, HSPIWP, HS2_DATA0, SD_DATA0
GPIO_USER, //3 IO RXD0 GPIO3, U0RXD, CLK_OUT2
GPIO_USER, //4 IO GPIO4, ADC2_CH0, TOUCH0, RTC_GPIO10, HSPIHD, HS2_DATA1, SD_DATA1, EMAC_TX_ER
GPIO_USER, //5 IO GPIO5, VSPICS0, HS1_DATA6, EMAC_RX_CLK
//6 IO GPIO6, Flash CLK
//7 IO GPIO7, Flash D0
//8 IO GPIO8, Flash D1
//9 IO GPIO9, Flash D2
//10 IO GPIO10, Flash D3
//11 IO GPIO11, Flash CMD
GPIO_USER, //12 (I)O GPIO12, ADC2_CH5, TOUCH5, RTC_GPIO15, MTDI, HSPIQ, HS2_DATA2, SD_DATA2, EMAC_TXD3 (If driven High, flash voltage (VDD_SDIO) is 1.8V not default 3.3V. Has internal pull-down, so unconnected = Low = 3.3V. May prevent flashing and/or booting if 3.3V flash is connected and pulled high. See ESP32 datasheet for more details.)
GPIO_USER, //13 IO GPIO13, ADC2_CH4, TOUCH4, RTC_GPIO14, MTCK, HSPID, HS2_DATA3, SD_DATA3, EMAC_RX_ER
GPIO_USER, //14 IO GPIO14, ADC2_CH6, TOUCH6, RTC_GPIO16, MTMS, HSPICLK, HS2_CLK, SD_CLK, EMAC_TXD2
GPIO_USER, //15 (I)O GPIO15, ADC2_CH3, TOUCH3, MTDO, HSPICS0, RTC_GPIO13, HS2_CMD, SD_CMD, EMAC_RXD3 (If driven Low, silences boot messages from normal boot. Has internal pull-up, so unconnected = High = normal output.)
GPIO_USER, //16 IO GPIO16, HS1_DATA4, U2RXD, EMAC_CLK_OUT
GPIO_USER, //17 IO GPIO17, HS1_DATA5, U2TXD, EMAC_CLK_OUT_180
GPIO_USER, //18 IO GPIO18, VSPICLK, HS1_DATA7
GPIO_USER, //19 IO GPIO19, VSPIQ, U0CTS, EMAC_TXD0
0, //20
GPIO_USER, //21 IO GPIO21, VSPIHD, EMAC_TX_EN
GPIO_USER, //22 IO LED GPIO22, VSPIWP, U0RTS, EMAC_TXD1
GPIO_USER, //23 IO GPIO23, VSPID, HS1_STROBE
0, //24
GPIO_USER, //25 IO GPIO25, DAC_1, ADC2_CH8, RTC_GPIO6, EMAC_RXD0
GPIO_USER, //26 IO GPIO26, DAC_2, ADC2_CH9, RTC_GPIO7, EMAC_RXD1
GPIO_USER, //27 IO GPIO27, ADC2_CH7, TOUCH7, RTC_GPIO17, EMAC_RX_DV
0, //28
0, //29
0, //30
0, //31
GPIO_USER, //32 IO GPIO32, XTAL_32K_P (32.768 kHz crystal oscillator input), ADC1_CH4, TOUCH9, RTC_GPIO9
GPIO_USER, //33 IO GPIO33, XTAL_32K_N (32.768 kHz crystal oscillator output), ADC1_CH5, TOUCH8, RTC_GPIO8
GPIO_USER, //34 I NO PULLUP GPIO34, ADC1_CH6, RTC_GPIO4
GPIO_USER, //35 I NO PULLUP GPIO35, ADC1_CH7, RTC_GPIO5
GPIO_USER, //36 I NO PULLUP GPIO36, SENSOR_VP, ADC_H, ADC1_CH0, RTC_GPIO0
0, //37 NO PULLUP
0, //38 NO PULLUP
GPIO_USER, //39 I NO PULLUP GPIO39, SENSOR_VN, ADC1_CH3, ADC_H, RTC_GPIO3
0 // Flag
};
#endif // ESP32

View File

@ -261,21 +261,18 @@ const char HTTP_SCRIPT_TEMPLATE[] PROGMEM =
"as=o.shift();" // Complete ADC0 list
"g=o.shift().split(',');" // Array separator
"j=0;"
// "for(i=0;i<13;i++){" // Supports 13 GPIOs
"for(i=0;i<" STR(MAX_USER_PINS) ";i++){" // Supports 13 GPIOs
#ifdef ESP8266
"if(6==i){j=9;}"
"if(8==i){j=12;}"
#endif
#ifdef ESP32
#else // ESP32
"if(6==i){j=12;}"
#endif
#endif // ESP8266 - ESP32
"sk(g[i],j);" // Set GPIO
"j++;"
"}"
"g=o.shift();" // FLAG
"os=as;"
// "sk(g&15,17);" // Set ADC0
"sk(g&15," STR(ADC0_PIN) ");" // Set ADC0
"g>>=4;"
"for(i=0;i<" STR(GPIO_FLAG_USED) ";i++){"
@ -295,7 +292,6 @@ const char HTTP_SCRIPT_TEMPLATE[] PROGMEM =
"function x2(a){"
"os=a.responseText;"
// "sk(17,99);" // 17 = WEMOS
"sk(" STR(WEMOS_MODULE) ",99);" // 17 = WEMOS
"st(" STR(USER_MODULE) ");"
"}"
@ -321,13 +317,11 @@ const char HTTP_SCRIPT_MODULE2[] PROGMEM =
"}"
"function x3(a){" // ADC0
"os=a.responseText;"
// "sk(%d,17);"
"sk(%d," STR(ADC0_PIN) ");"
"}"
"function sl(){"
"ld('md?m=1',x1);" // ?m related to Webserver->hasArg("m")
"ld('md?g=1',x2);" // ?g related to Webserver->hasArg("g")
// "if(eb('g17')){"
"if(eb('g" STR(ADC0_PIN) "')){"
"ld('md?a=1',x3);" // ?a related to Webserver->hasArg("a")
"}"
@ -1532,10 +1526,9 @@ void TemplateSaveSettings(void)
#ifdef ESP8266
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
#endif // ESP8266
#ifdef ESP32
#else // ESP32
if (6 == i) { j = 12; }
#endif // ESP32
#endif // ESP8266 - ESP32
snprintf_P(webindex, sizeof(webindex), PSTR("g%d"), j);
WebGetArg(webindex, tmp, sizeof(tmp)); // GPIO
uint8_t gpio = atoi(tmp);
@ -1543,7 +1536,6 @@ void TemplateSaveSettings(void)
j++;
}
// WebGetArg("g17", tmp, sizeof(tmp)); // FLAG - ADC0
WebGetArg("g" STR(ADC0_PIN), tmp, sizeof(tmp)); // FLAG - ADC0
uint32_t flag = atoi(tmp);
for (uint32_t i = 0; i < GPIO_FLAG_USED; i++) {