DM: make pylint happy

This commit is contained in:
dean 2018-07-12 16:28:01 -04:00
parent c673a7eacd
commit 01d7cfb046
3 changed files with 203 additions and 198 deletions

View file

@ -1,124 +1,131 @@
import time
from Adafruit_EPD import mcp_sram
import digitalio
import busio
from board import *
class Adafruit_EPD(object):
"""Base class for EPD displays
"""
BLACK = 0
WHITE = 1
INVERSE = 2
RED = 3
DARK = 4
LIGHT = 5
"""Base class for EPD displays
"""
BLACK = 0
WHITE = 1
INVERSE = 2
RED = 3
DARK = 4
LIGHT = 5
def __init__(self, width, height, rst, dc, busy, srcs, cs,
spi):
self.width = width
self.height = height
def __init__(self, width, height, rst_pin, dc_pin, busy_pin, srcs_pin, cs_pin, spi):
self.width = width
self.height = height
# Setup reset pin.
self._rst = rst
self._rst.direction = digitalio.Direction.OUTPUT
# Setup reset pin.
self._rst = rst_pin
self._rst.direction = digitalio.Direction.OUTPUT
# Setup busy pin.
self._busy = busy
self._busy.direction = digitalio.Direction.INPUT
# Setup busy pin.
self._busy = busy_pin
self._busy.direction = digitalio.Direction.INPUT
# Setup dc pin.
self._dc = dc
self._dc.direction = digitalio.Direction.OUTPUT
# Setup dc pin.
self._dc = dc_pin
self._dc.direction = digitalio.Direction.OUTPUT
# Setup cs pin.
self._cs = cs
self._cs.direction = digitalio.Direction.OUTPUT
# Setup cs pin.
self._cs = cs_pin
self._cs.direction = digitalio.Direction.OUTPUT
self.spi_device = spi
self.spi_device = spi
self.sram = mcp_sram.Adafruit_MCP_SRAM(srcs, spi)
self.sram = mcp_sram.Adafruit_MCP_SRAM(srcs_pin, spi)
def begin(self, reset=True):
self._cs.value = True
self._dc.value = False
def begin(self, reset=True):
self._cs.value = True
self._dc.value = False
if reset:
self._rst.value = False
time.sleep(.1)
self._rst.value = True
time.sleep(.1)
if reset:
self._rst.value = False
time.sleep(.1)
self._rst.value = True
time.sleep(.1)
def command(self, c, data=None, end=True):
"""Send command byte to display."""
self._cs.value = True
self._dc.value = False
self._cs.value = False
outbuf = bytearray(1)
def command(self, cmd, data=None, end=True):
"""Send command byte to display."""
self._cs.value = True
self._dc.value = False
self._cs.value = False
outbuf = bytearray(1)
while not self.spi_device.try_lock():
pass
self.spi_device.write_readinto(bytearray([c]), outbuf)
while not self.spi_device.try_lock():
pass
self.spi_device.write_readinto(bytearray([cmd]), outbuf)
if data is not None:
self.data(data)
if data is not None:
self.data(data)
elif end:
self._cs.value = True
elif end:
self._cs.value = True
self.spi_device.unlock()
return outbuf[0]
self.spi_device.unlock()
return outbuf[0]
def data(self, d):
"""Send data to display."""
self._dc.value = True
self.spi_device.write(d)
self._cs.value = True
self.spi_device.unlock()
def data(self, dat):
"""Send data to display."""
self._dc.value = True
self.spi_device.write(dat)
self._cs.value = True
self.spi_device.unlock()
#framebuf methods
def fill(self, color):
self.format.fill_rect(self, 0, 0, self.width, self.height, color)
def draw_pixel(self, x, y, color):
pass
def fill_rect(self, x, y, width, height, color):
if width < 1 or height < 1 or (x+width) <= 0 or (y+height) <= 0 or y >= self.height or x >= self.width:
return
xend = min(self.width, x+width)
yend = min(self.height, y+height)
x = max(x, 0)
y = max(y, 0)
for _x in range(xend - x):
for _y in range(yend - y):
self.draw_pixel(x + _x, y + _y, color)
def get_pixel(self, x, y):
pass
def pixel(self, x, y, color=None):
if x < 0 or x >= self.width or y < 0 or y >= self.height:
return
if color is None:
return self.get_pixel(self, x, y)
else:
self.draw_pixel(self, x, y, color)
#framebuf methods
def fill(self, color):
self.fill_rect(self, 0, 0, self.width, self.height, color)
def hline(self, x, y, width, color):
self.fill_rect(x, y, width, 1, color)
def fill_rect(self, x, y, width, height, color):
if width < 1 or height < 1 or (x+width) <= 0 or (y+height) <= 0 \
or y >= self.height or x >= self.width:
return
xend = min(self.width, x+width)
yend = min(self.height, y+height)
x = max(x, 0)
y = max(y, 0)
for _x in range(xend - x):
for _y in range(yend - y):
self.draw_pixel(x + _x, y + _y, color)
return
def vline(self, x, y, height, color):
self.fill_rect(x, y, 1, height, color)
def pixel(self, x, y, color=None):
if x < 0 or x >= self.width or y < 0 or y >= self.height:
return None
if color is None:
return self.get_pixel(self, x, y)
def rect(self, x, y, width, height, color):
self.fill_rect(x, y, width, 1, color)
self.fill_rect(x, y+height, width, 1, color)
self.fill_rect(self, x, y, 1, height, color)
self.fill_rect(self, x+width, y, 1, height, color)
self.draw_pixel(self, x, y, color)
return None
def line(self):
raise NotImplementedError()
def hline(self, x, y, width, color):
self.fill_rect(x, y, width, 1, color)
def blit(self):
raise NotImplementedError()
def vline(self, x, y, height, color):
self.fill_rect(x, y, 1, height, color)
def scroll(self):
raise NotImplementedError()
def rect(self, x, y, width, height, color):
self.fill_rect(x, y, width, 1, color)
self.fill_rect(x, y+height, width, 1, color)
self.fill_rect(self, x, y, 1, height, color)
self.fill_rect(self, x+width, y, 1, height, color)
def text(self):
raise NotImplementedError()
def line(self):
raise NotImplementedError()
def blit(self):
raise NotImplementedError()
def scroll(self):
raise NotImplementedError()
def text(self):
raise NotImplementedError()

View file

@ -1,7 +1,7 @@
import time
from micropython import const
from Adafruit_EPD.epd import Adafruit_EPD
from Adafruit_EPD.mcp_sram import Adafruit_MCP_SRAM
from micropython import const
import time
IL0373_PANEL_SETTING = const(0x00)
IL0373_POWER_SETTING = const(0x01)
@ -29,8 +29,9 @@ IL0373_RESOLUTION = const(0x61)
IL0373_VCM_DC_SETTING = const(0x82)
class Adafruit_IL0373(Adafruit_EPD):
def __init__(self, width, height, rst, dc, busy, srcs, cs, spi):
super().__init__(width, height, rst, dc, busy, srcs, cs, spi)
def __init__(self, width, height, rst_pin, dc_pin, busy_pin, srcs_pin, cs_pin, spi):
super(Adafruit_IL0373, self).__init__(width, height, rst_pin, dc_pin, busy_pin, \
srcs_pin, cs_pin, spi)
self.bw_bufsize = int(width * height / 8)
self.red_bufsize = int(width * height / 8)
@ -38,19 +39,19 @@ class Adafruit_IL0373(Adafruit_EPD):
self.begin()
def begin(self, reset=True):
super(Adafruit_IL0373, self).begin(reset)
super(Adafruit_IL0373, self).begin(reset)
while self._busy.value == False:
pass
while self._busy.value is False:
pass
self.command(IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09]))
self.command(IL0373_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17]))
self.command(IL0373_POWER_SETTING, bytearray([0x03, 0x00, 0x2b, 0x2b, 0x09]))
self.command(IL0373_BOOSTER_SOFT_START, bytearray([0x17, 0x17, 0x17]))
def update(self):
self.command(IL0373_DISPLAY_REFRESH)
while self._busy.value == False:
pass
while self._busy.value is False:
pass
self.command(IL0373_CDI, bytearray([0x17]))
self.command(IL0373_VCM_DC_SETTING, bytearray([0x00]))
@ -60,70 +61,72 @@ class Adafruit_IL0373(Adafruit_EPD):
def power_up(self):
self.command(IL0373_POWER_ON)
while self._busy.value == False:
pass
while self._busy.value is False:
pass
time.sleep(.2)
self.command(IL0373_PANEL_SETTING, bytearray([0xCF]))
self.command(IL0373_CDI, bytearray([0x37]))
self.command(IL0373_PLL, bytearray([0x29]))
b1 = self.height & 0xFF
b2 = (self.height >> 8) & 0xFF
b3 = self.width & 0xFF
b4 = (self.width >> 8) & 0xFF
self.command(IL0373_RESOLUTION, bytearray([b1, b2, b3, b4]))
_b1 = self.height & 0xFF
_b2 = (self.height >> 8) & 0xFF
_b3 = self.width & 0xFF
_b4 = (self.width >> 8) & 0xFF
self.command(IL0373_RESOLUTION, bytearray([_b1, _b2, _b3, _b4]))
self.command(IL0373_VCM_DC_SETTING, bytearray([0x0A]))
def display(self):
self.power_up()
while not self.spi_device.try_lock():
pass
self.sram.cs.value = False
pass
self.sram._cs.value = False
#send read command
self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_READ]))
#send start address
self.spi_device.write(bytearray([0x00, 0x00]))
self.spi_device.unlock()
#first data byte from SRAM will be transfered in at the same time as the EPD command is transferred out
c = self.command(IL0373_DTM1, end=False)
#first data byte from SRAM will be transfered in at the
#same time as the EPD command is transferred out
cmd = self.command(IL0373_DTM1, end=False)
while not self.spi_device.try_lock():
pass
pass
self._dc.value = True
xfer = bytearray([c])
xfer = bytearray([cmd])
outbuf = bytearray(1)
for i in range(self.bw_bufsize):
outbuf[0] = xfer[0]
self.spi_device.write_readinto(outbuf, xfer)
self._cs.value = True
self.sram.cs.value = True
self.sram._cs.value = True
time.sleep(.002)
self.sram.cs.value = False
self.sram._cs.value = False
#send read command
self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_READ]))
#send start address
self.spi_device.write(bytearray([(self.bw_bufsize >> 8), (self.bw_bufsize & 0xFF)]))
self.spi_device.unlock()
#first data byte from SRAM will be transfered in at the same time as the EPD command is transferred out
c = self.command(IL0373_DTM2, end=False)
#first data byte from SRAM will be transfered in at the
#same time as the EPD command is transferred out
cmd = self.command(IL0373_DTM2, end=False)
while not self.spi_device.try_lock():
pass
pass
self._dc.value = True
xfer = bytearray([c])
xfer = bytearray([cmd])
outbuf = bytearray(1)
for i in range(self.bw_bufsize):
outbuf[0] = xfer[0]
self.spi_device.write_readinto(outbuf, xfer)
self._cs.value = True
self.sram.cs.value = True
self.sram._cs.value = True
self.spi_device.unlock()
self.update()
@ -131,36 +134,37 @@ class Adafruit_IL0373(Adafruit_EPD):
def draw_pixel(self, x, y, color):
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
return
if x == 0:
x = 1
addr = int(((self.width - x) * self.height + y)/8)
if color == Adafruit_EPD.RED:
addr = addr + self.bw_bufsize
c = self.sram.read8(addr)
current = self.sram.read8(addr)
if color == Adafruit_EPD.WHITE:
c = c | (1 << (7 - y%8))
current = current | (1 << (7 - y%8))
elif color == Adafruit_EPD.RED or color == Adafruit_EPD.BLACK:
c = c & ~(1 << (7 - y%8))
current = current & ~(1 << (7 - y%8))
elif color == Adafruit_EPD.INVERSE:
c = c ^ (1 << (7 - y%8))
current = current ^ (1 << (7 - y%8))
self.sram.write8(addr, c)
self.sram.write8(addr, current)
return
def get_pixel(self, x, y, color):
if (x < 0) or (x >= self.width) or (y < 0) or (y >= self.height):
return
return None
if x == 0:
x = 1
addr = int(((self.width - x) * self.height + y)/8)
if color == Adafruit_EPD.RED:
addr = addr + self.bw_bufsize
c = self.sram.read8(addr)
return c
current = self.sram.read8(addr)
return current
def clear_buffer(self):
self.sram.erase(0x00, self.bw_bufsize, 0xFF)
@ -169,4 +173,3 @@ class Adafruit_IL0373(Adafruit_EPD):
def clear_display(self):
self.clear_buffer()
self.display()

View file

@ -1,77 +1,72 @@
import time
from micropython import const
import digitalio
from adafruit_bus_device.spi_device import SPIDevice
import busio
from board import *
SRAM_SEQUENTIAL_MODE = const(1 << 6)
class Adafruit_MCP_SRAM:
class Adafruit_MCP_SRAM(object):
SRAM_READ = 0x03
SRAM_WRITE = 0x02
SRAM_RDSR = 0x05
SRAM_WRSR = 0x01
SRAM_READ = 0x03
SRAM_WRITE = 0x02
SRAM_RDSR = 0x05
SRAM_WRSR = 0x01
def __init__(self, cs, spi):
# Handle hardware SPI
self.spi_device = spi
self.cs = cs
def __init__(self, cs_pin, spi):
# Handle hardware SPI
self.spi_device = spi
self._cs = cs_pin
self.cs.direction = digitalio.Direction.OUTPUT
while not self.spi_device.try_lock():
pass
self.cs.value = False
self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_WRSR, 0x43]))
self.cs.value = True
self.spi_device.unlock()
self._cs.direction = digitalio.Direction.OUTPUT
while not self.spi_device.try_lock():
pass
self._cs.value = False
self.spi_device.write(bytearray([Adafruit_MCP_SRAM.SRAM_WRSR, 0x43]))
self._cs.value = True
self.spi_device.unlock()
def write(self, addr, buf, reg=SRAM_WRITE):
c = bytearray([reg, (addr >> 8) & 0xFF, addr & 0xFF] + buf)
def write(self, addr, buf, reg=SRAM_WRITE):
cmd = bytearray([reg, (addr >> 8) & 0xFF, addr & 0xFF] + buf)
while not self.spi_device.try_lock():
pass
self.cs.value = False
self.spi_device.write(c)
self.cs.value = True
self.spi_device.unlock()
while not self.spi_device.try_lock():
pass
self._cs.value = False
self.spi_device.write(cmd)
self._cs.value = True
self.spi_device.unlock()
def read(self, addr, length, reg=SRAM_READ):
c = bytearray([reg, (addr >> 8) & 0xFF, addr & 0xFF])
buf = bytearray(length)
while not self.spi_device.try_lock():
pass
self.cs.value = False
self.spi_device.write(c)
self.spi_device.readinto(buf)
self.cs.value = True
self.spi_device.unlock()
return buf
def read(self, addr, length, reg=SRAM_READ):
cmd = bytearray([reg, (addr >> 8) & 0xFF, addr & 0xFF])
def read8(self, addr, reg=SRAM_READ):
return self.read(addr, 1, reg)[0]
buf = bytearray(length)
while not self.spi_device.try_lock():
pass
self._cs.value = False
self.spi_device.write(cmd)
self.spi_device.readinto(buf)
self._cs.value = True
self.spi_device.unlock()
return buf
def read16(self, addr, reg=SRAM_READ):
buf = self.read(addr, 2, reg)
return (buf[0] << 8 | buf[1])
def read8(self, addr, reg=SRAM_READ):
return self.read(addr, 1, reg)[0]
def write8(self, addr, value, reg=SRAM_WRITE):
self.write(addr, [value], reg)
def read16(self, addr, reg=SRAM_READ):
buf = self.read(addr, 2, reg)
return buf[0] << 8 | buf[1]
def write16(self, addr, value, reg=SRAM_WRITE):
self.write(addr, [value >> 8, value], reg)
def write8(self, addr, value, reg=SRAM_WRITE):
self.write(addr, [value], reg)
def erase(self, addr, length, value):
c = bytearray([Adafruit_MCP_SRAM.SRAM_WRITE, (addr >> 8) & 0xFF, addr & 0xFF])
def write16(self, addr, value, reg=SRAM_WRITE):
self.write(addr, [value >> 8, value], reg)
while not self.spi_device.try_lock():
pass
self.cs.value = False
self.spi_device.write(c)
for x in range(length):
self.spi_device.write(bytearray([value]))
self.cs.value = True
self.spi_device.unlock()
def erase(self, addr, length, value):
cmd = bytearray([Adafruit_MCP_SRAM.SRAM_WRITE, (addr >> 8) & 0xFF, addr & 0xFF])
while not self.spi_device.try_lock():
pass
self._cs.value = False
self.spi_device.write(cmd)
for x in range(length):
self.spi_device.write(bytearray([value]))
self._cs.value = True
self.spi_device.unlock()