59 CHARTREUSE = 0x7FFF00,
61 AQUAMARINE = 0x7FFFD4,
82 static unsigned int to_color (
const unsigned int red,
const unsigned int green,
const unsigned int blue) {
83 return ((red) << 16) | ((green) << 8) | (blue);
86 static unsigned int scale (
const unsigned int x,
const unsigned int l) {
90 static unsigned int colorx (
const unsigned int red,
const unsigned int green,
const unsigned int blue,
91 const unsigned int l) {
92 return (scale(red, l) << 16) | (scale(green, l) << 8) | scale(blue, l);
103 : m_pin(pinMask,
Pin::Dir::OUT),
113 void send (
const unsigned int color)
const {
123 void send_array (
const unsigned int *buffer,
const size_t length)
const {
126 const unsigned int LONG_PULSE_WIDTH = (900 * MICROSECOND / 1000);
127 const unsigned int SHORT_PULSE_WIDTH = (350 * MICROSECOND / 1000);
128 const unsigned int RESET_DELAY = (50 * MICROSECOND);
130 unsigned int clock = RESET_DELAY;
133 unsigned int colorbits = 0;
134 unsigned int bitCounter = 0;
137 FC_START(
"Ws2812Start",
"Ws2812End")
138 " add %[_clock], CNT \n\t"
139 " waitcnt %[_clock], #0 \n\t"
142 " rdlong %[_colorbits], %[_nextLed] \n\t"
143 " add %[_nextLed], #4 \n\t"
146 " tjz %[_swaprg], #" FC_ADDR(
"shift_out%=",
"Ws2812Start")
" \n\t"
147 " mov %[_t1], %[_colorbits] \n\t"
148 " mov %[_t2], %[_colorbits] \n\t"
149 " and %[_colorbits], #0xff \n\t"
150 " shr %[_t1], #8 \n\t"
151 " and %[_t1], %[_byte1] \n\t"
152 " or %[_colorbits], %[_t1] \n\t"
153 " shl %[_t2], #8 \n\t"
154 " and %[_t2], %[_byte2] \n\t"
155 " or %[_colorbits], %[_t2] \n\t"
158 " shl %[_colorbits], #8 \n\t"
159 " mov %[_bitCounter], #24 \n\t"
161 "shift_out.loop%=: \n\t"
162 " rcl %[_colorbits], #1 wc \n\t"
163 " if_c mov %[_clock], %[_longPulse] ' bit1hi \n\t"
164 " if_nc mov %[_clock], %[_shortPulse] ' bit0hi \n\t"
165 " or OUTA, %[_pinMask] \n\t"
166 " add %[_clock], CNT \n\t"
167 " if_c waitcnt %[_clock], %[_shortPulse] ' bit1lo \n\t"
168 " if_nc waitcnt %[_clock], %[_longPulse] ' bit0lo \n\t"
169 " andn OUTA, %[_pinMask] \n\t"
170 " waitcnt %[_clock], #0 \n\t"
171 " djnz %[_bitCounter], #" FC_ADDR(
"shift_out.loop%=",
"Ws2812Start")
" \n\t"
172 " djnz %[_nleds], #" FC_ADDR(
"frame_loop%=",
"Ws2812Start")
" \n\t"
174 :[_clock]
"+r"(clock),
177 [_colorbits]
"+r"(colorbits),
178 [_bitCounter]
"+r"(bitCounter),
179 [_nextLed]
"+r"(buffer)
180 :[_pinMask]
"r"(this->m_pin.get_mask()),
181 [_nleds]
"r"(length),
182 [_swaprg]
"r"(this->m_type),
183 [_byte1]
"r"(BYTE_1),
184 [_byte2]
"r"(BYTE_2),
185 [_shortPulse]
"r"(SHORT_PULSE_WIDTH),
186 [_longPulse]
"r"(LONG_PULSE_WIDTH),
187 [_resetDelay]
"r"(RESET_DELAY));
190 uint32_t wheel (
unsigned int position)
const {
191 uint32_t resultingColor;
198 resultingColor =
to_color(255 - position * 3, position * 3, 0);
201 else if (position < 170) {
203 resultingColor =
to_color(0, 255 - position * 3, position * 3);
208 resultingColor =
to_color(position * 3, 0, 255 - position * 3);
211 return resultingColor;
214 uint32_t wheel_dim (
unsigned int position,
unsigned int brightness)
const {
222 color = colorx(255 - position * 3, position * 3, 0, brightness);
225 else if (position < 170) {
227 color = colorx(0, 255 - position * 3, position * 3, brightness);
233 color = colorx(position * 3, 0, 255 - position * 3, brightness);