Compare commits

..

No commits in common. "main" and "5.4_fixfbcp" have entirely different histories.

66 changed files with 768 additions and 5752 deletions

View file

@ -1,68 +0,0 @@
name: 🐞 Bug Report
description: Create a bug report to help us improve
labels:
- bug
body:
- type: markdown
attributes:
value: >-
Thanks! for using the installer scripts. Now that you have encountered a
bug... you can file a report for it.
- type: textarea
id: script
attributes:
label: Script Command
description: >-
Include the exact command you're running with any parameters. There are quite
a handful of scripts and knowing which one is helpful. :)
placeholder: sudo python3 adafruit-pitft.py --display=28r --rotation=90 --install-type=console
render: shell
validations:
required: true
- type: textarea
id: os
attributes:
label: Operating System
description: >-
Which OS was the script running under? Include details such as if it
was 32 or 64-bit, Whether it was the Lite of Full Desktop version. If it's on an older or newer
kernel, include that as well.
placeholder: |
64-bit Raspberry Pi OS Lite with Bullseye
validations:
required: true
- type: textarea
id: hardware
attributes:
label: Hardware
description: This is the board or computer you are running the script on.
placeholder: |
Raspberry Pi 4B
validations:
required: true
- type: textarea
id: behavior
attributes:
label: Behavior
description: What happens when you run the script above? Include error messages (if any).
placeholder: |
An error occurs at line 459 with this message...
validations:
required: true
- type: textarea
id: description
attributes:
label: Description
description: Optionally, describe the bug in more detail.
placeholder: |
- I selected options 1, then 3, then 4...
- Only happens when...
- might be related to #123...
- type: textarea
id: more-info
attributes:
label: Additional information
description: >-
Optionally, add any other information like hardware connection, scope
output etc. If you have already done some debugging, mention it here.
placeholder: Removing [this](url) line resolves the issue.

View file

@ -1,7 +0,0 @@
contact_links:
- name: 🔗 Adafruit Forum
url: https://forums.adafruit.com/
about: Official Adafruit technical support forum. Good for getting help on getting a project working.
- name: 🔗 Adafruit Discord
url: https://adafru.it/discord
about: Unofficial chat with many helpful folks and normally prompt replies.

View file

@ -1,11 +0,0 @@
---
name: 🚀 Feature Request
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
assignees: ''
---
<!-- If you have an idea for any new features and enhancements to any of our scripts 🚀
and would love ❤ to see what ideas you have for us... 🙂 -->

16
.gitignore vendored
View file

@ -1,16 +0,0 @@
# SPDX-FileCopyrightText: 2019 Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
*.mpy
.idea
__pycache__
_build
*.pyc
.env
build*
bundles
*.DS_Store
.eggs
dist
**/*.egg-info

View file

@ -2,36 +2,6 @@
Some scripts for helping install Adafruit HATs, bonnets, add-on's, & friends! Some scripts for helping install Adafruit HATs, bonnets, add-on's, & friends!
Many scripts are based heavily on get.pimoroni.com scripts! Based heavily on get.pimoroni.com scripts!
* Install i2s amplifier with: curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash * Install i2s amplifier with: curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash
## Python Scripts
We are in the process of converting our Shell Scripts to Python. Instructions for running specific scripts are available in the [Adafruit Learning System](https://learn.adafruit.com/). Here are the general setup instructions.
### Dependencies
- Python 3
- [Adafruit_Python_Shell](https://github.com/adafruit/Adafruit_Python_Shell)
- [Click](https://pypi.org/project/click/)
### Prepare your system
To install the dependencies for the python scripts, run the following commands:
```bash
sudo apt-get install python3-pip
sudo pip3 install --upgrade click
sudo pip3 install --upgrade setuptools
sudo pip3 install --upgrade adafruit-python-shell
```
Then to run the python script, type the following replacing "scriptname.py" with the actual script name:
```bash
sudo python3 scriptname.py
```
## Old Shell Scripts
If you were directed here from an external site and the script you were looking for appears to be missing, you can either use the newer python script or check the [converted_shell_scripts](https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/tree/main/converted_shell_scripts) folder to use the old shell scripts.

File diff suppressed because it is too large Load diff

View file

@ -47,9 +47,9 @@ TRANSFORM_28c90="0 1 0 -1 0 1 0 0 1"
TRANSFORM_28c180="1 0 0 0 1 0 0 0 1" TRANSFORM_28c180="1 0 0 0 1 0 0 0 1"
TRANSFORM_28c270="0 -1 1 1 0 0 0 0 1" TRANSFORM_28c270="0 -1 1 1 0 0 0 0 1"
ROTATE_28c0="rotate=90,touch-invx=true,touch-invy=true" ROTATE_28c0="rotate=0,touch-invx=true,touch-invy=true"
ROTATE_28c90="rotate=90,touch-swapxy=true,touch-invx=true" ROTATE_28c90="rotate=90,touch-swapxy=true,touch-invx=true"
ROTATE_28c180="rotate=90" ROTATE_28c180="rotate=180"
ROTATE_28c270="rotate=270,touch-swapxy=true,touch-invy=true" ROTATE_28c270="rotate=270,touch-swapxy=true,touch-invy=true"
warning() { warning() {
@ -232,7 +232,7 @@ function update_configtxt() {
fi fi
if [ "${pitfttype}" == "28c" ]; then if [ "${pitfttype}" == "28c" ]; then
rotateparams=$(eval echo "\$ROTATE_$pitfttype$touchrot") rotateparams=$(eval echo "\$ROTATE_$pitfttype$pitftrot")
overlay=$(printf "dtoverlay=pitft28-capacitive,speed=64000000,fps=30\ndtoverlay=pitft28-capacitive,${rotateparams}") overlay=$(printf "dtoverlay=pitft28-capacitive,speed=64000000,fps=30\ndtoverlay=pitft28-capacitive,${rotateparams}")
fi fi
@ -406,7 +406,6 @@ function install_fbcp() {
reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1" reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2" reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87" reconfig /boot/config.txt "^.*hdmi_mode.*$" "hdmi_mode=87"
reconfig /boot/config.txt "^[^#]*dtoverlay=vc4-fkms-v3d.*$" "#dtoverlay=vc4-fkms-v3d"
# if there's X11 installed... # if there's X11 installed...
if [ -e /etc/lightdm ]; then if [ -e /etc/lightdm ]; then
@ -474,7 +473,6 @@ function uninstall_fbcp() {
# Set up HDMI parameters: # Set up HDMI parameters:
echo "Configuring boot/config.txt for default HDMI" echo "Configuring boot/config.txt for default HDMI"
reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=0" reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=0"
reconfig /boot/config.txt "^.*#.*dtoverlay=vc4-fkms-v3d.*$" "dtoverlay=vc4-fkms-v3d"
sed -i -e '/^hdmi_group=2.*$/d' /boot/config.txt sed -i -e '/^hdmi_group=2.*$/d' /boot/config.txt
sed -i -e '/^hdmi_mode=87.*$/d' /boot/config.txt sed -i -e '/^hdmi_mode=87.*$/d' /boot/config.txt
sed -i -e '/^hdmi_cvt=.*$/d' /boot/config.txt sed -i -e '/^hdmi_cvt=.*$/d' /boot/config.txt
@ -551,9 +549,9 @@ fi
if ! $UNINSTALL; then if ! $UNINSTALL; then
echo "Select rotation:" echo "Select rotation:"
selectN "90 degrees (landscape)" \ selectN "90 degrees (landscape)" \
"180 degrees (portrait)" \ "180 degrees (portait)" \
"270 degrees (landscape)" \ "270 degrees (landscape)" \
"0 degrees (portrait)" "0 degrees (portait)"
PITFT_ROTATE=$? PITFT_ROTATE=$?
if [ $PITFT_ROTATE -gt 4 ]; then if [ $PITFT_ROTATE -gt 4 ]; then
exit 1 exit 1
@ -622,7 +620,7 @@ if ! $UNINSTALL;
then then
pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]} pitfttype=${PITFT_TYPES[$PITFT_SELECT-1]}
pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]} pitftrot=${PITFT_ROTATIONS[$PITFT_ROTATE-1]}
touchrot=$pitftrot
if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ] && [ "${pitfttype}" != "st7789_240x320" ] && [ "${pitfttype}" != "st7789_240x135" ]; then if [ "${pitfttype}" != "28r" ] && [ "${pitfttype}" != "28c" ] && [ "${pitfttype}" != "35r" ] && [ "${pitfttype}" != "22" ] && [ "${pitfttype}" != "st7789_240x240" ] && [ "${pitfttype}" != "st7789_240x320" ] && [ "${pitfttype}" != "st7789_240x135" ]; then
echo "Type must be one of:" echo "Type must be one of:"

View file

@ -1,93 +0,0 @@
"""
Adafruit Raspberry Pi Fan Service Setup Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
"""
import os
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group = 'ADAFRUIT'
def main():
shell.clear()
if shell.is_raspberry_pi():
print("""This script will enable the Raspberry Pi
fan service, which will turn on an
external fan controlled by a given pin
Operations performed include:
- Enable Fan Service
Run time < 1 minute. Reboot required.""")
else:
print("""This script will install Adafruit
fan service, which will turn on an
external fan controlled by a given pin
Operations performed include:
- Create a Fan Service File
- Enable Fan Service
- Automatically Start Fan Service
on System startup
Run time < 1 minute. Reboot not required.""")
if not shell.argument_exists('y'):
if not shell.prompt("CONTINUE?", default='n'):
print("Canceled.")
shell.exit()
print("Continuing...")
# check init system (technique borrowed from raspi-config):
shell.group = 'FAN'
shell.info('Checking init system...')
if shell.run_command("which systemctl", suppress_message=True) and shell.run_command("systemctl | grep '\-\.mount'", suppress_message=True):
print("Found systemd, OK!")
elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):
shell.bail("Found sysvinit, but we require systemd")
else:
shell.bail("Unrecognised init system")
if shell.is_raspberry_pi():
shell.info('Enabling Raspberry Pi Fan Service on GPIO 4')
shell.run_command("sudo raspi-config nonint do_fan 0 4")
shell.info('Done!')
shell.prompt_reboot()
else:
shell.info('Adding adafruit_fan.service')
contents = """[Unit]
Description=Fan service for some Adafruit boards
After=network.target
[Service]
Type=oneshot
ExecStartPre=-/bin/bash -c 'echo 4 >/sys/class/gpio/export'
ExecStartPre=/bin/bash -c 'echo out >/sys/class/gpio/gpio4/direction'
ExecStart=/bin/bash -c 'echo 1 >/sys/class/gpio/gpio4/value'
RemainAfterExit=true
ExecStop=/bin/bash -c 'echo 0 >/sys/class/gpio/gpio4/value'
StandardOutput=journal
[Install]
WantedBy=multi-user.target"""
shell.write_text_file("/etc/systemd/system/adafruit_fan.service", contents, append=False)
shell.info('Enabling adafruit_fan.service')
shell.run_command("sudo systemctl enable adafruit_fan.service")
shell.run_command("sudo systemctl start adafruit_fan.service")
shell.info('Done!')
print("You can stop the fan service with 'sudo systemctl stop adafruit_fan.service'")
print("You can start the fan service with 'sudo systemctl start adafruit_fan.service'")
# Main function
if __name__ == "__main__":
shell.require_root()
main()

237
ar1100.py
View file

@ -1,237 +0,0 @@
#!/usr/bin/python
import usb.core
import usb.util
import time
import os
import pygame
from pygame.locals import *
def mapnum(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
CALIBRATED_5IN_800x480 = [
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x55, 0x80, 0x05, 0x05, 0x40, 0x03, 0x00, 0x20, 0x00, 0x50, 0x00, 0x80, 0x00, 0xb0, 0x00, 0xe0,
0x00, 0x20, 0x00, 0x50, 0x00, 0x80, 0x00, 0xb0, 0x00, 0xe0, 0x4d, 0x2a, 0x3a, 0x2b, 0xcb, 0x56,
0xb5, 0x29, 0x18, 0x82, 0xe9, 0x29, 0x41, 0xad, 0x06, 0x2b, 0x16, 0xd9, 0x42, 0x2a, 0x45, 0x29,
0x82, 0x53, 0x10, 0x56, 0xda, 0x54, 0x99, 0x81, 0xcf, 0x55, 0x5e, 0xac, 0xec, 0x55, 0x83, 0xd8,
0xcf, 0x55, 0xf1, 0x29, 0x3d, 0x82, 0xa0, 0x55, 0x11, 0x82, 0x22, 0x81, 0x4b, 0x81, 0x47, 0xad,
0xc2, 0x82, 0x06, 0xd9, 0xc8, 0x82, 0x65, 0x2a, 0xda, 0xac, 0xc1, 0x55, 0xa3, 0xac, 0xeb, 0x80,
0x26, 0xae, 0x27, 0xac, 0xd9, 0xad, 0x8e, 0xd8, 0xd9, 0xae, 0x8b, 0x28, 0xb9, 0xda, 0x9a, 0x54,
0x59, 0xdb, 0x1e, 0x7f, 0x78, 0xdc, 0x0f, 0xad, 0xdd, 0xdc, 0x88, 0xd8, 0xde, 0xdb, 0x00, 0x00,
]
CALIBRATED_7IN_800x480 = [
0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x55, 0x80, 0x03, 0x03, 0x40, 0x02, 0x00, 0x20, 0x00, 0x80, 0x00, 0xe0, 0x00, 0xb0, 0x00, 0xe0,
0x00, 0x20, 0x00, 0x80, 0x00, 0xe0, 0x00, 0xb0, 0x00, 0xe0, 0x7f, 0x22, 0x5c, 0x2d, 0xbf, 0x7d,
0xdd, 0x2a, 0xaf, 0xdc, 0xf3, 0x2b, 0x21, 0x23, 0xb2, 0x82, 0xb4, 0x80, 0x4c, 0x82, 0x40, 0xde,
0xe7, 0x85, 0x42, 0x23, 0xcc, 0xd6, 0xda, 0x7e, 0x7d, 0xd7, 0xd9, 0xdc, 0x8b, 0xd8, 0x83, 0xd8,
0xcf, 0x55, 0xf1, 0x29, 0x3d, 0x82, 0xa0, 0x55, 0x11, 0x82, 0x22, 0x81, 0x4b, 0x81, 0x47, 0xad,
0xc2, 0x82, 0x06, 0xd9, 0xc8, 0x82, 0x65, 0x2a, 0xda, 0xac, 0xc1, 0x55, 0xa3, 0xac, 0xeb, 0x80,
0x26, 0xae, 0x27, 0xac, 0xd9, 0xad, 0x8e, 0xd8, 0xd9, 0xae, 0x8b, 0x28, 0xb9, 0xda, 0x9a, 0x54,
0x59, 0xdb, 0x1e, 0x7f, 0x78, 0xdc, 0x0f, 0xad, 0xdd, 0xdc, 0x88, 0xd8, 0xde, 0xdb, 0x00, 0x00,
]
writeeeprom = CALIBRATED_5IN_800x480;
USB_MODE_GENERIC = [0x55, 0x01, 0x70]
USB_MODE_MOUSE = [0x55, 0x01, 0x71]
MCP_VID = 0x04D8
MOUSE_PID = 0x0C02
GENERIC_PID = 0x0C01
# Try to locate it as a mouse:
dev = usb.core.find(idVendor=MCP_VID, idProduct=MOUSE_PID)
if dev:
# first endpoint
interface = 0
endpoint = dev[0][(0,0)][0]
# if the OS kernel already claimed the device, which is most likely true
# thanks to http://stackoverflow.com/questions/8218683/pyusb-cannot-set-configuration
if dev.is_kernel_driver_active(interface) is True:
# tell the kernel to detach
dev.detach_kernel_driver(interface)
# claim the device
usb.util.claim_interface(dev, interface)
# try to send it command to swap to generic HID
try:
# turn into HID
# bReq, wVal, wIndex, data
ret = dev.ctrl_transfer(0x21, 0x09, 0x0003, 0x0000, [0x55, 0x01, 0x70])
if (ret == 3):
print("Turned into HID!")
except:
# failed to get data for this request
print("Failed to turn into HID")
exit(-1)
# Try to locate it as a mouse:
dev = usb.core.find(idVendor=MCP_VID, idProduct=GENERIC_PID)
if (not dev):
print("Couldn't find generic either :/")
exit(-1)
print("Found Generic!")
interface = 0
endpoint = dev[0][(0,0)][1]
while True:
#try:
if dev.is_kernel_driver_active(interface) is True:
# tell the kernel to detach
dev.detach_kernel_driver(interface)
# claim the device
usb.util.claim_interface(dev, interface)
time.sleep(1)
dev.set_configuration()
break
#except:
# print("retrying set config...")
print("Writing EEPROM...")
for addr in range (0x60, 0xFF, 8):
msg = [0x55, 0x04 + 8, 0x29, 0x00, addr, 8]
msg.extend(writeeeprom[addr-0x60:addr-0x60+8])
#print(msg)
#print(', '.join([hex(i) for i in msg]))
ret = dev.write(1, msg)
#print("Wrote : ", ret)
ret = dev.read(0x81, 64)
#print("Read : ", readeeprom.extend(ret[4:20]))
#print(', '.join([hex(i) for i in ret[0:4]]))
if ret[2] != 0:
print("Failed to write")
exit(-1)
print("Reading EEPROM...")
readeeprom = []
for addr in range (0x60, 0xF8 , 16):
msg = [0x55, 0x04, 0x28, 0x00, addr, 16]
ret = dev.write(1, msg)
#print("Wrote :", ret)
ret = dev.read(0x81, 64)
#print("Read :",ret)
readeeprom.extend(ret[4:20])
#print(', '.join([hex(i) for i in ret[4:20]]))
for i in range(len(readeeprom)):
print(("0x%02x," % readeeprom[i]), end='')
if (i % 16 == 15):
print("")
#print(", 0x%2X".join([hex (i) for i in readeeprom]))
# compare eeproms
if (writeeeprom != readeeprom):
print("Failed to write eeprom correctly (verification fail)")
exit(-1)
print("EEPROM verified OK!")
# try to send it command to swap to generic HID
try:
# turn into Mouse
# bReq, wVal, wIndex, data
ret = dev.ctrl_transfer(0x21, 0x09, 0x0003, 0x0000, [0x55, 0x01, 0x71])
if (ret == 3):
print("Turned into Mouse!")
except:
# failed to get data for this request
print("Failed to turn into Mouse")
exit(-1)
try:
# release the device
usb.util.release_interface(dev, interface)
# reattach the device to the OS kernel
dev.attach_kernel_driver(interface)
except:
pass
time.sleep(3)
# Try to locate it as a mouse:
dev = usb.core.find(idVendor=MCP_VID, idProduct=MOUSE_PID)
if not dev:
print("No mouse :(")
exit(-1)
# first endpoint
interface = 0
endpoint = dev[0][(0,0)][0]
# if the OS kernel already claimed the device, which is most likely true
# thanks to http://stackoverflow.com/questions/8218683/pyusb-cannot-set-configuration
if dev.is_kernel_driver_active(interface) is True:
# tell the kernel to detach
dev.detach_kernel_driver(interface)
# claim the device
usb.util.claim_interface(dev, interface)
# set up pygame
white = (255, 255, 255)
w = 800
h = 480
# Output to the LCD instead of the console
os.putenv("DISPLAY", ":0")
pygame.init()
screen = pygame.display.set_mode((w, h))
running = 1
img = pygame.image.load('gradient800x480.jpg')
screen.fill((white))
screen.blit(img,(0,0))
pygame.display.flip()
while running:
for event in pygame.event.get():
print(event)
if event.type == QUIT:
exit(0)
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
pygame.quit()
exit(0)
try:
data = dev.read(endpoint.bEndpointAddress,endpoint.wMaxPacketSize)
#print(data)
x = data[1] + (data[2] << 8)
y = data[3] + (data[4] << 8)
#print(x, y)
x = mapnum(x, 0, 4096, 0, w)
y = mapnum(y, 0, 4096, 0, h)
print(x, y)
pygame.draw.circle(screen, white, (x,y), 10)
pygame.display.flip()
except usb.core.USBError as e:
data = None
if e.args == ('Operation timed out',):
continue
# release the device
usb.util.release_interface(dev, interface)
# reattach the device to the OS kernel
dev.attach_kernel_driver(interface)

View file

@ -110,8 +110,8 @@ echo "Updating package index files..."
apt-get update apt-get update
echo "Installing Python libraries..." echo "Installing Python libraries..."
apt-get install -y python3-pip apt-get install -y --force-yes python-pip python-dev python-smbus
pip3 install evdev smbus pip install evdev
echo "Installing Adafruit code in /boot..." echo "Installing Adafruit code in /boot..."
cd /tmp cd /tmp
@ -158,10 +158,10 @@ fi
grep arcadeBonnet.py /etc/rc.local >/dev/null grep arcadeBonnet.py /etc/rc.local >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# arcadeBonnet.py already in rc.local, but make sure correct: # arcadeBonnet.py already in rc.local, but make sure correct:
sed -i "s/^.*arcadeBonnet.py.*$/cd \/boot;python3 arcadeBonnet.py \&/g" /etc/rc.local >/dev/null sed -i "s/^.*arcadeBonnet.py.*$/cd \/boot;python arcadeBonnet.py \&/g" /etc/rc.local >/dev/null
else else
# Insert arcadeBonnet.py into rc.local before final 'exit 0' # Insert arcadeBonnet.py into rc.local before final 'exit 0'
sed -i "s/^exit 0/cd \/boot;python3 arcadeBonnet.py \&\\nexit 0/g" /etc/rc.local >/dev/null sed -i "s/^exit 0/cd \/boot;python arcadeBonnet.py \&\\nexit 0/g" /etc/rc.local >/dev/null
fi fi
# Add udev rule (will overwrite if present) # Add udev rule (will overwrite if present)

View file

@ -1,91 +0,0 @@
#!/bin/bash
if [ $(id -u) -ne 0 ]; then
echo "Installer must be run as root."
echo "Try 'sudo bash $0'"
exit 1
fi
clear
echo "This script will install Adafruit"
echo "fan service, which will turn on an"
echo "external fan controlled by a given pin"
echo
echo "Operations performed include:"
echo "- Create a Fan Service File"
echo "- Enable Fan Service"
echo "- Automatically Start Fan Service"
echo " on System startup"
echo
echo "Run time < 1 minute. Reboot not required."
echo
group=ADAFRUIT
function info() {
system="$1"
group="${system}"
shift
FG="1;32m"
BG="40m"
echo -e "[\033[${FG}\033[${BG}${system}\033[0m] $*"
}
function bail() {
FG="1;31m"
BG="40m"
echo -en "[\033[${FG}\033[${BG}${group}\033[0m] "
if [ -z "$1" ]; then
echo "Exiting due to error"
else
echo "Exiting due to error: $*"
fi
exit 1
}
if [ "$1" != '-y' ]; then
echo -n "CONTINUE? [y/N]"
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
fi
echo "Continuing..."
# check init system (technique borrowed from raspi-config):
info FAN 'Checking init system...'
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
echo "Found systemd, OK!"
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
bail "Found sysvinit, but we require systemd"
else
bail "Unrecognised init system"
fi
info FAN 'Adding adafruit_fan.service'
cat > /etc/systemd/system/adafruit_fan.service <<EOF
[Unit]
Description=Fan service for some Adafruit boards
After=network.target
[Service]
Type=oneshot
ExecStartPre=-/bin/bash -c 'echo 4 >/sys/class/gpio/export'
ExecStartPre=/bin/bash -c 'echo out >/sys/class/gpio/gpio4/direction'
ExecStart=/bin/bash -c 'echo 1 >/sys/class/gpio/gpio4/value'
RemainAfterExit=true
ExecStop=/bin/bash -c 'echo 0 >/sys/class/gpio/gpio4/value'
StandardOutput=journal
[Install]
WantedBy=multi-user.target
EOF
info FAN 'Enabling adafruit_fan.service'
sudo systemctl enable adafruit_fan.service
sudo systemctl start adafruit_fan.service
info FAN 'Done!'
echo "You can stop the fan service with 'sudo systemctl stop adafruit_fan.service'"
echo "You can start the fan service with 'sudo systemctl start adafruit_fan.service'"

View file

@ -1,40 +0,0 @@
#!/bin/sh
# rpi-pin-kernel-firmware: Pin a specific version of the rpi kernel and firmware
set -e
if [ $# -ne 1 ]; then
echo "Usage: $0 kernel-version"
echo
echo "e.g., $0 1.20201126-1"
exit 1
fi
if ! dpkg -l raspberrypi-kernel:armhf > /dev/null 2>&1; then
echo "This command is designed to run only on Raspbian with the armhf kernel"
echo 99
fi
if [ `id -u` -ne 0 ]; then
echo "If necessary, enter your password to run this script as root"
exec sudo sh "$0" "$1"
fi
version=$1
fileversion=$(echo $version | cut -d':' -f 2)
base=http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/
packagelist="libraspberrypi0 libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc raspberrypi-bootloader raspberrypi-kernel raspberrypi-kernel-headers"
set --
for package in $packagelist; do
filename="${package}_${fileversion}_armhf.deb"
set -- "$@" "$filename"
wget --continue -O "$filename" "$base/$filename"
done
dpkg -i "$@"
for package in $packagelist; do
/usr/bin/printf "Package: $package\nPin: version ${version}\nPin-Priority:999\n\n"
done > /etc/apt/preferences.d/99-adafruit-pin-kernel

View file

@ -24,7 +24,7 @@ $ sudo apt install dkms raspberrypi-kernel-headers
$ sudo dpkg -i snd-i2s-rpi-dkms_0.0.2_all.deb $ sudo dpkg -i snd-i2s-rpi-dkms_0.0.2_all.deb
# For this to work, remember to modify these first: # For this to work, remember to modify these first:
# /boot/firmware/config.txt -> dtparam=i2s=on # /boot/config.txt -> dtparam=i2s=on
# and # and
# /etc/modules -> snd-bcm2835 # /etc/modules -> snd-bcm2835
# remember to reboot # remember to reboot

View file

@ -38,7 +38,7 @@
* N.B. playback vs capture is determined by the codec choice * N.B. playback vs capture is determined by the codec choice
* */ * */
static struct simple_card_info card_info; static struct asoc_simple_card_info card_info;
static struct platform_device card_device; static struct platform_device card_device;
/* /*
@ -56,7 +56,7 @@ void device_release_callback(struct device *dev) { /* do nothing */ };
/* /*
* Setup the card info * Setup the card info
*/ */
static struct simple_card_info default_card_info = { static struct asoc_simple_card_info default_card_info = {
.card = "snd_rpi_i2s_card", // -> snd_soc_card.name .card = "snd_rpi_i2s_card", // -> snd_soc_card.name
.name = "simple-card_codec_link", // -> snd_soc_dai_link.name .name = "simple-card_codec_link", // -> snd_soc_dai_link.name
.codec = "snd-soc-dummy", // "dmic-codec", // -> snd_soc_dai_link.codec_name .codec = "snd-soc-dummy", // "dmic-codec", // -> snd_soc_dai_link.codec_name

136
i2samp.py
View file

@ -1,136 +0,0 @@
import os
try:
from adafruit_shell import Shell
from clint.textui import colored
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
BLACKLIST = "/etc/modprobe.d/raspi-blacklist.conf"
PRODUCT_NAME = "I2S Amplifier"
OVERLAY = "googlevoicehat-soundcard"
def driver_loaded(driver_name):
return shell.run_command(f"lsmod | grep -q '{driver_name}'", suppress_message=True)
def main():
reboot = False
shell.clear()
if not shell.is_raspberry_pi():
shell.bail("Non-Raspberry Pi board detected.")
print("\nThis script will install everything needed to use\n"
f"{PRODUCT_NAME}.\n")
print(colored.red("--- Warning ---"))
print("\nAlways be careful when running scripts and commands\n"
"copied from the internet. Ensure they are from a\n"
"trusted source.\n")
if not shell.prompt("Do you wish to continue?"):
print("\nAborting...")
shell.exit()
print("\nChecking hardware requirements...")
# Enable I2S overlay
config = shell.get_boot_config()
if config is None:
shell.bail("No Device Tree Detected, not supported")
print(f"\nAdding Device Tree Entry to {config}")
if shell.pattern_search(config, f"^dtoverlay={OVERLAY}$"):
print("dtoverlay already active")
else:
shell.write_text_file(config, f"dtoverlay={OVERLAY}")
reboot = True
if os.path.exists(BLACKLIST):
print("\nCommenting out Blacklist entry in", BLACKLIST)
shell.pattern_replace(BLACKLIST, "^blacklist[[:space:]]*snd_soc_max98357a.*", "#blacklist snd_soc_max98357a")
shell.pattern_replace(BLACKLIST, "^blacklist[[:space:]]*snd_soc_max98357a_i2c.*", "#blacklist snd_soc_max98357a_i2c")
shell.pattern_replace(BLACKLIST, "^blacklist[[:space:]]*snd_soc_max98357a.*", "#blacklist snd_soc_max98357a")
print("Configuring sound output")
if os.path.exists("/etc/asound.conf"):
if os.path.exists("/etc/asound.conf.old"):
shell.remove("/etc/asound.conf.old")
shell.move("/etc/asound.conf", "/etc/asound.conf.old")
shell.write_text_file("~/asound.conf",
"""
pcm.speakerbonnet {
type hw card 0
}
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "speakerbonnet"
period_time 0
period_size 1024
buffer_size 8192
rate 44100
channels 2
}
}
ctl.dmixer {
type hw card 0
}
pcm.softvol {
type softvol
slave.pcm "dmixer"
control.name "PCM"
control.card 0
}
ctl.softvol {
type hw card 0
}
pcm.!default {
type plug
slave.pcm "softvol"
}
""")
shell.move("~/asound.conf", "/etc/asound.conf")
print("Installing aplay systemd unit")
shell.write_text_file("/etc/systemd/system/aplay.service", """
[Unit]
Description=Invoke aplay from /dev/zero at system start.
[Service]
ExecStart=/usr/bin/aplay -D default -t raw -r 44100 -c 2 -f S16_LE /dev/zero
[Install]
WantedBy=multi-user.target""", append=False)
shell.run_command("sudo systemctl daemon-reload")
shell.run_command("sudo systemctl disable aplay")
print("\nYou can optionally activate '/dev/zero' playback in\n"
"the background at boot. This will remove all\n"
"popping/clicking but does use some processor time.\n\n")
if shell.prompt("Activate '/dev/zero' playback in background? [RECOMMENDED]\n", default="y"):
shell.run_command("sudo systemctl enable aplay")
reboot = True
if driver_loaded("max98357a"):
print(f"\nWe can now test your {PRODUCT_NAME}")
shell.warn("Set your speakers at a low volume if possible!")
if shell.prompt("Do you wish to test your system now?"):
print("Testing...")
shell.run_command("speaker-test -l5 -c2 -t wav")
print("\n" + colored.green("All done!"))
print("\nEnjoy your new $productname!")
if reboot:
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -31,10 +31,10 @@ forcesudo="no" # whether the script requires to be ran with root privileges
promptreboot="no" # whether the script should always prompt user to reboot promptreboot="no" # whether the script should always prompt user to reboot
mininstall="no" # whether the script enforces minimum install routine mininstall="no" # whether the script enforces minimum install routine
customcmd="yes" # whether to execute commands specified before exit customcmd="yes" # whether to execute commands specified before exit
armhfonly="yes" # whether the script is allowed to run on other arch
armv6="yes" # whether armv6 processors are supported armv6="yes" # whether armv6 processors are supported
armv7="yes" # whether armv7 processors are supported armv7="yes" # whether armv7 processors are supported
armv8="yes" # whether armv8 processors are supported armv8="yes" # whether armv8 processors are supported
arm64="yes" # whether arm64 processors are supported
raspbianonly="no" # whether the script is allowed to run on other OSes raspbianonly="no" # whether the script is allowed to run on other OSes
osreleases=( "Raspbian" ) # list os-releases supported osreleases=( "Raspbian" ) # list os-releases supported
oswarning=( "Debian" "Kano" "Mate" "PiTop" "Ubuntu" ) # list experimental os-releases oswarning=( "Debian" "Kano" "Mate" "PiTop" "Ubuntu" ) # list experimental os-releases
@ -46,19 +46,14 @@ ASK_TO_REBOOT=false
CURRENT_SETTING=false CURRENT_SETTING=false
UPDATE_DB=false UPDATE_DB=false
BOOTCMD=/boot/firmware/cmdline.txt BOOTCMD=/boot/cmdline.txt
CONFIG=/boot/firmware/config.txt CONFIG=/boot/config.txt
APTSRC=/etc/apt/sources.list APTSRC=/etc/apt/sources.list
INITABCONF=/etc/inittab INITABCONF=/etc/inittab
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
LOADMOD=/etc/modules LOADMOD=/etc/modules
DTBODIR=/boot/overlays DTBODIR=/boot/overlays
# Fall back to old location
if ! test -f $CONFIG; then
CONFIG=/boot/config.txt
fi
# function define # function define
confirm() { confirm() {
@ -144,13 +139,9 @@ sysreboot() {
} }
arch_check() { arch_check() {
IS_ARM64=false
IS_ARMHF=false IS_ARMHF=false
IS_ARMv6=false IS_ARMv6=false
if uname -m | grep "aarch64" > /dev/null; then
IS_ARM64=true
fi
if uname -m | grep "armv.l" > /dev/null; then if uname -m | grep "armv.l" > /dev/null; then
IS_ARMHF=true IS_ARMHF=true
if uname -m | grep "armv6l" > /dev/null; then if uname -m | grep "armv6l" > /dev/null; then
@ -237,12 +228,10 @@ raspbian_check() {
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
if cat /etc/os-release | grep "/sid" > /dev/null; then if cat /etc/os-release | grep "/sid" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "bullseye" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "buster" > /dev/null; then elif cat /etc/os-release | grep "buster" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "stretch" > /dev/null; then elif cat /etc/os-release | grep "stretch" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "jessie" > /dev/null; then elif cat /etc/os-release | grep "jessie" > /dev/null; then
IS_SUPPORTED=true && IS_EXPERIMENTAL=false IS_SUPPORTED=true && IS_EXPERIMENTAL=false
elif cat /etc/os-release | grep "wheezy" > /dev/null; then elif cat /etc/os-release | grep "wheezy" > /dev/null; then
@ -274,16 +263,13 @@ if [ $debugmode != "no" ]; then
newline newline
fi fi
if ! $IS_ARMHF && ! $IS_ARM64; then if ! $IS_ARMHF; then
warning "This hardware is not supported, sorry!" warning "This hardware is not supported, sorry!"
warning "Config files have been left untouched" warning "Config files have been left untouched"
newline && exit 1 newline && exit 1
fi fi
if $IS_ARM64 && [ $arm64 == "no" ]; then if $IS_ARMv8 && [ $armv8 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer"
newline && exit 1
elif $IS_ARMv8 && [ $armv8 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer" warning "Sorry, your CPU is not supported by this installer"
newline && exit 1 newline && exit 1
elif $IS_ARMv7 && [ $armv7 == "no" ]; then elif $IS_ARMv7 && [ $armv7 == "no" ]; then

View file

@ -1,77 +0,0 @@
import os
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
def main():
shell.clear()
boot_config = shell.get_boot_config()
print("""This script downloads and installs
I2S microphone support.
""")
if not shell.is_raspberry_pi():
shell.bail("Non-Raspberry Pi board detected.")
pi_model = shell.get_board_model()
print("{} detected.\n".format(pi_model))
if pi_model in ("RASPBERRY_PI_ZERO", "RASPBERRY_PI_ZERO_W", "RASPBERRY_PI_B_REV2"):
pimodel_select = 0
elif pi_model in ("RASPBERRY_PI_2B", "RASPBERRY_PI_3B", "RASPBERRY_PI_3B_PLUS", "RASPBERRY_PI_3A_PLUS", "RASPBERRY_PI_ZERO_2_W"):
pimodel_select = 1
elif pi_model in ("RASPBERRY_PI_4B", "RASPBERRY_PI_CM4", "RASPBERRY_PI_400"):
pimodel_select = 2
else:
shell.bail("Unsupported Pi board detected.")
auto_load = (
not shell.argument_exists('noautoload') and
shell.prompt("Auto load module at boot?", force_arg="autoload"))
print("""
Installing...""")
# Get needed packages
shell.run_command("apt-get -y install git raspberrypi-kernel-headers")
# Clone the repo
shell.run_command("git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git")
# Build and install the module
shell.chdir("Raspberry-Pi-Installer-Scripts/i2s_mic_module")
shell.run_command("make clean")
shell.run_command("make")
shell.run_command("make install")
# Setup auto load at boot if selected
if auto_load:
shell.write_text_file(
"/etc/modules-load.d/snd-i2smic-rpi.conf",
"snd-i2smic-rpi"
)
shell.write_text_file(
"/etc/modprobe.d/snd-i2smic-rpi.conf",
"options snd-i2smic-rpi rpi_platform_generation={}".format(pimodel_select)
)
# Enable I2S overlay
shell.run_command(f"sed -i -e 's/#dtparam=i2s/dtparam=i2s/g' {boot_config}")
# Done
print("""DONE.
Settings take effect on next boot.
""")
if not shell.argument_exists('noreboot'):
shell.prompt_reboot(force_arg="reboot")
# Main function
if __name__ == "__main__":
shell.require_root()
# Probably not necessary for now because the Pi 5 doesn't work anyway
if shell.is_raspberry_pi_os() and shell.is_kernel_userspace_mismatched() and shell.is_pi5_or_newer():
shell.bail("Unable to proceed on Pi 5 or newer boards with a with a 32-bit OS. Please reinstall with a 64-bit OS.")
shell.check_kernel_userspace_mismatch()
main()

View file

@ -1,114 +0,0 @@
#!/usr/bin/env bash
set -o xtrace
set -o errexit
set -o pipefail
set -o nounset
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root (use sudo)" 1>&2
exit 1
fi
if [ ! -f /etc/rpi-issue ]; then
echo "Sorry, this drivers only works on raspberry pi"
exit 1
fi
#download the archive
rm -rf WM8960-Audio-HAT
git clone https://github.com/waveshare/WM8960-Audio-HAT
cd WM8960-Audio-HAT
apt-get -y update
apt-get -y install raspberrypi-kernel-headers --no-install-recommends --no-install-suggests
apt-get -y install dkms git i2c-tools libasound2-plugins --no-install-recommends --no-install-suggests
apt-get -y clean
# locate currently installed kernels (may be different to running kernel if
# it's just been updated)
kernels=$(ls /lib/modules)
function install_module {
ver="1.0"
# we create a dir with this version to ensure that 'dkms remove' won't delete
# the sources during kernel updates
marker="0.0.0"
src=$1
mod=$2
if [[ -d /var/lib/dkms/$mod/$ver/$marker ]]; then
rmdir /var/lib/dkms/$mod/$ver/$marker
fi
if [[ -e /usr/src/$mod-$ver || -e /var/lib/dkms/$mod/$ver ]]; then
dkms remove --force -m $mod -v $ver --all || true
rm -rf /usr/src/$mod-$ver
fi
mkdir -p /usr/src/$mod-$ver
cp -a $src/* /usr/src/$mod-$ver/
dkms add -m $mod -v $ver
for kernel in $kernels
do
# It works for kernels greater than or equal 6.5
if [ $(echo "$kernel 6.5" | awk '{if ($1 >= $2) print 1; else print 0}') -eq 0 ]; then
continue
fi
dkms build "$kernel" -k "$kernel" --kernelsourcedir "/lib/modules/$kernel/build" -m $mod -v $ver &&
dkms install --force "$kernel" -k "$kernel" -m $mod -v $ver
done
mkdir -p /var/lib/dkms/$mod/$ver/$marker
}
install_module "./" "wm8960-soundcard"
# install dtbos
cp wm8960-soundcard.dtbo /boot/overlays
#set kernel modules
grep -q "^i2c-dev$" /etc/modules || \
echo "i2c-dev" >> /etc/modules
grep -q "^snd-soc-wm8960$" /etc/modules || \
echo "snd-soc-wm8960" >> /etc/modules
grep -q "^snd-soc-wm8960-soundcard$" /etc/modules || \
echo "snd-soc-wm8960-soundcard" >> /etc/modules
# set modprobe blacklist
grep -q "^blacklist snd_bcm2835$" /etc/modprobe.d/raspi-blacklist.conf || \
echo "blacklist snd_bcm2835" >> /etc/modprobe.d/raspi-blacklist.conf
#set dtoverlays
sed -i -e 's:#dtparam=i2s=on:dtparam=i2s=on:g' /boot/firmware/config.txt || true
sed -i -e 's:#dtparam=i2c_arm=on:dtparam=i2c_arm=on:g' /boot/firmware/config.txt || true
grep -q "^dtoverlay=i2s-mmap$" /boot/firmware/config.txt || \
echo "dtoverlay=i2s-mmap" >> /boot/firmware/config.txt
grep -q "^dtparam=i2s=on$" /boot/firmware/config.txt || \
echo "dtparam=i2s=on" >> /boot/firmware/config.txt
grep -q "^dtoverlay=wm8960-soundcard$" /boot/firmware/config.txt || \
echo "dtoverlay=wm8960-soundcard" >> /boot/firmware/config.txt
#install config files
mkdir -p /etc/wm8960-soundcard
cp *.conf /etc/wm8960-soundcard
cp *.state /etc/wm8960-soundcard
#set service
cp wm8960-soundcard /usr/bin/
chmod -x wm8960-soundcard.service
cp wm8960-soundcard.service /lib/systemd/system/
systemctl enable wm8960-soundcard.service
#cleanup
cd ..
rm -rf WM8960-Audio-HAT
echo "------------------------------------------------------"
echo "Please reboot your raspberry pi to apply all settings"
echo "Enjoy!"
echo "------------------------------------------------------"

View file

@ -1,121 +0,0 @@
"""
Adafruit Raspberry Pi Joy Bonnet Setup Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
"""
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group = "JOY"
def main():
shell.clear()
print("""This script installs software for the Adafruit
Joy Bonnet for Raspberry Pi. Steps include:
- Update package index files (apt-get update).
- Install Python libraries: smbus, evdev.
- Install joyBonnet.py in /boot and
configure /etc/rc.local to auto-start script.
- Enable I2C bus.
- OPTIONAL: disable overscan.
Run time ~10 minutes. Reboot required.
EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN.
""")
if not shell.prompt("CONTINUE?", default='n'):
print("Canceled.")
shell.exit()
print("Continuing...")
disable_overscan = shell.prompt("Disable overscan?", default='n')
install_halt = shell.prompt("Install GPIO-halt utility?", default='n')
if install_halt:
#halt_pin = shell.prompt("Install GPIO-halt utility?"
halt_pin = input("GPIO pin for halt: ").strip()
print("\n")
if disable_overscan:
print("Overscan: disable.")
else:
print("Overscan: keep current setting.")
if install_halt:
print("Install GPIO-halt: YES (GPIO{})".format(halt_pin))
else:
print("Install GPIO-halt: NO")
if not shell.prompt("CONTINUE?", default='n'):
print("Canceled.")
shell.exit()
# START INSTALL ------------------------------------------------------------
# All selections are validated at this point...
print("""
Starting installation...
Updating package index files...""")
shell.run_command('sudo apt-get update', suppress_message=True)
print("Installing Python libraries...")
shell.run_command('sudo apt-get install -y python3-pip python3-dev python3-smbus')
shell.run_command('pip3 install evdev --upgrade')
print("Installing Adafruit code in /boot...")
shell.chdir("/tmp")
shell.run_command("curl -LO https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/joyBonnet.py")
# Moving between filesystems requires copy-and-delete:
shell.copy("joyBonnet.py", "/boot")
shell.remove("joyBonnet.py")
if install_halt:
print("Installing gpio-halt in /usr/local/bin...")
shell.run_command("curl -LO https://github.com/adafruit/Adafruit-GPIO-Halt/archive/master.zip")
shell.run_command("unzip -u master.zip")
shell.chdir("Adafruit-GPIO-Halt-master")
shell.run_command("make")
shell.move("gpio-halt", "/usr/local/bin")
shell.chdir("..")
shell.remove("Adafruit-GPIO-Halt-master")
# CONFIG -------------------------------------------------------------------
print("Configuring system...")
# Enable I2C using raspi-config
shell.run_command("sudo raspi-config nonint do_i2c 0")
# Disable overscan compensation (use full screen):
if disable_overscan:
shell.run_command("sudo raspi-config nonint do_overscan 1")
if install_halt:
if shell.pattern_search("/etc/rc.local", "gpio-halt"):
# gpio-halt already in rc.local, but make sure correct:
shell.pattern_replace("/etc/rc.local", "^.*gpio-halt.*$", "/usr/local/bin/gpio-halt {} &".format(halt_pin))
else:
# Insert gpio-halt into rc.local before final 'exit 0'
shell.pattern_replace("/etc/rc.local", "^exit 0", "/usr/local/bin/gpio-halt {} &\\nexit 0".format(halt_pin))
# Auto-start joyBonnet.py on boot
if shell.pattern_search("/etc/rc.local", "joyBonnet.py"):
# joyBonnet.py already in rc.local, but make sure correct:
shell.pattern_replace("/etc/rc.local", "^.*joyBonnet.py.*$", "cd /boot;python3 joyBonnet.py &")
else:
# Insert joyBonnet.py into rc.local before final 'exit 0'
shell.pattern_replace("/etc/rc.local", "^exit 0", "cd /boot;python3 joyBonnet.py &\\nexit 0")
# Add udev rule (will overwrite if present)
shell.write_text_file("/etc/udev/rules.d/10-retrogame.rules", "SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", ENV{ID_INPUT_KEYBOARD}=\"1\"", append=False)
# PROMPT FOR REBOOT --------------------------------------------------------
print("""DONE.
Settings take effect on next boot.
""")
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -1,60 +0,0 @@
# Instructions!
# cd ~
# sudo apt-get install python3-pip
# sudo pip3 install --upgrade adafruit-python-shell click
# wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/libgpiod.py
# sudo python3 libgpiod.py
import sys
try:
import click
except ImportError:
raise RuntimeError("The library 'Click' was not found. To install, try typing: sudo pip3 install --upgrade click")
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group = 'LIBGPIOD'
@click.command()
@click.option('-l', '--legacy', is_flag=True, help="Install a legacy version of libgpiod for systems with older libraries")
def main(legacy):
print("Installing build requirements - this may take a few minutes!\n")
# install generic linux packages required
shell.run_command("sudo apt-get update")
shell.run_command("sudo apt-get install -y autoconf autoconf-archive automake build-essential git libtool pkg-config python3-dev python3-setuptools swig4.0 wget")
# for raspberry pi we need...
shell.run_command("sudo apt-get install -y raspberrypi-kernel-headers")
build_dir = shell.run_command("mktemp -d /tmp/libgpiod.XXXX", return_output=True).strip()
print(f"Cloning libgpiod repository to {build_dir}\n")
shell.chdir(build_dir)
shell.run_command("git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git .")
if legacy:
shell.run_command("git checkout v1.4.2 -b v1.4.2")
print("Building libgpiod\n")
include_path = shell.run_command("python3 -c \"from sysconfig import get_paths; print(get_paths()['include'])\"", return_output=True)
shell.run_command("export PYTHON_VERSION=3")
shell.run_command("./autogen.sh --enable-tools=yes --prefix=/usr/local/ --enable-bindings-python CFLAGS=\"-I/{}\" && make && sudo make install && sudo ldconfig".format(include_path))
if shell.exists("bindings/python/.libs"):
version = sys.version_info
python_folder = f"python{version.major}.{version.minor}"
shell.run_command(f"sudo cp bindings/python/.libs/gpiod.so /usr/local/lib/{python_folder}/dist-packages/")
shell.run_command(f"sudo cp bindings/python/.libs/gpiod.la /usr/local/lib/{python_folder}/dist-packages/")
shell.run_command(f"sudo cp bindings/python/.libs/gpiod.a /usr/local/lib/{python_folder}/dist-packages/")
shell.exit()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -6,21 +6,6 @@
# chmod +x libgpiod.sh # chmod +x libgpiod.sh
# ./libgpiod.sh # ./libgpiod.sh
is_legacy=0
# Loop through arguments and process them
for arg in "$@"
do
case $arg in
-l|--legacy)
is_legacy=1
shift
;;
*)
shift
;;
esac
done
echo "Installing build requirements - this may take a few minutes!" echo "Installing build requirements - this may take a few minutes!"
echo echo
@ -50,11 +35,6 @@ echo
cd "$build_dir" cd "$build_dir"
git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git . git clone git://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git .
if test $is_legacy = 1; then
git checkout v1.4.2 -b v1.4.2
fi
echo "Building libgpiod" echo "Building libgpiod"
echo echo

View file

@ -1,36 +0,0 @@
# Adafruit HX8257 PiTFT Plus TFT LCD Screen
# width=480,height=320
command 0x01 # _SWRESET and Delay 100ms
delay 100
command 0xB9 0xFF 0x83 0x57 # _SETC and delay 500ms
delay 250
delay 250
command 0xB3 0x80 0x00 0x06 0x06 # _SETRGB 0x80 enables SDO pin (0x00 disables)
command 0xB6 0x25 # _SETCOM -1.52V
command 0xB0 0x68 # _SETOSC Normal mode 70Hz, Idle mode 55 Hz
command 0xCC 0x05 # _SETPANEL BGR, Gate direction swapped
command 0xB1 0x00 0x15 0x1C 0x1C 0x83 0xAA # _SETPWR1 Not deep standby BT VSPR VSNR AP
command 0xC0 0x50 0x50 0x01 0x3C 0x1E 0x08 # _SETSTBA OPON normal OPON idle STBA GEN
command 0xB4 0x02 0x40 0x00 0x2A 0x2A 0x0D 0x78 # _SETCYC NW 0x02 RTN DIV DUM DUM GDON GDOFF
# _SETGAMMA
command 0xE0 0x02 0x0A 0x11 0x1d 0x23 0x35 0x41 0x4b 0x4b 0x42 0x3A 0x27 0x1B 0x08 0x09 0x03 0x02 0x0A 0x11 0x1d 0x23 0x35 0x41 0x4b 0x4b 0x42 0x3A 0x27 0x1B 0x08 0x09 0x03 0x00 0x01
command 0x3A 0x55 # _COLMOD 16 bit
# Command 36h sets the read order from frame memory to the display panel
# Remember to swap width/height on 90/270 rotations
command 0x36 0x00 # rotation 0
#command 0x36 0xA0 # rotation 90
#command 0x36 0xC0 # rotation 180
#command 0x36 0x60 # rotation 270
command 0x35 0x00 # _TEON TW off
command 0x44 0x00 0x02 # _TEARLINE
command 0x11 # _SLPOUT
delay 150
command 0x29 # _DISPON
delay 50

View file

@ -1,48 +0,0 @@
# Adafruit ILI9341 PiTFT TFT LCD Screen
# width=320,height=240
command 0x01 # Software reset
delay 128
command 0xEF 0x03 0x80 0x02
command 0xCF 0x00 0xC1 0x30
command 0xED 0x64 0x03 0x12 0x81
command 0xE8 0x85 0x00 0x78
command 0xCB 0x39 0x2C 0x00 0x34 0x02
command 0xF7 0x20
command 0xEA 0x00 0x00
command 0xc0 0x23 # Power control VRH[5:0]
command 0xc1 0x10 # Power control SAP[2:0];BT[3:0]
command 0xc5 0x3e 0x28 # VCM control
command 0xc7 0x86 # VCM control2
#define MADCTL_MY 0x80 ///< Bottom to top
#define MADCTL_MX 0x40 ///< Right to left
#define MADCTL_MV 0x20 ///< Reverse Mode
#define MADCTL_ML 0x10 ///< LCD refresh Bottom to top
#define MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order
#define MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order
#define MADCTL_MH 0x04 ///< LCD refresh right to left
# Command 36h sets the read order from frame memory to the display panel
# Remember to swap width/height on 90/270 rotations
command 0x36 0x88 # rotation 0
#command 0x36 0xE8 # rotation 90
#command 0x36 0x48 # rotation 180
#command 0x36 0x28 # rotation 270
command 0x37 0x00 # Vertical scroll zero
command 0x3a 0x55 # COLMOD: Pixel Format Set
command 0xb1 0x00 0x18 # Frame Rate Control (In Normal Mode/Full Colors)
command 0xb6 0x08 0x82 0x27 # Display Function Control
command 0xF2 0x00 # 3Gamma Function Disable
command 0x26 0x01 # Gamma curve selected
# Set Gamma
command 0xe0 0x0F 0x31 0x2B 0x0C 0x0E 0x08 0x4E 0xF1 0x37 0x07 0x10 0x03 0x0E 0x09 0x00
command 0xe1 0x00 0x0E 0x14 0x03 0x11 0x07 0x31 0xC1 0x48 0x08 0x0F 0x0C 0x31 0x36 0x0F
command 0x11 # Exit Sleep
delay 120
command 0x29 # Display on
delay 120

View file

@ -1,29 +0,0 @@
# Adafruit ST7789 MiniPiTFT LCD and TFT Bonnet
# width=240,height=240
command 0x01 # _SWRESET and Delay 150ms
delay 150
command 0x11 # _SLPOUT and Delay 10ms
delay 10
command 0x3A 0x55 # _COLMOD and Delay 10ms
delay 10
command 0x36 0x08 # _MADCTL Botton->Top Refresh
command 0x21 # _INVON Hack and Delay 10ms
delay 10
command 0x13 # _NORON and Delay 10ms
delay 10
# Command 36h sets the read order from frame memory to the display panel
# Remember to swap width/height on 90/270 rotations if required
command 0x36 0x00 # rotation 0
#command 0x36 0xA0 # rotation 90
#command 0x36 0xC0 # rotation 180
#command 0x36 0x60 # rotation 270
command 0x29 # _DISPON and Delay 500ms
delay 250
delay 250

View file

@ -1,559 +0,0 @@
"""
Adafruit PiTFT MIPI Display Installer Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Written by Melissa LeBlanc-Williams for Adafruit Industries
"""
import time
import os
try:
import click
except ImportError:
raise RuntimeError("The library 'Click' was not found. To install, try typing: pip3 install Click")
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: pip3 install adafruit-python-shell")
shell = Shell()
shell.group = 'PITFT-MIPI'
__version__ = "1.0.1"
"""
This is the main configuration. Displays should be placed in the order
they are to appear in the menu.
"""
config = [
{
"type": "28r",
"menulabel": "PiTFT 2.4\", 2.8\" or 3.2\" resistive (240x320)",
"product": "2.8\" resistive, PID 1601",
"touchscreen": {
"identifier": "STMPE Touchscreen Calibration",
"product": "stmpe",
"transforms": {
"0": "0.988809 -0.023645 0.060523 -0.028817 1.003935 0.034176 0 0 1",
"90": "0.014773 -1.132874 1.033662 1.118701 0.009656 -0.065273 0 0 1",
"180": "-1.115235 -0.010589 1.057967 -0.005964 -1.107968 1.025780 0 0 1",
"270": "-0.033192 1.126869 -0.014114 -1.115846 0.006580 1.050030 0 0 1",
},
"calibrations": {
"0": "4232 11 -879396 1 5786 -752768 65536",
"90": "33 -5782 21364572 4221 35 -1006432 65536",
"180": "-4273 61 16441290 4 -5772 21627524 65536",
"270": "-9 5786 -784608 -4302 19 16620508 65536",
},
"overlay": "touch-stmpe",
},
"mipi_data": {
"command_bin": "adafruit_ili9341_drm",
"gpio": "dc-gpio=25",
"viewport": {
"90": "width=320,height=240",
"180": "width=240,height=320",
"270": "width=320,height=240",
"0": "width=240,height=320",
},
},
"width": 320,
"height": 240,
},
{
"type": "22",
"menulabel": "PiTFT 2.2\" no touch",
"product": "2.2\" no touch",
"mipi_data": {
"command_bin": "adafruit_ili9341_drm",
"gpio": "dc-gpio=25",
"viewport": {
"90": "width=320,height=240",
"180": "width=240,height=320",
"270": "width=320,height=240",
"0": "width=240,height=320",
},
},
"width": 320,
"height": 240,
},
{
"type": "28c",
"menulabel": "PiTFT 2.8\" capacitive touch",
"product": "2.8\" capacitive, PID 1983",
"touchscreen": {
"identifier": "FocalTech Touchscreen Calibration",
"product": "EP0110M09",
"transforms": {
"0": "-1 0 1 0 -1 1 0 0 1",
"90": "0 1 0 -1 0 1 0 0 1",
"180": "1 0 0 0 1 0 0 0 1",
"270": "0 -1 1 1 0 0 0 0 1",
},
"calibrations": "320 65536 0 -65536 0 15728640 65536",
"overlay": "touch-ft6236",
},
"mipi_data": {
"command_bin": "adafruit_ili9341_drm",
"gpio": "dc-gpio=25",
"viewport": {
"90": "width=320,height=240",
"180": "width=240,height=320",
"270": "width=320,height=240",
"0": "width=240,height=320",
},
},
"width": 320,
"height": 240,
},
{
"type": "35r",
"menulabel": "PiTFT 3.5\" resistive touch",
"product": "3.5\" Resistive",
"touchscreen": {
"identifier": "STMPE Touchscreen Calibration",
"product": "stmpe",
"transforms": {
"0": "-1.098388 0.003455 1.052099 0.005512 -1.093095 1.026309 0 0 1",
"90": "-0.000087 1.094214 -0.028826 -1.091711 -0.004364 1.057821 0 0 1",
"180": "1.102807 0.000030 -0.066352 0.001374 1.085417 -0.027208 0 0 1",
"270": "0.003893 -1.087542 1.025913 1.084281 0.008762 -0.060700 0 0 1",
},
"calibrations": {
"0": "5724 -6 -1330074 26 8427 -1034528 65536",
"90": "5 8425 -978304 -5747 61 22119468 65536",
"180": "-5682 -1 22069150 13 -8452 32437698 65536",
"270": "3 -8466 32440206 5703 -1 -1308696 65536",
},
"overlay": "touch-stmpe",
},
"mipi_data": {
"command_bin": "adafruit_hx8357_drm",
"gpio": "dc-gpio=25",
"viewport": {
"90": "width=480,height=320",
"180": "width=320,height=480",
"270": "width=480,height=320",
"0": "width=320,height=480",
},
},
"width": 480,
"height": 320,
"x11_scale": 1.5,
},
{
"type": "st7789_240x240",
"menulabel": "PiTFT Mini 1.3\" or 1.54\" display",
"product": "1.54\" or 1.3\" no touch",
"mipi_data": {
"command_bin": "adafruit_st7789_drm",
"gpio": "dc-gpio=25,backlight-gpio=22",
"viewport": {
"0": "width=240,height=240",
"90": "width=240,height=240,x-offset=80",
"180": "width=240,height=240,y-offset=80",
"270": "width=240,height=240",
},
},
"width": 240,
"height": 240,
},
{
"type": "st7789_240x320",
"menulabel": "ST7789V 2.0\" no touch",
"product": "2.0\" no touch",
"mipi_data": {
"command_bin": "adafruit_st7789_drm",
"gpio": "dc-gpio=25,backlight-gpio=22",
"viewport": {
"0": "width=320,height=240",
"90": "width=240,height=320",
"180": "width=320,height=240",
"270": "width=240,height=320",
},
},
"width": 320,
"height": 240,
},
{
"type": "st7789_240x135",
"menulabel": "MiniPiTFT 1.14\" display",
"product": "1.14\" no touch",
"mipi_data": {
"command_bin": "adafruit_st7789_drm",
"gpio": "dc-gpio=25,backlight-gpio=22",
"viewport": {
"0": "width=136,height=240,x-offset=52,y-offset=40",
"90": "width=240,height=136,y-offset=52,x-offset=40",
"180": "width=136,height=240,x-offset=52,y-offset=40",
"270": "width=240,height=136,y-offset=52,x-offset=40",
},
},
"width": 240,
"height": 135,
},
{
"type": "st7789v_bonnet_240x240",
"menulabel": "BrainCraft HAT or TFT 1.3\" Bonnet + Joystick",
"product": "1.3\" Joystick",
"mipi_data": {
"command_bin": "adafruit_st7789_drm",
"gpio": "dc-gpio=25,backlight-gpio=26",
"viewport": {
"0": "width=240,height=240",
"90": "width=240,height=240,x-offset=80",
"180": "width=240,height=240,y-offset=80",
"270": "width=240,height=240",
},
},
"width": 240,
"height": 240,
},
]
# default mipi data
mipi_data = {
"speed": 40000000,
"spi": "spi0-0",
}
PITFT_ROTATIONS = ("90", "180", "270", "0")
UPDATE_DB = False
SYSTEMD = None
MIPI_MINIMUM_KERNEL = 5.15
pitft_config = None
pitftrot = None
auto_reboot = None
def warn_exit(message):
shell.warn(message)
shell.exit(1)
def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
print("Adafruit PiTFT Helper v{}".format(__version__))
shell.exit(1)
def progress(ellipsis_count):
for i in range(ellipsis_count):
print("...", end='')
time.sleep(1)
print("")
def sysupdate():
global UPDATE_DB
if not UPDATE_DB:
print("Updating apt indexes...", end='')
progress(3)
if not shell.run_command('sudo apt update', suppress_message=True):
warn_exit("Apt failed to update indexes!")
if not shell.run_command('sudo apt-get update', suppress_message=True):
warn_exit("Apt failed to update indexes!")
print("Reading package lists...")
progress(3)
UPDATE_DB = True
return True
############################ Sub-Scripts ############################
def softwareinstall():
print("Installing Pre-requisite Software...This may take a few minutes!")
if not shell.run_command("apt-get install -y libts0", suppress_message=True):
if not shell.run_command("apt-get install -y tslib"):
if not shell.run_command("apt-get install -y libts-dev"):
warn_exit("Apt failed to install TSLIB!")
if not shell.run_command("apt-get install -y bc fbi git python3-dev python3-pip python3-smbus python3-spidev evtest libts-bin device-tree-compiler libraspberrypi-dev build-essential python3-evdev"):
warn_exit("Apt failed to install software!")
return True
def uninstall_bootconfigtxt():
"""Remove any old flexfb/fbtft stuff"""
if shell.pattern_search(f"{boot_dir}/config.txt", "adafruit-pitft-helper"):
print(f"Already have an adafruit-pitft-helper section in {boot_dir}/config.txt.")
print("Removing old section...")
shell.run_command(f"cp {boot_dir}/config.txt {boot_dir}/configtxt.bak")
shell.pattern_replace(f"{boot_dir}/config.txt", '\n# --- added by adafruit-pitft-helper.*?\n# --- end adafruit-pitft-helper.*?\n', multi_line=True)
return True
def update_configtxt():
f"""update {boot_dir}/config.txt with appropriate values"""
uninstall_bootconfigtxt()
# Driver does not work if hdmi_force_hotplug=1 is present
shell.pattern_replace(f"{boot_dir}/config.txt", "hdmi_force_hotplug=1", "hdmi_force_hotplug=0")
display_overlay = f"dtoverlay=mipi-dbi-spi,{mipi_data['spi']},speed=40000000"
display_overlay += f"\ndtparam=compatible={mipi_data['command_bin']}\\0panel-mipi-dbi-spi"
viewport = ""
if mipi_data['viewport'][pitftrot] is not None:
viewport = mipi_data['viewport'][pitftrot]
display_overlay += f"\ndtparam={viewport}"
if "gpio" in mipi_data:
display_overlay += f"\ndtparam={mipi_data['gpio']}"
# Touch Overlay
touch_overlay = ""
if "touchscreen" in pitft_config and "overlay" in pitft_config["touchscreen"]:
# use dtc to compile and copy overlay
touch_overlay = pitft_config["touchscreen"]["overlay"]
shell.run_command(f"dtc -I dts -O dtb -o {boot_dir}/overlays/{touch_overlay}.dtbo overlays/{touch_overlay}.dts")
touch_overlay = f"\ndtoverlay={touch_overlay}"
date = shell.date()
shell.write_text_file(f"{boot_dir}/config.txt", f"""
# --- added by adafruit-pitft-helper {date} ---
[all]
dtparam=spi=on
dtparam=i2c1=on
dtparam=i2c_arm=on
{display_overlay}
{touch_overlay}
# --- end adafruit-pitft-helper {date} ---
""")
return True
def update_udev():
shell.write_text_file("/etc/udev/rules.d/95-touchmouse.rules", """
SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
""", append=False)
shell.write_text_file("/etc/udev/rules.d/95-ftcaptouch.rules", """
SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
SUBSYSTEM=="input", ATTRS{name}=="generic ft5x06*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
""", append=False)
shell.write_text_file("/etc/udev/rules.d/95-stmpe.rules", """
SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
""", append=False)
return True
def compile_display_fw():
command_src = "mipi/panel.txt"
# We could just copy the file to panel.txt, edit that, then remove it after
shell.copy(f"mipi/{mipi_data['command_bin']}.txt", command_src)
# Make sure each of the lines with "# rotation" starts with exactly 1 # and no more
shell.pattern_replace(command_src, "^#*(.*?# rotation.*?$)", "#\\1")
# Uncomment the one for the rotation we are going for
shell.pattern_replace(command_src, "^#(.*?# rotation " + pitftrot + ".*?$)", "\\1")
# Download the mipi-dbi-cmd script if it doesn't exist
if not shell.exists("mipi-dbi-cmd"):
shell.run_command("wget https://raw.githubusercontent.com/notro/panel-mipi-dbi/main/mipi-dbi-cmd")
shell.run_command("chmod +x mipi-dbi-cmd")
# Run the mipi-dbi-script and output directly to the /lib/firmware folder
shell.run_command(f"./mipi-dbi-cmd /lib/firmware/{mipi_data['command_bin']}.bin mipi/panel.txt")
shell.remove(command_src)
return True
def update_pointercal():
if "calibrations" in pitft_config["touchscreen"]:
if isinstance(pitft_config["touchscreen"]["calibrations"], dict):
shell.write_text_file("/etc/pointercal", pitft_config["touchscreen"]["calibrations"][pitftrot])
else:
shell.write_text_file("/etc/pointercal", pitft_config["touchscreen"]["calibrations"])
return True
def install_mipi():
global mipi_data
if "mipi_data" in pitft_config:
mipi_data.update(pitft_config['mipi_data'])
if not compile_display_fw():
shell.bail("Unable to compile MIPI firmware")
# if there's X11 installed...
if shell.exists("/etc/lightdm"):
print("Setting raspi-config to boot to desktop w/o login...")
shell.run_command("raspi-config nonint do_boot_behaviour B4")
# Disable overscan compensation (use full screen):
shell.run_command("raspi-config nonint do_overscan 1")
if not update_configtxt():
shell.bail(f"Unable to update {boot_dir}/config.txt")
return True
def update_xorg():
if "touchscreen" in pitft_config:
transform = "Option \"TransformationMatrix\" \"{}\"".format(pitft_config["touchscreen"]["transforms"][pitftrot])
shell.write_text_file("/usr/share/X11/xorg.conf.d/20-calibration.conf", f"""
Section "InputClass"
Identifier "{pitft_config["touchscreen"]["identifier"]}"
MatchProduct "{pitft_config["touchscreen"]["product"]}"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
{transform}
EndSection
""",
append=False,
)
return True
def get_config_types():
types = []
for item in config:
types.append(item["type"])
return types
def get_config(type):
for item in config:
if item["type"] == type:
return item
return None
def success():
global auto_reboot
shell.info("Success!")
print("""
Settings take effect on next boot.
""")
if auto_reboot is None:
auto_reboot = shell.prompt("REBOOT NOW?", default="y")
if not auto_reboot:
print("Exiting without reboot.")
shell.exit()
print("Reboot started...")
shell.reboot()
shell.exit()
####################################################### MAIN
target_homedir = "/home/pi"
username = os.environ["SUDO_USER"]
user_homedir = os.path.expanduser(f"~{username}")
if shell.isdir(user_homedir):
target_homedir = user_homedir
boot_dir = "/boot/firmware"
if not shell.exists(boot_dir) or not shell.isdir(boot_dir):
boot_dir = "/boot"
@click.command()
@click.option('-v', '--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help="Print version information")
@click.option('-u', '--user', nargs=1, default=target_homedir, type=str, help="Specify path of primary user's home directory", show_default=True)
@click.option('--display', nargs=1, default=None, help="Specify a display option (1-{}) or type {}".format(len(config), get_config_types()))
@click.option('--rotation', nargs=1, default=None, type=int, help="Specify a rotation option (1-4) or degrees {}".format(tuple(sorted([int(x) for x in PITFT_ROTATIONS]))))
@click.option('--reboot', nargs=1, default=None, type=click.Choice(['yes', 'no']), help="Specify whether to reboot after the script is finished")
@click.option('--boot', nargs=1, default=boot_dir, type=str, help="Specify the boot directory", show_default=True)
def main(user, display, rotation, reboot, boot):
global target_homedir, pitft_config, pitftrot, auto_reboot, boot_dir
shell.clear()
if user != target_homedir:
target_homedir = user
print(f"Homedir = {target_homedir}")
if boot != boot_dir:
if shell.isdir(boot):
boot_dir = boot
print(f"Boot dir = {boot_dir}")
else:
print(f"{boot} not found or not a directory. Using {boot_dir} instead.")
print("""This script downloads and installs
PiTFT Support using userspace touch
controls and a DTO for display drawing.
one of several configuration files.
Run time of up to 5 minutes. Reboot required!
""")
if reboot is not None:
auto_reboot = reboot.lower() == 'yes'
# Check that the user is running the minimum kernel on this device
if not shell.kernel_minimum(MIPI_MINIMUM_KERNEL):
shell.warn(f"In order to continue, you will need to update your kernel to a minimum of {MIPI_MINIMUM_KERNEL}. ")
if shell.get_os() == "Raspbian":
shell.info("It looks like you are running this on a Raspberry Pi. You can update it to the latest version by running 'sudo rpi-update'.")
shell.exit()
if display in [str(x) for x in range(1, len(config) + 1)]:
pitft_config = config[int(display) - 1]
print("Display Type: {}".format(pitft_config["menulabel"]))
elif display in get_config_types():
pitft_config = get_config(display)
print("Display Type: {}".format(pitft_config["menulabel"]))
else:
# Build menu from config
selections = []
for item in config:
option = "{} ({}x{})".format(item['menulabel'], item['width'], item['height'])
selections.append(option)
selections.append("Quit without installing")
PITFT_SELECT = shell.select_n("Select configuration:", selections)
if PITFT_SELECT == len(config) + 1:
shell.exit(1)
pitft_config = config[PITFT_SELECT - 1]
if rotation is not None and 1 <= rotation <= 4:
pitftrot = PITFT_ROTATIONS[rotation - 1]
print("Rotation: {}".format(pitftrot))
elif str(rotation) in PITFT_ROTATIONS:
pitftrot = str(rotation)
print("Rotation: {}".format(pitftrot))
else:
PITFT_ROTATE = shell.select_n(
"Select rotation:", (
"90 degrees (landscape)",
"180 degrees (portrait)",
"270 degrees (landscape)",
"0 degrees (portrait)"
))
pitftrot = PITFT_ROTATIONS[PITFT_ROTATE - 1]
if 'rotations' in pitft_config and isinstance(pitft_config['rotations'], dict) and pitftrot in pitft_config['rotations'] and pitft_config['rotations'][pitftrot] is None:
shell.bail("""Unfortunately {rotation} degrees for the {display} is not working at this time. Please
restart the script and choose a different orientation.""".format(rotation=pitftrot, display=pitft_config["menulabel"]))
# check init system (technique borrowed from raspi-config):
shell.info('Checking init system...')
if shell.run_command("which systemctl", suppress_message=True) and shell.run_command("systemctl | grep '\-\.mount'", suppress_message=True):
SYSTEMD = True
print("Found systemd")
elif os.path.isfile("/etc/init.d/cron") and not os.path.islink("/etc/init.d/cron"):
SYSTEMD = False
print("Found sysvinit")
else:
shell.bail("Unrecognised init system")
if shell.grep("boot", "/proc/mounts"):
print("/boot is mounted")
else:
print("/boot must be mounted. if you think it's not, quit here and try: sudo mount /dev/mmcblk0p1 /boot")
if shell.prompt("Continue?"):
print("Proceeding.")
else:
shell.bail("Aborting.")
if not shell.isdir(target_homedir):
shell.bail("{} must be an existing directory (use -u /home/foo to specify)".format(target_homedir))
shell.info("System update")
if not sysupdate():
shell.bail("Unable to apt-get update")
shell.info("Installing Python libraries & Software...")
if not softwareinstall():
shell.bail("Unable to install software")
shell.info("Adding MIPI support...")
if not install_mipi():
shell.bail("Unable to configure mipi")
shell.info(f"Updating {boot_dir}/config.txt...")
if not update_configtxt():
shell.bail(f"Unable to update {boot_dir}/config.txt")
if "touchscreen" in pitft_config:
shell.info("Updating SysFS rules for Touchscreen...")
if not update_udev():
shell.bail("Unable to update /etc/udev/rules.d")
shell.info("Updating TSLib default calibration...")
if not update_pointercal():
shell.bail("Unable to update /etc/pointercal")
if shell.exists("/etc/lightdm"):
shell.info("Updating X11 default calibration...")
if not update_xorg():
shell.bail("Unable to update calibration")
success()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -1,5 +1,5 @@
/* /*
* Device Tree overlay for Adafruit Mini PiTFT 1.14" 135x240 Display * Device Tree overlay for Adafruit Mini PiTFT 1.14" Display
* *
*/ */
@ -18,9 +18,6 @@
status = "disabled"; status = "disabled";
}; };
spidev@1{
status = "disabled";
};
}; };
}; };
@ -28,9 +25,9 @@
target = <&gpio>; target = <&gpio>;
__overlay__ { __overlay__ {
pitft_pins: pitft_pins { pitft_pins: pitft_pins {
brcm,pins = <25>; brcm,pins = <25>; /* dc pin */
brcm,function = <1>; /* out */ brcm,function = <1>; /* out */
brcm,pull = <0>; /* none */ brcm,pull = <0>; /* no pull */
}; };
}; };
}; };
@ -43,29 +40,39 @@
#size-cells = <0>; #size-cells = <0>;
pitft: pitft@0{ pitft: pitft@0{
compatible = "fbtft,minipitft13"; compatible = "multi-inno,mi0283qt";
reg = <0>; reg = <0>;
pinctrl-names = "default"; pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>; pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>; spi-max-frequency = <32000000>;
rotate = <270>; rotation = <90>;
width = <135>; width = <136>;
height = <240>; height = <240>;
txbuflen = <32768>; col_offset = <53>;
buswidth = <8>; row_offset = <40>;
dc-gpios = <&gpio 25 0>; dc-gpios = <&gpio 25 0>;
led-gpios = <&gpio 26 0>; backlight = <&backlight>;
debug = <0>; };
};
};
fragment@3 {
target-path = "/soc";
__overlay__ {
backlight: backlight {
compatible = "gpio-backlight";
gpios = <&gpio 22 0>;
}; };
}; };
}; };
__overrides__ { __overrides__ {
speed = <&pitft>,"spi-max-frequency:0"; speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0"; rotation = <&pitft>,"rotation:0";
width = <&pitft>,"width:0"; width = <&pitft>,"width:0";
height = <&pitft>,"height:0"; height = <&pitft>,"height:0";
fps = <&pitft>,"fps:0"; col_offset = <&pitft>,"col_offset:0";
debug = <&pitft>,"debug:0"; row_offset = <&pitft>,"row_offset:0";
}; };
}; };

View file

@ -43,7 +43,7 @@
#size-cells = <0>; #size-cells = <0>;
pitft: pitft@0{ pitft: pitft@0{
compatible = "fbtft,minipitft13"; compatible = "sitronix,st7789v";
reg = <0>; reg = <0>;
pinctrl-names = "default"; pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>; pinctrl-0 = <&pitft_pins>;
@ -51,7 +51,6 @@
rotate = <0>; rotate = <0>;
width = <240>; width = <240>;
height = <240>; height = <240>;
txbuflen = <32768>;
buswidth = <8>; buswidth = <8>;
dc-gpios = <&gpio 25 0>; dc-gpios = <&gpio 25 0>;
led-gpios = <&gpio 26 0>; led-gpios = <&gpio 26 0>;

View file

@ -1,71 +0,0 @@
/*
* Device Tree overlay for pitft by Adafruit
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@1 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <25>;
brcm,function = <1>; /* out */
brcm,pull = <0>; /* none */
};
};
};
fragment@3 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
pitft: pitft@0{
compatible = "ilitek,ili9340";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotate = <90>;
fps = <25>;
bgr;
buswidth = <8>;
dc-gpios = <&gpio 25 0>;
debug = <0>;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0", /* fbtft */
<&pitft>,"rotation:0"; /* drm */
fps = <&pitft>,"fps:0";
debug = <&pitft>,"debug:0";
drm = <&pitft>,"compatible=adafruit,yx240qv29";
};
};

View file

@ -1,114 +0,0 @@
/*
* Device Tree overlay for Adafruit PiTFT 2.4" resistive touch screen with tsc2007
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
};
};
fragment@2 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@3 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
fragment@4 {
target = <&gpio>;
__overlay__ {
adafruit_2_4_tft_pins: adafruit_2_4_tft_pins {
brcm,pins = <25 24 18>;
brcm,function = <1 0 1>; /* out in out*/
brcm,pull = <0 2 2>; /* none up up */
};
};
};
fragment@5 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
cs-gpios = <&gpio 8 1>;
adafruit_2_4_tft: adafruit_2_4_tft@0{
compatible = "adafruit,yx240qv29";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&adafruit_2_4_tft_pins>;
spi-max-frequency = <32000000>;
rotation = <90>;
reset-gpios = <&gpio 23 0>;
dc-gpios = <&gpio 25 0>;
};
};
};
fragment@7 {
target = <&i2c1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";
tsc2007: tsc2007@48 {
compatible = "ti,tsc2007";
reg = <0x48>;
ti,fuzzx = <4>;
ti,fuzzy = <4>;
ti,max-rt = <3700>;
ti,fuzzz = <4>;
ti,x-plate-ohms = <180>;
panel = <&adafruit_2_4_tft>;
pinctrl-0 = <&adafruit_2_4_tft_pins>;
interrupt-parent = <&gpio>;
interrupts = <24 2>;
gpios = <&gpio 24 1>;
};
};
};
fragment@8 {
target-path = "/soc";
__overlay__ {
backlight: backlight {
compatible = "gpio-backlight";
pinctrl-0 = <&adafruit_2_4_tft_pins>;
gpios = <&gpio 18 2>;
default-on;
};
};
};
__overrides__ {
speed = <&adafruit_2_4_tft>,"spi-max-frequency:0";
rotate = <&adafruit_2_4_tft>,"rotation:0";
fps = <&adafruit_2_4_tft>,"fps:0";
debug = <&adafruit_2_4_tft>,"debug:0";
// xohms = <&tsc2007>,"touchscreen-x-plate-ohms;0";
// swapxy = <&tsc2007>,"touchscreen-swapped-x-y?";
};
};

View file

@ -1,93 +0,0 @@
/*
* Device Tree overlay for Adafruit PiTFT 2.8" capacitive touch screen
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <24 25>;
brcm,function = <0 1>; /* in out */
brcm,pull = <2 0>; /* pullup none */
};
};
};
fragment@3 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft@0{
compatible = "ilitek,ili9340";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotate = <90>;
fps = <25>;
bgr;
buswidth = <8>;
dc-gpios = <&gpio 25 0>;
debug = <0>;
};
};
};
fragment@4 {
target = <&i2c1>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
ft6236: ft6236@38 {
compatible = "focaltech,ft6236";
reg = <0x38>;
interrupt-parent = <&gpio>;
interrupts = <24 2>;
touchscreen-size-x = <240>;
touchscreen-size-y = <320>;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0", /* fbtft */
<&pitft>,"rotation:0"; /* drm */
fps = <&pitft>,"fps:0";
debug = <&pitft>,"debug:0";
drm = <&pitft>,"compatible=adafruit,yx240qv29";
touch-sizex = <&ft6236>,"touchscreen-size-x:0";
touch-sizey = <&ft6236>,"touchscreen-size-y:0";
touch-invx = <&ft6236>,"touchscreen-inverted-x?";
touch-invy = <&ft6236>,"touchscreen-inverted-y?";
touch-swapxy = <&ft6236>,"touchscreen-swapped-x-y?";
};
};

View file

@ -1,126 +0,0 @@
/*
* Device Tree overlay for Adafruit PiTFT 2.8" resistive touch screen
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
fragment@3 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <24 25>;
brcm,function = <0 1>; /* in out */
brcm,pull = <2 0>; /* pullup none */
};
};
};
fragment@4 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft@0{
compatible = "ilitek,ili9340";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotate = <90>;
fps = <25>;
bgr;
buswidth = <8>;
dc-gpios = <&gpio 25 0>;
debug = <0>;
};
pitft_ts@1 {
/* needed to avoid dtc warning */
#address-cells = <1>;
#interrupt-cells = <1>;
compatible = "st,stmpe610";
reg = <1>;
spi-max-frequency = <500000>;
interrupts = <24 2>; /* high-to-low edge triggered */
interrupt-parent = <&gpio>;
interrupt-controller;
stmpe_touchscreen: stmpe_touchscreen {
compatible = "st,stmpe-ts";
st,sample-time = <4>;
st,mod-12b = <1>;
st,ref-sel = <0>;
st,adc-freq = <2>;
st,ave-ctrl = <3>;
st,touch-det-delay = <4>;
st,settling = <2>;
st,fraction-z = <7>;
st,i-drive = <0>;
};
stmpe_gpio: stmpe_gpio {
#gpio-cells = <2>;
compatible = "st,stmpe-gpio";
/*
* only GPIO2 is wired/available
* and it is wired to the backlight
*/
st,norequest-mask = <0x7b>;
};
};
};
};
fragment@5 {
target-path = "/soc";
__overlay__ {
backlight {
compatible = "gpio-backlight";
gpios = <&stmpe_gpio 2 0>;
default-on;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0", /* fbtft */
<&pitft>,"rotation:0"; /* drm */
fps = <&pitft>,"fps:0";
debug = <&pitft>,"debug:0";
drm = <&pitft>,"compatible=adafruit,yx240qv29";
touch-invx = <&stmpe_touchscreen>,"touchscreen-inverted-x?";
touch-invy = <&stmpe_touchscreen>,"touchscreen-inverted-y?";
touch-swapxy = <&stmpe_touchscreen>,"touchscreen-swapped-x-y?";
};
};

View file

@ -1,127 +0,0 @@
/*
* Device Tree overlay for Adafruit PiTFT 3.5" resistive touch screen
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev0>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
fragment@3 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <24 25>;
brcm,function = <0 1>; /* in out */
brcm,pull = <2 0>; /* pullup none */
};
};
};
fragment@4 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft@0{
compatible = "himax,hx8357d";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotate = <90>;
fps = <25>;
bgr;
buswidth = <8>;
dc-gpios = <&gpio 25 0>;
debug = <0>;
};
pitft_ts@1 {
/* needed to avoid dtc warning */
#address-cells = <1>;
#interrupt-cells = <1>;
compatible = "st,stmpe610";
reg = <1>;
spi-max-frequency = <500000>;
interrupts = <24 2>; /* high-to-low edge triggered */
interrupt-parent = <&gpio>;
interrupt-controller;
stmpe_touchscreen: stmpe_touchscreen {
compatible = "st,stmpe-ts";
st,sample-time = <4>;
st,mod-12b = <1>;
st,ref-sel = <0>;
st,adc-freq = <2>;
st,ave-ctrl = <3>;
st,touch-det-delay = <4>;
st,settling = <2>;
st,fraction-z = <7>;
st,i-drive = <0>;
};
stmpe_gpio: stmpe_gpio {
#gpio-cells = <2>;
compatible = "st,stmpe-gpio";
/*
* only GPIO2 is wired/available
* and it is wired to the backlight
*/
st,norequest-mask = <0x7b>;
};
};
};
};
fragment@5 {
target-path = "/soc";
__overlay__ {
backlight: backlight {
compatible = "gpio-backlight";
gpios = <&stmpe_gpio 2 0>;
default-on;
};
};
};
__overrides__ {
speed = <&pitft>,"spi-max-frequency:0";
rotate = <&pitft>,"rotate:0", /* fbtft */
<&pitft>,"rotation:0"; /* drm */
fps = <&pitft>,"fps:0";
debug = <&pitft>,"debug:0";
drm = <&pitft>,"compatible=adafruit,yx350hv15",
<&pitft>,"backlight:0=",<&backlight>;
touch-invx = <&stmpe_touchscreen>,"touchscreen-inverted-x?";
touch-invy = <&stmpe_touchscreen>,"touchscreen-inverted-y?";
touch-swapxy = <&stmpe_touchscreen>,"touchscreen-swapped-x-y?";
};
};

View file

@ -51,7 +51,6 @@
rotate = <0>; rotate = <0>;
width = <240>; width = <240>;
height = <320>; height = <320>;
txbuflen = <32768>;
buswidth = <8>; buswidth = <8>;
dc-gpios = <&gpio 25 0>; dc-gpios = <&gpio 25 0>;
led-gpios = <&gpio 12 0>; led-gpios = <&gpio 12 0>;

View file

@ -1,115 +0,0 @@
/*
* Device Tree overlay for Adafruit TFT Bonnet 1.3" 240x240 Display + Joystick
*
*/
/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 = <25>;
brcm,function = <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 = "fbtft,minipitft13";
reg = <0>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <32000000>;
rotate = <0>;
width = <240>;
height = <240>;
buswidth = <8>;
dc-gpios = <&gpio 25 0>;
led-gpios = <&gpio 26 0>;
debug = <0>;
};
};
};
fragment@3 {
target-path = "/";
__overlay__ {
keypad: tft_bonnet_keys {
compatible = "gpio-keys";
button@17 {
label = "Controller Up";
linux,code = <103>;
gpios = <&gpio 17 1>;
};
button@22 {
label = "Controller Down";
linux,code = <108>;
gpios = <&gpio 22 1>;
};
button@27 {
label = "Controller Left";
linux,code = <105>;
gpios = <&gpio 27 1>;
};
button@23 {
label = "Controller Right";
linux,code = <106>;
gpios = <&gpio 23 1>;
};
button@4 {
label = "Controller Center";
linux,code = <28>;
gpios = <&gpio 4 1>;
};
button@5 {
label = "Controller B";
linux,code = <48>;
gpios = <&gpio 5 1>;
};
button@6 {
label = "Controller A";
linux,code = <30>;
gpios = <&gpio 6 1>;
};
};
};
};
__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";
};
};

View file

@ -1,53 +0,0 @@
/*
* Device Tree overlay for the Focaltech FT6236 capacitive
* touch screen controller on the Adafruit PiTFT
*
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <24>;
brcm,function = <0>; /* in out */
brcm,pull = <2>; /* pullup none */
};
};
};
fragment@1 {
target = <&i2c1>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
ft6236: ft6236@38 {
compatible = "focaltech,ft6236";
reg = <0x38>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
interrupt-parent = <&gpio>;
interrupts = <24 2>;
touchscreen-size-x = <240>;
touchscreen-size-y = <320>;
};
};
};
__overrides__ {
touch-sizex = <&ft6236>,"touchscreen-size-x?";
touch-sizey = <&ft6236>,"touchscreen-size-y?";
touch-invx = <&ft6236>,"touchscreen-inverted-x?";
touch-invy = <&ft6236>,"touchscreen-inverted-y?";
touch-swapxy = <&ft6236>,"touchscreen-swapped-x-y?";
};
};

View file

@ -1,81 +0,0 @@
/*
* Device Tree overlay for the STMPE resistive
* touch screen controller on the Adafruit PiTFT
*/
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
fragment@0 {
target = <&spi0>;
__overlay__ {
status = "okay";
};
};
fragment@1 {
target = <&spidev1>;
__overlay__ {
status = "disabled";
};
};
fragment@2 {
target = <&gpio>;
__overlay__ {
pitft_pins: pitft_pins {
brcm,pins = <24>;
brcm,function = <0>; /* in out */
brcm,pull = <2>; /* pullup none */
};
};
};
fragment@3 {
target = <&spi0>;
__overlay__ {
/* needed to avoid dtc warning */
#address-cells = <1>;
#size-cells = <0>;
pitft: pitft_ts@1 {
compatible = "st,stmpe610";
reg = <1>;
pinctrl-names = "default";
pinctrl-0 = <&pitft_pins>;
spi-max-frequency = <500000>;
irq-gpio = <&gpio 24 0x2>; /* IRQF_TRIGGER_FALLING */
interrupts = <24 2>; /* high-to-low edge triggered */
interrupt-parent = <&gpio>;
interrupt-controller;
stmpe_touchscreen {
compatible = "st,stmpe-ts";
st,sample-time = <4>;
st,mod-12b = <1>;
st,ref-sel = <0>;
st,adc-freq = <2>;
st,ave-ctrl = <3>;
st,touch-det-delay = <4>;
st,settling = <2>;
st,fraction-z = <7>;
st,i-drive = <0>;
};
stmpe_gpio: stmpe_gpio {
#gpio-cells = <2>;
compatible = "st,stmpe-gpio";
/*
* only GPIO2 is wired/available
* and it is wired to the backlight
*/
st,norequest-mask = <0x7b>;
};
};
};
};
};

Binary file not shown.

View file

@ -6,6 +6,27 @@ if [ $(id -u) -ne 0 ]; then
exit 1 exit 1
fi fi
clear
# smbus and ads1x15 Python libs are installed regardless whether ADC
echo "This script installs software for the Adafruit"
echo "Snake Eyes Bonnet for Raspberry Pi. Steps include:"
echo "- Update package index files (apt-get update)"
echo "- Install Python libraries: numpy, pi3d, svg.path,"
echo " rpi-gpio, python3-dev, python3-pil"
echo "- Install Adafruit eye code and data in /boot"
echo "- Enable SPI0 and SPI1 peripherals if needed"
echo "- Set HDMI resolution, disable overscan"
echo "Run time ~25 minutes. Reboot required."
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo
echo -n "CONTINUE? [y/N] "
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
# FEATURE PROMPTS ---------------------------------------------------------- # FEATURE PROMPTS ----------------------------------------------------------
# Installation doesn't begin until after all user input is taken. # Installation doesn't begin until after all user input is taken.
@ -32,45 +53,6 @@ selectN() {
done done
} }
clear
echo "This script installs Adafruit Snake Eyes Bonnet"
echo "software for Raspberry Pi. It's best to dedicate"
echo "a card to this, not for systems in regular use."
echo
echo "Target system (may be different than current host):"
selectN "Raspberry Pi 4, Pi 400, or Compute Module 4" "All other models"
#if [[ $? -eq "1" ]]; then
if [ $? -eq "1" ]; then
IS_PI4=1
fi
if [ $IS_PI4 ]; then
# Verify this is Raspbian Desktop OS (X11 should exist)
if [ ! -d "/usr/bin/X11" ]; then
echo "Target system is Pi 4/400/CM4 but this appears to"
echo "be a \"Lite\" OS. \"Desktop\" OS is required."
echo -n "Continue anyway? [y/N]"
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
fi
else
# Verify this is Raspbian Lite OS (X11 should NOT exist)
if [ -d "/usr/bin/X11" ]; then
echo "Target system is not Pi 4/400/CM4 yet this appears to"
echo "be a \"Desktop\" OS. \"Lite\" OS (Legacy) is required."
echo -n "Continue anyway? [y/N]"
read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled."
exit 0
fi
fi
fi
SCREEN_VALUES=(-o -t -i) SCREEN_VALUES=(-o -t -i)
SCREEN_NAMES=("OLED (128x128)" "TFT (128x128)" "IPS (240x240)" HDMI) SCREEN_NAMES=("OLED (128x128)" "TFT (128x128)" "IPS (240x240)" HDMI)
RADIUS_VALUES=(128 128 240) RADIUS_VALUES=(128 128 240)
@ -92,7 +74,7 @@ if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
HALT_PIN=$REPLY HALT_PIN=$REPLY
fi fi
echo -n "Install Bonnet ADC support? [y/N] " echo -n "Install ADC support? [y/N] "
read read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
INSTALL_ADC=1 INSTALL_ADC=1
@ -111,31 +93,15 @@ if [ $INSTALL_HALT -eq 1 ]; then
else else
echo "Install GPIO-halt: NO" echo "Install GPIO-halt: NO"
fi fi
echo "Bonnet ADC support: ${OPTION_NAMES[$INSTALL_ADC]}" echo "ADC support: ${OPTION_NAMES[$INSTALL_ADC]}"
echo "Ethernet USB gadget support: ${OPTION_NAMES[$INSTALL_GADGET]}" echo "Ethernet USB gadget support: ${OPTION_NAMES[$INSTALL_GADGET]}"
if [ $SCREEN_SELECT -eq 3 ]; then if [ $SCREEN_SELECT -eq 3 ]; then
echo "Video resolution will be set to 1280x720, no overscan" echo "Video resolution will be set to 1280x720, no overscan"
else else
echo "Video resolution will be set to 640x480, no overscan" echo "Video resolution will be set to 640x480, no overscan"
fi fi
echo echo
echo "Installation steps include:" echo -n "CONTINUE? [y/N] "
echo "- Update package index files (apt-get update)"
echo "- Install Python libraries: numpy, pi3d, svg.path,"
echo " rpi-gpio, python3-dev, python3-pil"
echo "- Install Adafruit eye code and data in /boot"
echo "- Set HDMI resolution, GPU RAM, disable overscan"
if [ $IS_PI4 ]; then
echo "- Disable desktop, configure video driver"
fi
echo "- Enable SPI0 and SPI1 peripherals if needed"
echo
echo "THIS IS A ONE-WAY OPERATION, NO UNINSTALL PROVIDED."
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo "Run time ~10 minutes. Reboot required."
echo
echo -n "Do you understand and want to proceed? [y/N]"
read read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled." echo "Canceled."
@ -179,8 +145,8 @@ apt-get update
echo "Installing Python libraries..." echo "Installing Python libraries..."
# WAS: apt-get install -y --force-yes python-pip python-dev python-imaging python-smbus # WAS: apt-get install -y --force-yes python-pip python-dev python-imaging python-smbus
apt-get install -y python3-pip python3-dev python3-pil python3-smbus libatlas-base-dev apt-get install -y python3-pip python3-dev python3-pil python3-smbus libatlas-base-dev
# WAS: pip3 install numpy pi3d==2.34 svg.path rpi-gpio adafruit-ads1x15 # WAS: pip3 install numpy pi3d svg.path rpi-gpio adafruit-ads1x15
pip3 install numpy pi3d svg.path rpi-gpio adafruit-blinka adafruit-circuitpython-ads1x15 pip3 install numpy pi3d==2.34 svg.path rpi-gpio adafruit-blinka adafruit-circuitpython-ads1x15
# smbus and Blinka+ADC libs are installed regardless whether ADC is # smbus and Blinka+ADC libs are installed regardless whether ADC is
# enabled; simplifies the Python code a little (no "uncomment this") # enabled; simplifies the Python code a little (no "uncomment this")
@ -206,47 +172,9 @@ fi
echo "Configuring system..." echo "Configuring system..."
if [ $IS_PI4 ]; then
# Make desktop system to boot to console (from raspi-config script):
systemctl set-default multi-user.target
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
rm -f /etc/systemd/system/getty@tty1.service.d/autologin.conf
# Pi3D requires "fake" KMS overlay to work. Check /boot/config.txt for
# vc4-fkms-v3d overlay present and active. If so, nothing to do here,
# module's already configured.
grep '^dtoverlay=vc4-fkms-v3d' /boot/config.txt >/dev/null
if [ $? -ne 0 ]; then
# fkms overlay not present, or is commented out. Check if vc4-kms-v3d
# (no 'f') is present and active. That's normally the default.
grep '^dtoverlay=vc4-kms-v3d' /boot/config.txt >/dev/null
if [ $? -eq 0 ]; then
# It IS present. Comment out that line for posterity, and insert the
# 'fkms' item on the next line.
sed -i "s/^dtoverlay=vc4-kms-v3d/#&\ndtoverlay=vc4-fkms-v3d/g" /boot/config.txt >/dev/null
else
# It's NOT present. Silently append 'fkms' overlay to end of file.
echo dtoverlay=vc4-fkms-v3d | sudo tee -a /boot/config.txt >/dev/null
fi
fi
# Disable screen blanking in X config
echo "Section \"ServerFlags\"
Option \"BlankTime\" \"0\"
Option \"StandbyTime\" \"0\"
Option \"SuspendTime\" \"0\"
Option \"OffTime\" \"0\"
Option \"dpms\" \"false\"
EndSection" > /etc/X11/xorg.conf
fi
# Disable overscan compensation (use full screen): # Disable overscan compensation (use full screen):
raspi-config nonint do_overscan 1 raspi-config nonint do_overscan 1
# Dedicate 128 MB to the GPU:
sudo raspi-config nonint do_memory_split 128
# HDMI settings for Pi eyes # HDMI settings for Pi eyes
reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1" reconfig /boot/config.txt "^.*hdmi_force_hotplug.*$" "hdmi_force_hotplug=1"
reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2" reconfig /boot/config.txt "^.*hdmi_group.*$" "hdmi_group=2"
@ -259,7 +187,6 @@ else
reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=640 480 60 1 0 0 0" reconfig /boot/config.txt "^.*hdmi_cvt.*$" "hdmi_cvt=640 480 60 1 0 0 0"
fi fi
# Enable I2C for ADC # Enable I2C for ADC
if [ $INSTALL_ADC -ne 0 ]; then if [ $INSTALL_ADC -ne 0 ]; then
raspi-config nonint do_i2c 0 raspi-config nonint do_i2c 0
@ -308,19 +235,11 @@ if [ $SCREEN_SELECT -ne 4 ]; then
grep eyes.py /etc/rc.local >/dev/null grep eyes.py /etc/rc.local >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# eyes.py already in rc.local, but make sure correct: # eyes.py already in rc.local, but make sure correct:
if [ $IS_PI4 ]; then
sed -i "s/^.*eyes.py.*$/cd \/boot\/Pi_Eyes;xinit \/usr\/bin\/python3 eyes.py --radius $RADIUS \:0 \&/g" /etc/rc.local >/dev/null
else
sed -i "s/^.*eyes.py.*$/cd \/boot\/Pi_Eyes;python3 eyes.py --radius $RADIUS \&/g" /etc/rc.local >/dev/null sed -i "s/^.*eyes.py.*$/cd \/boot\/Pi_Eyes;python3 eyes.py --radius $RADIUS \&/g" /etc/rc.local >/dev/null
fi
else else
# Insert eyes.py into rc.local before final 'exit 0' # Insert eyes.py into rc.local before final 'exit 0'
if [ $IS_PI4 ]; then
sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;xinit \/usr\/bin\/python3 eyes.py --radius $RADIUS \:0 \&\\nexit 0/g" /etc/rc.local >/dev/null
else
sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;python3 eyes.py --radius $RADIUS \&\\nexit 0/g" /etc/rc.local >/dev/null sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;python3 eyes.py --radius $RADIUS \&\\nexit 0/g" /etc/rc.local >/dev/null
fi fi
fi
else else
@ -328,19 +247,11 @@ else
grep cyclops.py /etc/rc.local >/dev/null grep cyclops.py /etc/rc.local >/dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
# cyclops.py already in rc.local, but make sure correct: # cyclops.py already in rc.local, but make sure correct:
if [ $IS_PI4 ]; then
sed -i "s/^.*cyclops.py.*$/cd \/boot\/Pi_Eyes;xinit \/usr\/bin\/python3 cyclops.py \:0 \&/g" /etc/rc.local >/dev/null
else
sed -i "s/^.*cyclops.py.*$/cd \/boot\/Pi_Eyes;python3 cyclops.py \&/g" /etc/rc.local >/dev/null sed -i "s/^.*cyclops.py.*$/cd \/boot\/Pi_Eyes;python3 cyclops.py \&/g" /etc/rc.local >/dev/null
fi
else else
# Insert cyclops.py into rc.local before final 'exit 0' # Insert cyclops.py into rc.local before final 'exit 0'
if [ $IS_PI4 ]; then
sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;xinit \/usr\/bin\/python3 cyclops.py \:0 \&\\nexit 0/g" /etc/rc.local >/dev/null
else
sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;python3 cyclops.py \&\\nexit 0/g" /etc/rc.local >/dev/null sed -i "s/^exit 0/cd \/boot\/Pi_Eyes;python3 cyclops.py \&\\nexit 0/g" /etc/rc.local >/dev/null
fi fi
fi
fi fi

View file

@ -1,129 +0,0 @@
"""
Adafruit Pi Touch Cam Setup Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
Note: Currently Untested
"""
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
import os
shell = Shell()
shell.group="Retrogame"
def main():
shell.clear()
print("""This script will install and/or modify
packages needed for the Adafruit Pi
Camera project. It requires that the
adafruit-pitft.sh installer script (for
PiTFT display support) was run first.
Operations performed include:
- In /boot/firmware/config.txt, enable camera
- apt-get update
- Install Python libraries:
picamera, pygame, PIL
- Downgrade SDL library for pygame
touch compatibility
- Download Dropbox Updater and
Adafruit Pi Cam software
Run time 5+ minutes. Reboot required.
""")
boot_config = shell.get_boot_config()
if not shell.prompt("CONTINUE?", default='n'):
print("Canceled.")
shell.exit()
print("Continuing...")
if shell.grep("dtoverlay=pitft", boot_config):
shell.bail(f"PiTFT overlay not in {boot_config}.\n"
"Download & run adafruit-pitft.py first.\n"
"Canceling.")
print("Configuring camera + PiTFT settings...")
# Set PiTFT speed to 80 MHz, 60 Hz
shell.pattern_replace(boot_config, "speed=.*,fps=.*", "speed=80000000,fps=60")
# Check if Pi camera is enabled. If not, add it...
shell.reconfig(boot_config, "^start_x=.*", "start_x=1")
# gpu_mem must be >= 128 MB for camera to work
result = shell.pattern_search(boot_config, "^gpu_mem=", return_match=True)
if not result:
# gpu_mem isn't set. Add to config
shell.write_text_file(boot_config, "\ngpu_mem=128", append=True)
elif result.group(1) < 128:
# gpu_mem present but too small; increase to 128MB
shell.reconfig(boot_config, "^gpu_mem=.*", "gpu_mem=128")
print("Installing prerequisite packages...")
# Enable Wheezy package sources (for SDL downgrade)
shell.write_text_file("/etc/apt/sources.list.d/wheezy.list", "deb http://archive.raspbian.org/raspbian wheezy main\n", append=True)
# Set 'stable' as default package source (current OS)
shell.write_text_file("/etc/apt/apt.conf.d/10defaultRelease", "APT::Default-release \"stable\";\n", append=True)
# Set priority for libsdl from Wheezy higher than current package
shell.write_text_file("/etc/apt/preferences.d/libsdl", (
"Package: libsdl1.2debian\n"
"Pin: release n=stretch\n"
"Pin-Priority: -10\n"
"Pin: release n=jessie\n"
"Pin-Priority: -10\n"
"Package: libsdl1.2debian\n"
"Pin: release n=wheezy\n"
"Pin-Priority:900\n"
))
# Update the APT package index files, install Python libraries
print("Updating System Packages")
if not shell.run_command("sudo apt-get update"):
shell.bail("Apt failed to update indexes!")
print("Installing packages...")
if not shell.run_command("sudo apt-get -y --force-yes install python-picamera python-pygame python-imaging"):
shell.bail("Apt failed to install software!")
print("Downgrading SDL library...")
if not shell.run_command("apt-get -y --force-yes install libsdl1.2debian/wheezy"):
shell.bail("Apt failed to downgrade SDL library!")
print("Downloading Dropbox uploader and")
print("Adafruit Pi Cam to home directory...")
shell.chdir("~pi")
shell.run_command("wget https://github.com/andreafabrizi/Dropbox-Uploader/archive/master.zip")
shell.run_command("unzip master.zip")
shell.remove("master.zip")
shell.move("Dropbox-Uploader-master", "Dropbox-Uploader")
shell.run_command("wget https://github.com/adafruit/adafruit-pi-cam/archive/master.zip")
shell.run_command("unzip master.zip")
shell.remove("master.zip")
shell.chown("Dropbox-Uploader", "pi", recursive=True)
shell.chown("adafruit-pi-cam-master", "pi", recursive=True)
# Add lines to /etc/rc.local (commented out by default):
shell.pattern_replace("/etc/rc.local", "^exit 0", "# Enable this line to run camera at startup:\n# cd /home/pi/adafruit-pi-cam-master ; sudo python cam.py\n\nexit 0")
# Prompt to reboot!
print("\nCamera and PiTFT settings won't take")
print("effect until next boot.")
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -1,181 +0,0 @@
"""
Adafruit Raspberry Pi Blinka Setup Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Written by Melissa LeBlanc-Williams for Adafruit Industries
"""
import os
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group="Blinka"
default_python = 3
blinka_minimum_python_version = 3.8
def default_python_version(numeric=True):
version = shell.run_command("python -c 'import platform; print(platform.python_version())'", suppress_message=True, return_output=True)
if numeric:
try:
return float(version[0:version.rfind(".")])
except ValueError:
return None
return version
def get_python3_version(numeric=True):
version = shell.run_command("python3 -c 'import platform; print(platform.python_version())'", suppress_message=True, return_output=True)
if numeric:
return float(version[0:version.rfind(".")])
return version
def check_blinka_python_version():
"""
Check the Python 3 version for Blinka (which may be a later version than we're running this script with)
"""
print("Making sure the required version of Python is installed")
current = get_python3_version(False)
current_major, current_minor = current.split(".")[0:2]
required_major, required_minor = str(blinka_minimum_python_version).split(".")[0:2]
if int(current_major) >= int(required_major) and int(current_minor) >= int(required_minor):
return
shell.bail("Blinka requires a minimum of Python version {} to install, current one is {}. Please update your OS!".format(blinka_minimum_python_version, current))
def sys_update():
print("Updating System Packages")
if not shell.run_command("sudo apt-get update --allow-releaseinfo-change"):
shell.bail("Apt failed to update indexes!")
print("Upgrading packages...")
if not shell.run_command("sudo apt-get -y upgrade"):
shell.bail("Apt failed to install software!")
def set_raspiconfig():
"""
Enable various Raspberry Pi interfaces
"""
print("Enabling I2C")
shell.run_command("sudo raspi-config nonint do_i2c 0")
print("Enabling SPI")
shell.run_command("sudo raspi-config nonint do_spi 0")
print("Enabling Serial")
if not shell.run_command("sudo raspi-config nonint do_serial_hw 0", suppress_message=True):
shell.run_command("sudo raspi-config nonint do_serial 0")
print("Enabling SSH")
shell.run_command("sudo raspi-config nonint do_ssh 0")
print("Enabling Camera")
shell.run_command("sudo raspi-config nonint do_camera 0")
print("Disable raspi-config at Boot")
shell.run_command("sudo raspi-config nonint disable_raspi_config_at_boot 0")
def update_python():
print("Making sure Python 3 is the default")
if default_python < 3:
shell.run_command("sudo apt-get install -y python3 git python3-pip")
shell.run_command("sudo update-alternatives --install /usr/bin/python python $(which python2) 1")
shell.run_command("sudo update-alternatives --install /usr/bin/python python $(which python3) 2")
shell.run_command("sudo update-alternatives --skip-auto --config python")
def update_pip():
print("Making sure PIP and setuptools is installed")
shell.run_command("sudo apt-get install --upgrade -y python3-pip python3-setuptools")
def install_blinka(user=False):
print("Installing latest version of Blinka locally")
shell.run_command("sudo apt-get install -y i2c-tools libgpiod-dev python3-libgpiod")
pip_command = "pip3 install --upgrade"
username = None
if user:
username = os.environ["SUDO_USER"]
shell.run_command(f"{pip_command} adafruit-blinka", run_as_user=username)
# Custom function to run additional commands for Pi 5
def check_and_install_for_pi5(pi_model, user=False):
if shell.is_pi5_or_newer():
username = None
if user:
# Username should be used for PIP install commands
username = os.environ["SUDO_USER"]
print("Detected Raspberry Pi 5, applying additional fixes...")
if shell.exists("lg"):
shell.remove("lg")
shell.run_command("sudo apt-get install -y wget swig python3-dev python3-setuptools")
# Temporarily install setuptools to as root for the build process
shell.run_command("sudo pip3 install -U setuptools", run_as_user=username)
shell.run_command("wget https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/raw/refs/heads/main/packages/lgpio.zip")
shell.run_command("unzip lgpio.zip")
if shell.exists("lgpio.zip"):
shell.remove("lgpio.zip")
shell.chdir("lgpio")
shell.run_command("make")
shell.run_command("sudo make install")
# Remove setuptools after the build process is complete
shell.run_command("sudo pip3 uninstall -y setuptools", run_as_user=username)
else:
print(f"Detected {pi_model}, no additional fixes needed.")
def check_user_groups():
# Check if the user has the groups i2c, spi, gpio, input, and video. If the user is not in a group, then they need to be added.
groups = shell.run_command("groups", suppress_message=True, return_output=True).split()
required_groups = ["i2c", "spi", "gpio", "input", "video"]
for group in required_groups:
if group not in groups:
print(f"Adding user to the group: {group}.")
shell.run_command(f"sudo usermod -aG {group} {os.environ['SUDO_USER']}")
def main():
global default_python
shell.clear()
# Check Raspberry Pi and Bail
pi_model = shell.get_board_model()
if not shell.is_raspberry_pi():
shell.bail("This model of Raspberry Pi is not currently supported by Blinka")
print("""This script configures your
Raspberry Pi and installs Blinka
""")
print("{} detected.\n".format(pi_model))
if not shell.is_raspberry_pi():
shell.bail("Non-Raspberry Pi board detected. This must be run on a Raspberry Pi")
os_identifier = shell.get_os()
if os_identifier != "Raspbian":
shell.bail("Sorry, the OS detected was {}. This script currently only runs on Raspberry Pi OS.".format(os_identifier))
if not shell.is_python3():
shell.bail("You must be running Python 3. Older versions have now been deprecated.")
shell.check_kernel_update_reboot_required()
python_version = default_python_version()
if not python_version:
shell.warn("WARNING No Default System python tied to the `python` command. It will be set to Version 3.")
default_python = 0
if not shell.prompt("Continue?"):
shell.exit()
elif int(default_python_version()) < 3:
shell.warn("WARNING Default System python version is {}. It will be updated to Version 3.".format(default_python_version(False)))
default_python = 2
if not shell.prompt("Continue?"):
shell.exit()
sys_update()
check_blinka_python_version()
set_raspiconfig()
update_python()
update_pip()
install_blinka(True)
check_user_groups()
# Check and install any Pi 5 fixes if detected
check_and_install_for_pi5(pi_model, True)
# Done
print("""DONE.
Settings take effect on next boot.
""")
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -1,188 +0,0 @@
"""
Adafruit Raspberry Pi SPI Chip Enable Reassignment Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
"""
try:
import click
except ImportError:
raise RuntimeError("The library 'Click' was not found. To install, try typing: sudo pip3 install --upgrade click")
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group="SPI Reassign"
allowed_gpios = (4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27)
spi0_default_pins = (8, 7)
DISABLE_GPIO_TEXT = "Disabled"
boot_dir = "/boot/firmware"
if not shell.exists(boot_dir) or not shell.isdir(boot_dir):
boot_dir = "/boot"
"""
For now this will only ask about SPI0, but we can later add SPI1
"""
def valid_pins(ce0_pin, ce1_pin):
if ce0_pin is None and ce1_pin is not None:
return False
if ce0_pin is not None and ce0_pin == ce1_pin:
return False
if ce0_pin is not None and int(ce0_pin) not in allowed_gpios:
return False
if ce1_pin is not None and int(ce1_pin) not in allowed_gpios:
return False
return True
def convert_option(pin):
if pin == "disabled":
return None
return int(pin)
def valid_options(ce0_option, ce1_option):
if ce0_option is None or ce1_option is None:
return False
return valid_pins(convert_option(ce0_option), convert_option(ce1_option))
def disable_spi():
print("Disabling SPI")
shell.run_command("sudo raspi-config nonint do_spi 1")
def enable_spi():
print("Enabling SPI")
shell.run_command("sudo raspi-config nonint do_spi 0")
def spi_disabled():
return shell.run_command("sudo raspi-config nonint get_spi", suppress_message=True, return_output=True).strip() == "1"
def remove_custom():
shell.pattern_replace(f"{boot_dir}/config.txt", 'dtoverlay=spi0-[0-2]cs,cs.*?\n', multi_line=True)
def format_gpio(gpio):
if gpio is None:
return DISABLE_GPIO_TEXT
return f"GPIO {gpio}"
def gpio_options(pool):
options = []
for gpio in pool:
options.append(format_gpio(gpio))
return options
def write_new_custom(ce0_pin, ce1_pin):
if (ce0_pin, ce1_pin) != spi0_default_pins:
overlay_command = "dtoverlay=spi0-2cs"
if ce0_pin is None and ce1_pin is None:
overlay_command = "dtoverlay=spi0-0cs"
elif ce1_pin is None:
overlay_command = "dtoverlay=spi0-1cs"
if ce0_pin != spi0_default_pins[0] and ce0_pin is not None:
overlay_command += ",cs0_pin={}".format(ce0_pin)
if ce1_pin != spi0_default_pins[1] and ce1_pin is not None:
overlay_command += ",cs1_pin={}".format(ce1_pin)
shell.write_text_file(f"{boot_dir}/config.txt", overlay_command + "\n")
@click.command()
@click.option('--ce0', nargs=1, default=None, help="Specify a GPIO for CE0 or 'disabled' to disable", type=str)
@click.option('--ce1', nargs=1, default=None, help="Specify a GPIO for CE1 or 'disabled' to disable", type=str)
@click.option('--reboot', nargs=1, default=None, type=click.Choice(['yes', 'no']), help="Specify whether to reboot after the script is finished")
def main(ce0, ce1, reboot):
ask_reboot = True
auto_reboot = False
if reboot is not None:
ask_reboot = False
auto_reboot = reboot.lower() == 'yes'
if valid_options(ce0, ce1):
ce0 = convert_option(ce0)
ce1 = convert_option(ce1)
remove_custom()
write_new_custom(ce0, ce1)
if auto_reboot:
shell.reboot()
if ask_reboot:
shell.prompt_reboot()
exit(0)
else:
print("Invalid ce0 or ce1", ce0, ce1)
#shell.clear()
# Check Raspberry Pi and Bail
pi_model = shell.get_board_model()
print("""This script allows you
to easily reassign the SPI Chip Enable
pins so the OS automatic handling of the
lines doesn't interfere with CircuitPython.
Run time of < 1 minute. Reboot required for
changes to take effect!
""")
menu_options = [
"Reassign SPI Chip Enable Pins",
"Reset to Defaults Pins",
"Disable SPI",
"Exit",
]
if spi_disabled():
menu_options[2] = "Enable SPI"
shell.info("{} detected.\n".format(pi_model))
if not shell.is_raspberry_pi():
shell.bail("Non-Raspberry Pi board detected. This must be run on a Raspberry Pi")
os_identifier = shell.get_os()
if os_identifier != "Raspbian":
shell.bail("Sorry, the OS detected was {}. This script currently only runs on Raspberry Pi OS.".format(os_identifier))
menu_selection = shell.select_n(
"Select an option:", menu_options
)
if menu_selection == 1:
while True:
# Reassign
gpio_pool = list(allowed_gpios)
gpio_pool.append(None)
# Ask for pin for CE0
ce0_selection = shell.select_n("Select a new GPIO for CE0", gpio_options(gpio_pool))
ce0_pin = gpio_pool[ce0_selection - 1]
if ce0_pin is not None:
gpio_pool.remove(ce0_pin)
# Ask for pin for CE1
ce1_selection = shell.select_n("Select a new GPIO for CE1", gpio_options(gpio_pool))
ce1_pin = gpio_pool[ce1_selection - 1]
else:
ce1_pin = None
if shell.prompt(f"The new settings will be {format_gpio(ce0_pin)} for CE0 and {format_gpio(ce1_pin)} for CE1. Is this correct?"):
break
remove_custom()
write_new_custom(ce0_pin, ce1_pin)
if spi_disabled():
enable_spi()
elif menu_selection == 2:
# Reset to Defaults
remove_custom()
elif menu_selection == 3:
# Enable/Disable SPI
if spi_disabled():
enable_spi()
else:
disable_spi()
remove_custom()
elif menu_selection == 4:
# Exit
shell.exit(0)
# Done
print("""DONE.
Settings take effect on next boot.
""")
if auto_reboot:
shell.reboot()
if ask_reboot:
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
echo "NEWS: see https://learn.adafruit.com/read-only-raspberry-pi"
echo "This script is deprecated, with better functionality now in"
echo "the OS without hacks. It's being kept temporarily for reference."
echo "You can edit this part out if you really need to run it."
exit 0
# CREDIT TO THESE TUTORIALS: # CREDIT TO THESE TUTORIALS:
# petr.io/en/blog/2015/11/09/read-only-raspberry-pi-with-jessie # petr.io/en/blog/2015/11/09/read-only-raspberry-pi-with-jessie
# hallard.me/raspberry-pi-read-only # hallard.me/raspberry-pi-read-only
@ -290,23 +284,18 @@ replace /usr/lib/tmpfiles.d/var.conf "spool\s*0755" "spool 1777"
touch /tmp/dhcpcd.resolv.conf touch /tmp/dhcpcd.resolv.conf
rm /etc/resolv.conf rm /etc/resolv.conf
ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf ln -s /tmp/dhcpcd.resolv.conf /etc/resolv.conf
# systemd-ntp must use systemwide /tmp to access /tmp/dhcpcd.resolv.conf
replace /lib/systemd/system/ntp.service "PrivateTmp=true" "PrivateTmp=false"
# Make edits to fstab # Make edits to fstab
# make / ro # make / ro
# tmpfs /var/log tmpfs nodev,nosuid 0 0 # tmpfs /var/log tmpfs nodev,nosuid 0 0
# tmpfs /var/tmp tmpfs nodev,nosuid 0 0 # tmpfs /var/tmp tmpfs nodev,nosuid 0 0
# tmpfs /tmp tmpfs nodev,nosuid 0 0 # tmpfs /tmp tmpfs nodev,nosuid 0 0
replace /etc/fstab "vfat\s*defaults\s.*" "vfat defaults,ro\t0\t0" replace /etc/fstab "vfat\s*defaults\s" "vfat defaults,ro "
replace /etc/fstab "ext4\s*defaults,noatime\s.*" "ext4 defaults,noatime,ro\t0\t0" replace /etc/fstab "ext4\s*defaults,noatime\s" "ext4 defaults,noatime,ro "
append1 /etc/fstab "/var/log" "tmpfs /var/log tmpfs nodev,nosuid 0 0" append1 /etc/fstab "/var/log" "tmpfs /var/log tmpfs nodev,nosuid 0 0"
append1 /etc/fstab "/var/tmp" "tmpfs /var/tmp tmpfs nodev,nosuid 0 0" append1 /etc/fstab "/var/tmp" "tmpfs /var/tmp tmpfs nodev,nosuid 0 0"
append1 /etc/fstab "\s/tmp" "tmpfs /tmp tmpfs nodev,nosuid 0 0" append1 /etc/fstab "\s/tmp" "tmpfs /tmp tmpfs nodev,nosuid 0 0"
# Stop vim creating tmp files in ~/.viminfo (ro)
echo 'set viminfo=""' >>/etc/vim/vimrc.local
# PROMPT FOR REBOOT -------------------------------------------------------- # PROMPT FOR REBOOT --------------------------------------------------------
echo "Done." echo "Done."

View file

@ -1,98 +0,0 @@
"""
Adafruit Retrogame Setup Script
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
Note: Currently Untested
"""
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
import os
shell = Shell()
shell.group="Retrogame"
def main():
shell.clear()
print("""This script downloads and installs
retrogame, a GPIO-to-keypress utility
for adding buttons and joysticks, plus
one of several configuration files.
Run time <1 minute. Reboot recommended.
""")
# Grouped by config name and menu label
config = {
"pigrrl2": "PiGRRL 2 controls",
"pocket": "Pocket PiGRRL",
"zero": "PiGRRL Zero",
"super": "Super Game Pi",
"2button": "Two buttons + joystick",
"6button": "Six buttons + joystick",
"bonnet": "Adafruit Arcade Bonnet",
"cupcade-orig": "Cupcade (gen 1 & 2 only)"
}
RETROGAME_SELECT = shell.select_n(
"Select configuration:", list(config.values()) + ["Quit without installing"]
)
if RETROGAME_SELECT <= len(config):
CONFIG_NAME = list(config.keys())[RETROGAME_SELECT-1]
if shell.exists("/boot/retrogame.cfg"):
print("/boot/retrogame.cfg already exists.\n"
"Continuing will overwrite file.\n")
if not shell.prompt("CONTINUE?", default='n'):
print("Canceled.")
shell.exit()
print("Downloading, installing retrogame...", end="")
# Download to tmpfile because might already be running
if shell.run_command("curl -f -s -o /tmp/retrogame https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/retrogame"):
shell.move("/tmp/retrogame", "/usr/local/bin/")
os.chmod("/usr/local/bin/retrogame", 0o755)
print("OK")
else:
print("ERROR")
print("Downloading, installing retrogame.cfg...", end="")
if shell.run_command(f"curl -f -s -o /boot/retrogame.cfg https://raw.githubusercontent.com/adafruit/Adafruit-Retrogame/master/configs/retrogame.cfg.{CONFIG_NAME}"):
print("OK")
else:
print("ERROR")
print("Performing other system configuration...", end="")
# Add udev rule (will overwrite if present)
shell.write_text_file("/etc/udev/rules.d/10-retrogame.rules", (
r"SUBSYSTEM==\"input\", ATTRS{name}==\"retrogame\", "
r"ENV{ID_INPUT_KEYBOARD}=\"1\""
))
if CONFIG_NAME == "bonnet":
# If Bonnet, make sure I2C is enabled. Call the I2C
# setup function in raspi-config (noninteractive):
shell.run_command("raspi-config nonint do_i2c 0")
# Start on boot
if shell.run_command("grep retrogame /etc/rc.local", suppress_message=True):
# retrogame already in rc.local, but make sure correct:
shell.pattern_replace("/etc/rc.local", "^.*retrogame.*$", "/usr/local/bin/retrogame &")
else:
# Insert retrogame into rc.local before final 'exit 0'
shell.pattern_replace("/etc/rc.local", "^exit 0", "/usr/local/bin/retrogame &\nexit 0")
print("OK")
shell.prompt_reboot()
print("Done")
# Main function
if __name__ == "__main__":
shell.require_root()
main()

View file

@ -7,10 +7,7 @@
# we reference a specific commit (update this as needed): # we reference a specific commit (update this as needed):
GITUSER=https://github.com/hzeller GITUSER=https://github.com/hzeller
REPO=rpi-rgb-led-matrix REPO=rpi-rgb-led-matrix
COMMIT=7a503494378a67f3baa4ac680cecbae2703cc58f COMMIT=21410d2b0bac006b4a1661594926af347b3ce334
# Previously: COMMIT=a3eea997a9254b83ab2de97ae80d83588f696387
# Previously: COMMIT=45d3ab5d6cff6e0c14da58930d662822627471fc
# Previously: COMMIT=21410d2b0bac006b4a1661594926af347b3ce334
# Previously: COMMIT=e3dd56dcc0408862f39cccc47c1d9dea1b0fb2d2 # Previously: COMMIT=e3dd56dcc0408862f39cccc47c1d9dea1b0fb2d2
if [ $(id -u) -ne 0 ]; then if [ $(id -u) -ne 0 ]; then
@ -19,14 +16,6 @@ if [ $(id -u) -ne 0 ]; then
exit 1 exit 1
fi fi
HAS_PYTHON2=$(which python2)
HAS_PYTHON3=$(which python3)
if [ $HAS_PYTHON2 ] && ! [ $HAS_PYTHON3 ]; then
"Python 2 not supported. Must use Python 3."
exit 0
fi
clear clear
echo "This script installs software for the Adafruit" echo "This script installs software for the Adafruit"
@ -39,7 +28,7 @@ echo "- Configure boot options"
echo "Run time ~15 minutes. Some options require reboot." echo "Run time ~15 minutes. Some options require reboot."
echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN." echo "EXISTING INSTALLATION, IF ANY, WILL BE OVERWRITTEN."
echo echo
echo -n "CONTINUE? [y/n] " echo -n "CONTINUE? [y/N] "
read read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled." echo "Canceled."
@ -90,7 +79,7 @@ INTERFACES=( \
) )
QUALITY_OPTS=( \ QUALITY_OPTS=( \
"Quality (disables sound, requires soldering on single matrix Bonnet/HAT)" \ "Quality (disables sound, requires soldering)" \
"Convenience (sound on, no soldering)" \ "Convenience (sound on, no soldering)" \
) )
@ -122,7 +111,7 @@ INTERFACE_TYPE=$?
if [ $INTERFACE_TYPE -eq 1 ]; then if [ $INTERFACE_TYPE -eq 1 ]; then
# For matrix HAT, ask about RTC install # For matrix HAT, ask about RTC install
echo echo
echo -n "Install realtime clock support? [y/n] " echo -n "Install realtime clock support? [y/N] "
read read
if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then if [[ "$REPLY" =~ (yes|y|Y)$ ]]; then
INSTALL_RTC=1 INSTALL_RTC=1
@ -154,14 +143,11 @@ echo "Now you must choose between QUALITY and CONVENIENCE."
echo echo
echo "QUALITY: best output from the LED matrix requires" echo "QUALITY: best output from the LED matrix requires"
echo "commandeering hardware normally used for sound, plus" echo "commandeering hardware normally used for sound, plus"
echo "some soldering on the single matrix Bonnet/HAT. If" echo "some soldering. If you choose this option, there will"
echo "you choose this option, there will"
echo "be NO sound from the audio jack or HDMI (USB audio" echo "be NO sound from the audio jack or HDMI (USB audio"
echo "adapters will work and sound best anyway), AND you" echo "adapters will work and sound best anyway), AND you"
echo "must SOLDER a wire between GPIO4 and GPIO18 on the" echo "must SOLDER a wire between GPIO4 and GPIO18 on the"
echo "single matrix Bonnet or HAT board. For the Triple LED" echo "Bonnet or HAT board."
echo "Matrix Bonnet choose QUALITY, and No soldering is"
echo "required."
echo echo
echo "CONVENIENCE: sound works normally, no extra soldering." echo "CONVENIENCE: sound works normally, no extra soldering."
echo "Images on the LED matrix are not quite as steady, but" echo "Images on the LED matrix are not quite as steady, but"
@ -188,7 +174,7 @@ if [ $QUALITY_MOD -eq 0 ]; then
echo "and GPIO18, and internal sound is DISABLED!" echo "and GPIO18, and internal sound is DISABLED!"
fi fi
echo echo
echo -n "CONTINUE? [y/n] " echo -n "CONTINUE? [y/N] "
read read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Canceled." echo "Canceled."
@ -218,7 +204,7 @@ echo "Updating package index files..."
apt-get update apt-get update
echo "Downloading prerequisites..." echo "Downloading prerequisites..."
apt-get install -y python3-dev python3-pillow cython3 apt-get install -y --force-yes python2.7-dev python-pillow python3-dev python3-pillow
echo "Downloading RGB matrix software..." echo "Downloading RGB matrix software..."
curl -L $GITUSER/$REPO/archive/$COMMIT.zip -o $REPO-$COMMIT.zip curl -L $GITUSER/$REPO/archive/$COMMIT.zip -o $REPO-$COMMIT.zip
@ -228,12 +214,29 @@ mv $REPO-$COMMIT rpi-rgb-led-matrix
echo "Building RGB matrix software..." echo "Building RGB matrix software..."
cd rpi-rgb-led-matrix cd rpi-rgb-led-matrix
USER_DEFINES="" USER_DEFINES=""
if [ $QUALITY_MOD -eq 1 ]; then #if [ $SLOWDOWN_GPIO -lt 5 ]; then
USER_DEFINES+=" -DDISABLE_HARDWARE_PULSES" # USER_DEFINES+=" -DRGB_SLOWDOWN_GPIO=$SLOWDOWN_GPIO"
fi #fi
#if [ $MATRIX_SIZE --lt 3 ]; then
# USER_DEFINES+=" -DLED_COLS=${MATRIX_WIDTHS[$MATRIX_SIZE]}"
# USER_DEFINES+=" -DLED_ROWS=${MATRIX_HEIGHTS[$MATRIX_SIZE]}"
#fi
if [ $QUALITY_MOD -eq 0 ]; then
# Build and install for Python 2.7...
make clean make clean
make build-python USER_DEFINES="$USER_DEFINES" make install-python HARDWARE_DESC=adafruit-hat-pwm USER_DEFINES="$USER_DEFINES" PYTHON=$(which python2)
# Do over for Python 3...
make clean
make install-python HARDWARE_DESC=adafruit-hat-pwm USER_DEFINES="$USER_DEFINES" PYTHON=$(which python3)
else
# Build then install for Python 2.7...
USER_DEFINES+=" -DDISABLE_HARDWARE_PULSES"
make clean
make install-python HARDWARE_DESC=adafruit-hat USER_DEFINES="$USER_DEFINES" PYTHON=$(which python2)
# Do over for Python 3...
make clean
make install-python HARDWARE_DESC=adafruit-hat USER_DEFINES="$USER_DEFINES" PYTHON=$(which python3)
fi
# Change ownership to user calling sudo # Change ownership to user calling sudo
chown -R $SUDO_USER:$(id -g $SUDO_USER) `pwd` chown -R $SUDO_USER:$(id -g $SUDO_USER) `pwd`
@ -246,18 +249,19 @@ if [ $INSTALL_RTC -ne 0 ]; then
# Enable I2C for RTC # Enable I2C for RTC
raspi-config nonint do_i2c 0 raspi-config nonint do_i2c 0
# Do additional RTC setup for DS1307 # Do additional RTC setup for DS1307
reconfig /boot/firmware/config.txt "^.*dtoverlay=i2c-rtc.*$" "dtoverlay=i2c-rtc,ds1307" reconfig /boot/config.txt "^.*dtoverlay=i2c-rtc.*$" "dtoverlay=i2c-rtc,ds1307"
apt-get -y remove fake-hwclock apt-get -y remove fake-hwclock
update-rc.d -f fake-hwclock remove update-rc.d -f fake-hwclock remove
sed --in-place '/if \[ -e \/run\/systemd\/system \] ; then/,+2 s/^#*/#/' /lib/udev/hwclock-set sudo sed --in-place '/if \[ -e \/run\/systemd\/system \] ; then/,+2 s/^#*/#/' /lib/udev/hwclock-set
fi fi
if [ $QUALITY_MOD -eq 0 ]; then if [ $QUALITY_MOD -eq 0 ]; then
# Disable sound via blacklist # Disable sound ('easy way' -- kernel module not blacklisted)
echo "blacklist snd_bcm2835" > /etc/modprobe.d/blacklist-rgb-matrix.conf reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=off"
else else
# Remove from blacklist # Enable sound (ditto)
rm -f /etc/modprobe.d/blacklist-rgb-matrix.conf reconfig /boot/config.txt "^.*dtparam=audio.*$" "dtparam=audio=on"
fi fi
# PROMPT FOR REBOOT -------------------------------------------------------- # PROMPT FOR REBOOT --------------------------------------------------------
@ -268,15 +272,14 @@ echo "Settings take effect on next boot."
if [ $INSTALL_RTC -ne 0 ]; then if [ $INSTALL_RTC -ne 0 ]; then
echo "RTC will be enabled then but time must be set" echo "RTC will be enabled then but time must be set"
echo "up using the 'date' and 'hwclock' commands." echo "up using the 'date' and 'hwclock' commands."
echo "ref: https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time#sync-time-from-pi-to-rtc"
fi fi
echo echo
echo -n "REBOOT NOW? [y/n] " echo -n "REBOOT NOW? [y/N] "
read read
if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then if [[ ! "$REPLY" =~ ^(yes|y|Y)$ ]]; then
echo "Exiting without reboot." echo "Exiting without reboot."
exit 0 exit 0
fi fi
echo "Reboot process started..." echo "Reboot started..."
reboot reboot
sleep infinity sleep infinity

View file

@ -1,60 +0,0 @@
"""
Adafruit Raspberry Pi Script to Pin a specific version of the rpi kernel and firmware
(C) Adafruit Industries, Creative Commons 3.0 - Attribution Share Alike
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
"""
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
shell.group = 'PINNING'
def main():
shell.clear()
# Check Raspberry Pi and Bail
pi_model = shell.get_board_model()
print("{} detected.\n".format(pi_model))
if not shell.is_raspberry_pi():
shell.bail("Non-Raspberry Pi board detected. This must be run on a Raspberry Pi")
if shell.get_os() != "Raspbian":
print("OS Detected:" + shell.get_os())
shell.bail("Sorry. This script currently only runs on Raspberry Pi OS.")
if len(shell.args) == 1:
print("Usage: sudo python3 {} kernel-version\n".format(shell.script()))
print("e.g., {} 1.20201126-1".format(shell.script()))
shell.exit(1)
version = shell.args[1]
base = "http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/"
packagelist = [
"libraspberrypi0",
"libraspberrypi-bin",
"libraspberrypi-dev",
"libraspberrypi-doc",
"raspberrypi-bootloader",
"raspberrypi-kernel",
"raspberrypi-kernel-headers"
]
new_packages = []
for package in packagelist:
filename = f"{package}_{version}_armhf.deb"
new_packages.append(filename)
shell.run_command("wget --continue -O {} {}".format(filename, base + filename))
shell.run_command("dpkg -i " + " ".join(new_packages))
for package in packagelist:
shell.write_text_file("/etc/apt/preferences.d/99-adafruit-pin-kernel", (
f"Package: {package}\n"
f"Pin: version {version}\n"
f"Pin-Priority:999\n\n"
))
shell.prompt_reboot()
# Main function
if __name__ == "__main__":
shell.require_root()
main()

163
rtc.py
View file

@ -1,163 +0,0 @@
"""
Adafruit Raspberry Pi Real Time Clock Setup Script
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This script is licensed under the terms of the MIT license.
Unless otherwise noted, code reproduced herein
was written for this script.
Originally written by the - The Pimoroni Crew -
Converted to Python by Melissa LeBlanc-Williams for Adafruit Industries
Note: Currently Untested
"""
try:
from adafruit_shell import Shell
except ImportError:
raise RuntimeError("The library 'adafruit_shell' was not found. To install, try typing: sudo pip3 install adafruit-python-shell")
shell = Shell()
productname = "Real Time Clock module" # the name of the product to install
rtcsubtype = "ds1307"
baseurl = "http://www.adafru.it"
scriptname = "rtc.py" # the name of this script
spacereq = 1 # minimum size required on root partition in MB
debugmode = False # whether the script should use debug routines
debuguser = None # optional test git user to use in debug mode
debugpoint = None # optional git repo branch or tag to checkout
forcesudo = True # whether the script requires to be ran with root privileges
promptreboot = False # whether the script should always prompt user to reboot
customcmd = True # whether to execute commands specified before exit
i2creq = True # whether the i2c interface is required
i2sreq = False # whether the i2s interface is required
spireq = False # whether the spi interface is required
uartreq = False # whether uart communication is required
armhfonly = True # whether the script is allowed to run on other arch
armv6 = True # whether armv6 processors are supported
armv7 = True # whether armv7 processors are supported
armv8 = True # whether armv8 processors are supported
raspbianonly = True # whether the script is allowed to run on other OSes
macosxsupport = False # whether Mac OS X is supported by the script
osreleases = ( "Raspbian" ) # list os-releases supported
oswarning = ( "Debian", "Ubuntu", "Mate" ) # list experimental os-releases
squeezesupport = False # whether Squeeze is supported
wheezysupport = False # whether Wheezy is supported
jessiesupport = True # whether Jessie is supported
DEVICE_TREE = True
ASK_TO_REBOOT = False
CURRENT_SETTING = False
UPDATED_DB = False
BOOTCMD = "/boot/cmdline.txt"
CONFIG = shell.get_boot_config()
APTSRC = "/etc/apt/sources.list"
INITABCONF = "/etc/inittab"
BLACKLIST = "/etc/modprobe.d/raspi-blacklist.conf"
LOADMOD = "/etc/modules"
DTBODIR = "/boot/overlays"
def raspbian_old():
return shell.get_raspbian_version() in ("wheezy", "squeeze")
def dt_check():
# Check if /boot/firmware/config.txt exists and de
return shell.exists(CONFIG) and not shell.pattern_search(CONFIG, "^device_tree=$")
#Perform all global variables declarations as well as function definition
#above this section for clarity, thanks!
def main():
os_release = shell.get_raspbian_version()
IS_SUPPORTED = os_release in osreleases
IS_EXPERIMENTAL = os_release in oswarning
if not shell.is_armhf() or shell.is_arm64():
shell.bail("This hardware is not supported, sorry!\n"
"Config files have been left untouched")
if shell.is_raspberry_pi_os():
if not wheezysupport and raspbian_old():
shell.bail(
"\n--- Warning ---\n"
f"The {productname} installer\n"
"does not work on this version of Raspbian.\n"
r"Check https://github.com/{gitusername}/{gitreponame}"
"\nfor additional information and support")
elif raspbianonly:
shell.bail("This script is intended for Raspbian on a Raspberry Pi!")
else:
if not IS_SUPPORTED and not IS_EXPERIMENTAL:
shell.bail(
"Your operating system is not supported, sorry!\n"
"Config files have been left untouched")
if forcesudo:
shell.require_root()
print(f"\nThis script will install everything needed to use {productname}\n")
shell.warn(
"--- Warning ---\n"
"Always be careful when running scripts and commands\n"
"copied from the internet. Ensure they are from a\n"
"trusted source.\n"
"\n"
"If you want to see what this script does before\n"
"running it, you should run:\n"
" \curl -sS $baseurl/$scriptname\n"
"\n"
)
if shell.prompt("Do you wish to continue?", force_arg="y", default="n"):
print("\nChecking hardware requirements...")
if i2creq == "yes":
print()
if shell.prompt("Hardware requires I2C, enable now?", force_arg="y", default="n"):
shell.run_command("sudo raspi-config nonint do_i2c 0")
if not dt_check():
shell.bail(
"Device Tree support required!\n"
"Config files have been left untouched\n"
)
rtc_values = ("ds1307", "ds3231", "pcf8523")
rtcsubtype = rtc_values[shell.select_n("What RTC would you like to install?", rtc_values) - 1]
print("Disabling any current RTC")
shell.run_command(f"sudo sed --in-place '/dtoverlay[[:space:]]*=[[:space:]]*i2c-rtc/d' {CONFIG}")
print(f"Adding DT overlay for {rtcsubtype}")
shell.write_text_file(CONFIG, f"dtoverlay=i2c-rtc,{rtcsubtype}", append=True)
print("Removing fake-hwclock")
shell.run_command("sudo apt-get -y remove fake-hwclock")
shell.run_command("sudo update-rc.d -f fake-hwclock remove")
if not shell.exists("/lib/udev/hwclock-set"):
shell.bail("Couldn't find /lib/udev/hwclock-set")
shell.warn("Configuring HW Clock")
shell.run_command("sudo sed --in-place '/if \[ -e \/run\/systemd\/system \] ; then/,+2 s/^#*/#/' /lib/udev/hwclock-set")
shell.prompt_reboot()
else:
shell.warn("\nAborting...")
# Main function
if __name__ == "__main__":
main()

View file

@ -99,9 +99,9 @@ echo
echo "Faster Pi boards require dialing back GPIO speed" echo "Faster Pi boards require dialing back GPIO speed"
echo "to work with the LED matrix. For Raspberry Pi 4," echo "to work with the LED matrix. For Raspberry Pi 4,"
echo "this usually means the max '4' slowdown setting." echo "this usually means the max '4' slowdown setting."
echo "For Pi 2 or 3, try the '1' or '2' settings. There" echo "For early single-core boards, '0' will often"
echo "is no hard-set rule to this, it can vary with" echo "suffice. Try '1' or '2' for anything else. There's"
echo "matrix and cabling as well. If the Spectro display" echo "no hard-set rule to this. If the Spectro display"
echo "is glitchy, just re-run this installer, selecting" echo "is glitchy, just re-run this installer, selecting"
echo "a higher setting until you find a stable value." echo "a higher setting until you find a stable value."
echo "GPIO slowdown setting:" echo "GPIO slowdown setting:"
@ -204,11 +204,11 @@ echo "Starting installation..."
# Although Spectro is all Python3-ready, user additions might rely on # Although Spectro is all Python3-ready, user additions might rely on
# Python2, so we'll install the prerequisite libraries for both 2 and 3... # Python2, so we'll install the prerequisite libraries for both 2 and 3...
echo "Downloading prerequisites..." echo "Downloading prerequisites..."
pip3 install psutil RPi.GPIO pip3 install psutil
pip install psutil RPi.GPIO pip install psutil
apt-get install -y --allow-unauthenticated python3-dev python3-pillow python2.7-dev python-pillow apt-get install -y --force-yes python3-dev python3-pillow python2.7-dev python-pillow
if [ $ENABLE_MIC -ne 0 ]; then if [ $ENABLE_MIC -ne 0 ]; then
apt-get install -y --allow-unauthenticated python3-pyaudio python3-numpy python-pyaudio python-numpy apt-get install -y --force-yes python3-pyaudio python3-numpy python-pyaudio python-numpy
fi fi
if [ $ENABLE_ACCEL -ne 0 ]; then if [ $ENABLE_ACCEL -ne 0 ]; then
pip3 install adafruit-circuitpython-busdevice adafruit-circuitpython-lis3dh pip3 install adafruit-circuitpython-busdevice adafruit-circuitpython-lis3dh

View file

@ -1,13 +1,15 @@
obj-m += st7789v_ada.o
obj-m += fb_st7789v.o obj-m += fb_st7789v.o
KDIR ?= /lib/modules/`uname -r`/build KDIR ?= /lib/modules/`uname -r`/build
default: default:
$(MAKE) -C $(KDIR) M=$(shell pwd) modules $(MAKE) -C $(KDIR) M=$(pwd) modules
install: install:
$(MAKE) -C $(KDIR) M=$(shell pwd) modules_install $(MAKE) -C $(KDIR) M=$(PWD) modules_install
$(DEPMOD) $(DEPMOD)
clean: clean:
$(MAKE) -C $(KDIR) M=$(shell pwd) clean $(MAKE) -C $(KDIR) M=$(PWD) clean

View file

@ -7,29 +7,40 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/module.h> #include <linux/module.h>
#include <video/mipi_display.h> #include <video/mipi_display.h>
#include "fbtft.h" #include "fbtft.h"
#define DRVNAME "fb_st7789v" #define DRVNAME "fb_st7789v"
static unsigned int width;
module_param(width, uint, 0000);
MODULE_PARM_DESC(width, "Display width");
static unsigned int height;
module_param(height, uint, 0000);
MODULE_PARM_DESC(height, "Display height");
static u32 col_offset = 0;
static u32 row_offset = 0;
static u8 col_hack_fix_offset = 0;
static short x_offset = 0;
static short y_offset = 0;
#define ST77XX_MADCTL_MY 0x80
#define ST77XX_MADCTL_MX 0x40
#define ST77XX_MADCTL_MV 0x20
#define ST77XX_MADCTL_ML 0x10
#define ST77XX_MADCTL_BGR 0x08
#define ST77XX_MADCTL_RGB 0x00
#define DEFAULT_GAMMA \ #define DEFAULT_GAMMA \
"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25\n" \ "70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25\n" \
"70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25" "70 2C 2E 15 10 09 48 33 53 0B 19 18 20 25"
#define HSD20_IPS_GAMMA \
"D0 05 0A 09 08 05 2E 44 45 0F 17 16 2B 33\n" \
"D0 05 0A 09 08 05 2E 43 45 0F 16 16 2B 33"
#define HSD20_IPS 1
/** /**
* enum st7789v_command - ST7789V display controller commands * enum st7789v_command - ST7789V display controller commands
* *
@ -65,73 +76,6 @@ enum st7789v_command {
NVGAMCTRL = 0xE1, NVGAMCTRL = 0xE1,
}; };
#define MADCTL_BGR BIT(3) /* bitmask for RGB/BGR order */
#define MADCTL_MV BIT(5) /* bitmask for page/column order */
#define MADCTL_MX BIT(6) /* bitmask for column address order */
#define MADCTL_MY BIT(7) /* bitmask for page address order */
/* 60Hz for 16.6ms, configured as 2*16.6ms */
#define PANEL_TE_TIMEOUT_MS 33
static struct completion panel_te; /* completion for panel TE line */
static int irq_te; /* Linux IRQ for LCD TE line */
static u32 col_start_offset = 0;
static u32 col_end_offset = 0;
static u32 row_start_offset = 0;
static u32 row_end_offset = 0;
static short x_offset = 0;
static short y_offset = 0;
static irqreturn_t panel_te_handler(int irq, void *data)
{
complete(&panel_te);
return IRQ_HANDLED;
}
/*
* init_tearing_effect_line() - init tearing effect line.
* @par: FBTFT parameter object.
*
* Return: 0 on success, or a negative error code otherwise.
*/
static int init_tearing_effect_line(struct fbtft_par *par)
{
struct device *dev = par->info->device;
struct gpio_desc *te;
int rc, irq;
te = gpiod_get_optional(dev, "te", GPIOD_IN);
if (IS_ERR(te))
return dev_err_probe(dev, PTR_ERR(te), "Failed to request te GPIO\n");
/* if te is NULL, indicating no configuration, directly return success */
if (!te) {
irq_te = 0;
return 0;
}
irq = gpiod_to_irq(te);
/* GPIO is locked as an IRQ, we may drop the reference */
gpiod_put(te);
if (irq < 0)
return irq;
irq_te = irq;
init_completion(&panel_te);
/* The effective state is high and lasts no more than 1000 microseconds */
rc = devm_request_irq(dev, irq_te, panel_te_handler,
IRQF_TRIGGER_RISING, "TE_GPIO", par);
if (rc)
return dev_err_probe(dev, rc, "TE IRQ request failed.\n");
disable_irq_nosync(irq_te);
return 0;
}
/** /**
* init_display() - initialize the display controller * init_display() - initialize the display controller
* *
@ -148,141 +92,44 @@ static int init_tearing_effect_line(struct fbtft_par *par)
*/ */
static int init_display(struct fbtft_par *par) static int init_display(struct fbtft_par *par)
{ {
int rc; printk(KERN_INFO "ST7789 adafruit fbtft driver\n");
par->fbtftops.reset(par); width = par->info->var.xres;
height = par->info->var.yres;
rc = init_tearing_effect_line(par); if ((width == 0) || (width > 240)) {
if (rc) width = 240;
return rc; }
if ((height == 0) || (height > 320)) {
height = 320;
}
printk(KERN_INFO "Size: (%d, %d)\n", width, height);
// Go to sleep
write_reg(par, MIPI_DCS_SET_DISPLAY_OFF);
// Soft reset
write_reg(par, MIPI_DCS_SOFT_RESET);
mdelay(150);
/* turn off sleep mode */ /* turn off sleep mode */
write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE); write_reg(par, MIPI_DCS_EXIT_SLEEP_MODE);
mdelay(120); mdelay(10);
/* set pixel format to RGB-565 */ /* set pixel format to RGB-565 */
write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT); write_reg(par, MIPI_DCS_SET_PIXEL_FORMAT, MIPI_DCS_PIXEL_FMT_16BIT);
if (HSD20_IPS)
write_reg(par, PORCTRL, 0x05, 0x05, 0x00, 0x33, 0x33);
else write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, 0);
write_reg(par, PORCTRL, 0x08, 0x08, 0x00, 0x22, 0x22); write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, 240);
write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 320>>8, 320&0xFF);
write_reg(par, MIPI_DCS_ENTER_INVERT_MODE); // odd hack, displays are inverted
write_reg(par, MIPI_DCS_ENTER_NORMAL_MODE);
mdelay(10);
/*
* VGH = 13.26V
* VGL = -10.43V
*/
if (HSD20_IPS)
write_reg(par, GCTRL, 0x75);
else
write_reg(par, GCTRL, 0x35);
/*
* VDV and VRH register values come from command write
* (instead of NVM)
*/
write_reg(par, VDVVRHEN, 0x01, 0xFF);
/*
* VAP = 4.1V + (VCOM + VCOM offset + 0.5 * VDV)
* VAN = -4.1V + (VCOM + VCOM offset + 0.5 * VDV)
*/
if (HSD20_IPS)
write_reg(par, VRHS, 0x13);
else
write_reg(par, VRHS, 0x0B);
/* VDV = 0V */
write_reg(par, VDVS, 0x20);
/* VCOM = 0.9V */
if (HSD20_IPS)
write_reg(par, VCOMS, 0x22);
else
write_reg(par, VCOMS, 0x20);
/* VCOM offset = 0V */
write_reg(par, VCMOFSET, 0x20);
/*
* AVDD = 6.8V
* AVCL = -4.8V
* VDS = 2.3V
*/
write_reg(par, PWCTRL1, 0xA4, 0xA1);
/* TE line output is off by default when powering on */
if (irq_te)
write_reg(par, MIPI_DCS_SET_TEAR_ON, 0x00);
write_reg(par, MIPI_DCS_SET_DISPLAY_ON); write_reg(par, MIPI_DCS_SET_DISPLAY_ON);
if (HSD20_IPS)
write_reg(par, MIPI_DCS_ENTER_INVERT_MODE);
return 0; return 0;
} }
/*
* write_vmem() - write data to display.
* @par: FBTFT parameter object.
* @offset: offset from screen_buffer.
* @len: the length of data to be writte.
*
* Return: 0 on success, or a negative error code otherwise.
*/
static int write_vmem(struct fbtft_par *par, size_t offset, size_t len)
{
struct device *dev = par->info->device;
int ret;
if (irq_te) {
enable_irq(irq_te);
reinit_completion(&panel_te);
ret = wait_for_completion_timeout(&panel_te,
msecs_to_jiffies(PANEL_TE_TIMEOUT_MS));
if (ret == 0)
dev_err(dev, "wait panel TE timeout\n");
disable_irq(irq_te);
}
switch (par->pdata->display.buswidth) {
case 8:
ret = fbtft_write_vmem16_bus8(par, offset, len);
break;
case 9:
ret = fbtft_write_vmem16_bus9(par, offset, len);
break;
case 16:
ret = fbtft_write_vmem16_bus16(par, offset, len);
break;
default:
dev_err(dev, "Unsupported buswidth %d\n",
par->pdata->display.buswidth);
ret = 0;
break;
}
return ret;
}
static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
int xe, int ye)
{
xs += x_offset;
xe += x_offset;
ys += y_offset;
ye += y_offset;
write_reg(par, MIPI_DCS_SET_COLUMN_ADDRESS,
xs >> 8, xs & 0xFF, xe >> 8, xe & 0xFF);
write_reg(par, MIPI_DCS_SET_PAGE_ADDRESS,
ys >> 8, ys & 0xFF, ye >> 8, ye & 0xFF);
write_reg(par, MIPI_DCS_WRITE_MEMORY_START);
}
/** /**
* set_var() - apply LCD properties like rotation and BGR mode * set_var() - apply LCD properties like rotation and BGR mode
* *
@ -292,105 +139,36 @@ static void minipitft13_set_addr_win(struct fbtft_par *par, int xs, int ys,
*/ */
static int set_var(struct fbtft_par *par) static int set_var(struct fbtft_par *par)
{ {
u8 madctl_par = 0; u8 addr_mode = 0;
struct fbtft_display *display = &par->pdata->display;
u32 width = display->width;
u32 height = display->height;
if (par->bgr)
madctl_par |= MADCTL_BGR;
if (width < 240) {
// Smaller displays are centered
row_start_offset = row_end_offset = (int)((320 - height + 1) / 2);
col_start_offset = (int)((240 - width) / 2);
col_end_offset = (int)((240 - width + 1) / 2); // Account for extra pixel
} else {
// Larger displays are left-aligned
row_start_offset = 0;
row_end_offset = (320 - height);
col_start_offset = col_end_offset = 0;
}
switch (par->info->var.rotate) { switch (par->info->var.rotate) {
case 0: case 0:
x_offset = col_start_offset; addr_mode = 0;
y_offset = row_start_offset; x_offset = col_offset;
y_offset = row_offset;
break; break;
case 90: case 90:
madctl_par |= (MADCTL_MV | MADCTL_MY); addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MX;
x_offset = row_start_offset; x_offset = row_offset;
y_offset = col_start_offset; y_offset = col_offset;
break; break;
case 180: case 180:
madctl_par |= (MADCTL_MX | MADCTL_MY); addr_mode = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY;
x_offset = col_end_offset; x_offset = (240 - width) - col_offset + col_hack_fix_offset;
y_offset = row_end_offset; // hack tweak to account for extra pixel width to make even
y_offset = (320 - height) - row_offset;
break; break;
case 270: case 270:
madctl_par |= (MADCTL_MV | MADCTL_MX); addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY;
x_offset = row_end_offset; x_offset = (320 - height) - row_offset;
y_offset = col_end_offset; y_offset = (240 - width) - col_offset;
break; break;
default: default:
return -EINVAL; return -EINVAL;
} }
write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, madctl_par); printk(KERN_INFO "Rotation %d offsets %d %d\n", par->info->var.rotate, x_offset, y_offset);
return 0;
}
/** write_reg(par, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
* set_gamma() - set gamma curves
*
* @par: FBTFT parameter object
* @curves: gamma curves
*
* Before the gamma curves are applied, they are preprocessed with a bitmask
* to ensure syntactically correct input for the display controller.
* This implies that the curves input parameter might be changed by this
* function and that illegal gamma values are auto-corrected and not
* reported as errors.
*
* Return: 0 on success, < 0 if error occurred.
*/
static int set_gamma(struct fbtft_par *par, u32 *curves)
{
int i;
int j;
int c; /* curve index offset */
/*
* Bitmasks for gamma curve command parameters.
* The masks are the same for both positive and negative voltage
* gamma curves.
*/
static const u8 gamma_par_mask[] = {
0xFF, /* V63[3:0], V0[3:0]*/
0x3F, /* V1[5:0] */
0x3F, /* V2[5:0] */
0x1F, /* V4[4:0] */
0x1F, /* V6[4:0] */
0x3F, /* J0[1:0], V13[3:0] */
0x7F, /* V20[6:0] */
0x77, /* V36[2:0], V27[2:0] */
0x7F, /* V43[6:0] */
0x3F, /* J1[1:0], V50[3:0] */
0x1F, /* V57[4:0] */
0x1F, /* V59[4:0] */
0x3F, /* V61[5:0] */
0x3F, /* V62[5:0] */
};
for (i = 0; i < par->gamma.num_curves; i++) {
c = i * par->gamma.num_values;
for (j = 0; j < par->gamma.num_values; j++)
curves[c + j] &= gamma_par_mask[j];
write_reg(par, PVGAMCTRL + i,
curves[c + 0], curves[c + 1], curves[c + 2],
curves[c + 3], curves[c + 4], curves[c + 5],
curves[c + 6], curves[c + 7], curves[c + 8],
curves[c + 9], curves[c + 10], curves[c + 11],
curves[c + 12], curves[c + 13]);
}
return 0; return 0;
} }
@ -417,26 +195,15 @@ static struct fbtft_display display = {
.height = 320, .height = 320,
.gamma_num = 2, .gamma_num = 2,
.gamma_len = 14, .gamma_len = 14,
.gamma = HSD20_IPS_GAMMA, .gamma = DEFAULT_GAMMA,
.fbtftops = { .fbtftops = {
.init_display = init_display, .init_display = init_display,
.write_vmem = write_vmem,
.set_var = set_var, .set_var = set_var,
.set_gamma = set_gamma,
.blank = blank, .blank = blank,
}, },
}; };
int variant_minipitft13(struct fbtft_display *display) FBTFT_REGISTER_DRIVER(DRVNAME, "sitronix,st7789v", &display);
{
display->fbtftops.set_addr_win = minipitft13_set_addr_win;
return 0;
}
FBTFT_REGISTER_DRIVER_START(&display)
FBTFT_COMPATIBLE("sitronix,st7789v")
FBTFT_VARIANT_COMPATIBLE("fbtft,minipitft13", variant_minipitft13)
FBTFT_REGISTER_DRIVER_END(DRVNAME, &display);
MODULE_ALIAS("spi:" DRVNAME); MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME); MODULE_ALIAS("platform:" DRVNAME);

View file

@ -240,7 +240,7 @@ struct fbtft_par {
int fbtft_write_buf_dc(struct fbtft_par *par, void *buf, size_t len, int dc); int fbtft_write_buf_dc(struct fbtft_par *par, void *buf, size_t len, int dc);
__printf(5, 6) __printf(5, 6)
void fbtft_dbg_hex(const struct device *dev, int groupsize, void fbtft_dbg_hex(const struct device *dev, int groupsize,
const void *buf, size_t len, const char *fmt, ...); void *buf, size_t len, const char *fmt, ...);
struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display, struct fb_info *fbtft_framebuffer_alloc(struct fbtft_display *display,
struct device *dev, struct device *dev,
struct fbtft_platform_data *pdata); struct fbtft_platform_data *pdata);
@ -251,9 +251,8 @@ void fbtft_register_backlight(struct fbtft_par *par);
void fbtft_unregister_backlight(struct fbtft_par *par); void fbtft_unregister_backlight(struct fbtft_par *par);
int fbtft_init_display(struct fbtft_par *par); int fbtft_init_display(struct fbtft_par *par);
int fbtft_probe_common(struct fbtft_display *display, struct spi_device *sdev, int fbtft_probe_common(struct fbtft_display *display, struct spi_device *sdev,
struct platform_device *pdev, struct platform_device *pdev);
const struct of_device_id *dt_ids); int fbtft_remove_common(struct device *dev, struct fb_info *info);
void fbtft_remove_common(struct device *dev, struct fb_info *info);
/* fbtft-io.c */ /* fbtft-io.c */
int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len); int fbtft_write_spi(struct fbtft_par *par, void *buf, size_t len);
@ -273,45 +272,34 @@ void fbtft_write_reg8_bus9(struct fbtft_par *par, int len, ...);
void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...); void fbtft_write_reg16_bus8(struct fbtft_par *par, int len, ...);
void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...); void fbtft_write_reg16_bus16(struct fbtft_par *par, int len, ...);
#define FBTFT_REGISTER_DRIVER_START(_display) \ #define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \
\
static const struct of_device_id dt_ids[]; \
\ \
static int fbtft_driver_probe_spi(struct spi_device *spi) \ static int fbtft_driver_probe_spi(struct spi_device *spi) \
{ \ { \
return fbtft_probe_common(_display, spi, NULL, dt_ids); \ return fbtft_probe_common(_display, spi, NULL); \
} \ } \
\ \
static void fbtft_driver_remove_spi(struct spi_device *spi) \ static int fbtft_driver_remove_spi(struct spi_device *spi) \
{ \ { \
struct fb_info *info = spi_get_drvdata(spi); \ struct fb_info *info = spi_get_drvdata(spi); \
\ \
fbtft_remove_common(&spi->dev, info); \ return fbtft_remove_common(&spi->dev, info); \
} \ } \
\ \
static int fbtft_driver_probe_pdev(struct platform_device *pdev) \ static int fbtft_driver_probe_pdev(struct platform_device *pdev) \
{ \ { \
return fbtft_probe_common(_display, NULL, pdev, dt_ids); \ return fbtft_probe_common(_display, NULL, pdev); \
} \ } \
\ \
static int fbtft_driver_remove_pdev(struct platform_device *pdev) \ static int fbtft_driver_remove_pdev(struct platform_device *pdev) \
{ \ { \
struct fb_info *info = platform_get_drvdata(pdev); \ struct fb_info *info = platform_get_drvdata(pdev); \
\ \
fbtft_remove_common(&pdev->dev, info); \ return fbtft_remove_common(&pdev->dev, info); \
return 0; \
} \ } \
\ \
static const struct of_device_id dt_ids[] = { static const struct of_device_id dt_ids[] = { \
{ .compatible = _compatible }, \
#define FBTFT_COMPATIBLE(_compatible) \
{ .compatible = _compatible },
#define FBTFT_VARIANT_COMPATIBLE(_compatible, _variant) \
{ .compatible = _compatible, .data = _variant },
#define FBTFT_REGISTER_DRIVER_END(_name, _display) \
\
{}, \ {}, \
}; \ }; \
\ \
@ -321,7 +309,7 @@ MODULE_DEVICE_TABLE(of, dt_ids); \
static struct spi_driver fbtft_driver_spi_driver = { \ static struct spi_driver fbtft_driver_spi_driver = { \
.driver = { \ .driver = { \
.name = _name, \ .name = _name, \
.of_match_table = dt_ids, \ .of_match_table = of_match_ptr(dt_ids), \
}, \ }, \
.probe = fbtft_driver_probe_spi, \ .probe = fbtft_driver_probe_spi, \
.remove = fbtft_driver_remove_spi, \ .remove = fbtft_driver_remove_spi, \
@ -331,7 +319,7 @@ static struct platform_driver fbtft_driver_platform_driver = { \
.driver = { \ .driver = { \
.name = _name, \ .name = _name, \
.owner = THIS_MODULE, \ .owner = THIS_MODULE, \
.of_match_table = dt_ids, \ .of_match_table = of_match_ptr(dt_ids), \
}, \ }, \
.probe = fbtft_driver_probe_pdev, \ .probe = fbtft_driver_probe_pdev, \
.remove = fbtft_driver_remove_pdev, \ .remove = fbtft_driver_remove_pdev, \
@ -344,10 +332,7 @@ static int __init fbtft_driver_module_init(void) \
ret = spi_register_driver(&fbtft_driver_spi_driver); \ ret = spi_register_driver(&fbtft_driver_spi_driver); \
if (ret < 0) \ if (ret < 0) \
return ret; \ return ret; \
ret = platform_driver_register(&fbtft_driver_platform_driver); \ return platform_driver_register(&fbtft_driver_platform_driver); \
if (ret < 0) \
spi_unregister_driver(&fbtft_driver_spi_driver); \
return ret; \
} \ } \
\ \
static void __exit fbtft_driver_module_exit(void) \ static void __exit fbtft_driver_module_exit(void) \
@ -359,66 +344,13 @@ static void __exit fbtft_driver_module_exit(void) \
module_init(fbtft_driver_module_init); \ module_init(fbtft_driver_module_init); \
module_exit(fbtft_driver_module_exit); module_exit(fbtft_driver_module_exit);
#define FBTFT_REGISTER_SPI_DRIVER(_name, _comp_vend, _comp_dev, _display) \
\
static const struct of_device_id dt_ids[] = { \
{ .compatible = _comp_vend "," _comp_dev }, \
{}, \
}; \
\
static int fbtft_driver_probe_spi(struct spi_device *spi) \
{ \
return fbtft_probe_common(_display, spi, NULL, dt_ids); \
} \
\
static void fbtft_driver_remove_spi(struct spi_device *spi) \
{ \
struct fb_info *info = spi_get_drvdata(spi); \
\
fbtft_remove_common(&spi->dev, info); \
} \
\
MODULE_DEVICE_TABLE(of, dt_ids); \
\
static const struct spi_device_id spi_ids[] = { \
{ .name = _comp_dev }, \
{}, \
}; \
\
MODULE_DEVICE_TABLE(spi, spi_ids); \
\
static struct spi_driver fbtft_driver_spi_driver = { \
.driver = { \
.name = _name, \
.of_match_table = dt_ids, \
}, \
.id_table = spi_ids, \
.probe = fbtft_driver_probe_spi, \
.remove = fbtft_driver_remove_spi, \
}; \
\
module_spi_driver(fbtft_driver_spi_driver);
#define FBTFT_REGISTER_DRIVER(_name, _compatible, _display) \
FBTFT_REGISTER_DRIVER_START(_display) \
FBTFT_COMPATIBLE(_compatible) \
FBTFT_REGISTER_DRIVER_END(_name, _display)
/* Debug macros */ /* Debug macros */
/* shorthand debug levels */ /* shorthand debug levels */
#define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS #define DEBUG_LEVEL_1 DEBUG_REQUEST_GPIOS
#define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS \ #define DEBUG_LEVEL_2 (DEBUG_LEVEL_1 | DEBUG_DRIVER_INIT_FUNCTIONS | DEBUG_TIME_FIRST_UPDATE)
| DEBUG_TIME_FIRST_UPDATE) #define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY | DEBUG_BLANK | DEBUG_REQUEST_GPIOS | DEBUG_FREE_GPIOS | DEBUG_VERIFY_GPIOS | DEBUG_BACKLIGHT | DEBUG_SYSFS)
#define DEBUG_LEVEL_3 (DEBUG_LEVEL_2 | DEBUG_RESET | DEBUG_INIT_DISPLAY \ #define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE | DEBUG_FB_FILLRECT | DEBUG_FB_COPYAREA | DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
| DEBUG_BLANK | DEBUG_REQUEST_GPIOS \
| DEBUG_FREE_GPIOS \
| DEBUG_VERIFY_GPIOS \
| DEBUG_BACKLIGHT | DEBUG_SYSFS)
#define DEBUG_LEVEL_4 (DEBUG_LEVEL_2 | DEBUG_FB_READ | DEBUG_FB_WRITE \
| DEBUG_FB_FILLRECT \
| DEBUG_FB_COPYAREA \
| DEBUG_FB_IMAGEBLIT | DEBUG_FB_BLANK)
#define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY) #define DEBUG_LEVEL_5 (DEBUG_LEVEL_3 | DEBUG_UPDATE_DISPLAY)
#define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5) #define DEBUG_LEVEL_6 (DEBUG_LEVEL_4 | DEBUG_LEVEL_5)
#define DEBUG_LEVEL_7 0xFFFFFFFF #define DEBUG_LEVEL_7 0xFFFFFFFF
@ -466,8 +398,8 @@ do { \
#define fbtft_par_dbg(level, par, format, arg...) \ #define fbtft_par_dbg(level, par, format, arg...) \
do { \ do { \
if (unlikely((par)->debug & (level))) \ if (unlikely(par->debug & level)) \
dev_info((par)->info->device, format, ##arg); \ dev_info(par->info->device, format, ##arg); \
} while (0) } while (0)
#define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \ #define fbtft_par_dbg_hex(level, par, dev, type, buf, num, format, arg...) \

View file

@ -1,14 +0,0 @@
#!/bin/bash
# Unload
sudo dtoverlay -r drm-minipitft114
sudo modprobe -r fb_st7789v
sudo modprobe -r fbtft
# Compile
sudo make
# Load again
sudo modprobe fbtft
sudo insmod ./fb_st7789v.ko
sudo dtoverlay drm-minipitft114

408
st7789_module/st7789v_ada.c Normal file
View file

@ -0,0 +1,408 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* DRM driver for ST7789V panels with flexible config
*
* Copyright 2019 Limor Fried
* Copyright 2016 Noralf Trønnes
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/backlight.h>
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_damage_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_fb_cma_helper.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_mipi_dbi.h>
#include <drm/drm_rect.h>
#include <drm/drm_vblank.h>
#include <drm/drm_modeset_helper.h>
#include <video/mipi_display.h>
#define ST77XX_MADCTL_MY 0x80
#define ST77XX_MADCTL_MX 0x40
#define ST77XX_MADCTL_MV 0x20
#define ST77XX_MADCTL_ML 0x10
#define ST77XX_MADCTL_BGR 0x08
#define ST77XX_MADCTL_RGB 0x00
static u32 col_offset = 0;
static u32 row_offset = 0;
static u8 col_hack_fix_offset = 0;
static short x_offset = 0;
static short y_offset = 0;
static void st7789vada_fb_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
{
struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
unsigned int height = rect->y2 - rect->y1;
unsigned int width = rect->x2 - rect->x1;
struct mipi_dbi *dbi = &dbidev->dbi;
bool swap = dbi->swap_bytes;
u16 x1, x2, y1, y2;
int idx, ret = 0;
bool full;
void *tr;
if (!dbidev->enabled)
return;
if (!drm_dev_enter(fb->dev, &idx))
return;
full = width == fb->width && height == fb->height;
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
if (!dbi->dc || !full || swap ||
fb->format->format == DRM_FORMAT_XRGB8888) {
tr = dbidev->tx_buf;
ret = mipi_dbi_buf_copy(dbidev->tx_buf, fb, rect, swap);
if (ret)
goto err_msg;
} else {
tr = cma_obj->vaddr;
}
x1 = rect->x1 + x_offset;
x2 = rect->x2 - 1 + x_offset;
y1 = rect->y1 + y_offset;
y2 = rect->y2 - 1 + y_offset;
//printk(KERN_INFO "setaddrwin (%d, %d) -> (%d, %d) offsets: %d & %d \n", x1, y1, x2, y2, x_offset, y_offset);
mipi_dbi_command(dbi, MIPI_DCS_SET_COLUMN_ADDRESS,
(x1 >> 8) & 0xFF, x1 & 0xFF,
(x2 >> 8) & 0xFF, x2 & 0xFF);
mipi_dbi_command(dbi, MIPI_DCS_SET_PAGE_ADDRESS,
(y1 >> 8) & 0xFF, y1 & 0xFF,
(y2 >> 8) & 0xFF, y2 & 0xFF);
ret = mipi_dbi_command_buf(dbi, MIPI_DCS_WRITE_MEMORY_START, tr,
width*height * 2);
err_msg:
if (ret)
dev_err_once(fb->dev->dev, "Failed to update display %d\n", ret);
drm_dev_exit(idx);
}
static void st7789vada_pipe_update(struct drm_simple_display_pipe *pipe,
struct drm_plane_state *old_state)
{
struct drm_plane_state *state = pipe->plane.state;
struct drm_crtc *crtc = &pipe->crtc;
struct drm_rect rect;
if (drm_atomic_helper_damage_merged(old_state, state, &rect))
st7789vada_fb_dirty(state->fb, &rect);
if (crtc->state->event) {
spin_lock_irq(&crtc->dev->event_lock);
drm_crtc_send_vblank_event(crtc, crtc->state->event);
spin_unlock_irq(&crtc->dev->event_lock);
crtc->state->event = NULL;
}
}
static struct drm_display_mode st7789vada_mode = {
DRM_SIMPLE_MODE(240, 320, 58, 43),
};
DEFINE_DRM_GEM_CMA_FOPS(st7789vada_fops);
static struct drm_driver st7789vada_driver = {
.driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
.fops = &st7789vada_fops,
.release = mipi_dbi_release,
DRM_GEM_CMA_VMAP_DRIVER_OPS,
.debugfs_init = mipi_dbi_debugfs_init,
.name = "st7789vada",
.desc = "ST7789V Adafruit",
.date = "20200727",
.major = 1,
.minor = 0,
};
static const struct of_device_id st7789vada_of_match[] = {
{ .compatible = "multi-inno,mi0283qt" },
{},
};
MODULE_DEVICE_TABLE(of, st7789vada_of_match);
static const struct spi_device_id st7789vada_id[] = {
{ "st7789vada", 0 },
{ },
};
MODULE_DEVICE_TABLE(spi, st7789vada_id);
static void st7789vada_enable(struct drm_simple_display_pipe *pipe,
struct drm_crtc_state *crtc_state,
struct drm_plane_state *plane_state)
{
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
struct mipi_dbi *dbi = &dbidev->dbi;
u8 addr_mode;
u16 width = st7789vada_mode.htotal;
u16 height = st7789vada_mode.vtotal;
int ret, idx;
//printk(KERN_INFO "w/h %d %d\n", width, height);
if (!drm_dev_enter(pipe->crtc.dev, &idx))
return;
DRM_DEBUG_KMS("\n");
ret = mipi_dbi_poweron_conditional_reset(dbidev);
if (ret < 0)
goto out_exit;
if (ret == 1)
goto out_enable;
mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF);
mipi_dbi_command(dbi, MIPI_DCS_SOFT_RESET);
msleep(150);
mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE);
msleep(10);
mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, 0x55); // 16 bit color
msleep(10);
mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, 0);
mipi_dbi_command(dbi, MIPI_DCS_SET_COLUMN_ADDRESS, 0, 0, 0, 240);
mipi_dbi_command(dbi, MIPI_DCS_SET_PAGE_ADDRESS, 0, 0, 320>>8, 320&0xFF);
mipi_dbi_command(dbi, MIPI_DCS_ENTER_INVERT_MODE); // odd hack, displays are inverted
mipi_dbi_command(dbi, MIPI_DCS_ENTER_NORMAL_MODE);
msleep(10);
mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
msleep(10);
out_enable:
/* The PiTFT has a hardware reset circuit that
* resets only on power-on and not on each reboot through
* a gpio like the rpi-display does.
* As a result, we need to always apply the rotation value
* regardless of the display "on/off" state.
*/
switch (dbidev->rotation) {
default:
addr_mode = 0;
x_offset = col_offset;
y_offset = row_offset;
break;
case 90:
addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MX;
x_offset = row_offset;
y_offset = col_offset;
break;
case 180:
addr_mode = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY;
x_offset = (240 - width) - col_offset + col_hack_fix_offset;
// hack tweak to account for extra pixel width to make even
y_offset = (320 - height) - row_offset;
break;
case 270:
addr_mode = ST77XX_MADCTL_MV | ST77XX_MADCTL_MY;
x_offset = (320 - height) - row_offset;
y_offset = (240 - width) - col_offset;
break;
}
//printk(KERN_INFO "Rotation offsets %d %d\n", x_offset, y_offset);
mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
mipi_dbi_enable_flush(dbidev, crtc_state, plane_state);
out_exit:
drm_dev_exit(idx);
}
static const struct drm_simple_display_pipe_funcs st7789vada_pipe_funcs = {
.enable = st7789vada_enable,
.disable = mipi_dbi_pipe_disable,
.update = st7789vada_pipe_update,
.prepare_fb = drm_gem_fb_simple_display_pipe_prepare_fb,
};
static int st7789vada_probe(struct spi_device *spi)
{
struct device *dev = &spi->dev;
struct mipi_dbi_dev *dbidev;
struct drm_device *drm;
struct mipi_dbi *dbi;
struct gpio_desc *dc;
u32 rotation = 0;
u32 width = 240;
u32 height = 320;
int ret;
dbidev = kzalloc(sizeof(*dbidev), GFP_KERNEL);
if (!dbidev)
return -ENOMEM;
//printk(KERN_INFO "ST7789 fake driver\n");
dbi = &dbidev->dbi;
drm = &dbidev->drm;
ret = devm_drm_dev_init(dev, drm, &st7789vada_driver);
if (ret) {
kfree(dbidev);
return ret;
}
drm_mode_config_init(drm);
dbi->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(dbi->reset)) {
DRM_DEV_ERROR(dev, "Failed to get gpio 'reset'\n");
return PTR_ERR(dbi->reset);
}
dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
if (IS_ERR(dc)) {
DRM_DEV_ERROR(dev, "Failed to get gpio 'dc'\n");
return PTR_ERR(dc);
}
dbidev->regulator = devm_regulator_get(dev, "power");
if (IS_ERR(dbidev->regulator))
return PTR_ERR(dbidev->regulator);
dbidev->backlight = devm_of_find_backlight(dev);
if (IS_ERR(dbidev->backlight))
return PTR_ERR(dbidev->backlight);
device_property_read_u32(dev, "rotation", &rotation);
//printk(KERN_INFO "Rotation %d\n", rotation);
device_property_read_u32(dev, "width", &width);
if (width % 2) {
width +=1; // odd width will cause a kernel panic
col_hack_fix_offset = 3;
} else {
col_hack_fix_offset = 0;
}
//printk(KERN_INFO "Width %d\n", width);
if ((width == 0) || (width > 240)) {
width = 240; // default to full framebuff;
}
device_property_read_u32(dev, "height", &height);
//printk(KERN_INFO "Height %d\n", height);
if ((height == 0) || (height > 320)) {
height = 320; // default to full framebuff;
}
st7789vada_mode.hdisplay = st7789vada_mode.hsync_start =
st7789vada_mode.hsync_end = st7789vada_mode.htotal = width;
st7789vada_mode.vdisplay = st7789vada_mode.vsync_start =
st7789vada_mode.vsync_end = st7789vada_mode.vtotal = height;
device_property_read_u32(dev, "col_offset", &col_offset);
//printk(KERN_INFO "Column offset %d\n", col_offset);
device_property_read_u32(dev, "row_offset", &row_offset);
//printk(KERN_INFO "Row offset %d\n", row_offset);
ret = mipi_dbi_spi_init(spi, dbi, dc);
if (ret)
return ret;
/* Cannot read from this controller via SPI */
dbi->read_commands = NULL;
ret = mipi_dbi_dev_init(dbidev, &st7789vada_pipe_funcs, &st7789vada_mode, rotation);
if (ret)
return ret;
drm_mode_config_reset(drm);
ret = drm_dev_register(drm, 0);
if (ret)
return ret;
spi_set_drvdata(spi, drm);
drm_fbdev_generic_setup(drm, 0);
return 0;
}
static int st7789vada_remove(struct spi_device *spi)
{
struct drm_device *drm = spi_get_drvdata(spi);
drm_dev_unplug(drm);
drm_atomic_helper_shutdown(drm);
return 0;
}
static void st7789vada_shutdown(struct spi_device *spi)
{
drm_atomic_helper_shutdown(spi_get_drvdata(spi));
}
static int __maybe_unused st7789vada_pm_suspend(struct device *dev)
{
return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
}
static int __maybe_unused st7789vada_pm_resume(struct device *dev)
{
drm_mode_config_helper_resume(dev_get_drvdata(dev));
return 0;
}
static const struct dev_pm_ops st7789vada_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(st7789vada_pm_suspend, st7789vada_pm_resume)
};
static struct spi_driver st7789vada_spi_driver = {
.driver = {
.name = "st7789vada",
.owner = THIS_MODULE,
.of_match_table = st7789vada_of_match,
.pm = &st7789vada_pm_ops,
},
.id_table = st7789vada_id,
.probe = st7789vada_probe,
.remove = st7789vada_remove,
.shutdown = st7789vada_shutdown,
};
module_spi_driver(st7789vada_spi_driver);
MODULE_DESCRIPTION("Sitronix ST7789V Flexible DRM driver");
MODULE_AUTHOR("Noralf Trønnes + Limor Fried");
MODULE_LICENSE("GPL");

View file

@ -1,3 +0,0 @@
# udev rule for Focaltouch Capactive Touchscreen
SUBSYSTEM=="input", ATTRS{name}=="EP0110M09", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"
SUBSYSTEM=="input", ATTRS{name}=="generic ft5x06*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"

View file

@ -1,2 +0,0 @@
udev rule for STMPE Resistive Touchscreen Controller
SUBSYSTEM=="input", ATTRS{name}=="*stmpe*", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"

View file

@ -1 +0,0 @@
SUBSYSTEM=="input", ATTRS{name}=="touchmouse", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"

View file

@ -1,14 +0,0 @@
# udev rules for SPI TFT DRM devices to create reliable symlinks
# Supports ili9341, st7789, and other SPI TFT displays
# Rule for ili9341 DRM device (and other SPI TFT displays)
SUBSYSTEM=="drm", KERNEL=="card*", KERNELS=="spi0.0", DRIVERS=="ili9341", SYMLINK+="dri/spitft"
# Generic rule for any SPI TFT display on spi0.0
SUBSYSTEM=="drm", KERNEL=="card*", KERNELS=="spi0.0", SUBSYSTEMS=="spi", SYMLINK+="dri/spitft"
# Rule for st7789 displays (add when needed)
SUBSYSTEM=="drm", KERNEL=="card*", KERNELS=="spi0.0", DRIVERS=="st7789", SYMLINK+="dri/spitft"
# Alternative rule using device path pattern
SUBSYSTEM=="drm", KERNEL=="card*", DEVPATH=="*/spi0/spi0.0/drm/card*", SYMLINK+="dri/spitft"

View file

@ -1,5 +0,0 @@
# udev rule for TSC2007 touchscreen to create /dev/input/touchscreen symlink and apply transformation
SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="TSC2007 Touchscreen", SYMLINK+="input/touchscreen", ENV{LIBINPUT_CALIBRATION_MATRIX}="{calibration_matrix}"
# Backup rule using touchscreen capability and TSC2007 name pattern
SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_TOUCHSCREEN}=="1", ATTRS{name}=="*TSC2007*", SYMLINK+="input/touchscreen", ENV{LIBINPUT_CALIBRATION_MATRIX}="{calibration_matrix}"

View file

@ -1,25 +0,0 @@
#!/bin/bash
# Wait for TFT framebuffer to be ready
echo "Waiting for SPI TFT framebuffer..."
# Wait up to 30 seconds for /dev/fb0 or /dev/fb1 to appear
for i in {1..300}; do
for fbdev in 0 1; do
if [ -e /dev/fb$fbdev ]; then
echo "Found /dev/fb$fbdev, checking if it's {display_type}..."
# Check if it's actually the ili9341 device
if dmesg | grep -q "{display_type}.*fb$fbdev"; then
echo "{display_type} framebuffer ready, mapping console..."
con2fbmap 1 $fbdev
echo "Console mapped to framebuffer $fbdev"
exit 0
fi
fi
done
sleep 0.1
done
echo "Timeout waiting for SPI TFT framebuffer"
exit 1

View file

@ -1,14 +0,0 @@
[Unit]
Description=Map console to framebuffer for SPI TFT
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/con2fbmap-helper.sh
RemainAfterExit=yes
StandardOutput=journal
StandardError=journal
TimeoutStartSec=60
[Install]
WantedBy=multi-user.target

View file

@ -1,8 +0,0 @@
# --- added by adafruit-pitft-helper {date} ---
[all]
hdmi_force_hotplug=1 # required for cases when HDMI is not plugged in!
dtparam=spi=on
dtparam=i2c1=on
dtparam=i2c_arm=on
{overlay}
# --- end adafruit-pitft-helper {date} ---

View file

@ -1,11 +0,0 @@
[Unit]
Description=Framebuffer copy utility for PiTFT
After=network.target
[Service]
Type=simple
ExecStartPre=/bin/sleep 10
ExecStart=/usr/local/bin/fbcp
[Install]
WantedBy=multi-user.target

View file

@ -1,430 +0,0 @@
#!/bin/bash
: <<'DISCLAIMER'
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
This script is licensed under the terms of the MIT license.
Unless otherwise noted, code reproduced herein
was written for this script.
- The Pimoroni Crew - (modified by Adafruit!)
DISCLAIMER
# script control variables
productname="voice bonnet/BrainCraft HAT" # the name of the product to install
scriptname="voice_bonnet" # the name of this script
spacereq=1 # minimum size required on root partition in MB
debugmode="no" # whether the script should use debug routines
debuguser="none" # optional test git user to use in debug mode
debugpoint="none" # optional git repo branch or tag to checkout
forcesudo="no" # whether the script requires to be ran with root privileges
promptreboot="no" # whether the script should always prompt user to reboot
mininstall="no" # whether the script enforces minimum install routine
customcmd="yes" # whether to execute commands specified before exit
armv6="yes" # whether armv6 processors are supported
armv7="yes" # whether armv7 processors are supported
armv8="yes" # whether armv8 processors are supported
arm64="yes" # whether arm64 processors are supported
raspbianonly="no" # whether the script is allowed to run on other OSes
osreleases=( "Raspbian" ) # list os-releases supported
oswarning=( "Debian" "Kano" "Mate" "PiTop" "Ubuntu" ) # list experimental os-releases
osdeny=( "Darwin" "Kali" ) # list os-releases specifically disallowed
FORCE=$1
DEVICE_TREE=true
ASK_TO_REBOOT=false
CURRENT_SETTING=false
UPDATE_DB=false
BOOTCMD=/boot/firmware/cmdline.txt
CONFIG=/boot/firmware/config.txt
APTSRC=/etc/apt/sources.list
INITABCONF=/etc/inittab
BLACKLIST=/etc/modprobe.d/raspi-blacklist.conf
LOADMOD=/etc/modules
DTBODIR=/boot/overlays
# Fall back to old location
if ! test -f $CONFIG; then
CONFIG=/boot/config.txt
fi
# function define
confirm() {
if [ "$FORCE" == '-y' ]; then
true
else
read -r -p "$1 [y/N] " response < /dev/tty
if [[ $response =~ ^(yes|y|Y)$ ]]; then
true
else
false
fi
fi
}
prompt() {
read -r -p "$1 [y/N] " response < /dev/tty
if [[ $response =~ ^(yes|y|Y)$ ]]; then
true
else
false
fi
}
success() {
echo -e "$(tput setaf 2)$1$(tput sgr0)"
}
inform() {
echo -e "$(tput setaf 6)$1$(tput sgr0)"
}
warning() {
echo -e "$(tput setaf 1)$1$(tput sgr0)"
}
newline() {
echo ""
}
progress() {
count=0
until [ $count -eq $1 ]; do
echo -n "..." && sleep 1
((count++))
done
echo
}
sudocheck() {
if [ $(id -u) -ne 0 ]; then
echo -e "Install must be run as root. Try 'sudo ./$scriptname'\n"
exit 1
fi
}
sysclean() {
sudo apt-get clean && sudo apt-get autoclean
sudo apt-get -y autoremove &> /dev/null
}
sysupdate() {
if ! $UPDATE_DB; then
echo "Updating apt indexes..." && progress 3 &
sudo apt-get update 1> /dev/null || { warning "Apt failed to update indexes!" && exit 1; }
echo "Reading package lists..."
progress 3 && UPDATE_DB=true
fi
}
sysupgrade() {
sudo apt-get upgrade
sudo apt-get clean && sudo apt-get autoclean
sudo apt-get -y autoremove &> /dev/null
}
sysreboot() {
warning "Some changes made to your system require"
warning "your computer to reboot to take effect."
newline
if prompt "Would you like to reboot now?"; then
sync && sudo reboot
fi
}
# Given a filename, a regex pattern to match and a replacement string,
# perform replacement if found, else append replacement to end of file.
# (# $1 = filename, $2 = pattern to match, $3 = replacement)
reconfig() {
grep $2 $1 >/dev/null
if [ $? -eq 0 ]; then
# Pattern found; replace in file
sed -i "s/$2/$3/g" $1 >/dev/null
else
# Not found; append (silently)
echo $3 | sudo tee -a $1 >/dev/null
fi
}
# If /boot/firmware/config.txt exists, make sure /boot/config.txt is a symlink to it
fix_config_symlink() {
if [ -f /boot/firmware/config.txt ]; then
if [ ! -L /boot/config.txt ]; then
warning "/boot/config.txt was overwritten as a file by another script."
if confirm "/boot/config.txt will be moved to /boot/firmware/config.txt and the symlink restored. Do you wish to continue?"; then
sudo mv /boot/config.txt /boot/firmware/config.txt
sudo ln -s /boot/firmware/config.txt /boot/config.txt
fi
fi
fi
}
arch_check() {
IS_ARM64=false
IS_ARMHF=false
IS_ARMv6=false
if uname -m | grep "aarch64" > /dev/null; then
IS_ARM64=true
fi
if uname -m | grep "armv.l" > /dev/null; then
IS_ARMHF=true
if uname -m | grep "armv6l" > /dev/null; then
IS_ARMv6=true
fi
fi
}
os_check() {
IS_RASPBIAN=false
IS_MACOSX=false
IS_SUPPORTED=false
IS_EXPERIMENTAL=false
if [ -f /etc/os-release ]; then
if cat /etc/os-release | grep "Raspbian" > /dev/null; then
IS_RASPBIAN=true && IS_SUPPORTED=true
fi
if command -v apt-get > /dev/null; then
for os in ${osreleases[@]}; do
if cat /etc/os-release | grep $os > /dev/null; then
IS_SUPPORTED=true && IS_EXPERIMENTAL=false
fi
done
for os in ${oswarning[@]}; do
if cat /etc/os-release | grep $os > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
fi
done
for os in ${osdeny[@]}; do
if cat /etc/os-release | grep $os > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
done
fi
fi
if [ -d ~/.kano-settings ] || [ -d ~/.kanoprofile ]; then
IS_RASPBIAN=false
for os in ${oswarning[@]}; do
if [ $os == "Kano" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
fi
done
for os in ${osdeny[@]}; do
if [ $os == "Kano" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
done
fi
if [ -f ~/.pt-dashboard-config ] || [ -d ~/.pt-dashboard ] || [ -d ~/.pt-os-dashboard ]; then
IS_RASPBIAN=false
for os in ${oswarning[@]}; do
if [ $os == "PiTop" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
fi
done
for os in ${osdeny[@]}; do
if [ $os == "PiTop" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
done
fi
if [ -d ~/.config/ubuntu-mate ]; then
for os in ${osdeny[@]}; do
if [ $os == "Mate" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
done
fi
if uname -s | grep "Darwin" > /dev/null; then
IS_MACOSX=true
for os in ${osdeny[@]}; do
if [ $os == "Darwin" ]; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
done
fi
}
raspbian_check() {
IS_SUPPORTED=false
IS_EXPERIMENTAL=false
if [ -f /etc/os-release ]; then
if cat /etc/os-release | grep "/sid" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "bullseye" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "buster" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=true
elif cat /etc/os-release | grep "stretch" > /dev/null; then
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
elif cat /etc/os-release | grep "jessie" > /dev/null; then
IS_SUPPORTED=true && IS_EXPERIMENTAL=false
elif cat /etc/os-release | grep "wheezy" > /dev/null; then
IS_SUPPORTED=true && IS_EXPERIMENTAL=false
else
IS_SUPPORTED=false && IS_EXPERIMENTAL=false
fi
fi
}
: <<'MAINSTART'
Perform all global variables declarations as well as function definition
above this section for clarity, thanks!
MAINSTART
# checks and init
arch_check
os_check
if [ $debugmode != "no" ]; then
echo "USER_HOME is $USER_HOME" && newline
echo "IS_RASPBIAN is $IS_RASPBIAN"
echo "IS_MACOSX is $IS_MACOSX"
echo "IS_SUPPORTED is $IS_SUPPORTED"
echo "IS_EXPERIMENTAL is $IS_EXPERIMENTAL"
newline
fi
if ! $IS_ARMHF && ! $IS_ARM64; then
warning "This hardware is not supported, sorry!"
warning "Config files have been left untouched"
newline && exit 1
fi
if $IS_ARM64 && [ $arm64 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer"
newline && exit 1
elif $IS_ARMv8 && [ $armv8 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer"
newline && exit 1
elif $IS_ARMv7 && [ $armv7 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer"
newline && exit 1
elif $IS_ARMv6 && [ $armv6 == "no" ]; then
warning "Sorry, your CPU is not supported by this installer"
newline && exit 1
fi
if [ $raspbianonly == "yes" ] && ! $IS_RASPBIAN;then
warning "This script is intended for Raspbian on a Raspberry Pi!"
newline && exit 1
fi
if $IS_RASPBIAN; then
raspbian_check
if ! $IS_SUPPORTED && ! $IS_EXPERIMENTAL; then
newline && warning "--- Warning ---" && newline
echo "The $productname installer"
echo "does not work on this version of Raspbian."
echo "Check https://github.com/$gitusername/$gitreponame"
echo "for additional information and support"
newline && exit 1
fi
fi
if ! $IS_SUPPORTED && ! $IS_EXPERIMENTAL; then
warning "Your operating system is not supported, sorry!"
newline && exit 1
fi
if $IS_EXPERIMENTAL; then
warning "Support for your operating system is experimental. Please visit"
warning "forums.adafruit.com if you experience issues with this product."
newline
fi
if [ $forcesudo == "yes" ]; then
sudocheck
fi
newline
echo "This script will install everything needed to use"
echo "$productname"
newline
warning "--- Warning ---"
newline
echo "Always be careful when running scripts and commands"
echo "copied from the internet. Ensure they are from a"
echo "trusted source."
newline
echo "If you want to see what this script does before"
echo "running it, you should run:"
echo " \curl -sS github.com/adafruit/Raspberry-Pi-Installer-Scripts/$scriptname"
newline
if confirm "Do you wish to continue?"; then
newline
echo "Checking hardware requirements..."
fix_config_symlink
if [ -e $CONFIG ] && grep -q "^device_tree=$" $CONFIG; then
DEVICE_TREE=false
fi
if $DEVICE_TREE; then
newline
echo "Adding Device Tree Entry to $CONFIG"
if [ -e $CONFIG ] && grep -q "^dtoverlay=seeed-2mic-voicecard$" $CONFIG; then
echo "dtoverlay already active"
else
echo "dtoverlay=seeed-2mic-voicecard" | sudo tee -a $CONFIG
ASK_TO_REBOOT=true
fi
if [ -e $CONFIG ] && grep -q "^dtoverlay=i2s-mmap$" $CONFIG; then
echo "i2s mmap dtoverlay already active"
else
echo "dtoverlay=i2s-mmap" | sudo tee -a $CONFIG
ASK_TO_REBOOT=true
fi
if [ -e $CONFIG ] && grep -q "^dtparam=i2s=on$" $CONFIG; then
echo "i2s interface already enabled"
else
reconfig $CONFIG "^#dtparam=i2s=on$" "dtparam=i2s=on"
ASK_TO_REBOOT=true
fi
else
newline
echo "No Device Tree Detected, not supported"
newline
exit 1
fi
newline
success "All done!"
newline
echo "Enjoy your new $productname!"
newline
if [ $promptreboot == "yes" ] || $ASK_TO_REBOOT; then
sysreboot
fi
else
newline
echo "Aborting..."
newline
fi
exit 0

View file

@ -1,12 +0,0 @@
[Unit]
Description=WM8960 Soundcard service
After=alsa-restore.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wm8960-soundcard
User=root
[Install]
WantedBy=sysinit.target