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

http://hertaville.com/2012/07/28/stm32f0-gpio-tutorial-part-1/
http://hertaville.com/2012/09/01/understanding-the-stm32f0′s-gpio-part-2/

2 Likes

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:

2 Likes

You are my favorite today, @mdma.

1 Like