No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pitft-fbcp.sh 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #!/bin/bash
  2. if [ $(id -u) -ne 0 ]; then
  3. echo "Installer must be run as root."
  4. echo "Try 'sudo bash $0'"
  5. exit 1
  6. fi
  7. clear
  8. echo "This script enables basic PiTFT display"
  9. echo "support for portable gaming, etc. Does"
  10. echo "not cover X11, touchscreen or buttons"
  11. echo "(see adafruit-pitft-helper for those)."
  12. echo "HDMI output is set to PiTFT resolution,"
  13. echo "not all monitors support this, PiTFT"
  14. echo "may be only display after reboot."
  15. echo "Run time ~5 minutes. Reboot required."
  16. echo
  17. echo -n "CONTINUE? [y/N] "
  18. read
  19. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  20. echo "Canceled."
  21. exit 0
  22. fi
  23. # FEATURE PROMPTS ----------------------------------------------------------
  24. # Installation doesn't begin until after all user input is taken.
  25. # Given a list of strings representing options, display each option
  26. # preceded by a number (1 to N), display a prompt, check input until
  27. # a valid number within the selection range is entered.
  28. selectN() {
  29. for ((i=1; i<=$#; i++)); do
  30. echo $i. ${!i}
  31. done
  32. echo
  33. REPLY=""
  34. while :
  35. do
  36. echo -n "SELECT 1-$#: "
  37. read
  38. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  39. return $REPLY
  40. fi
  41. done
  42. }
  43. echo
  44. echo "Select project:"
  45. selectN "PiGRRL 2" \
  46. "Pocket PiGRRL" \
  47. "PiGRRL Zero" \
  48. "Cupcade (horizontal screen)" \
  49. "Cupcade (vertical screen)" \
  50. "Configure options manually"
  51. PROJ_SELECT=$?
  52. PITFT_VALUES=(pitft22 pitft28-resistive pitft28-capacitive pitft35-resistive)
  53. WIDTH_VALUES=(320 320 320 480)
  54. HEIGHT_VALUES=(240 240 240 320)
  55. HZ_VALUES=(80000000 80000000 80000000 32000000)
  56. # Framebuffer (HDMI out) rotation:
  57. FBROTATE_VALUES=(0 1 2 3)
  58. # PiTFT (MADCTL) rotation:
  59. TFTROTATE_VALUES=(0 90 180 270)
  60. if [ $PROJ_SELECT -lt 6 ]; then
  61. # Use preconfigured settings per-project
  62. # 3 elements per project; first is index (1+) into
  63. # PITFT_VALUES, second and third are index into
  64. # FBROTATE_VALUES and TFTROTATE_VALUES:
  65. PROJ_VALUES=(2 1 4 1 1 4 1 1 4 2 1 2 2 2 2)
  66. # FBROTATE index is almost always 1, except for HDMI portrait mode
  67. PITFT_SELECT=${PROJ_VALUES[($PROJ_SELECT-1)*3]}
  68. FBROTATE_SELECT=${PROJ_VALUES[($PROJ_SELECT-1)*3+1]}
  69. TFTROTATE_SELECT=${PROJ_VALUES[($PROJ_SELECT-1)*3+2]}
  70. else
  71. # Configure options manually
  72. echo
  73. echo "Select display type:"
  74. # 123456789012345678901234567890123456789
  75. selectN "PiTFT 2.2\" HAT" \
  76. "PiTFT / PiTFT Plus resistive 2.4-3.2\"" \
  77. "PiTFT / PiTFT Plus 2.8\" capacitive" \
  78. "PiTFT / PiTFT Plus 3.5\""
  79. PITFT_SELECT=$?
  80. echo
  81. echo "HDMI rotation:"
  82. selectN "Normal (landscape)" \
  83. "90° clockwise (portrait)" \
  84. "180° (landscape)" \
  85. "90° counterclockwise (portrait)"
  86. FBROTATE_SELECT=$?
  87. echo
  88. echo "TFT (MADCTL) rotation:"
  89. selectN "0" \
  90. "90" \
  91. "180" \
  92. "270"
  93. TFTROTATE_SELECT=$?
  94. fi
  95. # START INSTALL ------------------------------------------------------------
  96. echo
  97. echo "Device: ${PITFT_VALUES[$PITFT_SELECT-1]}"
  98. echo "HDMI framebuffer rotate: ${FBROTATE_VALUES[$FBROTATE_SELECT-1]}"
  99. echo "TFT MADCTL rotate: ${TFTROTATE_VALUES[$TFTROTATE_SELECT-1]}"
  100. echo
  101. echo -n "CONTINUE? [y/N] "
  102. read
  103. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  104. echo "Canceled."
  105. exit 0
  106. fi
  107. # All selections are validated at this point...
  108. # *_SELECT variables will have numeric index of 1+
  109. echo
  110. echo "Starting installation..."
  111. echo "Updating package index files..."
  112. apt-get update
  113. # Given a filename, a regex pattern to match and a replacement string,
  114. # perform replacement if found, else append replacement to end of file.
  115. # (# $1 = filename, $2 = pattern to match, $3 = replacement)
  116. reconfig() {
  117. grep $2 $1 >/dev/null
  118. if [ $? -eq 0 ]; then
  119. # Pattern found; replace in file
  120. sed -i "s/$2/$3/g" $1 >/dev/null
  121. else
  122. # Not found; append (silently)
  123. echo $3 | sudo tee -a $1 >/dev/null
  124. fi
  125. }
  126. # FBCP INSTALL -------------------------------------------------------------
  127. echo "Downloading and installing fbcp..."
  128. apt-get --yes --force-yes install cmake
  129. cd /tmp
  130. curl -LO https://github.com/tasanakorn/rpi-fbcp/archive/master.zip
  131. unzip master.zip
  132. cd rpi-fbcp-master
  133. mkdir build
  134. cd build
  135. cmake ..
  136. make
  137. install fbcp /usr/local/bin/fbcp
  138. cd ../..
  139. rm -rf rpi-fbcp-master
  140. # Add fbcp to /rc.local:
  141. grep fbcp /etc/rc.local >/dev/null
  142. if [ $? -eq 0 ]; then
  143. # fbcp already in rc.local, but make sure correct:
  144. sed -i "s/^.*fbcp.*$/\/usr\/local\/bin\/fbcp \&/g" /etc/rc.local >/dev/null
  145. else
  146. # Insert fbcp into rc.local before final 'exit 0'
  147. sed -i "s/^exit 0/\/usr\/local\/bin\/fbcp \&\\nexit 0/g" /etc/rc.local >/dev/null
  148. fi
  149. # PITFT SETUP (/boot/config.txt mostly) ------------------------------------
  150. echo "Configuring PiTFT..."
  151. # Enable SPI using raspi-config
  152. raspi-config nonint do_spi 0
  153. # Set up PiTFT device tree overlay
  154. reconfig /boot/config.txt "^.*dtoverlay=pitft.*$" "dtoverlay=${PITFT_VALUES[PITFT_SELECT-1]},rotate=${TFTROTATE_VALUES[TFTROTATE_SELECT-1]},speed=${HZ_VALUES[PITFT_SELECT-1]},fps=60"
  155. # Set up framebuffer rotation
  156. reconfig /boot/config.txt "^.*display_rotate.*$" "display_rotate=${FBROTATE_VALUES[FBROTATE_SELECT-1]}"
  157. # Disable overscan compensation (use full screen):
  158. raspi-config nonint do_overscan 1
  159. # Set up HDMI parameters:
  160. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
  161. reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
  162. reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
  163. reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=${WIDTH_VALUES[PITFT_SELECT-1]} ${HEIGHT_VALUES[PITFT_SELECT-1]} 60 1 0 0 0"
  164. # Use smaller console font:
  165. reconfig /etc/default/console-setup "^.*FONTFACE.*$" "FONTFACE=\"Terminus\""
  166. reconfig /etc/default/console-setup "^.*FONTSIZE.*$" "FONTSIZE=\"6x12\""
  167. # Enable Retropie video smoothing
  168. reconfig /opt/retropie/configs/all/retroarch.cfg "^.*video_smooth.*$" "video_smooth = \"true\""
  169. # PROMPT FOR REBOOT --------------------------------------------------------
  170. echo "Done."
  171. echo
  172. echo "Settings take effect on next boot."
  173. echo
  174. echo -n "REBOOT NOW? [y/N] "
  175. read
  176. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  177. echo "Exiting without reboot."
  178. exit 0
  179. fi
  180. echo "Reboot started..."
  181. reboot
  182. exit 0