Pin Info update

* Additional functions: isPinPWM, isPinINT
* aliases: PM_ADC1 instead of PinManagerClass::ADC1
* make getADCPin work on "classic ESP32"

--> Tested and works on 8266, ESP32 (default platform), ESP32 (V4 Platform). ESP32-S3, ESP32-S2, ESP32-C3
This commit is contained in:
Frank
2023-01-20 22:13:30 +01:00
parent 718cd0df8d
commit 5eb18a6173
4 changed files with 26 additions and 11 deletions

View File

@@ -662,7 +662,8 @@ bool PinManagerClass::joinWire(int8_t pinSDA, int8_t pinSCL) {
if (adcPort >= SOC_ADC_MAX_CHANNEL_NUM) analogChannel = 255;
#else // for classic ESP32
int8_t analogChannel = (adcUnit == ADC1) ? adcPort : (10 + adcPort);
if (adcPort >= 10) analogChannel = 255;
if ((adcUnit == ADC1) && (adcPort >= 8)) analogChannel = 127;
if (adcPort >= 10) analogChannel = 127;
#endif
//int analogPin = analogChannelToDigitalPin(analogChannel);

View File

@@ -131,13 +131,19 @@ class PinManagerClass {
String getPinSpecialText(int gpio); // WLEDMM - return PIN special comments (if any)
String getPinConflicts(int gpio); // WLEDMM - return PIN alloc conflicts (if any)
bool isPinTouch(int gpio); // true if gpio supports touch functions
bool isPinPWM(int gpio) {return(digitalPinHasPWM(gpio));} // true if gpio supports PWM
bool isPinINT(int gpio) {return(digitalPinToInterrupt(gpio) >= 0);} // true if gpio supports PWM
bool isPinTouch(int gpio); // true if gpio supports touch functions
bool isPinAnalog(int gpio); // true if gpio supports analogRead
bool isPinADC1(int gpio); // true if gpio supports analogRead, and it belongs to ADC unit 1
bool isPinADC2(int gpio); // true if gpio supports analogRead, and it belongs to ADC unit 2
#define PM_NO_PIN 255
bool isPinADC2(int gpio); // true if gpio supports analogRead, and it belongs to ADC unit 2
typedef enum { ADC_none = 0, ADC1 = 1, ADC2 = 2 } AdcIdentifier;
uint8_t getADCPin(AdcIdentifier adcUnit, uint8_t adcPort); // get GPIO number for ADC unit x, channel y. 255 = no such pin
#define PM_ADC1 PinManagerClass::ADC1 // Alias for ADC1
#define PM_ADC2 PinManagerClass::ADC2 // Alias for ADC2
#define PM_NO_PIN 255
uint8_t getADCPin(AdcIdentifier adcUnit, uint8_t adcPort); // get GPIO number for ADC unit x, channel y. 255 = no such pin
// WLEDMM end
#ifdef ARDUINO_ARCH_ESP32

View File

@@ -565,6 +565,14 @@ void WLED::setup()
if(pinManager.isPinOk(pinNr, false)) {
//if ((!pinManager.isPinAllocated(pinNr)) && (pinManager.getPinSpecialText(pinNr).length() == 0)) continue; // un-comment to hide no-name,unused GPIO pins
bool is_inOut = pinManager.isPinOk(pinNr, true);
#if 0 // for testing
USER_PRINT(pinManager.isPinAnalog(pinNr) ? "A": " ");
USER_PRINT(pinManager.isPinADC1(pinNr) ? "1": " ");
USER_PRINT(pinManager.isPinADC2(pinNr) ? "2": " ");
USER_PRINT(pinManager.isPinTouch(pinNr) ? "T": " ");
USER_PRINT(pinManager.isPinPWM(pinNr) ? " P": " ");
USER_PRINT(pinManager.isPinINT(pinNr) ? "I ": " ");
#endif
USER_PRINTF("%s %2d\t %-17s %s\t %s\n",
(is_inOut?"i/o":"in "),
pinNr,
@@ -579,17 +587,17 @@ void WLED::setup()
#if 0 // for testing
USER_PRINTLN(F("\n"));
USER_PRINTF("ADC1-0 = %d, ADC1-3 = %d, ADC1-7 = %d, ADC2-0 = %d, ADC2-1 = %d, ADC2-8 = %d, ADC2-10 = %d\n",
pinManager.getADCPin(PinManagerClass::ADC1, 0), pinManager.getADCPin(PinManagerClass::ADC1, 3), pinManager.getADCPin(PinManagerClass::ADC1, 7),
pinManager.getADCPin(PinManagerClass::ADC2, 0), pinManager.getADCPin(PinManagerClass::ADC2, 1), pinManager.getADCPin(PinManagerClass::ADC2, 8),
pinManager.getADCPin(PinManagerClass::ADC2, 10)
pinManager.getADCPin(PM_ADC1, 0), pinManager.getADCPin(PM_ADC1, 3), pinManager.getADCPin(PM_ADC1, 7),
pinManager.getADCPin(PM_ADC2, 0), pinManager.getADCPin(PM_ADC2, 1), pinManager.getADCPin(PM_ADC2, 8),
pinManager.getADCPin(PM_ADC2, 10)
);
USER_PRINTLN();
for(int p=0; p<12; p++) {
for(int p=0; p<11; p++) {
if(pinManager.getADCPin(PinManagerClass::ADC1, p) < 255)
USER_PRINTF("ADC1-%d = %d, ", p, pinManager.getADCPin(PinManagerClass::ADC1, p));
}
USER_PRINTLN();
for(int p=0; p<12; p++) {
for(int p=0; p<11; p++) {
if(pinManager.getADCPin(PinManagerClass::ADC2, p) < 255)
USER_PRINTF("ADC2-%d = %d, ", p, pinManager.getADCPin(PinManagerClass::ADC2, p));
}

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2301202
#define VERSION 2301203
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG