Skip to content

Commit efb02d3

Browse files
authored
feat(gpio): allows mixing digital and analog read/write operations (#11016)
* feat(gpio): allows mixing digital and analog read/write operations * fix(gpio): simple mistake in calling __pinMode() fnuction * fix(gpio): simple mistake in calling __pinMode() fnuction * feat(gpio): update the log message to tell the solution for the error. * feat(gpio): warn user about digitalRead() used with non GPIO pin * fix(gpio): wrong peripheral manager test case
1 parent fb5f11b commit efb02d3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

cores/esp32/esp32-hal-gpio.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
173173
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
174174
gpio_set_level((gpio_num_t)pin, val);
175175
} else {
176-
log_e("IO %i is not set as GPIO.", pin);
176+
log_e("IO %i is not set as GPIO. Execute digitalMode(%i, OUTPUT) first.", pin, pin);
177177
}
178178
}
179179

@@ -182,14 +182,12 @@ 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 (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
188-
return gpio_get_level((gpio_num_t)pin);
189-
} else {
190-
log_e("IO %i is not set as GPIO.", pin);
191-
return 0;
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.");
192189
}
190+
return gpio_get_level((gpio_num_t)pin);
193191
}
194192

195193
static void ARDUINO_ISR_ATTR __onPinInterrupt(void *arg) {

0 commit comments

Comments
 (0)