[En-Nut-Discussion] Unified GPIO implementation
Ulrich Prinz
uprinz2 at netscape.net
Wed Oct 6 21:22:18 CEST 2010
Am 06.10.2010 20:50, schrieb Thiago A. Corrêa:
> 2010/10/6 Thiago A. Corrêa<thiago.correa at gmail.com>:
>>
>> I thought about instead of ALTERNATE2, reuse the GPIO_CFG_PERIPHERAL0
>> which is already defined. But it might be a bit confusing to see that
>> in the Nutconf. Should we just define a new set of macros for the
>> config? Something along the lines of:
>>
>> #define ALTERNATE_PIN1 1
>> ...
>> #define ALTERNATE_PINn n
>>
>
> Replying to myself, on a second thought, GPIO_CFG_PERIPHERAL0 implies
> in the wrong concept here... really not suitable. Would mean it's the
> same set of pins just changing the peripheral it's connected to, which
> isn't true.
>
> Well, can't see any other way except a new "enumeration" of macros.
>
I don't know the AVR32 way. But as I saw that the STM32 does it totally
different, I decided to bind the pin config to the peripheral. So I have
to write a driver for each peripheral but who cares, someone needs to do
so, why not me :)
My set of GPIO options as a proposal:
Mandatory Set:
GPIO_CFG_INPUT Port as Input
GPIO_CFG_OUPUT Port as Output Open-Drain
GPIO_CFG_MULTIDRIVE Activate PullUp/Disable PushPull
GPIO_CFG_PUSHPULL Activate PushPull
GPIO_CFG_DISABLE Port disconnected from GPIO
GPIO_CFG_PERIPHERAL = GPIO_CFG_DISABLE
Optional Set:
GPIO_CFG_OUTPP Port as Output Push-Pull
GPIO_CFG_OUTOD Port as Output Open-Drain
GPIO_CFG_INPU Port as Input with PullUp
Optional STM specific:
GPIO_CFG_ANALOG Port as Input Analog
GPIO_CFG_OUT2M Port as Output 2MHz speed
GPIO_CFG_OUT10M Port as Output 10MHz speed
GPIO_CFG_OUT50M Port as Output 50MHz speed
I'd like to add GPIO_CFG_INPUT to the mandatory set even if will be 0x00
in AVR but it is clearly more readable as a simple 0 in the
GpioPinConfigSet( b, p, 0);
I'd like to modify GPIO_CFG_OUPUT to be Open-Drain for architectures
that support OD and PushPull. It will save your developments board life
if you start your first tries with Nut/OS on it.
With some CPUs PushPull is not a weak thing like it is in AVR, it really
hard ties the output to Vcc or Vss!
GPIO_CFG_OUTPP and _OUTOC is an abbreviation for the combination of
output + feature. It makes code more readable on non 24:9 monitors.
I can imagine that for ARM there might be some still missing functions
as these sometimes support additional filters on the pins.
For the functions I'd like to see:
** Mandatory **
Control a single pins option, return -1 if not available else 0
int GpioPinConfigSet( bank, pin, option);
int GpioPinConfigGet( bank, pin, option);
Control all pins options represented by the mask on that port:
int GpioPortConfigSet( bank, mask, option);
int GpioPortConfigGet( bank, mask, option);
Set pin ( val != 0 means pin high)
void GpioPinSet( bank, pin, val);
void GpioPinSetHigh( bank, pin);
void GpioPinSetLow( baank, pin);
Set all pins represented by the bits in mask
void GpioPortSet( bank, mask, val);
void GpioPortSetHigh( bank, mask);
void GpioPortSetLow( bank, mask);
Remarks:
For STM any peripheral that will be used has to get connected to the
clock. For not introducing additional functions I connect the clock in
GpioPortConfigSet() automatically.
I intentionally didn't write any types for the parameters as these might
be architecture specific as discussed before.
Best regards
Ulrich
More information about the En-Nut-Discussion
mailing list