-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cpu/esp32: fix of gpio_read for output ports #11950
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
cpu/esp32: fix of gpio_read for output ports #11950
Conversation
While testing the Arduino example for ESP32 boards, the problem of gpio_read for output ports was figured out. During these tests, also the wrong comment has been fixed.
Although it isn't explicitly specified in API, gpio_read should return the last written output value for output ports. Since the handling of inputs and outputs is strictly separated by several registers in ESP32, gpio_read returned always the initial value of the input register. Therefore, a case distinction had to make. While for input ports the real value has to be read from the input register, the last written value for the output port has to be read from the output register.
@gschorcht would like to see this merged for 2019.10, but we need someone to confirm the fix. @yegorich, did you actually test this? |
Since it is a fix of a real bug, I would say yes. |
I've tested this PR on a TTGO T-Beam board (#11418). And everything is working as expected. |
Thanks for testing, @yegorich! Let me see if I can motivate a maintainer to inspect the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes make sense. I tested this on the esp32-wroom-32, both for pins below and above number 32, inputs and outputs, and works as expected. ACK!
Rebuilding once more just in case |
Thank you all for testing and merging. |
Contribution description
Although it isn't explicitly specified in API,
gpio_read
should return the last written output value for output ports. Since the handling of inputs and outputs is strictly separated by several registers in ESP32,gpio_read
returned always the initial value of the input register. Therefore,gpio_read
always returned0
for output ports.This PR fixes this problem. For this purpose, a case distinction is made in
gpio_read
. While for input ports the real value are read from the ESP32 input register, the last written value for the output port is read from the ESP32 output register.Testing procedure
Flash
tests/periph_gpio
with to ESP32 board, for example:Use the following commands:
Without this fix
read 0 4
would always returnGPIO_PIN(0.04) is LOW
.Issues/PRs references