From dfa74b004198794d01bdc461ea88d1cf9cdb80b5 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Wed, 2 Aug 2023 17:02:48 +0200 Subject: [PATCH] Implementation for CI 20 --- .../python/lib/waveshare_epd/epdconfig.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py b/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py index f692f43..6a57f26 100644 --- a/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py +++ b/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epdconfig.py @@ -230,6 +230,89 @@ class SunriseX3: self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN) +class CreatorCI20: + # Pin definition + RST_PIN = 122 + DC_PIN = 136 + CS_PIN = 0 + BUSY_PIN = 162 + PWR_PIN = 18 + Flag = 0 + + def __init__(self): + import spidev + + self.SPI = spidev.SpiDev() + + def digital_write(self, pin, value): + if pin == 0: + return + + with open("/sys/class/gpio/gpio"+str(pin)+"/value", "w") as f: + f.write(str(value)) + + def digital_read(self, pin): + v = "0" + if pin != 0: + with open("/sys/class/gpio/gpio"+str(pin)+"/value") as f: + v = f.readline() + return int(v) + + def delay_ms(self, delaytime): + time.sleep(delaytime / 1000.0) + + def spi_writebyte(self, data): + self.SPI.writebytes(data) + + def spi_writebyte2(self, data): + # for i in range(len(data)): + # self.SPI.writebytes([data[i]]) + self.SPI.xfer3(data) + + def module_init(self): + if self.Flag == 0: + self.Flag = 1 + + # BUSY + with open("/sys/class/gpio/export", "w") as f: + f.write(str(self.BUSY_PIN)) + + # RST + with open("/sys/class/gpio/export", "w") as f: + f.write(str(self.RST_PIN)) + with open("/sys/class/gpio/gpio" + str(self.RST_PIN) + "/direction", "w") as f: + f.write("out") + + # DC + with open("/sys/class/gpio/export", "w") as f: + f.write(str(self.DC_PIN)) + with open("/sys/class/gpio/gpio" + str(self.DC_PIN) + "/direction", "w") as f: + f.write("out") + + # SPI device, bus = 0, device = 0 + self.SPI.open(32766, 0) + self.SPI.max_speed_hz = 4000000 + self.SPI.mode = 0b00 + return 0 + else: + return 0 + + def module_exit(self): + logger.debug("spi end") + self.SPI.close() + + logger.debug("close 5V, Module enters 0 power consumption ...") + self.Flag = 0 + + self.digital_write(self.RST_PIN, 0) + self.digital_write(self.DC_PIN, 0) + + # Clean up + for pin in [self.BUSY_PIN, self.RST_PIN, self.DC_PIN] + with open("/sys/class/gpio/unexport", "w") as f: + f.write(str(pin)) + + if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'): implementation = RaspberryPi() elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'):