A fork of Adafruit_ST7735 library compilable for mbed-os 6.3

Committer:
amouroug
Date:
Tue Oct 06 21:17:03 2020 +0000
Revision:
0:300afe8ecf63
Adafruit ST7735 fork with mbed-os fixes;

Who changed what in which revision?

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