Skip to content

Instantly share code, notes, and snippets.

@xerpi
Last active May 15, 2021 14:52
Show Gist options
  • Save xerpi/400fabaa0c363e9541f552e66996d5fd to your computer and use it in GitHub Desktop.
Save xerpi/400fabaa0c363e9541f552e66996d5fd to your computer and use it in GitHub Desktop.
1.54" LCD Raspberry Pi Zero
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
spidev@0{
status = "disabled";
};
spidev@1{
status = "disabled";
};
};
};
fragment@1 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <22 27>;
brcm,function = <1 1>; /* out */
brcm,pull = <0>; /* none */
};
};
};
fragment@2 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft@0{
compatible = "sitronix,st7789v";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <48000000>;
rotate = <270>;
width = <240>;
height = <240>;
fps = <30>;
buswidth = <8>;
txbuflen = <32768>;
custom = <1>;
reset-gpios = <&gpio 27 1>;
dc-gpios = <&gpio 22 0>;
debug = <0>;
spi-cpol;
spi-cpha;
bgr;
init = <0x1000011
0x20000ff
0x100003A 0x55
0x10000C0 0x0C
0x1000021
0x1000029
>;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0";
width = <&pitft>,"width:0";
height = <&pitft>,"height:0";
fps = <&pitft>,"fps:0";
debug = <&pitft>,"debug:0";
};
};
#SUBSYSTEM=="input", GROUP="input", MODE="0660"
#KERNEL=="tty[0-9]*", GROUP="tty", MODE="0660"
#KERNEL=="hidraw*", GROUP="input", MODE="0660"
# Needed for permissions set correctly for /dev/input/event* for keyboard input
#SUBSYSTEM=="input", ATTRS{name}=="input/%k", KERNEL=="event*", MODE="0666", ENV{ID_INPUT_KEYBOARD}="1"
#SUBSYSTEM=="input", ATTRS{name}=="gpio_keys", ENV{ID_INPUT_KEYBOARD}="1"
KERNEL=="event*", SUBSYSTEM=="input", GROUP="input", MODE="0660", ENV{ID_INPUT_KEYBOARD}="1"
gpu_mem=32
#cma_lwm=16
#cma_hwm=256
dtoverlay=vc4-fkms-v3d,cma-256
initramfs initramfs-linux.img followkernel
#dtoverlay=dwc2
#dtoverlay=1-54inchlcd
# GPIO buttons
dtoverlay=gpio-key,gpio=3,active_low=1,gpio_pull=up,label=center,keycode=28
dtoverlay=gpio-key,gpio=5,active_low=1,gpio_pull=up,label=up,keycode=103
dtoverlay=gpio-key,gpio=16,active_low=1,gpio_pull=up,label=down,keycode=108
dtoverlay=gpio-key,gpio=13,active_low=1,gpio_pull=up,label=left,keycode=105
dtoverlay=gpio-key,gpio=6,active_low=1,gpio_pull=up,label=right,keycode=106
dtoverlay=gpio-key,gpio=12,active_low=1,gpio_pull=up,label=y,keycode=21
dtoverlay=gpio-key,gpio=20,active_low=1,gpio_pull=up,label=b,keycode=48
dtoverlay=gpio-key,gpio=15,active_low=1,gpio_pull=up,label=x,keycode=45
dtoverlay=gpio-key,gpio=21,active_low=1,gpio_pull=up,label=a,keycode=30
dtoverlay=gpio-key,gpio=19,active_low=1,gpio_pull=up,label=start,keycode=14
dtoverlay=gpio-key,gpio=26,active_low=1,gpio_pull=up,label=select,keycode=1
dtoverlay=gpio-key,gpio=23,active_low=1,gpio_pull=up,label=ltrigger,keycode=16
dtoverlay=gpio-key,gpio=14,active_low=1,gpio_pull=up,label=rtrigger,keycode=18
enable_uart=0
hdmi_force_hotplug=1
max_usb_current=1
hdmi_group=2
hdmi_mode=9
hdmi_mode=87
hdmi_cvt 240 240 60 1 0 0 0
hdmi_drive=2
[Unit]
Description=FB Copy SPI LCD displays
#After=graphical.target
ConditionKernelCommandLine=!fbcp=0
#Requires=graphical.target
[Service]
User=root
PermissionsStartOnly=true
#Environment=HOME=/home/alarm
ExecStart=/home/alarm/fbcp-ili9341/build/fbcp-ili9341
# keep KillMode=process unless there is no good reason to switch to cgroup
KillMode=process
TimeoutStopSec=10
Restart=always
RestartSec=2
StartLimitInterval=0
[Install]
WantedBy=fbcp.target
WantedBy=multi-user.target
# Using https://github.com/juj/fbcp-ili9341:
cmake -DST7789VW=ON -DGPIO_TFT_DATA_CONTROL=22 -DGPIO_TFT_RESET_PIN=27 -DUSE_DMA_TRANSFERS=ON -DSPI_BUS_CLOCK_DIVISOR=20 -DDISPLAY_ROTATE_180_DEGREES=ON -DSTATISTICS=0 ..
# (or using Linux kernel driver "sitronix,st7789v"):
cd /boot/overlays
dtc -I dts -O dtb -o 1-54inchlcd.dtbo 1-54inchlcd.dto
sudo usermod -a -G audio,video,input,dialout,plugdev,tty alarm
# Retroarch: ~/.config/retroarch/retroarch.cfg
libretro_directory = "~/.config/retroarch/cores/"
libretro_info_path = "~/.config/retroarch/cores/info"
core_updater_buildbot_cores_url = "http://buildbot.libretro.com/nightly/linux/armhf/latest/"
core_updater_show_experimental_cores = "true"
video_context_driver = "KMS"
# Explanation: https://unix.stackexchange.com/a/506374
[Unit]
Description=Retroarch
#After=graphical.target
ConditionKernelCommandLine=!retroarch=0
#Requires=graphical.target
Requires=fbcp.service
[Service]
User=alarm
PermissionsStartOnly=true
#Environment=HOME=/home/alarm
ExecStart=/usr/bin/retroarch
# keep KillMode=process unless there is no good reason to switch to cgroup
KillMode=process
TimeoutStopSec=10
Restart=always
RestartSec=2
StartLimitInterval=0
[Install]
WantedBy=retroarch.target
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment