esp32_adc2gpio not declared in pins_arduino.h for M5StickCPlus
-
The file
pins_arduino.hin the 2.0.5 board files for the M5Stick-C-Plus contains a macro definition that refers to an arrayesp32_adc2gpiothat appears to be undefined and causes a compile error. I first ran into the problem when trying to compile a Blynk Quickstart example.Comparing this with the
pins_arduino.hfiles for other M5Stack devices including Atom, Stick-C, and Core2, I noticed that they do not refer toesp32_adc2gpio, but instead call a functionanalogChannelToDigitalPinthat compiles properly. Is this a bug for Stick-C-Plus and should it call the same function as the Stick-C and other devices? Any insights/comments would be appreciated!Here's a bunch more detail on what I've found.
Here's the macro definition from the file
packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus\pins_arduino.h#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)Note that the same macro is also used in the
pins_arduino.hfiles for several other device variants, includingm5stack_paperandm5stack_tough.Here's a simple sketch that causes a compile error related that uses the macro:
void setup() { analogInputToDigitalPin(5); } void loop() { }Here's the error I get:
C:\Users\xxx\AppData\Local\Arduino15\packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus/pins_arduino.h:10:48: error: 'esp32_adc2gpio' was not declared in this scope #define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)When I searched the entire m5stack for
esp32_adc2gpiousinggrep -r, it wasn't anywhere to be found.If I change the device to M5Stack-Atom, it compiles fine.
I looked at the
pins_arduino.hfiles for a few other device variants and saw that they use a different definition for the macro. For variantsm5stack_atomandm5stick_c, the macroanalogInputToDigitalPinis defined as:#define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)The function
analogChannelToDigitalPinis defined inpackages\m5stack\hardware\esp32\2.0.5\cores\esp32\esp32-hal-gpio.cThis function refers to another array calledadc_channel_io_mapthat does appear to be defined in the esp32 library archive files according to grep:(base) PS C:\Users\xxx\Downloads\m5stack-2.0.5\m5stack-2.0.5> grep -r adc_channel_io_map . ./cores/esp32/esp32-hal-gpio.c: if (adc_channel_io_map[i][j] == pin) { ./cores/esp32/esp32-hal-gpio.c: return adc_channel_io_map[adc_unit][adc_chan]; ./tools/sdk/esp32/include/soc/include/soc/adc_periph.h:extern const int adc_channel_io_map[SOC_ADC_PERIPH_NUM][SOC_ADC_MAX_CHANNEL_NUM]; Binary file ./tools/sdk/esp32/lib/libdriver.a matches Binary file ./tools/sdk/esp32/lib/libhal.a matches Binary file ./tools/sdk/esp32/lib/libsoc.a matchesPerhaps the version of the macro
analogInputToDigitalPinfor the Stick-C-Plus is obsolete and should replaced with the version that callsanalogChannelToDigitalPin? Or maybe I'm missing something else? -
I replaced the macro
analogInputToDigitalPin(p)in the file packages\m5stack\hardware\esp32\2.0.5\variants\m5stick_c_plus\pins_arduino.h and it seemed to work://#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1) #define analogInputToDigitalPin(p) (((p)<20)?(analogChannelToDigitalPin(p)):-1)I tested it with the following sketch, which printed the correct sequence of mappings (36, 37, 38, 39, 32, 33, 34, 35, -1, -1, 4, 0, 2, 15, 13, 12, 14, 27, 25, 26):
#include <M5StickCPlus.h> void setup() { M5.begin(); M5.Lcd.fillScreen(RED); for (uint8_t i = 0; i < 20; i++) { Serial.println(analogInputToDigitalPin(i)); } } void loop() { }With this change, I was able to get the Blynk Quickstart example working with my M5StickCPlus, which is what led me down this rabbit hole in the first place!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login