WS2812B
Dependents: high speed light Bracelet
Fork of PololuLedStrip by
Diff: PololuLedStrip.cpp
- Revision:
- 7:9a088f042ee0
- Parent:
- 6:9d0530b7dae2
- Child:
- 8:1578776ceac5
diff -r 9d0530b7dae2 -r 9a088f042ee0 PololuLedStrip.cpp --- a/PololuLedStrip.cpp Fri Mar 01 00:31:24 2013 +0000 +++ b/PololuLedStrip.cpp Fri Mar 01 01:16:48 2013 +0000 @@ -2,26 +2,26 @@ bool PololuLedStrip::interruptFriendly = false; -// TODO: read clock frequency from SystemCoreClock and use that to make this work on different boards. -// calculate the three delays needed and pass them to the assembly. The assembly can implement them with computed jumps. +uint8_t led_strip_write_delays[3]; -uint8_t led_strip_write_delays[3]; +void PololuLedStrip::calculateDelays() +{ + int fmhz = SystemCoreClock / 1000000; + led_strip_write_delays[0] = 700*fmhz/1000 - 25; + led_strip_write_delays[1] = 600*fmhz/1000 - 19; + led_strip_write_delays[2] = 1200*fmhz/1000 - 24; +} PololuLedStrip::PololuLedStrip(PinName pinName) { gpio_init(&gpio, pinName, PIN_OUTPUT); + calculateDelays(); // Assumption } void PololuLedStrip::write(rgb_color * colors, unsigned int count) { __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. - - int f = SystemCoreClock/1000000; - led_strip_write_delays[0] = 700*f/1000 - 10; - led_strip_write_delays[1] = 600*f/1000 - 10; - led_strip_write_delays[2] = 1200*f/1000 - 10; - led_strip_write_delays[0] = 59; - + while(count--) { led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);