Skip to content

Commit

Permalink
configurable pwmchip for hw clock on pi5
Browse files Browse the repository at this point in the history
  • Loading branch information
mgineer85 committed Oct 23, 2024
1 parent b5cb8e2 commit 5da204b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions node/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions node/services/gpio_primary_clockwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 5da204b

Please sign in to comment.