Repository navigation
machine.Pin: Implement Pin.toggle() for three ports. - #16607
Conversation
mattytrentini
left a comment
There was a problem hiding this comment.
LGTM (we should check toggle exists for all other ports too...)
|
So ports with a machine module missing
I can try to implement it for ESP8266 and CC3200, even it it may be waste of time for the latter. I have no hardware with Zephyr loaded, and I never dealt with Zephyr. And it depends a lot from the way, the functions |
|
Pin.toggle() is added for ESP8266 and CC3200 as well. |
|
Fantastic work @robert-hh! |
|
Then perhaps it's good to update the docs on this as well
|
|
That's right |
ecefc78 to
968e323
Compare
|
Note that the stm32 port does not have But in general it's not easy to implement this function. To make it work correctly you must be able to read the current output state of the pin, not the input state. For the three ports that you implemented |
|
When the Pin was set to OUT mode, the state of the Pin was inverted properly independent of the initial state. When set to OPEN_DRAIN mode, the ESP32 works fine. The ESP8266 toggles once from the initial value of 0 to 1, the CC3200 does not support OPEN_DRAIN. All if the Pin could change it's level and was not hard wired to GND or Vcc. But then it would anyhow not toggle. I did not check in detail whether the level is read back from the pad or the driver. I would assume it is reading the pad value, since the function used for the Pin input value is used. Edit: Checking the implementation for mimxrt and samd: there the output driver itself supports toggling, which is used by the code. I have to check whether is is supported by the ESP32 hardware. The API does not seem to support it. But it can be done by reading back the output register. Same for ESP8266, |
OK, thanks for checking. I think we should only implement
Please do. And if we need to do raw register access to read back the current state, I think that's what we should do. |
968e323 to
78b01e9
Compare
Done. ESP32 and ESP8266 use the output register value, while the CC3200 port already stored the actual set output value at the pin object. So that could be used. |
da04166 to
a4cdfbf
Compare
a4cdfbf to
e57acb5
Compare
|
All suggested comments implemented & tested. For ESP32 I tested the ESP32_GENERIC and ESP32_GENERIC_C3 board to cover all changed code. |
e57acb5 to
9c35aea
Compare
9c35aea to
dbee85b
Compare
The actual output pin value is taken from the OUT register, not from the pad. Tested with: - ESP32 low and high Pin numbers - ESP32C3 low Pin numbers - ESP32C6 low Pin numbers - ESP32S2 low and high Pin numbers - ESP32S3 low and high Pin numbers Signed-off-by: robert-hh <[email protected]>
Tested with a generic ESP8266 device. The actual output value is taken from the output register, not by reading the pad level. Signed-off-by: robert-hh <[email protected]>
Tested with a WiPy 1 board. Signed-off-by: robert-hh <[email protected]>
Signed-off-by: robert-hh <[email protected]>
dbee85b to
48925fd
Compare
|
Thank you. |
Summary
The ESP32, ESP8266 and CC3200 ports did not provide the method Pin.toggle(). This PR adds it.
Testing
Tested with: