Library for Aitendo 2.6 inch TFT shield for Arduino-UNO and Nucleo

Dependents:   Nucleo_Pic_Viewer

Files at this revision

API Documentation at this revision

Comitter:
h_nari
Date:
Wed Apr 30 08:05:41 2014 +0000
Commit message:
First Version

Changed in this revision

AitendoTFT.cpp Show annotated file Show diff for this revision Revisions of this file
AitendoTFT.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f53f19ac1457 AitendoTFT.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AitendoTFT.cpp	Wed Apr 30 08:05:41 2014 +0000
@@ -0,0 +1,194 @@
+#include "AitendoTFT.h"
+#include "mbed_debug.h"
+
+
+#define TFTLCD_GRAM_HOR_AD          0x20
+#define TFTLCD_GRAM_VER_AD          0x21
+#define TFTLCD_RW_GRAM              0x22
+#define TFTLCD_DELAYCMD             0xFF
+
+static const unsigned short _regValues[] = {
+  0x0001,0x0100,    
+  0x0002,0x0700,    
+  0x0003,0x1030,    
+  0x0008,0x0302,    
+  0x0009,0x0000,   
+  0x000A,0x0008,    
+  //*******POWER CONTROL REGISTER INITIAL*******//    
+  0x0010,0x0790,    
+  0x0011,0x0005,    
+  0x0012,0x0000,   
+  0x0013,0x0000,
+  TFTLCD_DELAYCMD, 50,      //delayms(50, 
+  //********POWER SUPPPLY STARTUP 1 SETTING*******//    
+  0x0010,0x12B0,    
+  TFTLCD_DELAYCMD, 50,      // delayms(50,  
+  0x0011,0x0007,    
+  //delayms(50,  
+  //********POWER SUPPLY STARTUP 2 SETTING******//    
+  0x0012,0x008C,    
+  0x0013,0x1700,    
+  0x0029,0x0022,    
+  TFTLCD_DELAYCMD, 50,      // delayms(50,   
+  //******GAMMA CLUSTER SETTING******//    
+  0x0030,0x0000,    
+  0x0031,0x0505,    
+  0x0032,0x0205,    
+  0x0035,0x0206,    
+  0x0036,0x0408,    
+  0x0037,0x0000,    
+  0x0038,0x0504,
+  0x0039,0x0206,    
+  0x003C,0x0206,    
+  0x003D,0x0408,    
+  // -----------DISPLAY WINDOWS 240*320-------------//    
+  0x0050,0x0000,
+  0x0051,0x00EF,   
+  0x0052,0x0000,   
+  0x0053,0x013F,   
+  //-----FRAME RATE SETTING-------//    
+  0x0060,0xA700,   
+  0x0061,0x0001,   
+  0x0090,0x0033, //RTNI setting
+  //-------DISPLAY ON------//    
+  0x0007,0x0133,    0x0001,0x0100,    
+  0x0002,0x0700,    
+  0x0003,0x1030,    
+  0x0008,0x0302,    
+  0x0009,0x0000,   
+  0x000A,0x0008,    
+  //*******POWER CONTROL REGISTER INITIAL*******//    
+  0x0010,0x0790,    
+  0x0011,0x0005,    
+  0x0012,0x0000,   
+  0x0013,0x0000,    
+  //delayms(50, 
+  //********POWER SUPPPLY STARTUP 1 SETTING*******//    
+  0x0010,0x12B0,    
+  TFTLCD_DELAYCMD, 50,      // delayms(50,  
+  0x0011,0x0007,    
+  TFTLCD_DELAYCMD, 50,      // delayms(50,  
+  //********POWER SUPPLY STARTUP 2 SETTING******//    
+  0x0012,0x008C,    
+  0x0013,0x1700,    
+  0x0029,0x0022,    
+  TFTLCD_DELAYCMD, 50,      // delayms(50,   
+  //******GAMMA CLUSTER SETTING******//    
+  0x0030,0x0000,    
+  0x0031,0x0505,    
+  0x0032,0x0205,    
+  0x0035,0x0206,    
+  0x0036,0x0408,    
+  0x0037,0x0000,    
+  0x0038,0x0504,
+  0x0039,0x0206,    
+  0x003C,0x0206,    
+  0x003D,0x0408,    
+  // -----------DISPLAY WINDOWS 240*320-------------//    
+  0x0050,0x0000,
+  0x0051,0x00EF,   
+  0x0052,0x0000,   
+  0x0053,0x013F,   
+  //-----FRAME RATE SETTING-------//    
+  0x0060,0xA700,   
+  0x0061,0x0001,   
+  0x0090,0x0033, //RTNI setting
+  //-------DISPLAY ON------//    
+  0x0007,0x0133,   
+};
+
+
+AitendoTFT::AitendoTFT(void) :
+    _rst(A4), _cs(A3), _rs(A2), _wr(A1), _rd(A0),_d( D8, D9, D2, D3, D4, D5, D6, D7)
+{
+    _init();
+}
+
+void AitendoTFT::_init(void)
+{
+    _rst = 1;
+    _cs = 1;
+    _wr = 1;
+    _rd = 1;
+    _d.input();
+
+    _reset();
+
+    for(int i=0; i < sizeof(_regValues)/sizeof(_regValues[0]); i+= 2) {
+        int a = _regValues[i];
+        int d = _regValues[i+1];
+        if(a == TFTLCD_DELAYCMD)
+            wait_ms(d);
+        else
+            _reg_write(a, d);
+    }
+}
+
+void AitendoTFT::_reset(void)
+{
+    _rst = 0;
+    wait_ms(2);    
+    _rst = 1;
+    
+    _data_write(0);
+    _data_write(0);
+    _data_write(0);
+    _data_write(0);
+}
+
+void AitendoTFT::_write(int rs, int d)
+{
+    _cs = 0;
+    _rs = rs;
+    _rd = 1;
+    _wr = 1;
+    _d.output();
+    
+    _d = d >> 8;
+    _wr = 0;
+    wait_us(1);     // 1us
+    _wr = 1;
+    
+    _d = d;
+    _wr = 0;
+    wait_us(1);     // 1us
+    _wr = 1;
+    
+    _cs = 1;
+}
+
+void AitendoTFT::_reg_write(int addr, int data)
+{
+    _cmd_write(addr);
+    _data_write(data);
+}
+
+void AitendoTFT::_pos_set(int x, int y)
+{
+    _reg_write(TFTLCD_GRAM_HOR_AD, x);
+    _reg_write(TFTLCD_GRAM_VER_AD, y);
+    _cmd_write(TFTLCD_RW_GRAM);
+}
+
+void AitendoTFT::fillArea(int x0, int y0, int x1, int y1, int color)
+{
+    for(int y=y0; y<y1; y++){
+        _pos_set(x0, y);
+        for(int x = x0; x < x1; x++)
+            _data_write(color);
+    }
+}
+
+void AitendoTFT::pset(int x, int y, int color)
+{
+    if(x >= 0 && x < TFT_WIDTH && y > 0 && y < TFT_HEIGHT){
+        _pos_set(x, y);
+        _data_write(color);
+    }
+}
+
+
+
+    
+    
+
diff -r 000000000000 -r f53f19ac1457 AitendoTFT.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AitendoTFT.h	Wed Apr 30 08:05:41 2014 +0000
@@ -0,0 +1,41 @@
+#ifndef _aitendo_tft_h
+#define _aitendo_tft_h
+
+#include "mbed.h"
+
+class AitendoTFT
+{
+public:
+    AitendoTFT();
+    enum {TFT_WIDTH = 240, TFT_HEIGHT = 320,
+          BLACK = 0x0000, BLUE = 0x001F, RED = 0xf800, GREEN = 0x07e0, WHITE = 0xffff
+         };
+    void fillArea(int x0, int y0, int x1, int y1, int color);
+    void fill(int color) {
+        fillArea(0, 0, TFT_WIDTH, TFT_HEIGHT, color);
+    };
+    void pset(int x, int y, int color);
+    void setPos(int x, int y) {
+        _pos_set(x, y);
+    };
+    void put(int color) {
+        _write(1, color);
+    }
+private:
+    DigitalOut _rst, _cs, _rs, _wr, _rd;
+    BusInOut _d;
+
+    void _init(void);
+    void _reset(void);
+    void _write(int rs, int d);
+    void _data_write(int data) {
+        _write(1, data);
+    };
+    void _cmd_write(int cmd) {
+        _write(0, cmd);
+    };
+    void _reg_write(int addr, int data);
+    void _pos_set(int x, int y);
+};
+
+#endif /* _aitendo_tft_h */
\ No newline at end of file