STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
st7735.c
Go to the documentation of this file.
1 
39 /* Includes ------------------------------------------------------------------*/
40 #include "st7735.h"
41 
86 {
88  0,
93  0,
100 };
101 
102 static uint16_t ArrayRGB[320] = {0};
103 
125 void st7735_Init(void)
126 {
127  uint8_t data = 0;
128 
129  /* Initialize ST7735 low level bus layer -----------------------------------*/
130  LCD_IO_Init();
131  /* Out of sleep mode, 0 args, no delay */
132  st7735_WriteReg(LCD_REG_17, 0x00);
133  /* Frame rate ctrl - normal mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D)*/
135  data = 0x01;
136  LCD_IO_WriteMultipleData(&data, 1);
137  data = 0x2C;
138  LCD_IO_WriteMultipleData(&data, 1);
139  data = 0x2D;
140  LCD_IO_WriteMultipleData(&data, 1);
141  /* Frame rate control - idle mode, 3 args:Rate = fosc/(1x2+40) * (LINE+2C+2D) */
145  /* Frame rate ctrl - partial mode, 6 args: Dot inversion mode, Line inversion mode */
152  /* Display inversion ctrl, 1 arg, no delay: No inversion */
154  /* Power control, 3 args, no delay: -4.6V , AUTO mode */
158  /* Power control, 1 arg, no delay: VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD */
160  /* Power control, 2 args, no delay: Opamp current small, Boost frequency */
163  /* Power control, 2 args, no delay: BCLK/2, Opamp current small & Medium low */
166  /* Power control, 2 args, no delay */
169  /* Power control, 1 arg, no delay */
171  /* Don't invert display, no args, no delay */
173  /* Set color mode, 1 arg, no delay: 16-bit color */
175  /* Column addr set, 4 args, no delay: XSTART = 0, XEND = 127 */
177  data = 0x00;
178  LCD_IO_WriteMultipleData(&data, 1);
179  LCD_IO_WriteMultipleData(&data, 1);
180  LCD_IO_WriteMultipleData(&data, 1);
181  data = 0x7F;
182  LCD_IO_WriteMultipleData(&data, 1);
183  /* Row addr set, 4 args, no delay: YSTART = 0, YEND = 159 */
185  data = 0x00;
186  LCD_IO_WriteMultipleData(&data, 1);
187  LCD_IO_WriteMultipleData(&data, 1);
188  LCD_IO_WriteMultipleData(&data, 1);
189  data = 0x9F;
190  LCD_IO_WriteMultipleData(&data, 1);
191  /* Magical unicorn dust, 16 args, no delay */
208  /* Sparkles and rainbows, 16 args, no delay */
225  /* Normal display on, no args, no delay */
227  /* Main screen turn on, no delay */
229  /* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
231 }
232 
239 {
240  uint8_t data = 0;
242  LCD_Delay(10);
244  LCD_Delay(10);
246  data = 0xC0;
247  LCD_IO_WriteMultipleData(&data, 1);
248 }
249 
256 {
257  uint8_t data = 0;
259  LCD_Delay(10);
261  LCD_Delay(10);
263  data = 0xC0;
264  LCD_IO_WriteMultipleData(&data, 1);
265 }
266 
273 void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos)
274 {
275  uint8_t data = 0;
277  data = (Xpos) >> 8;
278  LCD_IO_WriteMultipleData(&data, 1);
279  data = (Xpos) & 0xFF;
280  LCD_IO_WriteMultipleData(&data, 1);
282  data = (Ypos) >> 8;
283  LCD_IO_WriteMultipleData(&data, 1);
284  data = (Ypos) & 0xFF;
285  LCD_IO_WriteMultipleData(&data, 1);
287 }
288 
296 void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
297 {
298  uint8_t data = 0;
299  if((Xpos >= ST7735_LCD_PIXEL_WIDTH) || (Ypos >= ST7735_LCD_PIXEL_HEIGHT))
300  {
301  return;
302  }
303 
304  /* Set Cursor */
305  st7735_SetCursor(Xpos, Ypos);
306 
307  data = RGBCode >> 8;
308  LCD_IO_WriteMultipleData(&data, 1);
309  data = RGBCode;
310  LCD_IO_WriteMultipleData(&data, 1);
311 }
312 
313 
320 void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue)
321 {
322  LCD_IO_WriteReg(LCDReg);
323  LCD_IO_WriteMultipleData(&LCDRegValue, 1);
324 }
325 
334 void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
335 {
336  uint8_t data = 0;
337  /* Column addr set, 4 args, no delay: XSTART = Xpos, XEND = (Xpos + Width - 1) */
339  data = (Xpos) >> 8;
340  LCD_IO_WriteMultipleData(&data, 1);
341  data = (Xpos) & 0xFF;
342  LCD_IO_WriteMultipleData(&data, 1);
343  data = (Xpos + Width - 1) >> 8;
344  LCD_IO_WriteMultipleData(&data, 1);
345  data = (Xpos + Width - 1) & 0xFF;
346  LCD_IO_WriteMultipleData(&data, 1);
347  /* Row addr set, 4 args, no delay: YSTART = Ypos, YEND = (Ypos + Height - 1) */
349  data = (Ypos) >> 8;
350  LCD_IO_WriteMultipleData(&data, 1);
351  data = (Ypos) & 0xFF;
352  LCD_IO_WriteMultipleData(&data, 1);
353  data = (Ypos + Height - 1) >> 8;
354  LCD_IO_WriteMultipleData(&data, 1);
355  data = (Ypos + Height - 1) & 0xFF;
356  LCD_IO_WriteMultipleData(&data, 1);
357 }
358 
367 void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
368 {
369  uint8_t counter = 0;
370 
371  if(Xpos + Length > ST7735_LCD_PIXEL_WIDTH) return;
372 
373  /* Set Cursor */
374  st7735_SetCursor(Xpos, Ypos);
375 
376  for(counter = 0; counter < Length; counter++)
377  {
378  ArrayRGB[counter] = RGBCode;
379  }
380  LCD_IO_WriteMultipleData((uint8_t*)&ArrayRGB[0], Length * 2);
381 }
382 
391 void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
392 {
393  uint8_t counter = 0;
394 
395  if(Ypos + Length > ST7735_LCD_PIXEL_HEIGHT) return;
396  for(counter = 0; counter < Length; counter++)
397  {
398  st7735_WritePixel(Xpos, Ypos + counter, RGBCode);
399  }
400 }
401 
408 {
409  return ST7735_LCD_PIXEL_WIDTH;
410 }
411 
418 {
420 }
421 
427 void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
428 {
429  uint32_t index = 0, size = 0;
430 
431  /* Read bitmap size */
432  size = *(volatile uint16_t *) (pbmp + 2);
433  size |= (*(volatile uint16_t *) (pbmp + 4)) << 16;
434  /* Get bitmap data address offset */
435  index = *(volatile uint16_t *) (pbmp + 10);
436  index |= (*(volatile uint16_t *) (pbmp + 12)) << 16;
437  size = (size - index)/2;
438  pbmp += index;
439 
440  /* Set GRAM write direction and BGR = 0 */
441  /* Memory access control: MY = 0, MX = 1, MV = 0, ML = 0 */
443 
444  /* Set Cursor */
445  st7735_SetCursor(Xpos, Ypos);
446 
447  LCD_IO_WriteMultipleData((uint8_t*)pbmp, size*2);
448 
449  /* Set GRAM write direction and BGR = 0 */
450  /* Memory access control: MY = 1, MX = 1, MV = 0, ML = 0 */
452 }
453 
470 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
471 
#define LCD_REG_42
Definition: st7735.h:101
#define LCD_REG_17
Definition: st7735.h:93
#define LCD_REG_178
Definition: st7735.h:114
#define LCD_REG_54
Definition: st7735.h:109
#define ST7735_LCD_PIXEL_WIDTH
ST7735 Size.
Definition: st7735.h:77
#define LCD_REG_180
Definition: st7735.h:116
void st7735_DisplayOff(void)
Disables the Display.
Definition: st7735.c:255
void st7735_Init(void)
Initialize the ST7735 LCD Component.
Definition: st7735.c:125
uint16_t st7735_GetLcdPixelWidth(void)
Gets the LCD pixel Width.
Definition: st7735.c:407
void st7735_DisplayOn(void)
Enables the Display.
Definition: st7735.c:238
#define LCD_REG_224
Definition: st7735.h:132
void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size)
void LCD_Delay(uint32_t delay)
void st7735_WritePixel(uint16_t Xpos, uint16_t Ypos, uint16_t RGBCode)
Writes pixel.
Definition: st7735.c:296
This file contains all the functions prototypes for the st7735.c driver.
void st7735_DrawBitmap(uint16_t Xpos, uint16_t Ypos, uint8_t *pbmp)
Displays a bitmap picture loaded in the internal Flash.
Definition: st7735.c:427
#define LCD_REG_41
Definition: st7735.h:100
#define LCD_REG_177
Definition: st7735.h:113
#define LCD_REG_192
Definition: st7735.h:117
LCD_DrvTypeDef st7735_drv
Definition: st7735.c:85
#define LCD_REG_179
Definition: st7735.h:115
#define LCD_REG_225
Definition: st7735.h:133
void st7735_DrawHLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Draws horizontal line.
Definition: st7735.c:367
#define ST7735_LCD_PIXEL_HEIGHT
Definition: st7735.h:78
#define LCD_REG_19
Definition: st7735.h:95
#define LCD_REG_193
Definition: st7735.h:118
void LCD_IO_WriteReg(uint8_t Reg)
void st7735_DrawVLine(uint16_t RGBCode, uint16_t Xpos, uint16_t Ypos, uint16_t Length)
Draws vertical line.
Definition: st7735.c:391
uint16_t st7735_GetLcdPixelHeight(void)
Gets the LCD pixel Height.
Definition: st7735.c:417
#define LCD_REG_195
Definition: st7735.h:120
#define LCD_REG_196
Definition: st7735.h:121
#define LCD_REG_197
Definition: st7735.h:122
#define LCD_REG_44
Definition: st7735.h:103
void st7735_SetCursor(uint16_t Xpos, uint16_t Ypos)
Sets Cursor position.
Definition: st7735.c:273
void st7735_WriteReg(uint8_t LCDReg, uint8_t LCDRegValue)
Writes to the selected LCD register.
Definition: st7735.c:320
#define LCD_REG_40
Definition: st7735.h:99
void st7735_SetDisplayWindow(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
Sets a display window.
Definition: st7735.c:334
#define LCD_REG_58
Definition: st7735.h:112
void LCD_IO_Init(void)
#define LCD_REG_43
Definition: st7735.h:102
#define LCD_REG_194
Definition: st7735.h:119
#define LCD_REG_32
Definition: st7735.h:96