Open PaintYourDragon opened 4 years ago
Some notes regarding last two items (throttling software bitbang-out speed). Less an issue in the future if we start to optimize with DMA and timers, etc. But for now:
NOPs are probably good enough on SAMD21 (if even needed) and maybe nRF52840. Things get more complicated on faster devices, especially those where the CPU clock is configurable at compile time (e.g. M4, Teensy), as the number of cycles to delay is not constant across all configurations (requiring different NOP lists for different speeds), plus the number of NOPs gets really ridiculous on fast devices like Teensy 4. Some alternatives might include:
#define _PM_DELAYLET(n) \
for(volatile uint32_t _PM_BLAT=F_CPU * n / _PM_SOME_CONSTANT, _PM_BLAT_--;);
Must be volatile as even casual optimizer settings recognize and remove do-nothing loops. _PM_SOME_CONSTANT would be an empirically-derived value (per architecture) that gives enough resolution to tune the bit-banging to the target frequency range, not an actual established time interval like micro- or nano-seconds.
Speaking of target frequency range, 12-16 MHz might be too conservative, and it might be OK to go a bit faster. Or not. Something to test with different matrices, wiring setups, etc.
Or
_PM_BLAT=(F_CPU * n + (_PM_SOME_CONSTANT / 2)) / _PM_SOME_CONSTANT
if you want to be persnickety and have it round up fractions.
In either case, everything’s a constant there and the preprocessor reduces this to a value; no math actually occurs when setting up the _PM_DELAYLET loop, it’s just a load instruction.
Variable and define names are hypothetical, just for demonstration purposes. Don’t actually use these, or they’ll stick just like the Protomatter name.
Oh also, don’t just go making an “arch” directory willy-nilly, that’ll break when compiling in Arduino IDE. Proper Layout™ for Arduino libs (and note of “arch” being deprecated) is described here (arch is probably fine if everything’s moved into a src subdirectory): http://goo.gl/gfFJzU
This isn’t really an issue, but putting some future roadmap notes here publicly for anyone’s input if there are different approaches or better ideas.