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 SD600A by
Diff: SD600A.cpp
- Revision:
- 26:98163818a82e
- Parent:
- 25:14e5984d3aae
- Child:
- 27:6667543f3b28
--- a/SD600A.cpp Sat Oct 13 03:10:29 2012 +0000 +++ b/SD600A.cpp Sat Oct 13 04:49:47 2012 +0000 @@ -9,6 +9,22 @@ #include "LedStrip.h" #include "SD600A.h" +SD600ASupervisor::SD600ASupervisor(void) { + numstrips = 0; + byte_index = 0; + bit_index = 0; +} + +void SD600ASupervisor::add(SD600A *strip) { + strips[numstrips] = strip; + numstrips++; + if (numstrips == 1) { // this is the first one, set up the interrupt. + data_length = strip->data_length; + NVIC_SetPriority(TIMER3_IRQn, 0); + idletoggle.attach_us(this, &SD600ASupervisor::spi_isr, INTERRUPT_INTERVAL); + } +} + /* * Soft SPI clockout routine. Triggered every few microseconds, * repeatedly clocks out the strip contents. Since each update function @@ -16,14 +32,25 @@ * there is no need to lock the buffer. */ -void SD600A::spi_isr(void) { - clk = 1; - dat = pixels[byte_index] & (0x80 >> bit_index); - clk = 0; +void SD600ASupervisor::spi_isr(void) { + int i; + SD600A *curstrip; + for (i=0; i<numstrips; i++) { + curstrip = strips[i]; + curstrip->clk = 1; + curstrip->dat = curstrip->pixels[byte_index] & (0x80 >> bit_index); + } + for (i=0; i<numstrips; i++) + strips[i]->clk = 0; bit_index++; - clk = 1; - dat = pixels[byte_index] & (0x80 >> bit_index); - clk = 0; + for (i=0; i<numstrips; i++) + strips[i]->clk = 1; + for (i=0; i<numstrips; i++) { + curstrip = strips[i]; + curstrip->dat = curstrip->pixels[byte_index] & (0x80 >> bit_index); + } + for (i=0; i<numstrips; i++) + strips[i]->clk = 0; bit_index++; if (bit_index == 8) { byte_index++; @@ -33,6 +60,8 @@ byte_index = 0; } + + SD600A::SD600A(PinName dataPin, PinName clockPin, int n) : dat(dataPin), clk(clockPin) { @@ -48,8 +77,6 @@ byte_index = 0; bit_index = 0; } else error("SD600A could not allocate memory!\r\n"); - NVIC_SetPriority(TIMER3_IRQn, 0); - idletoggle.attach_us(this, &SD600A::spi_isr, INTERRUPT_INTERVAL); } void SD600A::begin(void) {