Select one of the symbols to view example projects that use it.
 
Outline
#include "st7735.h"
st7735_drv
ArrayRGB
st7735_Init()
st7735_DisplayOn()
st7735_DisplayOff()
st7735_SetCursor(uint16_t, uint16_t)
st7735_WritePixel(uint16_t, uint16_t, uint16_t)
st7735_WriteReg(uint8_t, uint8_t)
st7735_SetDisplayWindow(uint16_t, uint16_t, uint16_t, uint16_t)
st7735_DrawHLine(uint16_t, uint16_t, uint16_t, uint16_t)
st7735_DrawVLine(uint16_t, uint16_t, uint16_t, uint16_t)
st7735_GetLcdPixelWidth()
st7735_GetLcdPixelHeight()
st7735_DrawBitmap(uint16_t, uint16_t, uint8_t *)
Files
loading...
CodeScopeSTM32 Libraries and Samplesst7735st7735.c
 
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file st7735.c * @author MCD Application Team * @brief This file includes the driver for ST7735 LCD mounted on the Adafruit * 1.8" TFT LCD shield (reference ID 802). ****************************************************************************** * @attention * * Copyright (c) 2014 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "st7735.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup Components * @{ *//* ... */ /** @addtogroup ST7735 * @brief This file provides a set of functions needed to drive the * ST7735 LCD. * @{ *//* ... */ /** @defgroup ST7735_Private_TypesDefinitions * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup ST7735_Private_Defines * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup ST7735_Private_Macros * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup ST7735_Private_Variables * @{ *//* ... */ LCD_DrvTypeDef st7735_drv = { st7735_Init, 0, st7735_DisplayOn, st7735_DisplayOff, st7735_SetCursor, st7735_WritePixel, 0, st7735_SetDisplayWindow, st7735_DrawHLine, st7735_DrawVLine, st7735_GetLcdPixelWidth, st7735_GetLcdPixelHeight, st7735_DrawBitmap, ...}; static uint16_t ArrayRGB[320] = {0}; /** * @} *//* ... */ /** @defgroup ST7735_Private_FunctionPrototypes * @{ *//* ... */ /** * @} *//* ... */ /** @defgroup ST7735_Private_Functions * @{ *//* ... */ /** * @brief Initialize the ST7735 LCD Component. * @param None * @retval None *//* ... */ void st7735_Init(void) { uint8_t data = 0; /* Initialize ST7735 low level bus layer -----------------------------------*/ LCD_IO_Init(); /* Out of sleep mode, 0 args, no delay */ st7735_WriteReg(LCD_REG_17, 0x00); /* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/ LCD_IO_WriteReg(LCD_REG_177); data = 0x01; LCD_IO_WriteMultipleData(&data, 1); data = 0x2C; LCD_IO_WriteMultipleData(&data, 1); data = 0x2D; LCD_IO_WriteMultipleData(&data, 1); /* Frame rate control - idle mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D) */ st7735_WriteReg(LCD_REG_178, 0x01); st7735_WriteReg(LCD_REG_178, 0x2C); st7735_WriteReg(LCD_REG_178, 0x2D); /* Frame rate ctrl - partial mode, 6 args: Dot inversion mode, Line inversion mode */ st7735_WriteReg(LCD_REG_179, 0x01); st7735_WriteReg(LCD_REG_179, 0x2C); st7735_WriteReg(LCD_REG_179, 0x2D); st7735_WriteReg(LCD_REG_179, 0x01); st7735_WriteReg(LCD_REG_179, 0x2C); st7735_WriteReg(LCD_REG_179, 0x2D); /* Display inversion ctrl, 1 arg, no delay: No inversion */ st7735_WriteReg(LCD_REG_180, 0x07); /* Power control, 3 args, no delay: -4.6V , AUTO mode */ st7735_WriteReg(LCD_REG_192, 0xA2); st7735_WriteReg(LCD_REG_192, 0x02); st7735_WriteReg(LCD_REG_192, 0x84); /* Power control, 1 arg, no delay: VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */ st7735_WriteReg(LCD_REG_193, 0xC5); /* Power control, 2 args, no delay: Opamp current small, Boost frequency */ st7735_WriteReg(LCD_REG_194, 0x0A); st7735_WriteReg(LCD_REG_194, 0x00); /* Power control, 2 args, no delay: BCLK/2, Opamp current small & Medium low */ st7735_WriteReg(LCD_REG_195, 0x8A); st7735_WriteReg(LCD_REG_195, 0x2A); /* Power control, 2 args, no delay */ st7735_WriteReg(LCD_REG_196, 0x8A); st7735_WriteReg(LCD_REG_196, 0xEE); /* Power control, 1 arg, no delay */ st7735_WriteReg(LCD_REG_197, 0x0E); /* Don't invert display, no args, no delay */ LCD_IO_WriteReg(LCD_REG_32); /* Set color mode, 1 arg, no delay: 16-bit color */ st7735_WriteReg(LCD_REG_58, 0x05); /* Column addr set, 4 args, no delay: XSTART = 0, XEND = 127 */ LCD_IO_WriteReg(LCD_REG_42); data = 0x00; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); data = 0x7F; LCD_IO_WriteMultipleData(&data, 1); /* Row addr set, 4 args, no delay: YSTART = 0, YEND = 159 */ LCD_IO_WriteReg(LCD_REG_43); data = 0x00; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteMultipleData(&data, 1); data = 0x9F; LCD_IO_WriteMultipleData(&data, 1); /* Magical unicorn dust, 16 args, no delay */ st7735_WriteReg(LCD_REG_224, 0x02); st7735_WriteReg(LCD_REG_224, 0x1c); st7735_WriteReg(LCD_REG_224, 0x07); st7735_WriteReg(LCD_REG_224, 0x12); st7735_WriteReg(LCD_REG_224, 0x37); st7735_WriteReg(LCD_REG_224, 0x32); st7735_WriteReg(LCD_REG_224, 0x29); st7735_WriteReg(LCD_REG_224, 0x2d); st7735_WriteReg(LCD_REG_224, 0x29); st7735_WriteReg(LCD_REG_224, 0x25); st7735_WriteReg(LCD_REG_224, 0x2B); st7735_WriteReg(LCD_REG_224, 0x39); st7735_WriteReg(LCD_REG_224, 0x00); st7735_WriteReg(LCD_REG_224, 0x01); st7735_WriteReg(LCD_REG_224, 0x03); st7735_WriteReg(LCD_REG_224, 0x10); /* Sparkles and rainbows, 16 args, no delay */ st7735_WriteReg(LCD_REG_225, 0x03); st7735_WriteReg(LCD_REG_225, 0x1d); st7735_WriteReg(LCD_REG_225, 0x07); st7735_WriteReg(LCD_REG_225, 0x06); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x2C); st7735_WriteReg(LCD_REG_225, 0x29); st7735_WriteReg(LCD_REG_225, 0x2D); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x2E); st7735_WriteReg(LCD_REG_225, 0x37); st7735_WriteReg(LCD_REG_225, 0x3F); st7735_WriteReg(LCD_REG_225, 0x00); st7735_WriteReg(LCD_REG_225, 0x00); st7735_WriteReg(LCD_REG_225, 0x02); st7735_WriteReg(LCD_REG_225, 0x10); /* Normal display on, no args, no delay */ st7735_WriteReg(LCD_REG_19, 0x00); /* Main screen turn on, no delay */ st7735_WriteReg(LCD_REG_41, 0x00); /* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */ st7735_WriteReg(LCD_REG_54, 0xC0); }{ ... } /** * @brief Enables the Display. * @param None * @retval None *//* ... */ void st7735_DisplayOn(void) { uint8_t data = 0; LCD_IO_WriteReg(LCD_REG_19); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_41); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_54); data = 0xC0; LCD_IO_WriteMultipleData(&data, 1); }{ ... } /** * @brief Disables the Display. * @param None * @retval None *//* ... */ void st7735_DisplayOff(void) { uint8_t data = 0; LCD_IO_WriteReg(LCD_REG_19); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_40); LCD_Delay(10); LCD_IO_WriteReg(LCD_REG_54); data = 0xC0; LCD_IO_WriteMultipleData(&data, 1); }{ ... } /** * @brief Sets Cursor position. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @retval None *//* ... */ void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos) { uint8_t data = 0; LCD_IO_WriteReg(LCD_REG_42); data = (Xpos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteReg(LCD_REG_43); data = (Ypos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); LCD_IO_WriteReg(LCD_REG_44); }{ ... } /** * @brief Writes pixel. * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param RGBCode: the RGB pixel color * @retval None *//* ... */ void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode) { uint8_t data = 0; if((Xpos >= ST7735_LCD_PIXEL_WIDTH) || (Ypos >= ST7735_LCD_PIXEL_HEIGHT)) { return; }if ((Xpos >= ST7735_LCD_PIXEL_WIDTH) || (Ypos >= ST7735_LCD_PIXEL_HEIGHT)) { ... } /* Set Cursor */ st7735_SetCursor(Xpos, Ypos); data = RGBCode >> 8; LCD_IO_WriteMultipleData(&data, 1); data = RGBCode; LCD_IO_WriteMultipleData(&data, 1); }{ ... } /** * @brief Writes to the selected LCD register. * @param LCDReg: Address of the selected register. * @param LCDRegValue: value to write to the selected register. * @retval None *//* ... */ void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue) { LCD_IO_WriteReg(LCDReg); LCD_IO_WriteMultipleData(&LCDRegValue, 1); }{ ... } /** * @brief Sets a display window * @param Xpos: specifies the X bottom left position. * @param Ypos: specifies the Y bottom left position. * @param Height: display window height. * @param Width: display window width. * @retval None *//* ... */ void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) { uint8_t data = 0; /* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */ LCD_IO_WriteReg(LCD_REG_42); data = (Xpos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos + Width - 1) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Xpos + Width - 1) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); /* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */ LCD_IO_WriteReg(LCD_REG_43); data = (Ypos) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos + Height - 1) >> 8; LCD_IO_WriteMultipleData(&data, 1); data = (Ypos + Height - 1) & 0xFF; LCD_IO_WriteMultipleData(&data, 1); }{ ... } /** * @brief Draws horizontal line. * @param RGBCode: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the line length. * @retval None *//* ... */ void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint8_t counter = 0; if(Xpos + Length > ST7735_LCD_PIXEL_WIDTH) return; /* Set Cursor */ st7735_SetCursor(Xpos, Ypos); for(counter = 0; counter < Length; counter++) { ArrayRGB[counter] = RGBCode; }for (counter = 0; counter < Length; counter++) { ... } LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2); }{ ... } /** * @brief Draws vertical line. * @param RGBCode: Specifies the RGB color * @param Xpos: specifies the X position. * @param Ypos: specifies the Y position. * @param Length: specifies the line length. * @retval None *//* ... */ void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length) { uint8_t counter = 0; if(Ypos + Length > ST7735_LCD_PIXEL_HEIGHT) return; for(counter = 0; counter < Length; counter++) { st7735_WritePixel(Xpos, Ypos + counter, RGBCode); }for (counter = 0; counter < Length; counter++) { ... } }{ ... } /** * @brief Gets the LCD pixel Width. * @param None * @retval The Lcd Pixel Width *//* ... */ uint16_t st7735_GetLcdPixelWidth(void) { return ST7735_LCD_PIXEL_WIDTH; }{ ... } /** * @brief Gets the LCD pixel Height. * @param None * @retval The Lcd Pixel Height *//* ... */ uint16_t st7735_GetLcdPixelHeight(void) { return ST7735_LCD_PIXEL_HEIGHT; }{ ... } /** * @brief Displays a bitmap picture loaded in the internal Flash. * @param BmpAddress: Bmp picture address in the internal Flash. * @retval None *//* ... */ void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp) { uint32_t index = 0, size = 0; /* Read bitmap size */ size = *(volatile uint16_t *) (pbmp + 2); size |= (*(volatile uint16_t *) (pbmp + 4)) << 16; /* Get bitmap data address offset */ index = *(volatile uint16_t *) (pbmp + 10); index |= (*(volatile uint16_t *) (pbmp + 12)) << 16; size = (size - index)/2; pbmp += index; /* Set GRAM write direction and BGR = 0 */ /* Memory access control: MY = 0, MX = 1, MV = 0, ML = 0 */ st7735_WriteReg(LCD_REG_54, 0x40); /* Set Cursor */ st7735_SetCursor(Xpos, Ypos); LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*2); /* Set GRAM write direction and BGR = 0 */ /* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */ st7735_WriteReg(LCD_REG_54, 0xC0); }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */