#180 ledcdriver redundand timer config (#188)

* fix: #180 Remove redundant info in LedcDriver::new

This is an implementation of one of the possible solutions to the issue.

Signed-off-by: Raphael Höser <raphael@hoeser.info>

* Remove speed_mode method from LedcTimerDriver as it's not needed.

* Fix rustfmt issues

Signed-off-by: Raphael Höser <raphael@hoeser.info>
This commit is contained in:
Raphael Höser 2022-12-12 10:35:36 +01:00 committed by GitHub
parent 2270ebed79
commit bf13eee9a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 14 deletions

View File

@ -9,12 +9,13 @@ fn main() -> anyhow::Result<()> {
println!("Configuring output channel"); println!("Configuring output channel");
let peripherals = Peripherals::take().unwrap(); let peripherals = Peripherals::take().unwrap();
let config = config::TimerConfig::new().frequency(25.kHz().into());
let mut channel = LedcDriver::new( let mut channel = LedcDriver::new(
peripherals.ledc.channel0, peripherals.ledc.channel0,
LedcTimerDriver::new(peripherals.ledc.timer0, &config)?, LedcTimerDriver::new(
peripherals.ledc.timer0,
&config::TimerConfig::new().frequency(25.kHz().into()),
)?,
peripherals.pins.gpio4, peripherals.pins.gpio4,
&config,
)?; )?;
println!("Starting duty-cycle loop"); println!("Starting duty-cycle loop");

View File

@ -20,14 +20,8 @@ fn main() -> anyhow::Result<()> {
peripherals.ledc.channel0, peripherals.ledc.channel0,
timer.clone(), timer.clone(),
peripherals.pins.gpio4, peripherals.pins.gpio4,
&config,
)?;
let channel1 = LedcDriver::new(
peripherals.ledc.channel1,
timer,
peripherals.pins.gpio5,
&config,
)?; )?;
let channel1 = LedcDriver::new(peripherals.ledc.channel1, timer, peripherals.pins.gpio5)?;
println!("Spawning PWM threads"); println!("Spawning PWM threads");

View File

@ -10,12 +10,13 @@
//! //!
//! Create a 25 kHz PWM signal with 75 % duty cycle on GPIO 1 //! Create a 25 kHz PWM signal with 75 % duty cycle on GPIO 1
//! ``` //! ```
//! use esp_idf_hal::ledc::{config::TimerConfig, Channel, LedcDriver, Timer}; //! use esp_idf_hal::ledc::{config::TimerConfig, Channel, LedcDriver, LedcTimerDriver, Timer};
//! use esp_idf_hal::peripherals::Peripherals; //! use esp_idf_hal::peripherals::Peripherals;
//! use esp_idf_hal::prelude::*; //! use esp_idf_hal::prelude::*;
//! //!
//! let peripherals = Peripherals::take().unwrap(); //! let peripherals = Peripherals::take().unwrap();
//! let mut driver = LedcDriver::new(peripherals.ledc.channel0, peripherals.ledc.timer0, peripherals.pins.gpio1, &TimerConfig::default().frequency(25.kHz().into()))?; //! let timer_driver = LedcTimerDriver::new(peripherals.ledc.timer0, &TimerConfig::default().frequency(25.kHz().into()));
//! let mut driver = LedcDriver::new(peripherals.ledc.channel0, timer_driver, peripherals.pins.gpio1)?;
//! //!
//! let max_duty = driver.get_max_duty()?; //! let max_duty = driver.get_max_duty()?;
//! driver.set_duty(max_duty * 3 / 4)?; //! driver.set_duty(max_duty * 3 / 4)?;
@ -179,7 +180,6 @@ impl<'d> LedcDriver<'d> {
_channel: impl Peripheral<P = C> + 'd, _channel: impl Peripheral<P = C> + 'd,
timer_driver: B, timer_driver: B,
pin: impl Peripheral<P = impl OutputPin> + 'd, pin: impl Peripheral<P = impl OutputPin> + 'd,
config: &config::TimerConfig,
) -> Result<Self, EspError> { ) -> Result<Self, EspError> {
crate::into_ref!(pin); crate::into_ref!(pin);
@ -187,7 +187,7 @@ impl<'d> LedcDriver<'d> {
let hpoint = 0; let hpoint = 0;
let channel_config = ledc_channel_config_t { let channel_config = ledc_channel_config_t {
speed_mode: config.speed_mode.into(), speed_mode: timer_driver.borrow().speed_mode.into(),
channel: C::channel(), channel: C::channel(),
timer_sel: timer_driver.borrow().timer(), timer_sel: timer_driver.borrow().timer(),
intr_type: ledc_intr_type_t_LEDC_INTR_DISABLE, intr_type: ledc_intr_type_t_LEDC_INTR_DISABLE,