Skip to content

Commit 97d78bc

Browse files
authored
feat(gpio): warn user about digitalRead() used with non GPIO pin
1 parent b34be47 commit 97d78bc

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Diff for: cores/esp32/esp32-hal-gpio.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,10 @@ extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) {
182182
if (pin == RGB_BUILTIN) {
183183
return RGB_BUILTIN_storage;
184184
}
185-
#endif
186-
187-
// if the pin is not in GPIO mode, make it happen
188-
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) {
189-
__pinMode(pin, INPUT);
185+
#endif // RGB_BUILTIN
186+
// This work when the pin is set as GPIO and in INPUT mode. For all other pin functions, it may return inconsistent response
187+
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
188+
log_w("IO %i is not set as GPIO. digitalRead() may return an inconsistent value.");
190189
}
191190
return gpio_get_level((gpio_num_t)pin);
192191
}

0 commit comments

Comments
 (0)