hexbright icon indicating copy to clipboard operation
hexbright copied to clipboard

Write custom versions of arduino functions?

Open dhiltonp opened this issue 12 years ago • 9 comments

Arduino's pinMode, (digital/analog)(Read/Write) take up 850 bytes all together.

Writing non-generalized versions for our library could reduce our flash footprint. Investigate costs/benefits.

dhiltonp avatar Jan 10 '13 07:01 dhiltonp

Maybe we can pull in this patch:

http://code.google.com/p/arduino/issues/detail?id=140

dhiltonp avatar Jan 13 '13 09:01 dhiltonp

I've pulled in this library, which is the implementation discussed here.

pinMode -> pinModeFast digitalWrite -> digitalWriteFast analogWrite -> analogWriteFast

This saves around 250 bytes, and reduces execution time.

dhiltonp avatar Jan 13 '13 09:01 dhiltonp

arduino-lite seems to be poorly maintained, but it should have a macro for analogWrite, which could be useful. No such optimization seems to exist for analogRead.

dhiltonp avatar Jan 13 '13 09:01 dhiltonp

http://maxembedded.com/2011/06/20/the-adc-of-the-avr/

This link demonstrates how to convert analog to digital on the avr. We currently use similar code in read_avr_voltage.

dhiltonp avatar Jan 25 '13 17:01 dhiltonp

adc reading implemented in read_adc.

dhiltonp avatar Feb 10 '13 02:02 dhiltonp

If we have those functions now isn't this completed?

joshgoebel avatar Mar 30 '14 19:03 joshgoebel

I've not verified that all arduino functions are replaced (doable by compiling the library directly in avr-gcc)

dhiltonp avatar Mar 30 '14 19:03 dhiltonp

Well, it's only a replacement if all the pins and values written are constants as determined by the compiler and therefor the dynamic code paths can be optimized out. So I assume you mean confirm that that is the case with the default compile of hexbright.h?

How were you planning to confirm that? Dissassembly?

joshgoebel avatar Mar 30 '14 19:03 joshgoebel

Part of the desire was to make this library usable outside of the arduino environment, compiling via avr-gcc while including/linking no arduino code.

At this point, I believe most of the inefficiencies of the arduino libraries have been resolved (interesting catch on the linked ram, by the way), so this is much less of a priority than before.

dhiltonp avatar Mar 30 '14 19:03 dhiltonp