Closed digitalcircuit closed 2 years ago
@caternuson also take a look since i thiiiink ya did the busioification?
@digitalcircuit this is one of the nicest, most helpful PR we've seen this year - wish we could give it an award. we look forward to reviewing any other PR's you submit to our repos!
Nice! This looks good. The busioification really just translated the logic that was already in place - so this has been in the library even before that.
@ladyada Thank you! I'm glad I was able to help out, and if I find other useful changes or fixes I'll certainly send PRs. Thank you (and the Adafruit team and contributors) for the awesome hardware, guides, and libraries!
@caternuson That makes sense. I recall in 2019 when implementing an SPI speed override for my simple lighting controller firmware (which I reverted after this was merged, yay!) that based on the delay for show()
the default speed on an ItsyBitsy M4 wasn't even 6 MHz, let alone 8 MHz due to logic set in place for the Arduino Due. However, I hadn't revisited this until today, and it's quite possible that later changes resulted in 8 MHz being applied more widely and I simply didn't notice.
I repeated the same tests in the first linked commit before submitting this PR, and strangely enough, while 8 MHz caused me slight problems with 300 LEDs over 10 meters in 2019, it's perfectly fine today. Maybe Adafruit's BusIO or changes in other Arduino components made SPI more reliable.
yep - ideally we want to put all I2C / SPI management logic into adafruit_busio because there are so many finicky platform-specific bugs and requirements. if there's something still wrong with SPI that you encounter - plz open an issue there :)
In short
begin/endTransaction()
new Adafruit_SPIDevice(-1, 8000000)
/etcAdafruit_SPIDevice
only applies thisfreq
after callingbeginTransaction()
1.2 ms
(from3479 µs
to2270 µs
)SCK
andMO
pins1.2.0
Details
The BusIO update in Adafruit_DotStar v1.2.0 specified 8 MHz as the desired SPI frequency. However, it overlooked the need to begin and end transactions on the
Adafruit_SPIDevice
in order to actually apply this frequency and ensure the settings are correct after any unrelated SPI transactions to other devices.Alternatively, if avoiding the use of SPI transactions is intentional (e.g. to allow others to customize the SPI frequency before/after calling
show()
), the DotStar library code should probably have a comment to explain this.Testing
Steps
strandtest_perf.ino
codeBefore
Average of
3479 µs
delay to update 300 DotStar LEDs.After
Average of
2270 µs
delay to update 300 DotStar LEDs.Example code
strandtest_perf.ino