Fast! Install BurstSPI library! https://os.mbed.com/users/peekpt/code/BurstSPI/ New display (greentab2 blue module compact).

Committer:
peekpt
Date:
Fri Apr 24 11:14:56 2020 +0000
Revision:
8:66c5dc727281
Parent:
7:856a3443f68d
ADDED BURST SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SomeRandomBloke 0:99ee879ef5a9 1 /***************************************************
SomeRandomBloke 0:99ee879ef5a9 2 This is a library for the Adafruit 1.8" SPI display.
SomeRandomBloke 0:99ee879ef5a9 3 This library works with the Adafruit 1.8" TFT Breakout w/SD card
SomeRandomBloke 0:99ee879ef5a9 4 ----> http://www.adafruit.com/products/358
SomeRandomBloke 0:99ee879ef5a9 5 as well as Adafruit raw 1.8" TFT display
SomeRandomBloke 0:99ee879ef5a9 6 ----> http://www.adafruit.com/products/618
SomeRandomBloke 0:99ee879ef5a9 7
SomeRandomBloke 0:99ee879ef5a9 8 Check out the links above for our tutorials and wiring diagrams
SomeRandomBloke 0:99ee879ef5a9 9 These displays use SPI to communicate, 4 or 5 pins are required to
SomeRandomBloke 0:99ee879ef5a9 10 interface (RST is optional)
SomeRandomBloke 0:99ee879ef5a9 11 Adafruit invests time and resources providing this open source code,
SomeRandomBloke 0:99ee879ef5a9 12 please support Adafruit and open-source hardware by purchasing
SomeRandomBloke 0:99ee879ef5a9 13 products from Adafruit!
SomeRandomBloke 0:99ee879ef5a9 14
SomeRandomBloke 0:99ee879ef5a9 15 Written by Limor Fried/Ladyada for Adafruit Industries.
SomeRandomBloke 0:99ee879ef5a9 16 MIT license, all text above must be included in any redistribution
SomeRandomBloke 0:99ee879ef5a9 17 ****************************************************/
SomeRandomBloke 0:99ee879ef5a9 18
peekpt 8:66c5dc727281 19 // + GREENTAB2 display
peekpt 8:66c5dc727281 20 // BurstSPI
peekpt 7:856a3443f68d 21
SomeRandomBloke 0:99ee879ef5a9 22 #ifndef _ADAFRUIT_ST7735H_
SomeRandomBloke 0:99ee879ef5a9 23 #define _ADAFRUIT_ST7735H_
SomeRandomBloke 0:99ee879ef5a9 24
peekpt 7:856a3443f68d 25 #include "Adafruit_GFX.h"
peekpt 8:66c5dc727281 26 #include "BurstSPI.h"
SomeRandomBloke 0:99ee879ef5a9 27 #include "mbed.h"
peekpt 7:856a3443f68d 28
SomeRandomBloke 0:99ee879ef5a9 29 #define boolean bool
SomeRandomBloke 0:99ee879ef5a9 30
SomeRandomBloke 0:99ee879ef5a9 31 // some flags for initR() :(
SomeRandomBloke 3:5cd5edbf5b72 32 // some flags for initR() :(
SomeRandomBloke 0:99ee879ef5a9 33 #define INITR_GREENTAB 0x0
peekpt 7:856a3443f68d 34 #define INITR_REDTAB 0x1
peekpt 7:856a3443f68d 35 #define INITR_BLACKTAB 0x2
peekpt 7:856a3443f68d 36 #define INITR_GREENTAB2 0x3
SomeRandomBloke 3:5cd5edbf5b72 37
peekpt 7:856a3443f68d 38 #define INITR_18GREENTAB INITR_GREENTAB
peekpt 7:856a3443f68d 39 #define INITR_18REDTAB INITR_REDTAB
peekpt 7:856a3443f68d 40 #define INITR_18BLACKTAB INITR_BLACKTAB
peekpt 7:856a3443f68d 41 #define INITR_144GREENTAB 0x1
SomeRandomBloke 0:99ee879ef5a9 42
peekpt 7:856a3443f68d 43 #define ST7735_TFTWIDTH 128
SomeRandomBloke 3:5cd5edbf5b72 44 // for 1.44" display
SomeRandomBloke 3:5cd5edbf5b72 45 #define ST7735_TFTHEIGHT_144 128
SomeRandomBloke 3:5cd5edbf5b72 46 // for 1.8" display
peekpt 7:856a3443f68d 47 #define ST7735_TFTHEIGHT_18 160
peekpt 7:856a3443f68d 48 #define ST7735_TFTHEIGHT 160
SomeRandomBloke 0:99ee879ef5a9 49
peekpt 7:856a3443f68d 50 #define ST7735_NOP 0x00
SomeRandomBloke 0:99ee879ef5a9 51 #define ST7735_SWRESET 0x01
peekpt 7:856a3443f68d 52 #define ST7735_RDDID 0x04
peekpt 7:856a3443f68d 53 #define ST7735_RDDST 0x09
SomeRandomBloke 0:99ee879ef5a9 54
peekpt 7:856a3443f68d 55 #define ST7735_SLPIN 0x10
peekpt 7:856a3443f68d 56 #define ST7735_SLPOUT 0x11
peekpt 7:856a3443f68d 57 #define ST7735_PTLON 0x12
peekpt 7:856a3443f68d 58 #define ST7735_NORON 0x13
SomeRandomBloke 0:99ee879ef5a9 59
peekpt 7:856a3443f68d 60 #define ST7735_INVOFF 0x20
peekpt 7:856a3443f68d 61 #define ST7735_INVON 0x21
SomeRandomBloke 0:99ee879ef5a9 62 #define ST7735_DISPOFF 0x28
peekpt 7:856a3443f68d 63 #define ST7735_DISPON 0x29
peekpt 7:856a3443f68d 64 #define ST7735_CASET 0x2A
peekpt 7:856a3443f68d 65 #define ST7735_RASET 0x2B
peekpt 7:856a3443f68d 66 #define ST7735_RAMWR 0x2C
peekpt 7:856a3443f68d 67 #define ST7735_RAMRD 0x2E
SomeRandomBloke 0:99ee879ef5a9 68
peekpt 7:856a3443f68d 69 #define ST7735_PTLAR 0x30
peekpt 7:856a3443f68d 70 #define ST7735_COLMOD 0x3A
peekpt 7:856a3443f68d 71 #define ST7735_MADCTL 0x36
SomeRandomBloke 0:99ee879ef5a9 72
SomeRandomBloke 0:99ee879ef5a9 73 #define ST7735_FRMCTR1 0xB1
SomeRandomBloke 0:99ee879ef5a9 74 #define ST7735_FRMCTR2 0xB2
SomeRandomBloke 0:99ee879ef5a9 75 #define ST7735_FRMCTR3 0xB3
peekpt 7:856a3443f68d 76 #define ST7735_INVCTR 0xB4
SomeRandomBloke 0:99ee879ef5a9 77 #define ST7735_DISSET5 0xB6
SomeRandomBloke 0:99ee879ef5a9 78
peekpt 7:856a3443f68d 79 #define ST7735_PWCTR1 0xC0
peekpt 7:856a3443f68d 80 #define ST7735_PWCTR2 0xC1
peekpt 7:856a3443f68d 81 #define ST7735_PWCTR3 0xC2
peekpt 7:856a3443f68d 82 #define ST7735_PWCTR4 0xC3
peekpt 7:856a3443f68d 83 #define ST7735_PWCTR5 0xC4
peekpt 7:856a3443f68d 84 #define ST7735_VMCTR1 0xC5
SomeRandomBloke 0:99ee879ef5a9 85
peekpt 7:856a3443f68d 86 #define ST7735_RDID1 0xDA
peekpt 7:856a3443f68d 87 #define ST7735_RDID2 0xDB
peekpt 7:856a3443f68d 88 #define ST7735_RDID3 0xDC
peekpt 7:856a3443f68d 89 #define ST7735_RDID4 0xDD
SomeRandomBloke 0:99ee879ef5a9 90
peekpt 7:856a3443f68d 91 #define ST7735_PWCTR6 0xFC
SomeRandomBloke 0:99ee879ef5a9 92
SomeRandomBloke 0:99ee879ef5a9 93 #define ST7735_GMCTRP1 0xE0
SomeRandomBloke 0:99ee879ef5a9 94 #define ST7735_GMCTRN1 0xE1
SomeRandomBloke 0:99ee879ef5a9 95
SomeRandomBloke 0:99ee879ef5a9 96 // Color definitions
peekpt 7:856a3443f68d 97 #define ST7735_BLACK 0x0000
peekpt 7:856a3443f68d 98 #define ST7735_BLUE 0x001F
peekpt 7:856a3443f68d 99 #define ST7735_RED 0xF800
peekpt 7:856a3443f68d 100 #define ST7735_GREEN 0x07E0
peekpt 7:856a3443f68d 101 #define ST7735_CYAN 0x07FF
SomeRandomBloke 0:99ee879ef5a9 102 #define ST7735_MAGENTA 0xF81F
peekpt 7:856a3443f68d 103 #define ST7735_YELLOW 0xFFE0
peekpt 7:856a3443f68d 104 #define ST7735_WHITE 0xFFFF
peekpt 8:66c5dc727281 105 #define ST7735_ORANGE 0xFC00
SomeRandomBloke 0:99ee879ef5a9 106
SomeRandomBloke 0:99ee879ef5a9 107 class Adafruit_ST7735 : public Adafruit_GFX {
SomeRandomBloke 0:99ee879ef5a9 108
peekpt 7:856a3443f68d 109 public:
peekpt 7:856a3443f68d 110 Adafruit_ST7735(PinName mosi, PinName miso, PinName sck, PinName CS,
peekpt 7:856a3443f68d 111 PinName RS, PinName RST);
SomeRandomBloke 0:99ee879ef5a9 112
peekpt 7:856a3443f68d 113 void initB(void); // for ST7735B displays
peekpt 7:856a3443f68d 114 void initR(uint8_t options = INITR_GREENTAB); // for ST7735R
peekpt 7:856a3443f68d 115 void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
peekpt 7:856a3443f68d 116 void pushColor(uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 117
peekpt 7:856a3443f68d 118 void fillScreen(uint16_t color);
peekpt 7:856a3443f68d 119 void drawPixel(int16_t x, int16_t y, uint16_t color);
peekpt 7:856a3443f68d 120 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
peekpt 7:856a3443f68d 121 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
peekpt 7:856a3443f68d 122 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
peekpt 7:856a3443f68d 123 void invertDisplay(boolean i);
SomeRandomBloke 0:99ee879ef5a9 124
peekpt 7:856a3443f68d 125 void setRotation(uint8_t r);
SomeRandomBloke 0:99ee879ef5a9 126 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b);
SomeRandomBloke 0:99ee879ef5a9 127
peekpt 7:856a3443f68d 128 private:
peekpt 7:856a3443f68d 129 uint8_t tabcolor;
peekpt 7:856a3443f68d 130 void spiwrite(uint8_t), writecommand(uint8_t c), writedata(uint8_t d),
peekpt 7:856a3443f68d 131 commandList(uint8_t *addr), commonInit(uint8_t *cmdList);
SomeRandomBloke 0:99ee879ef5a9 132
peekpt 7:856a3443f68d 133 uint8_t colstart, rowstart; // some displays need this changed
SomeRandomBloke 0:99ee879ef5a9 134
peekpt 8:66c5dc727281 135 BurstSPI lcdPort; // does SPI MOSI, MISO and SCK
peekpt 8:66c5dc727281 136 DigitalOut _cs; // does SPI CE
peekpt 8:66c5dc727281 137 DigitalOut _rs; // register/date select
peekpt 8:66c5dc727281 138 DigitalOut _rst; // does 3310 LCD_RST
SomeRandomBloke 0:99ee879ef5a9 139 };
SomeRandomBloke 0:99ee879ef5a9 140
peekpt 8:66c5dc727281 141 #endif