FYI: Paul Stoffregen is working on full Arduino Mega support for Firmata/Pduino. I know some people onthis list were interested in that. He's looking for testers now, the code is here:

http://www.pjrc.com/tmp/firmata/

Once its tested, we'll work on integrating it into the regular Firmata releases.

.hc


Begin forwarded message:

From: Paul Stoffregen <p...@pjrc.com>
Date: January 5, 2010 10:12:55 AM EST
To: firmata-de...@lists.sourceforge.net, Hans-Christoph Steiner <h...@at.or.at >
Subject: better hardware abstraction
User-Agent: Thunderbird 2.0.0.23 (X11/20090817)

I just uploaded a copy of StandardFirmata using what I believe will be much better hardware abstraction.

http://www.pjrc.com/tmp/firmata/

The concept is use two sets of macros, IS_PIN_xxx() to test if any particular pin supports a feature, and PIN_TO_xxx() to translate firmata pin numbers (as used in the protocol) to actual numbers used by the hardware functions.

Often these macros are very simple. But when a translation is needed, they can. For example, on a standard Arduino, for digital pins the macros are:

#define IS_PIN_DIGITAL(p) (((p) >= 2 && (p) <= 13) || ((p) >= 16 && (p) <= 21))
#define PIN_TO_DIGITAL(p)       (((p) < 16) ? (p) : (p) - 2)

Pins 14 and 15 are not implemented, and pins 0 and 1 are not available for digital I/O due to being used for Rx and Tx. The PIN_PIN_DIGITAL() macro lets StandardFirmata easily adapt. The PIN_TO_DIGITAL() macro is used whenever calling pinMode, digitalWrite, digitalRead (but optimized 8 bit port access has to be special coded). For a standard Arduino, when the analog pins are used as digital I/O, this macro makes sure pinMode gets called correctly. Even though it's pin 16 as presented by Firmata, Arduino's pinMode function expected 14 to map to the first analog input.

The core concept behind this abstraction layer is every "firmata pin" may support any number of features which are checked with IS_PIN_xxx(), and if the feature is available, PIN_TO_xxx() translates the "firmata pin" into a "hardware pin". Everything in StandardFirmata works based on "firmata pins" and then checks and translation into "hardware pins" are used when actually performing I/ O.

This simplifies the StandardFirmata code in many places. In the long run, I believe this approach will be much more maintainable, since it tends to make the code more readable. As more pin features are added, this scheme is simple to extend.

As promised, I've done quite a bit more testing. I modified Pduino to work with more pins and did quite a lot of testing on Arduino Mega (on 0017, there is a known bug with analog inputs 8 to 15, so be sure to patch your wiring_analog.c file, if you haven't already). I haven't tested everything in every possible way, but this does seem to be working quite well.

I realize this is a pretty substantial change. I hope you'll consider it.


-Paul









----------------------------------------------------------------------------

Looking at things from a more basic level, you can come up with a more direct solution... It may sound small in theory, but it in practice, it can change entire economies. - Amy Smith



_______________________________________________
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to