From f913f64d84a03b13d49e4ec2ea4399b8ecb890d5 Mon Sep 17 00:00:00 2001 From: hishizuka <12926652+hishizuka@users.noreply.github.com> Date: Sun, 30 Jun 2024 17:46:34 +0900 Subject: [PATCH] added for raspberry pi 5 --- modules/display/display_core.py | 14 ++++--- modules/display/mip_display_spidev.py | 59 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 modules/display/mip_display_spidev.py diff --git a/modules/display/display_core.py b/modules/display/display_core.py index 30be8eb7..292bd43c 100644 --- a/modules/display/display_core.py +++ b/modules/display/display_core.py @@ -119,7 +119,6 @@ def detect_display(): def init_display(config): # default dummy display - display = Display(config) if not config.G_IS_RASPI: @@ -137,13 +136,18 @@ def init_display(config): if _SENSOR_DISPLAY: display = PiTFT28r(config) elif config.G_DISPLAY.startswith("MIP_"): + # stop importing when a valid import is found from .mip_display_pigpio import _SENSOR_DISPLAY as _SENSOR_DISPLAY_PIGPIO, MipDisplayPigpio - from .mip_display_mraa import _SENSOR_DISPLAY as _SENSOR_DISPLAY_MRAA, MipDisplayMraa - if _SENSOR_DISPLAY_PIGPIO: display = MipDisplayPigpio(config, *SUPPORTED_DISPLAYS[config.G_DISPLAY]) - elif _SENSOR_DISPLAY_MRAA: - display = MipDisplayMraa(config, *SUPPORTED_DISPLAYS[config.G_DISPLAY]) + else: + from .mip_display_mraa import _SENSOR_DISPLAY as _SENSOR_DISPLAY_MRAA, MipDisplayMraa + if _SENSOR_DISPLAY_MRAA: + display = MipDisplayMraa(config, *SUPPORTED_DISPLAYS[config.G_DISPLAY]) + else: + from .mip_display_spidev import _SENSOR_DISPLAY as _SENSOR_DISPLAY_SPIDEV, MipDisplaySpidev + if _SENSOR_DISPLAY_SPIDEV: + display = MipDisplaySpidev(config, *SUPPORTED_DISPLAYS[config.G_DISPLAY]) elif config.G_DISPLAY == "Papirus": from .papirus_display import _SENSOR_DISPLAY, PapirusDisplay diff --git a/modules/display/mip_display_spidev.py b/modules/display/mip_display_spidev.py new file mode 100644 index 00000000..df050341 --- /dev/null +++ b/modules/display/mip_display_spidev.py @@ -0,0 +1,59 @@ +from .mip_display_base import MipDisplayBase + +from logger import app_logger + +_SENSOR_DISPLAY = False +try: + import spidev + import gpiod + + _SENSOR_DISPLAY = True +except ImportError: + pass + +if _SENSOR_DISPLAY: + app_logger.info(f"MIP DISPLAY(spidev): {_SENSOR_DISPLAY}") + + +class MipDisplaySpidev(MipDisplayBase): + chip = None + GPIO = {} + + def __init__(self, config, size=None, color=None): + super().__init__(config, size, color) + + def init_cython(self): + if self.color == 2: + self.conv_color = self.conv_1bit_color_py + elif self.color == 8: + self.conv_color = self.conv_3bit_color_py + if self.color == 64: + self.conv_color = self.conv_4bit_color_py + + def init_spi(self): + self.spi = spidev.SpiDev() + self.spi.open(0, 0) + self.spi.mode = 0b00 #SPI MODE0 + self.spi.max_speed_hz = self.config.G_DISPLAY_PARAM["SPI_CLOCK"] + self.spi.no_cs + + def init_gpio(self): + self.chip = gpiod.Chip('gpiochip4', gpiod.Chip.OPEN_BY_NAME) + for key in [self.DISP, self.SCS, self.VCOMSEL]: + self.GPIO[key] = self.chip.get_line(key) + self.GPIO[key].request(consumer="LED", type=gpiod.LINE_REQ_DIR_OUT) + + def init_backlight(self): + pass + + def spi_write(self, data): + self.spi.xfer3(data) + + def gpio_write(self, pin, value): + self.GPIO[pin].set_value(value) + + def set_PWM(self, value): + pass + + def spi_close(self): + self.spi.close()