51 bool Write(uint8_t *data,
size_t size)
65template <
typename Transport>
81 RGB = ((0 << 4) | (1 << 2) | (2)),
82 RBG = ((0 << 4) | (2 << 2) | (1)),
83 GRB = ((1 << 4) | (0 << 2) | (2)),
84 GBR = ((2 << 4) | (0 << 2) | (1)),
85 BRG = ((1 << 4) | (2 << 2) | (0)),
86 BGR = ((2 << 4) | (1 << 2) | (0)),
89 typename Transport::Config
114 r_offset_ = ((config.
color_order >> 4) & 0b11) + 1;
115 g_offset_ = ((config.
color_order >> 2) & 0b11) + 1;
137 for(uint16_t i = 0; i < num_pixels_; i++)
156 if(idx >= num_pixels_)
160 uint8_t *pixel = (uint8_t *)(&pixels_[idx]);
161 pixel[0] = 0xE0 | std::min(b, (uint16_t)31);
167 if(idx >= num_pixels_)
170 const uint8_t *pixel = (uint8_t *)&pixels_[idx];
171 c = c | (pixel[r_offset_] << 16);
172 c = c | (pixel[g_offset_] << 8);
173 c = c | pixel[b_offset_];
194 uint8_t r = (color >> 16) & 0xFF;
195 uint8_t g = (color >> 8) & 0xFF;
196 uint8_t b = color & 0xFF;
210 if(idx >= num_pixels_)
214 uint8_t *pixel = (uint8_t *)(&pixels_[idx]);
215 pixel[r_offset_] = r;
216 pixel[b_offset_] = b;
217 pixel[g_offset_] = g;
227 for(uint16_t i = 0; i < num_pixels_; i++)
239 for(uint16_t i = 0; i < num_pixels_; i++)
251 void Fill(uint8_t r, uint8_t g, uint8_t b)
253 for(uint16_t i = 0; i < num_pixels_; i++)
265 for(uint16_t i = 0; i < num_pixels_; i++)
274 uint8_t sf[4] = {0x00, 0x00, 0x00, 0x00};
275 uint8_t ef[4] = {0xFF, 0xFF, 0xFF, 0xFF};
276 if(!transport_.Write(sf, 4))
280 for(uint16_t i = 0; i < num_pixels_; i++)
282 if(!transport_.Write((uint8_t *)&pixels_[i], 4))
287 if(!transport_.Write(ef, 4))
295 static const size_t kMaxNumPixels = 64;
296 Transport transport_;
297 uint16_t num_pixels_;
298 uint32_t pixels_[kMaxNumPixels];
299 uint8_t r_offset_, g_offset_, b_offset_;
uint8_t Green8() const
Definition color.h:67
uint8_t Blue8() const
Definition color.h:68
uint8_t Red8() const
Definition color.h:66
Device support for Adafruit DotStar LEDs (Opsco SK9822)
Definition dotstar.h:67
Result Show()
Writes current pixel buffer data to LEDs.
Definition dotstar.h:272
void SetPixelColor(uint16_t idx, uint32_t color)
Sets color of a single pixel.
Definition dotstar.h:192
~DotStar()
Definition dotstar.h:103
Result Init(Config &config)
Definition dotstar.h:105
DotStar()
Definition dotstar.h:102
uint16_t GetPixelColor(uint16_t idx)
Definition dotstar.h:165
Result SetPixelGlobalBrightness(uint16_t idx, uint16_t b)
Set global brightness for a single pixel.
Definition dotstar.h:154
Result SetPixelColor(uint16_t idx, uint8_t r, uint8_t g, uint8_t b)
Sets color of a single pixel.
Definition dotstar.h:208
void Fill(uint32_t color)
Fills all pixels with color.
Definition dotstar.h:237
void Clear()
Clears all current color data. Does not reset global brightnesses. Does not write pixel buffer data t...
Definition dotstar.h:263
void Fill(uint8_t r, uint8_t g, uint8_t b)
Fill all pixels with color.
Definition dotstar.h:251
void SetAllGlobalBrightness(uint16_t b)
Set global brightness for all pixels.
Definition dotstar.h:135
void SetPixelColor(uint16_t idx, const Color &color)
Sets color of a single pixel.
Definition dotstar.h:183
Result
Definition dotstar.h:70
void Fill(const Color &color)
Fills all pixels with color.
Definition dotstar.h:225
SPI Transport for DotStars.
Definition dotstar.h:14
bool Write(uint8_t *data, size_t size)
Definition dotstar.h:51
void Init(Config &config)
Definition dotstar.h:32
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result Init(const Config &config)
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTB
Definition daisy_core.h:178
@ PORTG
Definition daisy_core.h:183
uint16_t num_pixels
Definition dotstar.h:92
void Defaults()
Definition dotstar.h:94
Transport::Config transport_config
Definition dotstar.h:90
ColorOrder
Definition dotstar.h:79
@ GBR
Definition dotstar.h:84
@ RGB
Definition dotstar.h:81
@ BRG
Definition dotstar.h:85
@ BGR
Definition dotstar.h:86
@ RBG
Definition dotstar.h:82
@ GRB
Definition dotstar.h:83
ColorOrder color_order
Definition dotstar.h:91
Pin data_pin
Definition dotstar.h:21
SpiHandle::Config::BaudPrescaler baud_prescaler
Definition dotstar.h:19
Pin clk_pin
Definition dotstar.h:20
SpiHandle::Config::Peripheral periph
Definition dotstar.h:18
void Defaults()
Definition dotstar.h:23
representation of hardware port/pin combination
Definition daisy_core.h:193
ClockPolarity clock_polarity
Definition spi.h:104
BaudPrescaler
Definition spi.h:72
Peripheral periph
Definition spi.h:100
Pin nss
Definition spi.h:88
struct daisy::SpiHandle::Config::@18 pin_config
Mode mode
Definition spi.h:101
Peripheral
Definition spi.h:29
Pin mosi
Definition spi.h:87
Pin sclk
Definition spi.h:85
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Pin miso
Definition spi.h:86
Direction direction
Definition spi.h:102
unsigned long datasize
Definition spi.h:103