-
Notifications
You must be signed in to change notification settings - Fork 0
/
glcd.c
98 lines (92 loc) · 2.87 KB
/
glcd.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
#include "glcd.h"
#include <string.h>
screen_type_t currentScreen = GLCD_NONE;
void GLCD_Initialize(screen_type_t screenType) {
switch (screenType) {
case GLCD_KS0108:
KS0108_Initialize();
break;
#ifdef ST7920_SUPPORT
case GLCD_ST7920:
ST7920_Initialize();
break;
#endif
default:
break;
}
currentScreen = screenType;
}
void GLCD_ClearScreen() {
switch (currentScreen) {
case GLCD_KS0108:
KS0108_ClearScreen();
break;
#ifdef ST7920_SUPPORT
case GLCD_ST7920:
ST7920_ClearScreen();
break;
#endif
default:
break;
}
}
void GLCD_WriteBufToScreen() {
switch (currentScreen) {
case GLCD_KS0108:
KS0108_WriteBufToScreen();
break;
#ifdef ST7920_SUPPORT
case GLCD_ST7920:
BufCopy_KS0108_to_ST7920(ST7920Buf, KS0108Buf);
ST7920_WriteBufToScreen();
break;
#endif
default:
break;
}
}
#ifdef ST7920_SUPPORT
// Copy a screen buffer with vertical byte order (KS0108-style) into one with horizontal word order (ST7920-style)
// Both buffers are DISPBUF_SCREEN_WIDTH*DISPBUF_SCREEN_HEIGHT/8 bytes)
//
// Processes in 16x8 blocks - One block is shown
/*
* KS0108 ST7920
* ---------------------------------|--------------------------------|
* | a0 b0 c0 d0 e0 .. p0 | a15 a14 .. a0 |
* | a1 b1 c1 d1 e1 .. p1 | b15 b14 .. b0 |
* | .. | .. |
* | a7 b7 c7 d7 e7 .. p7 | h15 h14 .. h0 |
* ------------------------------------------------------------------|
*
* Although, in the ST7920 example, words a and b are not contiguous (words for an entire row are contiguous)
*
* Copying 128x64 screen takes ~400ns @ 192MHz :-)
*/
void BufCopy_KS0108_to_ST7920(uint16_t *dst_st7920, unsigned char *src_ks0108) {
unsigned char tmp[16];
int i,j,k,l;
unsigned int src_offset, dst_offset;
uint16_t x;
unsigned char mask;
// Iterate through groups of 8 rows
for (i=0; i<DISPBUF_SCREEN_HEIGHT/8; i++) {
// Iterate through 16x8 blocks
for (j=0; j<DISPBUF_SCREEN_WIDTH/16; j++) {
src_offset=(i*DISPBUF_SCREEN_WIDTH)+(j*16);
memcpy(tmp, &(src_ks0108[src_offset]), 16); // Copy 16x8 area to buffer
for (k=0; k<8; k++) { // Iterate through the 8 rows
x=0;
dst_offset=((i*8+k)*(DISPBUF_SCREEN_WIDTH/16))+j;
mask=1<<k;
for (l=0; l<15; l++) {
x+=(tmp[l]&mask)?1:0;
x = x<<1;
}
x+= (tmp[15]&mask)?1:0;
dst_st7920[dst_offset]=x;
}
}
}
}
#endif