Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gpio): allows mixing digital and analog read/write operations #11016

Merged
merged 9 commits into from
Mar 9, 2025
Next Next commit
feat(gpio): allows mixing digital and analog read/write operations
  • Loading branch information
SuGlider authored Feb 26, 2025
commit 130dbd6e6649edf1e0b5ed15d7f22e0b845087ab
17 changes: 8 additions & 9 deletions cores/esp32/esp32-hal-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ extern void ARDUINO_ISR_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
return;
}
#endif // RGB_BUILTIN
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
gpio_set_level((gpio_num_t)pin, val);
} else {
log_e("IO %i is not set as GPIO.", pin);
// if the pin is not in GPIO mode, make it happen
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) {
__pinMode(uint8_t pin, OUTPUT);
}
gpio_set_level((gpio_num_t)pin, val);
}

extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) {
Expand All @@ -184,12 +184,11 @@ extern int ARDUINO_ISR_ATTR __digitalRead(uint8_t pin) {
}
#endif

if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) != NULL) {
return gpio_get_level((gpio_num_t)pin);
} else {
log_e("IO %i is not set as GPIO.", pin);
return 0;
// if the pin is not in GPIO mode, make it happen
if (perimanGetPinBus(pin, ESP32_BUS_TYPE_GPIO) == NULL) {
__pinMode(uint8_t pin, INPUT);
}
return gpio_get_level((gpio_num_t)pin);
}

static void ARDUINO_ISR_ATTR __onPinInterrupt(void *arg) {
Expand Down
Loading