Skip to content

Commit

Permalink
Add DeviceInfo::pwm_channels()
Browse files Browse the repository at this point in the history
  • Loading branch information
golemparts committed Dec 11, 2024
1 parent fd86b9b commit ce452c2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ pub struct DeviceInfo {
gpio_interface: GpioInterface,
// PWM chip # used for hardware PWM on selected GPIO pins
pwm_chip: u8,
// Total number of supported hardware PWM channels
pwm_channels: u8,
}

impl DeviceInfo {
Expand Down Expand Up @@ -377,6 +379,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_BCM283X,
gpio_interface: GpioInterface::Bcm,
pwm_chip: 0,
pwm_channels: 2,
}),
Model::RaspberryPi2B => Ok(DeviceInfo {
model,
Expand All @@ -386,6 +389,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_BCM283X,
gpio_interface: GpioInterface::Bcm,
pwm_chip: 0,
pwm_channels: 2,
}),
Model::RaspberryPi3B | Model::RaspberryPiComputeModule3 | Model::RaspberryPiZero2W => {
Ok(DeviceInfo {
Expand All @@ -396,6 +400,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_BCM283X,
gpio_interface: GpioInterface::Bcm,
pwm_chip: 0,
pwm_channels: 2,
})
}
Model::RaspberryPi3BPlus
Expand All @@ -408,6 +413,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_BCM283X,
gpio_interface: GpioInterface::Bcm,
pwm_chip: 0,
pwm_channels: 2,
}),
Model::RaspberryPi4B
| Model::RaspberryPi400
Expand All @@ -420,6 +426,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_BCM2711,
gpio_interface: GpioInterface::Bcm,
pwm_chip: 0,
pwm_channels: 2,
}),
Model::RaspberryPi5
| Model::RaspberryPi500
Expand All @@ -432,6 +439,7 @@ impl DeviceInfo {
gpio_lines: GPIO_LINES_RP1,
gpio_interface: GpioInterface::Rp1,
pwm_chip: 2,
pwm_channels: 4,
}),
}
}
Expand All @@ -446,6 +454,11 @@ impl DeviceInfo {
self.soc
}

/// Returns the number of hardware PWM channels supported by this Raspberry Pi model.
pub fn pwm_channels(&self) -> u8 {
self.pwm_channels
}

/// Returns the peripheral base memory address.
pub(crate) fn peripheral_base(&self) -> u32 {
self.peripheral_base
Expand Down

0 comments on commit ce452c2

Please sign in to comment.