It is a program to turn on the LED serial two Jksoft Blue mbed Board. Jksoft Blue mbed Boardの2つのシリアルLEDを点灯させるプログラムです。
Revision 0:57df396a2de8, committed 2014-05-12
- Comitter:
- jksoft
- Date:
- Mon May 12 11:01:44 2014 +0000
- Commit message:
- First edition
Changed in this revision
diff -r 000000000000 -r 57df396a2de8 WS2812B/LEDStrip.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WS2812B/LEDStrip.h Mon May 12 11:01:44 2014 +0000 @@ -0,0 +1,6 @@ + +void tape_write (int d); +void tapeInit (int speed, int n); +void tapeSet (int n, int dat); +void tapeSet(int n, int red , int green , int blue); +void tapeSend ();
diff -r 000000000000 -r 57df396a2de8 WS2812B/LEDStrip_WS2812.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WS2812B/LEDStrip_WS2812.cpp Mon May 12 11:01:44 2014 +0000 @@ -0,0 +1,128 @@ +/* + * WS2812 tape led IC + * + * 0.35us 0.8us (+-150ns) + * 0: |^^^^^|__________| + * + * 0.7us 0.6us (+-150ns) + * 1: |^^^^^^^^^^|_____| + * + * >50us + * RESET: |________________| + */ +#include "mbed.h" +#include "LEDStrip.h" + +SPI tape(p11, NC, NC); + +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) + LPC_SSP_TypeDef *_ssp = LPC_SSP0; +#elif defined(TARGET_LPC11U24) + LPC_SSPx_Type *_ssp = LPC_SSP1; +#endif + +int num = 100; +int *data; +volatile int busy = 0, wakeup = 0; + + +extern "C" +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) +void SSP0_IRQHandler() { +#elif defined(TARGET_LPC11U24) +void SSP1_IRQHandler() { +#endif + static int addr = 0, bit = 0x800000; +repeat: + if (busy) { + // led data + while (_ssp->SR & (1<<1)) { // TNF + if (data[addr] & bit) { + // 1 + //_ssp->DR = 0x01f; + _ssp->DR = 0x007; + } else { + // 0 + _ssp->DR = 0x07f; + } + bit = bit >> 1; + if (bit == 0) { + bit = 0x800000; + addr ++; + if (addr >= num) { + addr = 0; + busy = 0; + goto repeat; + } + } + } + } else { + // blank + while (_ssp->SR & (1<<1)) { // TNF + _ssp->DR = 0xfff; + if (addr < 50) { + addr ++; + } else { + addr = 0; + if (wakeup) { + busy = 1; + wakeup = 0; + goto repeat; + } + } + } + } +} + +void tapeInit (int freq, int n) { + + num = n; +// data = new int(num); + data = (int*)malloc(sizeof(int) * num); + for (int i = 0; i < num; i ++) { + data[i] = 0; + } + + tape.format(10, 1); + if (freq) { + tape.frequency(freq * 1000); + } else { + tape.frequency(8000000); + } +#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) + NVIC_SetVector(SSP0_IRQn, (uint32_t)SSP0_IRQHandler); + NVIC_SetPriority(SSP0_IRQn, 0); + NVIC_EnableIRQ(SSP0_IRQn); +#elif defined(TARGET_LPC11U24) + NVIC_SetVector(SSP1_IRQn, (uint32_t)SSP1_IRQHandler); + NVIC_SetPriority(SSP1_IRQn, 0); + NVIC_EnableIRQ(SSP1_IRQn); +#endif + _ssp->IMSC |= (1<<3); // TXIM +} + +void tapeSet (int n, int dat) { + if (n >= 0 && n < num) { + // RGB -> GRB + data[n] = ((dat & 0xff0000) >> 8) | ((dat & 0xff00) << 8) | (dat & 0xff); + } +} +void tapeSet(int n, int red , int green , int blue) { + if (n >= 0 && n < num) { + // RGB -> GRB + data[n] = ((red & 0xff) << 8) | ((green & 0xff) << 16) | (blue & 0xff); + } +} + +void tapeSend () { + if (busy) { + while (busy); + wait_us(50); + } + wakeup = 1; + while (wakeup); +} + +int tapeGet (int n) { + return ((data[n] & 0xff0000) >> 8) | ((data[n] & 0xff00) << 8) | (data[n] & 0xff); +}
diff -r 000000000000 -r 57df396a2de8 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 12 11:01:44 2014 +0000 @@ -0,0 +1,32 @@ +/** + * Jksoft Blue mbed Board + * + * Serial LED test program + * + * Copyright (C) 2014 Junichi Katsu (JKSOFT) + */ +#include "mbed.h" +#include "LEDStrip.h" + + +int main() { + tapeInit(0, 2); // freq( 0:default ) , SerialLED num + + while(1) + { + for( int i=0 ; i < 256 ; i++ ) + { + tapeSet(0,i,0,0); // LED No , Red , Green , Blue + tapeSet(1,0,i,0); // LED No , Red , Green , Blue + tapeSend(); // Send to LED + wait_ms(20); + } + for( int i=255 ; i > 0 ; i-- ) + { + tapeSet(0,i,0,0); // LED No , Red , Green , Blue + tapeSet(1,0,i,0); // LED No , Red , Green , Blue + tapeSend(); // Send to led + wait_ms(20); + } + } +} \ No newline at end of file
diff -r 000000000000 -r 57df396a2de8 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 12 11:01:44 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776 \ No newline at end of file