mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
[ESP32-S2] Add touch pins to ESP32Touch plugin + check valid GPIO I2C
This commit is contained in:
+69
-13
@@ -31,8 +31,11 @@
|
||||
// Share this bitmap among all instances of this plugin
|
||||
DRAM_ATTR uint32_t p097_pinTouched = 0;
|
||||
DRAM_ATTR uint32_t p097_pinTouchedPrev = 0;
|
||||
#ifdef ESP32S2
|
||||
DRAM_ATTR uint32_t p097_timestamp[15] = { 0 };
|
||||
#else
|
||||
DRAM_ATTR uint32_t p097_timestamp[10] = { 0 };
|
||||
|
||||
#endif
|
||||
|
||||
boolean Plugin_097(uint8_t function, struct EventStruct *event, String& string)
|
||||
{
|
||||
@@ -192,9 +195,9 @@ void P097_setEventParams(int pin, uint16_t threshold) {
|
||||
|
||||
if (getADC_gpio_info(pin, adc, ch, t)) {
|
||||
switch (t) {
|
||||
#ifndef ESP32S2
|
||||
#ifndef ESP32S2
|
||||
case 0: touchAttachInterrupt(T0, P097_got_T0, threshold); break;
|
||||
#endif
|
||||
#endif
|
||||
case 1: touchAttachInterrupt(T1, P097_got_T1, threshold); break;
|
||||
case 2: touchAttachInterrupt(T2, P097_got_T2, threshold); break;
|
||||
case 3: touchAttachInterrupt(T3, P097_got_T3, threshold); break;
|
||||
@@ -204,26 +207,46 @@ void P097_setEventParams(int pin, uint16_t threshold) {
|
||||
case 7: touchAttachInterrupt(T7, P097_got_T7, threshold); break;
|
||||
case 8: touchAttachInterrupt(T8, P097_got_T8, threshold); break;
|
||||
case 9: touchAttachInterrupt(T9, P097_got_T9, threshold); break;
|
||||
#ifdef ESP32S2
|
||||
/*
|
||||
case 10: touchAttachInterrupt(T10, P097_got_T10, threshold); break;
|
||||
case 11: touchAttachInterrupt(T11, P097_got_T11, threshold); break;
|
||||
case 12: touchAttachInterrupt(T12, P097_got_T12, threshold); break;
|
||||
case 13: touchAttachInterrupt(T13, P097_got_T13, threshold); break;
|
||||
case 14: touchAttachInterrupt(T14, P097_got_T14, threshold); break;
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void P097_got_T0() ICACHE_RAM_ATTR;
|
||||
void P097_got_T1() ICACHE_RAM_ATTR;
|
||||
void P097_got_T2() ICACHE_RAM_ATTR;
|
||||
void P097_got_T3() ICACHE_RAM_ATTR;
|
||||
void P097_got_T4() ICACHE_RAM_ATTR;
|
||||
void P097_got_T5() ICACHE_RAM_ATTR;
|
||||
void P097_got_T6() ICACHE_RAM_ATTR;
|
||||
void P097_got_T7() ICACHE_RAM_ATTR;
|
||||
void P097_got_T8() ICACHE_RAM_ATTR;
|
||||
void P097_got_T9() ICACHE_RAM_ATTR;
|
||||
#ifndef ESP32S2
|
||||
void P097_got_T0() IRAM_ATTR;
|
||||
#endif
|
||||
void P097_got_T1() IRAM_ATTR;
|
||||
void P097_got_T2() IRAM_ATTR;
|
||||
void P097_got_T3() IRAM_ATTR;
|
||||
void P097_got_T4() IRAM_ATTR;
|
||||
void P097_got_T5() IRAM_ATTR;
|
||||
void P097_got_T6() IRAM_ATTR;
|
||||
void P097_got_T7() IRAM_ATTR;
|
||||
void P097_got_T8() IRAM_ATTR;
|
||||
void P097_got_T9() IRAM_ATTR;
|
||||
#ifdef ESP32S2
|
||||
void P097_got_T10() IRAM_ATTR;
|
||||
void P097_got_T11() IRAM_ATTR;
|
||||
void P097_got_T12() IRAM_ATTR;
|
||||
void P097_got_T13() IRAM_ATTR;
|
||||
void P097_got_T14() IRAM_ATTR;
|
||||
#endif
|
||||
|
||||
#ifndef ESP32S2
|
||||
void P097_got_T0() {
|
||||
bitSet(p097_pinTouched, 0);
|
||||
|
||||
if (p097_timestamp[0] == 0) { p097_timestamp[0] = millis(); }
|
||||
}
|
||||
#endif
|
||||
|
||||
void P097_got_T1() {
|
||||
bitSet(p097_pinTouched, 1);
|
||||
@@ -279,6 +302,39 @@ void P097_got_T9() {
|
||||
if (p097_timestamp[9] == 0) { p097_timestamp[9] = millis(); }
|
||||
}
|
||||
|
||||
#ifdef ESP32S2
|
||||
void P097_got_T10() {
|
||||
bitSet(p097_pinTouched, 10);
|
||||
|
||||
if (p097_timestamp[10] == 0) { p097_timestamp[10] = millis(); }
|
||||
}
|
||||
|
||||
void P097_got_T11() {
|
||||
bitSet(p097_pinTouched, 11);
|
||||
|
||||
if (p097_timestamp[11] == 0) { p097_timestamp[11] = millis(); }
|
||||
}
|
||||
|
||||
void P097_got_T12() {
|
||||
bitSet(p097_pinTouched, 12);
|
||||
|
||||
if (p097_timestamp[12] == 0) { p097_timestamp[12] = millis(); }
|
||||
}
|
||||
|
||||
void P097_got_T13() {
|
||||
bitSet(p097_pinTouched, 13);
|
||||
|
||||
if (p097_timestamp[13] == 0) { p097_timestamp[13] = millis(); }
|
||||
}
|
||||
|
||||
void P097_got_T14() {
|
||||
bitSet(p097_pinTouched, 14);
|
||||
|
||||
if (p097_timestamp[14] == 0) { p097_timestamp[14] = millis(); }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif // ifdef ESP32
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,11 @@
|
||||
#define TASKS_MAX 32
|
||||
#endif
|
||||
#ifndef MAX_GPIO
|
||||
#define MAX_GPIO 39
|
||||
#ifdef ESP32S2
|
||||
#define MAX_GPIO 46
|
||||
#else
|
||||
#define MAX_GPIO 39
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "../Helpers/PortStatus.h"
|
||||
#include "../Helpers/StringConverter.h"
|
||||
|
||||
|
||||
//#include "../../ESPEasy-Globals.h"
|
||||
|
||||
#ifdef ESP32
|
||||
@@ -165,32 +166,34 @@ void hardwareInit()
|
||||
|
||||
void initI2C() {
|
||||
// configure hardware pins according to eeprom settings.
|
||||
if (Settings.Pin_i2c_sda != -1 && Settings.Pin_i2c_scl != -1)
|
||||
if (!validGpio(Settings.Pin_i2c_sda) ||
|
||||
!validGpio(Settings.Pin_i2c_scl))
|
||||
{
|
||||
addLog(LOG_LEVEL_INFO, F("INIT : I2C"));
|
||||
I2CSelectClockSpeed(false); // Set normal clock speed
|
||||
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
|
||||
return;
|
||||
}
|
||||
addLog(LOG_LEVEL_INFO, F("INIT : I2C"));
|
||||
I2CSelectClockSpeed(false); // Set normal clock speed
|
||||
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
|
||||
|
||||
if (Settings.WireClockStretchLimit)
|
||||
{
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("INIT : I2C custom clockstretchlimit:");
|
||||
log += Settings.WireClockStretchLimit;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
Wire.setClockStretchLimit(Settings.WireClockStretchLimit);
|
||||
#endif // if defined(ESP8266)
|
||||
if (Settings.WireClockStretchLimit)
|
||||
{
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("INIT : I2C custom clockstretchlimit:");
|
||||
log += Settings.WireClockStretchLimit;
|
||||
addLog(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
#if defined(ESP8266)
|
||||
Wire.setClockStretchLimit(Settings.WireClockStretchLimit);
|
||||
#endif // if defined(ESP8266)
|
||||
}
|
||||
|
||||
#ifdef FEATURE_I2CMULTIPLEXER
|
||||
|
||||
if (Settings.I2C_Multiplexer_ResetPin != -1) { // Initialize Reset pin to High if configured
|
||||
pinMode(Settings.I2C_Multiplexer_ResetPin, OUTPUT);
|
||||
digitalWrite(Settings.I2C_Multiplexer_ResetPin, HIGH);
|
||||
}
|
||||
#endif // ifdef FEATURE_I2CMULTIPLEXER
|
||||
if (Settings.I2C_Multiplexer_ResetPin != -1) { // Initialize Reset pin to High if configured
|
||||
pinMode(Settings.I2C_Multiplexer_ResetPin, OUTPUT);
|
||||
digitalWrite(Settings.I2C_Multiplexer_ResetPin, HIGH);
|
||||
}
|
||||
#endif // ifdef FEATURE_I2CMULTIPLEXER
|
||||
|
||||
// I2C Watchdog boot status check
|
||||
if (Settings.WDI2CAddress != 0)
|
||||
@@ -822,14 +825,16 @@ void addPredefinedRules(const GpioFactorySettingsStruct& gpio_settings) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ESP32S2
|
||||
#ifdef ESP32
|
||||
|
||||
// ********************************************************************************
|
||||
// Get info of a specific GPIO pin - ESP32-S2
|
||||
// Get info of a specific GPIO pin
|
||||
// ********************************************************************************
|
||||
bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning) {
|
||||
pinnr = -1; // ESP32 does not label the pins, they just use the GPIO number.
|
||||
|
||||
#ifdef ESP32S2
|
||||
|
||||
// Input GPIOs: 0-21, 26, 33-46
|
||||
// Output GPIOs: 0-21, 26, 33-45
|
||||
input = gpio <= 46;
|
||||
@@ -900,35 +905,8 @@ bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning)
|
||||
# endif // ifdef HAS_ETHERNET
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getGpioPullResistor(int gpio, bool& hasPullUp, bool& hasPullDown) {
|
||||
hasPullDown = false;
|
||||
hasPullUp = false;
|
||||
|
||||
int pinnr;
|
||||
bool input;
|
||||
bool output;
|
||||
bool warning;
|
||||
if (!getGpioInfo(gpio, pinnr, input, output, warning)) {
|
||||
return false;
|
||||
}
|
||||
if (gpio <= 45) {
|
||||
hasPullUp = true;
|
||||
hasPullDown = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef ESP32
|
||||
|
||||
// ********************************************************************************
|
||||
// Get info of a specific GPIO pin - classic ESP32
|
||||
// ********************************************************************************
|
||||
bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning) {
|
||||
pinnr = -1; // ESP32 does not label the pins, they just use the GPIO number.
|
||||
#else
|
||||
// ESP32 classic
|
||||
|
||||
// Input GPIOs: 0-19, 21-23, 25-27, 32-39
|
||||
// Output GPIOs: 0-19, 21-23, 25-27, 32-33
|
||||
@@ -997,6 +975,8 @@ bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning)
|
||||
|
||||
|
||||
# endif // ifdef HAS_ETHERNET
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1011,6 +991,14 @@ bool getGpioPullResistor(int gpio, bool& hasPullUp, bool& hasPullDown) {
|
||||
if (!getGpioInfo(gpio, pinnr, input, output, warning)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef ESP32S2
|
||||
if (gpio <= 45) {
|
||||
hasPullUp = true;
|
||||
hasPullDown = true;
|
||||
}
|
||||
#else
|
||||
// ESP32 classic
|
||||
if (gpio >= 34) {
|
||||
// For GPIO 34 .. 39, no pull-up nor pull-down.
|
||||
} else if (gpio == 12) {
|
||||
@@ -1021,12 +1009,12 @@ bool getGpioPullResistor(int gpio, bool& hasPullUp, bool& hasPullDown) {
|
||||
hasPullUp = true;
|
||||
hasPullDown = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ESP8266
|
||||
|
||||
// return true when pin can be used.
|
||||
@@ -1112,6 +1100,15 @@ bool getGpioPullResistor(int gpio, bool& hasPullUp, bool& hasPullDown) {
|
||||
|
||||
#endif
|
||||
|
||||
bool validGpio(int gpio) {
|
||||
if (gpio < 0 || gpio > MAX_GPIO) return false;
|
||||
int pinnr;
|
||||
bool input;
|
||||
bool output;
|
||||
bool warning;
|
||||
return getGpioInfo(gpio, pinnr, input, output, warning);
|
||||
}
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
@@ -1151,7 +1148,7 @@ bool getADC_gpio_info(int gpio_pin, int& adc, int& ch, int& t)
|
||||
}
|
||||
#else
|
||||
// Classic ESP32
|
||||
switch (gpio_pin) {
|
||||
switch (gpio_pin) {
|
||||
case -1: adc = 0; break; // Hall effect Sensor
|
||||
case 36: adc = 1; ch = 0; break;
|
||||
case 37: adc = 1; ch = 1; break;
|
||||
@@ -1180,10 +1177,8 @@ bool getADC_gpio_info(int gpio_pin, int& adc, int& ch, int& t)
|
||||
|
||||
int touchPinToGpio(int touch_pin)
|
||||
{
|
||||
#ifdef ESP32S2
|
||||
switch (touch_pin) {
|
||||
#ifndef ESP32S2
|
||||
case 0: return T0;
|
||||
#endif
|
||||
case 1: return T1;
|
||||
case 2: return T2;
|
||||
case 3: return T3;
|
||||
@@ -1193,16 +1188,31 @@ int touchPinToGpio(int touch_pin)
|
||||
case 7: return T7;
|
||||
case 8: return T8;
|
||||
case 9: return T9;
|
||||
#ifdef ESP32S2
|
||||
case 10: return T10;
|
||||
case 11: return T11;
|
||||
case 12: return T12;
|
||||
case 13: return T13;
|
||||
case 14: return T14;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
// ESP32 classic
|
||||
switch (touch_pin) {
|
||||
case 0: return T0;
|
||||
case 1: return T1;
|
||||
case 2: return T2;
|
||||
case 3: return T3;
|
||||
case 4: return T4;
|
||||
case 5: return T5;
|
||||
case 6: return T6;
|
||||
case 7: return T7;
|
||||
case 8: return T8;
|
||||
case 9: return T9;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,8 @@ bool getGpioInfo(int gpio, int& pinnr, bool& input, bool& output, bool& warning)
|
||||
|
||||
bool getGpioPullResistor(int gpio, bool& hasPullUp, bool& hasPullDown);
|
||||
|
||||
bool validGpio(int gpio);
|
||||
|
||||
|
||||
#ifdef ESP32
|
||||
|
||||
|
||||
Reference in New Issue
Block a user