-
Notifications
You must be signed in to change notification settings - Fork 18
/
hx8347g.cpp
139 lines (122 loc) · 4.42 KB
/
hx8347g.cpp
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
// IMPORTANT: LIBRARY MUST BE SPECIFICALLY CONFIGURED FOR EITHER TFT SHIELD
// OR BREAKOUT BOARD USAGE. SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h
// Graphics library by ladyada/adafruit with init code from Rossum
// MIT license
#include "Adafruit_TFTLCD_8bit_STM32.h"
//#include "pin_magic.h"
#include "hx8347g.h"
/*****************************************************************************/
static const uint8_t HX8347G_regValues[] PROGMEM = {
0x2E , 0x89,
0x29 , 0x8F,
0x2B , 0x02,
0xE2 , 0x00,
0xE4 , 0x01,
0xE5 , 0x10,
0xE6 , 0x01,
0xE7 , 0x10,
0xE8 , 0x70,
0xF2 , 0x00,
0xEA , 0x00,
0xEB , 0x20,
0xEC , 0x3C,
0xED , 0xC8,
0xE9 , 0x38,
0xF1 , 0x01,
// skip gamma, do later
0x1B , 0x1A,
0x1A , 0x02,
0x24 , 0x61,
0x25 , 0x5C,
0x18 , 0x36,
0x19 , 0x01,
0x1F , 0x88,
TFTLCD_DELAY , 5 , // delay 5 ms
0x1F , 0x80,
TFTLCD_DELAY , 5 ,
0x1F , 0x90,
TFTLCD_DELAY , 5 ,
0x1F , 0xD4,
TFTLCD_DELAY , 5 ,
0x17 , 0x05,
0x36 , 0x09,
0x28 , 0x38,
TFTLCD_DELAY , 40 ,
0x28 , 0x3C,
0x02 , 0x00,
0x03 , 0x00,
0x04 , 0x00,
0x05 , 0xEF,
0x06 , 0x00,
0x07 , 0x00,
0x08 , 0x01,
0x09 , 0x3F
};
/*****************************************************************************/
// Unlike the 932X drivers that set the address window to the full screen
// by default (using the address counter for drawPixel operations), the
// 7575 needs the address window set on all graphics operations. In order
// to save a few register writes on each pixel drawn, the lower-right
// corner of the address window is reset after most fill operations, so
// that drawPixel only needs to change the upper left each time.
/*****************************************************************************/
void hx8347g_setLR(void)
{
writeRegisterPair(HX8347G_COLADDREND_HI, HX8347G_COLADDREND_LO, TFTWIDTH - 1);
writeRegisterPair(HX8347G_ROWADDREND_HI, HX8347G_ROWADDREND_LO, TFTHEIGHT - 1);
}
/*****************************************************************************/
void hx8347g_begin(void)
{
uint8_t a, d, i = 0;
CS_ACTIVE;
while(i < sizeof(HX8347G_regValues)) {
a = pgm_read_byte(&HX8347G_regValues[i++]);
d = pgm_read_byte(&HX8347G_regValues[i++]);
if(a == TFTLCD_DELAY) delay(d);
else writeRegister8(a, d);
}
hx8347g_setRotation(0);
hx8347g_setLR(); // Lower-right corner of address window
}
/*****************************************************************************/
// Sets the LCD address window (and address counter, on 932X).
// Relevant to rect/screen fills and H/V lines. Input coordinates are
// assumed pre-sorted (e.g. x2 >= x1).
/*****************************************************************************/
void hx8347g_setAddrWindow(int x1, int y1, int x2, int y2)
{
writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x1);
writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y1);
writeRegisterPair(HX8347G_COLADDREND_HI , HX8347G_COLADDREND_LO , x2);
writeRegisterPair(HX8347G_ROWADDREND_HI , HX8347G_ROWADDREND_LO , y2);
}
/*****************************************************************************/
void hx8347g_fillScreen(uint16_t color)
{
}
/*****************************************************************************/
void hx8347g_drawPixel(int16_t x, int16_t y, uint16_t color)
{
}
/*****************************************************************************/
void hx8347g_setRotation(uint8_t x)
{
uint8_t t;
switch(x) {
default: t = 0 ; break;
case 1 : t = 0x60; break;
case 2 : t = 0xc0; break;
case 3 : t = 0xa0; break;
}
writeRegister8(HX8347G_MEMACCESS, t);
// 7575 has to set the address window on most drawing operations.
// drawPixel() cheats by setting only the top left...by default,
// the lower right is always reset to the corner.
hx8347g_setLR(); // CS_IDLE happens here
}
/*****************************************************************************/
uint16_t hx8347g_readPixel(int16_t x, int16_t y)
{
return 0;
}