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.

667 lines
22 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/bash
  2. # (C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
  3. #
  4. # Instructions!
  5. # cd ~
  6. # wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/adafruit-pitft.sh
  7. # chmod +x adafruit-pitft.sh
  8. # sudo ./adafruit-pitft.sh
  9. if [ $(id -u) -ne 0 ]; then
  10. echo "Installer must be run as root."
  11. echo "Try 'sudo bash $0'"
  12. exit 1
  13. fi
  14. UPDATE_DB=false
  15. ############################ CALIBRATIONS ############################
  16. # For TSLib
  17. POINTERCAL_28r0="4232 11 -879396 1 5786 -752768 65536"
  18. POINTERCAL_28r90="33 -5782 21364572 4221 35 -1006432 65536"
  19. POINTERCAL_28r180="-4273 61 16441290 4 -5772 21627524 65536"
  20. POINTERCAL_28r270="-9 5786 -784608 -4302 19 16620508 65536"
  21. POINTERCAL_35r0="5724 -6 -1330074 26 8427 -1034528 65536"
  22. POINTERCAL_35r90="5 8425 -978304 -5747 61 22119468 65536"
  23. POINTERCAL_35r180="-5682 -1 22069150 13 -8452 32437698 65536"
  24. POINTERCAL_35r270="3 -8466 32440206 5703 -1 -1308696 65536"
  25. POINTERCAL_28c="320 65536 0 -65536 0 15728640 65536"
  26. # for PIXEL desktop
  27. TRANSFORM_28r0="0.988809 -0.023645 0.060523 -0.028817 1.003935 0.034176 0 0 1"
  28. TRANSFORM_28r90="0.014773 -1.132874 1.033662 1.118701 0.009656 -0.065273 0 0 1"
  29. TRANSFORM_28r180="-1.115235 -0.010589 1.057967 -0.005964 -1.107968 1.025780 0 0 1"
  30. TRANSFORM_28r270="-0.033192 1.126869 -0.014114 -1.115846 0.006580 1.050030 0 0 1"
  31. TRANSFORM_35r0="-1.098388 0.003455 1.052099 0.005512 -1.093095 1.026309 0 0 1"
  32. TRANSFORM_35r90="-0.000087 1.094214 -0.028826 -1.091711 -0.004364 1.057821 0 0 1"
  33. TRANSFORM_35r180="1.102807 0.000030 -0.066352 0.001374 1.085417 -0.027208 0 0 1"
  34. TRANSFORM_35r270="0.003893 -1.087542 1.025913 1.084281 0.008762 -0.060700 0 0 1"
  35. TRANSFORM_28c0="-1 0 1 0 -1 1 0 0 1"
  36. TRANSFORM_28c90="0 1 0 -1 0 1 0 0 1"
  37. TRANSFORM_28c180="1 0 0 0 1 0 0 0 1"
  38. TRANSFORM_28c270="0 -1 1 1 0 0 0 0 1"
  39. warning() {
  40. echo WARNING : $1
  41. }
  42. ############################ Script assisters ############################
  43. # Given a list of strings representing options, display each option
  44. # preceded by a number (1 to N), display a prompt, check input until
  45. # a valid number within the selection range is entered.
  46. selectN() {
  47. for ((i=1; i<=$#; i++)); do
  48. echo $i. ${!i}
  49. done
  50. echo
  51. REPLY=""
  52. while :
  53. do
  54. echo -n "SELECT 1-$#: "
  55. read
  56. if [[ $REPLY -ge 1 ]] && [[ $REPLY -le $# ]]; then
  57. return $REPLY
  58. fi
  59. done
  60. }
  61. function print_version() {
  62. echo "Adafruit PiTFT Helper v2.1.0"
  63. exit 1
  64. }
  65. function print_help() {
  66. echo "Usage: $0 "
  67. echo " -h Print this help"
  68. echo " -v Print version information"
  69. echo " -u [homedir] Specify path of primary user's home directory (defaults to /home/pi)"
  70. exit 1
  71. }
  72. group=ADAFRUIT
  73. function info() {
  74. system="$1"
  75. group="${system}"
  76. shift
  77. FG="1;32m"
  78. BG="40m"
  79. echo -e "[\033[${FG}\033[${BG}${system}\033[0m] $*"
  80. }
  81. function bail() {
  82. FG="1;31m"
  83. BG="40m"
  84. echo -en "[\033[${FG}\033[${BG}${group}\033[0m] "
  85. if [ -z "$1" ]; then
  86. echo "Exiting due to error"
  87. else
  88. echo "Exiting due to error: $*"
  89. fi
  90. exit 1
  91. }
  92. function ask() {
  93. # http://djm.me/ask
  94. while true; do
  95. if [ "${2:-}" = "Y" ]; then
  96. prompt="Y/n"
  97. default=Y
  98. elif [ "${2:-}" = "N" ]; then
  99. prompt="y/N"
  100. default=N
  101. else
  102. prompt="y/n"
  103. default=
  104. fi
  105. # Ask the question
  106. read -p "$1 [$prompt] " REPLY
  107. # Default?
  108. if [ -z "$REPLY" ]; then
  109. REPLY=$default
  110. fi
  111. # Check if the reply is valid
  112. case "$REPLY" in
  113. Y*|y*) return 0 ;;
  114. N*|n*) return 1 ;;
  115. esac
  116. done
  117. }
  118. function has_repo() {
  119. # Checks for the right raspbian repository
  120. # http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware
  121. if [[ $(grep -h ^deb /etc/apt/sources.list /etc/apt/sources.list.d/* | grep "mirrordirector.raspbian.org") ]]; then
  122. return 0
  123. else
  124. return 1
  125. fi
  126. }
  127. progress() {
  128. count=0
  129. until [ $count -eq $1 ]; do
  130. echo -n "..." && sleep 1
  131. ((count++))
  132. done
  133. echo
  134. }
  135. sysupdate() {
  136. if ! $UPDATE_DB; then
  137. # echo "Checking for correct software repositories..."
  138. # has_repo || { warning "Missing Apt repo, please add deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi firmware to /etc/apt/sources.list.d/raspi.list" && exit 1; }
  139. echo "Updating apt indexes..." && progress 3 &
  140. sudo apt update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
  141. sudo apt-get update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
  142. echo "Reading package lists..."
  143. progress 3 && UPDATE_DB=true
  144. fi
  145. }
  146. # Given a filename, a regex pattern to match and a replacement string,
  147. # perform replacement if found, else append replacement to end of file.
  148. # (# $1 = filename, $2 = pattern to match, $3 = replacement)
  149. reconfig() {
  150. grep $2 $1 >/dev/null
  151. if [ $? -eq 0 ]; then
  152. # Pattern found; replace in file
  153. sed -i "s/$2/$3/g" $1 >/dev/null
  154. else
  155. # Not found; append (silently)
  156. echo $3 | sudo tee -a $1 >/dev/null
  157. fi
  158. }
  159. ############################ Sub-Scripts ############################
  160. function softwareinstall() {
  161. echo "Installing Pre-requisite Software...This may take a few minutes!"
  162. apt-get install -y libts0 1> /dev/null 2>&1 || apt-get install -y tslib 1> /dev/null 2>&1 || { warning "Apt failed to install TSLIB!" && exit 1; }
  163. apt-get install -y bc fbi git python-dev python-pip python-smbus python-spidev evtest libts-bin device-tree-compiler 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  164. pip install evdev 1> /dev/null || { warning "Pip failed to install software!" && exit 1; }
  165. }
  166. # update /boot/config.txt with appropriate values
  167. function update_configtxt() {
  168. if grep -q "adafruit-pitft-helper" "/boot/config.txt"; then
  169. echo "Already have an adafruit-pitft-helper section in /boot/config.txt."
  170. echo "Removing old section..."
  171. cp /boot/config.txt /boot/configtxt.bak
  172. sed -i -e "/^# --- added by adafruit-pitft-helper/,/^# --- end adafruit-pitft-helper/d" /boot/config.txt
  173. fi
  174. # remove any old flexfb/fbtft stuff
  175. rm -f /etc/modprobe.d/fbtft.conf
  176. sed -i 's/flexfb//g' "/etc/modules"
  177. sed -i 's/fbtft_device//g' "/etc/modules"
  178. sed -i 's/spi-bcm2835//g' "/etc/modules"
  179. if [ "${pitfttype}" == "22" ]; then
  180. overlay="dtoverlay=pitft22,rotate=${pitftrot},speed=64000000,fps=30"
  181. fi
  182. if [ "${pitfttype}" == "28r" ]; then
  183. overlay="dtoverlay=pitft28-resistive,rotate=${pitftrot},speed=64000000,fps=30"
  184. fi
  185. if [ "${pitfttype}" == "28c" ]; then
  186. overlay="dtoverlay=pitft28-capacitive,rotate=${pitftrot},speed=64000000,fps=30"
  187. fi
  188. if [ "${pitfttype}" == "35r" ]; then
  189. overlay="dtoverlay=pitft35-resistive,rotate=${pitftrot},speed=20000000,fps=20"
  190. fi
  191. if [ "${pitfttype}" == "st7789_240x240" ]; then
  192. cat >> /etc/modprobe.d/fbtft.conf <<EOF
  193. # --- added by adafruit-pitft-helper $date ---
  194. options fbtft_device name=flexfb gpios=dc:25,cs:8,led:26 speed=40000000 bgr=1 fps=60
  195. options flexfb setaddrwin=0 width=240 height=240 init=-1,0x11,-2,120,-1,0x36,0x00,-1,0x3A,0x05,-1,0xB2,0x0C,0x0C,0x00,0x33,0x33,-1,0xB7,0x35,-1,0xBB,0x1A,-1,0xC0,0x2C,-1,0xC2,0x01,-1,0xC3,0x0B,-1,0xC4,0x20,-1,0xC6,0x0F,-1,0xD0,0xA4,0xA1,-1,0x21,-1,0xE0,0x00,0x19,0x1E,0x0A,0x09,0x15,0x3D,0x44,0x51,0x12,0x03,0x00,0x3F,0x3F,-1,0xE1,0x00,0x18,0x1E,0x0A,0x09,0x25,0x3F,0x43,0x52,0x33,0x03,0x00,0x3F,0x3F,-1,0x29,-3
  196. # --- end adafruit-pitft-helper $date ---
  197. EOF
  198. echo "flexfb" >> /etc/modules
  199. echo "fbtft_device" >> /etc/modules
  200. echo "spi-bcm2835" >> /etc/modules
  201. overlay=""
  202. fi
  203. if [ "${pitfttype}" == "st7789_240x135" ]; then
  204. dtc -@ -I dts -O dtb -o /boot/overlays/drm-minipitft114.dtbo overlays/minipitft114-overlay.dts
  205. echo "############# UPGRADING KERNEL ###############"
  206. sudo apt update || { warning "Apt failed to update itself!" && exit 1; }
  207. sudo apt-get upgrade || { warning "Apt failed to install software!" && exit 1; }
  208. apt-get install -y raspberrypi-kernel-headers 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  209. [ -d /lib/modules/$(uname -r)/build ] || { warning "Kernel was updated, please reboot now and re-run script!" && exit 1; }
  210. cd st7789_module
  211. make -C /lib/modules/$(uname -r)/build M=$(pwd) modules || { warning "Apt failed to compile ST7789V driver!" && exit 1; }
  212. mv /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.BACK
  213. mv st7789v_ada.ko /lib/modules/$(uname -r)/kernel/drivers/gpu/drm/tinydrm/mi0283qt.ko
  214. overlay="dtoverlay=drm-minipitft114,rotation=${pitftrot}"
  215. fi
  216. date=`date`
  217. cat >> /boot/config.txt <<EOF
  218. # --- added by adafruit-pitft-helper $date ---
  219. dtparam=spi=on
  220. dtparam=i2c1=on
  221. dtparam=i2c_arm=on
  222. $overlay
  223. # --- end adafruit-pitft-helper $date ---
  224. EOF
  225. }
  226. function update_udev() {
  227. cat > /etc/udev/rules.d/95-touchmouse.rules <<EOF
  228. SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  229. EOF
  230. cat > /etc/udev/rules.d/95-ftcaptouch.rules <<EOF
  231. SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  232. EOF
  233. cat > /etc/udev/rules.d/95-stmpe.rules <<EOF
  234. SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
  235. EOF
  236. }
  237. function update_pointercal() {
  238. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  239. echo $(eval echo "\$POINTERCAL_$pitfttype$pitftrot") > /etc/pointercal
  240. fi
  241. if [ "${pitfttype}" == "28c" ]; then
  242. echo $(eval echo "\$POINTERCAL_$pitfttype") > /etc/pointercal
  243. fi
  244. }
  245. function install_console() {
  246. echo "Set up main console turn on"
  247. if ! grep -q 'fbcon=map:10 fbcon=font:VGA8x8' /boot/cmdline.txt; then
  248. echo "Updating /boot/cmdline.txt"
  249. sed -i 's/rootwait/rootwait fbcon=map:10 fbcon=font:VGA8x8/g' "/boot/cmdline.txt"
  250. else
  251. echo "/boot/cmdline.txt already updated"
  252. fi
  253. echo "Turning off console blanking"
  254. # pre-stretch this is what you'd do:
  255. if [ -e /etc/kbd/config ]; then
  256. sed -i 's/BLANK_TIME=.*/BLANK_TIME=0/g' "/etc/kbd/config"
  257. fi
  258. # as of stretch....
  259. # removing any old version
  260. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  261. sed -i -e '/^sudo sh -c "TERM=linux setterm -blank.*/d' /etc/rc.local
  262. sed -i -e "s|^exit 0|# disable console blanking on PiTFT\\nsudo sh -c \"TERM=linux setterm -blank 0 >/dev/tty0\"\\nexit 0|" /etc/rc.local
  263. reconfig /etc/default/console-setup "^.*FONTFACE.*$" "FONTFACE=\"Terminus\""
  264. reconfig /etc/default/console-setup "^.*FONTSIZE.*$" "FONTSIZE=\"6x12\""
  265. echo "Setting raspi-config to boot to console w/o login..."
  266. (cd "$target_homedir" && raspi-config nonint do_boot_behaviour B2)
  267. # remove fbcp
  268. sed -i -e "/^.*fbcp.*$/d" /etc/rc.local
  269. }
  270. function uninstall_console() {
  271. echo "Removing console fbcon map from /boot/cmdline.txt"
  272. sed -i 's/rootwait fbcon=map:10 fbcon=font:VGA8x8/rootwait/g' "/boot/cmdline.txt"
  273. echo "Screen blanking time reset to 10 minutes"
  274. if [ -e "/etc/kbd/config" ]; then
  275. sed -i 's/BLANK_TIME=0/BLANK_TIME=10/g' "/etc/kbd/config"
  276. fi
  277. sed -i -e '/^# disable console blanking.*/d' /etc/rc.local
  278. sed -i -e '/^sudo sh -c "TERM=linux.*/d' /etc/rc.local
  279. }
  280. function install_fbcp() {
  281. echo "Installing cmake..."
  282. apt-get --yes --force-yes install cmake 1> /dev/null || { warning "Apt failed to install software!" && exit 1; }
  283. echo "Downloading rpi-fbcp..."
  284. cd /tmp
  285. #curl -sLO https://github.com/tasanakorn/rpi-fbcp/archive/master.zip
  286. curl -sLO https://github.com/adafruit/rpi-fbcp/archive/master.zip
  287. echo "Uncompressing rpi-fbcp..."
  288. rm -rf /tmp/rpi-fbcp-master
  289. unzip master.zip 1> /dev/null || { warning "Failed to uncompress fbcp!" && exit 1; }
  290. cd rpi-fbcp-master
  291. mkdir build
  292. cd build
  293. echo "Building rpi-fbcp..."
  294. echo -e "\nset (CMAKE_C_FLAGS \"-std=gnu99 ${CMAKE_C_FLAGS}\")" >> ../CMakeLists.txt
  295. cmake .. 1> /dev/null || { warning "Failed to cmake fbcp!" && exit 1; }
  296. make 1> /dev/null || { warning "Failed to make fbcp!" && exit 1; }
  297. echo "Installing rpi-fbcp..."
  298. install fbcp /usr/local/bin/fbcp
  299. cd ~
  300. rm -rf /tmp/rpi-fbcp-master
  301. # Start fbcp in the appropriate place, depending on init system:
  302. if [ "$SYSTEMD" == "0" ]; then
  303. # Add fbcp to /etc/rc.local:
  304. echo "We have sysvinit, so add fbcp to /etc/rc.local..."
  305. grep fbcp /etc/rc.local >/dev/null
  306. if [ $? -eq 0 ]; then
  307. # fbcp already in rc.local, but make sure correct:
  308. sed -i "s|^.*fbcp.*$|/usr/local/bin/fbcp \&|g" /etc/rc.local >/dev/null
  309. else
  310. # Insert fbcp into rc.local before final 'exit 0':
  311. sed -i "s|^exit 0|/usr/local/bin/fbcp \&\\nexit 0|g" /etc/rc.local >/dev/null
  312. fi
  313. else
  314. # Install fbcp systemd unit, first making sure it's not in rc.local:
  315. uninstall_fbcp_rclocal
  316. echo "We have systemd, so install fbcp systemd unit..."
  317. install_fbcp_unit || bail "Unable to install fbcp unit file"
  318. sudo systemctl enable fbcp.service
  319. fi
  320. # if there's X11 installed...
  321. if [ -e /etc/lightdm ]; then
  322. echo "Setting raspi-config to boot to desktop w/o login..."
  323. raspi-config nonint do_boot_behaviour B4
  324. fi
  325. # Disable overscan compensation (use full screen):
  326. raspi-config nonint do_overscan 1
  327. # Set up HDMI parameters:
  328. echo "Configuring boot/config.txt for forced HDMI"
  329. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
  330. reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
  331. reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
  332. # if there's X11 installed...
  333. if [ -e /etc/lightdm ]; then
  334. if [ "${pitfttype}" == "35r" ]; then
  335. echo "Using x1.5 resolution"
  336. SCALE=1.5
  337. else
  338. echo "Using x2 resolution"
  339. SCALE=2.0
  340. fi
  341. else
  342. echo "Using native resolution"
  343. SCALE=1
  344. fi
  345. WIDTH=`python -c "print(int(${WIDTH_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  346. HEIGHT=`python -c "print(int(${HEIGHT_VALUES[PITFT_SELECT-1]} * ${SCALE}))"`
  347. reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=${WIDTH} ${HEIGHT} 60 1 0 0 0"
  348. if [ "${pitftrot}" == "90" ] || [ "${pitftrot}" == "270" ]; then
  349. # dont rotate HDMI on 90 or 270
  350. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" ""
  351. fi
  352. if [ "${pitftrot}" == "0" ]; then
  353. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=1"
  354. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  355. pitftrot=90
  356. update_configtxt || bail "Unable to update /boot/config.txt"
  357. pitftrot=0
  358. fi
  359. if [ "${pitftrot}" == "180" ]; then
  360. reconfig /boot/config.txt "^.*display_hdmi_rotate.*$" "display_hdmi_rotate=3"
  361. # this is a hack but because we rotate HDMI we have to 'unrotate' the TFT!
  362. pitftrot=90
  363. update_configtxt || bail "Unable to update /boot/config.txt"
  364. pitftrot=180
  365. fi
  366. }
  367. function install_fbcp_unit() {
  368. cat > /etc/systemd/system/fbcp.service <<EOF
  369. [Unit]
  370. Description=Framebuffer copy utility for PiTFT
  371. After=network.target
  372. [Service]
  373. Type=simple
  374. ExecStartPre=/bin/sleep 10
  375. ExecStart=/usr/local/bin/fbcp
  376. [Install]
  377. WantedBy=multi-user.target
  378. EOF
  379. }
  380. function uninstall_fbcp() {
  381. uninstall_fbcp_rclocal
  382. # Enable overscan compensation
  383. raspi-config nonint do_overscan 0
  384. # Set up HDMI parameters:
  385. echo "Configuring boot/config.txt for default HDMI"
  386. reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=0"
  387. sed -i -e '/^hdmi_group=2.*$/d' /boot/config.txt
  388. sed -i -e '/^hdmi_mode=87.*$/d' /boot/config.txt
  389. sed -i -e '/^hdmi_cvt=.*$/d' /boot/config.txt
  390. }
  391. function uninstall_fbcp_rclocal() {
  392. # Remove fbcp from /etc/rc.local:
  393. echo "Remove fbcp from /etc/rc.local, if it's there..."
  394. sed -i -e '/^.*fbcp.*$/d' /etc/rc.local
  395. }
  396. function update_xorg() {
  397. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ]; then
  398. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  399. transform="Option \"TransformationMatrix\" \"${matrix}\""
  400. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  401. Section "InputClass"
  402. Identifier "STMPE Touchscreen Calibration"
  403. MatchProduct "stmpe"
  404. MatchDevicePath "/dev/input/event*"
  405. Driver "libinput"
  406. ${transform}
  407. EndSection
  408. EOF
  409. fi
  410. if [ "${pitfttype}" == "28c" ]; then
  411. matrix=$(eval echo "\$TRANSFORM_$pitfttype$pitftrot")
  412. transform="Option \"TransformationMatrix\" \"${matrix}\""
  413. cat > /usr/share/X11/xorg.conf.d/20-calibration.conf <<EOF
  414. Section "InputClass"
  415. Identifier "FocalTech Touchscreen Calibration"
  416. MatchProduct "EP0110M09"
  417. MatchDevicePath "/dev/input/event*"
  418. Driver "libinput"
  419. ${transform}
  420. EndSection
  421. EOF
  422. fi
  423. }
  424. ####################################################### MAIN
  425. target_homedir="/home/pi"
  426. clear
  427. echo "This script downloads and installs"
  428. echo "PiTFT Support using userspace touch"
  429. echo "controls and a DTO for display drawing."
  430. echo "one of several configuration files."
  431. echo "Run time of up to 5 minutes. Reboot required!"
  432. echo
  433. echo "Select configuration:"
  434. selectN "PiTFT 2.4\", 2.8\" or 3.2\" resistive (240x320)" \
  435. "PiTFT 2.2\" no touch (240x320)" \
  436. "PiTFT 2.8\" capacitive touch (240x320)" \
  437. "PiTFT 3.5\" resistive touch (320x480)" \
  438. "Braincraft 1.54\" display (240x240)" \
  439. "MiniPiTFT 1.14\" display (240x135) - WARNING! CUTTING EDGE! WILL UPGRADE YOUR KERNEL TO LATEST" \
  440. "Quit without installing"
  441. PITFT_SELECT=$?
  442. if [ $PITFT_SELECT -gt 6 ]; then
  443. exit 1
  444. fi
  445. echo "Select rotation:"
  446. selectN "90 degrees (landscape)" \
  447. "180 degrees (portait)" \
  448. "270 degrees (landscape)" \
  449. "0 degrees (portait)"
  450. PITFT_ROTATE=$?
  451. if [ $PITFT_ROTATE -gt 4 ]; then
  452. exit 1
  453. fi
  454. PITFT_ROTATIONS=("90" "180" "270" "0")
  455. PITFT_TYPES=("28r" "22" "28c" "35r" "st7789_240x240" "st7789_240x135")
  456. WIDTH_VALUES=(320 320 320 480 240)
  457. HEIGHT_VALUES=(240 240 240 320 240)
  458. HZ_VALUES=(64000000 64000000 64000000 32000000 64000000)
  459. args=$(getopt -uo 'hvri:o:b:u:' -- $*)
  460. [ $? != 0 ] && print_help
  461. set -- $args
  462. for i
  463. do
  464. case "$i"
  465. in
  466. -h)
  467. print_help
  468. ;;
  469. -v)
  470. print_version
  471. ;;
  472. -u)
  473. target_homedir="$2"
  474. echo "Homedir = ${2}"
  475. shift
  476. shift
  477. ;;
  478. esac
  479. done
  480. # check init system (technique borrowed from raspi-config):
  481. info PITFT 'Checking init system...'
  482. if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
  483. echo "Found systemd"
  484. SYSTEMD=1
  485. elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
  486. echo "Found sysvinit"
  487. SYSTEMD=0
  488. else
  489. bail "Unrecognised init system"
  490. fi
  491. if grep -q boot /proc/mounts; then
  492. echo "/boot is mounted"
  493. else
  494. echo "/boot must be mounted. if you think it's not, quit here and try: sudo mount /dev/mmcblk0p1 /boot"
  495. if ask "Continue?"; then
  496. echo "Proceeding."
  497. else
  498. bail "Aborting."
  499. fi
  500. fi
  501. if [[ ! -e "$target_homedir" || ! -d "$target_homedir" ]]; then
  502. bail "$target_homedir must be an existing directory (use -u /home/foo to specify)"
  503. fi
  504. pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]}
  505. pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]}
  506. if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ] && [ "${pitfttype}" != "st7789_240x135" ]; then
  507. echo "Type must be one of:"
  508. echo " '28r' (2.8\" resistive, PID 1601)"
  509. echo " '28c' (2.8\" capacitive, PID 1983)"
  510. echo " '35r' (3.5\" Resistive)"
  511. echo " '22' (2.2\" no touch)"
  512. echo " 'st7789_240x240' (1.54\" or 1.3\" no touch)"
  513. echo " 'st7789_240x135' 1.14\" no touch)"
  514. echo
  515. print_help
  516. fi
  517. info PITFT "System update"
  518. sysupdate || bail "Unable to apt-get update"
  519. info PITFT "Installing Python libraries & Software..."
  520. softwareinstall || bail "Unable to install software"
  521. info PITFT "Updating /boot/config.txt..."
  522. update_configtxt || bail "Unable to update /boot/config.txt"
  523. if [ "${pitfttype}" == "28r" ] || [ "${pitfttype}" == "35r" ] || [ "${pitfttype}" == "28c" ] ; then
  524. info PITFT "Updating SysFS rules for Touchscreen..."
  525. update_udev || bail "Unable to update /etc/udev/rules.d"
  526. info PITFT "Updating TSLib default calibration..."
  527. update_pointercal || bail "Unable to update /etc/pointercal"
  528. fi
  529. # ask for console access
  530. if ask "Would you like the console to appear on the PiTFT display?"; then
  531. info PITFT "Updating console to PiTFT..."
  532. uninstall_fbcp || bail "Unable to uninstall fbcp"
  533. install_console || bail "Unable to configure console"
  534. else
  535. info PITFT "Making sure console doesn't use PiTFT"
  536. uninstall_console || bail "Unable to configure console"
  537. if ask "Would you like the HDMI display to mirror to the PiTFT display?"; then
  538. info PITFT "Adding FBCP support..."
  539. install_fbcp || bail "Unable to configure fbcp"
  540. if [ -e /etc/lightdm ]; then
  541. info PITFT "Updating X11 default calibration..."
  542. update_xorg || bail "Unable to update calibration"
  543. fi
  544. fi
  545. fi
  546. #info PITFT "Updating X11 setup tweaks..."
  547. #update_x11profile || bail "Unable to update X11 setup"
  548. #if [ "${pitfttype}" != "35r" ]; then
  549. # # ask for 'on/off' button
  550. # if ask "Would you like GPIO #23 to act as a on/off button?"; then
  551. # info PITFT "Adding GPIO #23 on/off to PiTFT..."
  552. # install_onoffbutton || bail "Unable to add on/off button"
  553. # fi
  554. #fi
  555. # update_bootprefs || bail "Unable to set boot preferences"
  556. info PITFT "Success!"
  557. echo
  558. echo "Settings take effect on next boot."
  559. echo
  560. echo -n "REBOOT NOW? [y/N] "
  561. read
  562. if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
  563. echo "Exiting without reboot."
  564. exit 0
  565. fi
  566. echo "Reboot started..."
  567. reboot
  568. exit 0