microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
41 stars 22 forks source link

`pin.get_analog_period_microseconds()` returns `-1` if the pin has not been used yet with `write_analog()` #143

Open microbit-carlos opened 1 year ago

microbit-carlos commented 1 year ago

In comparison V1 returns the configured period (default is 20ms).

V1:

>>> pin0.get_analog_period_microseconds()
20000

V2:

>>> pin0.get_analog_period_microseconds()
-1
>>> pin0.write_analog(512)
>>> pin0.get_analog_period_microseconds()
20000

Looks like this is by design? as CODAL is not providing the data: https://github.com/microbit-foundation/micropython-microbit-v2/blob/fd99f400b42857b1094811cea76bd3fb841a8286/src/codal_app/microbithal.cpp#L172-L179

So if we cannot support this V1 compatibility we might need to update the docs.

microbit-carlos commented 11 months ago

The resolution of this issue should result in NRF52Pin::getAnalogPeriodUs() to not return DEVICE_NOT_SUPPORTED, so this should be fixed with a future CODAL update: