TG-LPC11U35-501に対応

Dependencies:   mbed

こちらのページのプログラムを、TG-LPC11U35-501に対応させました。
https://developer.mbed.org/users/tkasa/code/LEDTape_WS2812/wiki/Homepage

動作に疑問があるため、教えを請うための公開です。
疑問が解消され次第公開を終了します。

(2016/04/13 追記)
おかしな動作解消されました。

プログラム LEDstrip_WS2812.cpp を修正しました。
修正点はコメントを加えてあります。

しばらくしたら、削除する予定です。

Committer:
hirobe0913
Date:
Wed Apr 13 06:52:12 2016 +0000
Revision:
2:ebd3f4b4e0a3
Parent:
1:4aff1ebb42c1
????????????

Who changed what in which revision?

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