SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Revision:
41:7b21c5e3599e
Parent:
40:be98219930e4
Child:
42:c4e1606087ff
--- a/Hardwares/ArduUTFT.cpp	Wed Mar 22 23:43:24 2017 +0000
+++ b/Hardwares/ArduUTFT.cpp	Thu Mar 23 23:17:51 2017 +0000
@@ -24,9 +24,10 @@
     uint8_t front_color_high = 0;
     uint8_t front_color_low = 0;
     
-    DigitalOut utft_cs(PIN_AUC_CS);
 }
 
+DigitalOut utft_cs(PIN_AUC_CS, 1);
+
 inline void ardu_cam_spi_write_8(int address, int value)
 {
     utft_cs = 0;
@@ -44,7 +45,7 @@
     return value;
 }
 
-inline void ardu_utft_write_COM(uint8_t VL)  
+inline void ardu_utft_write_COM_internal(uint8_t VL)  
 {   
     utft_cs = 0;
     g_spi_port.write(0xBE);
@@ -52,20 +53,27 @@
     utft_cs = 1;
 }
  
-inline void ardu_utft_write_DATA(uint8_t VH, uint8_t VL)
+inline void ardu_utft_write_DATA_internal(uint8_t VH, uint8_t VL)
 {
     utft_cs = 0;
     g_spi_port.write(0xBF);
     g_spi_port.write(VH);
+    utft_cs = 1;
+    utft_cs = 0;
     g_spi_port.write(0xBF);
     g_spi_port.write(VL);
     utft_cs = 1;
 }
 
-inline void ardu_utft_write_COM_DATA(uint8_t com1, uint16_t dat1)
+inline void ardu_utft_write_COM_DATA_internal(uint8_t com1, uint16_t dat1)
 {
-     ardu_utft_write_COM(com1);
-     ardu_utft_write_DATA(dat1 >> 8, dat1);
+     ardu_utft_write_COM_internal(com1);
+     ardu_utft_write_DATA_internal((dat1 >> 8) & 0xFF, dat1);
+}
+
+void ardu_utft_write_DATA(uint8_t VH, uint8_t VL)
+{
+    ardu_utft_write_DATA_internal(VH, VL);
 }
 
 void ardu_utft_init()
@@ -90,57 +98,58 @@
     }
     
     ardu_cam_set_mode(MCU2LCD_MODE);
-    utft_cs = 1;
-    ardu_utft_write_COM_DATA(0x00,0x0001);
-    ardu_utft_write_COM_DATA(0x03,0xA8A4);
-    ardu_utft_write_COM_DATA(0x0C,0x0000);
-    ardu_utft_write_COM_DATA(0x0D,0x080C);
-    ardu_utft_write_COM_DATA(0x0E,0x2B00);
-    ardu_utft_write_COM_DATA(0x1E,0x00B7);
-    ardu_utft_write_COM_DATA(0x01,0x693F);
-    ardu_utft_write_COM_DATA(0x02,0x0600);
-    ardu_utft_write_COM_DATA(0x10,0x0000);
-    ardu_utft_write_COM_DATA(0x11,0x6078);
-    ardu_utft_write_COM_DATA(0x05,0x0000);
-    ardu_utft_write_COM_DATA(0x06,0x0000);
-    ardu_utft_write_COM_DATA(0x16,0xEF1C);
-    ardu_utft_write_COM_DATA(0x17,0x0003);
-    ardu_utft_write_COM_DATA(0x07,0x0233);
-    ardu_utft_write_COM_DATA(0x0B,0x0000);
-    ardu_utft_write_COM_DATA(0x0F,0x0000);
-    ardu_utft_write_COM_DATA(0x41,0x0000);
-    ardu_utft_write_COM_DATA(0x42,0x0000);
-    ardu_utft_write_COM_DATA(0x48,0x0000);
-    ardu_utft_write_COM_DATA(0x49,0x013F);
-    ardu_utft_write_COM_DATA(0x4A,0x0000);
-    ardu_utft_write_COM_DATA(0x4B,0x0000);
-    ardu_utft_write_COM_DATA(0x44,0xEF00);
-    ardu_utft_write_COM_DATA(0x45,0x0000);
-    ardu_utft_write_COM_DATA(0x46,0x013F);
-    ardu_utft_write_COM_DATA(0x30,0x0707);
-    ardu_utft_write_COM_DATA(0x31,0x0204);
-    ardu_utft_write_COM_DATA(0x32,0x0204);
-    ardu_utft_write_COM_DATA(0x33,0x0502);
-    ardu_utft_write_COM_DATA(0x34,0x0507);
-    ardu_utft_write_COM_DATA(0x35,0x0204);
-    ardu_utft_write_COM_DATA(0x36,0x0204);
-    ardu_utft_write_COM_DATA(0x37,0x0502);
-    ardu_utft_write_COM_DATA(0x3A,0x0302);
-    ardu_utft_write_COM_DATA(0x3B,0x0302);
-    ardu_utft_write_COM_DATA(0x23,0x0000);
-    ardu_utft_write_COM_DATA(0x24,0x0000);
-    ardu_utft_write_COM_DATA(0x25,0x8000);
-    ardu_utft_write_COM_DATA(0x4f,0x0000);
-    ardu_utft_write_COM_DATA(0x4e,0x0000);
-    ardu_utft_write_COM(0x22);
- 
+    ardu_utft_write_COM_DATA_internal(0x00,0x0001);
+    ardu_utft_write_COM_DATA_internal(0x03,0xA8A4);
+    ardu_utft_write_COM_DATA_internal(0x0C,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x0D,0x080C);
+    ardu_utft_write_COM_DATA_internal(0x0E,0x2B00);
+    ardu_utft_write_COM_DATA_internal(0x1E,0x00B7);
+    ardu_utft_write_COM_DATA_internal(0x01,0x6B3F); //693F
+    ardu_utft_write_COM_DATA_internal(0x02,0x0600);
+    ardu_utft_write_COM_DATA_internal(0x10,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x11,0x6078);
+    ardu_utft_write_COM_DATA_internal(0x05,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x06,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x16,0xEF1C);
+    ardu_utft_write_COM_DATA_internal(0x17,0x0003);
+    ardu_utft_write_COM_DATA_internal(0x07,0x0233);
+    ardu_utft_write_COM_DATA_internal(0x0B,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x0F,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x41,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x42,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x48,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x49,0x013F);
+    ardu_utft_write_COM_DATA_internal(0x4A,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x4B,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x44,0xEF00);
+    ardu_utft_write_COM_DATA_internal(0x45,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x46,0x013F);
+    ardu_utft_write_COM_DATA_internal(0x30,0x0707);
+    ardu_utft_write_COM_DATA_internal(0x31,0x0204);
+    ardu_utft_write_COM_DATA_internal(0x32,0x0204);
+    ardu_utft_write_COM_DATA_internal(0x33,0x0502);
+    ardu_utft_write_COM_DATA_internal(0x34,0x0507);
+    ardu_utft_write_COM_DATA_internal(0x35,0x0204);
+    ardu_utft_write_COM_DATA_internal(0x36,0x0204);
+    ardu_utft_write_COM_DATA_internal(0x37,0x0502);
+    ardu_utft_write_COM_DATA_internal(0x3A,0x0302);
+    ardu_utft_write_COM_DATA_internal(0x3B,0x0302);
+    ardu_utft_write_COM_DATA_internal(0x23,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x24,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x25,0x8000);
+    ardu_utft_write_COM_DATA_internal(0x4f,0x0000);
+    ardu_utft_write_COM_DATA_internal(0x4e,0x0000);
+    ardu_utft_write_COM_internal(0x22);
+    
+    //ardu_cam_spi_write_8(0x03, 0x04); ////////////////
+    
     //setColor(255, 255, 255);
     //setBackColor(0, 0, 0);
     current_font = NULL;
     ardu_utft_clr_scr();
     
-    ardu_utft_set_color(20, 0, 20);
-    ardu_utft_draw_rect(150, 150, 20, 20);
+    ardu_utft_set_color(255, 0, 255);
+    //ardu_utft_draw_rect(150, 150, 20, 20);
     
 }
 
@@ -148,7 +157,8 @@
 {
     /////////////////////////////////
     //Careful here!!
-    ardu_cam_spi_write_8(ARDUCHIP_MODE, 0x04);
+    ardu_cam_spi_write_8(0x02, 0x00);
+    
 }
 
 void ardu_utft_clr_scr()
@@ -158,17 +168,7 @@
     long i;
     for (i = 0; i < ((UTFT_DISP_X_SIZE + 1) * (UTFT_DISP_Y_SIZE + 1)); ++i)
     {
-        //////////////////////////
-        //Can be simplified later!!
-        if (UTFT_DISP_TRANS_MODE != 1)
-        {
-            ardu_utft_write_DATA(0x00,0x00);
-        }
-        else
-        {
-            ardu_utft_write_DATA(1,0);
-            ardu_utft_write_DATA(1,0);
-        }
+        ardu_utft_write_DATA_internal(0x00,0x00);
     }
 }
 
@@ -188,12 +188,12 @@
     swap(uint16_t, y1, y2);
     /////////////////////////////
     
-    ardu_utft_write_COM_DATA(0x44, (x2 << 8) + x1);
-    ardu_utft_write_COM_DATA(0x45, y1);
-    ardu_utft_write_COM_DATA(0x46, y2);
-    ardu_utft_write_COM_DATA(0x4e, x1);
-    ardu_utft_write_COM_DATA(0x4f, y1);
-    ardu_utft_write_COM(0x22);
+    ardu_utft_write_COM_DATA_internal(0x44, (x2 << 8) + x1);
+    ardu_utft_write_COM_DATA_internal(0x45, y1);
+    ardu_utft_write_COM_DATA_internal(0x46, y2);
+    ardu_utft_write_COM_DATA_internal(0x4e, x1);
+    ardu_utft_write_COM_DATA_internal(0x4f, y1);
+    ardu_utft_write_COM_internal(0x22);
 }
  
 void ardu_utft_set_color(uint8_t r, uint8_t g, uint8_t b)
@@ -231,7 +231,7 @@
     
     for (int i = 0; i < l + 1; ++i)
     {
-        ardu_utft_write_DATA(front_color_high, front_color_low);
+        ardu_utft_write_DATA_internal(front_color_high, front_color_low);
     }
     
     ardu_utft_reset_xy();
@@ -249,7 +249,7 @@
     
     for (int i = 0; i < l + 1; ++i)
     {
-        ardu_utft_write_DATA(front_color_high, front_color_low);
+        ardu_utft_write_DATA_internal(front_color_high, front_color_low);
     }
     
     ardu_utft_reset_xy();