WS2812B

Dependents:   high speed light Bracelet

Fork of PololuLedStrip by David Grayson

Committer:
DavidEGrayson
Date:
Thu Feb 28 00:42:44 2013 +0000
Revision:
4:d3b60bd43811
Parent:
1:102307d9b701
Child:
6:9d0530b7dae2
Proof of the concept that we can achieve variable delays by jumping into a particular portion of a large subroutine with noops.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidEGrayson 1:102307d9b701 1 #include "PololuLedStrip.h"
DavidEGrayson 1:102307d9b701 2
DavidEGrayson 1:102307d9b701 3 bool PololuLedStrip::interruptFriendly = false;
DavidEGrayson 1:102307d9b701 4
DavidEGrayson 4:d3b60bd43811 5 // TODO: read clock frequency from SystemCoreClock and use that to make this work on different boards.
DavidEGrayson 4:d3b60bd43811 6 // calculate the three delays needed and pass them to the assembly. The assembly can implement them with computed jumps.
DavidEGrayson 4:d3b60bd43811 7
DavidEGrayson 1:102307d9b701 8 PololuLedStrip::PololuLedStrip(PinName pinName)
DavidEGrayson 1:102307d9b701 9 {
DavidEGrayson 1:102307d9b701 10 gpio_init(&gpio, pinName, PIN_OUTPUT);
DavidEGrayson 1:102307d9b701 11 }
DavidEGrayson 1:102307d9b701 12
DavidEGrayson 1:102307d9b701 13 void PololuLedStrip::write(rgb_color * colors, unsigned int count)
DavidEGrayson 1:102307d9b701 14 {
DavidEGrayson 1:102307d9b701 15 __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
DavidEGrayson 1:102307d9b701 16
DavidEGrayson 1:102307d9b701 17 while(count--)
DavidEGrayson 1:102307d9b701 18 {
DavidEGrayson 1:102307d9b701 19 led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask);
DavidEGrayson 1:102307d9b701 20
DavidEGrayson 1:102307d9b701 21 if (interruptFriendly)
DavidEGrayson 1:102307d9b701 22 {
DavidEGrayson 1:102307d9b701 23 __enable_irq();
DavidEGrayson 1:102307d9b701 24 __nop();
DavidEGrayson 1:102307d9b701 25 __nop();
DavidEGrayson 1:102307d9b701 26 __nop();
DavidEGrayson 1:102307d9b701 27 __disable_irq();
DavidEGrayson 1:102307d9b701 28 }
DavidEGrayson 1:102307d9b701 29 }
DavidEGrayson 1:102307d9b701 30
DavidEGrayson 1:102307d9b701 31 __enable_irq(); // Re-enable interrupts now that we are done.
DavidEGrayson 1:102307d9b701 32 wait_us(24); // Hold the line low for 24 microseconds to send the reset signal.
DavidEGrayson 1:102307d9b701 33 }