Merge pull request #12320 from s-hadinger/esp32c3_phase_1

Add preliminary support for Esp32C3 - RiscV based
This commit is contained in:
Theo Arends 2021-06-08 22:03:50 +02:00 committed by GitHub
commit 10646ac28e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 1 deletions

View File

@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- Allow longer MQTT response messages by removing fixed memory buffer with size 1040 to heap allocated buffer
- Command ``Timers`` layout of JSON message changed to single line
- Command ``Gpio`` layout of JSON message changed to single line
- Add preliminary support for Esp32C3 - RiscV based
## [9.4.0.4]
### Added

View File

@ -985,6 +985,7 @@ String GetSerialConfig(void) {
}
uint32_t GetSerialBaudrate(void) {
// Serial.printf(">> GetSerialBaudrate baudrate = %d\n", Serial.baudRate());
return (Serial.baudRate() / 300) * 300; // Fix ESP32 strange results like 115201
}
@ -1018,7 +1019,9 @@ void SetSerialBaudrate(uint32_t baudrate) {
TasmotaGlobal.baudrate = baudrate;
Settings.baudrate = TasmotaGlobal.baudrate / 300;
if (GetSerialBaudrate() != TasmotaGlobal.baudrate) {
#if defined(CONFIG_IDF_TARGET_ESP32C3) && !CONFIG_IDF_TARGET_ESP32C3 // crashes on ESP32C3 - TODO
SetSerialBegin();
#endif
}
}
@ -1574,8 +1577,11 @@ void TemplateGpios(myio *gp)
uint32_t j = 0;
for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) {
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3
#else
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
#endif
dest[j] = src[i];
j++;
}
@ -1628,7 +1634,20 @@ void SetModuleType(void)
bool FlashPin(uint32_t pin)
{
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3
return (pin > 10) && (pin < 18); // ESP32C3 has GPIOs 11-17 reserved for Flash
#else // ESP32 and ESP8266
return (((pin > 5) && (pin < 9)) || (11 == pin));
#endif
}
bool RedPin(uint32_t pin) // pin may be dangerous to change, display in RED in template console
{
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3
return false; // no red pin on ESP32C3
#else // ESP32 and ESP8266
return (9==pin)||(10==pin);
#endif
}
uint32_t ValidPin(uint32_t pin, uint32_t gpio) {

View File

@ -1404,8 +1404,11 @@ void CmndTemplate(void)
SettingsUpdateText(SET_TEMPLATE_NAME, PSTR("Merged"));
uint32_t j = 0;
for (uint32_t i = 0; i < nitems(Settings.user_template.gp.io); i++) {
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3
#else
if (6 == i) { j = 9; }
if (8 == i) { j = 12; }
#endif
if (TasmotaGlobal.my_module.io[j] > GPIO_NONE) {
Settings.user_template.gp.io[i] = TasmotaGlobal.my_module.io[j];
}

View File

@ -1815,11 +1815,19 @@ void GpioInit(void)
}
// Set any non-used GPIO to INPUT - Related to resetPins() in support_legacy_cores.ino
// Doing it here solves relay toggles at restart.
#if CONFIG_IDF_TARGET_ESP32C3
else if (((i < 11) || (i > 17)) && (GPIO_NONE == mpin)) { // Skip SPI flash interface
if (!((20 == i) || (21 == i))) { // Skip serial
pinMode(i, INPUT);
}
}
#else // CONFIG_IDF_TARGET_ESP32C3
else if (((i < 6) || (i > 11)) && (GPIO_NONE == mpin)) { // Skip SPI flash interface
if (!((1 == i) || (3 == i))) { // Skip serial
pinMode(i, INPUT);
}
}
#endif // CONFIG_IDF_TARGET_ESP32C3
}
// Digital input

View File

@ -977,6 +977,17 @@ typedef struct MYTMPLT8266 {
#endif // ESP8266
#ifdef ESP32
#if CONFIG_IDF_TARGET_ESP32C3
#define MAX_GPIO_PIN 22 // Number of supported GPIO
#define MIN_FLASH_PINS 0 // Number of flash chip pins unusable for configuration (GPIO6, 7, 8 and 11)
#define MAX_USER_PINS 22 // MAX_GPIO_PIN - MIN_FLASH_PINS
#define WEMOS_MODULE 0 // Wemos module
// 0 1 2 3 4 5 6 7 8 9101112131415161718192021
const char PINS_WEMOS[] PROGMEM = "AOAOAOAOAOAOIOIOIOIOIOFLFLFLFLFLFLFLIOIORXTX";
#else // v CONFIG_IDF_TARGET_ESP32C3 v
#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)
@ -986,6 +997,7 @@ typedef struct MYTMPLT8266 {
// 0 1 2 3 4 5 6 7 8 9101112131415161718192021222324252627282930313233343536373839
const char PINS_WEMOS[] PROGMEM = "IOTXIORXIOIOflashcFLFLolIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOIOAOAOIAIAIAIAIAIA";
#endif // CONFIG_IDF_TARGET_ESP32C3
#endif // ESP32
//********************************************************************************************
@ -2443,6 +2455,63 @@ const mytmplt8285 kModules8285[TMP_MAXMODULE_8266 - TMP_WEMOS] PROGMEM = {
#endif // ESP8266
#ifdef ESP32
#if CONFIG_IDF_TARGET_ESP32C3
/********************************************************************************************\
* ESP32 Module templates
\********************************************************************************************/
#define USER_MODULE 255
// Supported hardware modules
enum SupportedModules {
WEMOS,
MAXMODULE };
// Default module settings
const uint8_t kModuleNiceList[] PROGMEM = {
WEMOS,
};
// !!! Update this list in the same order as kModuleNiceList !!!
const char kModuleNames[] PROGMEM =
"ESP32C3|"
;
// !!! Update this list in the same order as SupportedModules !!!
const mytmplt kModules[] PROGMEM = {
{ // Generic ESP32C3 device
AGPIO(GPIO_USER), // 0 IO GPIO0, ADC1_CH0, XTAL_32K_P
AGPIO(GPIO_USER), // 1 IO GPIO1, ADC1_CH1, XTAL_32K_N
AGPIO(GPIO_USER), // 2 IO GPIO2, ADC1_CH2, FSPIQ
AGPIO(GPIO_USER), // 3 IO GPIO3, ADC1_CH3
AGPIO(GPIO_USER), // 4 IO GPIO4, ADC1_CH4, FSPIHD, MTMS
AGPIO(GPIO_USER), // 5 IO GPIO5, ADC2_CH0, FSPIWP, MTDI
AGPIO(GPIO_USER), // 6 IO GPIO6, FSPICLK, MTCK
AGPIO(GPIO_USER), // 7 IO GPIO7, FSPID, MTDO
AGPIO(GPIO_USER), // 8 IO GPIO8
AGPIO(GPIO_USER), // 9 IO GPIO9
AGPIO(GPIO_USER), // 10 IO GPIO10
0, // 11 IO GPIO11, output power supply for flash
0, // 12 IO GPIO12, SPIHD
0, // 13 IO GPIO13, SPIWP
0, // 14 IO GPIO14, SPICS0
0, // 15 IO GPIO15, SPICLK
0, // 16 IO GPIO16, SPID
0, // 17 IO GPIO17, SPIQ
AGPIO(GPIO_USER), // 18 IO GPIO18, USB_D
AGPIO(GPIO_USER), // 19 IO GPIO19, USB_D+
AGPIO(GPIO_USER), // 20 IO RXD0 GPIO20, U0RXD
AGPIO(GPIO_USER), // 21 IO TXD0 GPIO21, U0TXD
},
};
/*********************************************************************************************\
Known templates
\*********************************************************************************************/
#else // CONFIG_IDF_TARGET_ESP32C3 - now ESP32
/********************************************************************************************\
* ESP32 Module templates
\********************************************************************************************/
@ -2757,6 +2826,7 @@ const mytmplt kModules[] PROGMEM = {
\*********************************************************************************************/
#endif // CONFIG_IDF_TARGET_ESP32C3
#endif // ESP32
#endif // _TASMOTA_TEMPLATE_H_

View File

@ -146,6 +146,15 @@ const char HTTP_MODULE_TEMPLATE_REPLACE_NO_INDEX[] PROGMEM =
#include "./html_uncompressed/HTTP_SCRIPT_TEMPLATE.h"
#endif
#if defined(ESP32) && CONFIG_IDF_TARGET_ESP32C3
const char HTTP_SCRIPT_TEMPLATE2[] PROGMEM =
"j=0;"
"for(i=0;i<" STR(MAX_USER_PINS) ";i++){" // Skip GPIO 11-17
"if(11==i){j=18;}"
"sk(g[i],j);" // Set GPIO
"j++;"
"}";
#else // Now ESP32 and ESP8266
const char HTTP_SCRIPT_TEMPLATE2[] PROGMEM =
"j=0;"
"for(i=0;i<" STR(MAX_USER_PINS) ";i++){" // Supports 13 GPIOs
@ -154,6 +163,7 @@ const char HTTP_SCRIPT_TEMPLATE2[] PROGMEM =
"sk(g[i],j);" // Set GPIO
"j++;"
"}";
#endif
const char HTTP_SCRIPT_TEMPLATE3[] PROGMEM =
"\";"
"sk(g[13]," STR(ADC0_PIN) ");"; // Set ADC0
@ -1583,7 +1593,7 @@ void HandleTemplateConfiguration(void) {
for (uint32_t i = 0; i < MAX_GPIO_PIN; i++) {
if (!FlashPin(i)) {
WSContentSend_P(PSTR("<tr><td><b><font color='#%06x'>" D_GPIO "%d</font></b></td><td%s><select id='g%d' onchange='ot(%d,this.value)'></select></td>"),
((9==i)||(10==i)) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? PSTR(" style='width:146px'") : "", i, i);
RedPin(i) ? WebColor(COL_TEXT_WARNING) : WebColor(COL_TEXT), i, (0==i) ? PSTR(" style='width:146px'") : "", i, i);
WSContentSend_P(PSTR("<td style='width:54px'><select id='h%d'></select></td></tr>"), i);
}
}