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:
Mon Apr 11 06:52:42 2016 +0000
Revision:
0:4b0686730a99
Child:
1:4aff1ebb42c1
TG-LPC11U35-501???????

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 0:4b0686730a99 46 //_ssp->DR = 0x007;
hirobe0913 0:4b0686730a99 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 0:4b0686730a99 65 if (addr < 50) {
hirobe0913 0:4b0686730a99 66 addr ++;
hirobe0913 0:4b0686730a99 67 } else {
hirobe0913 0:4b0686730a99 68 addr = 0;
hirobe0913 0:4b0686730a99 69 if (wakeup) {
hirobe0913 0:4b0686730a99 70 busy = 1;
hirobe0913 0:4b0686730a99 71 wakeup = 0;
hirobe0913 0:4b0686730a99 72 goto repeat;
hirobe0913 0:4b0686730a99 73 }
hirobe0913 0:4b0686730a99 74 }
hirobe0913 0:4b0686730a99 75 }
hirobe0913 0:4b0686730a99 76 }
hirobe0913 0:4b0686730a99 77 }
hirobe0913 0:4b0686730a99 78
hirobe0913 0:4b0686730a99 79 void tapeInit (int freq, int n) {
hirobe0913 0:4b0686730a99 80
hirobe0913 0:4b0686730a99 81 num = n;
hirobe0913 0:4b0686730a99 82 // data = new int(num);
hirobe0913 0:4b0686730a99 83 data = (int*)malloc(sizeof(int) * num);
hirobe0913 0:4b0686730a99 84 for (int i = 0; i < num; i ++) {
hirobe0913 0:4b0686730a99 85 data[i] = 0;
hirobe0913 0:4b0686730a99 86 }
hirobe0913 0:4b0686730a99 87
hirobe0913 0:4b0686730a99 88 tape.format(10, 1);
hirobe0913 0:4b0686730a99 89 if (freq) {
hirobe0913 0:4b0686730a99 90 tape.frequency(freq * 1000);
hirobe0913 0:4b0686730a99 91 } else {
hirobe0913 0:4b0686730a99 92 tape.frequency(8000000);
hirobe0913 0:4b0686730a99 93 }
hirobe0913 0:4b0686730a99 94 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
hirobe0913 0:4b0686730a99 95 NVIC_SetVector(SSP0_IRQn, (uint32_t)SSP0_IRQHandler);
hirobe0913 0:4b0686730a99 96 NVIC_SetPriority(SSP0_IRQn, 0);
hirobe0913 0:4b0686730a99 97 NVIC_EnableIRQ(SSP0_IRQn);
hirobe0913 0:4b0686730a99 98 #elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_501)
hirobe0913 0:4b0686730a99 99 NVIC_SetVector(SSP1_IRQn, (uint32_t)SSP1_IRQHandler);
hirobe0913 0:4b0686730a99 100 NVIC_SetPriority(SSP1_IRQn, 0);
hirobe0913 0:4b0686730a99 101 NVIC_EnableIRQ(SSP1_IRQn);
hirobe0913 0:4b0686730a99 102 #endif
hirobe0913 0:4b0686730a99 103 _ssp->IMSC |= (1<<3); // TXIM
hirobe0913 0:4b0686730a99 104 }
hirobe0913 0:4b0686730a99 105
hirobe0913 0:4b0686730a99 106 void tapeSet (int n, int dat) {
hirobe0913 0:4b0686730a99 107 if (n >= 0 && n < num) {
hirobe0913 0:4b0686730a99 108 // RGB -> GRB
hirobe0913 0:4b0686730a99 109 data[n] = ((dat & 0xff0000) >> 8) | ((dat & 0xff00) << 8) | (dat & 0xff);
hirobe0913 0:4b0686730a99 110 }
hirobe0913 0:4b0686730a99 111 }
hirobe0913 0:4b0686730a99 112
hirobe0913 0:4b0686730a99 113 void tapeSend () {
hirobe0913 0:4b0686730a99 114 if (busy) {
hirobe0913 0:4b0686730a99 115 while (busy);
hirobe0913 0:4b0686730a99 116 wait_us(50);
hirobe0913 0:4b0686730a99 117 }
hirobe0913 0:4b0686730a99 118 wakeup = 1;
hirobe0913 0:4b0686730a99 119 while (wakeup);
hirobe0913 0:4b0686730a99 120 }
hirobe0913 0:4b0686730a99 121
hirobe0913 0:4b0686730a99 122 int tapeGet (int n) {
hirobe0913 0:4b0686730a99 123 return ((data[n] & 0xff0000) >> 8) | ((data[n] & 0xff00) << 8) | (data[n] & 0xff);
hirobe0913 0:4b0686730a99 124 }