Do we have access to a direction register somewhere?

I’m looking for the equivalent of the port data direction registers on Arduino, and haven’t found it documented yet. I’m building a utility library that works a bit like Tinker, so it’s very helpful to be able to display whether a read value of 0 is real or just an output pin… and moreover, save some cycles and only read pins that are actually inputs.

Thoughts? Suggestions?

I’ve found a quite enlightening tutorial here′s-gpio-part-2/


In the feature/hal branch, we have HAL_Get_PinMode() to retrieve the current pin mode for a given pin. This would allow you to distinguish inputs from outputs.

Awesome @mdma, you have no idea how excited I am for HAL. We have any similar thing on ye olde firmware, or should I just wait for HAL to get pushed out for Cores?

on ye olde firmware, you can write

PinMode mode = PIN_MAP[pin].pin_mode;
if (mode==INPUT) {
  // ... got an input pin

HTH! :smile:


You are my favorite today, @mdma.

1 Like