Go Down

Topic: Trim some fat from twi/Wire! (Read 634 times) previous topic - next topic

jwatte

I saw today that the "twi.c" file, used to talk to the TWI interface of the Atmega, contains no less than three full-size buffers for TWI data packets. In addition, the "Wire.cpp" file used to wrap the twi.c file in a class interface adds another two buffers!

I think the buffers in Wire could pretty easily be eliminated by implementing the state machine from twi.c into the Wire.cpp class.

Additionally, the code says things like "I have to do this in this order, because I make take an interrupt at any time" -- while I'm sure that's true, it could also just turn off interrupts for the duration of the critical section, and possibly be a little clearer. Dunno if it would actually save any instructions, so that might be of secondary importance.

lesto

also it's a good idea to make the library not-locking, or at least implement timeout.
Do you want to be the first to post the modified code?
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

jwatte

My TWI code ended up using other custom functions I have for dieing-on-usage-error, and for scheduling-completion-callback, so it wouldn't fit inside the Arduino framework.

lesto

seems a good thing, why should not being implemented?
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

jwatte

It is a good thing, but it is totally different from the standard Arduino project.

If we want to turn Arduino into more of a mini-tasking/executive system, and less of a Wiring clone, that would be one thing, but I think that wouldn't be well received. I could be wrong, though!

Go Up