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.
Dependencies: TLC59116
Fork of led-panel by
main.cpp@2:417ed8ce01b5, 2021-11-09 (annotated)
- Committer:
 - Suzutomo
 - Date:
 - Tue Nov 09 07:29:21 2021 +0000
 - Revision:
 - 2:417ed8ce01b5
 - Parent:
 - 1:c3f2c02fa679
 - Child:
 - 5:f7b4ba4aa6af
 
2019 code
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Suzutomo | 0:0ba9df5f8571 | 1 | #include "mbed.h" | 
| Suzutomo | 1:c3f2c02fa679 | 2 | #include "TLC59116.h" | 
| Suzutomo | 0:0ba9df5f8571 | 3 | |
| Suzutomo | 2:417ed8ce01b5 | 4 | #define PI 3.1415926535897934238 | 
| Suzutomo | 2:417ed8ce01b5 | 5 | |
| Suzutomo | 2:417ed8ce01b5 | 6 | RawSerial pc(USBTX,USBRX,115200); | 
| Suzutomo | 2:417ed8ce01b5 | 7 | RawSerial dev(PA_9,PA_10,115200); | 
| Suzutomo | 2:417ed8ce01b5 | 8 | DigitalIn user(PC_13); | 
| Suzutomo | 2:417ed8ce01b5 | 9 | I2C i2c(PB_9,PB_8); | 
| Suzutomo | 2:417ed8ce01b5 | 10 | I2C arI2c(PB_4,PA_8); | 
| Suzutomo | 2:417ed8ce01b5 | 11 | TLC59116 ledUnit[] = {TLC59116(&i2c,0x60 << 1), | 
| Suzutomo | 2:417ed8ce01b5 | 12 | TLC59116(&i2c,0x61 << 1), | 
| Suzutomo | 2:417ed8ce01b5 | 13 | TLC59116(&i2c,0x62 << 1), | 
| Suzutomo | 2:417ed8ce01b5 | 14 | TLC59116(&i2c,0x63 << 1) | 
| Suzutomo | 2:417ed8ce01b5 | 15 | }; | 
| Suzutomo | 2:417ed8ce01b5 | 16 | |
| Suzutomo | 2:417ed8ce01b5 | 17 | char data = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 18 | |
| Suzutomo | 2:417ed8ce01b5 | 19 | void re() | 
| Suzutomo | 2:417ed8ce01b5 | 20 | { | 
| Suzutomo | 2:417ed8ce01b5 | 21 | while (1) { | 
| Suzutomo | 2:417ed8ce01b5 | 22 | arI2c.read(0x10<<1,&data,1); | 
| Suzutomo | 2:417ed8ce01b5 | 23 | //printf("%x\r\n",data); | 
| Suzutomo | 2:417ed8ce01b5 | 24 | wait_us(0.05 * 1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 25 | } | 
| Suzutomo | 2:417ed8ce01b5 | 26 | } | 
| Suzutomo | 2:417ed8ce01b5 | 27 | |
| Suzutomo | 2:417ed8ce01b5 | 28 | void Init(); | 
| Suzutomo | 2:417ed8ce01b5 | 29 | |
| Suzutomo | 2:417ed8ce01b5 | 30 | void I2cDeviceChecker(); | 
| Suzutomo | 2:417ed8ce01b5 | 31 | |
| Suzutomo | 2:417ed8ce01b5 | 32 | void LightPanel(int i,uint32_t color); | 
| Suzutomo | 2:417ed8ce01b5 | 33 | void LightPanel(int i,uint8_t color_r,uint8_t color_g,uint8_t color_b); | 
| Suzutomo | 2:417ed8ce01b5 | 34 | void Gradation(int i,uint32_t start,uint32_t end,float per); | 
| Suzutomo | 2:417ed8ce01b5 | 35 | void Send(); | 
| Suzutomo | 2:417ed8ce01b5 | 36 | |
| Suzutomo | 2:417ed8ce01b5 | 37 | uint32_t HSVtoRGB(float h,float s,float v); | 
| Suzutomo | 2:417ed8ce01b5 | 38 | |
| Suzutomo | 2:417ed8ce01b5 | 39 | |
| Suzutomo | 2:417ed8ce01b5 | 40 | int main() | 
| Suzutomo | 2:417ed8ce01b5 | 41 | { | 
| Suzutomo | 2:417ed8ce01b5 | 42 | printf("Start Program\r\n"); | 
| Suzutomo | 2:417ed8ce01b5 | 43 | |
| Suzutomo | 2:417ed8ce01b5 | 44 | Thread i2cRead; | 
| Suzutomo | 2:417ed8ce01b5 | 45 | i2cRead.start(re); | 
| Suzutomo | 2:417ed8ce01b5 | 46 | |
| Suzutomo | 2:417ed8ce01b5 | 47 | float count = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 48 | int color = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 49 | |
| Suzutomo | 2:417ed8ce01b5 | 50 | Init(); | 
| Suzutomo | 2:417ed8ce01b5 | 51 | |
| Suzutomo | 2:417ed8ce01b5 | 52 | while(1) { | 
| Suzutomo | 2:417ed8ce01b5 | 53 | count += 0.01; | 
| Suzutomo | 2:417ed8ce01b5 | 54 | for (int i = 0; i < 16; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 55 | LightPanel(i,HSVtoRGB(fmod((i / 16.0) + count,1),1,1)); | 
| Suzutomo | 2:417ed8ce01b5 | 56 | } | 
| Suzutomo | 2:417ed8ce01b5 | 57 | //printf("%f",fmod((0 / 16.0) + count,1)); | 
| Suzutomo | 2:417ed8ce01b5 | 58 | //float tri =abs(fmod(count / 30.0, 2.0) - 1); | 
| Suzutomo | 2:417ed8ce01b5 | 59 | for (int i = 0; i < 4; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 60 | if ((data >> i) & 0x01) | 
| Suzutomo | 2:417ed8ce01b5 | 61 | for(int j = 0; j < 4; j++) LightPanel(i + 4*j,0xFFFFFF); | 
| Suzutomo | 2:417ed8ce01b5 | 62 | //printf("%d ",(data >> i)&0x01); | 
| Suzutomo | 2:417ed8ce01b5 | 63 | } | 
| Suzutomo | 2:417ed8ce01b5 | 64 | |
| Suzutomo | 2:417ed8ce01b5 | 65 | //printf("%f\r\n",sin(count)); | 
| Suzutomo | 2:417ed8ce01b5 | 66 | //printf("%f\r\n",tri); | 
| Suzutomo | 2:417ed8ce01b5 | 67 | Send(); | 
| Suzutomo | 2:417ed8ce01b5 | 68 | |
| Suzutomo | 2:417ed8ce01b5 | 69 | wait_us(1*1e6 / 60); | 
| Suzutomo | 2:417ed8ce01b5 | 70 | |
| Suzutomo | 2:417ed8ce01b5 | 71 | //printf("\r\n"); | 
| Suzutomo | 2:417ed8ce01b5 | 72 | } | 
| Suzutomo | 2:417ed8ce01b5 | 73 | } | 
| Suzutomo | 2:417ed8ce01b5 | 74 | |
| Suzutomo | 2:417ed8ce01b5 | 75 | void Init() | 
| Suzutomo | 2:417ed8ce01b5 | 76 | { | 
| Suzutomo | 2:417ed8ce01b5 | 77 | for (int i = 0; i <= 16; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 78 | LightPanel(i - 1,0x0); | 
| Suzutomo | 2:417ed8ce01b5 | 79 | LightPanel(i,0xFFFFFF); | 
| Suzutomo | 2:417ed8ce01b5 | 80 | Send(); | 
| Suzutomo | 2:417ed8ce01b5 | 81 | wait_us(100 * 1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 82 | } | 
| Suzutomo | 2:417ed8ce01b5 | 83 | } | 
| Suzutomo | 2:417ed8ce01b5 | 84 | |
| Suzutomo | 2:417ed8ce01b5 | 85 | void Gradation(int i,uint32_t start,uint32_t end,float per) | 
| Suzutomo | 2:417ed8ce01b5 | 86 | { | 
| Suzutomo | 2:417ed8ce01b5 | 87 | uint8_t s_r = (start & 0xFF0000) >> 16; | 
| Suzutomo | 2:417ed8ce01b5 | 88 | uint8_t s_g = (start & 0xFF00) >> 8; | 
| Suzutomo | 2:417ed8ce01b5 | 89 | uint8_t s_b = (start & 0xFF); | 
| Suzutomo | 2:417ed8ce01b5 | 90 | |
| Suzutomo | 2:417ed8ce01b5 | 91 | uint8_t e_r = (end & 0xFF0000) >> 16; | 
| Suzutomo | 2:417ed8ce01b5 | 92 | uint8_t e_g = (end & 0xFF00) >> 8; | 
| Suzutomo | 2:417ed8ce01b5 | 93 | uint8_t e_b = (end & 0xFF); | 
| Suzutomo | 2:417ed8ce01b5 | 94 | |
| Suzutomo | 2:417ed8ce01b5 | 95 | uint8_t c_r = (e_r - s_r) * per + s_r; | 
| Suzutomo | 2:417ed8ce01b5 | 96 | uint8_t c_g = (e_g - s_g) * per + s_g; | 
| Suzutomo | 2:417ed8ce01b5 | 97 | uint8_t c_b = (e_b - s_b) * per + s_b; | 
| Suzutomo | 2:417ed8ce01b5 | 98 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3,c_g); | 
| Suzutomo | 2:417ed8ce01b5 | 99 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 1,c_r); | 
| Suzutomo | 2:417ed8ce01b5 | 100 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 2,c_b); | 
| Suzutomo | 2:417ed8ce01b5 | 101 | |
| Suzutomo | 2:417ed8ce01b5 | 102 | } | 
| Suzutomo | 2:417ed8ce01b5 | 103 | |
| Suzutomo | 2:417ed8ce01b5 | 104 | |
| Suzutomo | 2:417ed8ce01b5 | 105 | |
| Suzutomo | 2:417ed8ce01b5 | 106 | void LightPanel(int i,uint32_t color) | 
| Suzutomo | 2:417ed8ce01b5 | 107 | { | 
| Suzutomo | 2:417ed8ce01b5 | 108 | if (i >= 0 && i < 16) { | 
| Suzutomo | 2:417ed8ce01b5 | 109 | uint8_t c_r = (color & 0xFF0000) >> 16; | 
| Suzutomo | 2:417ed8ce01b5 | 110 | uint8_t c_g = (color & 0xFF00) >> 8; | 
| Suzutomo | 2:417ed8ce01b5 | 111 | uint8_t c_b = (color & 0xFF); | 
| Suzutomo | 2:417ed8ce01b5 | 112 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3,c_g); | 
| Suzutomo | 2:417ed8ce01b5 | 113 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 1,c_r); | 
| Suzutomo | 2:417ed8ce01b5 | 114 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 2,c_b); | 
| Suzutomo | 2:417ed8ce01b5 | 115 | } | 
| Suzutomo | 2:417ed8ce01b5 | 116 | } | 
| Suzutomo | 2:417ed8ce01b5 | 117 | |
| Suzutomo | 2:417ed8ce01b5 | 118 | void LightPanel(int i,uint8_t c_r,uint8_t c_g,uint8_t c_b) | 
| Suzutomo | 2:417ed8ce01b5 | 119 | { | 
| Suzutomo | 2:417ed8ce01b5 | 120 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3,c_g); | 
| Suzutomo | 2:417ed8ce01b5 | 121 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 1,c_r); | 
| Suzutomo | 2:417ed8ce01b5 | 122 | ledUnit[(int)(i / 4)].SetChannel((i % 4) * 3 + 2,c_b); | 
| Suzutomo | 2:417ed8ce01b5 | 123 | } | 
| Suzutomo | 2:417ed8ce01b5 | 124 | |
| Suzutomo | 2:417ed8ce01b5 | 125 | void Send() | 
| Suzutomo | 2:417ed8ce01b5 | 126 | { | 
| Suzutomo | 2:417ed8ce01b5 | 127 | for (int i = 0; i < 4; i++) ledUnit[i].Send(2,12); | 
| Suzutomo | 2:417ed8ce01b5 | 128 | } | 
| Suzutomo | 2:417ed8ce01b5 | 129 | |
| Suzutomo | 2:417ed8ce01b5 | 130 | void I2cDeviceChecker() | 
| Suzutomo | 2:417ed8ce01b5 | 131 | { | 
| Suzutomo | 2:417ed8ce01b5 | 132 | char data[1] = {0x00}; | 
| Suzutomo | 2:417ed8ce01b5 | 133 | for (int i = 0; i < 127; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 134 | printf("%2x : %d\r\n",i,i2c.write(i<<1,data,1)); | 
| Suzutomo | 2:417ed8ce01b5 | 135 | } | 
| Suzutomo | 2:417ed8ce01b5 | 136 | } | 
| Suzutomo | 2:417ed8ce01b5 | 137 | |
| Suzutomo | 2:417ed8ce01b5 | 138 | uint32_t HSVtoRGB(float h,float s,float v) | 
| Suzutomo | 2:417ed8ce01b5 | 139 | { | 
| Suzutomo | 2:417ed8ce01b5 | 140 | float r = v; | 
| Suzutomo | 2:417ed8ce01b5 | 141 | float g = v; | 
| Suzutomo | 2:417ed8ce01b5 | 142 | float b = v; | 
| Suzutomo | 2:417ed8ce01b5 | 143 | if (s > 0.0f) { | 
| Suzutomo | 2:417ed8ce01b5 | 144 | h *= 6.0f; | 
| Suzutomo | 2:417ed8ce01b5 | 145 | int i = (int) h; | 
| Suzutomo | 2:417ed8ce01b5 | 146 | float f = h - (float) i; | 
| Suzutomo | 2:417ed8ce01b5 | 147 | switch (i) { | 
| Suzutomo | 2:417ed8ce01b5 | 148 | default: | 
| Suzutomo | 2:417ed8ce01b5 | 149 | case 0: | 
| Suzutomo | 2:417ed8ce01b5 | 150 | g *= 1 - s * (1 - f); | 
| Suzutomo | 2:417ed8ce01b5 | 151 | b *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 152 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 153 | case 1: | 
| Suzutomo | 2:417ed8ce01b5 | 154 | r *= 1 - s * f; | 
| Suzutomo | 2:417ed8ce01b5 | 155 | b *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 156 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 157 | case 2: | 
| Suzutomo | 2:417ed8ce01b5 | 158 | r *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 159 | b *= 1 - s * (1 - f); | 
| Suzutomo | 2:417ed8ce01b5 | 160 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 161 | case 3: | 
| Suzutomo | 2:417ed8ce01b5 | 162 | r *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 163 | g *= 1 - s * f; | 
| Suzutomo | 2:417ed8ce01b5 | 164 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 165 | case 4: | 
| Suzutomo | 2:417ed8ce01b5 | 166 | r *= 1 - s * (1 - f); | 
| Suzutomo | 2:417ed8ce01b5 | 167 | g *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 168 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 169 | case 5: | 
| Suzutomo | 2:417ed8ce01b5 | 170 | g *= 1 - s; | 
| Suzutomo | 2:417ed8ce01b5 | 171 | b *= 1 - s * f; | 
| Suzutomo | 2:417ed8ce01b5 | 172 | break; | 
| Suzutomo | 2:417ed8ce01b5 | 173 | } | 
| Suzutomo | 2:417ed8ce01b5 | 174 | } | 
| Suzutomo | 2:417ed8ce01b5 | 175 | r *= 255; | 
| Suzutomo | 2:417ed8ce01b5 | 176 | g *= 255; | 
| Suzutomo | 2:417ed8ce01b5 | 177 | b *= 255; | 
| Suzutomo | 2:417ed8ce01b5 | 178 | return ((int)r << 16) | ((int)g << 8) | (int)b; | 
| Suzutomo | 2:417ed8ce01b5 | 179 | |
| Suzutomo | 2:417ed8ce01b5 | 180 | } | 
| Suzutomo | 2:417ed8ce01b5 | 181 | |
| Suzutomo | 2:417ed8ce01b5 | 182 | |
| Suzutomo | 2:417ed8ce01b5 | 183 | /* | 
| Suzutomo | 2:417ed8ce01b5 | 184 | SPI spi(PB_15,PB_14,PB_13); | 
| Suzutomo | 2:417ed8ce01b5 | 185 | |
| Suzutomo | 2:417ed8ce01b5 | 186 | DigitalOut cs(PC_0); | 
| Suzutomo | 2:417ed8ce01b5 | 187 | |
| Suzutomo | 0:0ba9df5f8571 | 188 | DigitalIn sv2[8] = { | 
| Suzutomo | 0:0ba9df5f8571 | 189 | PC_4, | 
| Suzutomo | 0:0ba9df5f8571 | 190 | PA_10, | 
| Suzutomo | 0:0ba9df5f8571 | 191 | PB_13, | 
| Suzutomo | 0:0ba9df5f8571 | 192 | PB_5, | 
| Suzutomo | 0:0ba9df5f8571 | 193 | PB_14, | 
| Suzutomo | 0:0ba9df5f8571 | 194 | PB_4, | 
| Suzutomo | 0:0ba9df5f8571 | 195 | PB_15, | 
| Suzutomo | 0:0ba9df5f8571 | 196 | PB_10, | 
| Suzutomo | 0:0ba9df5f8571 | 197 | }; | 
| Suzutomo | 0:0ba9df5f8571 | 198 | |
| Suzutomo | 0:0ba9df5f8571 | 199 | DigitalOut clk(PC_9); | 
| Suzutomo | 0:0ba9df5f8571 | 200 | DigitalOut oe(PC_5,0); | 
| Suzutomo | 0:0ba9df5f8571 | 201 | //PwmOut intb(PA_12); | 
| Suzutomo | 0:0ba9df5f8571 | 202 | PwmOut sdb(PA_11); | 
| Suzutomo | 0:0ba9df5f8571 | 203 | Thread te; | 
| Suzutomo | 2:417ed8ce01b5 | 204 | |
| Suzutomo | 2:417ed8ce01b5 | 205 | volatile bool touch[8] = {0}; | 
| Suzutomo | 2:417ed8ce01b5 | 206 | |
| Suzutomo | 2:417ed8ce01b5 | 207 | |
| Suzutomo | 2:417ed8ce01b5 | 208 | const int generallyWait = 200; | 
| Suzutomo | 2:417ed8ce01b5 | 209 | |
| Suzutomo | 2:417ed8ce01b5 | 210 | void GetData(char com,char *data,int length) | 
| Suzutomo | 2:417ed8ce01b5 | 211 | { | 
| Suzutomo | 2:417ed8ce01b5 | 212 | cs = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 213 | char enable = spi.write(com); | 
| Suzutomo | 2:417ed8ce01b5 | 214 | wait_us(generallyWait); | 
| Suzutomo | 2:417ed8ce01b5 | 215 | if (enable == 0x55) { | 
| Suzutomo | 2:417ed8ce01b5 | 216 | for (int i = 0; i < length; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 217 | data[i] = spi.write(0x00); | 
| Suzutomo | 2:417ed8ce01b5 | 218 | wait_us(generallyWait); | 
| Suzutomo | 2:417ed8ce01b5 | 219 | } | 
| Suzutomo | 2:417ed8ce01b5 | 220 | } else printf("error\r\n"); | 
| Suzutomo | 2:417ed8ce01b5 | 221 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 222 | } | 
| Suzutomo | 2:417ed8ce01b5 | 223 | |
| Suzutomo | 2:417ed8ce01b5 | 224 | void SetData(char com,char *data,int length) | 
| Suzutomo | 2:417ed8ce01b5 | 225 | { | 
| Suzutomo | 2:417ed8ce01b5 | 226 | cs = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 227 | char enable = spi.write(com); | 
| Suzutomo | 2:417ed8ce01b5 | 228 | wait_us(generallyWait); | 
| Suzutomo | 2:417ed8ce01b5 | 229 | if (enable == 0x55) { | 
| Suzutomo | 2:417ed8ce01b5 | 230 | for (int i = 0; i < length; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 231 | spi.write(data[i]); | 
| Suzutomo | 2:417ed8ce01b5 | 232 | wait_us(generallyWait); | 
| Suzutomo | 2:417ed8ce01b5 | 233 | } | 
| Suzutomo | 2:417ed8ce01b5 | 234 | } else printf("error\r\n"); | 
| Suzutomo | 2:417ed8ce01b5 | 235 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 236 | wait_us(150*1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 237 | } | 
| Suzutomo | 2:417ed8ce01b5 | 238 | |
| Suzutomo | 2:417ed8ce01b5 | 239 | int Reset() | 
| Suzutomo | 2:417ed8ce01b5 | 240 | { | 
| Suzutomo | 2:417ed8ce01b5 | 241 | cs = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 242 | char enable = spi.write(0x04); | 
| Suzutomo | 2:417ed8ce01b5 | 243 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 244 | wait_us(180 * 1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 245 | return enable == 0x55; | 
| Suzutomo | 2:417ed8ce01b5 | 246 | } | 
| Suzutomo | 2:417ed8ce01b5 | 247 | |
| Suzutomo | 2:417ed8ce01b5 | 248 | int EraseEeprom() | 
| Suzutomo | 2:417ed8ce01b5 | 249 | { | 
| Suzutomo | 2:417ed8ce01b5 | 250 | cs = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 251 | char enable = spi.write(0x0C); | 
| Suzutomo | 2:417ed8ce01b5 | 252 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 253 | wait_us(60 * 1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 254 | return enable == 0x55; | 
| Suzutomo | 2:417ed8ce01b5 | 255 | } | 
| Suzutomo | 2:417ed8ce01b5 | 256 | |
| Suzutomo | 2:417ed8ce01b5 | 257 | int Calibrate() | 
| Suzutomo | 2:417ed8ce01b5 | 258 | { | 
| Suzutomo | 2:417ed8ce01b5 | 259 | cs = 0; | 
| Suzutomo | 2:417ed8ce01b5 | 260 | char enable = spi.write(0x03); | 
| Suzutomo | 2:417ed8ce01b5 | 261 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 262 | wait_us(180 * 1e3); | 
| Suzutomo | 2:417ed8ce01b5 | 263 | return enable == 0x55; | 
| Suzutomo | 2:417ed8ce01b5 | 264 | } | 
| Suzutomo | 2:417ed8ce01b5 | 265 | |
| Suzutomo | 0:0ba9df5f8571 | 266 | |
| Suzutomo | 0:0ba9df5f8571 | 267 | void teTh() | 
| Suzutomo | 0:0ba9df5f8571 | 268 | { | 
| Suzutomo | 2:417ed8ce01b5 | 269 | int place[8] = {0,1,8,9,6,7,4,5}; | 
| Suzutomo | 2:417ed8ce01b5 | 270 | char *data; | 
| Suzutomo | 2:417ed8ce01b5 | 271 | data = new char[2]; | 
| Suzutomo | 0:0ba9df5f8571 | 272 | while(1) { | 
| Suzutomo | 2:417ed8ce01b5 | 273 | GetData(0xC1,data,2); | 
| Suzutomo | 2:417ed8ce01b5 | 274 | int d = (data[0] << 8)| data[1]; | 
| Suzutomo | 0:0ba9df5f8571 | 275 | for (int i = 0; i < 8; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 276 | touch[i] = (d >> place[i]) & 0x1; | 
| Suzutomo | 0:0ba9df5f8571 | 277 | } | 
| Suzutomo | 2:417ed8ce01b5 | 278 | |
| Suzutomo | 2:417ed8ce01b5 | 279 | for (int i = 7; i >= 0; i--) { | 
| Suzutomo | 2:417ed8ce01b5 | 280 | printf("%x",touch[i]); | 
| Suzutomo | 2:417ed8ce01b5 | 281 | } | 
| Suzutomo | 0:0ba9df5f8571 | 282 | printf("\r\n"); | 
| Suzutomo | 2:417ed8ce01b5 | 283 | |
| Suzutomo | 2:417ed8ce01b5 | 284 | //wait_us(100); | 
| Suzutomo | 2:417ed8ce01b5 | 285 | |
| Suzutomo | 0:0ba9df5f8571 | 286 | } | 
| Suzutomo | 2:417ed8ce01b5 | 287 | delete data; | 
| Suzutomo | 0:0ba9df5f8571 | 288 | } | 
| Suzutomo | 0:0ba9df5f8571 | 289 | |
| Suzutomo | 2:417ed8ce01b5 | 290 | |
| Suzutomo | 2:417ed8ce01b5 | 291 | void main() { | 
| Suzutomo | 2:417ed8ce01b5 | 292 | cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 293 | |
| Suzutomo | 2:417ed8ce01b5 | 294 | spi.format(8,3); | 
| Suzutomo | 2:417ed8ce01b5 | 295 | spi.frequency(1500000); | 
| Suzutomo | 2:417ed8ce01b5 | 296 | |
| Suzutomo | 2:417ed8ce01b5 | 297 | char* data; | 
| Suzutomo | 2:417ed8ce01b5 | 298 | printf("Reset : %s\r\n",Reset() ? "OK" : "FALSE"); | 
| Suzutomo | 2:417ed8ce01b5 | 299 | printf("Erase EEPROM : %s\r\n",EraseEeprom() ? "OK" : "FALSE"); | 
| Suzutomo | 2:417ed8ce01b5 | 300 | |
| Suzutomo | 2:417ed8ce01b5 | 301 | |
| Suzutomo | 2:417ed8ce01b5 | 302 | |
| Suzutomo | 0:0ba9df5f8571 | 303 | |
| Suzutomo | 2:417ed8ce01b5 | 304 | |
| Suzutomo | 2:417ed8ce01b5 | 305 | |
| Suzutomo | 2:417ed8ce01b5 | 306 | data = new char[1]; | 
| Suzutomo | 2:417ed8ce01b5 | 307 | data[0] = 0b11110010; | 
| Suzutomo | 0:0ba9df5f8571 | 308 | |
| Suzutomo | 2:417ed8ce01b5 | 309 | SetData(0x90,data,1); | 
| Suzutomo | 2:417ed8ce01b5 | 310 | data[0] = 0b0; | 
| Suzutomo | 2:417ed8ce01b5 | 311 | SetData(0x97,data,1); | 
| Suzutomo | 2:417ed8ce01b5 | 312 | SetData(0x98,data,1); | 
| Suzutomo | 2:417ed8ce01b5 | 313 | |
| Suzutomo | 2:417ed8ce01b5 | 314 | data[0] = 0b00101000; | 
| Suzutomo | 2:417ed8ce01b5 | 315 | for (int i = 0; i < 11; i++) { | 
| Suzutomo | 2:417ed8ce01b5 | 316 | SetData(0xA3 + i,data,1); | 
| Suzutomo | 0:0ba9df5f8571 | 317 | } | 
| Suzutomo | 0:0ba9df5f8571 | 318 | |
| Suzutomo | 2:417ed8ce01b5 | 319 | |
| Suzutomo | 2:417ed8ce01b5 | 320 | printf("Calibrate : %s\r\n",Calibrate() ? "OK" : "FALSE"); | 
| Suzutomo | 0:0ba9df5f8571 | 321 | |
| Suzutomo | 2:417ed8ce01b5 | 322 | data = new char[42]; | 
| Suzutomo | 2:417ed8ce01b5 | 323 | GetData(0xC8,data,42); | 
| Suzutomo | 0:0ba9df5f8571 | 324 | |
| Suzutomo | 2:417ed8ce01b5 | 325 | //spi.write(0xC9); | 
| Suzutomo | 2:417ed8ce01b5 | 326 | //wait_us(150); | 
| Suzutomo | 2:417ed8ce01b5 | 327 | //printf("%x\r\n",spi.write(0x00)); | 
| Suzutomo | 2:417ed8ce01b5 | 328 | //cs = 1; | 
| Suzutomo | 2:417ed8ce01b5 | 329 | //wait_us(50 * 1e3); | 
| Suzutomo | 0:0ba9df5f8571 | 330 | |
| Suzutomo | 0:0ba9df5f8571 | 331 | |
| Suzutomo | 2:417ed8ce01b5 | 332 | //while (user.read()); | 
| Suzutomo | 2:417ed8ce01b5 | 333 | //te.start(teTh); | 
| Suzutomo | 2:417ed8ce01b5 | 334 | |
| Suzutomo | 2:417ed8ce01b5 | 335 | |
| Suzutomo | 0:0ba9df5f8571 | 336 | } | 
| Suzutomo | 2:417ed8ce01b5 | 337 | */ | 
