[ws2812] resumable write and dma example#879
Conversation
|
The driver was explicitly written as blocking, because any pause in the SPI transfers will break the timing protocol of the LEDs. See the caveats. |
That seems to be the intention of this change. If you look at the example you'll see DMA SPI is used. It won't work without DMA anymore, though. |
|
Ah, you're right, I only looked at the implementation. 🙈 |
|
I just don't see a nice way to determine in a driver if the SPI master uses DMA, so I would suggest adding a ( template<typename T = void>
std::enable_if_t<SpiMaster::usedDma(), modm::ResumableResult<void>>
write()
{
return SpiMaster::transfer(data, nullptr, length+1);
}
template<typename T = void>
std::enable_if_t<! SpiMaster::usedDma(), void>
write()
{
for (const auto value : data) {
while (not SpiMaster::Hal::isTransmitRegisterEmpty()) ;
SpiMaster::Hal::write(value);
}
}
|
|
I think we should keep the function signature as RF for both implementations, otherwise you cannot write platform-independent code here. |
|
@rleh In C++20 you could write that code without modm::ResumableResult<void>
write() requires SpiMaster::usesDma
{}or something similar. I agree with @salkinium, that we should keep the resumable function signature for both versions to allow platform independent code. |
Something similar is actually: template<typename T = void>
static void
write()
requires (SpiMaster::usesDma())
{}See details in compiler explorer.
Agree 👍🏽 |
|
You don't need the |
63fd13c to
3d40be4
Compare
|
Code works with DMA and non-DMA SPI (see both examples). Not sure, if you want to keep the copy of the F411/ws2812 for the F469 board. I used this for testing the non-dma version because I don't have an F411 board around... |
|
LOL I think I don't get @chris-durand suggestion to actually use the DMA version... The parenthesis seem to be neccessary? |
If you defined a variable |
Tested in hardware