Consolidate repeated functions

This commit is contained in:
missionfloyd 2021-02-24 22:31:05 -07:00
commit c586f8d0f7
38 changed files with 2001 additions and 2881 deletions

View file

@ -36,10 +36,7 @@ EPD_HEIGHT = 296
class EPD:
def __init__(self):
self.reset_pin = epdconfig.RST_PIN
self.dc_pin = epdconfig.DC_PIN
self.busy_pin = epdconfig.BUSY_PIN
self.cs_pin = epdconfig.CS_PIN
self.width = EPD_WIDTH
self.height = EPD_HEIGHT
@ -57,94 +54,73 @@ class EPD:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x13, 0x14, 0x44, 0x12,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]
# Hardware reset
def reset(self):
epdconfig.digital_write(self.reset_pin, 1)
epdconfig.delay_ms(200)
epdconfig.digital_write(self.reset_pin, 0)
epdconfig.delay_ms(5)
epdconfig.digital_write(self.reset_pin, 1)
epdconfig.delay_ms(200)
def send_command(self, command):
epdconfig.digital_write(self.dc_pin, 0)
epdconfig.digital_write(self.cs_pin, 0)
epdconfig.spi_writebyte([command])
epdconfig.digital_write(self.cs_pin, 1)
def send_data(self, data):
epdconfig.digital_write(self.dc_pin, 1)
epdconfig.digital_write(self.cs_pin, 0)
epdconfig.spi_writebyte([data])
epdconfig.digital_write(self.cs_pin, 1)
]
def ReadBusy(self):
while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
epdconfig.delay_ms(200)
def TurnOnDisplay(self):
self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
self.send_data(0xC4)
self.send_command(0x20) # MASTER_ACTIVATION
self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE
epdconfig.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
epdconfig.send_data(0xC4)
epdconfig.send_command(0x20) # MASTER_ACTIVATION
epdconfig.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE
logging.debug("e-Paper busy")
self.ReadBusy()
logging.debug("e-Paper busy release")
def SetWindow(self, x_start, y_start, x_end, y_end):
self.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
epdconfig.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
# x point must be the multiple of 8 or the last 3 bits will be ignored
self.send_data((x_start >> 3) & 0xFF)
self.send_data((x_end >> 3) & 0xFF)
self.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
self.send_data(y_start & 0xFF)
self.send_data((y_start >> 8) & 0xFF)
self.send_data(y_end & 0xFF)
self.send_data((y_end >> 8) & 0xFF)
epdconfig.send_data((x_start >> 3) & 0xFF)
epdconfig.send_data((x_end >> 3) & 0xFF)
epdconfig.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
epdconfig.send_data(y_start & 0xFF)
epdconfig.send_data((y_start >> 8) & 0xFF)
epdconfig.send_data(y_end & 0xFF)
epdconfig.send_data((y_end >> 8) & 0xFF)
def SetCursor(self, x, y):
self.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
epdconfig.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
# x point must be the multiple of 8 or the last 3 bits will be ignored
self.send_data((x >> 3) & 0xFF)
self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
self.send_data(y & 0xFF)
self.send_data((y >> 8) & 0xFF)
epdconfig.send_data((x >> 3) & 0xFF)
epdconfig.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
epdconfig.send_data(y & 0xFF)
epdconfig.send_data((y >> 8) & 0xFF)
self.ReadBusy()
def init(self, lut):
if (epdconfig.module_init() != 0):
return -1
# EPD hardware init start
self.reset()
epdconfig.reset(200, 5, 200)
self.send_command(0x01) # DRIVER_OUTPUT_CONTROL
self.send_data((EPD_HEIGHT - 1) & 0xFF)
self.send_data(((EPD_HEIGHT - 1) >> 8) & 0xFF)
self.send_data(0x00) # GD = 0 SM = 0 TB = 0
epdconfig.send_command(0x01) # DRIVER_OUTPUT_CONTROL
epdconfig.send_data((EPD_HEIGHT - 1) & 0xFF)
epdconfig.send_data(((EPD_HEIGHT - 1) >> 8) & 0xFF)
epdconfig.send_data(0x00) # GD = 0 SM = 0 TB = 0
self.send_command(0x0C) # BOOSTER_SOFT_START_CONTROL
self.send_data(0xD7)
self.send_data(0xD6)
self.send_data(0x9D)
epdconfig.send_command(0x0C) # BOOSTER_SOFT_START_CONTROL
epdconfig.send_data(0xD7)
epdconfig.send_data(0xD6)
epdconfig.send_data(0x9D)
self.send_command(0x2C) # WRITE_VCOM_REGISTER
self.send_data(0xA8) # VCOM 7C
epdconfig.send_command(0x2C) # WRITE_VCOM_REGISTER
epdconfig.send_data(0xA8) # VCOM 7C
self.send_command(0x3A) # SET_DUMMY_LINE_PERIOD
self.send_data(0x1A) # 4 dummy lines per gate
epdconfig.send_command(0x3A) # SET_DUMMY_LINE_PERIOD
epdconfig.send_data(0x1A) # 4 dummy lines per gate
self.send_command(0x3B) # SET_GATE_TIME
self.send_data(0x08) # 2us per line
epdconfig.send_command(0x3B) # SET_GATE_TIME
epdconfig.send_data(0x08) # 2us per line
self.send_command(0x11) # DATA_ENTRY_MODE_SETTING
self.send_data(0x03) # X increment Y increment
epdconfig.send_command(0x11) # DATA_ENTRY_MODE_SETTING
epdconfig.send_data(0x03) # X increment Y increment
self.send_command(0x32) # WRITE_LUT_REGISTER
epdconfig.send_command(0x32) # WRITE_LUT_REGISTER
for i in range(0, len(lut)):
self.send_data(lut[i])
epdconfig.send_data(lut[i])
# EPD hardware init end
return 0
@ -178,23 +154,23 @@ class EPD:
self.SetWindow(0, 0, self.width - 1, self.height - 1)
for j in range(0, self.height):
self.SetCursor(0, j)
self.send_command(0x24) # WRITE_RAM
epdconfig.send_command(0x24) # WRITE_RAM
for i in range(0, int(self.width / 8)):
self.send_data(image[i + j * int(self.width / 8)])
epdconfig.send_data(image[i + j * int(self.width / 8)])
self.TurnOnDisplay()
def Clear(self, color):
self.SetWindow(0, 0, self.width - 1, self.height - 1)
for j in range(0, self.height):
self.SetCursor(0, j)
self.send_command(0x24) # WRITE_RAM
epdconfig.send_command(0x24) # WRITE_RAM
for i in range(0, int(self.width / 8)):
self.send_data(color)
epdconfig.send_data(color)
self.TurnOnDisplay()
def sleep(self):
self.send_command(0x10) # DEEP_SLEEP_MODE
self.send_data(0x01)
epdconfig.send_command(0x10) # DEEP_SLEEP_MODE
epdconfig.send_data(0x01)
epdconfig.delay_ms(2000)
epdconfig.module_exit()