debug
Fork of PololuLedStripx by
PololuLedStrip.cpp@6:9d0530b7dae2, 2013-03-01 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Fri Mar 01 00:31:24 2013 +0000
- Revision:
- 6:9d0530b7dae2
- Parent:
- 4:d3b60bd43811
- Child:
- 7:9a088f042ee0
Successfully read the delay amount from a table.
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 | 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 | 6:9d0530b7dae2 | 8 | uint8_t led_strip_write_delays[3]; |
DavidEGrayson | 6:9d0530b7dae2 | 9 | |
DavidEGrayson | 1:102307d9b701 | 10 | PololuLedStrip::PololuLedStrip(PinName pinName) |
DavidEGrayson | 1:102307d9b701 | 11 | { |
DavidEGrayson | 1:102307d9b701 | 12 | gpio_init(&gpio, pinName, PIN_OUTPUT); |
DavidEGrayson | 1:102307d9b701 | 13 | } |
DavidEGrayson | 1:102307d9b701 | 14 | |
DavidEGrayson | 1:102307d9b701 | 15 | void PololuLedStrip::write(rgb_color * colors, unsigned int count) |
DavidEGrayson | 1:102307d9b701 | 16 | { |
DavidEGrayson | 1:102307d9b701 | 17 | __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. |
DavidEGrayson | 1:102307d9b701 | 18 | |
DavidEGrayson | 6:9d0530b7dae2 | 19 | int f = SystemCoreClock/1000000; |
DavidEGrayson | 6:9d0530b7dae2 | 20 | led_strip_write_delays[0] = 700*f/1000 - 10; |
DavidEGrayson | 6:9d0530b7dae2 | 21 | led_strip_write_delays[1] = 600*f/1000 - 10; |
DavidEGrayson | 6:9d0530b7dae2 | 22 | led_strip_write_delays[2] = 1200*f/1000 - 10; |
DavidEGrayson | 6:9d0530b7dae2 | 23 | led_strip_write_delays[0] = 59; |
DavidEGrayson | 6:9d0530b7dae2 | 24 | |
DavidEGrayson | 1:102307d9b701 | 25 | while(count--) |
DavidEGrayson | 1:102307d9b701 | 26 | { |
DavidEGrayson | 1:102307d9b701 | 27 | led_strip_write_color(colors++, gpio.reg_set, gpio.reg_clr, gpio.mask); |
DavidEGrayson | 1:102307d9b701 | 28 | |
DavidEGrayson | 1:102307d9b701 | 29 | if (interruptFriendly) |
DavidEGrayson | 1:102307d9b701 | 30 | { |
DavidEGrayson | 1:102307d9b701 | 31 | __enable_irq(); |
DavidEGrayson | 1:102307d9b701 | 32 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 33 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 34 | __nop(); |
DavidEGrayson | 1:102307d9b701 | 35 | __disable_irq(); |
DavidEGrayson | 1:102307d9b701 | 36 | } |
DavidEGrayson | 1:102307d9b701 | 37 | } |
DavidEGrayson | 1:102307d9b701 | 38 | |
DavidEGrayson | 1:102307d9b701 | 39 | __enable_irq(); // Re-enable interrupts now that we are done. |
DavidEGrayson | 1:102307d9b701 | 40 | wait_us(24); // Hold the line low for 24 microseconds to send the reset signal. |
DavidEGrayson | 1:102307d9b701 | 41 | } |