debug
Fork of PololuLedStripx by
PololuLedStrip.cpp@8:1578776ceac5, 2013-03-01 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Fri Mar 01 02:05:21 2013 +0000
- Revision:
- 8:1578776ceac5
- Parent:
- 7:9a088f042ee0
- Child:
- 9:6ffb85d69eaf
Changed the registers so that the push and pop commands can work on the Cortex M0 (LPC 11U24). There are still more things to fix though.
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:1578776ceac5 | 13 | led_strip_write_delays[0] = 700*f_mhz/1000 - 25; |
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 | 1:102307d9b701 | 37 | led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); |
DavidEGrayson | 1:102307d9b701 | 38 | |
DavidEGrayson | 1:102307d9b701 | 39 | if (interruptFriendly) |
DavidEGrayson | 1:102307d9b701 | 40 | { |
DavidEGrayson | 1:102307d9b701 | 41 | __enable_irq(); |
DavidEGrayson | 1:102307d9b701 | 42 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 43 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 44 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 45 | __disable_irq(); |
DavidEGrayson | 1:102307d9b701 | 46 | } |
DavidEGrayson | 1:102307d9b701 | 47 | } |
DavidEGrayson | 1:102307d9b701 | 48 | |
DavidEGrayson | 1:102307d9b701 | 49 | __enable_irq(); // Re-enable interrupts now that we are done. |
DavidEGrayson | 1:102307d9b701 | 50 | wait_us(24); // Hold the line low for 24 microseconds to send the reset signal. |
DavidEGrayson | 1:102307d9b701 | 51 | } |