in libs/core/input.cpp [108:141]
static void registerEvent(int dpin, uint8_t type, Action body)
{
if (!body)
return;
int pin = dpin;
if ((pin >= (int)DigitalPin::D0) && (pin <= (int)DigitalPin::D5))
{
pin &= 0x7;
}
else if ((pin >= (int)AnalogPin::A0) && (pin <= (int)AnalogPin::A5))
{
pin &= 0x7;
}
else if ((pin >= 0) && (pin <= 5))
{
pin &= 0x7;
}
else
{
return;
}
spawnPinPollThread();
// Switch the pin to an input, and rely on the Schmitt trigger.
pinMode(pin, (int)PinMode::Input);
event_count++;
events = (InputEvent *)realloc((void *)events, sizeof(*events) * event_count);
incr(body);
events[event_count - 1].body = body;
events[event_count - 1].event_mask = make_event_mask(pin, 0, type, 0);
}