Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PololuLedStrip by
PololuLedStrip.cpp@7:9a088f042ee0, 2013-03-01 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Fri Mar 01 01:16:48 2013 +0000
- Revision:
- 7:9a088f042ee0
- Parent:
- 6:9d0530b7dae2
- Child:
- 8:1578776ceac5
Things are still working well.
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 | 7:9a088f042ee0 | 9 | int fmhz = SystemCoreClock / 1000000; |
DavidEGrayson | 7:9a088f042ee0 | 10 | led_strip_write_delays[0] = 700*fmhz/1000 - 25; |
DavidEGrayson | 7:9a088f042ee0 | 11 | led_strip_write_delays[1] = 600*fmhz/1000 - 19; |
DavidEGrayson | 7:9a088f042ee0 | 12 | led_strip_write_delays[2] = 1200*fmhz/1000 - 24; |
DavidEGrayson | 7:9a088f042ee0 | 13 | } |
DavidEGrayson | 6:9d0530b7dae2 | 14 | |
DavidEGrayson | 1:102307d9b701 | 15 | PololuLedStrip::PololuLedStrip(PinName pinName) |
DavidEGrayson | 1:102307d9b701 | 16 | { |
DavidEGrayson | 1:102307d9b701 | 17 | gpio_init(&gpio, pinName, PIN_OUTPUT); |
DavidEGrayson | 7:9a088f042ee0 | 18 | calculateDelays(); // Assumption |
DavidEGrayson | 1:102307d9b701 | 19 | } |
DavidEGrayson | 1:102307d9b701 | 20 | |
DavidEGrayson | 1:102307d9b701 | 21 | void PololuLedStrip::write(rgb_color * colors, unsigned int count) |
DavidEGrayson | 1:102307d9b701 | 22 | { |
DavidEGrayson | 1:102307d9b701 | 23 | __disable_irq(); // Disable interrupts temporarily because we don't want our pulse timing to be messed up. |
DavidEGrayson | 7:9a088f042ee0 | 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 | } |