Bug Fix and support for color space

This commit is contained in:
sumotoy 2014-05-25 00:01:05 +02:00
parent 31c662cf59
commit 08ef3981d5
2 changed files with 150 additions and 138 deletions

View file

@ -250,6 +250,29 @@ void TFT_ILI9163C::begin(void) {
digitalWrite(_rst, HIGH);
delay(500);
}
/*
7) MY: 1(bottom to top), 0(top to bottom) Row Address Order
6) MX: 1(R to L), 0(L to R) Column Address Order
5) MV: 1(Exchanged), 0(normal) Row/Column exchange
4) ML: 1(bottom to top), 0(top to bottom) Vertical Refresh Order
3) RGB: 1(BGR), 0(RGB) Color Space
2) MH: 1(R to L), 0(L to R) Horizontal Refresh Order
1)
0)
MY, MX, MV, ML,RGB, MH, D1, D0
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 //normal
1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 //Y-Mirror
0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 //X-Mirror
1 | 1 | 0 | 0 | 1 | 0 | 0 | 0 //X-Y-Mirror
0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 //X-Y Exchange
1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 //X-Y Exchange, Y-Mirror
0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 //XY exchange
1 | 1 | 1 | 0 | 1 | 0 | 0 | 0
*/
_Mactrl_Data = 0b00000000;
_colorspaceData = __COLORSPC;//start with default data;
chipInit();
}
@ -259,21 +282,21 @@ void TFT_ILI9163C::chipInit() {
writecommand(CMD_SWRESET);//software reset
delay(500);
writecommand(CMD_SLPOUT);//exit sleep
delay(50);
delay(5);
writecommand(CMD_PIXFMT);//Set Color Format 16bit
writedata(0x05);
delay(50);
delay(5);
writecommand(CMD_GAMMASET);//default gamma curve 3
writedata(0x04);//0x04
delay(10);
delay(1);
writecommand(CMD_GAMRSEL);//Enable Gamma adj
writedata(0x01);
delay(10);
delay(1);
writecommand(CMD_NORML);
writecommand(0xB6);
writedata(0b11111111);//0x04
writedata(0b00000110);//0x04
writecommand(CMD_DFUNCTR);
writedata(0b11111111);//
writedata(0b00000110);//
writecommand(CMD_PGAMMAC);//Positive Gamma Correction Setting
#if defined(__GAMMASET1)
@ -310,7 +333,6 @@ void TFT_ILI9163C::chipInit() {
writedata(0x00);//p15
#endif
writecommand(CMD_NGAMMAC);//Negative Gamma Correction Setting
#if defined(__GAMMASET1)
writedata(0x09);//p1
@ -346,28 +368,27 @@ void TFT_ILI9163C::chipInit() {
writedata(0x3A);//p15
#endif
writecommand(CMD_FRMCTR1);//Frame Rate Control (In normal mode/Full colors)
writedata(0x08);//0x0C//0x08
writedata(0x02);//0x14//0x08
delay(10);
delay(1);
writecommand(CMD_DINVCTR);//display inversion
writedata(0x07);
delay(10);
delay(1);
writecommand(CMD_PWCTR1);//Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD
writedata(0x0A);//4.30 - 0x0A
writedata(0x02);//0x05
delay(10);
delay(1);
writecommand(CMD_PWCTR2);//Set BT[2:0] for AVDD & VCL & VGH & VGL
writedata(0x02);
delay(10);
delay(1);
writecommand(CMD_VCOMCTR1);//Set VMH[6:0] & VML[6:0] for VOMH & VCOML
writedata(0x50);//0x50
writedata(99);//0x5b
delay(10);
delay(1);
writecommand(CMD_VCOMOFFS);
writedata(0);//0x40
delay(10);
delay(1);
writecommand(CMD_CLMADRS);//Set Column Address
writedata(0x00);
@ -381,23 +402,32 @@ void TFT_ILI9163C::chipInit() {
writedata(0X00);
writedata(_GRAMHEIGH);
//writecommand(CMD_MADCTL);//Set Scanning Direction && Colorspace
//writedata(DTA_MADCTL_MX | __COLORSPC); //08
writecommand(CMD_MADCTL);
writedata(0b00001000);
delay(10);
writecommand(CMD_DISPON);//display ON
delay(10);
writecommand(CMD_RAMWR);//Memory Write
writedata16(0X0000);
writedata16(0X0000);
writedata16(0X0000);
writedata16(0X0000);
delay(10);
fillScreen(BLACK);
//colorSpace(__COLORSPC);//set default colorspace and other access data
colorSpace(_colorspaceData);
setRotation(0);
writecommand(CMD_DISPON);//display ON
delay(1);
writecommand(CMD_RAMWR);//Memory Write
delay(1);
fillScreen(BLACK);
}
/*
Colorspace selection:
0: RGB
1: GBR
*/
void TFT_ILI9163C::colorSpace(uint8_t cspace) {
if (cspace < 1){
bitClear(_Mactrl_Data,3);
} else {
bitSet(_Mactrl_Data,3);
}
//writecommand(CMD_MADCTL);
//writedata(_Mactrl_Data);
//delay(1);
}
@ -409,7 +439,7 @@ void TFT_ILI9163C::clearScreen(uint16_t color) {
}
void TFT_ILI9163C::homeAddress() {
setAddrWindow(0x00,0x00,_GRAMWIDTH,_GRAMHEIGH);
setAddrWindow(0x00,0x00,_GRAMWIDTH-1,_GRAMHEIGH-1);
}
void TFT_ILI9163C::setCursor(int16_t x, int16_t y) {
@ -435,8 +465,8 @@ void TFT_ILI9163C::drawPixel(int16_t x, int16_t y, uint16_t color) {
void TFT_ILI9163C::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) {
// Rudimentary clipping
if (boundaryCheck(x,y)) return;
if ((y+h-1) >= _height) h = _height-y;
setAddrWindow(x, y, x, y+h-1);
if (((y + h) - 1) >= _height) h = _height-y;
setAddrWindow(x,y,x,(y+h)-1);
while (h--) {
writedata16(color);
}
@ -450,8 +480,8 @@ bool TFT_ILI9163C::boundaryCheck(int16_t x,int16_t y){
void TFT_ILI9163C::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) {
// Rudimentary clipping
if (boundaryCheck(x,y)) return;
if ((x+w-1) >= _width) w = _width-x;
setAddrWindow(x, y, x+w-1, y);
if (((x+w) - 1) >= _width) w = _width-x;
setAddrWindow(x,y,(x+w)-1,y);
while (w--) {
writedata16(color);
}
@ -459,18 +489,17 @@ void TFT_ILI9163C::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color
void TFT_ILI9163C::fillScreen(uint16_t color) {
clearScreen(color);
//homeAddress();
}
// fill a rectangle
void TFT_ILI9163C::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
if (boundaryCheck(x,y)) return;
if ((x + w - 1) >= _width) w = _width - x;
if ((y + h - 1) >= _height) h = _height - y;
setAddrWindow(x, y, x+w-1, y+h-1);
if (((x + w) - 1) >= _width) w = _width - x;
if (((y + h) - 1) >= _height) h = _height - y;
setAddrWindow(x,y,(x+w)-1,(y+h)-1);
for (y=h; y>0; y--) {
for (x=w; x>0; x--) {
for (y = h;y > 0;y--) {
for (x = w;x > 0;x--) {
writedata16(color);
}
}
@ -490,8 +519,8 @@ void TFT_ILI9163C::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
writedata16(x0);
writedata16(x1);
} else if (rotation == 1){
writedata16(x0+32);
writedata16(x1+32);
writedata16(x0 + __OFFSET);
writedata16(x1 + __OFFSET);
} else if (rotation == 2){
writedata16(x0);
writedata16(x1);
@ -502,8 +531,8 @@ void TFT_ILI9163C::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
writecommand(CMD_PGEADRS); // Page
if (rotation == 0){
writedata16(y0+__OFFSET);
writedata16(y1+__OFFSET);
writedata16(y0 + __OFFSET);
writedata16(y1 + __OFFSET);
} else if (rotation == 1){
writedata16(y0);
writedata16(y1);
@ -514,57 +543,37 @@ void TFT_ILI9163C::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t
writedata16(y0);
writedata16(y1);
}
writecommand(CMD_RAMWR); //Into RAM
}
//MY: 1(bottom to top), 0(top to bottom) Row Address Order
//MX: 1(R to L), 0(L to R) Column Address Order
//MV: 1(Exchanged), 0(normal) Row/Column exchange
//ML: 1(bottom to top), 0(top to bottom) Vertical Refresh Order
//RGB: 1(BGR), 0(RGB) Color Space
//MH: 1(R to L), 0(L to R) Horizontal Refresh Order
// MY, MX, MV, ML,RGB, MH, D1, D0
/*
( 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0),//normal
( 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0),//Y-Mirror
( 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0),//X-Mirror
( 1 | 1 | 0 | 0 | 1 | 0 | 0 | 0),//X-Y-Mirror
( 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0),//X-Y Exchange
( 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0),//X-Y Exchange, Y-Mirror
( 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0),//XY exchange
( 1 | 1 | 1 | 0 | 1 | 0 | 0 | 0)
};
*/
void TFT_ILI9163C::setRotation(uint8_t m) {
writecommand(CMD_MADCTL);
rotation = m % 4; // can't be higher than 3
switch (rotation) {
case 0:
writecommand(CMD_MADCTL);
writedata(0b00001000);
_Mactrl_Data = 0b00001000;
_width = _TFTWIDTH;
_height = _TFTHEIGHT;//-__OFFSET;
break;
case 1:
writecommand(CMD_MADCTL);
writedata(0b01101000);
_Mactrl_Data = 0b01101000;
_width = _TFTHEIGHT;//-__OFFSET;
_height = _TFTWIDTH;
break;
case 2:
writecommand(CMD_MADCTL);
writedata(0b11001000);
_Mactrl_Data = 0b11001000;
_width = _TFTWIDTH;
_height = _TFTHEIGHT;//-__OFFSET;
break;
case 3:
writecommand(CMD_MADCTL);
writedata(0b10101000);
_Mactrl_Data = 0b10101000;
_width = _TFTWIDTH;
_height = _TFTHEIGHT;//-__OFFSET;
break;
}
colorSpace(_colorspaceData);
writecommand(CMD_MADCTL);
writedata(_Mactrl_Data);
}

View file

@ -66,6 +66,7 @@
0.1b1: Beta! Addressing solved, now rotation works and boundaries ok.
0.2b1: Cleaned up.
0.2b3: Added 2.2" Red PCB parameters
0.2b4: Bug fixes, added colorSpace (for future send image)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
BugList of the current version:
@ -128,7 +129,7 @@ you can copy those parameters and create setup for different displays.
#define _GRAMWIDTH 128
#define _GRAMHEIGH 160
#define _GRAMSIZE _GRAMWIDTH * _GRAMHEIGH//*see note 1
#define __COLORSPC DTA_MADCTL_BGR//DTA_MADCTL_RGB
#define __COLORSPC 1// 1:GBR - 0:RGB
#define __GAMMASET1 //uncomment for another gamma
#define __OFFSET 32//*see note 2
//Tested!
@ -143,7 +144,7 @@ Not tested!
#define _GRAMWIDTH 240
#define _GRAMHEIGH 320
#define _GRAMSIZE _GRAMWIDTH * _GRAMHEIGH
#define __COLORSPC DTA_MADCTL_BGR//DTA_MADCTL_RGB
#define __COLORSPC 1// 1:GBR - 0:RGB
#define __GAMMASET1 //uncomment for another gamma
#define __OFFSET 0
#else
@ -152,7 +153,7 @@ Not tested!
#define _GRAMWIDTH 128
#define _GRAMHEIGH 160
#define _GRAMSIZE _GRAMWIDTH * _GRAMHEIGH
#define __COLORSPC DTA_MADCTL_BGR//DTA_MADCTL_RGB
#define __COLORSPC 1// 1:GBR - 0:RGB
#define __GAMMASET1
#define __OFFSET 0
#endif
@ -267,8 +268,10 @@ class TFT_ILI9163C : public Adafruit_GFX {
void setBitrate(uint32_t n);
private:
uint8_t _Mactrl_Data;//container for the memory access control data
uint8_t _colorspaceData;
uint8_t tabcolor;
void colorSpace(uint8_t cspace);
void writecommand(uint8_t c);
void writedata(uint8_t d);
void writedata16(uint16_t d);