UniGraphic library test using MPS2+

Dependencies:   MMA8451Q SPI_STMPE610 UniGraphic mbed

Fork of testUniGraphic_150217 by GraphicsDisplay

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Tue Feb 17 13:22:06 2015 +0000
Child:
1:6cd56ddffb40
Commit message:
first commit

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
SPI_STMPE610.lib Show annotated file Show diff for this revision Revisions of this file
UniGraphic.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SPI_STMPE610.lib	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Rhyme/code/SPI_STMPE610/#988661c63061
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UniGraphic.lib	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/GraphicsDisplay/code/UniGraphic/#bb0383b91104
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,270 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#include <ILI9341.h>
+#include "Arial12x12.h"
+#include "Arial24x23.h"
+#include "Arial28x28.h"
+#include "Arial43x48_numb.h"
+#include "SPI_STMPE610.h"
+#include "main.h"
+
+DigitalOut myled(LED1);
+ILI9341 TFT(SPI_8, 10000000, 
+    PIN_MOSI, PIN_MISO,  PIN_SCLK, 
+    PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
+    
+SPI_STMPE610 TSC(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
+
+DigitalOut backlight(PIN_BL_TFT) ;
+
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+MMA8451Q *acc = 0 ;
+
+int page = 0 ;
+int numPage = 3 ;
+
+void initTFT(void)
+{
+    //Configure the display driver    
+    TFT.background(Black);
+    TFT.foreground(White);
+    wait(0.01) ;
+    TFT.cls();
+}
+
+void screen1(void) // Welcome Screen
+{
+    backlight = 0 ;
+    TFT.background(White) ;
+    TFT.cls() ;
+
+    wait(0.1) ;
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.foreground(Red) ;
+    TFT.locate(80, 40) ;
+    TFT.printf("MBED") ;
+    TFT.foreground(Blue);
+    TFT.locate(60, 80) ;
+    TFT.printf("2.8\"TFT") ; 
+    TFT.locate(40, 120) ;
+    TFT.printf("with touch") ;
+    TFT.foreground(Black);
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.foreground(Blue) ;
+    TFT.locate(10, 180) ;
+    TFT.printf("This program is running on") ;
+    TFT.locate(10, 200) ;
+    TFT.printf("freescale FRDM-KL25Z with") ;
+    TFT.locate(10, 220) ;
+    TFT.printf("a program developed on mbed") ;
+    TFT.foreground(Green) ;
+    TFT.locate(10, 260) ;
+    TFT.printf("To advance demo page, touch") ;
+    TFT.locate(10, 280) ;
+    TFT.printf("and hold right side of screen") ;
+    TFT.locate(10, 300) ;
+    TFT.printf("until the next screen starts") ;
+    backlight = 1 ;
+}
+
+void screen2(void) // Graphics
+{
+    //Draw some graphics
+    int i, x[2], y[2] ;
+    backlight = 0 ;
+
+    TFT.background(Black);
+    TFT.foreground(White);
+    TFT.cls() ;
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(90,0);
+    TFT.printf("Graphics");
+    
+    x[0] = 25 ; x[1] = 224 ;
+    y[0] = 20 ; y[1] = 219 ;
+    for (i = 20 ; i < 220 ; i += 10) {
+        TFT.line(i+5, y[0], i+5, y[1], Blue) ;
+        TFT.line(x[0], i, x[1], i, Blue) ;
+    }
+    TFT.line(125, y[0], 125, y[1], Green) ;
+    TFT.line(x[0], 120, x[1], 120, Green) ;
+    TFT.rect(x[0],y[0], x[1], y[1], Green) ;
+    TFT.locate(10, 20) ;
+    TFT.printf("V") ;
+    TFT.locate(0, 115) ;
+    TFT.printf("0.0") ;
+    TFT.locate(115, 225) ;
+    TFT.printf("0.0") ;
+    TFT.locate(215, 225) ;
+    TFT.printf("T") ;
+
+    double s;
+    for (int i = x[0]; i < 225; i++) {
+        s = 40 * sin((long double)i / 20);
+        TFT.pixel(i, 120 + (int)s, White);
+    }
+    
+    TFT.fillrect(10, 240, 229, 309, White) ;
+    TFT.rect(10, 240, 229, 309, Red) ;
+    TFT.rect(11, 241, 228, 308, Red) ;
+    
+    TFT.background(White) ;
+    TFT.foreground(Black) ;
+    TFT.locate(20, 250) ;
+    TFT.printf("With QVGA resolution") ;
+    TFT.locate(20, 270) ;
+    TFT.printf("simple graphics drawing") ;
+    TFT.locate(20, 290) ;
+    TFT.printf("capability is provided") ;
+    backlight = 1 ;
+}    
+
+double clip(double src)
+{
+    double value ;
+    value = src ;
+    if (value < 0.0) {
+        value = 0.0 ;
+    } else if (value > 2.0) {
+        value = 2.0 ;
+    }
+    return( value ) ;
+}
+
+void screen3(void)
+{
+    int t = 0 ;
+    int pt = 0 ; // previous t 
+    int i, x, y ;
+    unsigned int data[3] ; // for x, y, z 
+    unsigned int prev[3] ;
+    unsigned short signalHeight = 39 ;
+    unsigned short xoffset = 30 ;
+    unsigned short yoffset = 120 ;
+    unsigned short zoffset = 210 ;
+    unsigned short paneX[2] = {20, 235} ;
+    unsigned short paneH = 81 ;
+ 
+    backlight = 0 ;
+    TFT.background(Black) ;
+    TFT.foreground(White) ;
+//    TFT.cls() ;
+
+ 
+    TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
+    TFT.fillrect(paneX[0], yoffset, paneX[1], yoffset+paneH, Black) ;
+    TFT.fillrect(paneX[0], zoffset, paneX[1], zoffset+paneH, Black) ;
+    TFT.fillrect(paneX[0], xoffset, paneX[1], xoffset+paneH, Black) ;
+    for (i = 0 ; i < 10 ; i++ ) {
+        y = i * 8 ;
+        TFT.line(paneX[0], xoffset + y, paneX[1], xoffset + y, Blue) ;
+        TFT.line(paneX[0], yoffset + y, paneX[1], yoffset + y, Blue) ;
+        TFT.line(paneX[0], zoffset + y, paneX[1], zoffset + y, Blue) ;
+    }
+    for (x = 30 ; x < paneX[1] ; x += 10 ) {
+        TFT.line(x, xoffset, x, xoffset+paneH, Blue) ;
+        TFT.line(x, yoffset, x, yoffset+paneH, Blue) ;
+        TFT.line(x, zoffset, x, zoffset+paneH, Blue) ;
+    } 
+    TFT.rect(paneX[0], xoffset, paneX[1], xoffset+paneH, White) ;
+    TFT.rect(paneX[0], yoffset, paneX[1], yoffset+paneH, White) ;
+    TFT.rect(paneX[0], zoffset, paneX[1], zoffset+paneH, White) ;
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(5, xoffset+30) ;
+    TFT.printf("X") ;
+    TFT.locate(5, yoffset+30) ;
+    TFT.printf("Y") ;
+    TFT.locate(5, zoffset+30) ;
+    TFT.printf("Z") ;
+    TFT.locate(50, 10) ;
+    TFT.printf("Xtrinsic Accelerometer") ;
+    TFT.locate(90, 300) ;
+    TFT.printf("MMA8451Q") ;
+    
+    prev[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
+    prev[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
+    prev[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
+    pt = paneX[0] ;
+    backlight = 1 ;
+    for(t = 21 ; t < paneX[1] ; t++) {
+        data[0] = xoffset + (signalHeight * clip((1.0 + acc->getAccX()))) ;
+        data[1] = yoffset + (signalHeight * clip((1.0 + acc->getAccY()))) ;
+        data[2] = zoffset + (signalHeight * clip((1.0 + acc->getAccZ()))) ;
+        TFT.line(pt, prev[0], t, data[0], Red) ;
+        TFT.line(pt, prev[1], t, data[1], Green) ;
+        TFT.line(pt, prev[2], t, data[2], Yellow) ;
+        prev[0] = data[0] ;
+        prev[1] = data[1] ;
+        prev[2] = data[2] ;
+        pt = t ;
+        wait(0.01) ;
+    }
+}
+
+void incPage(void)
+{
+    page++ ;
+    if (page >= numPage) {
+        page = 0 ;
+    }
+}
+
+void decPage(void) 
+{
+    page-- ;
+    if (page < 0) {
+        page = numPage - 1 ;
+    }
+}
+
+int main() {
+    uint16_t x, y, z ;
+    int prevPage = 0 ;
+    
+    acc = new MMA8451Q(PTE25, PTE24, MMA8451_I2C_ADDRESS) ;
+    
+    initTFT() ;
+    
+    screen1() ;
+        
+    printf("Program Started!\n\r") ;
+    
+    for(;;) {
+//        printf("TFT width = %d, height = %d\n\r", TFT.width(), TFT.height()) ;
+        switch(page) {
+        case 0:
+            if (prevPage != page) {
+                screen1() ;
+            }
+            break ;
+        case 1:
+            if (prevPage != page) {
+                screen2() ; 
+            }
+            break ;
+        case 2:
+            if (prevPage != page) {
+                TFT.background(Black) ;
+                TFT.foreground(White) ;
+                TFT.cls() ;
+            }
+            screen3() ; 
+            wait(2) ;
+            break ;
+        default:
+            page = 0 ; 
+            break ;
+        }
+        prevPage = page ;
+ 
+        TSC.getRAWPoint(&x, &y, &z) ;
+        if ((x != 0)||(y != 0) || (z != 0)) {
+            if (x < 1000) { // left
+                decPage() ;
+            } else if (x > 3000) { // right
+                incPage() ;
+            }
+        }
+//        wait(1) ;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,32 @@
+#ifndef _MAIN_H_
+#define _MAIN_H_ included
+
+#if   defined (TARGET_KL25Z) 
+#define PIN_MOSI        PTD2
+#define PIN_MISO        PTD3 
+#define PIN_SCLK        PTD1 
+#define PIN_CS_TFT      PTD0 
+#define PIN_DC_TFT      PTD5 
+#define PIN_BL_TFT      PTC9 
+#define PIN_CS_SD       PTA4 
+#define PIN_CS_TSC      PTA13
+#define PIN_TSC_INTR    PTC9
+#define PIN_RESET_TFT   PTB10
+ 
+#elif defined (TARGET_KL46Z)
+#define PIN_MOSI        PTD6
+#define PIN_MISO        PTD7 
+#define PIN_SCLK        PTD5 
+#define PIN_CS_TFT      PTD4 
+#define PIN_DC_TFT      PTD2 
+#define PIN_BL_TFT      PTC9 
+#define PIN_CS_SD       PTA4 
+#define PIN_CS_TSC      PTA13
+#define PIN_TSC_INTR    PTC9
+#define PIN_RESET_TFT   PTB10
+
+#else
+  #error TARGET NOT DEFINED
+#endif
+
+#endif /* _MAIN_H_ */
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 17 13:22:06 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file