>
> A good way to develop application code is to hide the hardware
> accesses behind an interface, eg. define a key-pad API, something
> as simple as
>
> keypad.h
> int keypad_init();
> int keypad_read();
>
> Then the implementation hides all the access
>
> keypad.c
>
> static volatile int *portdata = <port data register>;
> static volatile int *portdir = <port direction register>;
>
> int keypad_init()
> {
> /* setup the port */
> }
>
> int keypad_read()
> {
> return *portdata;
> }
>
> Your main application would include the keypad.h file, and
> when you compile the application you would compile and
> link your main.c and keypad.c. Later when you get lots
> of library functions, you can compile them into a library
> (static or dynamic).
>
> Note that while the above code is an ok style for bare-metal
> microcontrollers, for a 'device driver' under Linux, its still
> a bit of a hack. Drivers are generally written in kernel
> space. But for many applications that is a little bit overkill.
>
> An issue with GPIO pins is that if you have multiple devices
> connected to the pins, and if the pins and directions need to
> be manipulated by the multiple device drivers, you need some
> form of locking to make accesses appear atomic. Some processors
> (eg. ARM) have set and clear bit registers that are inherently
> atomic, while others don't.
>
> By hiding your key-pad access behind an API, you can reimplement
> the functions if you use a different hardware access method
> later. If you want to use C++, then the Keypad API would
> be a virtual base class, and KeypadGPIO would be an inherited
> class implemented using GPIO.
>
> However, I'm sure the above code abstraction will work for your
> application.
>
> Cheers,
> Dave
>
Hi Dave,
Thanks for your response. That helps me out. My intention when I
started the project was to make it as transparent as possible but I
guess I have strayed away from that these past few weeks as I have
been trying to finish and get everything working together. Now that
it's all working I'll organize it as you suggested.
Brandon
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|