From ce452c23db1a8bceace53a86d3a39ed4aae659b9 Mon Sep 17 00:00:00 2001 From: Rene van der Meer <9930578+golemparts@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:36:42 +0100 Subject: [PATCH] Add DeviceInfo::pwm_channels() --- src/system.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/system.rs b/src/system.rs index bcc1cd5..c10a69e 100644 --- a/src/system.rs +++ b/src/system.rs @@ -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 { @@ -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, @@ -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 { @@ -396,6 +400,7 @@ impl DeviceInfo { gpio_lines: GPIO_LINES_BCM283X, gpio_interface: GpioInterface::Bcm, pwm_chip: 0, + pwm_channels: 2, }) } Model::RaspberryPi3BPlus @@ -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 @@ -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 @@ -432,6 +439,7 @@ impl DeviceInfo { gpio_lines: GPIO_LINES_RP1, gpio_interface: GpioInterface::Rp1, pwm_chip: 2, + pwm_channels: 4, }), } } @@ -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