Skip to content

Commit 30f18c3

Browse files
authored
Merge pull request #63 from fpammer/driver-5in65f
Add support for new Waveshare 5.65 inch 7 color e-paper display
2 parents 5ffe395 + 35d4898 commit 30f18c3

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed

drivers/drivers_color.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
from drivers.drivers_full import WaveshareFull
18+
from PIL import Image
1819

1920

2021
class WaveshareColor(WaveshareFull):
@@ -224,6 +225,160 @@ def sleep(self):
224225
self.send_data(0xa5)
225226

226227

228+
class EPD5in65f(WaveshareColor):
229+
"""Waveshare 5.65" - 7 colors"""
230+
231+
LUT_BLACK = 0x000000 # 0000 BGR
232+
LUT_WHITE = 0xffffff # 0001
233+
LUT_GREEN = 0x00ff00 # 0010
234+
LUT_BLUE = 0xff0000 # 0011
235+
LUT_RED = 0x0000ff # 0100
236+
LUT_YELLOW = 0x00ffff # 0101
237+
LUT_ORANGE = 0x0080ff # 0110
238+
POWER_SAVING = 0xE3
239+
TCON_RESOLUTION = 0x61
240+
TEMPERATURE_CALIBRATION = 0x41
241+
242+
def __init__(self):
243+
super().__init__(name='5.65" F', width=600, height=448)
244+
245+
def reset(self):
246+
self.digital_write(self.RST_PIN, 1)
247+
self.delay_ms(600)
248+
self.digital_write(self.RST_PIN, 0)
249+
self.delay_ms(2)
250+
self.digital_write(self.RST_PIN, 1)
251+
self.delay_ms(200)
252+
253+
def send_command(self, command):
254+
self.digital_write(self.DC_PIN, 0)
255+
self.digital_write(self.CS_PIN, 0)
256+
self.spi_transfer([command])
257+
self.digital_write(self.CS_PIN, 1)
258+
259+
def send_data(self, data):
260+
self.digital_write(self.DC_PIN, 1)
261+
self.digital_write(self.CS_PIN, 0)
262+
self.spi_transfer([data])
263+
self.digital_write(self.CS_PIN, 1)
264+
265+
def wait_until_busy(self):
266+
while self.digital_read(self.BUSY_PIN) == 0: # 0: idle, 1: busy
267+
self.delay_ms(100)
268+
269+
def wait_until_idle(self):
270+
while self.digital_read(self.BUSY_PIN) == 1: # 0: idle, 1: busy
271+
self.delay_ms(100)
272+
273+
def init(self, **kwargs):
274+
if self.epd_init() != 0:
275+
return -1
276+
277+
# EPD hardware init start
278+
self.reset()
279+
280+
self.wait_until_busy()
281+
self.send_command(self.PANEL_SETTING)
282+
self.send_data(0xEF)
283+
self.send_data(0x08)
284+
self.send_command(self.POWER_SETTING)
285+
self.send_data(0x37)
286+
self.send_data(0x00)
287+
self.send_data(0x23)
288+
self.send_data(0x23)
289+
self.send_command(self.POWER_OFF_SEQUENCE_SETTING)
290+
self.send_data(0x00)
291+
self.send_command(self.BOOSTER_SOFT_START)
292+
self.send_data(0xC7)
293+
self.send_data(0xC7)
294+
self.send_data(0x1D)
295+
self.send_command(self.PLL_CONTROL)
296+
self.send_data(0x3C)
297+
self.send_command(self.TEMPERATURE_SENSOR_COMMAND)
298+
self.send_data(0x00)
299+
self.send_command(self.VCOM_AND_DATA_INTERVAL_SETTING)
300+
self.send_data(0x37)
301+
self.send_command(self.TCON_SETTING)
302+
self.send_data(0x22)
303+
self.send_command(self.TCON_RESOLUTION)
304+
self.send_data(0x02)
305+
self.send_data(0x58)
306+
self.send_data(0x01)
307+
self.send_data(0xC0)
308+
self.send_command(self.POWER_SAVING)
309+
self.send_data(0xAA)
310+
311+
self.delay_ms(100)
312+
self.send_command(0x50)
313+
self.send_data(0x37)
314+
315+
def get_frame_buffer(self, image, reverse=False):
316+
buf = [0x00] * int(self.width * self.height / 2)
317+
318+
# quantize image with palette of possible colors
319+
image_palette = Image.new('P', (1, 1))
320+
image_palette.putpalette(([0, 0, 0, 255, 255, 255, 0, 255, 0, 0, 0, 255, 255, 0, 0, 255, 255, 0, 255, 128, 0]
321+
+ [0, 0, 0]) * 32) # multiply by 32 to pad palette to reach required length of 768
322+
image_rgb = image.quantize(palette=image_palette).convert('RGB')
323+
324+
imwidth, imheight = image_rgb.size
325+
326+
if imwidth != self.width or imheight != self.height:
327+
raise ValueError('Image must be same dimensions as display \
328+
({0}x{1}).'.format(self.width, self.height))
329+
330+
pixels = image_rgb.load()
331+
332+
for y in range(self.height):
333+
for x in range(self.width):
334+
pos = int((x + y * self.width) / 2)
335+
color = 0
336+
337+
if pixels[x, y][0] == 0 and pixels[x, y][1] == 0 and pixels[x, y][2] == 0:
338+
color = 0
339+
elif pixels[x, y][0] == 255 and pixels[x, y][1] == 255 and pixels[x, y][2] == 255:
340+
color = 1
341+
elif pixels[x, y][0] == 0 and pixels[x, y][1] == 255 and pixels[x, y][2] == 0:
342+
color = 2
343+
elif pixels[x, y][0] == 0 and pixels[x, y][1] == 0 and pixels[x, y][2] == 255:
344+
color = 3
345+
elif pixels[x, y][0] == 255 and pixels[x, y][1] == 0 and pixels[x, y][2] == 0:
346+
color = 4
347+
elif pixels[x, y][0] == 255 and pixels[x, y][1] == 255 and pixels[x, y][2] == 0:
348+
color = 5
349+
elif pixels[x, y][0] == 255 and pixels[x, y][1] == 128 and pixels[x, y][2] == 0:
350+
color = 6
351+
352+
data_t = buf[pos] & (~(0xF0 >> ((x % 2) * 4)))
353+
buf[pos] = data_t | ((color << 4) >> ((x % 2) * 4))
354+
355+
return buf
356+
357+
def display_frame(self, frame_buffer, *args):
358+
self.send_command(self.TCON_RESOLUTION)
359+
self.send_data(0x02)
360+
self.send_data(0x58)
361+
self.send_data(0x01)
362+
self.send_data(0xC0)
363+
self.send_command(self.DATA_START_TRANSMISSION_1)
364+
for i in range(0, int(self.height)):
365+
for j in range(0, int(self.width / 2)):
366+
self.send_data((frame_buffer[j + (int(self.width / 2) * i)]))
367+
self.send_command(self.POWER_ON)
368+
self.wait_until_busy()
369+
self.send_command(self.DISPLAY_REFRESH)
370+
self.wait_until_busy()
371+
self.send_command(self.POWER_OFF)
372+
self.wait_until_idle()
373+
self.delay_ms(500)
374+
375+
def sleep(self):
376+
self.delay_ms(500)
377+
self.send_command(self.DEEP_SLEEP)
378+
self.send_data(0XA5)
379+
self.digital_write(self.RST_PIN, 0)
380+
381+
227382
# This is a 'monochrome' display but surprisingly, the only difference to EPD7in5b is
228383
# setting a different resolution in init() (after TCON_RESOLUTION command),
229384
# thus, it is here and a subclass of EPD7in5b (for now).

papertty.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ def get_drivers():
411411

412412
drivers_color.EPD4in2b, drivers_color.EPD7in5b,
413413
drivers_color.EPD5in83, drivers_color.EPD5in83b,
414+
drivers_color.EPD5in65f,
414415

415416
drivers_colordraw.EPD1in54b, drivers_colordraw.EPD1in54c,
416417
drivers_colordraw.EPD2in13b, drivers_colordraw.EPD2in7b,

0 commit comments

Comments
 (0)