diff --git a/GPi_Case2_patch_lakka3.6/install_patch.bat b/GPi_Case2_patch_lakka3.6/install_patch.bat new file mode 100644 index 0000000..dba056f --- /dev/null +++ b/GPi_Case2_patch_lakka3.6/install_patch.bat @@ -0,0 +1,32 @@ +@echo off + +set Pan=.\ +set OrgFolder=original_files\ +set OverlaysFolder=overlays\ +set ConfigFile=config.txt +set Dpi24File=dpi24.dtbo + +if exist %Pan%%OrgFolder%%ConfigFile% ( + echo config.txt is backuped +) else ( + copy .\..\config.txt .\original_files\config.txt +) + +::if exist %Pan%%OrgFolder%%OverlaysFolder%%Dpi24File% ( +:: echo dpi24.dtbo is backuped +::) else ( +:: copy .\..\overlays\dpi24.dtbo .\original_files\overlays\dpi24.dtbo +::) + +copy .\patch_files\config.txt .\..\config.txt +copy .\patch_files\config_lcd.txt .\..\config_lcd.txt +copy .\patch_files\config_hdmi.txt .\..\config_hdmi.txt +::copy .\patch_files\overlays\dpi24.dtbo .\..\overlays\dpi24.dtbo +::copy .\patch_files\overlays\pwm-audio-pi-zero.dtbo .\..\overlays\pwm-audio-pi-zero.dtbo + +echo . +echo -----------------------Successful configuration----------------------- +echo . + + +pause \ No newline at end of file diff --git a/GPi_Case2_patch_lakka3.6/patch_files/config.txt b/GPi_Case2_patch_lakka3.6/patch_files/config.txt new file mode 100644 index 0000000..909183a --- /dev/null +++ b/GPi_Case2_patch_lakka3.6/patch_files/config.txt @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv) +# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv) +################################################################################ +# Bootloader configuration - config.txt +################################################################################ + +################################################################################ +# Memory (System/GPU configuration ) +################################################################################ + +# Default GPU memory split - at least 288M is needed for some 4k HEVC files +gpu_mem=384 + +################################################################################ +# For overclocking and various other settings, see: +# https://www.raspberrypi.org/documentation/configuration/config-txt.md +################################################################################ +# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always. +force_turbo=0 + +# Force HDMI even if unplugged or powered off +# hdmi_force_hotplug=1 + +# Doesn't sent initial active source message. +# Avoids bringing CEC (enabled TV) out of standby and channel switch when +# rebooting. +hdmi_ignore_cec_init=1 + +################################################################################ +# End of default configuration +################################################################################ + +# Choose between DVI and HDMI output +# 1 = DVI mode (no sound) +# 2 = HDMI mode (sound will be sent if supported and enabled) +# hdmi_drive=2 + +################################################################################ +# Include distribution specific config file if it exists. +################################################################################ +[all] +# Enable DRM VC4 V3D driver on top of the dispmanx display stack +# Preferred 'Full' Kernel Mode Setting (KMS) +# dtoverlay=vc4-kms-v3d-pi4 +# Optional 'Fake' KMS for displays that won't work with 'Full' KMS +dtoverlay=vc4-fkms-v3d + +dtoverlay=rpivid-v4l2 +disable_overscan=1 +disable_splash=1 +dtparam=audio=on +hdmi_max_pixel_freq:0=200000000 +hdmi_max_pixel_freq:1=200000000 +arm_64bit=1 +kernel=kernel.img + +# if you plug your tv at the same time as your rpi and that the rpi switches from the hdmi or give a low resolution because tv had no enough time to initialize it +# boot_delay=3 + +# uncomment if you have slow sound issues on composite output +#audio_pwm_mode=0 + +# enable UART (required for for retroflag) +# affect rpi performances +# enable_uart=1 + +# activate USB sockets +dtoverlay=dwc2,dr_mode=host + +# Ensure only one display output can be used on the Pi4 +max_framebuffers=1 + +[DPI] +# Put any DPI required display code here +# i.e. Official 7" DSI Raspberry Pi Touch Display for 'Full' KMS +#ignore_lcd=1 +#dtoverlay=vc4-kms-dsi-7inch +display_rotate=0 +dtoverlay=dpi24 +overscan_left=0 +overscan_right=0 +overscan_top=0 +overscan_bottom=0 +framebuffer_width=640 +framebuffer_height=480 +#framebuffer_depth=8 +enable_dpi_lcd=1 +display_default_lcd=1 +dpi_group=2 +dpi_mode=87 +dpi_output_format=0x00016 +hdmi_timings=640 0 41 40 41 480 0 18 9 18 0 0 0 60 0 24000000 1 #80hz +#hdmi_timings=640 0 20 1 20 480 0 1 1 2 0 0 0 60 0 24000000 1 #59hz + diff --git a/GPi_Case2_patch_lakka3.6/patch_files/config_hdmi.txt b/GPi_Case2_patch_lakka3.6/patch_files/config_hdmi.txt new file mode 100644 index 0000000..90f2e0f --- /dev/null +++ b/GPi_Case2_patch_lakka3.6/patch_files/config_hdmi.txt @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv) +# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv) +################################################################################ +# Bootloader configuration - config.txt +################################################################################ + +################################################################################ +# Memory (System/GPU configuration ) +################################################################################ + +# Default GPU memory split - at least 288M is needed for some 4k HEVC files +gpu_mem=384 + +################################################################################ +# For overclocking and various other settings, see: +# https://www.raspberrypi.org/documentation/configuration/config-txt.md +################################################################################ +# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always. +force_turbo=0 + +# Force HDMI even if unplugged or powered off +# hdmi_force_hotplug=1 + +# Doesn't sent initial active source message. +# Avoids bringing CEC (enabled TV) out of standby and channel switch when +# rebooting. +hdmi_ignore_cec_init=1 + +################################################################################ +# End of default configuration +################################################################################ + +# Choose between DVI and HDMI output +# 1 = DVI mode (no sound) +# 2 = HDMI mode (sound will be sent if supported and enabled) +# hdmi_drive=2 + +################################################################################ +# Include distribution specific config file if it exists. +################################################################################ +[all] +include distroconfig.txt + +# activate USB sockets +dtoverlay=dwc2,dr_mode=host diff --git a/GPi_Case2_patch_lakka3.6/patch_files/config_lcd.txt b/GPi_Case2_patch_lakka3.6/patch_files/config_lcd.txt new file mode 100644 index 0000000..909183a --- /dev/null +++ b/GPi_Case2_patch_lakka3.6/patch_files/config_lcd.txt @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv) +# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv) +################################################################################ +# Bootloader configuration - config.txt +################################################################################ + +################################################################################ +# Memory (System/GPU configuration ) +################################################################################ + +# Default GPU memory split - at least 288M is needed for some 4k HEVC files +gpu_mem=384 + +################################################################################ +# For overclocking and various other settings, see: +# https://www.raspberrypi.org/documentation/configuration/config-txt.md +################################################################################ +# Set 'force_turbo=1' to disable dynamic overclocking and enable overclocking always. +force_turbo=0 + +# Force HDMI even if unplugged or powered off +# hdmi_force_hotplug=1 + +# Doesn't sent initial active source message. +# Avoids bringing CEC (enabled TV) out of standby and channel switch when +# rebooting. +hdmi_ignore_cec_init=1 + +################################################################################ +# End of default configuration +################################################################################ + +# Choose between DVI and HDMI output +# 1 = DVI mode (no sound) +# 2 = HDMI mode (sound will be sent if supported and enabled) +# hdmi_drive=2 + +################################################################################ +# Include distribution specific config file if it exists. +################################################################################ +[all] +# Enable DRM VC4 V3D driver on top of the dispmanx display stack +# Preferred 'Full' Kernel Mode Setting (KMS) +# dtoverlay=vc4-kms-v3d-pi4 +# Optional 'Fake' KMS for displays that won't work with 'Full' KMS +dtoverlay=vc4-fkms-v3d + +dtoverlay=rpivid-v4l2 +disable_overscan=1 +disable_splash=1 +dtparam=audio=on +hdmi_max_pixel_freq:0=200000000 +hdmi_max_pixel_freq:1=200000000 +arm_64bit=1 +kernel=kernel.img + +# if you plug your tv at the same time as your rpi and that the rpi switches from the hdmi or give a low resolution because tv had no enough time to initialize it +# boot_delay=3 + +# uncomment if you have slow sound issues on composite output +#audio_pwm_mode=0 + +# enable UART (required for for retroflag) +# affect rpi performances +# enable_uart=1 + +# activate USB sockets +dtoverlay=dwc2,dr_mode=host + +# Ensure only one display output can be used on the Pi4 +max_framebuffers=1 + +[DPI] +# Put any DPI required display code here +# i.e. Official 7" DSI Raspberry Pi Touch Display for 'Full' KMS +#ignore_lcd=1 +#dtoverlay=vc4-kms-dsi-7inch +display_rotate=0 +dtoverlay=dpi24 +overscan_left=0 +overscan_right=0 +overscan_top=0 +overscan_bottom=0 +framebuffer_width=640 +framebuffer_height=480 +#framebuffer_depth=8 +enable_dpi_lcd=1 +display_default_lcd=1 +dpi_group=2 +dpi_mode=87 +dpi_output_format=0x00016 +hdmi_timings=640 0 41 40 41 480 0 18 9 18 0 0 0 60 0 24000000 1 #80hz +#hdmi_timings=640 0 20 1 20 480 0 1 1 2 0 0 0 60 0 24000000 1 #59hz + diff --git a/GPi_Case2_patch_lakka3.6/uninstall_patch.bat b/GPi_Case2_patch_lakka3.6/uninstall_patch.bat new file mode 100644 index 0000000..8262e60 --- /dev/null +++ b/GPi_Case2_patch_lakka3.6/uninstall_patch.bat @@ -0,0 +1,37 @@ +@echo off + +set Pan=.\ +set UpFolder=..\ +set OrgFolder=original_files\ +set OverlaysFolder=overlays\ +set ConfigFile=config.txt +set Dpi24File=dpi24.dtbo +set PwmAudiFile=pwm-audio-pi-zero.dtbo + +if exist %Pan%%OrgFolder%%ConfigFile% ( + copy .\original_files\config.txt .\..\config.txt +) else ( + echo .\original_files\config.txt is not exist +) + +::if exist %Pan%%OrgFolder%%OverlaysFolder%%Dpi24File% ( +:: copy .\original_files\overlays\dpi24.dtbo .\..\overlays\dpi24.dtbo +:: echo . +:: echo -----------------------Successful configuration----------------------- +:: echo . +::) else ( +:: echo .\original_files\overlays\dpi24.dtbo is not exist +::) + +::if exist %Pan%%UpFolder%%OverlaysFolder%%PwmAudiFile% ( +:: del .\..\overlays\pwm-audio-pi-zero.dtbo +::) +if exist %Pan%%UpFolder%%ConfigHDMIFile% ( + del .\..\config_hdmi.txt + del .\..\config_lcd.txt +) + echo . + echo -----------------------Successful configuration----------------------- + echo . + +pause \ No newline at end of file diff --git a/lakka_SafeShutdown_gpi2.py b/lakka_SafeShutdown_gpi2.py new file mode 100644 index 0000000..72d3524 --- /dev/null +++ b/lakka_SafeShutdown_gpi2.py @@ -0,0 +1,61 @@ +import RPi.GPIO as GPIO +import os +import time +from multiprocessing import Process + +#initialize pins +#powerPin = 3 #pin 5 +#ledPin = 14 #TXD +#resetPin = 2 #pin 13 +#powerenPin = 4 #pin 5 + +powerPin = 26 +powerenPin = 27 + +#initialize GPIO settings +def init(): + GPIO.setmode(GPIO.BCM) + GPIO.setup(powerPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) + GPIO.setup(powerenPin, GPIO.OUT, initial=GPIO.HIGH) + GPIO.output(powerenPin, GPIO.HIGH) + GPIO.setwarnings(False) + +#waits for user to hold button up to 1 second before issuing poweroff command +def poweroff(): + while True: + #self.assertEqual(GPIO.input(powerPin), GPIO.LOW) + GPIO.wait_for_edge(powerPin, GPIO.FALLING) + #start = time.time() + #while GPIO.input(powerPin) == GPIO.HIGH: + # time.sleep(0.5) + os.system("systemctl stop retroarch") + time.sleep(1) + os.system("systemctl poweroff") + +def lcdrun(): + while True: + os.system("sh /storage/.RetroFlag/lcdnext.sh") + time.sleep(1) + +def audiofix(): + while True: + time.sleep(0.5) + os.system("systemctl restart retroarch") + break + +if __name__ == "__main__": + #initialize GPIO settings + init() + #create a multiprocessing.Process instance for each function to enable parallelism + powerProcess = Process(target = poweroff) + powerProcess.start() + lcdrunProcess = Process(target = lcdrun) + lcdrunProcess.start() + audiofixProcess = Process(target = audiofix) + audiofixProcess.start() + + powerProcess.join() + lcdrunProcess.join() + audiofixProcess.join() + + GPIO.cleanup() diff --git a/lakka_install_gpi2.sh b/lakka_install_gpi2.sh new file mode 100644 index 0000000..201d2c2 --- /dev/null +++ b/lakka_install_gpi2.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# Step 1) Check if root #################################### +if [[ $EUID -ne 0 ]]; then + echo "Please execute script as root." + exit 1 +fi +#----------------------------------------------------------- + +SourcePath=https://gitee.com/clock333mhz/GPiCase2-Script/raw/cn_main + +#----------------------------------------------------------- +sleep 2s + +mount -o remount, rw /flash +mount -o remount, rw / + +#Download Python script----------------------------- +mkdir /storage/.RetroFlag/ +sleep 2s +script=/storage/.RetroFlag/SafeShutdown.py + +wget -O $script "$SourcePath/lakka_SafeShutdown_gpi2.py" +wget -O "/storage/.RetroFlag/lcdfirst.sh" "$SourcePath/lakkalcdfirst.sh" +wget -O "/storage/.RetroFlag/lcdnext.sh" "$SourcePath/lakkalcdnext.sh" +#----------------------------------------------------------- + +sleep 2s +# DIR=/userdata/system/custom.sh +DIR=/storage/.config/autostart.sh + +if grep -q "python $script &" "$DIR"; + then + if [ -x "$DIR" ]; + then + echo "Executable script already configured. Doing nothing." + else + chmod +x $DIR + fi + else + echo "python $script & sh /storage/.RetroFlag/lcdfirst.sh" >> $DIR + chmod +x $DIR + chmod +x /storage/.RetroFlag/lcdfirst.sh + chmod +x /storage/.RetroFlag/lcdnext.sh + echo "Executable script configured." +fi +#----------------------------------------------------------- + +echo "RetroFlag Pi Case Switch installation done. Will now reboot after 3 seconds." +sleep 3 +systemctl reboot +#----------------------------------------------------------- diff --git a/lakkalcdfirst.sh b/lakkalcdfirst.sh new file mode 100644 index 0000000..1519dfb --- /dev/null +++ b/lakkalcdfirst.sh @@ -0,0 +1,41 @@ + +HDMI_HPD=18 + +echo $HDMI_HPD > /sys/class/gpio/export +echo in > /sys/class/gpio/gpio18/direction + +HDMI_HPD_VALUE=$(cat /sys/class/gpio/gpio$HDMI_HPD/value) + +echo "HDMI_HPD_VALUE1=""$HDMI_HPD_VALUE" + +if grep -q "enable_dpi_lcd=1" "/flash/config.txt" ; then + ISLCDFILE="1" +else + ISLCDFILE="0" +fi + +echo "ISLCDFILE=""$ISLCDFILE" +if [ "1" = $HDMI_HPD_VALUE ]; then + if [ "1" = $ISLCDFILE ]; then + mount -o remount, rw /flash + # mount -o remount, rw / + # rm -f /flash/config_lcd.txt + # \cp -f "/flash/config.txt" "/flash/config_lcd.txt" + # rm -f /flash/config.txt + \cp -f "/flash/config_hdmi.txt" "/flash/config.txt" + systemctl reboot + sleep 10 + fi +else + if [ "0" = $ISLCDFILE ]; then + mount -o remount, rw /flash + # mount -o remount, rw / + # rm -f /flash/config_hdmi.txt + # \cp -f "flash/config.txt" "/boot/config_hdmi.txt" + # rm -f /flash/config.txt + \cp -f "/flash/config_lcd.txt" "/flash/config.txt" + systemctl reboot + sleep 10 + fi +fi + \ No newline at end of file diff --git a/lakkalcdnext.sh b/lakkalcdnext.sh new file mode 100644 index 0000000..9eb5dc2 --- /dev/null +++ b/lakkalcdnext.sh @@ -0,0 +1,34 @@ + +HDMI_HPD=18 +echo 18 > /sys/class/gpio/export +echo in > /sys/class/gpio/gpio18/direction + +HDMI_HPD_VALUE=$(cat /sys/class/gpio/gpio18/value) +echo "HDMI_HPD_VALUE2=""$HDMI_HPD_VALUE" + +if grep -q "enable_dpi_lcd=1" "/flash/config.txt" ; then + ISLCDFILE="1" +else + ISLCDFILE="0" +fi +echo "ISLCDFILE1=""$ISLCDFILE" + if [ "1" = $HDMI_HPD_VALUE ]; then + if [ "1" = $ISLCDFILE ]; then + mount -o remount, rw /flash + # mount -o remount, rw / + # rm -f /flash/config_lcd.txt + # \cp -f "/flash/config.txt" "/flasht/config_lcd.txt" + # rm -f /flash/config.txt + \cp -f "/flash/config_hdmi.txt" "/flash/config.txt" + fi + else + if [ "0" = $ISLCDFILE ]; then + mount -o remount, rw /flash + # mount -o remount, rw / + # rm -f /flash/config_hdmi.txt + # \cp -f "/flash/config.txt" "/flash/config_hdmi.txt" + # rm -f /flash/config.txt + \cp -f "/flash/config_lcd.txt" "/flash/config.txt" + fi + fi +