tft

Dependencies:   mbed Adafruit_GFX

Committer:
xkzy
Date:
Sun Dec 16 07:08:30 2018 +0000
Revision:
1:8daae36234f1
Parent:
0:bd6942344437
problem with put text;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
603405000053 0:bd6942344437 1 #include "mbed.h"
603405000053 0:bd6942344437 2 #include <Adafruit_GFX.h>
603405000053 0:bd6942344437 3 #define TFTWIDTH 320
603405000053 0:bd6942344437 4 #define TFTHEIGHT 480
603405000053 0:bd6942344437 5
603405000053 0:bd6942344437 6 #define TFT_NORTH {SPFD5408_MADCTL_MY | SPFD5408_MADCTL_BGR}
603405000053 0:bd6942344437 7 #define TFT_EAST {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_MY | SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR}
603405000053 0:bd6942344437 8 #define TFT_SOUTH {SPFD5408_MADCTL_MX | SPFD5408_MADCTL_BGR}
603405000053 0:bd6942344437 9 #define TFT_WEST {SPFD5408_MADCTL_MV | SPFD5408_MADCTL_BGR}
603405000053 0:bd6942344437 10
603405000053 0:bd6942344437 11 #define BLACK 0x0000
603405000053 0:bd6942344437 12 #define BLUE 0x001F
603405000053 0:bd6942344437 13 #define RED 0xF800
603405000053 0:bd6942344437 14 #define GREEN 0x07E0
603405000053 0:bd6942344437 15 #define CYAN 0x07FF
603405000053 0:bd6942344437 16 #define MAGENTA 0xF81F
603405000053 0:bd6942344437 17 #define YELLOW 0xFFE0
603405000053 0:bd6942344437 18 #define WHITE 0xFFFF
603405000053 0:bd6942344437 19
603405000053 0:bd6942344437 20 #define SPFD5408_SOFTRESET 0x01
603405000053 0:bd6942344437 21 #define SPFD5408_SLEEPIN 0x10
603405000053 0:bd6942344437 22 #define SPFD5408_SLEEPOUT 0x11
603405000053 0:bd6942344437 23 #define SPFD5408_NORMALDISP 0x13
603405000053 0:bd6942344437 24 #define SPFD5408_INVERTOFF 0x20
603405000053 0:bd6942344437 25 #define SPFD5408_INVERTON 0x21
603405000053 0:bd6942344437 26 #define SPFD5408_GAMMASET 0x26
603405000053 0:bd6942344437 27 #define SPFD5408_DISPLAYOFF 0x28
603405000053 0:bd6942344437 28 #define SPFD5408_DISPLAYON 0x29
603405000053 0:bd6942344437 29 #define SPFD5408_COLADDRSET 0x2A
603405000053 0:bd6942344437 30 #define SPFD5408_PAGEADDRSET 0x2B
603405000053 0:bd6942344437 31 #define SPFD5408_MEMORYWRITE 0x2C
603405000053 0:bd6942344437 32 #define SPFD5408_PIXELFORMAT 0x3A
603405000053 0:bd6942344437 33 #define SPFD5408_FRAMECONTROL 0xB1
603405000053 0:bd6942344437 34 #define SPFD5408_DISPLAYFUNC 0xB6
603405000053 0:bd6942344437 35 #define SPFD5408_ENTRYMODE 0xB7
603405000053 0:bd6942344437 36 #define SPFD5408_POWERCONTROL1 0xC0
603405000053 0:bd6942344437 37 #define SPFD5408_POWERCONTROL2 0xC1
603405000053 0:bd6942344437 38 #define SPFD5408_VCOMCONTROL1 0xC5
603405000053 0:bd6942344437 39 #define SPFD5408_VCOMCONTROL2 0xC7
603405000053 0:bd6942344437 40 #define SPFD5408_MEMCONTROL 0x36
603405000053 0:bd6942344437 41 #define SPFD5408_MADCTL 0x36
603405000053 0:bd6942344437 42 #define SPFD5408_MADCTL_MY 0x80
603405000053 0:bd6942344437 43 #define SPFD5408_MADCTL_MX 0x40
603405000053 0:bd6942344437 44 #define SPFD5408_MADCTL_MV 0x20
603405000053 0:bd6942344437 45 #define SPFD5408_MADCTL_ML 0x10
603405000053 0:bd6942344437 46 #define SPFD5408_MADCTL_RGB 0x00
603405000053 0:bd6942344437 47 #define SPFD5408_MADCTL_BGR 0x08
603405000053 0:bd6942344437 48 #define SPFD5408_MADCTL_MH 0x04
603405000053 0:bd6942344437 49
603405000053 0:bd6942344437 50 #define IDLE 1
603405000053 0:bd6942344437 51 #define ACTIVE 0
603405000053 0:bd6942344437 52 #define COMMAND 0
603405000053 0:bd6942344437 53 #define DATA 1
603405000053 0:bd6942344437 54
603405000053 0:bd6942344437 55 #define TEMPS 60
603405000053 0:bd6942344437 56
603405000053 0:bd6942344437 57 #define VERT_LINE 0
603405000053 0:bd6942344437 58 #define HORI_LINE 1
xkzy 1:8daae36234f1 59 /** setup tft **/
603405000053 0:bd6942344437 60 DigitalOut pinRD(A0); //PA_0;
603405000053 0:bd6942344437 61 DigitalOut pinWR(A1); //PA_1;
603405000053 0:bd6942344437 62 DigitalOut pinCD(A2); //PA_4;
603405000053 0:bd6942344437 63 DigitalOut pinCS(A3); //PB_0;
603405000053 0:bd6942344437 64 DigitalOut pinReset(A4);//PC_1;
603405000053 0:bd6942344437 65
603405000053 0:bd6942344437 66 BusInOut portTFT(D8, D9, D2, D3, D4, D5, D6, D7);
xkzy 1:8daae36234f1 67 /**set up cam*/
xkzy 1:8daae36234f1 68 RawSerial pc(SERIAL_TX, SERIAL_RX); //has to use rawserial ,serial too slow and has byte loss.
xkzy 1:8daae36234f1 69 RawSerial cam(PA_11, PA_12);
xkzy 1:8daae36234f1 70 RawSerial esp(PB_6, PA_10);
xkzy 1:8daae36234f1 71 DigitalOut read_state(LED1);
xkzy 1:8daae36234f1 72 InterruptIn frame_start(PC_5);
xkzy 1:8daae36234f1 73 InterruptIn ccap(USER_BUTTON);
xkzy 1:8daae36234f1 74
603405000053 0:bd6942344437 75
603405000053 0:bd6942344437 76 void WriteCommand(uint8_t c)
603405000053 0:bd6942344437 77 {
603405000053 0:bd6942344437 78 pinCD = COMMAND;
603405000053 0:bd6942344437 79 pinWR = ACTIVE;
603405000053 0:bd6942344437 80 portTFT = c;
603405000053 0:bd6942344437 81 pinWR = IDLE;
603405000053 0:bd6942344437 82 }
603405000053 0:bd6942344437 83
603405000053 0:bd6942344437 84 void WriteData(uint8_t d)
603405000053 0:bd6942344437 85 {
603405000053 0:bd6942344437 86 pinCD = DATA;
603405000053 0:bd6942344437 87 pinWR = ACTIVE;
603405000053 0:bd6942344437 88 portTFT = d;
603405000053 0:bd6942344437 89 pinWR = IDLE;
603405000053 0:bd6942344437 90 }
603405000053 0:bd6942344437 91
xkzy 1:8daae36234f1 92 //Serial pc(SERIAL_TX, SERIAL_RX);
603405000053 0:bd6942344437 93
603405000053 0:bd6942344437 94 DigitalOut myled(LED1);
603405000053 0:bd6942344437 95
603405000053 0:bd6942344437 96
603405000053 0:bd6942344437 97
603405000053 0:bd6942344437 98 void begin(void) {
603405000053 0:bd6942344437 99
603405000053 0:bd6942344437 100 pinCS = IDLE;
603405000053 0:bd6942344437 101 pinCD = DATA;
603405000053 0:bd6942344437 102 pinWR = IDLE;
603405000053 0:bd6942344437 103 pinRD = IDLE;
603405000053 0:bd6942344437 104 portTFT.output();
603405000053 0:bd6942344437 105
603405000053 0:bd6942344437 106 pinReset = ACTIVE;
603405000053 0:bd6942344437 107 pinReset = IDLE;
603405000053 0:bd6942344437 108
603405000053 0:bd6942344437 109 pinCS = ACTIVE;
603405000053 0:bd6942344437 110
603405000053 0:bd6942344437 111 WriteCommand(SPFD5408_SOFTRESET);
603405000053 0:bd6942344437 112 WriteData(0);
603405000053 0:bd6942344437 113 wait_ms(100);
603405000053 0:bd6942344437 114
603405000053 0:bd6942344437 115 WriteCommand(SPFD5408_MEMCONTROL);
603405000053 0:bd6942344437 116 WriteData(SPFD5408_MADCTL_MY | SPFD5408_MADCTL_BGR);
603405000053 0:bd6942344437 117
603405000053 0:bd6942344437 118 WriteCommand(SPFD5408_PIXELFORMAT);
603405000053 0:bd6942344437 119 WriteData(0x55);
603405000053 0:bd6942344437 120
603405000053 0:bd6942344437 121 WriteCommand(SPFD5408_FRAMECONTROL);
603405000053 0:bd6942344437 122 WriteData(0x00);
603405000053 0:bd6942344437 123 WriteData(0x1B);
603405000053 0:bd6942344437 124
603405000053 0:bd6942344437 125 WriteCommand(SPFD5408_SLEEPOUT);
603405000053 0:bd6942344437 126 WriteData(0);
603405000053 0:bd6942344437 127
603405000053 0:bd6942344437 128 WriteCommand(SPFD5408_DISPLAYON);
603405000053 0:bd6942344437 129 WriteData(0);
603405000053 0:bd6942344437 130 }
603405000053 0:bd6942344437 131
603405000053 0:bd6942344437 132 void setAddrWindow(int x1, int y1, int x2, int y2) {
603405000053 0:bd6942344437 133 pinCS = ACTIVE;
603405000053 0:bd6942344437 134 wait_us(TEMPS);
603405000053 0:bd6942344437 135 WriteCommand(SPFD5408_COLADDRSET);
603405000053 0:bd6942344437 136 WriteData(x1 >> 8);
603405000053 0:bd6942344437 137 WriteData(x1);
603405000053 0:bd6942344437 138 WriteData(x2 >> 8);
603405000053 0:bd6942344437 139 WriteData(x2);
603405000053 0:bd6942344437 140 wait_us(TEMPS);
603405000053 0:bd6942344437 141 pinCS = IDLE;
603405000053 0:bd6942344437 142
603405000053 0:bd6942344437 143 pinCS = ACTIVE;
603405000053 0:bd6942344437 144 wait_us(TEMPS);
603405000053 0:bd6942344437 145 WriteCommand(SPFD5408_PAGEADDRSET);
603405000053 0:bd6942344437 146 WriteData(y1 >> 8);
603405000053 0:bd6942344437 147 WriteData(y1);
603405000053 0:bd6942344437 148 WriteData(y2 >> 8);
603405000053 0:bd6942344437 149 WriteData(y2);
603405000053 0:bd6942344437 150 wait_us(TEMPS);
603405000053 0:bd6942344437 151 pinCS = IDLE;
603405000053 0:bd6942344437 152 }
603405000053 0:bd6942344437 153
603405000053 0:bd6942344437 154 void fillRect(uint16_t x1, uint16_t y1, uint16_t w, uint16_t h, uint16_t fillcolor) {
603405000053 0:bd6942344437 155 uint8_t hi, lo;
603405000053 0:bd6942344437 156 uint16_t x2, y2;
603405000053 0:bd6942344437 157 uint16_t i, j;
603405000053 0:bd6942344437 158
603405000053 0:bd6942344437 159 x2 = x1 + w - 1;
603405000053 0:bd6942344437 160 y2 = y1 + h - 1;
603405000053 0:bd6942344437 161 setAddrWindow(x1, y1, x2, y2);
603405000053 0:bd6942344437 162
603405000053 0:bd6942344437 163 hi = fillcolor >> 8;
603405000053 0:bd6942344437 164 lo = fillcolor;
603405000053 0:bd6942344437 165
603405000053 0:bd6942344437 166 pinCS = ACTIVE;
603405000053 0:bd6942344437 167
603405000053 0:bd6942344437 168 WriteCommand(SPFD5408_MEMORYWRITE);
603405000053 0:bd6942344437 169 pinCD = DATA;
603405000053 0:bd6942344437 170
603405000053 0:bd6942344437 171 for (i = h; i > 0; i--)
603405000053 0:bd6942344437 172 {
603405000053 0:bd6942344437 173 for (j = w; j > 0; j--)
603405000053 0:bd6942344437 174
603405000053 0:bd6942344437 175 {
603405000053 0:bd6942344437 176 pinWR = ACTIVE;
603405000053 0:bd6942344437 177 portTFT = hi;
603405000053 0:bd6942344437 178 pinWR = IDLE;
603405000053 0:bd6942344437 179 pinWR = ACTIVE;
603405000053 0:bd6942344437 180 portTFT = lo;
603405000053 0:bd6942344437 181 pinWR = IDLE;
603405000053 0:bd6942344437 182 }
603405000053 0:bd6942344437 183 }
603405000053 0:bd6942344437 184
603405000053 0:bd6942344437 185
603405000053 0:bd6942344437 186 pinCS = IDLE;
603405000053 0:bd6942344437 187 }
603405000053 0:bd6942344437 188
603405000053 0:bd6942344437 189 void drawLine(uint8_t orientation,uint16_t x1, uint16_t y1, uint16_t lenght, uint16_t fillcolor) {
603405000053 0:bd6942344437 190 uint8_t hi, lo;
603405000053 0:bd6942344437 191 uint16_t x2, y2;
603405000053 0:bd6942344437 192 uint16_t i, j;
603405000053 0:bd6942344437 193
603405000053 0:bd6942344437 194 if(orientation == VERT_LINE)
603405000053 0:bd6942344437 195 {
603405000053 0:bd6942344437 196 x2 = x1 - 1;
603405000053 0:bd6942344437 197 y2 = y1 + lenght - 1;
603405000053 0:bd6942344437 198 }
603405000053 0:bd6942344437 199 else if(orientation == HORI_LINE)
603405000053 0:bd6942344437 200 {
603405000053 0:bd6942344437 201 x2 = x1 + lenght - 1;
603405000053 0:bd6942344437 202 y2 = y1 - 1;
603405000053 0:bd6942344437 203 }
603405000053 0:bd6942344437 204 setAddrWindow(x1, y1, x2, y2);
603405000053 0:bd6942344437 205
603405000053 0:bd6942344437 206 hi = fillcolor >> 8;
603405000053 0:bd6942344437 207 lo = fillcolor;
603405000053 0:bd6942344437 208
603405000053 0:bd6942344437 209 pinCS = ACTIVE;
603405000053 0:bd6942344437 210
603405000053 0:bd6942344437 211 WriteCommand(SPFD5408_MEMORYWRITE);
603405000053 0:bd6942344437 212 pinCD = DATA;
603405000053 0:bd6942344437 213
603405000053 0:bd6942344437 214 for (i = lenght; i > 0; i--)
603405000053 0:bd6942344437 215 {
603405000053 0:bd6942344437 216 pinWR = ACTIVE;
603405000053 0:bd6942344437 217 portTFT = hi;
603405000053 0:bd6942344437 218 pinWR = IDLE;
603405000053 0:bd6942344437 219 pinWR = ACTIVE;
603405000053 0:bd6942344437 220 portTFT = lo;
603405000053 0:bd6942344437 221 pinWR = IDLE;
603405000053 0:bd6942344437 222
603405000053 0:bd6942344437 223 }
603405000053 0:bd6942344437 224
603405000053 0:bd6942344437 225
603405000053 0:bd6942344437 226 pinCS = IDLE;
603405000053 0:bd6942344437 227 }
603405000053 0:bd6942344437 228
603405000053 0:bd6942344437 229
603405000053 0:bd6942344437 230 void drawPixel(uint16_t x1, uint16_t y1, uint16_t fillcolor) {
603405000053 0:bd6942344437 231 uint8_t hi, lo;
603405000053 0:bd6942344437 232 uint16_t x2, y2;
603405000053 0:bd6942344437 233
603405000053 0:bd6942344437 234 x2 = x1 - 1;
603405000053 0:bd6942344437 235 y2 = y1 - 1;
603405000053 0:bd6942344437 236
603405000053 0:bd6942344437 237 setAddrWindow(x1, y1, x2, y2);
603405000053 0:bd6942344437 238
603405000053 0:bd6942344437 239 hi = fillcolor >> 8;
603405000053 0:bd6942344437 240 lo = fillcolor;
603405000053 0:bd6942344437 241
603405000053 0:bd6942344437 242 pinCS = ACTIVE;
603405000053 0:bd6942344437 243
603405000053 0:bd6942344437 244 WriteCommand(SPFD5408_MEMORYWRITE);
603405000053 0:bd6942344437 245 pinCD = DATA;
603405000053 0:bd6942344437 246
603405000053 0:bd6942344437 247 // for (i = 1; i > 0; i--)
603405000053 0:bd6942344437 248 // {
603405000053 0:bd6942344437 249 pinWR = ACTIVE;
603405000053 0:bd6942344437 250 portTFT = hi;
603405000053 0:bd6942344437 251 pinWR = IDLE;
603405000053 0:bd6942344437 252 pinWR = ACTIVE;
603405000053 0:bd6942344437 253 portTFT = lo;
603405000053 0:bd6942344437 254 pinWR = IDLE;
603405000053 0:bd6942344437 255 //
603405000053 0:bd6942344437 256 // }
603405000053 0:bd6942344437 257 //
603405000053 0:bd6942344437 258
603405000053 0:bd6942344437 259 pinCS = IDLE;
603405000053 0:bd6942344437 260 }
603405000053 0:bd6942344437 261 void draw_text_korn(uint64_t rttd,int x_k=100,int y_k=100)
603405000053 0:bd6942344437 262 {
603405000053 0:bd6942344437 263 for(int i=0;i<8;i++)
603405000053 0:bd6942344437 264 {for(int j=0;j<8;j++)
603405000053 0:bd6942344437 265 {
603405000053 0:bd6942344437 266 if( ( (rttd>>(i*8+j)) &0x01)==1){drawPixel(i*3+x_k,-1*2*j+y_k,GREEN);}
603405000053 0:bd6942344437 267 }
603405000053 0:bd6942344437 268 }
xkzy 1:8daae36234f1 269 }
603405000053 0:bd6942344437 270 void korn_text(char ttd,int y_k,int x_k)//important note x is y, y is x
603405000053 0:bd6942344437 271 {
603405000053 0:bd6942344437 272 const uint64_t IMAGES[] = {
603405000053 0:bd6942344437 273 0x6666667e66663c00,
603405000053 0:bd6942344437 274 0x3e66663e66663e00,
603405000053 0:bd6942344437 275 0x3c66060606663c00,
603405000053 0:bd6942344437 276 0x3e66666666663e00,
603405000053 0:bd6942344437 277 0x7e06063e06067e00,
603405000053 0:bd6942344437 278 0x0606063e06067e00,
603405000053 0:bd6942344437 279 0x3c66760606663c00,
603405000053 0:bd6942344437 280 0x6666667e66666600,
603405000053 0:bd6942344437 281 0x3c18181818183c00,
603405000053 0:bd6942344437 282 0x1c36363030307800,
603405000053 0:bd6942344437 283 0x66361e0e1e366600,
603405000053 0:bd6942344437 284 0x7e06060606060600,
603405000053 0:bd6942344437 285 0xc6c6c6d6feeec600,
603405000053 0:bd6942344437 286 0xc6c6e6f6decec600,
603405000053 0:bd6942344437 287 0x3c66666666663c00,
603405000053 0:bd6942344437 288 0x06063e6666663e00,
603405000053 0:bd6942344437 289 0x603c766666663c00,
603405000053 0:bd6942344437 290 0x66361e3e66663e00,
603405000053 0:bd6942344437 291 0x3c66603c06663c00,
603405000053 0:bd6942344437 292 0x18181818185a7e00,
603405000053 0:bd6942344437 293 0x7c66666666666600,
603405000053 0:bd6942344437 294 0x183c666666666600,
603405000053 0:bd6942344437 295 0xc6eefed6c6c6c600,
603405000053 0:bd6942344437 296 0xc6c66c386cc6c600,
603405000053 0:bd6942344437 297 0x1818183c66666600,
603405000053 0:bd6942344437 298 0x7e060c1830607e00,
603405000053 0:bd6942344437 299 0x0000000000000000,
603405000053 0:bd6942344437 300 0x7c667c603c000000,
603405000053 0:bd6942344437 301 0x3e66663e06060600,
603405000053 0:bd6942344437 302 0x3c6606663c000000,
603405000053 0:bd6942344437 303 0x7c66667c60606000,
603405000053 0:bd6942344437 304 0x3c067e663c000000,
603405000053 0:bd6942344437 305 0x0c0c3e0c0c6c3800,
603405000053 0:bd6942344437 306 0x3c607c66667c0000,
603405000053 0:bd6942344437 307 0x6666663e06060600,
603405000053 0:bd6942344437 308 0x3c18181800180000,
603405000053 0:bd6942344437 309 0x1c36363030003000,
603405000053 0:bd6942344437 310 0x66361e3666060600,
603405000053 0:bd6942344437 311 0x1818181818181800,
603405000053 0:bd6942344437 312 0xd6d6feeec6000000,
603405000053 0:bd6942344437 313 0x6666667e3e000000,
603405000053 0:bd6942344437 314 0x3c6666663c000000,
603405000053 0:bd6942344437 315 0x06063e66663e0000,
603405000053 0:bd6942344437 316 0xf0b03c36363c0000,
603405000053 0:bd6942344437 317 0x060666663e000000,
603405000053 0:bd6942344437 318 0x3e403c027c000000,
603405000053 0:bd6942344437 319 0x1818187e18180000,
603405000053 0:bd6942344437 320 0x7c66666666000000,
603405000053 0:bd6942344437 321 0x183c666600000000,
603405000053 0:bd6942344437 322 0x7cd6d6d6c6000000,
603405000053 0:bd6942344437 323 0x663c183c66000000,
603405000053 0:bd6942344437 324 0x3c607c6666000000,
603405000053 0:bd6942344437 325 0x3c0c18303c000000,
603405000053 0:bd6942344437 326
603405000053 0:bd6942344437 327 0x0000000000000000,0x7c667c603c000000,0x3e66663e06060600,0x3c6606663c000000,0x3c607c66667c0000,
603405000053 0:bd6942344437 328 0x7c66667c60606000,0x3c067e663c000000,0x0c0c3e0c0c6c3800,0x6666663e06060600,0x3c18181800180000,
603405000053 0:bd6942344437 329 0x1c36363030003000,0x66361e3666060600,0x1818181818181800,0xd6d6feeec6000000,0x6666667e3e000000,
603405000053 0:bd6942344437 330 0x3c6666663c000000,0x06063e66663e0000,0xf0b03c36363c0000,0x060666663e000000,0x3e403c027c000000,
603405000053 0:bd6942344437 331 0x1818187e18180000,0x7c66666666000000,0x183c666600000000,0x7cd6d6d6c6000000,0x663c183c66000000,
603405000053 0:bd6942344437 332 0x3c607c6666000000,0x3c0c18303c000000
603405000053 0:bd6942344437 333 };
603405000053 0:bd6942344437 334 /*switch(ttd)
603405000053 0:bd6942344437 335 {
603405000053 0:bd6942344437 336 case 'F':
603405000053 0:bd6942344437 337 draw_text_korn(0x0606063e06067e00);
603405000053 0:bd6942344437 338 break;
603405000053 0:bd6942344437 339 }*/
603405000053 0:bd6942344437 340 draw_text_korn(IMAGES[ttd-'A'],x_k,480-y_k);
603405000053 0:bd6942344437 341 }
603405000053 0:bd6942344437 342 void korn_text_string(char st[15])
603405000053 0:bd6942344437 343 {int x_s=100,y_s=100;
xkzy 1:8daae36234f1 344 for(int sz=0;sz<15;st++)
603405000053 0:bd6942344437 345 {
603405000053 0:bd6942344437 346 korn_text(st[sz],x_s,y_s);
603405000053 0:bd6942344437 347 x_s+=16;
603405000053 0:bd6942344437 348 }
603405000053 0:bd6942344437 349 }
xkzy 1:8daae36234f1 350
xkzy 1:8daae36234f1 351 /*cam part*/
xkzy 1:8daae36234f1 352 bool cap=1;
xkzy 1:8daae36234f1 353 uint8_t image[76800];
xkzy 1:8daae36234f1 354 uint32_t pix_count;
xkzy 1:8daae36234f1 355 bool read=1;
xkzy 1:8daae36234f1 356 void read_to_image(){
xkzy 1:8daae36234f1 357 pix_count = 0;
xkzy 1:8daae36234f1 358 read=1;
xkzy 1:8daae36234f1 359 while(pix_count<76800&&read){
xkzy 1:8daae36234f1 360 read_state=!read_state;
xkzy 1:8daae36234f1 361 if(cam.readable()) {
xkzy 1:8daae36234f1 362 image[pix_count++]=cam.getc();
xkzy 1:8daae36234f1 363 }
xkzy 1:8daae36234f1 364 }
xkzy 1:8daae36234f1 365 read_state=0;
xkzy 1:8daae36234f1 366 }
xkzy 1:8daae36234f1 367
xkzy 1:8daae36234f1 368 void set_cap(){cap = 1;}
xkzy 1:8daae36234f1 369 void end_read(){read = 0;}
xkzy 1:8daae36234f1 370 long map(long x, long in_min, long in_max, long out_min, long out_max)
xkzy 1:8daae36234f1 371 {
xkzy 1:8daae36234f1 372 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
xkzy 1:8daae36234f1 373 }
xkzy 1:8daae36234f1 374 uint16_t P2RGB(uint8_t val){
xkzy 1:8daae36234f1 375 uint8_t bits_5=val/8;
xkzy 1:8daae36234f1 376 uint8_t bits_6=val/4;
xkzy 1:8daae36234f1 377 uint16_t rgb= bits_5<<11|bits_6<<5|bits_5;
xkzy 1:8daae36234f1 378 return rgb;
xkzy 1:8daae36234f1 379 }
xkzy 1:8daae36234f1 380
603405000053 0:bd6942344437 381 int main()
603405000053 0:bd6942344437 382 {
603405000053 0:bd6942344437 383
xkzy 1:8daae36234f1 384 pc.baud(1000000);
xkzy 1:8daae36234f1 385 cam.baud(1000000);
xkzy 1:8daae36234f1 386 esp.baud(1000000);
xkzy 1:8daae36234f1 387 frame_start.fall(&read_to_image);
xkzy 1:8daae36234f1 388 frame_start.rise(&end_read);
xkzy 1:8daae36234f1 389 ccap.fall(&set_cap);
603405000053 0:bd6942344437 390 begin();
603405000053 0:bd6942344437 391 //drawLine(VERT_LINE,0, 20, 60,GREEN );
603405000053 0:bd6942344437 392 //drawLine(HORI_LINE,30, 10, 20, RED);
603405000053 0:bd6942344437 393 drawPixel(100,100,RED);
603405000053 0:bd6942344437 394 drawPixel(200,200,'H');
xkzy 1:8daae36234f1 395 fillRect(20, 100, 15,15, 0); //ซ้ายบน
603405000053 0:bd6942344437 396 fillRect(30, 110, 15,15, RED);
603405000053 0:bd6942344437 397 fillRect(40, 120, 15,15, RED);
603405000053 0:bd6942344437 398 fillRect(50, 130, 15,15, RED);
603405000053 0:bd6942344437 399 fillRect(60, 140, 15,15, RED);
603405000053 0:bd6942344437 400
603405000053 0:bd6942344437 401 fillRect(20, 90, 15,15, RED);//ขวาบน
603405000053 0:bd6942344437 402 fillRect(30, 80, 15,15, RED);
603405000053 0:bd6942344437 403 fillRect(40, 70, 15,15, RED);
603405000053 0:bd6942344437 404 fillRect(50, 60, 15,15, RED);
603405000053 0:bd6942344437 405 fillRect(60, 50, 15,15, RED);
603405000053 0:bd6942344437 406
603405000053 0:bd6942344437 407 fillRect(70, 140, 15,15, RED); //ซ้ายล่าง
603405000053 0:bd6942344437 408 fillRect(80, 130, 15,15, RED);
603405000053 0:bd6942344437 409 fillRect(90, 120, 15,15, RED);
603405000053 0:bd6942344437 410 fillRect(100, 110, 15,15, RED);
603405000053 0:bd6942344437 411 fillRect(110, 100, 15,15, RED);
603405000053 0:bd6942344437 412
603405000053 0:bd6942344437 413 fillRect(70, 50, 15,15, RED); //ขวาล่าง
603405000053 0:bd6942344437 414 fillRect(80, 60, 15,15, RED);
603405000053 0:bd6942344437 415 fillRect(90, 70, 15,15, RED);
603405000053 0:bd6942344437 416 fillRect(100, 80, 15,15, RED);
603405000053 0:bd6942344437 417 fillRect(110, 90, 15,15, RED);
603405000053 0:bd6942344437 418 while(1)
603405000053 0:bd6942344437 419 {
xkzy 1:8daae36234f1 420 //setRotation(3);
xkzy 1:8daae36234f1 421 korn_text_string("SFRDHTRTSYSTEM");
xkzy 1:8daae36234f1 422 korn_text_string("SFDSFDGSTEM");
xkzy 1:8daae36234f1 423 int yh=0;
xkzy 1:8daae36234f1 424 for(int y=0;y<240;y++){
xkzy 1:8daae36234f1 425 for (int x=0;x<480;x++){
xkzy 1:8daae36234f1 426 drawPixel(320-yh,480-x,P2RGB(image[(int)((x+y*480)/1.5)]));
xkzy 1:8daae36234f1 427 }
xkzy 1:8daae36234f1 428 if(y%3==0){
xkzy 1:8daae36234f1 429 yh++;
xkzy 1:8daae36234f1 430 for (int x=0;x<480;x++){
xkzy 1:8daae36234f1 431 drawPixel(320-yh,480-x,P2RGB(image[(int)((x+y*480)/1.5)]));
xkzy 1:8daae36234f1 432
xkzy 1:8daae36234f1 433 }
xkzy 1:8daae36234f1 434 }
xkzy 1:8daae36234f1 435 yh++;
xkzy 1:8daae36234f1 436 }
xkzy 1:8daae36234f1 437 //korn_text_string("SF-SYSTEM");
xkzy 1:8daae36234f1 438
603405000053 0:bd6942344437 439 }
603405000053 0:bd6942344437 440 }