tft

Dependencies:   mbed Adafruit_GFX

Revision:
1:8daae36234f1
Parent:
0:bd6942344437
--- a/main.cpp	Sat Dec 15 19:44:33 2018 +0000
+++ b/main.cpp	Sun Dec 16 07:08:30 2018 +0000
@@ -56,7 +56,7 @@
 
 #define VERT_LINE 0
 #define HORI_LINE 1
-
+/** setup tft **/
 DigitalOut pinRD(A0);   //PA_0;
 DigitalOut pinWR(A1);   //PA_1;
 DigitalOut pinCD(A2);   //PA_4;
@@ -64,6 +64,14 @@
 DigitalOut pinReset(A4);//PC_1;
 
 BusInOut portTFT(D8, D9, D2, D3, D4, D5, D6, D7);
+/**set up cam*/
+RawSerial pc(SERIAL_TX, SERIAL_RX); //has to use rawserial ,serial too slow and has byte loss.
+RawSerial cam(PA_11, PA_12);
+RawSerial esp(PB_6, PA_10);
+DigitalOut read_state(LED1);
+InterruptIn frame_start(PC_5);
+InterruptIn ccap(USER_BUTTON);
+
 
 void WriteCommand(uint8_t c)
 {
@@ -81,7 +89,7 @@
     pinWR = IDLE;
 }
 
-Serial pc(SERIAL_TX, SERIAL_RX);
+//Serial pc(SERIAL_TX, SERIAL_RX);
 
 DigitalOut myled(LED1);
 
@@ -258,7 +266,7 @@
         if( ( (rttd>>(i*8+j)) &0x01)==1){drawPixel(i*3+x_k,-1*2*j+y_k,GREEN);}
         }
     }
-    }
+}
 void korn_text(char ttd,int y_k,int x_k)//important note x is y, y is x
 {
     const uint64_t IMAGES[] = {
@@ -333,22 +341,58 @@
     }
 void korn_text_string(char st[15])
 {int x_s=100,y_s=100;
-    for(int sz=0;sz<sizeof(st);st++)
+    for(int sz=0;sz<15;st++)
     {
         korn_text(st[sz],x_s,y_s);
         x_s+=16;
         }
     }
+    
+/*cam part*/
+bool cap=1;
+uint8_t image[76800];
+uint32_t pix_count;
+bool read=1;
+void read_to_image(){
+    pix_count = 0;
+    read=1;
+    while(pix_count<76800&&read){
+        read_state=!read_state;
+        if(cam.readable()) {
+            image[pix_count++]=cam.getc();
+        }
+    }
+    read_state=0;
+}
+
+void set_cap(){cap = 1;}
+void end_read(){read = 0;}
+long map(long x, long in_min, long in_max, long out_min, long out_max)
+{
+  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
+}
+uint16_t P2RGB(uint8_t val){
+    uint8_t bits_5=val/8;
+    uint8_t bits_6=val/4;
+    uint16_t rgb= bits_5<<11|bits_6<<5|bits_5;
+    return rgb;
+}
+
 int main()
 {
     
-    
+    pc.baud(1000000);
+    cam.baud(1000000);
+    esp.baud(1000000);
+    frame_start.fall(&read_to_image); 
+    frame_start.rise(&end_read); 
+    ccap.fall(&set_cap); 
     begin();
     //drawLine(VERT_LINE,0, 20, 60,GREEN );
     //drawLine(HORI_LINE,30, 10, 20, RED);
     drawPixel(100,100,RED);
     drawPixel(200,200,'H');
-    fillRect(20, 100, 15,15, RED); //ซ้ายบน
+    fillRect(20, 100, 15,15, 0); //ซ้ายบน
     fillRect(30, 110, 15,15, RED);
     fillRect(40, 120, 15,15, RED);
     fillRect(50, 130, 15,15, RED);
@@ -373,6 +417,24 @@
     fillRect(110, 90, 15,15, RED);
     while(1)
     {
-    korn_text_string("SF-SYSTEM");
+     //setRotation(3);
+     korn_text_string("SFRDHTRTSYSTEM");
+     korn_text_string("SFDSFDGSTEM");
+     int yh=0;
+     for(int y=0;y<240;y++){
+         for (int x=0;x<480;x++){
+             drawPixel(320-yh,480-x,P2RGB(image[(int)((x+y*480)/1.5)]));
+        }
+        if(y%3==0){
+            yh++;
+            for (int x=0;x<480;x++){
+             drawPixel(320-yh,480-x,P2RGB(image[(int)((x+y*480)/1.5)]));
+             
+        }
+        }
+        yh++;
+    }
+    //korn_text_string("SF-SYSTEM");
+    
     }
 }