7#ifndef PLATFORM_STRIPIMPL_HPP
8#define PLATFORM_STRIPIMPL_HPP
22template<
size_t LedCount, u
int8_t ChannelCount>
bool LampdaStrip<LedCount, ChannelCount>::begin(
void)
27 digitalWrite(pin, LOW);
38template<
size_t LedCount, u
int8_t ChannelCount>
39void LampdaStrip<LedCount, ChannelCount>::setPixelColor(uint16_t n, uint32_t c)
43 uint8_t *p, r = (uint8_t)(c >> 16), g = (uint8_t)(c >> 8), b = (uint8_t)c;
44 if (wOffset == rOffset)
51 uint8_t w = (uint8_t)(c >> 24);
60template<
size_t LedCount, u
int8_t ChannelCount>
61uint32_t LampdaStrip<LedCount, ChannelCount>::getPixelColor(uint16_t n)
const
66 if (wOffset == rOffset)
68 uint8_t
const* p = &pixels[n * 3];
70 return ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) | (uint32_t)p[bOffset];
74 uint8_t
const* p = &pixels[n * 4];
75 return ((uint32_t)p[wOffset] << 24) | ((uint32_t)p[rOffset] << 16) | ((uint32_t)p[gOffset] << 8) |
80template<
size_t LedCount, u
int8_t ChannelCount>
bool LampdaStrip<LedCount, ChannelCount>::canShow(
void)
97 uint32_t now = micros();
102 return (now - endTime) >= 300L;
105template<
size_t LedCount, u
int8_t ChannelCount>
void LampdaStrip<LedCount, ChannelCount>::updateType(
neoPixelType t)
107 wOffset = (t >> 6) & 0b11;
108 rOffset = (t >> 4) & 0b11;
109 gOffset = (t >> 2) & 0b11;
112 if (wOffset == rOffset)
114 assert(ChannelCount == 3);
118 assert(ChannelCount == 4);
122template<
size_t LedCount, u
int8_t ChannelCount>
void LampdaStrip<LedCount, ChannelCount>::setPin(int16_t p)
124 if (begun && (pin >= 0))
130 digitalWrite(p, LOW);
178#define MAGIC_T0H 6UL | (0x8000)
179#define MAGIC_T1H 13UL | (0x8000)
182#define MAGIC_T0H_400KHz 8UL | (0x8000)
183#define MAGIC_T1H_400KHz 19UL | (0x8000)
187#define CTOPVAL_400KHz 40UL
199 NRF_PWM_Type* pwm = NULL;
203 NRF_PWM_Type* PWM[] = {NRF_PWM0,
212 for (
unsigned int device = 0; device < (
sizeof(PWM) /
sizeof(PWM[0])); device++)
214 if ((PWM[device]->ENABLE == 0) && (PWM[device]->PSEL.OUT[0] & PWM_PSEL_OUT_CONNECT_Msk) &&
215 (PWM[device]->PSEL.OUT[1] & PWM_PSEL_OUT_CONNECT_Msk) &&
216 (PWM[device]->PSEL.OUT[2] & PWM_PSEL_OUT_CONNECT_Msk) && (PWM[device]->PSEL.OUT[3] & PWM_PSEL_OUT_CONNECT_Msk))
225 if ((pixels_pattern != NULL) && (pwm != NULL))
229 for (uint16_t n = 0; n < numBytes; n++)
231 uint8_t pix = pixels[n];
233 for (uint8_t mask = 0x80; mask > 0; mask >>= 1)
235#if defined(NEO_KHZ400)
238 pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H_400KHz : MAGIC_T0H_400KHz;
243 pixels_pattern[pos] = (pix & mask) ? MAGIC_T1H : MAGIC_T0H;
251 pixels_pattern[pos++] = 0 | (0x8000);
252 pixels_pattern[pos++] = 0 | (0x8000);
255 pwm->MODE = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);
258 pwm->PRESCALER = (PWM_PRESCALER_PRESCALER_DIV_1 << PWM_PRESCALER_PRESCALER_Pos);
263#if defined(NEO_KHZ400)
266 pwm->COUNTERTOP = (CTOPVAL_400KHz << PWM_COUNTERTOP_COUNTERTOP_Pos);
271 pwm->COUNTERTOP = (CTOPVAL << PWM_COUNTERTOP_COUNTERTOP_Pos);
275 pwm->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos);
281 (PWM_DECODER_LOAD_Common << PWM_DECODER_LOAD_Pos) | (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);
284 pwm->SEQ[0].PTR = (uint32_t)(pixels_pattern) << PWM_SEQ_PTR_PTR_Pos;
287 pwm->SEQ[0].CNT = pattern_size << PWM_SEQ_CNT_CNT_Pos;
290 pwm->SEQ[0].REFRESH = 0;
291 pwm->SEQ[0].ENDDELAY = 0;
301#if defined(ARDUINO_ARCH_NRF52840)
302 pwm->PSEL.OUT[0] = g_APinDescription[pin].name;
304 pwm->PSEL.OUT[0] = g_ADigitalPinMap[pin];
312 pwm->EVENTS_SEQEND[0] = 0;
313 pwm->TASKS_SEQSTART[0] = 1;
316 while (!pwm->EVENTS_SEQEND[0])
318#if defined(ARDUINO_NRF52_ADAFRUIT) || defined(ARDUINO_ARCH_NRF52840)
324 pwm->EVENTS_SEQEND[0] = 0;
332 pwm->PSEL.OUT[0] = 0xFFFFFFFFUL;
Program scope.
Definition: control_fixed_modes.hpp:12
Implement a led strip object.
uint8_t neoPixelType
3rd arg to Adafruit_NeoPixel constructor
Definition: strip_impl.h:17