lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
41 stars 50 forks source link

How are pin default pull downs working? #367

Closed microbit-carlos closed 11 months ago

microbit-carlos commented 11 months ago

On issue https://github.com/lancaster-university/codal-microbit-v2/issues/357 we agreed that for V1 compatibility the pin pull downs should be enabled by default, as also discussed in https://github.com/lancaster-university/codal-microbit-v2/issues/17.

Looking at NRF52Pin, it is probably achieved by having the default state in target.json/target-locked.json: https://github.com/lancaster-university/codal-microbit-v2/blob/3fa546f7ef5fd34cb9167b41045f8d7b6235b67e/target.json#L26

And that being applied in the NRF52Pin constructor. But this only sets the internal state of the NRF52Pin instance, it is only applied on first usage of get/setDigitalValue, when the setPull method is actually called:

However the MicroBitIO constructor, which will be executed after all the NRF52Pins have been constructed, it sets the internal pull state of the edge connector pins to PullNone and applies it:

https://github.com/lancaster-university/codal-microbit-v2/blob/4f2aedcd8e093e7ca9eefd574d4a647884e82505/model/MicroBitIO.cpp#L99-L101

So not 100% sure how the pull downs are configured by default.

microbit-carlos commented 11 months ago

Argh, as I re-read the issue, I notice that the loop is actually from pin19 forward, so we are good and there is no issue here 🙈