Forked PololuLedStrip and modified it to work with the KL25Z. Renamed it to Adafruit_NeoPixel.

Fork of PololuLedStrip by David Grayson

Committer:
DavidEGrayson
Date:
Fri Mar 01 03:57:49 2013 +0000
Revision:
9:6ffb85d69eaf
Parent:
8:1578776ceac5
Child:
10:f1bb84b97788
Successfully transmitted colors on the M0.

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 7:9a088f042ee0 5 uint8_t led_strip_write_delays[3];
DavidEGrayson 4:d3b60bd43811 6
DavidEGrayson 7:9a088f042ee0 7 void PololuLedStrip::calculateDelays()
DavidEGrayson 7:9a088f042ee0 8 {
DavidEGrayson 8:1578776ceac5 9 // Get the clock frequency in MHz.
DavidEGrayson 8:1578776ceac5 10 int f_mhz = SystemCoreClock / 1000000;
DavidEGrayson 8:1578776ceac5 11
DavidEGrayson 8:1578776ceac5 12 // Arrange for a 700 nanosecond delay between the rise time and the fall time for a 0 bit.
DavidEGrayson 9:6ffb85d69eaf 13 led_strip_write_delays[0] = 700*f_mhz/1000 - 25 - 5;
DavidEGrayson 8:1578776ceac5 14
DavidEGrayson 8:1578776ceac5 15 // Arrange for a 600 nanosecond delay between the fall time for a 0 bit and the fall time for a 1 bit.
DavidEGrayson 8:1578776ceac5 16 // This means the pulses representing a 1 will be 700+600 = 1300 nanoseconds.
DavidEGrayson 8:1578776ceac5 17 led_strip_write_delays[1] = 600*f_mhz/1000 - 19;
DavidEGrayson 8:1578776ceac5 18
DavidEGrayson 8:1578776ceac5 19 // Arrange for a 1200 nanosecond delay between the fall time for a 1 bit and rise time of the next bit.
DavidEGrayson 8:1578776ceac5 20 // This means the period of the signal will be 2500 nanoseconds.
DavidEGrayson 8:1578776ceac5 21 led_strip_write_delays[2] = 1200*f_mhz/1000 - 24;
DavidEGrayson 7:9a088f042ee0 22 }
DavidEGrayson 6:9d0530b7dae2 23
DavidEGrayson 1:102307d9b701 24 PololuLedStrip::PololuLedStrip(PinName pinName)
DavidEGrayson 1:102307d9b701 25 {
DavidEGrayson 1:102307d9b701 26 gpio_init(&gpio, pinName, PIN_OUTPUT);
DavidEGrayson 1:102307d9b701 27 }
DavidEGrayson 1:102307d9b701 28
DavidEGrayson 1:102307d9b701 29 void PololuLedStrip::write(rgb_color * colors, unsigned int count)
DavidEGrayson 1:102307d9b701 30 {
DavidEGrayson 8:1578776ceac5 31 calculateDelays();
DavidEGrayson 8:1578776ceac5 32
DavidEGrayson 1:102307d9b701 33 __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up.
DavidEGrayson 7:9a088f042ee0 34
DavidEGrayson 1:102307d9b701 35 while(count--)
DavidEGrayson 1:102307d9b701 36 {
DavidEGrayson 9:6ffb85d69eaf 37 led_strip_write_color(colors, gpio.reg_set, gpio.reg_clr, gpio.mask);
DavidEGrayson 9:6ffb85d69eaf 38 colors++;
DavidEGrayson 9:6ffb85d69eaf 39
DavidEGrayson 1:102307d9b701 40 if (interruptFriendly)
DavidEGrayson 1:102307d9b701 41 {
DavidEGrayson 1:102307d9b701 42 __enable_irq();
DavidEGrayson 1:102307d9b701 43 __nop();
DavidEGrayson 1:102307d9b701 44 __nop();
DavidEGrayson 1:102307d9b701 45 __nop();
DavidEGrayson 1:102307d9b701 46 __disable_irq();
DavidEGrayson 1:102307d9b701 47 }
DavidEGrayson 1:102307d9b701 48 }
DavidEGrayson 1:102307d9b701 49
DavidEGrayson 1:102307d9b701 50 __enable_irq(); // Re-enable interrupts now that we are done.
DavidEGrayson 1:102307d9b701 51 wait_us(24); // Hold the line low for 24 microseconds to send the reset signal.
DavidEGrayson 9:6ffb85d69eaf 52
DavidEGrayson 9:6ffb85d69eaf 53 //*(gpio.reg_set) = gpio.mask;
DavidEGrayson 9:6ffb85d69eaf 54 //*(gpio.reg_clr) = gpio.mask;
DavidEGrayson 9:6ffb85d69eaf 55
DavidEGrayson 1:102307d9b701 56 }