Skip to content

Commit

Permalink
added for raspberry pi 5
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Jun 30, 2024
1 parent 6b25300 commit f913f64
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
14 changes: 9 additions & 5 deletions modules/display/display_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def detect_display():

def init_display(config):
# default dummy display

display = Display(config)

if not config.G_IS_RASPI:
Expand All @@ -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

Expand Down
59 changes: 59 additions & 0 deletions modules/display/mip_display_spidev.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f913f64

Please sign in to comment.