forked from adafruit/Adafruit_HX8357_Library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Adafruit_HX8357.h
188 lines (149 loc) · 5.03 KB
/
Adafruit_HX8357.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/***************************************************
This is our library for the Adafruit HX8357D Breakout
----> http://www.adafruit.com/products/2050
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#ifndef _ADAFRUIT_HX8357_H
#define _ADAFRUIT_HX8357_H
#ifdef ARDUINO
#if ARDUINO >= 100
#include "Arduino.h"
#include "Print.h"
#else
#include "WProgram.h"
#endif
#include <avr/pgmspace.h>
#include "pins_arduino.h"
#include "wiring_private.h"
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#endif
#ifdef SPARK
#include "application.h"
#define digitalPinToBitMask(pin) (volatile uint32_t)pin
#define portOutputRegister(port) NULL
#define digitalPinToPort(pin) (volatile uint32_t)pin
#define cbi(reg, bitmask) PIN_MAP[bitmask].gpio_peripheral->BRR = PIN_MAP[bitmask].gpio_pin
#define sbi(reg, bitmask) PIN_MAP[bitmask].gpio_peripheral->BSRR = PIN_MAP[bitmask].gpio_pin
#define SPARK_SPI_SPEED SPI_CLOCK_DIV4
#endif
#include <Adafruit_GFX.h>
#define HX8357D 0xD
#define HX8357B 0xB
#define HX8357_TFTWIDTH 320
#define HX8357_TFTHEIGHT 480
#define HX8357_NOP 0x00
#define HX8357_SWRESET 0x01
#define HX8357_RDDID 0x04
#define HX8357_RDDST 0x09
#define HX8357_RDPOWMODE 0x0A
#define HX8357_RDMADCTL 0x0B
#define HX8357_RDCOLMOD 0x0C
#define HX8357_RDDIM 0x0D
#define HX8357_RDDSDR 0x0F
#define HX8357_SLPIN 0x10
#define HX8357_SLPOUT 0x11
#define HX8357B_PTLON 0x12
#define HX8357B_NORON 0x13
#define HX8357_INVOFF 0x20
#define HX8357_INVON 0x21
#define HX8357_DISPOFF 0x28
#define HX8357_DISPON 0x29
#define HX8357_CASET 0x2A
#define HX8357_PASET 0x2B
#define HX8357_RAMWR 0x2C
#define HX8357_RAMRD 0x2E
#define HX8357B_PTLAR 0x30
#define HX8357_TEON 0x35
#define HX8357_TEARLINE 0x44
#define HX8357_MADCTL 0x36
#define HX8357_COLMOD 0x3A
#define HX8357_SETOSC 0xB0
#define HX8357_SETPWR1 0xB1
#define HX8357B_SETDISPLAY 0xB2
#define HX8357_SETRGB 0xB3
#define HX8357D_SETCOM 0xB6
#define HX8357B_SETDISPMODE 0xB4
#define HX8357D_SETCYC 0xB4
#define HX8357B_SETOTP 0xB7
#define HX8357D_SETC 0xB9
#define HX8357B_SET_PANEL_DRIVING 0xC0
#define HX8357D_SETSTBA 0xC0
#define HX8357B_SETDGC 0xC1
#define HX8357B_SETID 0xC3
#define HX8357B_SETDDB 0xC4
#define HX8357B_SETDISPLAYFRAME 0xC5
#define HX8357B_GAMMASET 0xC8
#define HX8357B_SETCABC 0xC9
#define HX8357_SETPANEL 0xCC
#define HX8357B_SETPOWER 0xD0
#define HX8357B_SETVCOM 0xD1
#define HX8357B_SETPWRNORMAL 0xD2
#define HX8357B_RDID1 0xDA
#define HX8357B_RDID2 0xDB
#define HX8357B_RDID3 0xDC
#define HX8357B_RDID4 0xDD
#define HX8357D_SETGAMMA 0xE0
#define HX8357B_SETGAMMA 0xC8
#define HX8357B_SETPANELRELATED 0xE9
// Color definitions
#define HX8357_BLACK 0x0000
#define HX8357_BLUE 0x001F
#define HX8357_RED 0xF800
#define HX8357_GREEN 0x07E0
#define HX8357_CYAN 0x07FF
#define HX8357_MAGENTA 0xF81F
#define HX8357_YELLOW 0xFFE0
#define HX8357_WHITE 0xFFFF
class Adafruit_HX8357 : public Adafruit_GFX {
public:
Adafruit_HX8357(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
int8_t _RST, int8_t _MISO);
Adafruit_HX8357(int8_t _CS, int8_t _DC, int8_t _RST = -1);
void begin(uint8_t),
setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
pushColor(uint16_t color),
fillScreen(uint16_t color),
drawPixel(int16_t x, int16_t y, uint16_t color),
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
uint16_t color),
setRotation(uint8_t r),
invertDisplay(boolean i);
uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
/* These are not for current use, 8-bit protocol only! */
uint8_t readdata(void),
readcommand8(uint8_t reg, uint8_t index = 0);
/*
uint16_t readcommand16(uint8_t);
uint32_t readcommand32(uint8_t);
void dummyclock(void);
*/
void spiwrite(uint8_t),
writecommand(uint8_t c),
writedata(uint8_t d),
commandList(uint8_t *addr);
uint8_t spiread(void);
private:
uint8_t tabcolor;
boolean hwSPI;
#if defined (SPARK) || defined (__AVR__)
uint8_t mySPCR;
volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
int8_t _cs, _dc, _rst, _mosi, _miso, _sclk;
uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
#elif defined (__arm__)
volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport;
uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
#endif
};
#endif