This library is for Arduino TFT LCD Screen module.(for new LCD driver IC)
Dependents: ArduinoTFTLCDScreenSample_SPI18TFT
Fork of ST7735_TFT by
You are viewing an older revision! See the latest version
Homepage
いきさつ¶
Arduino TFT LCD ScreenというLCD moduleをmbedで使用しました。(module詳細 switch science web)
このLCD moduleのLCD driver ICはST7735 ですが、複数のバージョンがあり、libraryとICのバージョンが合わないと正常に表示しません。
mbedにはこのICに対応したlibrary(ST7735_TFT)がありますが、私が入手したLCD moduleではICの種類が違うためか正常に動作しませんでした。幸い、switch scienceのwebにarduino用の対応libraryがあったので、これを元にmbedのlibrary(ST7735_TFT)に移植しました。
libraryの移植¶
移植元のArduino library¶
移植元はswitch science webにある置き換え用TFTライブラリ(Arduino IDE1.0.5用)を使用します。このファイルを解凍してできる、"Adfruit_ST7735.cpp"の230行目以降のGcmd[]配列が該当するdriver ICの設定データになります。
Adfruit_ST7735.cpp
・ ・ ・ Gcmd[] = { // Initialization commands for 7735B screens 19, // 18 commands in list: ST7735_SWRESET, DELAY, // 1: Software reset, no args, w/delay 50, // 50 ms delay ST7735_SLPOUT , DELAY, // 2: Out of sleep mode, no args, w/delay 100, // 255 = 500 ms delay 0x26 , 1, // 3: Set default gamma 0x04, // 16-bit color 0xb1, 2, // 4: Frame Rate 0x0b, 0x14, 0xc0, 2, // 5: VRH1[4:0] & VC[2:0] 0x08, 0x00, 0xc1, 1, // 6: BT[2:0] 0x05, 0xc5, 2, // 7: VMH[6:0] & VML[6:0] 0x41, 0x30, 0xc7, 1, // 8: LCD Driving control 0xc1, 0xEC, 1, // 9: Set pumping color freq 0x1b, 0x3a , 1 + DELAY, // 10: Set color format 0x55, // 16-bit color 100, 0x2a, 4, // 11: Set Column Address 0x00, 0x00, 0x00, 0x7f, 0x2b, 4, // 12: Set Page Address 0x00, 0x00, 0x00, 0x9f, 0x36, 1, // 12+1: Set Scanning Direction 0xc8, 0xb7, 1, // 14: Set Source Output Direciton 0x00, 0xf2, 1, // 15: Enable Gamma bit 0x00, 0xe0, 15 + DELAY, // 16: magic 0x28, 0x24, 0x22, 0x31, 0x2b, 0x0e, 0x53, 0xa5, 0x42, 0x16, 0x18, 0x12, 0x1a, 0x14, 0x03, 50, 0xe1, 15 + DELAY, // 17: more magic 0x17, 0x1b, 0x1d, 0x0e, 0x14, 0x11, 0x2c, 0xa5, 0x3d, 0x09, 0x27, 0x2d, 0x25, 0x2b, 0x3c, 50, ST7735_NORON , DELAY, // 17: Normal display on, no args, w/delay 10, // 10 ms delay ST7735_DISPON , DELAY, // 18: Main screen turn on, no args, w/delay 255 }; // 255 = 500 ms delay ・ ・ ・
移植先のmbed library¶
移植先となるmbed libraryはST7735_TFTとなります。
<<code ST7735_TFT.cpp>>
・
・
・
void ST7735_TFT::tft_reset() {
static unsigned short driverCode;
init SPI _spi.format(8,3); 8 bit spi mode 3 _spi.frequency(16000000); 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work
reset exactly like in Arduino version _cs = 0; _reset = 1; reset wait_ms(500); _reset = 0; reset wait_ms(500); _reset = 1; reset wait_ms(500);
- ifdef ST7735B @ss
/* Start Initial Sequence
----------*/ wr_cmd(ST7735_SWRESET); /* SW Reset */ wait_ms(150); wr_cmd(ST7735_SLPOUT); /* Out of sleepmode */ wait_ms(500);
wr_cmd(0x26); 3: Set default gamma wr_dat(0x04); 16-bit color
wr_cmd(ST7735_FRMCTR1); /*4 Frame rate in normal mode */ wr_dat(0x0b); wr_dat(0x14);
wr_cmd(0xc0); 5 POWER CONTROL 1 wr_dat(0x08); wr_dat(0x00);
wr_cmd(0xc1); 6 POWER CONTROL 2 wr_dat(0x05);
wr_cmd(0xC5); POWER CONTROL 6 wr_dat(0x41); wr_dat(0x30);
wr_cmd(0xc7); 8:LCD Driving control wr_dat(0xc1);
wr_cmd(0xec); 9:Set color format wr_dat(0x1b); 16-bit color
wr_cmd(0x3A); COLOR MODE wr_dat(0x55); wait_ms(100);
wr_cmd(0x2a); 11 COLUMN ADDR SET wr_dat(0x00); wr_dat(0x00); xstart = 0 wr_dat(0x00); wr_dat(0x7F); xend = 127
wr_cmd(0x2b); ROW ADDR SET wr_dat(0x00); wr_dat(0x00); ystart = 0 wr_dat(0x00); wr_dat(0x9F); yend = 159
wr_cmd(0x36); 13 Set Scanning Direction wr_dat(0xc8);
wr_cmd(0xb7); 14 Set Source Output Direction
wr_dat(0x00);
/* Gamma settings -----------*/
wr_cmd(0xE0); GMCTRP1 wr_dat(0x28); wr_dat(0x24); wr_dat(0x22); wr_dat(0x31);
wr_dat(0x2b); wr_dat(0x0e); wr_dat(0x53); wr_dat(0xa5);
wr_dat(0x42); wr_dat(0x16); wr_dat(0x18); wr_dat(0x12);
wr_dat(0x1a); wr_dat(0x14); wr_dat(0x03);
wait_ms(50);
wr_cmd(0xE1); GMCTRN1 wr_dat(0x17); wr_dat(0x1b); wr_dat(0x1d); wr_dat(0x0e);
wr_dat(0x14); wr_dat(0x11); wr_dat(0x2c); wr_dat(0xa5);
wr_dat(0x3d); wr_dat(0x09); wr_dat(0x27); wr_dat(0x2d);
wr_dat(0x25); wr_dat(0x2b); wr_dat(0x3c);
wait_ms(50);
wr_cmd(0x13); 18 Normal display on no args. wait_ms(10);
wr_cmd(0x29); 19 Main screen turn on, no args.normal display on wait_ms(500);
switch (orientation) { case 0: wr_reg(0x36, 0x0008); originalでの0xc8は間違いで、ST7735_MADCTL(0x36)ではないか break; case 1: wr_reg(0x36, 0x0068); break; case 2: wr_reg(0x36, 0x00C8); break; case 3: wr_reg(0x36, 0x00A8); break; }
- else @ss ST7735B (original)
/* Start Initial Sequence
----------*/ wr_cmd(ST7735_SWRESET); /* SW Reset */ wait_ms(150); wr_cmd(ST7735_SLPOUT); /* Out of sleepmode */ wait_ms(500); ・ ・ ・ <<\code>>