From 5da204be368d74b9791bcd582e7657f3966c41c3 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 23 Oct 2024 12:28:34 +0200 Subject: [PATCH] configurable pwmchip for hw clock on pi5 --- node/config/models.py | 2 ++ node/services/gpio_primary_clockwork.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/node/config/models.py b/node/config/models.py index 7d3e52f..e1dea28 100644 --- a/node/config/models.py +++ b/node/config/models.py @@ -7,6 +7,8 @@ class ConfigGpioPrimaryClockwork(BaseModel): trigger_out_pin_name: str = Field(default="GPIO17") ext_trigger_in_pin_name: str = Field(default="GPIO4") FPS_NOMINAL: int = Field(default=10) + pwmchip: str = Field(default="pwmchip2") # pi5: 2, other 0 + pwm_channel: int = Field(default=2) # pi5: 2, other 0 class ConfigGpioSecondaryNode(BaseModel): diff --git a/node/services/gpio_primary_clockwork.py b/node/services/gpio_primary_clockwork.py index bb01835..5ddedc2 100644 --- a/node/services/gpio_primary_clockwork.py +++ b/node/services/gpio_primary_clockwork.py @@ -85,10 +85,10 @@ def set_hardware_clock(self, enable: bool = True): # 1/10FPS = 0.1 * 1e6 = 100.000.000ns period # duty cycle = period / 2 """ - PWM_CHANNEL = "0" + PWM_CHANNEL = self._config.pwm_channel PERIOD = int(1 / self._config.FPS_NOMINAL * 1e9) # 1e9=ns DUTY_CYCLE = PERIOD // 2 - PWM_SYSFS = Path("/sys/class/pwm/pwmchip0") + PWM_SYSFS = Path(f"/sys/class/pwm/{self._config.pwmchip}") if not PWM_SYSFS.is_dir(): raise RuntimeError("pwm overlay not enabled in config.txt")