stm32-camera  1.0
st7735r.h
Go to the documentation of this file.
1 /**
2  * @file st7735r.h
3  * @brief Main header file for the ST7735R LCD chip.
4  *
5  * @details pinkeee @ j.t0dd@protonmail.com
6  * @note See README for contributing guides and info.
7  * @copyright See License file.
8  */
9 
10 #ifndef ST7735R_H
11 #define ST7735R_H
12 
13 #include "main.h"
14 
15 #define ST7735R_RET_OK 0
16 #define ST7735R_RET_FAIL 0
17 
18 #define ST7735R_SPI_TIMEOUT 100
19 
20 /* _Command list_ */
21 
22 /**
23  * @brief NOP command
24  * @details This command is empty command.
25  * @return 0x00
26 */
27 static uint8_t ST7735R_NOP_CMD = 0x00;
28 
29 /**
30  * @brief SWRESET command
31  * @details Software reset
32  * @return 0x01
33 */
34 static uint8_t ST7735R_SWRESET_CMD = 0x01;
35 
36 /**
37  * @brief RDDID command
38  * @details Read Display ID
39  * @return 0x04
40 */
41 static uint8_t ST7735R_RDDID_CMD = 0x04;
42 
43 /**
44  * @brief RDDST command
45  * @details Read Display Status
46  * @return 0x09
47 */
48 static uint8_t ST7735R_RDDST_CMD = 0x09;
49 
50 /**
51  * @brief RDDPM command
52  * @details Read Display Power
53  * @return 0xA0
54 */
55 static uint8_t ST7735R_RDDPM_CMD = 0xA0;
56 
57 /**
58  * @brief RDDMADCTL command
59  * @details Read Display
60  * @return 0xB0
61 */
62 static uint8_t ST7735R_RDDMADCTL_CMD = 0xB0;
63 
64 /**
65  * @brief RDDCOLMOD command
66  * @details Read Display Pixel
67  * @return 0xC0
68 */
69 static uint8_t ST7735R_RDDCOLMOD_CMD = 0xC0;
70 
71 /**
72  * @brief RDDIM command
73  * @details Read Display Image
74  * @return 0xD0
75 */
76 static uint8_t ST7735R_RDDIM_CMD = 0xD0;
77 
78 /**
79  * @brief RDDSM command
80  * @details Read Display Signal
81  * @return 0xE0
82 */
83 static uint8_t ST7735R_RDDSM_CMD = 0xE0;
84 
85 /**
86  * @brief SLPIN command
87  * @details Sleep in & booster off
88  * @return 0x10
89 */
90 static uint8_t ST7735R_SLPIN_CMD = 0x10;
91 
92 /**
93  * @brief SLPOUT command
94  * @details Sleep out & booster on
95  * @return 0x11
96 */
97 static uint8_t ST7735R_SLPOUT_CMD = 0x11;
98 
99 /**
100  * @brief PTLON command
101  * @details Partial mode on
102  * @return 0x12
103 */
104 static uint8_t ST7735R_PTLON_CMD = 0x12;
105 
106 /**
107  * @brief NORON command
108  * @details Partial off (Normal)
109  * @return 0x13
110 */
111 static uint8_t ST7735R_NORON_CMD = 0x13;
112 
113 /**
114  * @brief INVOFF command
115  * @details Display inversion off
116  * @return 0x20
117 */
118 static uint8_t ST7735R_INVOFF_CMD = 0x20;
119 
120 /**
121  * @brief INVON command
122  * @details Display inversion on
123  * @return 0x21
124 */
125 static uint8_t ST7735R_INVON_CMD = 0x21;
126 
127 /**
128  * @brief GAMSET command
129  * @details Gamma curve select
130  * @return 0x26
131 */
132 static uint8_t ST7735R_GAMSET_CMD = 0x26;
133 
134 /**
135  * @brief DISPOFF command
136  * @details Display off
137  * @return 0x28
138 */
139 static uint8_t ST7735R_DISPOFF_CMD = 0x28;
140 
141 /**
142  * @brief DISPON command
143  * @details Display on
144  * @return 0x29
145 */
146 static uint8_t ST7735R_DISPON_CMD = 0x29;
147 
148 /**
149  * @brief CASET command
150  * @details Column address set
151  * @return 0x2A
152 */
153 static uint8_t ST7735R_CASET_CMD = 0x2A;
154 
155 /**
156  * @brief RASET command
157  * @details Row address set
158  * @return 0x2B
159 */
160 static uint8_t ST7735R_RASET_CMD = 0x2B;
161 
162 /**
163  * @brief RAMWR command
164  * @details Memory write
165  * @return 0x2C
166 */
167 static uint8_t ST7735R_RAMWR_CMD = 0x2C;
168 
169 /**
170  * @brief RGBSET command
171  * @details LUT for 4k,65k,262k color
172  * @return 0x2D
173 */
174 static uint8_t ST7735R_RGBSET_CMD = 0x2D;
175 
176 /**
177  * @brief RAMRD command
178  * @details Memory read
179  * @return 0x2E
180 */
181 static uint8_t ST7735R_RAMRD_CMD = 0x2E;
182 
183 /**
184  * @brief PTLAR command
185  * @details Partial start/end address set
186  * @return 0x30
187 */
188 static uint8_t ST7735R_PTLAR_CMD = 0x30;
189 
190 /**
191  * @brief TEOFF command
192  * @details Tearing effect line off
193  * @return 0x34
194 */
195 static uint8_t ST7735R_TEOFF_CMD = 0x34;
196 
197 /**
198  * @brief TEON command
199  * @details Tearing effect mode set & on
200  * @return 0x35
201 */
202 static uint8_t ST7735R_TEON_CMD = 0x35;
203 
204 /**
205  * @brief MADCTL command
206  * @details Memory data access control
207  * @return 0x36
208 */
209 static uint8_t ST7735R_MADCTL_CMD = 0x36;
210 
211 /**
212  * @brief IDMOFF command
213  * @details Idle mode off
214  * @return 0x38
215 */
216 static uint8_t ST7735R_IDMOFF_CMD = 0x38;
217 
218 /**
219  * @brief IDMON command
220  * @details Idle mode on
221  * @return 0x39
222 */
223 static uint8_t ST7735R_IDMON_CMD = 0x39;
224 
225 /**
226  * @brief COLMOD command
227  * @details Interface pixel format
228  * @return 0x3A
229 */
230 static uint8_t ST7735R_COLMOD_CMD = 0x3A;
231 
232 /**
233  * @brief RDID1 command
234  * @details Read ID1
235  * @return 0xDA
236 */
237 static uint8_t ST7735R_RDID1_CMD = 0xDA;
238 
239 /**
240  * @brief RDID2 command
241  * @details Read ID2
242  * @return 0xDB
243 */
244 static uint8_t ST7735R_RDID2_CMD = 0xDB;
245 
246 /**
247  * @brief RDID3 command
248  * @details Read ID3
249  * @return 0xDC
250 */
251 static uint8_t ST7735R_RDID3_CMD = 0xDC;
252 
253 /*
254  * Write to the display:
255  * - Looking at the datasheet, we have have a special 'D/CX' pin that is also
256  * confusingly called 'A0' on the LCD itself. When writing a command byte this
257  * pin needs to be 'low' or in a RESET state as it is sometimes called. When writing
258  * parameters or data to be stored in the LCD's RAM the pin must be set 'high' or in
259  * a SET state.
260  *
261 */
262 
263 struct ST7735R
264 {
265  /* SPI1 Handler */
266  SPI_HandleTypeDef *SPI_Handler;
267 };
268 
269 typedef int ST7735R_Return;
270 
271 /**
272  * @brief Set SPI1 CS pin
273  * @param Void
274  * @return Void N/A
275 */
276 void ST7735R_CS_High(void);
277 
278 /**
279  * @brief Bring low SPI1 CS pin
280  * @param Void
281  * @return Void N/A
282 */
283 void ST7735R_CS_Low(void);
284 
285 /**
286  * @brief Write command on device
287  * @param cmd what command to write to
288  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
289  */
290 ST7735R_Return ST7735R_Write_Command(struct ST7735R *self, uint8_t cmd);
291 
292 /**
293  * @brief Write data to RAM on device
294  * @param data what command to write to
295  * @param size size of data buffer
296  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
297  */
298 ST7735R_Return ST7735R_Write_Data(struct ST7735R *self, uint8_t *data, uint8_t size);
299 
300 /**
301  * @brief Turn backlight off
302  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
303  */
305 
306 #endif /* ST7735R_H */
ST7735R_Return ST7735R_Write_Data(struct ST7735R *self, uint8_t *data, uint8_t size)
Write data to RAM on device.
Definition: st7735r.c:56
static uint8_t ST7735R_DISPOFF_CMD
DISPOFF command.
Definition: st7735r.h:139
static uint8_t ST7735R_RASET_CMD
RASET command.
Definition: st7735r.h:160
static uint8_t ST7735R_RDID2_CMD
RDID2 command.
Definition: st7735r.h:244
static uint8_t ST7735R_TEON_CMD
TEON command.
Definition: st7735r.h:202
static uint8_t ST7735R_SLPOUT_CMD
SLPOUT command.
Definition: st7735r.h:97
void ST7735R_CS_Low(void)
Bring low SPI1 CS pin.
Definition: st7735r.c:26
static uint8_t ST7735R_PTLAR_CMD
PTLAR command.
Definition: st7735r.h:188
static uint8_t ST7735R_CASET_CMD
CASET command.
Definition: st7735r.h:153
static uint8_t ST7735R_RDDSM_CMD
RDDSM command.
Definition: st7735r.h:83
static uint8_t ST7735R_INVON_CMD
INVON command.
Definition: st7735r.h:125
int ST7735R_Return
Definition: st7735r.h:269
static uint8_t ST7735R_INVOFF_CMD
INVOFF command.
Definition: st7735r.h:118
static uint8_t ST7735R_RGBSET_CMD
RGBSET command.
Definition: st7735r.h:174
static uint8_t ST7735R_RDDPM_CMD
RDDPM command.
Definition: st7735r.h:55
static uint8_t ST7735R_DISPON_CMD
DISPON command.
Definition: st7735r.h:146
static uint8_t ST7735R_NOP_CMD
NOP command.
Definition: st7735r.h:27
static uint8_t ST7735R_RDDCOLMOD_CMD
RDDCOLMOD command.
Definition: st7735r.h:69
static uint8_t ST7735R_NORON_CMD
NORON command.
Definition: st7735r.h:111
ST7735R_Return ST7735R_Backlight_Off(struct ST7735R *self)
Turn backlight off.
Definition: st7735r.c:74
static uint8_t ST7735R_COLMOD_CMD
COLMOD command.
Definition: st7735r.h:230
static uint8_t ST7735R_RDDID_CMD
RDDID command.
Definition: st7735r.h:41
static uint8_t ST7735R_IDMOFF_CMD
IDMOFF command.
Definition: st7735r.h:216
ST7735R_Return ST7735R_Write_Command(struct ST7735R *self, uint8_t cmd)
Write command on device.
Definition: st7735r.c:36
static uint8_t ST7735R_PTLON_CMD
PTLON command.
Definition: st7735r.h:104
static uint8_t ST7735R_SWRESET_CMD
SWRESET command.
Definition: st7735r.h:34
static uint8_t ST7735R_RAMWR_CMD
RAMWR command.
Definition: st7735r.h:167
static uint8_t ST7735R_RDDST_CMD
RDDST command.
Definition: st7735r.h:48
static uint8_t ST7735R_SLPIN_CMD
SLPIN command.
Definition: st7735r.h:90
SPI_HandleTypeDef * SPI_Handler
Definition: st7735r.h:266
static uint8_t ST7735R_RDDIM_CMD
RDDIM command.
Definition: st7735r.h:76
void ST7735R_CS_High(void)
Set SPI1 CS pin.
Definition: st7735r.c:16
static uint8_t ST7735R_RDID3_CMD
RDID3 command.
Definition: st7735r.h:251
static uint8_t ST7735R_MADCTL_CMD
MADCTL command.
Definition: st7735r.h:209
static uint8_t ST7735R_RAMRD_CMD
RAMRD command.
Definition: st7735r.h:181
static uint8_t ST7735R_GAMSET_CMD
GAMSET command.
Definition: st7735r.h:132
static uint8_t ST7735R_IDMON_CMD
IDMON command.
Definition: st7735r.h:223
static uint8_t ST7735R_RDID1_CMD
RDID1 command.
Definition: st7735r.h:237
static uint8_t ST7735R_TEOFF_CMD
TEOFF command.
Definition: st7735r.h:195
static uint8_t ST7735R_RDDMADCTL_CMD
RDDMADCTL command.
Definition: st7735r.h:62