Only Yesterday 制御プログラム

Dependencies:   mbed FATFileSystem

Fork of OnlyYestaerday by Junichi Katsu

Committer:
jksoft
Date:
Wed Apr 02 01:43:55 2014 +0000
Revision:
0:5975af170e43
1st Prototype

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:5975af170e43 1 /*
jksoft 0:5975af170e43 2 * WS2812 tape led IC
jksoft 0:5975af170e43 3 *
jksoft 0:5975af170e43 4 * 0.35us 0.8us (+-150ns)
jksoft 0:5975af170e43 5 * 0: |^^^^^|__________|
jksoft 0:5975af170e43 6 *
jksoft 0:5975af170e43 7 * 0.7us 0.6us (+-150ns)
jksoft 0:5975af170e43 8 * 1: |^^^^^^^^^^|_____|
jksoft 0:5975af170e43 9 *
jksoft 0:5975af170e43 10 * >50us
jksoft 0:5975af170e43 11 * RESET: |________________|
jksoft 0:5975af170e43 12 */
jksoft 0:5975af170e43 13 #include "mbed.h"
jksoft 0:5975af170e43 14 #include "LEDStrip.h"
jksoft 0:5975af170e43 15
jksoft 0:5975af170e43 16 SPI tape(p11, NC, NC);
jksoft 0:5975af170e43 17
jksoft 0:5975af170e43 18 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
jksoft 0:5975af170e43 19 LPC_SSP_TypeDef *_ssp = LPC_SSP0;
jksoft 0:5975af170e43 20 #elif defined(TARGET_LPC11U24)
jksoft 0:5975af170e43 21 LPC_SSPx_Type *_ssp = LPC_SSP1;
jksoft 0:5975af170e43 22 #endif
jksoft 0:5975af170e43 23
jksoft 0:5975af170e43 24 int num = 100;
jksoft 0:5975af170e43 25 int *data;
jksoft 0:5975af170e43 26 volatile int busy = 0, wakeup = 0;
jksoft 0:5975af170e43 27
jksoft 0:5975af170e43 28
jksoft 0:5975af170e43 29 extern "C"
jksoft 0:5975af170e43 30 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
jksoft 0:5975af170e43 31 void SSP0_IRQHandler() {
jksoft 0:5975af170e43 32 #elif defined(TARGET_LPC11U24)
jksoft 0:5975af170e43 33 void SSP1_IRQHandler() {
jksoft 0:5975af170e43 34 #endif
jksoft 0:5975af170e43 35 static int addr = 0, bit = 0x800000;
jksoft 0:5975af170e43 36 repeat:
jksoft 0:5975af170e43 37 if (busy) {
jksoft 0:5975af170e43 38 // led data
jksoft 0:5975af170e43 39 while (_ssp->SR & (1<<1)) { // TNF
jksoft 0:5975af170e43 40 if (data[addr] & bit) {
jksoft 0:5975af170e43 41 // 1
jksoft 0:5975af170e43 42 _ssp->DR = 0x01f;
jksoft 0:5975af170e43 43 } else {
jksoft 0:5975af170e43 44 // 0
jksoft 0:5975af170e43 45 _ssp->DR = 0x07f;
jksoft 0:5975af170e43 46 }
jksoft 0:5975af170e43 47 bit = bit >> 1;
jksoft 0:5975af170e43 48 if (bit == 0) {
jksoft 0:5975af170e43 49 bit = 0x800000;
jksoft 0:5975af170e43 50 addr ++;
jksoft 0:5975af170e43 51 if (addr >= num) {
jksoft 0:5975af170e43 52 addr = 0;
jksoft 0:5975af170e43 53 busy = 0;
jksoft 0:5975af170e43 54 goto repeat;
jksoft 0:5975af170e43 55 }
jksoft 0:5975af170e43 56 }
jksoft 0:5975af170e43 57 }
jksoft 0:5975af170e43 58 } else {
jksoft 0:5975af170e43 59 // blank
jksoft 0:5975af170e43 60 while (_ssp->SR & (1<<1)) { // TNF
jksoft 0:5975af170e43 61 _ssp->DR = 0xfff;
jksoft 0:5975af170e43 62 if (addr < 50) {
jksoft 0:5975af170e43 63 addr ++;
jksoft 0:5975af170e43 64 } else {
jksoft 0:5975af170e43 65 addr = 0;
jksoft 0:5975af170e43 66 if (wakeup) {
jksoft 0:5975af170e43 67 busy = 1;
jksoft 0:5975af170e43 68 wakeup = 0;
jksoft 0:5975af170e43 69 goto repeat;
jksoft 0:5975af170e43 70 }
jksoft 0:5975af170e43 71 }
jksoft 0:5975af170e43 72 }
jksoft 0:5975af170e43 73 }
jksoft 0:5975af170e43 74 }
jksoft 0:5975af170e43 75
jksoft 0:5975af170e43 76 void tapeInit (int freq, int n) {
jksoft 0:5975af170e43 77
jksoft 0:5975af170e43 78 num = n;
jksoft 0:5975af170e43 79 // data = new int(num);
jksoft 0:5975af170e43 80 data = (int*)malloc(sizeof(int) * num);
jksoft 0:5975af170e43 81 for (int i = 0; i < num; i ++) {
jksoft 0:5975af170e43 82 data[i] = 0;
jksoft 0:5975af170e43 83 }
jksoft 0:5975af170e43 84
jksoft 0:5975af170e43 85 tape.format(10, 1);
jksoft 0:5975af170e43 86 if (freq) {
jksoft 0:5975af170e43 87 tape.frequency(freq * 1000);
jksoft 0:5975af170e43 88 } else {
jksoft 0:5975af170e43 89 tape.frequency(8000000);
jksoft 0:5975af170e43 90 }
jksoft 0:5975af170e43 91 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
jksoft 0:5975af170e43 92 NVIC_SetVector(SSP0_IRQn, (uint32_t)SSP0_IRQHandler);
jksoft 0:5975af170e43 93 NVIC_SetPriority(SSP0_IRQn, 0);
jksoft 0:5975af170e43 94 NVIC_EnableIRQ(SSP0_IRQn);
jksoft 0:5975af170e43 95 #elif defined(TARGET_LPC11U24)
jksoft 0:5975af170e43 96 NVIC_SetVector(SSP1_IRQn, (uint32_t)SSP1_IRQHandler);
jksoft 0:5975af170e43 97 NVIC_SetPriority(SSP1_IRQn, 0);
jksoft 0:5975af170e43 98 NVIC_EnableIRQ(SSP1_IRQn);
jksoft 0:5975af170e43 99 #endif
jksoft 0:5975af170e43 100 _ssp->IMSC |= (1<<3); // TXIM
jksoft 0:5975af170e43 101 }
jksoft 0:5975af170e43 102
jksoft 0:5975af170e43 103 void tapeSet (int n, int dat) {
jksoft 0:5975af170e43 104 if (n >= 0 && n < num) {
jksoft 0:5975af170e43 105 // RGB -> GRB
jksoft 0:5975af170e43 106 data[n] = ((dat & 0xff0000) >> 8) | ((dat & 0xff00) << 8) | (dat & 0xff);
jksoft 0:5975af170e43 107 }
jksoft 0:5975af170e43 108 }
jksoft 0:5975af170e43 109
jksoft 0:5975af170e43 110 void tapeSend () {
jksoft 0:5975af170e43 111 if (busy) {
jksoft 0:5975af170e43 112 while (busy);
jksoft 0:5975af170e43 113 wait_us(50);
jksoft 0:5975af170e43 114 }
jksoft 0:5975af170e43 115 wakeup = 1;
jksoft 0:5975af170e43 116 while (wakeup);
jksoft 0:5975af170e43 117 }
jksoft 0:5975af170e43 118
jksoft 0:5975af170e43 119 int tapeGet (int n) {
jksoft 0:5975af170e43 120 return ((data[n] & 0xff0000) >> 8) | ((data[n] & 0xff00) << 8) | (data[n] & 0xff);
jksoft 0:5975af170e43 121 }