forked from thomoray/rockpi-penta
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from radxa/dev
Dev
- Loading branch information
Showing
28 changed files
with
393 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Build DEB Package | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build DEB package | ||
run: | | ||
chmod -R 775 rockpi-penta/DEBIAN/ | ||
dpkg-deb --build -Z gzip rockpi-penta | ||
- name: Upload DEB package | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: rockpi-penta.deb | ||
path: rockpi-penta.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
Package: rockpi-penta | ||
Version: 0.10 | ||
Version: 0.2 | ||
Architecture: all | ||
Maintainer: Radxa <[email protected]> | ||
Depends: python3 | ||
Depends: python3, python3-libgpiod, python3-pillow, python3-pip | ||
Section: utils | ||
Priority: optional | ||
Homepage: https://github.com/akgnah/rockpi-penta | ||
Homepage: https://github.com/radxa/rockpi-penta | ||
Description: Rockpi Penta Hat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/bin/bash -e | ||
|
||
checkReboot() { | ||
echo Installation will take effect after reboot!!! | ||
} | ||
|
||
is_armbian() { | ||
if [ -f /boot/armbianEnv.txt ] || [ -f /boot/dietpiEnv.txt ]; then | ||
echo true | ||
else | ||
echo false | ||
fi | ||
} | ||
|
||
armbian_require_overlay() { | ||
envFile='/boot/armbianEnv.txt' | ||
[ -f /boot/dietpiEnv.txt ] && envFile='/boot/dietpiEnv.txt' | ||
overlays=$(grep '^overlays=' "$envFile" | cut -d'=' -f2) | ||
for arg in "$@"; do | ||
if grep -qE "(^|[[:space:]])$arg([[:space:]]|$)" <<< $overlays; then | ||
echo "Overlay ${arg} was already added to $envFile, skip..." | ||
else | ||
overlays="${overlays} ${arg}" | ||
echo "Added overlay: $arg" | ||
fi | ||
done | ||
if grep -q "^overlays=" $envFile; then | ||
sed -i '/^overlays=/c\'"overlays=$overlays" $envFile | ||
else | ||
echo "overlays=$overlays" >> $envFile | ||
fi | ||
} | ||
|
||
if [ "$(python3 -c 'import sys; print(f"{sys.version_info.minor >= 11}")')" = "True" ]; then | ||
pip3 install adafruit-circuitpython-ssd1306 --break-system-packages | ||
else | ||
pip3 install adafruit-circuitpython-ssd1306 | ||
fi | ||
|
||
systemctl enable rockpi-penta.service | ||
|
||
model=$(tr -d '\0' </proc/device-tree/model) | ||
|
||
case "$model" in | ||
*"Raspberry Pi 5"*) | ||
raspi-config nonint do_i2c 0 >/dev/null || true | ||
cp /usr/bin/rockpi-penta/env/rpi5.env /etc/rockpi-penta.env | ||
systemctl start rockpi-penta.service | ||
;; | ||
*"Raspberry Pi 4"*) | ||
raspi-config nonint do_i2c 0 >/dev/null || true | ||
mv /usr/bin/rockpi-penta/env/rpi4.env /etc/rockpi-penta.env | ||
systemctl start rockpi-penta.service | ||
;; | ||
*"ROCK 5"*) | ||
if [ "$(is_armbian)" = "true" ]; then | ||
armbian_require_overlay rk3588-i2c8-m2 rk3588-pwm14-m1 | ||
cp /usr/bin/rockpi-penta/env/rock_5a_armbian.env /etc/rockpi-penta.env | ||
else | ||
mv /boot/dtbo/rk3588-i2c8-m2.dtbo.disabled /boot/dtbo/rk3588-i2c8-m2.dtbo || true | ||
mv /boot/dtbo/rk3588-pwm14-m1.dtbo.disabled /boot/dtbo/rk3588-pwm14-m1.dtbo || true | ||
cp /usr/bin/rockpi-penta/env/rock_5a.env /etc/rockpi-penta.env | ||
u-boot-update || true | ||
fi | ||
checkReboot | ||
;; | ||
*"ROCK3 Model C"*) | ||
mv /boot/dtbo/rk3568-i2c3-m0.dtbo.disabled /boot/dtbo/rk3568-i2c3-m0.dtbo || true | ||
cp /usr/bin/rockpi-penta/env/rock_3c.env /etc/rockpi-penta.env | ||
u-boot-update || true | ||
checkReboot | ||
;; | ||
*"ROCK3 Model A"*) | ||
mv /boot/dtbo/rk3568-i2c3-m0.dtbo.disabled /boot/dtbo/rk3568-i2c3-m0.dtbo || true | ||
mv /boot/dtbo/rk3568-pwm15-m0.dtbo.disabled /boot/dtbo/rk3568-pwm15-m0.dtbo || true | ||
cp /usr/bin/rockpi-penta/env/rock_pi_3.env /etc/rockpi-penta.env | ||
u-boot-update || true | ||
checkReboot | ||
;; | ||
*"Radxa ROCK 4SE"* | *"ROCK Pi 4"*) | ||
if [ "$(is_armbian)" = "true" ]; then | ||
cp /usr/bin/rockpi-penta/overlays/rk3399-pwm1.dtbo /boot/dtb/rockchip/overlay/rockchip-rk3399-pwm1-by-rockpi-penta.dtbo | ||
chmod +x /boot/dtb/rockchip/overlay/rockchip-rk3399-pwm1-by-rockpi-penta.dtbo | ||
armbian_require_overlay rk3399-i2c7 rk3399-pwm1-by-rockpi-penta | ||
cp /usr/bin/rockpi-penta/env/rock_pi_4_armbian.env /etc/rockpi-penta.env | ||
else | ||
mv /boot/dtbo/rk3399-i2c7.dtbo.disabled /boot/dtbo/rk3399-i2c7.dtbo || true | ||
mv /boot/dtbo/rk3399-pwm1.dtbo.disabled /boot/dtbo/rk3399-pwm1.dtbo || true | ||
cp /usr/bin/rockpi-penta/env/rock_pi_4.env /etc/rockpi-penta.env | ||
u-boot-update || true | ||
fi | ||
checkReboot | ||
;; | ||
*) | ||
echo Not support in your board. | ||
exit 2 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Template: rockpi-penta/reboot-system | ||
Type: boolean | ||
Default: false | ||
Description: Do you want to reboot the system now? | ||
Installation will take effect after reboot. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SDA=GPIO1_A0 | ||
SCL=GPIO1_A1 | ||
OLED_RESET=GPIO3_B1 | ||
BUTTON_CHIP=3 | ||
BUTTON_LINE=1 | ||
FAN_CHIP=3 | ||
FAN_LINE=2 | ||
HARDWARE_PWM=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SDA=I2C8_SDA_M4 | ||
SCL=I2C8_SCL_M4 | ||
OLED_RESET=GPIO1_A5 | ||
PWMCHIP=14 | ||
BUTTON_CHIP=4 | ||
BUTTON_LINE=11 | ||
HARDWARE_PWM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SDA=I2C8_SDA_M4 | ||
SCL=I2C8_SCL_M4 | ||
OLED_RESET=GPIO1_A5 | ||
PWMCHIP=1 | ||
BUTTON_CHIP=4 | ||
BUTTON_LINE=11 | ||
HARDWARE_PWM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SDA=I2C3_SDA_M0 | ||
SCL=I2C3_SCL_M0 | ||
OLED_RESET=GPIO0_B6 | ||
PWMCHIP=15 | ||
BUTTON_CHIP=3 | ||
BUTTON_LINE=20 | ||
HARDWARE_PWM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SDA=I2C7_SDA | ||
SCL=I2C7_SCL | ||
OLED_RESET=GPIO4_D2 | ||
PWMCHIP=1 | ||
BUTTON_CHIP=4 | ||
BUTTON_LINE=18 | ||
HARDWARE_PWM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SDA=I2C7_SDA | ||
SCL=I2C7_SCL | ||
OLED_RESET=GPIO4_D2 | ||
PWMCHIP=0 | ||
BUTTON_CHIP=4 | ||
BUTTON_LINE=18 | ||
HARDWARE_PWM=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SDA=SDA | ||
SCL=SCL | ||
OLED_RESET=D23 | ||
BUTTON_CHIP=0 | ||
BUTTON_LINE=17 | ||
FAN_CHIP=0 | ||
FAN_LINE=27 | ||
HARDWARE_PWM=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SDA=SDA | ||
SCL=SCL | ||
OLED_RESET=D23 | ||
BUTTON_CHIP=4 | ||
BUTTON_LINE=17 | ||
FAN_CHIP=4 | ||
FAN_LINE=27 | ||
HARDWARE_PWM=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env python3 | ||
import os.path | ||
import time | ||
import traceback | ||
import threading | ||
|
||
import gpiod | ||
|
||
import misc | ||
|
||
pin = None | ||
|
||
|
||
class Pwm: | ||
def __init__(self, chip): | ||
self.period_value = None | ||
try: | ||
int(chip) | ||
chip = f'pwmchip{chip}' | ||
except ValueError: | ||
pass | ||
self.filepath = f"/sys/class/pwm/{chip}/pwm0/" | ||
try: | ||
with open(f"/sys/class/pwm/{chip}/export", 'w') as f: | ||
f.write('0') | ||
except OSError: | ||
print("Waring: init pwm error") | ||
traceback.print_exc() | ||
|
||
def period(self, ns: int): | ||
self.period_value = ns | ||
with open(os.path.join(self.filepath, 'period'), 'w') as f: | ||
f.write(str(ns)) | ||
|
||
def period_us(self, us: int): | ||
self.period(us * 1000) | ||
|
||
def enable(self, t: bool): | ||
with open(os.path.join(self.filepath, 'enable'), 'w') as f: | ||
f.write(f"{int(t)}") | ||
|
||
def write(self, duty: float): | ||
assert self.period_value, "The Period is not set." | ||
with open(os.path.join(self.filepath, 'duty_cycle'), 'w') as f: | ||
f.write(f"{int(self.period_value * duty)}") | ||
|
||
|
||
class Gpio: | ||
|
||
def tr(self): | ||
while True: | ||
self.line.set_value(1) | ||
time.sleep(self.value[0]) | ||
self.line.set_value(0) | ||
time.sleep(self.value[1]) | ||
|
||
def __init__(self, period_s): | ||
self.line = gpiod.Chip(os.environ['FAN_CHIP']).get_line(int(os.environ['FAN_LINE'])) | ||
self.line.request(consumer='fan', type=gpiod.LINE_REQ_DIR_OUT) | ||
self.value = [period_s / 2, period_s / 2] | ||
self.period_s = period_s | ||
self.thread = threading.Thread(target=self.tr, daemon=True) | ||
self.thread.start() | ||
|
||
def write(self, duty): | ||
self.value[1] = duty * self.period_s | ||
self.value[0] = self.period_s - self.value[1] | ||
|
||
|
||
def read_temp(): | ||
with open('/sys/class/thermal/thermal_zone0/temp') as f: | ||
t = int(f.read().strip()) / 1000.0 | ||
return t | ||
|
||
|
||
def get_dc(cache={}): | ||
if misc.conf['run'].value == 0: | ||
return 0.999 | ||
|
||
if time.time() - cache.get('time', 0) > 60: | ||
cache['time'] = time.time() | ||
cache['dc'] = misc.fan_temp2dc(read_temp()) | ||
|
||
return cache['dc'] | ||
|
||
|
||
def change_dc(dc, cache={}): | ||
if dc != cache.get('dc'): | ||
cache['dc'] = dc | ||
pin.write(dc) | ||
|
||
|
||
def running(): | ||
global pin | ||
if os.environ['HARDWARE_PWM'] == '1': | ||
chip = os.environ['PWMCHIP'] | ||
pin = Pwm(chip) | ||
pin.period_us(40) | ||
pin.enable(True) | ||
else: | ||
pin = Gpio(0.025) | ||
while True: | ||
change_dc(get_dc()) | ||
time.sleep(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
running() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.