From 22e0a2474a4be7288980615bf65f659c1a0849a5 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 24 Aug 2020 16:56:29 +0200 Subject: [PATCH] Pandad: turn on panda power (#2073) * pandad turn on panda power * Add gpio.py * needs bytes Co-authored-by: Comma Device old-commit-hash: 6bb2630eba1bff2db745e56d639fce8b85ec6d0d --- common/gpio.py | 22 ++++++++++++++++++++++ common/hardware.py | 4 ++++ release/files_common | 2 ++ selfdrive/pandad.py | 23 ++++++++++++++++++++++- selfdrive/thermald/thermald.py | 4 +--- 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 common/gpio.py create mode 100644 common/hardware.py diff --git a/common/gpio.py b/common/gpio.py new file mode 100644 index 0000000000..73603f262d --- /dev/null +++ b/common/gpio.py @@ -0,0 +1,22 @@ +GPIO_HUB_RST_N = 30 +GPIO_UBLOX_RST_N = 32 +GPIO_UBLOX_SAFEBOOT_N = 33 +GPIO_UBLOX_PWR_EN = 34 +GPIO_STM_RST_N = 124 +GPIO_STM_BOOT0 = 134 + + +def gpio_init(pin, output): + try: + with open(f"/sys/class/gpio/gpio{pin}/direction", 'wb') as f: + f.write(b"out" if output else b"in") + except Exception as e: + print(f"Failed to set gpio {pin} direction: {e}") + + +def gpio_set(pin, high): + try: + with open(f"/sys/class/gpio/gpio{pin}/value", 'wb') as f: + f.write(b"1" if high else b"0") + except Exception as e: + print(f"Failed to set gpio {pin} value: {e}") diff --git a/common/hardware.py b/common/hardware.py new file mode 100644 index 0000000000..a1bab3c313 --- /dev/null +++ b/common/hardware.py @@ -0,0 +1,4 @@ +import os + +EON = os.path.isfile('/EON') +TICI = os.path.isfile('/TICI') diff --git a/release/files_common b/release/files_common index 3bff234eab..2df9430159 100644 --- a/release/files_common +++ b/release/files_common @@ -18,6 +18,8 @@ apk/ai.comma*.apk common/.gitignore common/__init__.py common/android.py +common/hardware.py +common/gpio.py common/realtime.py common/clock.pyx common/timeout.py diff --git a/selfdrive/pandad.py b/selfdrive/pandad.py index 64fde86686..36ccad3796 100755 --- a/selfdrive/pandad.py +++ b/selfdrive/pandad.py @@ -3,8 +3,27 @@ import os import time +from common.hardware import TICI +from common.gpio import GPIO_HUB_RST_N, GPIO_STM_BOOT0, GPIO_STM_RST_N, gpio_init, gpio_set +from panda import BASEDIR, Panda, PandaDFU, build_st from selfdrive.swaglog import cloudlog -from panda import Panda, PandaDFU, BASEDIR, build_st + + +def set_panda_power(power=True): + if not TICI: + return + + gpio_init(GPIO_STM_RST_N, True) + gpio_init(GPIO_STM_BOOT0, True) + gpio_init(GPIO_HUB_RST_N, True) + + gpio_set(GPIO_STM_RST_N, False) + gpio_set(GPIO_HUB_RST_N, True) + gpio_set(GPIO_STM_BOOT0, False) + + time.sleep(0.1) + + gpio_set(GPIO_STM_RST_N, power) def get_firmware_fn(): @@ -88,10 +107,12 @@ def update_panda(): def main(): + set_panda_power() update_panda() os.chdir("boardd") os.execvp("./boardd", ["./boardd"]) + if __name__ == "__main__": main() diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index cddcb562fc..63f1a7e9b6 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -11,6 +11,7 @@ import cereal.messaging as messaging from cereal import log from common.android import get_network_strength, get_network_type from common.filter_simple import FirstOrderFilter +from common.hardware import EON, TICI from common.numpy_fast import clip, interp from common.params import Params, put_nonblocking from common.realtime import DT_TRML, sec_since_boot @@ -39,9 +40,6 @@ DAYS_NO_CONNECTIVITY_MAX = 7 # do not allow to engage after a week without inte DAYS_NO_CONNECTIVITY_PROMPT = 4 # send an offroad prompt after 4 days with no internet DISCONNECT_TIMEOUT = 5. # wait 5 seconds before going offroad after disconnect so you get an alert -EON = os.path.isfile('/EON') -TICI = os.path.isfile('/TICI') - LEON = False last_eon_fan_val = None