fix for ILI9325

Fork of TFTLCD by Todor Todorov

Files at this revision

API Documentation at this revision

Comitter:
nameless129
Date:
Sun Jul 12 03:16:20 2015 +0000
Parent:
27:26491d710e72
Commit message:
first commit;

Changed in this revision

ili9328.cpp Show annotated file Show diff for this revision Revisions of this file
ili9328.h Show annotated file Show diff for this revision Revisions of this file
lcd_base.h Show annotated file Show diff for this revision Revisions of this file
--- a/ili9328.cpp	Mon Jul 22 01:48:06 2013 +0000
+++ b/ili9328.cpp	Sun Jul 12 03:16:20 2015 +0000
@@ -94,66 +94,56 @@
             entryMod |= 0x1000;
             break;
     }
-    
-    WriteCmdData( 0xE5, 0x78F0 ); // set SRAM internal timing
-    WriteCmdData( 0x01, drivOut ); // set Driver Output Control
-    WriteCmdData( 0x02, 0x0200 ); // set 1 line inversion
-    WriteCmdData( 0x03, entryMod ); // set GRAM write direction and BGR=1.
-    WriteCmdData( 0x04, 0x0000 ); // Resize register
-    WriteCmdData( 0x08, 0x0207 ); // set the back porch and front porch
-    WriteCmdData( 0x09, 0x0000 ); // set non-display area refresh cycle ISC[3:0]
-    WriteCmdData( 0x0A, 0x0000 ); // FMARK function
-    WriteCmdData( 0x0C, 0x0000 ); // RGB interface setting
-    WriteCmdData( 0x0D, 0x0000 ); // Frame marker Position
-    WriteCmdData( 0x0F, 0x0000 ); // RGB interface polarity
+
+    WriteCmdData( ILI932X_DRIV_OUT_CTRL, drivOut ); // set Driver Output Control
+    WriteCmdData( ILI932X_DRIV_WAV_CTRL, 0x0700 ); // set 1 line inversion
+    WriteCmdData( ILI932X_ENTRY_MOD, entryMod ); // set GRAM write direction and BGR=1.
+    WriteCmdData( ILI932X_RESIZE_CTRL, 0x0000 ); // Resize register
+    WriteCmdData( ILI932X_DISP_CTRL2, 0x0202 ); // set the back porch and front porch
+    WriteCmdData( ILI932X_DISP_CTRL3, 0x0000 ); // set non-display area refresh cycle ISC[3:0]
+    WriteCmdData( ILI932X_DISP_CTRL4, 0x0000 ); // FMARK function
+    WriteCmdData( ILI932X_RGB_DISP_IF_CTRL1, 0x0000 ); // RGB interface setting
+    WriteCmdData( ILI932X_FRM_MARKER_POS, 0x0000 ); // Frame marker Position
+    WriteCmdData( ILI932X_RGB_DISP_IF_CTRL2, 0x0000 ); // RGB interface polarity
     // ----------- Power On sequence ----------- //
-    WriteCmdData( 0x10, 0x0000 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
-    WriteCmdData( 0x11, 0x0007 ); // DC1[2:0], DC0[2:0], VC[2:0]
-    WriteCmdData( 0x12, 0x0000 ); // VREG1OUT voltage
-    WriteCmdData( 0x13, 0x0000 ); // VDV[4:0] for VCOM amplitude
-    WriteCmdData( 0x07, 0x0001 );
+    WriteCmdData( ILI932X_POW_CTRL1, 0x0000 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
+    WriteCmdData( ILI932X_POW_CTRL2, 0x0007 ); // DC1[2:0], DC0[2:0], VC[2:0]
+    WriteCmdData( ILI932X_POW_CTRL3, 0x0000 ); // VREG1OUT voltage
+    WriteCmdData( ILI932X_POW_CTRL4, 0x0000 ); // VDV[4:0] for VCOM amplitude
     wait_ms( 200 ); // Dis-charge capacitor power voltage
-    WriteCmdData( 0x10, 0x1690 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
-    WriteCmdData( 0x11, 0x0227 ); // Set DC1[2:0], DC0[2:0], VC[2:0]
+    WriteCmdData( ILI932X_POW_CTRL1, 0x1690 ); // SAP, BT[3:0], AP, DSTB, SLP, STB
+    WriteCmdData( ILI932X_POW_CTRL2, 0x0227 ); // Set DC1[2:0], DC0[2:0], VC[2:0]
     wait_ms( 50 ); // Delay 50ms
-    WriteCmdData( 0x12, 0x000D ); // 0012
+    WriteCmdData( ILI932X_POW_CTRL3, 0x001A ); // 0012
     wait_ms( 50 ); // Delay 50ms
-    WriteCmdData( 0x13, 0x1200 ); // VDV[4:0] for VCOM amplitude
-    WriteCmdData( 0x29, 0x000A ); // 04  VCM[5:0] for VCOMH
-    WriteCmdData( 0x2B, 0x000D ); // Set Frame Rate
+    WriteCmdData( ILI932X_POW_CTRL4, 0x1800 ); // VDV[4:0] for VCOM amplitude
+    WriteCmdData( ILI932X_POW_CTRL7, 0x002A ); // 04  VCM[5:0] for VCOMH
     wait_ms( 50 ); // Delay 50ms
-    WriteCmdData( 0x20, 0x0000 ); // GRAM horizontal Address
-    WriteCmdData( 0x21, 0x0000 ); // GRAM Vertical Address
+    WriteCmdData( ILI932X_GRAM_HOR_AD, 0x0000 ); // GRAM horizontal Address
+    WriteCmdData( ILI932X_GRAM_VER_AD, 0x0000 ); // GRAM Vertical Address
     // ----------- Adjust the Gamma Curve ----------//
-    WriteCmdData( 0x30, 0x0000 );
-    WriteCmdData( 0x31, 0x0404 );
-    WriteCmdData( 0x32, 0x0003 );
-    WriteCmdData( 0x35, 0x0405 );
-    WriteCmdData( 0x36, 0x0808 );
-    WriteCmdData( 0x37, 0x0407 );
-    WriteCmdData( 0x38, 0x0303 );
-    WriteCmdData( 0x39, 0x0707 );
-    WriteCmdData( 0x3C, 0x0504 );
-    WriteCmdData( 0x3D, 0x0808 );
+    WriteCmdData( ILI932X_GAMMA_CTRL1, 0x0000 );
+    WriteCmdData( ILI932X_GAMMA_CTRL2, 0x0000 );
+    WriteCmdData( ILI932X_GAMMA_CTRL3, 0x0000 );
+    WriteCmdData( ILI932X_GAMMA_CTRL4, 0x0206 );
+    WriteCmdData( ILI932X_GAMMA_CTRL5, 0x0808 );
+    WriteCmdData( ILI932X_GAMMA_CTRL6, 0x0007 );
+    WriteCmdData( ILI932X_GAMMA_CTRL7, 0x0201 );
+    WriteCmdData( ILI932X_GAMMA_CTRL8, 0x0000 );
+    WriteCmdData( ILI932X_GAMMA_CTRL9, 0x0000 );
+    WriteCmdData( ILI932X_GAMMA_CTRL10, 0x0000 );
     //------------------ Set GRAM area ---------------//
-    WriteCmdData( 0x50, 0x0000 ); // Horizontal GRAM Start Address
-    WriteCmdData( 0x51, 0x00EF ); // Horizontal GRAM End Address
-    WriteCmdData( 0x52, 0x0000 ); // Vertical GRAM Start Address
-    WriteCmdData( 0x53, 0x013F ); // Vertical GRAM Start Address
-    WriteCmdData( 0x60, gateScan ); // Gate Scan Line (0xA700)
-    WriteCmdData( 0x61, 0x0000 ); // NDL,VLE, REV
-    WriteCmdData( 0x6A, 0x0000 ); // set scrolling line
-    //-------------- Partial Display Control ---------//
-    WriteCmdData( 0x80, 0x0000 );
-    WriteCmdData( 0x81, 0x0000 );
-    WriteCmdData( 0x82, 0x0000 );
-    WriteCmdData( 0x83, 0x0000 );
-    WriteCmdData( 0x84, 0x0000 );
-    WriteCmdData( 0x85, 0x0000 );
+    WriteCmdData( ILI932X_HOR_END_AD, 0x00EF ); // Horizontal GRAM End Address
+    WriteCmdData( ILI932X_VER_START_AD, 0x0000 ); // Vertical GRAM Start Address
+    WriteCmdData( ILI932X_VER_END_AD, 0x013F ); // Vertical GRAM Start Address
+    WriteCmdData( ILI932X_GATE_SCAN_CTRL1, gateScan ); // Gate Scan Line (0xA700)
+    WriteCmdData( ILI932X_GATE_SCAN_CTRL2, 0x0003 ); // NDL,VLE, REV
+    WriteCmdData( ILI932X_GATE_SCAN_CTRL3, 0x0000 ); // set scrolling line
     //-------------- Panel Control -------------------//
-    WriteCmdData( 0x90, 0x0010 ); 
-    WriteCmdData( 0x92, 0x0000 );
-    WriteCmdData( 0x07, 0x0133 ); // 262K color and display ON
+    WriteCmdData( ILI932X_PANEL_IF_CTRL1, 0x0010 ); 
+    WriteCmdData( ILI932X_PANEL_IF_CTRL2, 0x0000 );
+    WriteCmdData( ILI932X_PANEL_IF_CTRL4, 0X1100 );
+    WriteCmdData( ILI932X_DISP_CTRL1, 0x0133 ); // 262K color and display ON
     
     Deactivate();
 }
@@ -176,17 +166,22 @@
     Deactivate();
 }
 
+//fix to 8bit mode
 void ILI9328_LCD::WriteCmd( unsigned short cmd )
 {
     _lcd_pin_rs = LOW;
+    _lcd_port->write( 0 );
+    pulseLow( _lcd_pin_wr );
     _lcd_port->write( cmd );
     pulseLow( _lcd_pin_wr );
 }
-
+//fix to 8bit mode
 void ILI9328_LCD::WriteData( unsigned short data )
 {
     _lcd_pin_rs = HIGH;
-    _lcd_port->write( data );
+    _lcd_port->write( data>>8 );
+    pulseLow( _lcd_pin_wr );
+    _lcd_port->write( data&0xff );
     pulseLow( _lcd_pin_wr );
 }
 
--- a/ili9328.h	Mon Jul 22 01:48:06 2013 +0000
+++ b/ili9328.h	Sun Jul 12 03:16:20 2015 +0000
@@ -181,6 +181,52 @@
     DigitalOut* _lcd_pin_rd;
 };
 
+#define ILI932X_DRIV_OUT_CTRL      0x01
+#define ILI932X_DRIV_WAV_CTRL      0x02
+#define ILI932X_ENTRY_MOD          0x03
+#define ILI932X_RESIZE_CTRL        0x04
+#define ILI932X_DISP_CTRL1         0x07
+#define ILI932X_DISP_CTRL2         0x08
+#define ILI932X_DISP_CTRL3         0x09
+#define ILI932X_DISP_CTRL4         0x0A
+#define ILI932X_RGB_DISP_IF_CTRL1  0x0C
+#define ILI932X_FRM_MARKER_POS     0x0D
+#define ILI932X_RGB_DISP_IF_CTRL2  0x0F
+#define ILI932X_POW_CTRL1          0x10
+#define ILI932X_POW_CTRL2          0x11
+#define ILI932X_POW_CTRL3          0x12
+#define ILI932X_POW_CTRL4          0x13
+#define ILI932X_GRAM_HOR_AD        0x20
+#define ILI932X_GRAM_VER_AD        0x21
+#define ILI932X_RW_GRAM            0x22
+#define ILI932X_POW_CTRL7          0x29
+#define ILI932X_FRM_RATE_COL_CTRL  0x2B
+#define ILI932X_GAMMA_CTRL1        0x30
+#define ILI932X_GAMMA_CTRL2        0x31
+#define ILI932X_GAMMA_CTRL3        0x32
+#define ILI932X_GAMMA_CTRL4        0x35
+#define ILI932X_GAMMA_CTRL5        0x36
+#define ILI932X_GAMMA_CTRL6        0x37
+#define ILI932X_GAMMA_CTRL7        0x38
+#define ILI932X_GAMMA_CTRL8        0x39
+#define ILI932X_GAMMA_CTRL9        0x3C
+#define ILI932X_GAMMA_CTRL10       0x3D
+#define ILI932X_HOR_END_AD         0x51
+#define ILI932X_VER_START_AD       0x52
+#define ILI932X_VER_END_AD         0x53
+#define ILI932X_GATE_SCAN_CTRL1    0x60
+#define ILI932X_GATE_SCAN_CTRL2    0x61
+#define ILI932X_GATE_SCAN_CTRL3    0x6A
+#define ILI932X_PART_IMG1_DISP_POS 0x80
+#define ILI932X_PART_IMG1_START_AD 0x81
+#define ILI932X_PART_IMG1_END_AD   0x82
+#define ILI932X_PART_IMG2_DISP_POS 0x83
+#define ILI932X_PART_IMG2_START_AD 0x84
+#define ILI932X_PART_IMG2_END_AD   0x85
+#define ILI932X_PANEL_IF_CTRL1     0x90
+#define ILI932X_PANEL_IF_CTRL2     0x92
+#define ILI932X_PANEL_IF_CTRL4     0x95
+
 #ifdef __cplusplus
 }
 #endif
--- a/lcd_base.h	Mon Jul 22 01:48:06 2013 +0000
+++ b/lcd_base.h	Sun Jul 12 03:16:20 2015 +0000
@@ -514,7 +514,7 @@
      * \param color The color of the pixel.
      * \param mode The depth (palette) of the color.
      */
-    virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB24 ) = 0;
+    virtual void SetPixelColor( unsigned int color, colordepth_t mode = RGB16 ) = 0;
     
     /** Draws a horizontal line.
      *