Skip to content

pinMode() breaks subtly when used with ESP32 #20

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

Open
novirium opened this issue May 12, 2023 · 0 comments
Open

pinMode() breaks subtly when used with ESP32 #20

novirium opened this issue May 12, 2023 · 0 comments

Comments

@novirium
Copy link

As implemented, pinMode() uses an additional pin mode constant to set the pin up with the LED driver:

#define ANALOG_OUTPUT 0x3

This collides with the constant used for OUTPUT in the ESP32 Arduino core:

#define OUTPUT            0x03

The result is that when setting the pin mode to OUTPUT, the pin is inadvertently set up in the ANALOG_OUTPUT LED driver mode, rather than the plain output GPIO mode. This isn't immediately obvious, as writing high or low to the pin will still work, but other things will break (I found it because once set as a LED output it disables the input buffer for the pin, and so switching the pin back to an input no longer works).

The AVR core uses 0x00 to 0x02, and the ESP32 one uses 0x01 to 0x12 for pin modes, with analog being 0xC0. As far as I can tell, almost any other constant would work - though maybe pick something up the other end to reduce chance of hitting something else? 0xE0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant