-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaveshare-spi.hpp
164 lines (139 loc) · 3.75 KB
/
waveshare-spi.hpp
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
/**
* Defines and data structures for the Waveshare WSLCD18 (ST7735S)
* SPI interface.
*
* Author: dev@c272.org
**/
#include <stdint.h>
//Opcode definitions for the ST7735S.
#define ST_OP_NOP 0x0
#define ST_OP_SWRESET 0x1
#define ST_OP_RDDID 0x4
#define ST_OP_RDDST 0x9
#define ST_OP_RDDPM 0xA
#define ST_OP_RDDMADCTL 0xB
#define ST_OP_RDDIM 0xD
#define ST_OP_RDDSM 0xE
#define ST_OP_RDDSDR 0xF
#define ST_OP_SLPIN 0x10
#define ST_OP_SLPOUT 0x11
#define ST_OP_PTLON 0x12
#define ST_OP_NORON 0x13
#define ST_OP_INVOFF 0x20
#define ST_OP_INFON 0x21
#define ST_OP_GAMSET 0x26
#define ST_OP_DISPOFF 0x28
#define ST_OP_DISPON 0x29
#define ST_OP_CASET 0x2A
#define ST_OP_RASET 0x2B
#define ST_OP_RAMWR 0x2C
#define ST_OP_RGBSET 0x2D
#define ST_OP_RAMRD 0x2E
#define ST_OP_PTLAR 0x30
#define ST_OP_SCRLAR 0x33
#define ST_OP_TEOFF 0x34
#define ST_OP_TEON 0x35
#define ST_OP_MADCTL 0x36
#define ST_OP_VSCSAD 0x37
#define ST_OP_IDMOFF 0x38
#define ST_OP_IDMON 0x39
#define ST_OP_COLMOD 0x3A
#define ST_OP_RDID1 0xDA
#define ST_OP_RDID2 0xDB
#define ST_OP_RDID3 0xDC
#define ST_OP_FRMCTR1 0xB1
#define ST_OP_FRMCTR2 0xB2
#define ST_OP_FRMCTR3 0xB3
#define ST_OP_INVCTR 0xB4
#define ST_OP_PWCTR1 0xC0
#define ST_OP_PWCTR2 0xC1
#define ST_OP_PWCTR3 0xC2
#define ST_OP_PWCTR4 0xC3
#define ST_OP_PWCTR5 0xC4
#define ST_OP_VMCTR1 0xC5
#define ST_OP_VMOFCTR 0xC7
#define ST_OP_WRID2 0xD1
#define ST_OP_WRID3 0xD2
#define ST_OP_NVFCTR1 0xD9
#define ST_OP_NVFCTR2 0xDE
#define ST_OP_NVFCTR3 0xDF
#define ST_OP_GMCTRP1 0xE0
#define ST_OP_GMCTRN1 0xE1
#define ST_OP_GCV 0xFC
namespace waveshare
{
//The colour modes available for the ST7735S.
enum colour_mode {
TWELVE_BIT = 3,
SIXTEEN_BIT = 5,
EIGHTEEN_BIT = 6,
UNKNOWN = 7
};
//Memory data access address ordering types.
enum mdac_address_mode {
//Goes left to right, from top to bottom (normal).
LTR_TOP_TO_BOTTOM = 0b000,
//Goes left to right, from bottom to top (Y-invert).
LTR_BOTTOM_TO_TOP = 0b001,
//Goes right to left, from top to bottom (X-invert).
RTL_TOP_TO_BOTTOM = 0b010,
//Goes right to left, from bottom to top (X/Y-invert).
RTL_BOTTOM_TO_TOP = 0b011,
//Goes top to bottom, from left to right (column mode).
TTB_LEFT_TO_RIGHT = 0b100,
//Goes bottom to top, from left to right (column-Y-invert).
BTT_LEFT_TO_RIGHT = 0b101,
//Goes top to bottom, from right to left (column-X-invert).
TTB_RIGHT_TO_LEFT = 0b110,
//Goes bottom to top, from right to left (column-X/Y-invert).
BTT_RIGHT_TO_LEFT = 0b111
};
//Display refresh orders.
enum vrefresh_order { TOP_TO_BOTTOM = 0, BOTTOM_TO_TOP = 1 };
enum hrefresh_order { LEFT_TO_RIGHT = 0, RIGHT_TO_LEFT = 1 };
//Colour data ordering mode.
enum colour_data_format { RGB = 0, BGR = 1 };
//Memory data access control configuration structure.
struct mdac_config {
mdac_address_mode address_mode : 3;
vrefresh_order vertical_refresh : 1;
colour_data_format colour_format : 1;
hrefresh_order horizontal_refresh : 1;
uint8_t resv : 2;
mdac_config()
{
address_mode = LTR_TOP_TO_BOTTOM;
vertical_refresh = TOP_TO_BOTTOM;
horizontal_refresh = LEFT_TO_RIGHT;
colour_format = RGB;
resv = 0;
}
} __attribute__((packed));
//Represents a single point on the Waveshare WSLCD18.
struct point {
uint8_t x;
uint8_t y;
};
//Represents a draw rectangle for the Waveshare WSLCD18.
struct rect {
point top_left;
point bottom_right;
};
//Represents a single 16-bit display colour.
struct colour16 {
uint8_t blue : 5;
uint8_t green : 6;
uint8_t red : 5;
//Return a uint16_t prepared for sending to display.
uint16_t pack()
{
uint16_t packed = *(uint16_t*)this;
return (packed >> 8) + (packed << 8);
}
//Initialises the colour with the given RGB values.
colour16(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0)
: blue(b), green(g), red(r)
{
}
} __attribute__((packed));
} //namespace waveshare