Skip to content

Commit 5b8af3a

Browse files
committed
first commit
0 parents  commit 5b8af3a

File tree

6 files changed

+404
-0
lines changed

6 files changed

+404
-0
lines changed

Adafruit_EPD.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import time
2+
from Adafruit_MCP_SRAM import *
3+
import digitalio
4+
import busio
5+
from board import *
6+
7+
from adafruit_bus_device.spi_device import SPIDevice
8+
9+
class Adafruit_EPD(object):
10+
"""Base class for EPD displays
11+
"""
12+
13+
def __init__(self, width, height, rst, dc, busy, srcs=None, cs=None,
14+
spi=None):
15+
self.width = width
16+
self.height = height
17+
18+
# Setup reset pin.
19+
self._rst = rst
20+
self._rst.direction = digitalio.Direction.OUTPUT
21+
22+
# Setup busy pin.
23+
self._busy = busy
24+
self._busy.direction = digitalio.Direction.INPUT
25+
26+
# Setup dc pin.
27+
self._dc = dc
28+
self._dc.direction = digitalio.Direction.OUTPUT
29+
30+
# Setup cs pin.
31+
self._cs = cs
32+
self._cs.direction = digitalio.Direction.OUTPUT
33+
34+
self.spi_device = spi
35+
36+
self.sram = Adafruit_MCP_SRAM(cs=srcs, spi=spi)
37+
38+
def begin(self, reset=True):
39+
self._cs.value = True
40+
self._dc.value = False
41+
42+
if reset:
43+
self._rst.value = False
44+
time.sleep(.1)
45+
self._rst.value = True
46+
time.sleep(.1)
47+
48+
while self._busy.value == True:
49+
pass
50+
51+
def command(self, c, data=None, end=True):
52+
"""Send command byte to display."""
53+
self._cs.value = True
54+
self._dc.value = False
55+
self._cs.value = False
56+
with self.spi_device as spi:
57+
spi.write(bytearray([c]))
58+
59+
if data is not None:
60+
self.data(data)
61+
62+
elif end:
63+
self._cs.value = True
64+
65+
def data(self, d):
66+
"""Send data to display."""
67+
self._dc.value = True
68+
with self.spi_device as spi:
69+
spi.write(d)
70+
self._cs.value = True

Adafruit_IL0376F.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
from Adafruit_EPD import *
2+
from micropython import const
3+
4+
IL0376F_PANEL_SETTING = const(0x00)
5+
IL0376F_POWER_SETTING = const(0x01)
6+
IL0376F_POWER_OFF = const(0x02)
7+
IL0376F_POWER_OFF_SEQUENCE = const(0x03)
8+
IL0376F_POWER_ON = const(0x04)
9+
IL0376F_POWER_ON_MEASURE = const(0x05)
10+
IL0376F_BOOSTER_SOFT_START = const(0x06)
11+
IL0376F_DTM1 = const(0x10)
12+
IL0376F_DATA_STOP = const(0x11)
13+
IL0376F_DISPLAY_REFRESH = const(0x12)
14+
IL0376F_DTM2 = const(0x13)
15+
IL0376F_VCOM1_LUT = const(0x20)
16+
IL0376F_WHITE_LUT = const(0x21)
17+
IL0376F_BLACK_LUT = const(0x22)
18+
IL0376F_GRAY1_LUT = const(0x23)
19+
IL0376F_GRAY2_LUT = const(0x24)
20+
IL0376F_VCOM2_LUT = const(0x25)
21+
IL0376F_RED0_LUT = const(0x26)
22+
IL0376F_RED1_LUT = const(0x27)
23+
IL0376F_PLL = const(0x30)
24+
IL0376F_CDI = const(0x50)
25+
IL0376F_RESOLUTION = const(0x61)
26+
IL0376F_VCM_DC_SETTING = const(0x82)
27+
28+
class Adafruit_IL0376F_base(Adafruit_EPD):
29+
30+
def __init__(self, width, height, rst, dc, busy, srcs=None, cs=None, spi=None):
31+
32+
super(Adafruit_IL0376F_base, self).__init__(width, height, rst, dc, busy, srcs, cs, spi)
33+
34+
def begin(self, reset=True):
35+
super(Adafruit_IL0376F_base, self).begin(reset)
36+
37+
self.command(IL0376F_POWER_SETTING, bytearray([0x07, 0x00, 0x0D, 0x00]))
38+
self.command(IL0376F_BOOSTER_SOFT_START, bytearray([0x07, 0x07, 0x07]))
39+
40+
def update(self):
41+
self.command(IL0376F_DISPLAY_REFRESH)
42+
43+
while self._busy.value == True:
44+
pass
45+
46+
time.sleep(10)
47+
48+
self.command(IL0376F_CDI, bytearray([0x17]))
49+
self.command(IL0376F_VCM_DC_SETTING, bytearray([0x00]))
50+
self.command(IL0376F_POWER_SETTING, bytearray([0x02, 0x00, 0x00, 0x00]))
51+
self.command(IL0376F_POWER_OFF)
52+
53+
def power_up(self):
54+
self.command(IL0376F_POWER_ON)
55+
while self._busy.value == True:
56+
pass
57+
58+
time.sleep(.2)
59+
60+
self.command(IL0376F_PANEL_SETTING, bytearray([0xCF]))
61+
self.command(IL0376F_CDI, bytearray([0x37]))
62+
self.command(IL0376F_PLL, bytearray([0x39]))
63+
self.command(IL0376F_VCM_DC_SETTING, bytearray([0x0E]))
64+
65+
def display(self):
66+
self.power_up()
67+
68+
self.command(IL0376F_DTM1, end=False)
69+
self._dc.value = True
70+
with self.spi_device as spi:
71+
for i in range(10000):
72+
spi.write(bytearray([0xff]))#TODO actual data
73+
self._cs.value = True
74+
75+
self.command(IL0376F_DTM2, end=False)
76+
self._dc.value = True
77+
with self.spi_device as spi:
78+
for i in range(5000):
79+
spi.write(bytearray([0xff]))#TODO actual data
80+
self._cs.value = True
81+
82+
self.update()
83+
84+
"""
85+
def image(self, image):
86+
Set buffer to value of Python Imaging Library image. The image should
87+
be in RGB mode and a size equal to the display size.
88+
89+
if image.mode != 'RGB':
90+
raise ValueError('Image must be in mode RGB.')
91+
imwidth, imheight = image.size
92+
if imwidth != self.width or imheight != self.height:
93+
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
94+
.format(self.width, self.height))
95+
# Grab all the pixels from the image, faster than getpixel.
96+
pix = image.load()
97+
98+
for y in xrange(image.size[0]):
99+
for x in xrange(image.size[1]):
100+
if x == 0:
101+
x = 1
102+
p = pix[x, y]
103+
if p == (0xFF, 0, 0):
104+
#RED
105+
addr = ( (self.width - x) * self.height + y) >> 3
106+
self.red_buffer[addr] &= ~(1 << (7 - (y%8)))
107+
else:
108+
#GS
109+
bits = (6 - y%4 * 2)
110+
addr = ( (self.width - x) * self.height + y) >> 2
111+
self.bw_buffer[addr] &= ~(0x3 << bits)
112+
if p == (0xFF, 0xFF, 0xFF): #WHITE
113+
self.bw_buffer[addr] |= (0x3 << bits)
114+
115+
elif p == (0x7F, 0x7F, 0x7F): #GRAY
116+
self.bw_buffer[addr] |= (0x2 << bits)
117+
"""

Adafruit_IL0376F_200_200.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from Adafruit_IL0376F import *
2+
3+
lut_vcom0 = bytearray([ 0x0E ,0x14 ,0x01 ,0x0A ,0x06 ,0x04 ,0x0A ,0x0A ,0x0F ,0x03 ,0x03 ,0x0C ,0x06 ,0x0A ,0x00 ])
4+
lut_w = bytearray([ 0x0E ,0x14 ,0x01 ,0x0A ,0x46 ,0x04 ,0x8A ,0x4A ,0x0F ,0x83 ,0x43 ,0x0C ,0x86 ,0x0A ,0x04 ])
5+
lut_b = bytearray([ 0x0E ,0x14 ,0x01 ,0x8A ,0x06 ,0x04 ,0x8A ,0x4A ,0x0F ,0x83 ,0x43 ,0x0C ,0x06 ,0x4A ,0x04 ])
6+
lut_g1 = bytearray([ 0x8E ,0x94 ,0x01 ,0x8A ,0x06 ,0x04 ,0x8A ,0x4A ,0x0F ,0x83 ,0x43 ,0x0C ,0x06 ,0x0A ,0x04 ])
7+
lut_g2 = bytearray([ 0x8E ,0x94 ,0x01 ,0x8A ,0x06 ,0x04 ,0x8A ,0x4A ,0x0F ,0x83 ,0x43 ,0x0C ,0x06 ,0x0A ,0x04 ])
8+
lut_vcom1 = bytearray([ 0x03 ,0x1D ,0x01 ,0x01 ,0x08 ,0x23 ,0x37 ,0x37 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ])
9+
lut_red0 = bytearray([ 0x83 ,0x5D ,0x01 ,0x81 ,0x48 ,0x23 ,0x77 ,0x77 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ])
10+
lut_red1 = bytearray([ 0x03 ,0x1D ,0x01 ,0x01 ,0x08 ,0x23 ,0x37 ,0x37 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ])
11+
12+
class Adafruit_IL0376F_200_200(Adafruit_IL0376F_base):
13+
14+
def __init__(self, rst, dc, busy, srcs=None, cs=None, spi=None):
15+
16+
super(Adafruit_IL0376F_200_200, self).__init__(200, 200, rst, dc, busy, srcs, cs, spi)
17+
18+
def power_up(self):
19+
super(Adafruit_IL0376F_200_200, self).power_up()
20+
21+
self.command(IL0376F_RESOLUTION, bytearray([0xC8, 0x00, 0xC8]))
22+
self.write_lut()
23+
24+
def write_lut(self):
25+
self.command(IL0376F_VCOM1_LUT, lut_vcom0)
26+
self.command(IL0376F_WHITE_LUT, lut_w)
27+
self.command(IL0376F_BLACK_LUT, lut_b)
28+
self.command(IL0376F_GRAY1_LUT, lut_g1)
29+
self.command(IL0376F_GRAY2_LUT, lut_g2)
30+
self.command(IL0376F_VCOM2_LUT, lut_vcom1)
31+
self.command(IL0376F_RED0_LUT, lut_red0)
32+
self.command(IL0376F_RED1_LUT, lut_red1)

Adafruit_IL91874.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from Adafruit_EPD import *
2+
3+
class Adafruit_IL91874_base(Adafruit_EPD):
4+
IL91874_PANEL_SETTING = 0x00
5+
IL91874_POWER_SETTING = 0x01
6+
IL91874_POWER_OFF = 0x02
7+
IL91874_POWER_OFF_SEQUENCE =0x03
8+
IL91874_POWER_ON = 0x04
9+
IL91874_POWER_ON_MEASURE = 0x05
10+
IL91874_BOOSTER_SOFT_START = 0x06
11+
IL91874_DEEP_SLEEP = 0x07
12+
IL91874_DTM1 = 0x10
13+
IL91874_DATA_STOP = 0x11
14+
IL91874_DISPLAY_REFRESH = 0x12
15+
IL91874_DTM2 = 0x13
16+
IL91874_PDTM1 = 0x14
17+
IL91874_PDTM2 = 0x15
18+
IL91874_PDRF = 0x16
19+
IL91874_LUT1 = 0x20
20+
IL91874_LUTWW = 0x21
21+
IL91874_LUTBW = 0x22
22+
IL91874_LUTWB = 0x23
23+
IL91874_LUTBB = 0x24
24+
IL91874_PLL = 0x30
25+
IL91874_CDI = 0x50
26+
IL91874_RESOLUTION = 0x61
27+
IL91874_VCM_DC_SETTING = 0x82
28+
29+
def __init__(self, width, height, rst, dc, busy, sclk=None, mosi=None, cs=None, gpio=None, spi=None):
30+
31+
super(Adafruit_IL91874_base, self).__init__(width, height, rst, dc, busy, sclk, mosi, cs, gpio, spi)
32+
33+
self.bw_buffer = [0xFF]* (width*height >> 3)
34+
self.red_buffer = [0xFF]* (width*height >> 3)
35+
36+
def begin(self, reset=True):
37+
super(Adafruit_IL91874_base, self).begin(reset)
38+
39+
self.command(self.IL91874_POWER_SETTING, [0x07, 0x00, 0x0A, 0x00])
40+
self.command(self.IL91874_BOOSTER_SOFT_START, [0x07, 0x07, 0x07])
41+
42+
def update(self):
43+
self.command(self.IL91874_DISPLAY_REFRESH)
44+
45+
while self._gpio.is_high(self._busy):
46+
pass
47+
48+
time.sleep(10)
49+
50+
self.command(self.IL91874_CDI, [0x17])
51+
self.command(self.IL91874_VCM_DC_SETTING, [0x00])
52+
self.command(self.IL91874_POWER_SETTING, [0x02, 0x00, 0x00, 0x00])
53+
self.command(self.IL91874_POWER_OFF)
54+
55+
time.sleep(10)
56+
57+
def power_up(self):
58+
self.command(self.IL91874_POWER_ON)
59+
while self._gpio.is_high(self._busy):
60+
pass
61+
62+
time.sleep(.2)
63+
64+
self.command(self.IL91874_PANEL_SETTING, [0xCF])
65+
self.command(self.IL91874_CDI, [0x37])
66+
self.command(self.IL91874_PLL, [0x29])
67+
self.command(self.IL91874_VCM_DC_SETTING, [0x0A])
68+
69+
def display(self):
70+
self.power_up()
71+
72+
self.command(self.IL91874_DTM1, end=False)
73+
self._gpio.set_high(self._dc)
74+
for i in range(len(self.bw_buffer)):
75+
self._spi.write([self.bw_buffer[i]])
76+
self._gpio.set_high(self._cs)
77+
78+
self.command(self.IL91874_DTM2, end=False)
79+
self._gpio.set_high(self._dc)
80+
for i in range(len(self.red_buffer)):
81+
self._spi.write([self.red_buffer[i]])
82+
self._gpio.set_high(self._cs)
83+
self.update()
84+
85+
def image(self, image):
86+
"""Set buffer to value of Python Imaging Library image. The image should
87+
be in RGB mode and a size equal to the display size.
88+
"""
89+
if image.mode != 'RGB':
90+
raise ValueError('Image must be in mode RGB.')
91+
imwidth, imheight = image.size
92+
if imwidth != self.width or imheight != self.height:
93+
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
94+
.format(self.width, self.height))
95+
# Grab all the pixels from the image, faster than getpixel.
96+
pix = image.load()
97+
98+
for y in xrange(image.size[1]):
99+
for x in xrange(image.size[0]):
100+
if x == 0:
101+
x = 1
102+
p = pix[x, y]
103+
addr = ( (self.width - x) * self.height + y) >> 3
104+
if p == (0xFF, 0, 0):
105+
#RED
106+
self.red_buffer[addr] &= ~(1 << (7 - (y%8)))
107+
elif p == (0, 0, 0):
108+
#BLACK
109+
self.bw_buffer[addr] &= ~(1 << (7 - (y%8)))
110+
else:
111+
#WHITE
112+
self.bw_buffer[addr] |= (1 << (7 - (y%8)))
113+
114+
def clear_buffer(self):
115+
self.bw_buffer = [0xFF]* (width*height >> 3)
116+
self.red_buffer = [0xFF]* (width*height >> 3)

Adafruit_IL91874_212_104.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from Adafruit_IL91874 import *
2+
3+
class Adafruit_IL91874_212_104(Adafruit_IL91874_base):
4+
def __init__(self, rst, dc, busy, sclk=None, mosi=None, cs=None, gpio=None, spi=None):
5+
6+
super(Adafruit_IL91874_212_104, self).__init__(212, 104, rst, dc, busy, sclk, mosi, cs, gpio, spi)
7+
8+
def power_up(self):
9+
super(Adafruit_IL91874_212_104, self).power_up()
10+
self.command(self.IL91874_RESOLUTION, [0x68, 0x00, 0xD4])
11+
time.sleep(.02)

0 commit comments

Comments
 (0)