GPIO module calling standards
Tank (53) 374 posts |
Does anyone have any thoughts about the way the GPIO module sets the OE for example. On the Beagle it needs logic 0 to set as output, but on the Pi it uses logic 1. I have just followed the way the underlying hardware sets this ATM. |
Jeffrey Lee (213) 6048 posts |
I think you should make the APIs consistent across all machine types wherever possible. That way a simple program that just uses the SWI interface to interact with the GPIOs can easily be ported from one platform to another just by changing the GPIO numbers it’s using. For lower-level interfaces (your module provides pointers to the GPIO registers, IIRC?) I guess there’s not much that you can do except leave it down to the application developers to deal with any hardware differences. Either that or provide something at a slightly higher layer, e.g. pointers to functions to read/write the different register types, using a consistent API across all platforms. When I get a chance I’ll also hook up the GPIO HAL device for the Pi (maybe tonight if you’re lucky!) Also I suspect this kind of discussion is more suited to the code review forum than community support. |
Tank (53) 374 posts |
Jeffrey, that was my thought, but… which standard do I make the default. |
Stephen Unwin (1516) 153 posts |
Don’t know if this helps, (probably not!) |
Tank (53) 374 posts |
Yes, sounds like the ideal answer…;-) It seems most of the rest of the “world” do use 0=Output, so unless there’s any objections…. |
Rick Murray (539) 13806 posts |
Sorry to throw a spanner in the works… but the 6522 VIA DDRA/DDRB uses 0 for input (high impedence), and 1 for output. Now, the thing is (and maybe new hardware is immune) the older hardware set the default power-up state to high impedence input (logic zero) so there is less/no chance of spurious output glitches at power-up. There’s no big deal to flipping/inverting bits in firmware/drivers – as anybody who has had to deal with parallel ports will know well. ;-) Best wishes, Rick. |