-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGT20L16_drive.cpp
More file actions
236 lines (199 loc) · 7.22 KB
/
Copy pathGT20L16_drive.cpp
File metadata and controls
236 lines (199 loc) · 7.22 KB
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
/*
ePaper.h
2013 Copyright (c) Seeed Technology Inc. All right reserved.
Modified by Loovee
www.seeedstudio.com
2013-7-2
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <SPI.h>
#include <Arduino.h>
#include "GT20L16_drive.h"
#include "ePaper.h"
static void spi_on()
{
SPI.begin();
//SPI.setClockDivider(SPI_CLOCK_DIV2);
//SPI_put(0x00);
//SPI_put(0x00);
}
/*********************************************************************************************************
** Function name: begin
** Descriptions: init IO
*********************************************************************************************************/
void GT20L16_drive::begin(int pinSelect)
{
pinCS = pinSelect;
pinMode(pinCS, OUTPUT);
digitalWrite(pinCS, HIGH);
}
/*********************************************************************************************************
** Function name: getMatrixUnicode
** Descriptions: get matrix, unicode
*********************************************************************************************************/
int GT20L16_drive::getMatrixUnicode(unsigned int uniCode, unsigned char *matrix)
{
if(matrix == NULL)return 0;
EPAPER.init_io();
begin();
unsigned char i;
unsigned char tempdata;
unsigned long Add=0;
unsigned char dtaLen = 0;
//spi_on();
if(uniCode <= 45632 )
{
dtaLen = 16;
}
else
{
dtaLen = 32;
}
Add=getAddrFromUnicode(uniCode);
delayMicroseconds(10);
GT_Select();
SPI.transfer(0x03);
SPI.transfer(Add>>16);
SPI.transfer(Add>>8);
SPI.transfer(Add);
SPI.setBitOrder(LSBFIRST);
for(i=0;i<dtaLen;i++)
{
tempdata=SPI.transfer(0x00);
matrix[i]=(tempdata); /*save dot matrix data in matrixdata[i]*/
delay(5);
}
SPI.setBitOrder(MSBFIRST);
GT_UnSelect();
return dtaLen;
}
/*********************************************************************************************************
** Function name: GT_Select
** Descriptions: chip select
*********************************************************************************************************/
void GT20L16_drive::GT_Select()
{
digitalWrite(pinCS, LOW);
}
/*********************************************************************************************************
** Function name: GT_UnSelect
** Descriptions: chip unselect
*********************************************************************************************************/
void GT20L16_drive::GT_UnSelect()
{
digitalWrite(pinCS, HIGH);
}
/*********************************************************************************************************
** Function name: getAddrFromUnicode
** Descriptions: get .. address
*********************************************************************************************************/
unsigned long GT20L16_drive::getAddrFromUnicode(unsigned int uniCode)
{
if (uniCode <= 45632) // char
{
unsigned int BaseAdd=0;
unsigned long Address;
if(uniCode>=0x20&&uniCode<=0x7f)
Address=16*(uniCode-0x20)+BaseAdd;
else if(uniCode>=0xa0&&uniCode<=0xff)
Address=16*(96+uniCode-0xa0)+BaseAdd;
else if(uniCode>=0x100&&uniCode<=0x17f)
Address=16*(192+uniCode-0x100)+BaseAdd;
else if(uniCode>=0x1a0&&uniCode<=0x1cf)
Address=16*(320+uniCode-0x1a0)+BaseAdd;
else if(uniCode>=0x1f0&&uniCode<=0x1ff)
Address=16*(368+uniCode-0x1f0)+BaseAdd;
else if(uniCode>=0x210&&uniCode<=0x21f)
Address=16*(384+uniCode-0x210)+BaseAdd;
else if(uniCode>=0x1ea0&&uniCode<=0x1eff)
Address=16*(400+uniCode-0x1ea0)+BaseAdd;
else if(uniCode>=0x370&&uniCode<=0x3cf)
Address=16*(496+uniCode-0x370)+BaseAdd;
else if(uniCode>=0x400&&uniCode<=0x45f)
Address=16*(592+uniCode-0x400)+BaseAdd;
else if(uniCode>=0x490&&uniCode<=0x4ff)
Address=16*(688+uniCode-0x490)+BaseAdd;
else if(uniCode>=0x590&&uniCode<=0x5ff)
Address=16*(800+uniCode-0x100)+BaseAdd;
else if(uniCode>=0xe00&&uniCode<=0xe7f)
Address=16*(912+uniCode-0xe00)+BaseAdd;
else Address=BaseAdd;
return Address;
}
else
{
unsigned long ZFAdd,HZAdd;
unsigned char MSB,LSB;
unsigned long ChineseTab;
unsigned int data;
unsigned long Add_Chinese;
MSB = uniCode>>8;
LSB = uniCode;
ZFAdd=36224;
HZAdd=93452;
ChineseTab=87436;
if(MSB>=0xA1&&MSB<=0xA5) //char area
{
if(MSB==0xA1&&LSB>=0xA1&&LSB<=0xBF)
Add_Chinese=32*(LSB-0xA1)+ZFAdd;
else if(MSB==0xA3&&LSB>=0xA1&&LSB<=0xFE)
Add_Chinese=32*(31+LSB-0xA1)+ZFAdd;
else if(MSB==0xA4&&LSB>=0xA1&&LSB<=0xF3)
Add_Chinese=32*(125+LSB-0xA1)+ZFAdd;
else if(MSB==0xA5&&LSB>=0xA1&&LSB<=0xF6)
Add_Chinese=32*(208+LSB-0xA1)+ZFAdd;
else
Add_Chinese=ZFAdd;
}
else if((MSB>=0xB0&&MSB<=0xD7)&&(LSB>=0xA1&&LSB<=0xFE)) //chinese 5720
{
Add_Chinese=(MSB-176)*94+(LSB-161)+1;
Add_Chinese=Add_Chinese*32 +HZAdd;
}
else if((MSB>=0xD8&&MSB<=0xF7)&&(LSB>=0xA1&&LSB<=0xFE)) //chinese 5720~6763
{
Add_Chinese=(MSB-0xD8)*94+(LSB-0xA1);
Add_Chinese=Add_Chinese*2+ChineseTab;
data=GTRead(Add_Chinese);
Add_Chinese=32*data+HZAdd;
}
return Add_Chinese;
}
}
/*********************************************************************************************************
** Function name: GTRead
** Descriptions: GTRead
*********************************************************************************************************/
unsigned long GT20L16_drive::GTRead(unsigned long Address)
{
unsigned char i;
unsigned char buffer[2]={0};
unsigned int data;
delayMicroseconds(10);
GT_Select();
SPI.transfer(0x03);
SPI.transfer(Address>>16);
SPI.transfer(Address>>8);
SPI.transfer(Address);
for(i=0;i<2;i++)
{
buffer[i]=SPI.transfer(0x00);
}
GT_UnSelect();
data=buffer[0]*256+buffer[1];
return data;
}
GT20L16_drive GT20L16;
/*********************************************************************************************************
END FILE
*********************************************************************************************************/