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
|
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
/* RA6963 Driver
* Pinout:
* Version 1:
* 1 - Vee Negative Voltage Output
* 2 - GND GND
* 3 - +5V
* 4 - Vo LCD Driver Supply (10-20k Pot between +5V and Vee)
* 5 - /WR Write (Low active)
* 6 - /RD Read (Low active)
* 7 - /CE Chip Enable (Low active)
* 8 - C/D Command or Data
* 9 - /RST Reset (Low active)
* 10..17 - D0..7
* 18 - FS Font Select
* 19 - A Backlight Anode (~4.3V)
* 20 - K Backlight Cathode (GND)
*/
#ifndef _GDISP_LLD_BOARD_H
#define _GDISP_LLD_BOARD_H
// My Settings
#define RA6963_NEED_READ GFXOFF //works, but is very slow!
#define RA6963_HAS_RESET GFXOFF
#define RA6963_NEED_FONT_SELECT GFXOFF
#define RA6963_NEED_BACKLIGHT GFXOFF
#define RA6963_NEED_PWMBACKLIGHT GFXOFF
#define GDISP_SCREEN_HEIGHT 64
#define GDISP_SCREEN_WIDTH 128
#define GDISP_INITIAL_CONTRAST 50
#define GDISP_INITIAL_BACKLIGHT 100
#define RA6963_delay(n) {asm("nop");asm("nop");asm("nop");asm("nop");}
#define LINE_WR PAL_LINE(GPIOB, 8U)
#if RA6963_NEED_READ
#define LINE_RD PAL_LINE(GPIOB, 9U)
#endif
#define LINE_CE PAL_LINE(GPIOB, 10U)
#define LINE_CD PAL_LINE(GPIOB, 11U)
#if RA6963_HAS_RESET
#define LINE_RST PAL_LINE(GPIOB, 12U)
#endif
#define LINE_D0 PAL_LINE(GPIOB, 0U)
#define LINE_D1 PAL_LINE(GPIOB, 1U)
#define LINE_D2 PAL_LINE(GPIOB, 2U)
#define LINE_D3 PAL_LINE(GPIOB, 3U)
#define LINE_D4 PAL_LINE(GPIOB, 4U)
#define LINE_D5 PAL_LINE(GPIOB, 5U)
#define LINE_D6 PAL_LINE(GPIOB, 6U)
#define LINE_D7 PAL_LINE(GPIOB, 7U)
#if RA6963_NEED_FONT_SELECT
#define LINE_FS PAL_LINE(GPIOA, 13U)
#endif
#if RA6963_NEED_BACKLIGHT
#define LINE_BL PAL_LINE(GPIOA, 14U)
#endif
typedef struct {
ioline_t WR; //Write PIN
#if RA6963_NEED_READ
ioline_t RD; //Read PIN (tie to +5V if not needed)
#endif
ioline_t CE; //Chip Enable PIN
ioline_t CD; //Command/Data Select PIN
#if RA6963_HAS_RESET
ioline_t RST; //Reset PIN (tie to +5V if not needed)
#endif
ioline_t D[8]; //Data PINs
#if RA6963_NEED_BACKLIGHT
ioline_t BL; //Backlight PIN
#endif
#if RA6963_NEED_FONT_SELECT
ioline_t FS; //Font Select PIN (tie to GND if not needed)
#endif
} lcd_pins_t;
/*===========================================================================*/
/* Driver local variables. */
/*===========================================================================*/
static const lcd_pins_t lcdpins = {
LINE_WR,
#if RA6963_NEED_READ
LINE_RD,
#endif
LINE_CE,
LINE_CD,
#if RA6963_HAS_RESET
LINE_RST,
#endif
{
LINE_D0,
LINE_D1,
LINE_D2,
LINE_D3,
LINE_D4,
LINE_D5,
LINE_D6,
LINE_D7
},
#if RA6963_NEED_BACKLIGHT
LINE_BL,
#endif
#if RA6963_NEED_FONT_SELECT
LINE_FS,
#endif
};
static GFXINLINE void init_board(GDisplay* g){
(void) g;
g->board = 0;
int ii;
//################################DEBUG#######################################
#define DEB13_ON palClearLine(PAL_LINE(GPIOB, 13U))
#define DEB13_OFF palSetLine(PAL_LINE(GPIOB, 13U))
#define DEB14_ON palClearLine(PAL_LINE(GPIOB, 14U))
#define DEB14_OFF palSetLine(PAL_LINE(GPIOB, 14U))
palSetLineMode(PAL_LINE(GPIOB, 13U), PAL_MODE_OUTPUT_PUSHPULL);
DEB13_OFF;
palSetLineMode(PAL_LINE(GPIOB, 14U), PAL_MODE_OUTPUT_PUSHPULL);
DEB14_OFF;
//################################DEBUG#######################################
palSetLineMode(lcdpins.WR, PAL_MODE_OUTPUT_PUSHPULL);
palSetLine(lcdpins.WR);
#if RA6963_NEED_READ
palSetLineMode(lcdpins.RD, PAL_MODE_OUTPUT_PUSHPULL);
palSetLine(lcdpins.RD);
#endif
palSetLineMode(lcdpins.CE, PAL_MODE_OUTPUT_PUSHPULL);
palSetLine(lcdpins.CE);
palSetLineMode(lcdpins.CD, PAL_MODE_OUTPUT_PUSHPULL);
palSetLine(lcdpins.CD);
#if RA6963_HAS_RESET
palSetLine(lcdpins.RST);
palSetLineMode(lcdpins.RST, PAL_MODE_OUTPUT_PUSHPULL);
#endif
for(ii = 0; ii < 8; ii++) {
palSetLineMode(lcdpins.D[ii], PAL_MODE_OUTPUT_PUSHPULL);
palClearLine(lcdpins.D[ii]);
}
#if RA6963_NEED_BACKLIGHT
#if RA6963_NEED_PWMBACKLIGHT
palSetLineMode(lcdpins.BL, PAL_MODE_ALTERNATE(1));
#else
palSetLineMode(lcdpins.BL, PAL_MODE_OUTPUT_PUSHPULL);
#endif
#endif
#if RA6963_NEED_FONT_SELECT
palSetLineMode(lcdpins.FS, PAL_MODE_OUTPUT_PUSHPULL);
palSetLine(lcdpins.FS);
#endif
}
static GFXINLINE void post_init_board(GDisplay *g) {
(void) g;
}
static GFXINLINE void setpin_reset(GDisplay *g, gBool state) {
(void) g;
#if RA6963_HAS_RESET //Make Hardware Reset
if (state)
palClearLine(lcdpins.RST);
else
palSetLine(lcdpins.RST);
#else
(void) state;
#endif
}
static GFXINLINE void set_backlight(GDisplay *g, uint8_t percent) {
(void) g;
(void) percent;
#if RA6963_NEED_BACKLIGHT
#if RA6963_NEED_PWMBACKLIGHT
#else
#endif
#endif
}
static GFXINLINE void acquire_bus(GDisplay *g) {
(void) g;
}
static GFXINLINE void release_bus(GDisplay *g) {
(void) g;
}
#if RA6963_NEED_READ
static GFXINLINE uint8_t RA6963_busy_wait(uint8_t pattern, gBool lh){
uint8_t data;
int ii;
for(ii = 0; ii < 2; ii++) //Only interested in Bit 0 and 1
palSetLineMode(lcdpins.D[ii], PAL_MODE_INPUT); //Set pads to input
palClearLine(lcdpins.CE);
palClearLine(lcdpins.RD);
do{
data = 0;
for(ii = 0; ii < 2; ii++){
if (palReadLine(lcdpins.D[ii]) == PAL_HIGH){ //Read output
data |= (1<<ii);
}
}
} while ((data & pattern) == lh);
palSetLine(lcdpins.CE);
palSetLine(lcdpins.RD);
for(ii = 0; ii < 2; ii++) {
palSetLineMode(lcdpins.D[ii], PAL_MODE_OUTPUT_PUSHPULL); //Set pads to output
}
return data;
}
#endif
static GFXINLINE void RA6963_write(uint8_t value){
int ii;
for(ii = 0; ii < 8; ii++){
if(value & (1 << ii))
palSetLine(lcdpins.D[ii]);
else
palClearLine(lcdpins.D[ii]);
}
}
static GFXINLINE void write_data(GDisplay* g, uint8_t data){
(void)g;
#if RA6963_NEED_READ
RA6963_busy_wait(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2, ~(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2));
#endif
RA6963_write(data);
palClearLine(lcdpins.CD);
palClearLine(lcdpins.CE);
palClearLine(lcdpins.WR);
RA6963_delay(1);
palSetLine(lcdpins.WR);
palSetLine(lcdpins.CE);
palSetLine(lcdpins.CD);
}
static GFXINLINE void write_cmd(GDisplay* g, uint8_t data){
(void)g;
#if RA6963_NEED_READ
RA6963_busy_wait(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2, ~(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2));
#endif
RA6963_write(data);
palClearLine(lcdpins.CE);
palClearLine(lcdpins.WR);
RA6963_delay(1);
palSetLine(lcdpins.WR);
palSetLine(lcdpins.CE);
}
static GFXINLINE void setreadmode(GDisplay *g) {
(void) g;
}
static GFXINLINE void setwritemode(GDisplay *g) {
(void) g;
}
static GFXINLINE uint8_t read_data(GDisplay *g) {
(void) g;
#if RA6963_NEED_READ
int ii;
uint8_t data;
write_cmd(g, RA6963_DATA_READ_AND_NONVARIABLE);
//RA6963_busy_wait(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2, ~(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2));
for(ii = 0; ii < 8; ii++)
palSetLineMode(lcdpins.D[ii], PAL_MODE_INPUT); //Set pads to input
palClearLine(lcdpins.CE);
palClearLine(lcdpins.RD);
do{
data = 0;
for(ii = 0; ii < 2; ii++){
if (palReadLine(lcdpins.D[ii]) == PAL_HIGH){ //Read output
data |= (1<<ii);
}
}
} while ((data & (RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2)) == ~(RA6963_STATUS_BUSY1 | RA6963_STATUS_BUSY2));
palClearLine(lcdpins.CD);
// RA6963_delay(1);
data = 0;
for(ii = 0; ii < 8; ii++){
if (palReadLine(lcdpins.D[ii]) == PAL_HIGH){ //Read output
data |= (1<<ii);
}
}
palSetLine(lcdpins.CE);
palSetLine(lcdpins.RD);
palSetLine(lcdpins.CD);
for(ii = 0; ii < 8; ii++) {
palSetLineMode(lcdpins.D[ii], PAL_MODE_OUTPUT_PUSHPULL); //Set pads to output
}
return data;
#else
return 0;
#endif
}
#endif /* _GDISP_LLD_BOARD_H */
|