Last active
November 12, 2025 00:20
-
-
Save Langerz82/08efbafd25eee661b3e948b0e7ed6c66 to your computer and use it in GitHub Desktop.
EE4.3 - setres.sh exaplained for cvbs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # SPDX-License-Identifier: GPL-2.0-or-later | |
| # Copyright (C) 2019-present Shanti Gilbert (https://github.com/shantigilbert) | |
| # Read the video output mode and set it for emuelec to avoid video flicking. | |
| # This file sets the hdmi output and frame buffer to the argument in pixel width. | |
| # Allowed argument example ./setres.sh 1080p60hz <-- For height 1080 pixels. | |
| # set -x #echo on | |
| # 1080p60hz | |
| # 1080i60hz | |
| # 720p60hz | |
| # 720p50hz | |
| # 480p60hz | |
| # 480cvbs | |
| # 576p50hz | |
| # 1080p50hz | |
| # 1080i50hz | |
| # 576cvbs | |
| # arg1, 1 = Hides, 0 = Show. | |
| show_buffer () | |
| { | |
| echo $1 > /sys/class/graphics/fb0/blank | |
| echo $1 > /sys/class/graphics/fb1/blank | |
| } | |
| blank_buffer() | |
| { | |
| # Blank the buffer. | |
| dd if=/dev/zero of=/dev/fb0 bs=12M > /dev/null 2>&1 | |
| } | |
| BPP=32 | |
| HZ=60 | |
| MODE=$1 | |
| CUR_MODE=`cat /sys/class/display/mode`; | |
| # If the current display is the same as the change just exit. | |
| [ -z "$MODE" ] && exit 0; | |
| [[ $MODE == "auto" ]] && exit 0; | |
| # Removed because if try to set invalid video mode it becomes a valid MODE | |
| # in display/mode and then when trying to revert back this becomes true exiting. | |
| #[[ "$MODE" == "$CUR_MODE" ]] && exit 0; | |
| if [[ ! "$MODE" == *"x"* ]]; then | |
| case $MODE in | |
| *p*) H=$(echo $MODE | cut -d'p' -f 1) ;; | |
| *i*) H=$(echo $MODE | cut -d'i' -f 1) ;; | |
| *cvbs*) H=$(echo $MODE | cut -d'c' -f 1) ;; | |
| esac | |
| fi | |
| HZ=${MODE:(-4):2} | |
| if [[ ! -n "$HZ" ]] || [[ $HZ -eq 50 ]]; then | |
| HZ=60 | |
| fi | |
| # hides buffer | |
| show_buffer 1 | |
| echo null > /sys/class/display/mode | |
| FBW=1024 | |
| FBH=768 | |
| case $MODE in | |
| 480p*hz|480i*hz|576p*hz|720p*hz|1080p*hz|1440p*hz|2160p*hz|576i*hz|720i*hz|1080i*hz|1440i*hz|2160i*hz) | |
| W=$(($H*16/9)) | |
| [[ "$MODE" == "480"* ]] && W=854 | |
| DH=$(($H*2)) | |
| W1=$(($W-1)) | |
| H1=$(($H-1)) | |
| fbset -fb /dev/fb0 -g $W $H $W $DH $BPP | |
| fbset -fb /dev/fb1 -g $BPP $BPP $BPP $BPP $BPP | |
| echo $MODE > /sys/class/display/mode | |
| echo 0 > /sys/class/graphics/fb0/free_scale | |
| echo 1 > /sys/class/graphics/fb0/freescale_mode | |
| echo 0 0 $W1 $H1 > /sys/class/graphics/fb0/free_scale_axis | |
| echo 0 0 $W1 $H1 > /sys/class/graphics/fb0/window_axis | |
| echo 0 > /sys/class/graphics/fb1/free_scale | |
| ;; | |
| 480cvbs) | |
| echo $MODE > /sys/class/display/mode | |
| # Here sets the main framebuffer values Width Height Width Height*2 32(BPP). | |
| fbset -fb /dev/fb0 -g $FBW $FBH $FBW $(( FBH * 2 )) $BPP | |
| # Here sets the secondary buffer no need to change. | |
| fbset -fb /dev/fb1 -g $BPP $BPP $BPP $BPP $BPP | |
| # This next bit sets the size of the free-scale which should be fb: 0 0 Width-1 Height-1 (1280-1, 960-1) | |
| echo 0 0 $(( FBW -1 )) $(( FBH - 1 )) > /sys/class/graphics/fb0/free_scale_axis | |
| # This sets the window resizing to fit the display. each number represents pixel number: X1 Y1 X2 Y2. | |
| # For this resolution it's resizing from 720x480. the X2 is calc by 720-X1(=30)-1, Y2 calc 480-Y1(=10)-1. | |
| echo 30 10 689 469 > /sys/class/graphics/fb0/window_axis | |
| echo 0x10001 > /sys/class/graphics/fb0/free_scale | |
| ;; | |
| 576cvbs) | |
| echo $MODE > /sys/class/display/mode | |
| # Here sets the main framebuffer values Width Height Width Height*2 32(BPP). | |
| fbset -fb /dev/fb0 -g $FBW $FBH $FBW $(( FBH * 2 )) $BPP | |
| # Here sets the secondary buffer no need to change. | |
| fbset -fb /dev/fb1 -g $BPP $BPP $BPP $BPP $BPP | |
| # This next bit sets the size of the free-scale which should be fb: 0 0 Width-1 Height-1 (1280-1, 960-1) | |
| echo 0 0 $(( FBW -1 )) $(( FBH - 1 )) > /sys/class/graphics/fb0/free_scale_axis | |
| # This sets the window resizing to fit the display. each number represents pixel number: X1 Y1 X2 Y2. | |
| # For this resolution it's resizing from 720x576. the X2 is calc by 720-X1(=35)-1, Y2 calc 576-Y1(=10)-1. | |
| echo 35 20 684 555 > /sys/class/graphics/fb0/window_axis | |
| echo 0x10001 > /sys/class/graphics/fb0/free_scale | |
| ;; | |
| *x*) | |
| W=$(echo $MODE | cut -d'x' -f 1) | |
| H=$(echo $MODE | cut -d'x' -f 2 | cut -d'p' -f 1) | |
| [ ! -n "$H" ] && H=$(echo $MODE | cut -d'x' -f 2 | cut -d'i' -f 1) | |
| if [ -n "$W" ] && [ -n "$H" ]; then | |
| DH=$(($H*2)) | |
| W1=$(($W-1)) | |
| H1=$(($H-1)) | |
| fbset -fb /dev/fb0 -g $W $H $W $DH $BPP | |
| fbset -fb /dev/fb1 -g $BPP $BPP $BPP $BPP $BPP | |
| # [[ "$MODE" = "720x480p"* ]] && MODE=$(echo "${H}p${HZ}hz") | |
| echo $MODE > /sys/class/display/mode | |
| echo 0 > /sys/class/graphics/fb0/free_scale | |
| echo 1 > /sys/class/graphics/fb0/freescale_mode | |
| echo 0 0 $W1 $H1 > /sys/class/graphics/fb0/free_scale_axis | |
| echo 0 0 $W1 $H1 > /sys/class/graphics/fb0/window_axis | |
| echo 0 > /sys/class/graphics/fb1/free_scale | |
| fi | |
| ;; | |
| esac | |
| blank_buffer | |
| # shows buffer | |
| show_buffer 0 | |
| # End of reading the video output mode and setting it for emuelec to avoid video flicking. | |
| # The codes can be simplified with "elseif" sentences. | |
| # The codes for 480I and 576I are adjusted to avoid overscan. | |
| # Forece 720p50hz to 720p60hz and 1080i/p60hz to 1080i/p60hz since 50hz would make video very choppy. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment