From 8bc4eddbe3161560d3e88cdc7ba4bb972d20377c Mon Sep 17 00:00:00 2001 From: Anthony Grondin <104731965+AnthonyGrondin@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:27:33 -0400 Subject: [PATCH] Use patched `esp-hal` until new release --- esp-hal-buzzer/Cargo.toml | 4 ++-- esp-hal-buzzer/examples/buzzer.rs | 5 ++--- esp-hal-buzzer/src/lib.rs | 26 +++++++++++--------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/esp-hal-buzzer/Cargo.toml b/esp-hal-buzzer/Cargo.toml index fb79c96..1afc5be 100644 --- a/esp-hal-buzzer/Cargo.toml +++ b/esp-hal-buzzer/Cargo.toml @@ -45,6 +45,6 @@ esp32s2 = ["esp-backtrace/esp32s2", "esp-hal/esp32s2", "esp-println/esp32s2"] ## Target the ESP32-S3. esp32s3 = ["esp-backtrace/esp32s3", "esp-hal/esp32s3", "esp-println/esp32s3"] -# Patch until https://github.com/esp-rs/esp-hal/pull/1984 is merged +# Patch until next esp-hal release [patch.crates-io] -esp-hal = { git = "https://github.com/AnthonyGrondin/esp-hal", rev = "00248bc" } +esp-hal = { git = "https://github.com/esp-rs/esp-hal", rev = "a787a13" } diff --git a/esp-hal-buzzer/examples/buzzer.rs b/esp-hal-buzzer/examples/buzzer.rs index 1269955..435b1dd 100644 --- a/esp-hal-buzzer/examples/buzzer.rs +++ b/esp-hal-buzzer/examples/buzzer.rs @@ -17,11 +17,11 @@ use esp_println::println; #[entry] fn main() -> ! { - let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default()); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); - let mut ledc = Ledc::new(peripherals.LEDC, &clocks); + let mut ledc = Ledc::new(peripherals.LEDC); ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); let mut buzzer = Buzzer::new( @@ -29,7 +29,6 @@ fn main() -> ! { timer::Number::Timer0, channel::Number::Channel1, io.pins.gpio6, - &clocks, ); buzzer.play_song(DOOM).unwrap(); diff --git a/esp-hal-buzzer/src/lib.rs b/esp-hal-buzzer/src/lib.rs index edd87f1..334d5dc 100644 --- a/esp-hal-buzzer/src/lib.rs +++ b/esp-hal-buzzer/src/lib.rs @@ -36,12 +36,11 @@ use core::{fmt::Debug, ops::DerefMut}; use esp_hal::{ clock::Clocks, delay::Delay, - gpio::{AnyPin, CreateErasedPin, InputPin, Level, Output, OutputPin}, + gpio::{AnyPin, Level, Output, OutputPin, Pin}, ledc::{ channel::{self, Channel, ChannelIFace}, timer::{self, Timer, TimerHW, TimerIFace, TimerSpeed}, - Ledc, - LowSpeed, + Ledc, LowSpeed, }, peripheral::{Peripheral, PeripheralRef}, }; @@ -110,9 +109,9 @@ pub enum VolumeType { } /// Volume configuration for the buzzer -struct Volume<'a> { +struct Volume { /// Output pin for the volume - volume_pin: AnyPin<'a>, + volume_pin: AnyPin, /// Type of the volume volume_type: VolumeType, @@ -130,8 +129,7 @@ pub struct Buzzer<'a, S: TimerSpeed, O: OutputPin> { channel_number: channel::Number, output_pin: PeripheralRef<'a, O>, delay: Delay, - volume: Option>, - clocks: &'a Clocks<'a>, + volume: Option, } impl<'a, S: TimerSpeed, O: OutputPin + Peripheral

> Buzzer<'a, S, O> @@ -146,27 +144,25 @@ where timer_number: timer::Number, channel_number: channel::Number, output_pin: impl Peripheral

+ 'a, - clocks: &'a Clocks, ) -> Self { let timer = ledc.get_timer(timer_number); Self { timer, channel_number, output_pin: output_pin.into_ref(), - delay: Delay::new(clocks), - volume: None::>, - clocks, + delay: Delay::new(), + volume: None::, } } /// Add a volume control for the buzzer. - pub fn with_volume( + pub fn with_volume( mut self, - volume_pin: impl Peripheral

+ 'a, + volume_pin: impl Peripheral

+ Pin + 'a, volume_type: VolumeType, ) -> Self { self.volume = Some(Volume { - volume_pin: AnyPin::new(volume_pin), + volume_pin: volume_pin.degrade(), volume_type, level: 50, }); @@ -256,7 +252,7 @@ where // Max duty resolution for a frequency: // Integer(log2(LEDC_APB_CKL / frequency)) let mut result = 0; - let mut value = (self.clocks.apb_clock / frequency).raw(); + let mut value = (Clocks::get().apb_clock / frequency).raw(); // Limit duty resolution to 14 bits while value > 1 && result < 14 {