-
Notifications
You must be signed in to change notification settings - Fork 1
/
el320_240.py
241 lines (164 loc) · 5.63 KB
/
el320_240.py
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
"""
Raw raster scan driver for controllerless
Planar EL320.240 electroluminescent display
Copyright (c) 2006 [email protected]
This file is released under the GNU Lesser General Public Licence.
See the file LICENSE for details.
"""
import time
VSYNC_LO = 0x0
VSYNC_HI = 0x20
HSYNC_LO = 0x0
HSYNC_HI = 0x40
inv=0; inv=1
if inv:
VSYNC_LO = 0x20
VSYNC_HI = 0x0
HSYNC_LO = 0x40
HSYNC_HI = 0x0
CLOCK_LO = 0
CLOCK_HI = 0x80
DATA0 = 0x01
DATA1 = 0x02
DATA2 = 0x04
DATA3 = 0x08
H = 240
W = 320 / 4
#
# this abstract base class presents the public interface to the
# Planar EL320.240 display driver
#
class EL320_240:
def __init__(self): pass
#
# send a monochrome bitmap, stored in an 8-bit string, to the display
#
def write(self, data, address=0):
# convert the 8-bit input into the display's 4-bit format
out = []
t = time.time()
for byte in data:
b = ord(byte)
hi = (b>>4) & 0x0F
out.append(hi)
lo = b & 0x0F
out.append(lo)
#print 1.0 / (time.time() - t),
# write the update frame out to the display
#t = time.time()
self.scan(out, address/40)
#print 1.0 / (time.time() - t)
#
# the core raster scan algorithm
#
def scan(self, data, start=0):
stop = start + len(data)/80;
if start == 0:
self.col0[0] = [data[0]]
self.col1[0] = [data[1]]
first = data[1:80]
self.col0[1] = [data[80]]
self.col1[1] = [data[81]]
second = data[81:160]
else:
first = self.col1[0]
second = self.col1[1]
# emit a hsync pulse
self.send(VSYNC_LO | HSYNC_HI, self.col0[0])
# clock the first scanline in
self.send(VSYNC_LO | HSYNC_LO, first)
# emit a hsync pulse
self.send(VSYNC_LO | HSYNC_HI, self.col0[1])
# clock the second scanline in with vsync pulse
self.send(VSYNC_HI | HSYNC_LO, second)
# for each scan line in the upper margin
for row in xrange(2, start):
# emit a hsync pulse, but skip the row
self.send(VSYNC_LO | HSYNC_HI, self.col0[row])
self.send(VSYNC_LO | HSYNC_LO, self.col1[row])
# for each scan line in the update region
for row in xrange(start, stop):
offset = (row-start) * 80
# emit a hsync pulse
self.send(VSYNC_LO | HSYNC_HI, data[offset:offset+1])
# clock the row data in
self.send(VSYNC_LO | HSYNC_LO, data[offset+1:offset+80])
self.col0[row] = [data[offset]]
self.col1[row] = [data[offset+1]]
# for each remaining scan line
for row in xrange(stop, H-1):
# emit a hsync pulse, but skip the row
self.send(VSYNC_LO | HSYNC_HI, self.col0[row])
self.send(VSYNC_LO | HSYNC_LO, self.col1[row])
# emit a hsync pulse, but skip the row
self.send(VSYNC_LO | HSYNC_HI)
self.send(VSYNC_LO | HSYNC_LO, [0]*79)
self.sync()
#
# this concrete class implements the raster scan algorithm over an
# FTDI FT232R USB client adapter
#
import threading
import sched
class UsbScanDriver:
def __init__(self):
device = ftdi.getFtdiDevices()
self.usb = ftdi.FT232R(device[0])
self.s = sched.scheduler(time.time, time.sleep)
self.s.enter(0, 0, self._scan, [])
self.t = threading.Thread(target=self._run, args=[])
self.t.start()
def _run(self):
try: self.s.run()
except: pass
def queueNewFrame(self, frame):
f = frame[:] # copy by client thread eliminates the need for locking
self.s.enter(0, 0, self._updateFrame, [f])
def _updateFrame(self, frame):
self._frame = frame
def _scan(self):
try:
#self.packet.append(VSYNC_HI) # leave the display on after the last frame
self.usb.writeData(self._frame)
except: pass
self.s.enter(0.001, 0, self._scan, [])
import ftdi
class EL320_240USB(EL320_240):
def __init__(self):
self.W = 320
self.H = 240
device = ftdi.getFtdiDevices()
self.usb = ftdi.FT232R(device[0])
self.usb.enableBitBang()
self.packet = []
self.col0 = [[0]]*self.H
self.col1 = [[0]]*self.H
#self.s = UsbScanDriver()
def send(self, sync, data=[0]):
if sync: data = [ sync|byte for byte in data ]
self.packet.extend(data)
#for byte in data:
# self.packet.append(sync|CLOCK_HI|byte)
# self.packet.append(sync|CLOCK_LO|byte)
def sync(self):
try: self.usb.write(self.packet*3)
except: pass
#try: self.usb.write(self.packet*2)
#except: pass
self.packet = []
time.sleep(0)
#
# this concrete class implements the display driver over a PC parallel interface
#
# probably too slow to be useful
#
import parallel # http://pyserial.sourceforge.net/pyparallel
class EL320_240Par(EL320_240):
pass
if __name__ == '__main__':
d = EL320_240USB()
while True:
d.write('\x11'*4800, 2400)
d.write('\x22'*4800, 2400)
d.write('\x44'*4800, 2400)
d.write('\x88'*4800, 2400)