Chinese module HY-1.8 SPI TFT lcd Display library.
Dependents: KL25Z_DCF77_HY-1_8LCD
Fork of HY-1_8TFT_ST7735 by
Diff: ST7735_TFT.cpp
- Revision:
- 2:26149011665e
- Parent:
- 1:ef70eaf15b18
diff -r ef70eaf15b18 -r 26149011665e ST7735_TFT.cpp --- a/ST7735_TFT.cpp Fri Apr 19 20:46:47 2013 +0000 +++ b/ST7735_TFT.cpp Sun Oct 11 21:30:26 2015 +0000 @@ -4,10 +4,10 @@ #include "ST7735_TFT.h" #include "mbed.h" -#define BPP 8 // Bits per pixel +#define BPP 16 // Bits per pixel ST7735_TFT::ST7735_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rs, PinName reset, const char *name) - : _spi(mosi, miso, sclk), _cs(cs), _rs(rs), _reset(reset),GraphicsDisplay(name) + : GraphicsDisplay(name),_spi(mosi, miso, sclk), _cs(cs), _rs(rs), _reset(reset) { tft_reset(); orientation = 2; @@ -128,7 +128,7 @@ void ST7735_TFT::tft_reset() { // 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 + _spi.frequency(15000000); // 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work _cs = 0; _reset = 1; // reset wait_ms(10); @@ -272,8 +272,8 @@ _rs = 1; _cs = 0; _spi.write(color); - _spi.write(color>>8); - _cs = 1; + _spi.write(color>>8); + _cs = 1; } void ST7735_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) { wr_cmd(ST7735_CASET); // column addr set @@ -297,9 +297,15 @@ WindowMax(); wr_dat_start(); for (i = 0; i < ( (width()) * (height())); i++) { - _spi.write(_background); - _spi.write(_background>>8); + + //_spi.write(_background>>8); + //_spi.write(_background); + + _spi.fastWrite(_background>>8); + _spi.fastWrite(_background); + } + _spi.clearRX(); wr_dat_stop(); } void ST7735_TFT::circle(int x0, int y0, int r, int color) { @@ -408,9 +414,12 @@ wr_cmd(0x2C); wr_dat_start(); for (int x=0; x<w; x++) { - _spi.write(color); - _spi.write(color >> 8); + //_spi.write(color); + //_spi.write(color >> 8); + _spi.fastWrite(color>>8); + _spi.fastWrite(color); } + _spi.clearRX(); wr_dat_stop(); return; } @@ -421,9 +430,12 @@ wr_cmd(0x2C); wr_dat_start(); for (int y=0; y<h; y++) { - _spi.write(color); - _spi.write(color >> 8); + //_spi.write(color); + //_spi.write(color >> 8); + _spi.fastWrite(color>>8); + _spi.fastWrite(color); } + _spi.clearRX(); wr_dat_stop(); return; } @@ -509,9 +521,14 @@ wr_cmd(0x2C); wr_dat_start(); for (int p=0; p<pixel; p++) { - _spi.write(color); - _spi.write(color >> 8); + //_spi.write(color); + //_spi.write(color >> 8); + _spi.fastWrite(color>>8); + _spi.fastWrite(color); + + } + _spi.clearRX(); wr_dat_stop(); return; } @@ -563,15 +580,22 @@ for (i=0; i<hor; i++) { // horz line z = sign[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - _spi.write(_background); - _spi.write(_background>>8); - } else { - _spi.write(_foreground); - _spi.write(_foreground>>8); + if (( z & b ) == 0x00) { + //_spi.write(_background>>8); + //_spi.write(_background); + _spi.fastWrite(_background>>8); + _spi.fastWrite(_background); + + } else { + // _spi.write(_foreground>>8); + // _spi.write(_foreground); + _spi.fastWrite(_foreground>>8); + _spi.fastWrite(_foreground); + } } } + _spi.clearRX(); wr_dat_stop(); if ((w + 2) < hor) { // x offset to next char char_x += w + 2; @@ -588,11 +612,14 @@ wr_dat_start(); for (j = 0; j < h; j++) { //Lines for (i = 0; i < w; i++) { // copy pixel data to TFT - _spi.write(*bitmap_ptr); // one line - _spi.write(*bitmap_ptr >> 8); + //_spi.write(*bitmap_ptr); // one line + //_spi.write(*bitmap_ptr >> 8); + _spi.fastWrite(*bitmap_ptr); + _spi.fastWrite(*bitmap_ptr >> 8); bitmap_ptr++; } } + _spi.clearRX(); wr_dat_stop(); } int ST7735_TFT::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) { @@ -657,10 +684,13 @@ fseek(Image, off ,SEEK_SET); fread(line,1,PixelWidth * 2,Image); // read a line - slow ! for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT - _spi.write(line[i]); // one 16 bit pixel - _spi.write(line[i]>>8); + //_spi.write(line[i]); // 2 x 8 bit pixel + //_spi.write(line[i]>>8); + _spi.fastWrite(line[i]); + _spi.fastWrite(line[i]>>8); } } + _spi.clearRX(); wr_dat_stop(); free (line); fclose(Image);