Implementation for CI 20

This commit is contained in:
nemunaire 2023-08-02 17:02:48 +02:00
parent fc4f54334d
commit dfa74b0041

View File

@ -230,6 +230,89 @@ class SunriseX3:
self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN) 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'): if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
implementation = RaspberryPi() implementation = RaspberryPi()
elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'): elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'):