FastLED 3.9.15
Loading...
Searching...
No Matches

◆ writePixels()

template<uint8_t DATA_PIN, uint8_t CLOCK_PIN, uint32_t SPI_SPEED>
template<uint8_t FLAGS, class D, EOrder RGB_ORDER>
void AVRSoftwareSPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED >::writePixels ( PixelController< RGB_ORDER > pixels,
void * context = NULL )
inline

Write LED pixel data to the SPI interface.

Data is written in groups of three, re-ordered per the RGB_ORDER.

Template Parameters
FLAGSOption flags, such as FLAG_START_BIT
DPer-byte modifier class, e.g. DATA_NOP
RGB_ORDERthe rgb ordering for the LED data (e.g. what order red, green, and blue data is written out in)
Parameters
pixelsa PixelController with the LED data and modifier options

Definition at line 352 of file fastspi_bitbang.h.

352 {
354 select();
355 int len = pixels.mLen;
356
357#ifdef FAST_SPI_INTERRUPTS_WRITE_PINS
358 // If interrupts or other things may be generating output while we're working on things, then we need
359 // to use this block
360 while(pixels.has(1)) {
361 if(FLAGS & FLAG_START_BIT) {
362 writeBit<0>(1);
363 }
364 writeByte(D::adjust(pixels.loadAndScale0()));
365 writeByte(D::adjust(pixels.loadAndScale1()));
366 writeByte(D::adjust(pixels.loadAndScale2()));
367 pixels.advanceData();
368 pixels.stepDithering();
369 }
370#else
371 // If we can guaruntee that no one else will be writing data while we are running (namely, changing the values of the PORT/PDOR pins)
372 // then we can use a bunch of optimizations in here
374
377 // If data and clock are on different ports, then writing a bit will consist of writing the value foor
378 // the bit (hi or low) to the data pin port, and then two writes to the clock port to strobe the clock line
383
384 while(pixels.has(1)) {
385 if(FLAGS & FLAG_START_BIT) {
387 }
391 pixels.advanceData();
392 pixels.stepDithering();
393 }
394
395 } else {
396 // If data and clock are on the same port then we can combine setting the data and clock pins
401
402 while(pixels.has(1)) {
403 if(FLAGS & FLAG_START_BIT) {
405 }
409 pixels.advanceData();
410 pixels.stepDithering();
411 }
412 }
413#endif
415 release();
416 }
void select()
Select the SPI output (chip select)
static void writeByte(uint8_t b)
Write a single byte over SPI.
void release()
Release the SPI chip select line.
FastPin< CLOCK_PIN >::port_t clock_t
static void writeBit(uint8_t b)
Write the BIT'th bit out via SPI, setting the data pin then strobing the clock.
FastPin< DATA_PIN >::port_t data_t
FastPin< DATA_PIN >::port_ptr_t data_ptr_t
FastPin< CLOCK_PIN >::port_ptr_t clock_ptr_t
Software SPI (aka bit-banging) support Includes aggressive optimizations for when the clock and data ...
static port_t hival()
Gets the state of the port with this pin HIGH
Definition fastpin.h:260
static port_t loval()
Gets the state of the port with this pin LOW
Definition fastpin.h:262
static port_t mask()
Get the pin mask.
Definition fastpin.h:266
static port_ptr_t port()
Get the output state of the port.
Definition fastpin.h:264
#define FASTLED_UNUSED(x)
Definition unused.h:3

References PixelController< RGB_ORDER, LANES, MASK >::advanceData(), FASTLED_REGISTER, FASTLED_UNUSED, FLAG_START_BIT, PixelController< RGB_ORDER, LANES, MASK >::has(), FastPin< PIN >::hival(), PixelController< RGB_ORDER, LANES, MASK >::loadAndScale0(), PixelController< RGB_ORDER, LANES, MASK >::loadAndScale1(), PixelController< RGB_ORDER, LANES, MASK >::loadAndScale2(), FastPin< PIN >::loval(), FastPin< PIN >::mask(), PixelController< RGB_ORDER, LANES, MASK >::mLen, FastPin< PIN >::port(), release(), select(), PixelController< RGB_ORDER, LANES, MASK >::stepDithering(), writeBit(), and writeByte().

+ Here is the call graph for this function: