Basic Library for Adafruit 1.44" Screen with ST7735 driver
Dependents: ME503_VehicleAssembly
Adafruit_ST7735.h
00001 /*************************************************** 00002 This is a library for the Adafruit 1.8" SPI display. 00003 This library works with the Adafruit 1.8" TFT Breakout w/SD card 00004 ----> http://www.adafruit.com/products/358 00005 as well as Adafruit raw 1.8" TFT display 00006 ----> http://www.adafruit.com/products/618 00007 00008 Check out the links above for our tutorials and wiring diagrams 00009 These displays use SPI to communicate, 4 or 5 pins are required to 00010 interface (RST is optional) 00011 Adafruit invests time and resources providing this open source code, 00012 please support Adafruit and open-source hardware by purchasing 00013 products from Adafruit! 00014 00015 Written by Limor Fried/Ladyada for Adafruit Industries. 00016 MIT license, all text above must be included in any redistribution 00017 ****************************************************/ 00018 00019 #ifndef _ADAFRUIT_ST7735H_ 00020 #define _ADAFRUIT_ST7735H_ 00021 00022 #include "mbed.h" 00023 #include "Adafruit_GFX.h" 00024 00025 #define boolean bool 00026 00027 // some flags for initR() :( 00028 #define INITR_GREENTAB 0x0 00029 #define INITR_REDTAB 0x1 00030 00031 #define ST7735_TFTWIDTH 128 00032 #define ST7735_TFTHEIGHT 128 //make 160 for 1.8" screen, 128 for 1.44" screen 00033 00034 #define ST7735_NOP 0x00 00035 #define ST7735_SWRESET 0x01 00036 #define ST7735_RDDID 0x04 00037 #define ST7735_RDDST 0x09 00038 00039 #define ST7735_SLPIN 0x10 00040 #define ST7735_SLPOUT 0x11 00041 #define ST7735_PTLON 0x12 00042 #define ST7735_NORON 0x13 00043 00044 #define ST7735_INVOFF 0x20 00045 #define ST7735_INVON 0x21 00046 #define ST7735_DISPOFF 0x28 00047 #define ST7735_DISPON 0x29 00048 #define ST7735_CASET 0x2A 00049 #define ST7735_RASET 0x2B 00050 #define ST7735_RAMWR 0x2C 00051 #define ST7735_RAMRD 0x2E 00052 00053 #define ST7735_PTLAR 0x30 00054 #define ST7735_COLMOD 0x3A 00055 #define ST7735_MADCTL 0x36 00056 00057 #define ST7735_FRMCTR1 0xB1 00058 #define ST7735_FRMCTR2 0xB2 00059 #define ST7735_FRMCTR3 0xB3 00060 #define ST7735_INVCTR 0xB4 00061 #define ST7735_DISSET5 0xB6 00062 00063 #define ST7735_PWCTR1 0xC0 00064 #define ST7735_PWCTR2 0xC1 00065 #define ST7735_PWCTR3 0xC2 00066 #define ST7735_PWCTR4 0xC3 00067 #define ST7735_PWCTR5 0xC4 00068 #define ST7735_VMCTR1 0xC5 00069 00070 #define ST7735_RDID1 0xDA 00071 #define ST7735_RDID2 0xDB 00072 #define ST7735_RDID3 0xDC 00073 #define ST7735_RDID4 0xDD 00074 00075 #define ST7735_PWCTR6 0xFC 00076 00077 #define ST7735_GMCTRP1 0xE0 00078 #define ST7735_GMCTRN1 0xE1 00079 00080 // color definitions 00081 #define ST7735_BLACK 0x0000 00082 #define ST7735_BLUE 0x001F 00083 #define ST7735_RED 0xF800 00084 #define ST7735_GREEN 0x07E0 00085 #define ST7735_CYAN 0x07FF 00086 #define ST7735_MAGENTA 0xF81F 00087 #define ST7735_YELLOW 0xFFE0 00088 #define ST7735_WHITE 0xFFFF 00089 #define ST7735_ORANGE 0xFD20 00090 00091 00092 class Adafruit_ST7735 : public Adafruit_GFX { 00093 00094 public: 00095 00096 Adafruit_ST7735(PinName mosi, PinName miso, PinName clk, PinName CS, PinName RS, PinName RST); 00097 00098 void initB(void); // for ST7735B displays 00099 void initR(uint8_t options = INITR_GREENTAB); // for ST7735R 00100 void initS(void); // for S6D02A1 displays 00101 void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1); 00102 void pushColor(uint16_t color); 00103 00104 void fillScreen(uint16_t color); 00105 void drawPixel(int16_t x, int16_t y, uint16_t color); 00106 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 00107 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 00108 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 00109 void invertDisplay(boolean i); 00110 00111 void setRotation(uint8_t r); 00112 void drawRect(int16_t x0, int16_t y0, int16_t x1,int16_t y1,uint16_t color);//added by Sarvesh 00113 void drawCircle(int16_t x0, int16_t y0,int16_t r,uint16_t color);//added by Sarvesh 00114 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); 00115 //void display(); 00116 00117 private: 00118 00119 void spiwrite(uint8_t), 00120 writecommand(uint8_t c), 00121 writedata(uint8_t d), 00122 commandList(uint8_t *addr), 00123 commonInit(uint8_t *cmdList); 00124 00125 uint8_t colstart, rowstart; // some displays need this changed 00126 00127 SPI lcdPort; // does SPI MOSI, MISO and SCK 00128 DigitalOut _cs; // does SPI CE 00129 DigitalOut _rs; // register/date select 00130 DigitalOut _rst; // does 3310 LCD_RST 00131 }; 00132 00133 #endif
Generated on Mon Jul 25 2022 18:08:25 by
1.7.2