Skip to content

pinMode() breaks subtly when used with ESP32 #20

Open
@novirium

Description

@novirium

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions