Summary
The M5Core2 and the very similar M5Tough have 40 digital pins
See reference here: https://docs.m5stack.com/en/core/core2 as well as the constant declarations in the bottom part of the file.
Impact
Without this, Code that needs the total number of pins (e.g. firmata) doesn't show the higher pin numbers correctly.
* GPIO refactoring
GPIO now using ESP-IDF API on all chips.
LEDC interrupt fix removed - no longer needed.
Edited pins_arduino.h in variants according to changes in gpio.
* Edited analog channels functions