Alfredo Espinoza Rhoton / Adafruit_ST7735

Fork of Adafruit_ST7735 by Andrew Lindsay

Committer:
AlfredoER
Date:
Tue Mar 03 20:20:07 2015 +0000
Revision:
5:57e689b2af4f
Parent:
4:2eb7d188ba43
-Merged changes.

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
AlfredoER 4:2eb7d188ba43 19 #pragma once
SomeRandomBloke 0:99ee879ef5a9 20
SomeRandomBloke 0:99ee879ef5a9 21 #include "mbed.h"
SomeRandomBloke 0:99ee879ef5a9 22 #include "Adafruit_GFX.h"
AlfredoER 4:2eb7d188ba43 23 #include "N3310LCDDefs.h"
AlfredoER 3:38c4a70421f0 24 #include "board.h"
SomeRandomBloke 0:99ee879ef5a9 25 #define boolean bool
SomeRandomBloke 0:99ee879ef5a9 26
SomeRandomBloke 0:99ee879ef5a9 27 // some flags for initR() :(
SomeRandomBloke 0:99ee879ef5a9 28 #define INITR_GREENTAB 0x0
SomeRandomBloke 0:99ee879ef5a9 29 #define INITR_REDTAB 0x1
SomeRandomBloke 0:99ee879ef5a9 30
AlfredoER 3:38c4a70421f0 31 #define INITR_GREENTAB 0x0
AlfredoER 3:38c4a70421f0 32 #define INITR_REDTAB 0x1
AlfredoER 3:38c4a70421f0 33 #define INITR_BLACKTAB 0x2
AlfredoER 3:38c4a70421f0 34
AlfredoER 3:38c4a70421f0 35 #define INITR_18GREENTAB INITR_GREENTAB
AlfredoER 3:38c4a70421f0 36 #define INITR_18REDTAB INITR_REDTAB
AlfredoER 3:38c4a70421f0 37 #define INITR_18BLACKTAB INITR_BLACKTAB
AlfredoER 3:38c4a70421f0 38 #define INITR_144GREENTAB 0x1
AlfredoER 3:38c4a70421f0 39
SomeRandomBloke 0:99ee879ef5a9 40 #define ST7735_TFTWIDTH 128
AlfredoER 3:38c4a70421f0 41 #define ST7735_TFTHEIGHT 128
SomeRandomBloke 0:99ee879ef5a9 42
SomeRandomBloke 0:99ee879ef5a9 43 #define ST7735_NOP 0x00
SomeRandomBloke 0:99ee879ef5a9 44 #define ST7735_SWRESET 0x01
SomeRandomBloke 0:99ee879ef5a9 45 #define ST7735_RDDID 0x04
SomeRandomBloke 0:99ee879ef5a9 46 #define ST7735_RDDST 0x09
SomeRandomBloke 0:99ee879ef5a9 47
SomeRandomBloke 0:99ee879ef5a9 48 #define ST7735_SLPIN 0x10
SomeRandomBloke 0:99ee879ef5a9 49 #define ST7735_SLPOUT 0x11
SomeRandomBloke 0:99ee879ef5a9 50 #define ST7735_PTLON 0x12
SomeRandomBloke 0:99ee879ef5a9 51 #define ST7735_NORON 0x13
SomeRandomBloke 0:99ee879ef5a9 52
SomeRandomBloke 0:99ee879ef5a9 53 #define ST7735_INVOFF 0x20
SomeRandomBloke 0:99ee879ef5a9 54 #define ST7735_INVON 0x21
SomeRandomBloke 0:99ee879ef5a9 55 #define ST7735_DISPOFF 0x28
SomeRandomBloke 0:99ee879ef5a9 56 #define ST7735_DISPON 0x29
SomeRandomBloke 0:99ee879ef5a9 57 #define ST7735_CASET 0x2A
SomeRandomBloke 0:99ee879ef5a9 58 #define ST7735_RASET 0x2B
SomeRandomBloke 0:99ee879ef5a9 59 #define ST7735_RAMWR 0x2C
SomeRandomBloke 0:99ee879ef5a9 60 #define ST7735_RAMRD 0x2E
SomeRandomBloke 0:99ee879ef5a9 61
SomeRandomBloke 0:99ee879ef5a9 62 #define ST7735_PTLAR 0x30
SomeRandomBloke 0:99ee879ef5a9 63 #define ST7735_COLMOD 0x3A
SomeRandomBloke 0:99ee879ef5a9 64 #define ST7735_MADCTL 0x36
SomeRandomBloke 0:99ee879ef5a9 65
SomeRandomBloke 0:99ee879ef5a9 66 #define ST7735_FRMCTR1 0xB1
SomeRandomBloke 0:99ee879ef5a9 67 #define ST7735_FRMCTR2 0xB2
SomeRandomBloke 0:99ee879ef5a9 68 #define ST7735_FRMCTR3 0xB3
SomeRandomBloke 0:99ee879ef5a9 69 #define ST7735_INVCTR 0xB4
SomeRandomBloke 0:99ee879ef5a9 70 #define ST7735_DISSET5 0xB6
SomeRandomBloke 0:99ee879ef5a9 71
SomeRandomBloke 0:99ee879ef5a9 72 #define ST7735_PWCTR1 0xC0
SomeRandomBloke 0:99ee879ef5a9 73 #define ST7735_PWCTR2 0xC1
SomeRandomBloke 0:99ee879ef5a9 74 #define ST7735_PWCTR3 0xC2
SomeRandomBloke 0:99ee879ef5a9 75 #define ST7735_PWCTR4 0xC3
SomeRandomBloke 0:99ee879ef5a9 76 #define ST7735_PWCTR5 0xC4
SomeRandomBloke 0:99ee879ef5a9 77 #define ST7735_VMCTR1 0xC5
SomeRandomBloke 0:99ee879ef5a9 78
SomeRandomBloke 0:99ee879ef5a9 79 #define ST7735_RDID1 0xDA
SomeRandomBloke 0:99ee879ef5a9 80 #define ST7735_RDID2 0xDB
SomeRandomBloke 0:99ee879ef5a9 81 #define ST7735_RDID3 0xDC
SomeRandomBloke 0:99ee879ef5a9 82 #define ST7735_RDID4 0xDD
SomeRandomBloke 0:99ee879ef5a9 83
SomeRandomBloke 0:99ee879ef5a9 84 #define ST7735_PWCTR6 0xFC
SomeRandomBloke 0:99ee879ef5a9 85
SomeRandomBloke 0:99ee879ef5a9 86 #define ST7735_GMCTRP1 0xE0
SomeRandomBloke 0:99ee879ef5a9 87 #define ST7735_GMCTRN1 0xE1
SomeRandomBloke 0:99ee879ef5a9 88
SomeRandomBloke 0:99ee879ef5a9 89 // Color definitions
SomeRandomBloke 0:99ee879ef5a9 90 #define ST7735_BLACK 0x0000
SomeRandomBloke 0:99ee879ef5a9 91 #define ST7735_BLUE 0x001F
SomeRandomBloke 0:99ee879ef5a9 92 #define ST7735_RED 0xF800
SomeRandomBloke 0:99ee879ef5a9 93 #define ST7735_GREEN 0x07E0
SomeRandomBloke 0:99ee879ef5a9 94 #define ST7735_CYAN 0x07FF
SomeRandomBloke 0:99ee879ef5a9 95 #define ST7735_MAGENTA 0xF81F
SomeRandomBloke 0:99ee879ef5a9 96 #define ST7735_YELLOW 0xFFE0
SomeRandomBloke 0:99ee879ef5a9 97 #define ST7735_WHITE 0xFFFF
SomeRandomBloke 0:99ee879ef5a9 98
AlfredoER 3:38c4a70421f0 99 #define BLACK 0x0000
AlfredoER 3:38c4a70421f0 100 #define BLUE 0x001F
AlfredoER 3:38c4a70421f0 101 #define RED 0xF800
AlfredoER 3:38c4a70421f0 102 #define GREEN 0x07E0
AlfredoER 3:38c4a70421f0 103 #define CYAN 0x07FF
AlfredoER 3:38c4a70421f0 104 #define MAGENTA 0xF81F
AlfredoER 3:38c4a70421f0 105 #define YELLOW 0xFFE0
AlfredoER 3:38c4a70421f0 106 #define WHITE 0xFFFF
AlfredoER 3:38c4a70421f0 107
SomeRandomBloke 0:99ee879ef5a9 108
AlfredoER 4:2eb7d188ba43 109
AlfredoER 4:2eb7d188ba43 110
SomeRandomBloke 0:99ee879ef5a9 111 class Adafruit_ST7735 : public Adafruit_GFX {
SomeRandomBloke 0:99ee879ef5a9 112
SomeRandomBloke 0:99ee879ef5a9 113 public:
SomeRandomBloke 0:99ee879ef5a9 114
AlfredoER 4:2eb7d188ba43 115 Adafruit_ST7735( PinName CS, PinName RS, PinName RST, PinName BL);
SomeRandomBloke 0:99ee879ef5a9 116
AlfredoER 5:57e689b2af4f 117 void chipEnable();
AlfredoER 5:57e689b2af4f 118 void chipDisable();
SomeRandomBloke 0:99ee879ef5a9 119 void initB(void); // for ST7735B displays
SomeRandomBloke 0:99ee879ef5a9 120 void initR(uint8_t options = INITR_GREENTAB); // for ST7735R
AlfredoER 4:2eb7d188ba43 121 void backlight( uint8_t setting );
AlfredoER 4:2eb7d188ba43 122 void writeString( int x, int row, char * str, int flag );
AlfredoER 4:2eb7d188ba43 123 void writeString( int x, int row, char * str, int flag, char size );
SomeRandomBloke 0:99ee879ef5a9 124 void setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1);
SomeRandomBloke 0:99ee879ef5a9 125 void pushColor(uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 126
SomeRandomBloke 0:99ee879ef5a9 127 void fillScreen(uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 128 void drawPixel(int16_t x, int16_t y, uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 129 void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 130 void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 131 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
SomeRandomBloke 0:99ee879ef5a9 132 void invertDisplay(boolean i);
SomeRandomBloke 0:99ee879ef5a9 133
AlfredoER 4:2eb7d188ba43 134
AlfredoER 4:2eb7d188ba43 135 void bitmap( int16_t x, int16_t y, int16_t w, int16_t h, const unsigned char *map );
AlfredoER 4:2eb7d188ba43 136 void bitmapBW(int16_t x, int16_t y, const unsigned char *map, int16_t w, int16_t h, int16_t foreground, int16_t background );
AlfredoER 4:2eb7d188ba43 137
AlfredoER 4:2eb7d188ba43 138 void setRotation( uint8_t r);
AlfredoER 4:2eb7d188ba43 139 uint16_t Color565( uint8_t r, uint8_t g, uint8_t b );
SomeRandomBloke 0:99ee879ef5a9 140
AlfredoER 4:2eb7d188ba43 141
SomeRandomBloke 0:99ee879ef5a9 142 private:
SomeRandomBloke 0:99ee879ef5a9 143
SomeRandomBloke 0:99ee879ef5a9 144 void spiwrite(uint8_t),
SomeRandomBloke 0:99ee879ef5a9 145 writecommand(uint8_t c),
SomeRandomBloke 0:99ee879ef5a9 146 writedata(uint8_t d),
SomeRandomBloke 0:99ee879ef5a9 147 commandList(uint8_t *addr),
SomeRandomBloke 0:99ee879ef5a9 148 commonInit(uint8_t *cmdList);
SomeRandomBloke 0:99ee879ef5a9 149
SomeRandomBloke 0:99ee879ef5a9 150 uint8_t colstart, rowstart; // some displays need this changed
SomeRandomBloke 0:99ee879ef5a9 151
AlfredoER 3:38c4a70421f0 152 // SPI lcdPort; // does SPI MOSI, MISO and SCK
SomeRandomBloke 0:99ee879ef5a9 153 DigitalOut _cs; // does SPI CE
SomeRandomBloke 0:99ee879ef5a9 154 DigitalOut _rs; // register/date select
SomeRandomBloke 0:99ee879ef5a9 155 DigitalOut _rst; // does 3310 LCD_RST
AlfredoER 4:2eb7d188ba43 156 DigitalOut _bl; // backlight
SomeRandomBloke 0:99ee879ef5a9 157 };