Remove the need to manually pass clocks around (#1999)

* Clean up passing clocks to drivers

* Update changelog

* Initialise Clocks in a critical section

* Fix calling now() before init

* Fix doc

* Fix esp-wifi migration guide

* Add safety comment

* Update tests
This commit is contained in:
Dániel Buga 2024-09-04 16:13:51 +02:00 committed by GitHub
parent 7688504289
commit 99bf346898
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
186 changed files with 747 additions and 882 deletions

View File

@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Removed the `clocks` parameter from `esp_hal_embassy::init`. (#1999)
## 0.3.0 - 2024-08-29 ## 0.3.0 - 2024-08-29
### Added ### Added

View File

@ -0,0 +1,30 @@
Migration Guide from 0.3.x to vNext
====================================
Initialsation
-------------
You no longer have to set up clocks and pass them to `esp_hal_embassy::init`.
```diff
use esp_hal::{
- clock::ClockControl,
- peripherals::Peripherals,
prelude::*,
- system::SystemControl,
};
#[esp_hal_embassy::main]
async fn main(_spawner: Spawner) -> ! {
- let peripherals = Peripherals::take();
- let system = SystemControl::new(peripherals.SYSTEM);
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
+ let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0);
- esp_hal_embassy::init(&clocks, timg0);
+ esp_hal_embassy::init(timg0);
// ...
}
```

View File

@ -38,10 +38,7 @@ mod fmt;
#[cfg(not(feature = "esp32"))] #[cfg(not(feature = "esp32"))]
use esp_hal::timer::systimer::Alarm; use esp_hal::timer::systimer::Alarm;
use esp_hal::{ use esp_hal::timer::{timg::Timer as TimgTimer, ErasedTimer};
clock::Clocks,
timer::{timg::Timer as TimgTimer, ErasedTimer},
};
pub use macros::main; pub use macros::main;
#[cfg(feature = "executors")] #[cfg(feature = "executors")]
@ -158,12 +155,12 @@ impl_array!(4);
#[doc = esp_hal::before_snippet!()] #[doc = esp_hal::before_snippet!()]
/// use esp_hal::timg::TimerGroup; /// use esp_hal::timg::TimerGroup;
/// ///
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); /// let timg0 = TimerGroup::new(peripherals.TIMG0);
/// esp_hal_embassy::init(&clocks, timg0.timer0); /// esp_hal_embassy::init(timg0.timer0);
/// ///
/// // ... now you can spawn embassy tasks or use `Timer::after` etc. /// // ... now you can spawn embassy tasks or use `Timer::after` etc.
/// # } /// # }
/// ``` /// ```
pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) { pub fn init(time_driver: impl TimerCollection) {
EmbassyTimer::init(clocks, time_driver.timers()) EmbassyTimer::init(time_driver.timers())
} }

View File

@ -3,7 +3,6 @@ use core::cell::{Cell, RefCell};
use critical_section::Mutex; use critical_section::Mutex;
use embassy_time_driver::{AlarmHandle, Driver}; use embassy_time_driver::{AlarmHandle, Driver};
use esp_hal::{ use esp_hal::{
clock::Clocks,
interrupt::{InterruptHandler, Priority}, interrupt::{InterruptHandler, Priority},
prelude::*, prelude::*,
time::current_time, time::current_time,
@ -45,7 +44,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTime
}); });
impl EmbassyTimer { impl EmbassyTimer {
pub(super) fn init(_clocks: &Clocks, timers: &'static mut [Timer]) { pub(super) fn init(timers: &'static mut [Timer]) {
if timers.len() > MAX_SUPPORTED_ALARM_COUNT { if timers.len() > MAX_SUPPORTED_ALARM_COUNT {
panic!( panic!(
"Maximum of {} timers can be used.", "Maximum of {} timers can be used.",

View File

@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Removed the `clocks` parameter from `SmartLedsAdapter::new` (#1999)
## 0.13.0 - 2024-08-29 ## 0.13.0 - 2024-08-29
## 0.12.0 - 2024-07-15 ## 0.12.0 - 2024-07-15

View File

@ -12,10 +12,10 @@
//! //!
//! ```rust,ignore //! ```rust,ignore
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks, None).unwrap(); //! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), None).unwrap();
//! //!
//! let rmt_buffer = smartLedBuffer!(1); //! let rmt_buffer = smartLedBuffer!(1);
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer, &clocks); //! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer);
//! ``` //! ```
//! //!
//! ## Feature Flags //! ## Feature Flags
@ -89,7 +89,6 @@ where
channel: C, channel: C,
pin: impl Peripheral<P = O> + 'd, pin: impl Peripheral<P = O> + 'd,
rmt_buffer: [u32; BUFFER_SIZE], rmt_buffer: [u32; BUFFER_SIZE],
clocks: &Clocks,
) -> SmartLedsAdapter<TX, BUFFER_SIZE> ) -> SmartLedsAdapter<TX, BUFFER_SIZE>
where where
O: OutputPin + 'd, O: OutputPin + 'd,
@ -107,6 +106,7 @@ where
let channel = channel.configure(pin, config).unwrap(); let channel = channel.configure(pin, config).unwrap();
// Assume the RMT peripheral is set up to use the APB clock // Assume the RMT peripheral is set up to use the APB clock
let clocks = Clocks::get();
let src_clock = clocks.apb_clock.to_MHz(); let src_clock = clocks.apb_clock.to_MHz();
Self { Self {

View File

@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Implement `embedded-hal` output pin traits for `DummyPin` (#2019) - Implement `embedded-hal` output pin traits for `DummyPin` (#2019)
- Added `esp_hal::init` to simplify HAL initialisation (#1970) - Added `esp_hal::init` to simplify HAL initialisation (#1970, #1999)
### Changed ### Changed
- `Delay::new()` is now a `const` function (#1999)
### Fixed ### Fixed
- Fixed an issue with DMA transfers potentially not waking up the correct async task (#2065) - Fixed an issue with DMA transfers potentially not waking up the correct async task (#2065)
@ -23,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removed `NoPinType` in favour of `DummyPin`. (#2068) - Removed `NoPinType` in favour of `DummyPin`. (#2068)
- Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070) - Removed the `async`, `embedded-hal-02`, `embedded-hal`, `embedded-io`, `embedded-io-async`, and `ufmt` features (#2070)
- Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073) - Removed the `GpioN` type aliasses. Use `GpioPin<N>` instead. (#2073)
- Removed `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999)
## [0.20.1] - 2024-08-30 ## [0.20.1] - 2024-08-30

View File

@ -139,6 +139,7 @@ defmt = [
"esp32h2?/defmt", "esp32h2?/defmt",
"esp32s2?/defmt", "esp32s2?/defmt",
"esp32s3?/defmt", "esp32s3?/defmt",
"fugit/defmt",
] ]
#! ### PSRAM Feature Flags #! ### PSRAM Feature Flags

View File

@ -30,7 +30,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
- let peripherals = Peripherals::take(); - let peripherals = Peripherals::take();
- let system = SystemControl::new(peripherals.SYSTEM); - let system = SystemControl::new(peripherals.SYSTEM);
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
+ let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); + let peripherals = esp_hal::init(esp_hal::Config::default());
// ... // ...
} }

View File

@ -46,7 +46,7 @@
//! ); //! );
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); //! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
//! //!
//! let mut delay = Delay::new(&clocks); //! let mut delay = Delay::new();
//! //!
//! loop { //! loop {
//! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap(); //! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();

View File

@ -27,7 +27,7 @@
#![cfg_attr(esp32s2, doc = "let dac1_pin = io.pins.gpio17;")] #![cfg_attr(esp32s2, doc = "let dac1_pin = io.pins.gpio17;")]
//! let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin); //! let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin);
//! //!
//! let mut delay = Delay::new(&clocks); //! let mut delay = Delay::new();
//! //!
//! let mut voltage_dac1 = 200u8; //! let mut voltage_dac1 = 200u8;
//! //!

View File

@ -48,14 +48,14 @@
//! # } //! # }
//! # fn main() { //! # fn main() {
//! // Initialize with the highest possible frequency for this chip //! // Initialize with the highest possible frequency for this chip
//! let (peripherals, clocks) = esp_hal::init({ //! let peripherals = esp_hal::init({
//! let mut config = esp_hal::Config::default(); //! let mut config = esp_hal::Config::default();
//! config.cpu_clock = CpuClock::max(); //! config.cpu_clock = CpuClock::max();
//! config //! config
//! }); //! });
//! //!
//! // Initialize with custom clock frequency //! // Initialize with custom clock frequency
//! // let (peripherals, clocks) = esp_hal::init({ //! // let peripherals = esp_hal::init({
//! // let mut config = esp_hal::Config::default(); //! // let mut config = esp_hal::Config::default();
#![cfg_attr( #![cfg_attr(
not(any(esp32c2, esp32h2)), not(any(esp32c2, esp32h2)),
@ -67,15 +67,11 @@
//! // }); //! // });
//! // //! //
//! // Initialize with default clock frequency for this chip //! // Initialize with default clock frequency for this chip
//! // let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); //! // let peripherals = esp_hal::init(esp_hal::Config::default());
//! # } //! # }
//! ``` //! ```
use core::marker::PhantomData;
use fugit::HertzU32; use fugit::HertzU32;
#[cfg(esp32c2)]
use portable_atomic::{AtomicU32, Ordering};
#[cfg(any(esp32, esp32c2))] #[cfg(any(esp32, esp32c2))]
use crate::rtc_cntl::RtcClock; use crate::rtc_cntl::RtcClock;
@ -275,38 +271,11 @@ impl Clock for ApbClock {
} }
} }
/// Frozen clock frequencies /// Clock frequencies.
/// #[derive(Debug, Clone, Copy)]
/// The instantiation of this type indicates that the clock configuration can no #[cfg_attr(feature = "defmt", derive(defmt::Format))]
/// longer be changed. #[non_exhaustive]
pub struct Clocks<'a> { pub struct Clocks {
_private: PhantomData<&'a ()>,
rates: RawClocks,
}
impl<'a> Clocks<'a> {
/// This should not be used in user code.
/// The whole point this exists is make it possible to have other crates
/// (i.e. esp-wifi) create `Clocks`
#[doc(hidden)]
pub(crate) fn from_raw_clocks(raw_clocks: RawClocks) -> Clocks<'a> {
Self {
_private: PhantomData,
rates: raw_clocks,
}
}
}
impl core::ops::Deref for Clocks<'_> {
type Target = RawClocks;
fn deref(&self) -> &RawClocks {
&self.rates
}
}
/// The list of the clock frequencies that are used in the system.
pub struct RawClocks {
/// CPU clock frequency /// CPU clock frequency
pub cpu_clock: HertzU32, pub cpu_clock: HertzU32,
@ -341,56 +310,53 @@ pub struct RawClocks {
pub pll_96m_clock: HertzU32, pub pll_96m_clock: HertzU32,
} }
cfg_if::cfg_if! { static mut ACTIVE_CLOCKS: Option<Clocks> = None;
if #[cfg(esp32c2)] {
static XTAL_FREQ_MHZ: AtomicU32 = AtomicU32::new(40);
pub(crate) fn xtal_freq_mhz() -> u32 { impl Clocks {
XTAL_FREQ_MHZ.load(Ordering::Relaxed) pub(crate) fn init(cpu_clock_speed: CpuClock) {
} critical_section::with(|_| {
} else if #[cfg(esp32h2)] { unsafe { ACTIVE_CLOCKS = Some(Self::configure(cpu_clock_speed)) };
pub(crate) fn xtal_freq_mhz() -> u32 { })
32
}
} else if #[cfg(any(esp32, esp32s2))] {
// Function would be unused
} else {
pub(crate) fn xtal_freq_mhz() -> u32 {
40
}
}
}
/// Used to configure the frequencies of the clocks present in the chip.
///
/// After setting all frequencies, call the freeze function to apply the
/// configuration.
pub struct ClockControl {
desired_rates: RawClocks,
}
impl ClockControl {
pub(crate) fn new(clock: CpuClock) -> Self {
Self::configure(clock)
} }
/// Applies the clock configuration and returns a Clocks struct that fn try_get() -> Option<&'static Clocks> {
/// signifies that the clocks are frozen, and contains the frequencies unsafe {
/// used. After this function is called, the clocks can not change // Safety: ACTIVE_CLOCKS is only set in `init` and never modified after that.
pub fn freeze(self) -> Clocks<'static> { ACTIVE_CLOCKS.as_ref()
Clocks::from_raw_clocks(self.desired_rates) }
}
/// Get the active clock configuration.
pub fn get() -> &'static Clocks {
unwrap!(Self::try_get())
}
/// Returns the xtal frequency.
///
/// This function will run the frequency estimation if called before
/// [`crate::init()`].
pub fn xtal_freq() -> HertzU32 {
if let Some(clocks) = Self::try_get() {
clocks.xtal_clock
} else {
Self::measure_xtal_frequency().frequency()
}
} }
} }
#[cfg(esp32)] #[cfg(esp32)]
impl ClockControl { impl Clocks {
/// Configure the CPU clock speed. fn measure_xtal_frequency() -> XtalClock {
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { if RtcClock::estimate_xtal_frequency() > 33 {
let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 {
XtalClock::RtcXtalFreq40M XtalClock::RtcXtalFreq40M
} else { } else {
XtalClock::RtcXtalFreq26M XtalClock::RtcXtalFreq26M
}; }
}
/// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = Self::measure_xtal_frequency();
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
let pll_freq = match cpu_clock_speed { let pll_freq = match cpu_clock_speed {
@ -405,31 +371,32 @@ impl ClockControl {
clocks_ll::set_cpu_freq(cpu_clock_speed); clocks_ll::set_cpu_freq(cpu_clock_speed);
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80),
apb_clock: HertzU32::MHz(80), xtal_clock: HertzU32::MHz(xtal_freq.mhz()),
xtal_clock: HertzU32::MHz(xtal_freq.mhz()), i2c_clock: HertzU32::MHz(80),
i2c_clock: HertzU32::MHz(80), // The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock
// The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock // while simultaneously being fixed at 160 MHz.
// while simultaneously being fixed at 160 MHz. // Testing showed 160 MHz to be correct for current clock configurations.
// Testing showed 160 MHz to be correct for current clock configurations. pwm_clock: HertzU32::MHz(160),
pwm_clock: HertzU32::MHz(160),
},
} }
} }
} }
#[cfg(esp32c2)] #[cfg(esp32c2)]
impl ClockControl { impl Clocks {
/// Configure the CPU clock speed. fn measure_xtal_frequency() -> XtalClock {
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { if RtcClock::estimate_xtal_frequency() > 33 {
let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 {
XtalClock::RtcXtalFreq40M XtalClock::RtcXtalFreq40M
} else { } else {
XtalClock::RtcXtalFreq26M XtalClock::RtcXtalFreq26M
}; }
XTAL_FREQ_MHZ.store(xtal_freq.mhz(), Ordering::Relaxed); }
/// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = Self::measure_xtal_frequency();
let apb_freq; let apb_freq;
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
@ -450,21 +417,23 @@ impl ClockControl {
apb_freq = ApbClock::ApbFreq40MHz; apb_freq = ApbClock::ApbFreq40MHz;
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(),
apb_clock: apb_freq.frequency(), xtal_clock: xtal_freq.frequency(),
xtal_clock: xtal_freq.frequency(),
},
} }
} }
} }
#[cfg(esp32c3)] #[cfg(esp32c3)]
impl ClockControl { impl Clocks {
fn measure_xtal_frequency() -> XtalClock {
XtalClock::RtcXtalFreq40M
}
/// Configure the CPU clock speed. /// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = XtalClock::RtcXtalFreq40M; let xtal_freq = Self::measure_xtal_frequency();
let apb_freq; let apb_freq;
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
@ -484,21 +453,23 @@ impl ClockControl {
apb_freq = ApbClock::ApbFreq80MHz; apb_freq = ApbClock::ApbFreq80MHz;
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(),
apb_clock: apb_freq.frequency(), xtal_clock: xtal_freq.frequency(),
xtal_clock: xtal_freq.frequency(),
},
} }
} }
} }
#[cfg(esp32c6)] #[cfg(esp32c6)]
impl ClockControl { impl Clocks {
fn measure_xtal_frequency() -> XtalClock {
XtalClock::RtcXtalFreq40M
}
/// Configure the CPU clock speed. /// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = XtalClock::RtcXtalFreq40M; let xtal_freq = Self::measure_xtal_frequency();
let apb_freq; let apb_freq;
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
@ -518,22 +489,24 @@ impl ClockControl {
apb_freq = ApbClock::ApbFreq80MHz; apb_freq = ApbClock::ApbFreq80MHz;
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(),
apb_clock: apb_freq.frequency(), xtal_clock: xtal_freq.frequency(),
xtal_clock: xtal_freq.frequency(), crypto_clock: HertzU32::MHz(160),
crypto_clock: HertzU32::MHz(160),
},
} }
} }
} }
#[cfg(esp32h2)] #[cfg(esp32h2)]
impl ClockControl { impl Clocks {
fn measure_xtal_frequency() -> XtalClock {
XtalClock::RtcXtalFreq32M
}
/// Configure the CPU clock speed. /// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = XtalClock::RtcXtalFreq32M; let xtal_freq = Self::measure_xtal_frequency();
let apb_freq; let apb_freq;
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
@ -553,52 +526,58 @@ impl ClockControl {
apb_freq = ApbClock::ApbFreq32MHz; apb_freq = ApbClock::ApbFreq32MHz;
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: apb_freq.frequency(),
apb_clock: apb_freq.frequency(), xtal_clock: xtal_freq.frequency(),
xtal_clock: xtal_freq.frequency(), pll_48m_clock: HertzU32::MHz(48),
pll_48m_clock: HertzU32::MHz(48), crypto_clock: HertzU32::MHz(96),
crypto_clock: HertzU32::MHz(96), pll_96m_clock: HertzU32::MHz(96),
pll_96m_clock: HertzU32::MHz(96),
},
} }
} }
} }
#[cfg(esp32s2)] #[cfg(esp32s2)]
impl ClockControl { impl Clocks {
fn measure_xtal_frequency() -> XtalClock {
XtalClock::RtcXtalFreq40M
}
/// Configure the CPU clock speed. /// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = Self::measure_xtal_frequency();
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
clocks_ll::set_cpu_clock(cpu_clock_speed); clocks_ll::set_cpu_clock(cpu_clock_speed);
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80),
apb_clock: HertzU32::MHz(80), xtal_clock: xtal_freq.frequency(),
xtal_clock: HertzU32::MHz(40),
},
} }
} }
} }
#[cfg(esp32s3)] #[cfg(esp32s3)]
impl ClockControl { impl Clocks {
fn measure_xtal_frequency() -> XtalClock {
XtalClock::RtcXtalFreq40M
}
/// Configure the CPU clock speed. /// Configure the CPU clock speed.
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl { pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
let xtal_freq = Self::measure_xtal_frequency();
if cpu_clock_speed != CpuClock::default() { if cpu_clock_speed != CpuClock::default() {
clocks_ll::set_cpu_clock(cpu_clock_speed); clocks_ll::set_cpu_clock(cpu_clock_speed);
} }
ClockControl { Self {
desired_rates: RawClocks { cpu_clock: cpu_clock_speed.frequency(),
cpu_clock: cpu_clock_speed.frequency(), apb_clock: HertzU32::MHz(80),
apb_clock: HertzU32::MHz(80), xtal_clock: xtal_freq.frequency(),
xtal_clock: HertzU32::MHz(40), crypto_pwm_clock: HertzU32::MHz(160),
crypto_pwm_clock: HertzU32::MHz(160),
},
} }
} }
} }

View File

@ -22,7 +22,7 @@
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::delay::Delay; //! # use esp_hal::delay::Delay;
//! # use embedded_hal::delay::DelayNs; //! # use embedded_hal::delay::DelayNs;
//! let mut delay = Delay::new(&clocks); //! let mut delay = Delay::new();
//! //!
//! delay.delay_ms(1000 as u32); //! delay.delay_ms(1000 as u32);
//! # } //! # }
@ -35,13 +35,11 @@
pub use fugit::MicrosDurationU64; pub use fugit::MicrosDurationU64;
use crate::clock::Clocks;
/// Delay driver /// Delay driver
/// ///
/// Uses the `SYSTIMER` peripheral internally for RISC-V devices, and the /// Uses the `SYSTIMER` peripheral internally for RISC-V devices, and the
/// built-in Xtensa timer for Xtensa devices. /// built-in Xtensa timer for Xtensa devices.
#[derive(Clone, Copy)] #[derive(Clone, Copy, Default)]
#[non_exhaustive] #[non_exhaustive]
pub struct Delay; pub struct Delay;
@ -71,8 +69,7 @@ impl embedded_hal::delay::DelayNs for Delay {
impl Delay { impl Delay {
/// Creates a new `Delay` instance. /// Creates a new `Delay` instance.
// Do not remove the argument, it makes sure that the clocks are initialized. pub const fn new() -> Self {
pub fn new(_clocks: &Clocks<'_>) -> Self {
Self {} Self {}
} }

View File

@ -34,7 +34,6 @@
//! peripherals.SPI2, //! peripherals.SPI2,
//! 100.kHz(), //! 100.kHz(),
//! SpiMode::Mode0, //! SpiMode::Mode0,
//! &clocks
//! ) //! )
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
//! .with_dma(dma_channel.configure( //! .with_dma(dma_channel.configure(

View File

@ -42,7 +42,6 @@
//! io.pins.gpio1, //! io.pins.gpio1,
//! io.pins.gpio2, //! io.pins.gpio2,
//! 100.kHz(), //! 100.kHz(),
//! &clocks,
//! ); //! );
//! //!
//! loop { //! loop {
@ -303,7 +302,6 @@ where
sda: impl Peripheral<P = SDA> + 'd, sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd, scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
timeout: Option<u32>, timeout: Option<u32>,
) -> Self { ) -> Self {
crate::into_ref!(i2c, sda, scl); crate::into_ref!(i2c, sda, scl);
@ -355,7 +353,7 @@ where
crate::private::Internal, crate::private::Internal,
); );
i2c.peripheral.setup(frequency, clocks, timeout); i2c.peripheral.setup(frequency, timeout);
i2c i2c
} }
@ -379,9 +377,8 @@ where
sda: impl Peripheral<P = SDA> + 'd, sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd, scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
) -> Self { ) -> Self {
Self::new_with_timeout(i2c, sda, scl, frequency, clocks, None) Self::new_with_timeout(i2c, sda, scl, frequency, None)
} }
/// Create a new I2C instance with a custom timeout value. /// Create a new I2C instance with a custom timeout value.
@ -392,10 +389,9 @@ where
sda: impl Peripheral<P = SDA> + 'd, sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd, scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
timeout: Option<u32>, timeout: Option<u32>,
) -> Self { ) -> Self {
Self::new_internal(i2c, sda, scl, frequency, clocks, timeout) Self::new_internal(i2c, sda, scl, frequency, timeout)
} }
} }
@ -422,9 +418,8 @@ where
sda: impl Peripheral<P = SDA> + 'd, sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd, scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
) -> Self { ) -> Self {
Self::new_with_timeout_async(i2c, sda, scl, frequency, clocks, None) Self::new_with_timeout_async(i2c, sda, scl, frequency, None)
} }
/// Create a new I2C instance with a custom timeout value. /// Create a new I2C instance with a custom timeout value.
@ -435,10 +430,9 @@ where
sda: impl Peripheral<P = SDA> + 'd, sda: impl Peripheral<P = SDA> + 'd,
scl: impl Peripheral<P = SCL> + 'd, scl: impl Peripheral<P = SCL> + 'd,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
timeout: Option<u32>, timeout: Option<u32>,
) -> Self { ) -> Self {
let mut this = Self::new_internal(i2c, sda, scl, frequency, clocks, timeout); let mut this = Self::new_internal(i2c, sda, scl, frequency, timeout);
let handler = match T::I2C_NUMBER { let handler = match T::I2C_NUMBER {
0 => asynch::i2c0_handler, 0 => asynch::i2c0_handler,
@ -1011,7 +1005,7 @@ pub trait Instance: crate::private::Sealed {
/// Configures the I2C peripheral with the specified frequency, clocks, and /// Configures the I2C peripheral with the specified frequency, clocks, and
/// optional timeout. /// optional timeout.
fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>, timeout: Option<u32>) { fn setup(&mut self, frequency: HertzU32, timeout: Option<u32>) {
self.register_block().ctr().modify(|_, w| unsafe { self.register_block().ctr().modify(|_, w| unsafe {
// Clear register // Clear register
w.bits(0) w.bits(0)
@ -1043,6 +1037,7 @@ pub trait Instance: crate::private::Sealed {
self.set_filter(Some(7), Some(7)); self.set_filter(Some(7), Some(7));
// Configure frequency // Configure frequency
let clocks = Clocks::get();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32)] { if #[cfg(esp32)] {
self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout); self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout);

View File

@ -54,7 +54,6 @@
//! ), //! ),
//! tx_descriptors, //! tx_descriptors,
//! rx_descriptors, //! rx_descriptors,
//! &clocks,
//! ); //! );
#![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")] #![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")]
//! let mut i2s_rx = i2s.i2s_rx //! let mut i2s_rx = i2s.i2s_rx
@ -88,7 +87,6 @@ use private::*;
#[cfg(any(esp32, esp32s3))] #[cfg(any(esp32, esp32s3))]
use crate::dma::I2s1Peripheral; use crate::dma::I2s1Peripheral;
use crate::{ use crate::{
clock::Clocks,
dma::{ dma::{
dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx},
Channel, Channel,
@ -350,7 +348,6 @@ where
mut channel: Channel<'d, CH, DmaMode>, mut channel: Channel<'d, CH, DmaMode>,
tx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor],
clocks: &Clocks<'d>,
) -> Self { ) -> Self {
// on ESP32-C3 / ESP32-S3 and later RX and TX are independent and // on ESP32-C3 / ESP32-S3 and later RX and TX are independent and
// could be configured totally independently but for now handle all // could be configured totally independently but for now handle all
@ -359,12 +356,7 @@ where
channel.tx.init_channel(); channel.tx.init_channel();
PeripheralClockControl::reset(I::get_peripheral()); PeripheralClockControl::reset(I::get_peripheral());
PeripheralClockControl::enable(I::get_peripheral()); PeripheralClockControl::enable(I::get_peripheral());
I::set_clock(calculate_clock( I::set_clock(calculate_clock(sample_rate, 2, data_format.channel_bits()));
sample_rate,
2,
data_format.channel_bits(),
clocks,
));
I::configure(&standard, &data_format); I::configure(&standard, &data_format);
I::set_master(); I::set_master();
I::update(); I::update();
@ -457,7 +449,6 @@ where
channel: Channel<'d, CH, DmaMode>, channel: Channel<'d, CH, DmaMode>,
tx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor],
clocks: &Clocks<'d>,
) -> Self ) -> Self
where where
I: I2s0Instance, I: I2s0Instance,
@ -472,7 +463,6 @@ where
channel, channel,
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
clocks,
) )
} }
@ -488,7 +478,6 @@ where
channel: Channel<'d, CH, DmaMode>, channel: Channel<'d, CH, DmaMode>,
tx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor],
clocks: &Clocks<'d>,
) -> Self ) -> Self
where where
I: I2s1Instance, I: I2s1Instance,
@ -502,7 +491,6 @@ where
channel, channel,
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
clocks,
) )
} }
@ -901,7 +889,6 @@ mod private {
#[cfg(any(esp32, esp32s3))] #[cfg(any(esp32, esp32s3))]
use crate::peripherals::{i2s1::RegisterBlock, I2S1}; use crate::peripherals::{i2s1::RegisterBlock, I2S1};
use crate::{ use crate::{
clock::Clocks,
dma::{ChannelRx, ChannelTx, DmaChannel, DmaDescriptor, DmaPeripheral}, dma::{ChannelRx, ChannelTx, DmaChannel, DmaDescriptor, DmaPeripheral},
gpio::{InputPin, InputSignal, OutputPin, OutputSignal}, gpio::{InputPin, InputSignal, OutputPin, OutputSignal},
interrupt::InterruptHandler, interrupt::InterruptHandler,
@ -2114,7 +2101,6 @@ mod private {
sample_rate: impl Into<fugit::HertzU32>, sample_rate: impl Into<fugit::HertzU32>,
channels: u8, channels: u8,
data_bits: u8, data_bits: u8,
_clocks: &Clocks<'_>,
) -> I2sClockDividers { ) -> I2sClockDividers {
// this loosely corresponds to `i2s_std_calculate_clock` and // this loosely corresponds to `i2s_std_calculate_clock` and
// `i2s_ll_tx_set_mclk` in esp-idf // `i2s_ll_tx_set_mclk` in esp-idf

View File

@ -55,7 +55,6 @@
//! rx_descriptors, //! rx_descriptors,
//! data_pins, //! data_pins,
//! 20u32.MHz(), //! 20u32.MHz(),
//! &clocks
//! ) //! )
//! // Remove this for slave mode. //! // Remove this for slave mode.
//! .with_master_clock(mclk_pin) //! .with_master_clock(mclk_pin)
@ -146,10 +145,10 @@ where
descriptors: &'static mut [DmaDescriptor], descriptors: &'static mut [DmaDescriptor],
_pins: P, _pins: P,
frequency: HertzU32, frequency: HertzU32,
clocks: &Clocks<'d>,
) -> Self { ) -> Self {
let lcd_cam = cam.lcd_cam; let lcd_cam = cam.lcd_cam;
let clocks = Clocks::get();
let (i, divider) = calculate_clkm( let (i, divider) = calculate_clkm(
frequency.to_Hz() as _, frequency.to_Hz() as _,
&[ &[

View File

@ -50,7 +50,6 @@
//! tx_pins, //! tx_pins,
//! 20.MHz(), //! 20.MHz(),
//! Config::default(), //! Config::default(),
//! &clocks,
//! ) //! )
//! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47); //! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47);
//! //!
@ -113,16 +112,15 @@ where
mut pins: P, mut pins: P,
frequency: HertzU32, frequency: HertzU32,
config: Config, config: Config,
clocks: &Clocks<'d>,
) -> Self { ) -> Self {
let is_2byte_mode = size_of::<P::Word>() == 2; let is_2byte_mode = size_of::<P::Word>() == 2;
let lcd_cam = lcd.lcd_cam; let lcd_cam = lcd.lcd_cam;
let clocks = Clocks::get();
// Due to https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf // Due to https://www.espressif.com/sites/default/files/documentation/esp32-s3_errata_en.pdf
// the LCD_PCLK divider must be at least 2. To make up for this the user // the LCD_PCLK divider must be at least 2. To make up for this the user
// provided frequency is doubled to match. // provided frequency is doubled to match.
let (i, divider) = calculate_clkm( let (i, divider) = calculate_clkm(
(frequency.to_Hz() * 2) as _, (frequency.to_Hz() * 2) as _,
&[ &[

View File

@ -33,7 +33,7 @@
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let led = io.pins.gpio0; //! # let led = io.pins.gpio0;
//! //!
//! let mut ledc = Ledc::new(peripherals.LEDC, &clocks); //! let mut ledc = Ledc::new(peripherals.LEDC);
//! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); //! ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);
//! //!
//! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0); //! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);
@ -65,7 +65,6 @@ use self::{
timer::{Timer, TimerSpeed}, timer::{Timer, TimerSpeed},
}; };
use crate::{ use crate::{
clock::Clocks,
gpio::OutputPin, gpio::OutputPin,
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
system::{Peripheral as PeripheralEnable, PeripheralClockControl}, system::{Peripheral as PeripheralEnable, PeripheralClockControl},
@ -85,7 +84,6 @@ pub enum LSGlobalClkSource {
pub struct Ledc<'d> { pub struct Ledc<'d> {
_instance: PeripheralRef<'d, crate::peripherals::LEDC>, _instance: PeripheralRef<'d, crate::peripherals::LEDC>,
ledc: &'d crate::peripherals::ledc::RegisterBlock, ledc: &'d crate::peripherals::ledc::RegisterBlock,
clock_control_config: &'d Clocks<'d>,
} }
#[cfg(esp32)] #[cfg(esp32)]
@ -112,21 +110,14 @@ impl Speed for LowSpeed {
impl<'d> Ledc<'d> { impl<'d> Ledc<'d> {
/// Return a new LEDC /// Return a new LEDC
pub fn new( pub fn new(_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd) -> Self {
_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd,
clock_control_config: &'d Clocks<'d>,
) -> Self {
crate::into_ref!(_instance); crate::into_ref!(_instance);
PeripheralClockControl::reset(PeripheralEnable::Ledc); PeripheralClockControl::reset(PeripheralEnable::Ledc);
PeripheralClockControl::enable(PeripheralEnable::Ledc); PeripheralClockControl::enable(PeripheralEnable::Ledc);
let ledc = unsafe { &*crate::peripherals::LEDC::ptr() }; let ledc = unsafe { &*crate::peripherals::LEDC::ptr() };
Ledc { Ledc { _instance, ledc }
_instance,
ledc,
clock_control_config,
}
} }
/// Set global slow clock source /// Set global slow clock source
@ -170,7 +161,7 @@ impl<'d> Ledc<'d> {
/// Return a new timer /// Return a new timer
pub fn get_timer<S: TimerSpeed>(&self, number: timer::Number) -> Timer<'d, S> { pub fn get_timer<S: TimerSpeed>(&self, number: timer::Number) -> Timer<'d, S> {
Timer::new(self.ledc, self.clock_control_config, number) Timer::new(self.ledc, number)
} }
/// Return a new channel /// Return a new channel

View File

@ -184,7 +184,6 @@ pub trait TimerHW<S: TimerSpeed> {
/// Timer struct /// Timer struct
pub struct Timer<'a, S: TimerSpeed> { pub struct Timer<'a, S: TimerSpeed> {
ledc: &'a crate::peripherals::ledc::RegisterBlock, ledc: &'a crate::peripherals::ledc::RegisterBlock,
clock_control_config: &'a Clocks<'a>,
number: Number, number: Number,
duty: Option<config::Duty>, duty: Option<config::Duty>,
frequency: u32, frequency: u32,
@ -256,15 +255,10 @@ where
} }
impl<'a, S: TimerSpeed> Timer<'a, S> { impl<'a, S: TimerSpeed> Timer<'a, S> {
/// Create a new intance of a timer /// Create a new instance of a timer
pub fn new( pub fn new(ledc: &'a ledc::RegisterBlock, number: Number) -> Self {
ledc: &'a ledc::RegisterBlock,
clock_control_config: &'a Clocks<'a>,
number: Number,
) -> Self {
Timer { Timer {
ledc, ledc,
clock_control_config,
number, number,
duty: None, duty: None,
frequency: 0u32, frequency: 0u32,
@ -278,9 +272,12 @@ impl<'a, S: TimerSpeed> Timer<'a, S> {
/// Timer HW implementation for LowSpeed timers /// Timer HW implementation for LowSpeed timers
impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> { impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
/// Get the current source timer frequency from the HW /// Get the current source timer frequency from the HW
fn get_freq_hw(&self) -> Option<fugit::HertzU32> { fn get_freq_hw(&self) -> Option<HertzU32> {
self.clock_source.map(|cs| match cs { self.clock_source.map(|source| match source {
LSClockSource::APBClk => self.clock_control_config.apb_clock, LSClockSource::APBClk => {
let clocks = Clocks::get();
clocks.apb_clock
}
}) })
} }
@ -322,10 +319,13 @@ impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
/// Update the timer in HW /// Update the timer in HW
fn update_hw(&self) { fn update_hw(&self) {
#[cfg(esp32)] cfg_if::cfg_if! {
let tmr = self.ledc.lstimer(self.number as usize); if #[cfg(esp32)] {
#[cfg(not(esp32))] let tmr = self.ledc.lstimer(self.number as usize);
let tmr = self.ledc.timer(self.number as usize); } else {
let tmr = self.ledc.timer(self.number as usize);
}
}
tmr.conf().modify(|_, w| w.para_up().set_bit()); tmr.conf().modify(|_, w| w.para_up().set_bit());
} }
@ -336,8 +336,11 @@ impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
impl<'a> TimerHW<HighSpeed> for Timer<'a, HighSpeed> { impl<'a> TimerHW<HighSpeed> for Timer<'a, HighSpeed> {
/// Get the current source timer frequency from the HW /// Get the current source timer frequency from the HW
fn get_freq_hw(&self) -> Option<HertzU32> { fn get_freq_hw(&self) -> Option<HertzU32> {
self.clock_source.map(|cs| match cs { self.clock_source.map(|source| match source {
HSClockSource::APBClk => self.clock_control_config.apb_clock, HSClockSource::APBClk => {
let clocks = Clocks::get();
clocks.apb_clock
}
}) })
} }

View File

@ -73,13 +73,13 @@
//! //!
//! #[entry] //! #[entry]
//! fn main() -> ! { //! fn main() -> ! {
//! let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); //! let peripherals = esp_hal::init(esp_hal::Config::default());
//! //!
//! // Set GPIO0 as an output, and set its state high initially. //! // Set GPIO0 as an output, and set its state high initially.
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let mut led = Output::new(io.pins.gpio0, Level::High); //! let mut led = Output::new(io.pins.gpio0, Level::High);
//! //!
//! let delay = Delay::new(&clocks); //! let delay = Delay::new();
//! //!
//! loop { //! loop {
//! led.toggle(); //! led.toggle();
@ -712,13 +712,13 @@ macro_rules! before_snippet {
# loop {} # loop {}
# } # }
# fn main() { # fn main() {
# let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); # let mut peripherals = esp_hal::init(esp_hal::Config::default());
"# "#
}; };
} }
use crate::{ use crate::{
clock::{ClockControl, Clocks, CpuClock}, clock::{Clocks, CpuClock},
peripherals::Peripherals, peripherals::Peripherals,
}; };
@ -733,9 +733,10 @@ pub struct Config {
/// Initialize the system. /// Initialize the system.
/// ///
/// This function sets up the CPU clock and returns the peripherals and clocks. /// This function sets up the CPU clock and returns the peripherals and clocks.
pub fn init(config: Config) -> (Peripherals, Clocks<'static>) { pub fn init(config: Config) -> Peripherals {
let peripherals = Peripherals::take(); let peripherals = Peripherals::take();
let clocks = ClockControl::new(config.cpu_clock).freeze();
(peripherals, clocks) Clocks::init(config.cpu_clock);
peripherals
} }

View File

@ -60,11 +60,11 @@
//! // initialize peripheral //! // initialize peripheral
#![cfg_attr( #![cfg_attr(
esp32h2, esp32h2,
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();" doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();"
)] )]
#![cfg_attr( #![cfg_attr(
not(esp32h2), not(esp32h2),
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();" doc = "let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap();"
)] )]
//! let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); //! let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
//! //!
@ -87,7 +87,7 @@
//! # } //! # }
//! ``` //! ```
use core::{marker::PhantomData, ops::Deref}; use core::ops::Deref;
use fugit::HertzU32; use fugit::HertzU32;
use operator::Operator; use operator::Operator;
@ -130,7 +130,7 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> {
// clocks.crypto_pwm_clock normally is 160 MHz // clocks.crypto_pwm_clock normally is 160 MHz
pub fn new( pub fn new(
peripheral: impl Peripheral<P = PWM> + 'd, peripheral: impl Peripheral<P = PWM> + 'd,
peripheral_clock: PeripheralClockConfig<'d>, peripheral_clock: PeripheralClockConfig,
) -> Self { ) -> Self {
crate::into_ref!(peripheral); crate::into_ref!(peripheral);
@ -190,13 +190,12 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> {
/// Clock configuration of the MCPWM peripheral /// Clock configuration of the MCPWM peripheral
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PeripheralClockConfig<'a> { pub struct PeripheralClockConfig {
frequency: HertzU32, frequency: HertzU32,
prescaler: u8, prescaler: u8,
phantom: PhantomData<&'a Clocks<'a>>,
} }
impl<'a> PeripheralClockConfig<'a> { impl PeripheralClockConfig {
/// Get a clock configuration with the given prescaler. /// Get a clock configuration with the given prescaler.
/// ///
/// With standard system clock configurations the input clock to the MCPWM /// With standard system clock configurations the input clock to the MCPWM
@ -204,7 +203,8 @@ impl<'a> PeripheralClockConfig<'a> {
/// ///
/// The peripheral clock frequency is calculated as: /// The peripheral clock frequency is calculated as:
/// `peripheral_clock = input_clock / (prescaler + 1)` /// `peripheral_clock = input_clock / (prescaler + 1)`
pub fn with_prescaler(clocks: &'a Clocks<'a>, prescaler: u8) -> Self { pub fn with_prescaler(prescaler: u8) -> Self {
let clocks = Clocks::get();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32)] { if #[cfg(esp32)] {
let source_clock = clocks.pwm_clock; let source_clock = clocks.pwm_clock;
@ -220,7 +220,6 @@ impl<'a> PeripheralClockConfig<'a> {
Self { Self {
frequency: source_clock / (prescaler as u32 + 1), frequency: source_clock / (prescaler as u32 + 1),
prescaler, prescaler,
phantom: PhantomData,
} }
} }
@ -238,10 +237,8 @@ impl<'a> PeripheralClockConfig<'a> {
/// Only divisors of the input clock (`160 Mhz / 1`, `160 Mhz / 2`, ..., /// Only divisors of the input clock (`160 Mhz / 1`, `160 Mhz / 2`, ...,
/// `160 Mhz / 256`) are representable exactly. Other target frequencies /// `160 Mhz / 256`) are representable exactly. Other target frequencies
/// will be rounded up to the next divisor. /// will be rounded up to the next divisor.
pub fn with_frequency( pub fn with_frequency(target_freq: HertzU32) -> Result<Self, FrequencyError> {
clocks: &'a Clocks<'a>, let clocks = Clocks::get();
target_freq: HertzU32,
) -> Result<Self, FrequencyError> {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32)] { if #[cfg(esp32)] {
let source_clock = clocks.pwm_clock; let source_clock = clocks.pwm_clock;
@ -263,7 +260,7 @@ impl<'a> PeripheralClockConfig<'a> {
return Err(FrequencyError); return Err(FrequencyError);
} }
Ok(Self::with_prescaler(clocks, prescaler as u8)) Ok(Self::with_prescaler(prescaler as u8))
} }
/// Get the peripheral clock frequency. /// Get the peripheral clock frequency.
@ -288,7 +285,7 @@ impl<'a> PeripheralClockConfig<'a> {
period: u16, period: u16,
mode: timer::PwmWorkingMode, mode: timer::PwmWorkingMode,
prescaler: u8, prescaler: u8,
) -> timer::TimerClockConfig<'a> { ) -> timer::TimerClockConfig {
timer::TimerClockConfig::with_prescaler(self, period, mode, prescaler) timer::TimerClockConfig::with_prescaler(self, period, mode, prescaler)
} }
@ -306,7 +303,7 @@ impl<'a> PeripheralClockConfig<'a> {
period: u16, period: u16,
mode: timer::PwmWorkingMode, mode: timer::PwmWorkingMode,
target_freq: HertzU32, target_freq: HertzU32,
) -> Result<timer::TimerClockConfig<'a>, FrequencyError> { ) -> Result<timer::TimerClockConfig, FrequencyError> {
timer::TimerClockConfig::with_frequency(self, period, mode, target_freq) timer::TimerClockConfig::with_frequency(self, period, mode, target_freq)
} }
} }

View File

@ -491,11 +491,11 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool>
/// true); /// true);
#[cfg_attr( #[cfg_attr(
esp32h2, esp32h2,
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();" doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();"
)] )]
#[cfg_attr( #[cfg_attr(
not(esp32h2), not(esp32h2),
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();" doc = "let clock_cfg = PeripheralClockConfig::with_frequency(32.MHz()).unwrap();"
)] )]
/// let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); /// let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);
/// ///

View File

@ -8,10 +8,7 @@ use core::marker::PhantomData;
use fugit::HertzU32; use fugit::HertzU32;
use crate::{ use crate::mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral};
clock::Clocks,
mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral},
};
/// A MCPWM timer /// A MCPWM timer
/// ///
@ -47,7 +44,7 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
/// ///
/// The hardware supports writing these settings in sync with certain timer /// The hardware supports writing these settings in sync with certain timer
/// events but this HAL does not expose these for now. /// events but this HAL does not expose these for now.
pub fn start(&mut self, timer_config: TimerClockConfig<'_>) { pub fn start(&mut self, timer_config: TimerClockConfig) {
// write prescaler and period with immediate update method // write prescaler and period with immediate update method
self.cfg0().write(|w| unsafe { self.cfg0().write(|w| unsafe {
w.prescale().bits(timer_config.prescaler); w.prescale().bits(timer_config.prescaler);
@ -115,18 +112,17 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
/// Use [`PeripheralClockConfig::timer_clock_with_prescaler`](super::PeripheralClockConfig::timer_clock_with_prescaler) or /// Use [`PeripheralClockConfig::timer_clock_with_prescaler`](super::PeripheralClockConfig::timer_clock_with_prescaler) or
/// [`PeripheralClockConfig::timer_clock_with_frequency`](super::PeripheralClockConfig::timer_clock_with_frequency) to it. /// [`PeripheralClockConfig::timer_clock_with_frequency`](super::PeripheralClockConfig::timer_clock_with_frequency) to it.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct TimerClockConfig<'a> { pub struct TimerClockConfig {
frequency: HertzU32, frequency: HertzU32,
period: u16, period: u16,
period_updating_method: PeriodUpdatingMethod, period_updating_method: PeriodUpdatingMethod,
prescaler: u8, prescaler: u8,
mode: PwmWorkingMode, mode: PwmWorkingMode,
phantom: PhantomData<&'a Clocks<'a>>,
} }
impl<'a> TimerClockConfig<'a> { impl TimerClockConfig {
pub(super) fn with_prescaler( pub(super) fn with_prescaler(
clock: &PeripheralClockConfig<'a>, clock: &PeripheralClockConfig,
period: u16, period: u16,
mode: PwmWorkingMode, mode: PwmWorkingMode,
prescaler: u8, prescaler: u8,
@ -144,12 +140,11 @@ impl<'a> TimerClockConfig<'a> {
period, period,
period_updating_method: PeriodUpdatingMethod::Immediately, period_updating_method: PeriodUpdatingMethod::Immediately,
mode, mode,
phantom: PhantomData,
} }
} }
pub(super) fn with_frequency( pub(super) fn with_frequency(
clock: &PeripheralClockConfig<'a>, clock: &PeripheralClockConfig,
period: u16, period: u16,
mode: PwmWorkingMode, mode: PwmWorkingMode,
target_freq: HertzU32, target_freq: HertzU32,
@ -178,7 +173,6 @@ impl<'a> TimerClockConfig<'a> {
period, period,
period_updating_method: PeriodUpdatingMethod::Immediately, period_updating_method: PeriodUpdatingMethod::Immediately,
mode, mode,
phantom: PhantomData,
}) })
} }

View File

@ -31,7 +31,6 @@ use peripheral::PeripheralRef;
use private::*; use private::*;
use crate::{ use crate::{
clock::Clocks,
dma::{ dma::{
dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx}, dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx},
Channel, Channel,
@ -1123,7 +1122,6 @@ where
tx_descriptors: &'static mut [DmaDescriptor], tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor], rx_descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
internal_init(&mut dma_channel, frequency)?; internal_init(&mut dma_channel, frequency)?;
@ -1217,7 +1215,6 @@ where
mut dma_channel: Channel<'d, CH, DM>, mut dma_channel: Channel<'d, CH, DM>,
descriptors: &'static mut [DmaDescriptor], descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
internal_init(&mut dma_channel, frequency)?; internal_init(&mut dma_channel, frequency)?;
@ -1306,7 +1303,6 @@ where
mut dma_channel: Channel<'d, CH, DM>, mut dma_channel: Channel<'d, CH, DM>,
descriptors: &'static mut [DmaDescriptor], descriptors: &'static mut [DmaDescriptor],
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
internal_init(&mut dma_channel, frequency)?; internal_init(&mut dma_channel, frequency)?;

View File

@ -287,8 +287,7 @@ mod peripheral_macros {
impl Peripherals { impl Peripherals {
/// Returns all the peripherals *once* /// Returns all the peripherals *once*
#[inline] #[inline]
pub fn take() -> Self { pub(crate) fn take() -> Self {
#[no_mangle] #[no_mangle]
static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false; static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false;

View File

@ -55,12 +55,11 @@
//! # use esp_hal::rmt::TxChannelConfig; //! # use esp_hal::rmt::TxChannelConfig;
//! # use esp_hal::rmt::Rmt; //! # use esp_hal::rmt::Rmt;
//! # use esp_hal::gpio::Io; //! # use esp_hal::gpio::Io;
//! # use esp_hal::clock::ClockControl;
//! # use crate::esp_hal::rmt::TxChannelCreator; //! # use crate::esp_hal::rmt::TxChannelCreator;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")] #![cfg_attr(esp32h2, doc = "let freq = 32.MHz();")]
#![cfg_attr(not(esp32h2), doc = "let freq = 80.MHz();")] #![cfg_attr(not(esp32h2), doc = "let freq = 80.MHz();")]
//! let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); //! let rmt = Rmt::new(peripherals.RMT, freq).unwrap();
//! let mut channel = rmt //! let mut channel = rmt
//! .channel0 //! .channel0
//! .configure( //! .configure(
@ -86,7 +85,6 @@ use core::marker::PhantomData;
use fugit::HertzU32; use fugit::HertzU32;
use crate::{ use crate::{
clock::Clocks,
gpio::{InputPin, OutputPin}, gpio::{InputPin, OutputPin},
interrupt::InterruptHandler, interrupt::InterruptHandler,
peripheral::Peripheral, peripheral::Peripheral,
@ -217,7 +215,6 @@ where
pub(crate) fn new_internal( pub(crate) fn new_internal(
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd, peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let me = Rmt::create(peripheral); let me = Rmt::create(peripheral);
@ -233,7 +230,7 @@ where
if #[cfg(any(esp32, esp32s2))] { if #[cfg(any(esp32, esp32s2))] {
self::chip_specific::configure_clock(); self::chip_specific::configure_clock();
} else { } else {
me.configure_clock(frequency, _clocks)?; me.configure_clock(frequency)?;
} }
} }
@ -249,7 +246,7 @@ where
} }
#[cfg(not(any(esp32, esp32s2)))] #[cfg(not(any(esp32, esp32s2)))]
fn configure_clock(&self, frequency: HertzU32, _clocks: &Clocks<'d>) -> Result<(), Error> { fn configure_clock(&self, frequency: HertzU32) -> Result<(), Error> {
let src_clock = crate::soc::constants::RMT_CLOCK_SRC_FREQ; let src_clock = crate::soc::constants::RMT_CLOCK_SRC_FREQ;
if frequency > src_clock { if frequency > src_clock {
@ -273,9 +270,8 @@ impl<'d> Rmt<'d, crate::Blocking> {
pub fn new( pub fn new(
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd, peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_internal(peripheral, frequency, _clocks) Self::new_internal(peripheral, frequency)
} }
} }
@ -292,9 +288,8 @@ impl<'d> Rmt<'d, crate::Async> {
pub fn new_async( pub fn new_async(
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd, peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
frequency: HertzU32, frequency: HertzU32,
_clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
let mut this = Self::new_internal(peripheral, frequency, _clocks)?; let mut this = Self::new_internal(peripheral, frequency)?;
this.internal_set_interrupt_handler(asynch::async_interrupt_handler); this.internal_set_interrupt_handler(asynch::async_interrupt_handler);
Ok(this) Ok(this)
} }

View File

@ -143,7 +143,6 @@ impl rand_core::RngCore for Rng {
/// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc}; /// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc};
/// # use esp_hal::gpio::Io; /// # use esp_hal::gpio::Io;
/// ///
/// let mut peripherals = Peripherals::take();
/// let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); /// let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
/// let mut buf = [0u8; 16]; /// let mut buf = [0u8; 16];
/// ///

View File

@ -36,7 +36,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap(); //! # let mut uart0 = Uart::new(peripherals.UART0, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let data = "Dummy"; //! # let data = "Dummy";
//! let d: md5::Digest = md5::compute(&data); //! let d: md5::Digest = md5::compute(&data);
//! writeln!(uart0, "{}", d); //! writeln!(uart0, "{}", d);
@ -52,7 +52,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut uart0 = Uart::new(peripherals.UART0, &clocks, io.pins.gpio1, io.pins.gpio2).unwrap(); //! # let mut uart0 = Uart::new(peripherals.UART0, io.pins.gpio1, io.pins.gpio2).unwrap();
//! # let data0 = "Dummy"; //! # let data0 = "Dummy";
//! # let data1 = "Dummy"; //! # let data1 = "Dummy";
//! # //! #

View File

@ -29,7 +29,7 @@
//! # use crate::esp_hal::prelude::_fugit_ExtU64; //! # use crate::esp_hal::prelude::_fugit_ExtU64;
//! # use crate::esp_hal::InterruptConfigurable; //! # use crate::esp_hal::InterruptConfigurable;
//! static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None)); //! static RWDT: Mutex<RefCell<Option<Rwdt>>> = Mutex::new(RefCell::new(None));
//! let mut delay = Delay::new(&clocks); //! let mut delay = Delay::new();
//! //!
//! let mut rtc = Rtc::new(peripherals.LPWR); //! let mut rtc = Rtc::new(peripherals.LPWR);
//! //!

View File

@ -15,7 +15,7 @@
//! # use esp_hal::prelude::*; //! # use esp_hal::prelude::*;
//! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); //! static mut APP_CORE_STACK: Stack<8192> = Stack::new();
//! //!
//! # let delay = Delay::new(&clocks); //! # let delay = Delay::new();
//! //!
//! let counter = Mutex::new(RefCell::new(0)); //! let counter = Mutex::new(RefCell::new(0));
//! //!

View File

@ -29,7 +29,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -26,7 +26,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -27,7 +27,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -27,7 +27,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -27,7 +27,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -29,7 +29,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -13,7 +13,7 @@
//! # use esp_hal::cpu_control::{CpuControl, Stack}; //! # use esp_hal::cpu_control::{CpuControl, Stack};
//! # use core::{cell::RefCell, ptr::addr_of_mut}; //! # use core::{cell::RefCell, ptr::addr_of_mut};
//! # use critical_section::Mutex; //! # use critical_section::Mutex;
//! # let delay = Delay::new(&clocks); //! # let delay = Delay::new();
//! static mut APP_CORE_STACK: Stack<8192> = Stack::new(); //! static mut APP_CORE_STACK: Stack<8192> = Stack::new();
//! //!
//! let counter = Mutex::new(RefCell::new(0)); //! let counter = Mutex::new(RefCell::new(0));

View File

@ -27,7 +27,7 @@
//! # use core::writeln; //! # use core::writeln;
//! # use core::fmt::Write; //! # use core::fmt::Write;
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! # let mut serial_tx = Uart::new(peripherals.UART0, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); //! # let mut serial_tx = Uart::new(peripherals.UART0, io.pins.gpio4, io.pins.gpio5).unwrap();
//! let mac_address = Efuse::read_base_mac_address(); //! let mac_address = Efuse::read_base_mac_address();
//! writeln!( //! writeln!(
//! serial_tx, //! serial_tx,

View File

@ -50,7 +50,6 @@
//! peripherals.SPI2, //! peripherals.SPI2,
//! 100.kHz(), //! 100.kHz(),
//! SpiMode::Mode0, //! SpiMode::Mode0,
//! &clocks,
//! ) //! )
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)); //! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
//! # } //! # }
@ -509,10 +508,9 @@ where
spi: impl Peripheral<P = T> + 'd, spi: impl Peripheral<P = T> + 'd,
frequency: HertzU32, frequency: HertzU32,
mode: SpiMode, mode: SpiMode,
clocks: &Clocks<'d>,
) -> Spi<'d, T, FullDuplexMode> { ) -> Spi<'d, T, FullDuplexMode> {
crate::into_ref!(spi); crate::into_ref!(spi);
Self::new_internal(spi, frequency, mode, clocks) Self::new_internal(spi, frequency, mode)
} }
/// Assign the SCK (Serial Clock) pin for the SPI instance. /// Assign the SCK (Serial Clock) pin for the SPI instance.
@ -612,7 +610,6 @@ where
spi: PeripheralRef<'d, T>, spi: PeripheralRef<'d, T>,
frequency: HertzU32, frequency: HertzU32,
mode: SpiMode, mode: SpiMode,
clocks: &Clocks<'d>,
) -> Spi<'d, T, FullDuplexMode> { ) -> Spi<'d, T, FullDuplexMode> {
spi.reset_peripheral(); spi.reset_peripheral();
spi.enable_peripheral(); spi.enable_peripheral();
@ -621,7 +618,7 @@ where
spi, spi,
_mode: PhantomData, _mode: PhantomData,
}; };
spi.spi.setup(frequency, clocks); spi.spi.setup(frequency);
spi.spi.init(); spi.spi.init();
spi.spi.set_data_mode(mode); spi.spi.set_data_mode(mode);
@ -632,8 +629,8 @@ where
/// ///
/// This method allows user to update the bus frequency for the SPI /// This method allows user to update the bus frequency for the SPI
/// communication after the instance has been created. /// communication after the instance has been created.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
self.spi.ch_bus_freq(frequency, clocks); self.spi.ch_bus_freq(frequency);
} }
} }
@ -649,10 +646,9 @@ where
spi: impl Peripheral<P = T> + 'd, spi: impl Peripheral<P = T> + 'd,
frequency: HertzU32, frequency: HertzU32,
mode: SpiMode, mode: SpiMode,
clocks: &Clocks<'d>,
) -> Spi<'d, T, HalfDuplexMode> { ) -> Spi<'d, T, HalfDuplexMode> {
crate::into_ref!(spi); crate::into_ref!(spi);
Self::new_internal(spi, frequency, mode, clocks) Self::new_internal(spi, frequency, mode)
} }
/// Assign the SCK (Serial Clock) pin for the SPI instance. /// Assign the SCK (Serial Clock) pin for the SPI instance.
@ -820,7 +816,6 @@ where
spi: PeripheralRef<'d, T>, spi: PeripheralRef<'d, T>,
frequency: HertzU32, frequency: HertzU32,
mode: SpiMode, mode: SpiMode,
clocks: &Clocks<'d>,
) -> Spi<'d, T, HalfDuplexMode> { ) -> Spi<'d, T, HalfDuplexMode> {
spi.reset_peripheral(); spi.reset_peripheral();
spi.enable_peripheral(); spi.enable_peripheral();
@ -829,7 +824,7 @@ where
spi, spi,
_mode: PhantomData, _mode: PhantomData,
}; };
spi.spi.setup(frequency, clocks); spi.spi.setup(frequency);
spi.spi.init(); spi.spi.init();
spi.spi.set_data_mode(mode); spi.spi.set_data_mode(mode);
@ -840,8 +835,8 @@ where
/// ///
/// This method allows you to update the bus frequency for the SPI /// This method allows you to update the bus frequency for the SPI
/// communication after the instance has been created. /// communication after the instance has been created.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
self.spi.ch_bus_freq(frequency, clocks); self.spi.ch_bus_freq(frequency);
} }
/// Set the bit order for the SPI instance. /// Set the bit order for the SPI instance.
@ -1127,8 +1122,8 @@ mod dma {
M: Mode, M: Mode,
{ {
/// Changes the SPI bus frequency for the DMA-enabled SPI instance. /// Changes the SPI bus frequency for the DMA-enabled SPI instance.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
self.spi.ch_bus_freq(frequency, clocks); self.spi.ch_bus_freq(frequency);
} }
} }
@ -1645,9 +1640,9 @@ mod dma {
} }
/// Changes the SPI bus frequency for the DMA-enabled SPI instance. /// Changes the SPI bus frequency for the DMA-enabled SPI instance.
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) { pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
let (mut spi_dma, tx_buf, rx_buf) = self.wait_for_idle(); let (mut spi_dma, tx_buf, rx_buf) = self.wait_for_idle();
spi_dma.change_bus_frequency(frequency, clocks); spi_dma.change_bus_frequency(frequency);
self.state = State::Idle(spi_dma, tx_buf, rx_buf); self.state = State::Idle(spi_dma, tx_buf, rx_buf);
} }
@ -2831,7 +2826,8 @@ pub trait Instance: private::Sealed {
} }
// taken from https://github.com/apache/incubator-nuttx/blob/8267a7618629838231256edfa666e44b5313348e/arch/risc-v/src/esp32c3/esp32c3_spi.c#L496 // taken from https://github.com/apache/incubator-nuttx/blob/8267a7618629838231256edfa666e44b5313348e/arch/risc-v/src/esp32c3/esp32c3_spi.c#L496
fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) { fn setup(&mut self, frequency: HertzU32) {
let clocks = Clocks::get();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32h2)] { if #[cfg(esp32h2)] {
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
@ -3033,7 +3029,7 @@ pub trait Instance: private::Sealed {
self self
} }
fn ch_bus_freq(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) { fn ch_bus_freq(&mut self, frequency: HertzU32) {
// Disable clock source // Disable clock source
#[cfg(not(any(esp32, esp32s2)))] #[cfg(not(any(esp32, esp32s2)))]
self.register_block().clk_gate().modify(|_, w| { self.register_block().clk_gate().modify(|_, w| {
@ -3046,7 +3042,7 @@ pub trait Instance: private::Sealed {
}); });
// Change clock frequency // Change clock frequency
self.setup(frequency, clocks); self.setup(frequency);
// Enable clock source // Enable clock source
#[cfg(not(any(esp32, esp32s2)))] #[cfg(not(any(esp32, esp32s2)))]

View File

@ -18,7 +18,7 @@
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup}; //! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup};
//! # //! #
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let timg0 = TimerGroup::new(peripherals.TIMG0);
//! let one_shot = OneShotTimer::new(timg0.timer0); //! let one_shot = OneShotTimer::new(timg0.timer0);
//! //!
//! one_shot.delay_millis(500); //! one_shot.delay_millis(500);
@ -30,7 +30,7 @@
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::{PeriodicTimer, timg::TimerGroup}; //! # use esp_hal::timer::{PeriodicTimer, timg::TimerGroup};
//! # //! #
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let timg0 = TimerGroup::new(peripherals.TIMG0);
//! let mut periodic = PeriodicTimer::new(timg0.timer0); //! let mut periodic = PeriodicTimer::new(timg0.timer0);
//! //!
//! periodic.start(1.secs()); //! periodic.start(1.secs());

View File

@ -129,21 +129,21 @@ impl<'d> SystemTimer<'d> {
pub fn ticks_per_second() -> u64 { pub fn ticks_per_second() -> u64 {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32s2)] { if #[cfg(esp32s2)] {
80_000_000 const MULTIPLIER: u64 = 2_000_000;
} else if #[cfg(esp32h2)] { } else if #[cfg(esp32h2)] {
// The counters and comparators are driven using `XTAL_CLK`. // The counters and comparators are driven using `XTAL_CLK`.
// The average clock frequency is fXTAL_CLK/2, which is 16 MHz. // The average clock frequency is fXTAL_CLK/2, which is 16 MHz.
// The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle. // The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle.
const MULTIPLIER: u64 = 10_000_000 / 20; const MULTIPLIER: u64 = 10_000_000 / 20;
crate::clock::xtal_freq_mhz() as u64 * MULTIPLIER
} else { } else {
// The counters and comparators are driven using `XTAL_CLK`. // The counters and comparators are driven using `XTAL_CLK`.
// The average clock frequency is fXTAL_CLK/2.5, which is 16 MHz. // The average clock frequency is fXTAL_CLK/2.5, which is 16 MHz.
// The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle. // The timer counting is incremented by 1/16 μs on each `CNT_CLK` cycle.
const MULTIPLIER: u64 = 10_000_000 / 25; const MULTIPLIER: u64 = 10_000_000 / 25;
crate::clock::xtal_freq_mhz() as u64 * MULTIPLIER
} }
} }
let xtal_freq_mhz = crate::clock::Clocks::xtal_freq().to_MHz();
xtal_freq_mhz as u64 * MULTIPLIER
} }
/// Create a new instance. /// Create a new instance.

View File

@ -28,7 +28,7 @@
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::timg::TimerGroup; //! # use esp_hal::timer::timg::TimerGroup;
//! //!
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let timg0 = TimerGroup::new(peripherals.TIMG0);
//! let timer0 = timg0.timer0; //! let timer0 = timg0.timer0;
//! //!
//! // Get the current timestamp, in microseconds: //! // Get the current timestamp, in microseconds:
@ -51,7 +51,7 @@
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::timg::TimerGroup; //! # use esp_hal::timer::timg::TimerGroup;
//! //!
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); //! let timg0 = TimerGroup::new(peripherals.TIMG0);
//! let mut wdt = timg0.wdt; //! let mut wdt = timg0.wdt;
//! //!
//! wdt.set_timeout(5_000.millis()); //! wdt.set_timeout(5_000.millis());
@ -256,7 +256,7 @@ where
DM: crate::Mode, DM: crate::Mode,
{ {
/// Construct a new instance of [`TimerGroup`] in blocking mode /// Construct a new instance of [`TimerGroup`] in blocking mode
pub fn new_inner(_timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self { pub fn new_inner(_timer_group: impl Peripheral<P = T> + 'd) -> Self {
crate::into_ref!(_timer_group); crate::into_ref!(_timer_group);
T::reset_peripheral(); T::reset_peripheral();
@ -264,6 +264,7 @@ where
T::configure_src_clk(); T::configure_src_clk();
let clocks = Clocks::get();
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(esp32h2)] { if #[cfg(esp32h2)] {
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
@ -271,7 +272,7 @@ where
} else { } else {
let apb_clk_freq = clocks.apb_clock; let apb_clk_freq = clocks.apb_clock;
} }
}; }
let timer0 = Timer::new( let timer0 = Timer::new(
Timer0 { Timer0 {
@ -303,8 +304,8 @@ where
T: TimerGroupInstance, T: TimerGroupInstance,
{ {
/// Construct a new instance of [`TimerGroup`] in blocking mode /// Construct a new instance of [`TimerGroup`] in blocking mode
pub fn new(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self { pub fn new(_timer_group: impl Peripheral<P = T> + 'd) -> Self {
Self::new_inner(timer_group, clocks) Self::new_inner(_timer_group)
} }
} }
@ -313,8 +314,8 @@ where
T: TimerGroupInstance, T: TimerGroupInstance,
{ {
/// Construct a new instance of [`TimerGroup`] in asynchronous mode /// Construct a new instance of [`TimerGroup`] in asynchronous mode
pub fn new_async(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self { pub fn new_async(_timer_group: impl Peripheral<P = T> + 'd) -> Self {
Self::new_inner(timer_group, clocks) Self::new_inner(_timer_group)
} }
} }

View File

@ -50,7 +50,6 @@
//! peripherals.TWAI0, //! peripherals.TWAI0,
//! can_tx_pin, //! can_tx_pin,
//! can_rx_pin, //! can_rx_pin,
//! &clocks,
//! TWAI_BAUDRATE, //! TWAI_BAUDRATE,
//! TwaiMode::Normal //! TwaiMode::Normal
//! ); //! );
@ -105,7 +104,6 @@
//! peripherals.TWAI0, //! peripherals.TWAI0,
//! can_tx_pin, //! can_tx_pin,
//! can_rx_pin, //! can_rx_pin,
//! &clocks,
//! TWAI_BAUDRATE, //! TWAI_BAUDRATE,
//! TwaiMode::SelfTest //! TwaiMode::SelfTest
//! ); //! );
@ -135,7 +133,6 @@ use core::marker::PhantomData;
use self::filter::{Filter, FilterType}; use self::filter::{Filter, FilterType};
use crate::{ use crate::{
clock::Clocks,
gpio::{InputPin, InputSignal, OutputPin, OutputSignal}, gpio::{InputPin, InputSignal, OutputPin, OutputSignal},
interrupt::InterruptHandler, interrupt::InterruptHandler,
peripheral::{Peripheral, PeripheralRef}, peripheral::{Peripheral, PeripheralRef},
@ -723,7 +720,6 @@ where
_peripheral: impl Peripheral<P = T> + 'd, _peripheral: impl Peripheral<P = T> + 'd,
tx_pin: impl Peripheral<P = TX> + 'd, tx_pin: impl Peripheral<P = TX> + 'd,
rx_pin: impl Peripheral<P = RX> + 'd, rx_pin: impl Peripheral<P = RX> + 'd,
clocks: &Clocks<'d>,
baud_rate: BaudRate, baud_rate: BaudRate,
no_transceiver: bool, no_transceiver: bool,
mode: TwaiMode, mode: TwaiMode,
@ -787,7 +783,7 @@ where
phantom: PhantomData, phantom: PhantomData,
}; };
cfg.set_baud_rate(baud_rate, clocks); cfg.set_baud_rate(baud_rate);
cfg cfg
} }
@ -801,11 +797,14 @@ where
/// Set the bitrate of the bus. /// Set the bitrate of the bus.
/// ///
/// Note: The timings currently assume a APB_CLK of 80MHz. /// Note: The timings currently assume a APB_CLK of 80MHz.
fn set_baud_rate(&mut self, baud_rate: BaudRate, _clocks: &Clocks<'d>) { fn set_baud_rate(&mut self, baud_rate: BaudRate) {
// TWAI is clocked from the APB_CLK according to Table 6-4 [ESP32C3 Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf) // TWAI is clocked from the APB_CLK according to Table 6-4 [ESP32C3 Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf)
// Included timings are all for 80MHz so assert that we are running at 80MHz. // Included timings are all for 80MHz so assert that we are running at 80MHz.
#[cfg(not(esp32c6))] #[cfg(not(esp32c6))]
assert!(_clocks.apb_clock == fugit::HertzU32::MHz(80)); {
let apb_clock = crate::clock::Clocks::get().apb_clock;
assert!(apb_clock == fugit::HertzU32::MHz(80));
}
// Unpack the baud rate timings and convert them to the values needed for the // Unpack the baud rate timings and convert them to the values needed for the
// register. Many of the registers have a minimum value of 1 which is // register. Many of the registers have a minimum value of 1 which is
@ -908,11 +907,10 @@ where
peripheral: impl Peripheral<P = T> + 'd, peripheral: impl Peripheral<P = T> + 'd,
tx_pin: impl Peripheral<P = TX> + 'd, tx_pin: impl Peripheral<P = TX> + 'd,
rx_pin: impl Peripheral<P = RX> + 'd, rx_pin: impl Peripheral<P = RX> + 'd,
clocks: &Clocks<'d>,
baud_rate: BaudRate, baud_rate: BaudRate,
mode: TwaiMode, mode: TwaiMode,
) -> Self { ) -> Self {
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, false, mode) Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode)
} }
/// Create a new instance of [TwaiConfiguration] meant to connect two ESP32s /// Create a new instance of [TwaiConfiguration] meant to connect two ESP32s
@ -924,11 +922,10 @@ where
peripheral: impl Peripheral<P = T> + 'd, peripheral: impl Peripheral<P = T> + 'd,
tx_pin: impl Peripheral<P = TX> + 'd, tx_pin: impl Peripheral<P = TX> + 'd,
rx_pin: impl Peripheral<P = RX> + 'd, rx_pin: impl Peripheral<P = RX> + 'd,
clocks: &Clocks<'d>,
baud_rate: BaudRate, baud_rate: BaudRate,
mode: TwaiMode, mode: TwaiMode,
) -> Self { ) -> Self {
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, true, mode) Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, true, mode)
} }
} }
@ -954,12 +951,10 @@ where
peripheral: impl Peripheral<P = T> + 'd, peripheral: impl Peripheral<P = T> + 'd,
tx_pin: impl Peripheral<P = TX> + 'd, tx_pin: impl Peripheral<P = TX> + 'd,
rx_pin: impl Peripheral<P = RX> + 'd, rx_pin: impl Peripheral<P = RX> + 'd,
clocks: &Clocks<'d>,
baud_rate: BaudRate, baud_rate: BaudRate,
mode: TwaiMode, mode: TwaiMode,
) -> Self { ) -> Self {
let mut this = let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode);
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, false, mode);
this.internal_set_interrupt_handler(T::async_handler()); this.internal_set_interrupt_handler(T::async_handler());
this this
} }
@ -973,12 +968,10 @@ where
peripheral: impl Peripheral<P = T> + 'd, peripheral: impl Peripheral<P = T> + 'd,
tx_pin: impl Peripheral<P = TX> + 'd, tx_pin: impl Peripheral<P = TX> + 'd,
rx_pin: impl Peripheral<P = RX> + 'd, rx_pin: impl Peripheral<P = RX> + 'd,
clocks: &Clocks<'d>,
baud_rate: BaudRate, baud_rate: BaudRate,
mode: TwaiMode, mode: TwaiMode,
) -> Self { ) -> Self {
let mut this = let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, true, mode);
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, true, mode);
this.internal_set_interrupt_handler(T::async_handler()); this.internal_set_interrupt_handler(T::async_handler());
this this
} }

View File

@ -29,7 +29,6 @@
//! //!
//! let mut uart1 = Uart::new( //! let mut uart1 = Uart::new(
//! peripherals.UART1, //! peripherals.UART1,
//! &clocks,
//! io.pins.gpio1, //! io.pins.gpio1,
//! io.pins.gpio2, //! io.pins.gpio2,
//! ).unwrap(); //! ).unwrap();
@ -62,7 +61,6 @@
//! # let mut uart1 = Uart::new_with_config( //! # let mut uart1 = Uart::new_with_config(
//! # peripherals.UART1, //! # peripherals.UART1,
//! # Config::default(), //! # Config::default(),
//! # &clocks,
//! # io.pins.gpio1, //! # io.pins.gpio1,
//! # io.pins.gpio2, //! # io.pins.gpio2,
//! # ).unwrap(); //! # ).unwrap();
@ -80,7 +78,6 @@
//! # let mut uart1 = Uart::new_with_config( //! # let mut uart1 = Uart::new_with_config(
//! # peripherals.UART1, //! # peripherals.UART1,
//! # Config::default(), //! # Config::default(),
//! # &clocks,
//! # io.pins.gpio1, //! # io.pins.gpio1,
//! # io.pins.gpio2, //! # io.pins.gpio2,
//! # ).unwrap(); //! # ).unwrap();
@ -105,7 +102,6 @@
//! let rx = AnyPin::new_inverted(io.pins.gpio2); //! let rx = AnyPin::new_inverted(io.pins.gpio2);
//! let mut uart1 = Uart::new( //! let mut uart1 = Uart::new(
//! peripherals.UART1, //! peripherals.UART1,
//! &clocks,
//! tx, //! tx,
//! rx, //! rx,
//! ).unwrap(); //! ).unwrap();
@ -120,10 +116,8 @@
//! //!
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); //! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! //!
//! let tx = UartTx::new(peripherals.UART0, &clocks, //! let tx = UartTx::new(peripherals.UART0, io.pins.gpio1).unwrap();
//! io.pins.gpio1).unwrap(); //! let rx = UartRx::new(peripherals.UART1, io.pins.gpio2).unwrap();
//! let rx = UartRx::new(peripherals.UART1, &clocks,
//! io.pins.gpio2).unwrap();
//! # } //! # }
//! ``` //! ```
//! //!
@ -579,10 +573,9 @@ where
/// Create a new UART TX instance in [`Blocking`] mode. /// Create a new UART TX instance in [`Blocking`] mode.
pub fn new<TX: OutputPin>( pub fn new<TX: OutputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_with_config(uart, Default::default(), clocks, tx) Self::new_with_config(uart, Default::default(), tx)
} }
/// Create a new UART TX instance with configuration options in /// Create a new UART TX instance with configuration options in
@ -590,15 +583,13 @@ where
pub fn new_with_config<TX: OutputPin>( pub fn new_with_config<TX: OutputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
crate::into_ref!(tx); crate::into_ref!(tx);
tx.set_to_push_pull_output(Internal); tx.set_to_push_pull_output(Internal);
tx.connect_peripheral_to_output(T::tx_signal(), Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal);
let (uart_tx, _) = let (uart_tx, _) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split();
Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split();
Ok(uart_tx) Ok(uart_tx)
} }
@ -787,10 +778,9 @@ where
/// Create a new UART RX instance in [`Blocking`] mode. /// Create a new UART RX instance in [`Blocking`] mode.
pub fn new<RX: InputPin>( pub fn new<RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_with_config(uart, Default::default(), clocks, rx) Self::new_with_config(uart, Default::default(), rx)
} }
/// Create a new UART RX instance with configuration options in /// Create a new UART RX instance with configuration options in
@ -798,15 +788,13 @@ where
pub fn new_with_config<RX: InputPin>( pub fn new_with_config<RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
crate::into_ref!(rx); crate::into_ref!(rx);
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
let (_, uart_rx) = let (_, uart_rx) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split();
Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split();
Ok(uart_rx) Ok(uart_rx)
} }
@ -821,7 +809,6 @@ where
pub fn new_with_config<TX: OutputPin, RX: InputPin>( pub fn new_with_config<TX: OutputPin, RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
@ -832,13 +819,12 @@ where
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
Self::new_with_config_inner(uart, config, clocks) Self::new_with_config_inner(uart, config)
} }
/// Create a new UART instance with defaults in [`Blocking`] mode. /// Create a new UART instance with defaults in [`Blocking`] mode.
pub fn new<TX: OutputPin, RX: InputPin>( pub fn new<TX: OutputPin, RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
@ -849,14 +835,13 @@ where
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
Self::new_inner(uart, clocks) Self::new_inner(uart)
} }
/// Create a new UART instance with defaults in [`Blocking`] mode. /// Create a new UART instance with defaults in [`Blocking`] mode.
/// Verify that the default pins (DefaultTxPin and DefaultRxPin) are used. /// Verify that the default pins (DefaultTxPin and DefaultRxPin) are used.
pub fn new_with_default_pins( pub fn new_with_default_pins(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: &mut DefaultTxPin, tx: &mut DefaultTxPin,
rx: &mut DefaultRxPin, rx: &mut DefaultRxPin,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
@ -865,7 +850,7 @@ where
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
Self::new_inner(uart, clocks) Self::new_inner(uart)
} }
} }
@ -877,7 +862,6 @@ where
pub(crate) fn new_with_config_inner( pub(crate) fn new_with_config_inner(
_uart: impl Peripheral<P = T> + 'd, _uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::init(); Self::init();
@ -893,7 +877,7 @@ where
.rx .rx
.set_rx_fifo_full_threshold(config.rx_fifo_full_threshold)?; .set_rx_fifo_full_threshold(config.rx_fifo_full_threshold)?;
serial.rx.set_rx_timeout(config.rx_timeout)?; serial.rx.set_rx_timeout(config.rx_timeout)?;
serial.change_baud_internal(config.baudrate, config.clock_source, clocks); serial.change_baud_internal(config.baudrate, config.clock_source);
serial.change_data_bits(config.data_bits); serial.change_data_bits(config.data_bits);
serial.change_parity(config.parity); serial.change_parity(config.parity);
serial.change_stop_bits(config.stop_bits); serial.change_stop_bits(config.stop_bits);
@ -925,8 +909,8 @@ where
} }
} }
fn new_inner(uart: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Result<Self, Error> { fn new_inner(uart: impl Peripheral<P = T> + 'd) -> Result<Self, Error> {
Self::new_with_config_inner(uart, Default::default(), clocks) Self::new_with_config_inner(uart, Default::default())
} }
/// Configure CTS pin /// Configure CTS pin
@ -1157,7 +1141,8 @@ where
} }
#[cfg(any(esp32c2, esp32c3, esp32s3))] #[cfg(any(esp32c2, esp32c3, esp32s3))]
fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) {
let clocks = Clocks::get();
let clk = match clock_source { let clk = match clock_source {
ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::Apb => clocks.apb_clock.to_Hz(),
ClockSource::Xtal => clocks.xtal_clock.to_Hz(), ClockSource::Xtal => clocks.xtal_clock.to_Hz(),
@ -1194,7 +1179,8 @@ where
} }
#[cfg(any(esp32c6, esp32h2))] #[cfg(any(esp32c6, esp32h2))]
fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) {
let clocks = Clocks::get();
let clk = match clock_source { let clk = match clock_source {
ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::Apb => clocks.apb_clock.to_Hz(),
ClockSource::Xtal => clocks.xtal_clock.to_Hz(), ClockSource::Xtal => clocks.xtal_clock.to_Hz(),
@ -1265,7 +1251,8 @@ where
} }
#[cfg(any(esp32, esp32s2))] #[cfg(any(esp32, esp32s2))]
fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { fn change_baud_internal(&self, baudrate: u32, clock_source: ClockSource) {
let clocks = Clocks::get();
let clk = match clock_source { let clk = match clock_source {
ClockSource::Apb => clocks.apb_clock.to_Hz(), ClockSource::Apb => clocks.apb_clock.to_Hz(),
ClockSource::RefTick => REF_TICK.to_Hz(), /* ESP32(/-S2) TRM, section 3.2.4.2 ClockSource::RefTick => REF_TICK.to_Hz(), /* ESP32(/-S2) TRM, section 3.2.4.2
@ -1304,8 +1291,8 @@ where
} }
/// Modify UART baud rate and reset TX/RX fifo. /// Modify UART baud rate and reset TX/RX fifo.
pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) { pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource) {
self.change_baud_internal(baudrate, clock_source, clocks); self.change_baud_internal(baudrate, clock_source);
self.txfifo_reset(); self.txfifo_reset();
self.rxfifo_reset(); self.rxfifo_reset();
} }
@ -2146,7 +2133,6 @@ mod asynch {
pub fn new_async_with_config<TX: OutputPin, RX: InputPin>( pub fn new_async_with_config<TX: OutputPin, RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
@ -2157,7 +2143,7 @@ mod asynch {
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
let mut this = Self::new_with_config_inner(uart, config, clocks)?; let mut this = Self::new_with_config_inner(uart, config)?;
this.inner_set_interrupt_handler(match T::uart_number() { this.inner_set_interrupt_handler(match T::uart_number() {
#[cfg(uart0)] #[cfg(uart0)]
@ -2175,21 +2161,19 @@ mod asynch {
/// Create a new UART instance with defaults in [`Async`] mode. /// Create a new UART instance with defaults in [`Async`] mode.
pub fn new_async<TX: OutputPin, RX: InputPin>( pub fn new_async<TX: OutputPin, RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_async_with_config(uart, Default::default(), clocks, tx, rx) Self::new_async_with_config(uart, Default::default(), tx, rx)
} }
/// Create a new UART instance with defaults in [`Async`] mode. /// Create a new UART instance with defaults in [`Async`] mode.
pub fn new_async_with_default_pins( pub fn new_async_with_default_pins(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: DefaultTxPin, tx: DefaultTxPin,
rx: DefaultRxPin, rx: DefaultRxPin,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_async_with_config(uart, Default::default(), clocks, tx, rx) Self::new_async_with_config(uart, Default::default(), tx, rx)
} }
} }
@ -2221,10 +2205,9 @@ mod asynch {
/// Create a new UART TX instance in [`Async`] mode. /// Create a new UART TX instance in [`Async`] mode.
pub fn new_async<TX: OutputPin>( pub fn new_async<TX: OutputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_async_with_config(uart, Default::default(), clocks, tx) Self::new_async_with_config(uart, Default::default(), tx)
} }
/// Create a new UART TX instance with configuration options in /// Create a new UART TX instance with configuration options in
@ -2232,14 +2215,13 @@ mod asynch {
pub fn new_async_with_config<TX: OutputPin>( pub fn new_async_with_config<TX: OutputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
tx: impl Peripheral<P = TX> + 'd, tx: impl Peripheral<P = TX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
crate::into_ref!(tx); crate::into_ref!(tx);
tx.set_to_push_pull_output(Internal); tx.set_to_push_pull_output(Internal);
tx.connect_peripheral_to_output(T::tx_signal(), Internal); tx.connect_peripheral_to_output(T::tx_signal(), Internal);
let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config, clocks)?; let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config)?;
uart.inner_set_interrupt_handler(match T::uart_number() { uart.inner_set_interrupt_handler(match T::uart_number() {
#[cfg(uart0)] #[cfg(uart0)]
@ -2308,10 +2290,9 @@ mod asynch {
/// Create a new UART RX instance in [`Async`] mode. /// Create a new UART RX instance in [`Async`] mode.
pub fn new_async<RX: InputPin>( pub fn new_async<RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
clocks: &Clocks<'d>,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::new_async_with_config(uart, Default::default(), clocks, rx) Self::new_async_with_config(uart, Default::default(), rx)
} }
/// Create a new UART RX instance with configuration options in /// Create a new UART RX instance with configuration options in
@ -2319,14 +2300,13 @@ mod asynch {
pub fn new_async_with_config<RX: InputPin>( pub fn new_async_with_config<RX: InputPin>(
uart: impl Peripheral<P = T> + 'd, uart: impl Peripheral<P = T> + 'd,
config: Config, config: Config,
clocks: &Clocks<'d>,
rx: impl Peripheral<P = RX> + 'd, rx: impl Peripheral<P = RX> + 'd,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
crate::into_ref!(rx); crate::into_ref!(rx);
rx.set_to_input(Internal); rx.set_to_input(Internal);
rx.connect_input_to_peripheral(T::rx_signal(), Internal); rx.connect_input_to_peripheral(T::rx_signal(), Internal);
let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config, clocks)?; let mut uart = Uart::<'d, T, Async>::new_with_config_inner(uart, config)?;
uart.inner_set_interrupt_handler(match T::uart_number() { uart.inner_set_interrupt_handler(match T::uart_number() {
#[cfg(uart0)] #[cfg(uart0)]

View File

@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed ### Removed
- Removed the `clocks` parameter from `esp_wifi::initialize` (#1999)
## 0.8.0 - 2024-08-29 ## 0.8.0 - 2024-08-29
### Added ### Added

41
esp-wifi/MIGRATING-0.9.md Normal file
View File

@ -0,0 +1,41 @@
Migration Guide from 0.9.x to vNext
====================================
Initialsation
-------------
You no longer have to set up clocks and pass them to `esp_wifi::initialize`.
```diff
use esp_hal::{
- clock::ClockControl,
- peripherals::Peripherals,
prelude::*,
- system::SystemControl,
};
use esp_wifi::{
initialize,
// ...
};
#[entry]
fn main() -> ! {
- let peripherals = Peripherals::take();
- let system = SystemControl::new(peripherals.SYSTEM);
- let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
+ let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0);
let init = initialize(
EspWifiInitFor::Wifi,
timg0.timer0,
Rng::new(peripherals.RNG),
peripherals.RADIO_CLK,
- &clocks,
)
.unwrap();
// ...
}
```

View File

@ -293,13 +293,12 @@ impl EspWifiTimerSource for TimeBase {
/// use esp_hal::{rng::Rng, timg::TimerGroup}; /// use esp_hal::{rng::Rng, timg::TimerGroup};
/// use esp_wifi::EspWifiInitFor; /// use esp_wifi::EspWifiInitFor;
/// ///
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); /// let timg0 = TimerGroup::new(peripherals.TIMG0);
/// let init = esp_wifi::initialize( /// let init = esp_wifi::initialize(
/// EspWifiInitFor::Wifi, /// EspWifiInitFor::Wifi,
/// timg0.timer0, /// timg0.timer0,
/// Rng::new(peripherals.RNG), /// Rng::new(peripherals.RNG),
/// peripherals.RADIO_CLK, /// peripherals.RADIO_CLK,
/// &clocks,
/// ) /// )
/// .unwrap(); /// .unwrap();
/// # } /// # }
@ -309,10 +308,10 @@ pub fn initialize(
timer: impl EspWifiTimerSource, timer: impl EspWifiTimerSource,
rng: hal::rng::Rng, rng: hal::rng::Rng,
radio_clocks: hal::peripherals::RADIO_CLK, radio_clocks: hal::peripherals::RADIO_CLK,
clocks: &Clocks,
) -> Result<EspWifiInitialization, InitializationError> { ) -> Result<EspWifiInitialization, InitializationError> {
// A minimum clock of 80MHz is required to operate WiFi module. // A minimum clock of 80MHz is required to operate WiFi module.
const MIN_CLOCK: u32 = 80; const MIN_CLOCK: u32 = 80;
let clocks = Clocks::get();
if clocks.cpu_clock < MegahertzU32::MHz(MIN_CLOCK) { if clocks.cpu_clock < MegahertzU32::MHz(MIN_CLOCK) {
return Err(InitializationError::WrongClockConfig); return Err(InitializationError::WrongClockConfig);
} }

View File

@ -27,7 +27,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
cfg_if::cfg_if! { cfg_if::cfg_if! {
@ -45,7 +45,7 @@ fn main() -> ! {
let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB); let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();

View File

@ -23,7 +23,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
cfg_if::cfg_if! { cfg_if::cfg_if! {
@ -49,7 +49,7 @@ fn main() -> ! {
adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB); adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config); let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
let pin_mv = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap(); let pin_mv = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();

View File

@ -19,13 +19,13 @@ use nb::block;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut serial1 = Uart::new(peripherals.UART1, &clocks, io.pins.gpio4, io.pins.gpio5).unwrap(); let mut serial1 = Uart::new(peripherals.UART1, io.pins.gpio4, io.pins.gpio5).unwrap();
let delay = Delay::new(&clocks); let delay = Delay::new();
println!("Start"); println!("Start");
loop { loop {

View File

@ -17,13 +17,13 @@ use esp_hal::{
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
// Set GPIO0 as an output, and set its state high initially. // Set GPIO0 as an output, and set its state high initially.
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut led = Output::new(io.pins.gpio0, Level::High); let mut led = Output::new(io.pins.gpio0, Level::High);
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
led.toggle(); led.toggle();

View File

@ -20,7 +20,7 @@ use esp_hal::{
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -39,7 +39,7 @@ fn main() -> ! {
let mut pins = [led1, led2, led3]; let mut pins = [led1, led2, led3];
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
toggle_pins(&mut pins, &button); toggle_pins(&mut pins, &button);

View File

@ -23,7 +23,7 @@ use esp_hal::{analog::dac::Dac, delay::Delay, gpio::Io, prelude::*};
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -41,7 +41,7 @@ fn main() -> ! {
let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin); let mut dac1 = Dac::new(peripherals.DAC1, dac1_pin);
let mut dac2 = Dac::new(peripherals.DAC2, dac2_pin); let mut dac2 = Dac::new(peripherals.DAC2, dac2_pin);
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut voltage_dac1: u8 = 200; let mut voltage_dac1: u8 = 200;
let mut voltage_dac2: u8 = 255; let mut voltage_dac2: u8 = 255;

View File

@ -18,7 +18,7 @@ static DA: Mutex<RefCell<Option<DebugAssist>>> = Mutex::new(RefCell::new(None));
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG);
da.set_interrupt_handler(interrupt_handler); da.set_interrupt_handler(interrupt_handler);

View File

@ -62,10 +62,10 @@ fn init_heap(psram: impl esp_hal::peripheral::Peripheral<P = esp_hal::peripheral
fn main() -> ! { fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info); esp_println::logger::init_logger(log::LevelFilter::Info);
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
init_heap(peripherals.PSRAM); init_heap(peripherals.PSRAM);
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64); let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64);
let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64); let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64);

View File

@ -21,9 +21,9 @@ const DATA_SIZE: usize = 1024 * 10;
fn main() -> ! { fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info); esp_println::logger::init_logger(log::LevelFilter::Info);
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE); let (tx_buffer, tx_descriptors, mut rx_buffer, rx_descriptors) = dma_buffers!(DATA_SIZE);

View File

@ -25,12 +25,12 @@ async fn run() {
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
esp_println::logger::init_logger_from_env(); esp_println::logger::init_logger_from_env();
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
esp_println::println!("Init!"); esp_println::println!("Init!");
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
spawner.spawn(run()).ok(); spawner.spawn(run()).ok();

View File

@ -24,20 +24,14 @@ use lis3dh_async::{Lis3dh, Range, SlaveAddr};
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let i2c0 = I2C::new_async( let i2c0 = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz());
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio5,
400.kHz(),
&clocks,
);
let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap();
lis3dh.set_range(Range::G8).await.unwrap(); lis3dh.set_range(Range::G8).await.unwrap();

View File

@ -1,4 +1,4 @@
//! Embassy "async" vesrion of ead calibration data from BMP180 sensor //! Embassy "async" version of ead calibration data from BMP180 sensor
//! //!
//! This example dumps the calibration data from a BMP180 sensor by reading by reading //! This example dumps the calibration data from a BMP180 sensor by reading by reading
//! with the direct I2C API and the embedded-hal-async I2C API. //! with the direct I2C API and the embedded-hal-async I2C API.
@ -24,20 +24,14 @@ use esp_hal::{gpio::Io, i2c::I2C, prelude::*, timer::timg::TimerGroup};
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut i2c = I2C::new_async( let mut i2c = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz());
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio5,
400.kHz(),
&clocks,
);
loop { loop {
let mut data = [0u8; 22]; let mut data = [0u8; 22];

View File

@ -1,4 +1,4 @@
//! This shows how to continously receive data via I2S. //! This shows how to continuously receive data via I2S.
//! //!
//! Without an additional I2S source device you can connect 3V3 or GND to DIN //! Without an additional I2S source device you can connect 3V3 or GND to DIN
//! to read 0 or 0xFF or connect DIN to WS to read two different values. //! to read 0 or 0xFF or connect DIN to WS to read two different values.
@ -32,10 +32,10 @@ use esp_println::println;
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
println!("Init!"); println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -55,7 +55,6 @@ async fn main(_spawner: Spawner) {
dma_channel.configure_for_async(false, DmaPriority::Priority0), dma_channel.configure_for_async(false, DmaPriority::Priority0),
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
&clocks,
); );
#[cfg(not(feature = "esp32"))] #[cfg(not(feature = "esp32"))]

View File

@ -1,4 +1,4 @@
//! This shows how to transmit data continously via I2S. //! This shows how to transmit data continuously via I2S.
//! //!
//! Without an additional I2S sink device you can inspect the BCLK, WS //! Without an additional I2S sink device you can inspect the BCLK, WS
//! and DOUT with a logic analyzer. //! and DOUT with a logic analyzer.
@ -54,10 +54,10 @@ const SINE: [i16; 64] = [
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
println!("Init!"); println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -77,7 +77,6 @@ async fn main(_spawner: Spawner) {
dma_channel.configure_for_async(false, DmaPriority::Priority0), dma_channel.configure_for_async(false, DmaPriority::Priority0),
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
&clocks,
); );
let i2s_tx = i2s let i2s_tx = i2s

View File

@ -51,14 +51,14 @@ async fn control_led(
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
let timer0: ErasedTimer = timg0.timer0.into(); let timer0: ErasedTimer = timg0.timer0.into();
let timer1: ErasedTimer = timg0.timer1.into(); let timer1: ErasedTimer = timg0.timer1.into();
esp_hal_embassy::init(&clocks, [timer0, timer1]); esp_hal_embassy::init([timer0, timer1]);
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);

View File

@ -71,16 +71,16 @@ async fn enable_disable_led(control: &'static Signal<CriticalSectionRawMutex, bo
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
let timer0: ErasedTimer = timg0.timer0.into(); let timer0: ErasedTimer = timg0.timer0.into();
let timer1: ErasedTimer = timg0.timer1.into(); let timer1: ErasedTimer = timg0.timer1.into();
esp_hal_embassy::init(&clocks, [timer0, timer1]); esp_hal_embassy::init([timer0, timer1]);
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL); let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);

View File

@ -71,11 +71,11 @@ async fn main(low_prio_spawner: Spawner) {
esp_println::logger::init_logger_from_env(); esp_println::logger::init_logger_from_env();
println!("Init!"); println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
let timer0: ErasedTimer = timg0.timer0.into(); let timer0: ErasedTimer = timg0.timer0.into();
cfg_if::cfg_if! { cfg_if::cfg_if! {
@ -84,12 +84,12 @@ async fn main(low_prio_spawner: Spawner) {
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
let timer1: ErasedTimer = systimer.alarm0.into(); let timer1: ErasedTimer = systimer.alarm0.into();
} else { } else {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1);
let timer1: ErasedTimer = timg1.timer0.into(); let timer1: ErasedTimer = timg1.timer0.into();
} }
} }
esp_hal_embassy::init(&clocks, [timer0, timer1]); esp_hal_embassy::init([timer0, timer1]);
static EXECUTOR: StaticCell<InterruptExecutor<2>> = StaticCell::new(); static EXECUTOR: StaticCell<InterruptExecutor<2>> = StaticCell::new();
let executor = InterruptExecutor::new(sw_ints.software_interrupt2); let executor = InterruptExecutor::new(sw_ints.software_interrupt2);

View File

@ -26,10 +26,10 @@ use esp_println::println;
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0); esp_hal_embassy::init(systimer.alarm0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -45,7 +45,6 @@ async fn main(_spawner: Spawner) {
dma_channel.configure_for_async(false, DmaPriority::Priority0), dma_channel.configure_for_async(false, DmaPriority::Priority0),
rx_descriptors, rx_descriptors,
1.MHz(), 1.MHz(),
&clocks,
) )
.unwrap(); .unwrap();

View File

@ -37,10 +37,10 @@ use esp_println::println;
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0); esp_hal_embassy::init(systimer.alarm0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -58,7 +58,6 @@ async fn main(_spawner: Spawner) {
dma_channel.configure_for_async(false, DmaPriority::Priority0), dma_channel.configure_for_async(false, DmaPriority::Priority0),
tx_descriptors, tx_descriptors,
1.MHz(), 1.MHz(),
&clocks,
) )
.unwrap(); .unwrap();

View File

@ -39,10 +39,10 @@ async fn signal_task(mut pin: Output<'static, GpioPin<5>>) {
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
println!("Init!"); println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -54,7 +54,7 @@ async fn main(spawner: Spawner) {
} }
}; };
let rmt = Rmt::new_async(peripherals.RMT, freq, &clocks).unwrap(); let rmt = Rmt::new_async(peripherals.RMT, freq).unwrap();
let rx_config = RxChannelConfig { let rx_config = RxChannelConfig {
clk_divider: 255, clk_divider: 255,
idle_threshold: 10000, idle_threshold: 10000,

View File

@ -25,10 +25,10 @@ use esp_println::println;
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
println!("Init!"); println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -40,7 +40,7 @@ async fn main(_spawner: Spawner) {
} }
}; };
let rmt = Rmt::new_async(peripherals.RMT, freq, &clocks).unwrap(); let rmt = Rmt::new_async(peripherals.RMT, freq).unwrap();
let mut channel = rmt let mut channel = rmt
.channel0 .channel0

View File

@ -78,10 +78,10 @@ async fn reader(
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -104,8 +104,7 @@ async fn main(spawner: Spawner) {
let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16); let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16);
let mut uart0 = let mut uart0 = Uart::new_async_with_config(peripherals.UART0, config, tx_pin, rx_pin).unwrap();
Uart::new_async_with_config(peripherals.UART0, config, &clocks, tx_pin, rx_pin).unwrap();
uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None));
let (tx, rx) = uart0.split(); let (tx, rx) = uart0.split();

View File

@ -33,10 +33,10 @@ use esp_hal::{
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let sclk = io.pins.gpio0; let sclk = io.pins.gpio0;
@ -58,7 +58,7 @@ async fn main(_spawner: Spawner) {
let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();
let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap(); let dma_rx_buf = DmaRxBuf::new(rx_descriptors, rx_buffer).unwrap();
let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks) let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
.with_dma(dma_channel.configure_for_async(false, DmaPriority::Priority0)) .with_dma(dma_channel.configure_for_async(false, DmaPriority::Priority0))
.with_buffers(dma_tx_buf, dma_rx_buf); .with_buffers(dma_tx_buf, dma_rx_buf);

View File

@ -27,10 +27,10 @@ use esp_println::println;
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::logger::init_logger_from_env(); esp_println::logger::init_logger_from_env();
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut rtc = Rtc::new(peripherals.LPWR); let mut rtc = Rtc::new(peripherals.LPWR);

View File

@ -82,10 +82,10 @@ async fn transmitter(
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -103,7 +103,6 @@ async fn main(spawner: Spawner) {
peripherals.TWAI0, peripherals.TWAI0,
can_tx_pin, can_tx_pin,
can_rx_pin, can_rx_pin,
&clocks,
CAN_BAUDRATE, CAN_BAUDRATE,
TwaiMode::Normal, TwaiMode::Normal,
); );

View File

@ -32,10 +32,10 @@ use esp_hal::{
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -63,10 +63,10 @@ async fn reader(
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(spawner: Spawner) { async fn main(spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split(); let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split();

View File

@ -19,10 +19,10 @@ use esp_hal::{
#[esp_hal_embassy::main] #[esp_hal_embassy::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
esp_println::println!("Init!"); esp_println::println!("Init!");
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
esp_hal_embassy::init(&clocks, timg0.timer0); esp_hal_embassy::init(timg0.timer0);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -24,7 +24,7 @@ use fugit::ExtU32;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let syst = SystemTimer::new(peripherals.SYSTIMER); let syst = SystemTimer::new(peripherals.SYSTIMER);
let syst_alarms = syst.split::<Periodic>(); let syst_alarms = syst.split::<Periodic>();

View File

@ -22,7 +22,7 @@ use esp_hal::{
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let mut led = io.pins.gpio1; let mut led = io.pins.gpio1;

View File

@ -28,9 +28,9 @@ static TIMER0: Mutex<RefCell<Option<Timer<Timer0<TIMG0>, esp_hal::Blocking>>>> =
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0);
let timer0 = timg0.timer0; let timer0 = timg0.timer0;
timer0.set_interrupt_handler(tg0_t0_level); timer0.set_interrupt_handler(tg0_t0_level);
@ -55,7 +55,7 @@ fn main() -> ! {
TIMER0.borrow_ref_mut(cs).replace(timer0); TIMER0.borrow_ref_mut(cs).replace(timer0);
}); });
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
delay.delay_millis(500u32); delay.delay_millis(500u32);

View File

@ -34,7 +34,7 @@ static BUTTON: Mutex<RefCell<Option<Input<GpioPin<BUTTON_PIN>>>>> = Mutex::new(R
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
// Set GPIO2 as an output, and set its state high initially. // Set GPIO2 as an output, and set its state high initially.
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -57,7 +57,7 @@ fn main() -> ! {
}); });
led.set_high(); led.set_high();
let delay = Delay::new(&clocks); let delay = Delay::new();
loop { loop {
led.toggle(); led.toggle();

View File

@ -36,7 +36,7 @@ use smart_leds::{
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -65,14 +65,14 @@ fn main() -> ! {
} }
} }
let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); let rmt = Rmt::new(peripherals.RMT, freq).unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations
let rmt_buffer = smartLedBuffer!(1); let rmt_buffer = smartLedBuffer!(1);
let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer, &clocks); let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer);
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut color = Hsv { let mut color = Hsv {
hue: 0, hue: 0,

View File

@ -19,9 +19,9 @@ use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -43,7 +43,7 @@ fn main() -> ! {
} }
let mut uart0 = let mut uart0 =
Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); Uart::new_with_default_pins(peripherals.UART0, &mut tx_pin, &mut rx_pin).unwrap();
loop { loop {
writeln!(uart0, "Hello world!").unwrap(); writeln!(uart0, "Hello world!").unwrap();

View File

@ -73,7 +73,7 @@ type HmacSha256 = HmacSw<Sha256>;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let mut rng = Rng::new(peripherals.RNG); let mut rng = Rng::new(peripherals.RNG);

View File

@ -17,19 +17,13 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Create a new peripheral object with the described wiring and standard // Create a new peripheral object with the described wiring and standard
// I2C clock speed: // I2C clock speed:
let mut i2c = I2C::new( let mut i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz());
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio5,
100.kHz(),
&clocks,
);
loop { loop {
let mut data = [0u8; 22]; let mut data = [0u8; 22];

View File

@ -27,20 +27,14 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Create a new peripheral object with the described wiring // Create a new peripheral object with the described wiring
// and standard I2C clock speed // and standard I2C clock speed
let i2c = I2C::new( let i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz());
peripherals.I2C0,
io.pins.gpio4,
io.pins.gpio5,
100.kHz(),
&clocks,
);
// Initialize display // Initialize display
let interface = I2CDisplayInterface::new(i2c); let interface = I2CDisplayInterface::new(i2c);

View File

@ -28,7 +28,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -52,7 +52,6 @@ fn main() -> ! {
dma_channel.configure(false, DmaPriority::Priority0), dma_channel.configure(false, DmaPriority::Priority0),
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
&clocks,
); );
#[cfg(not(feature = "esp32"))] #[cfg(not(feature = "esp32"))]

View File

@ -49,7 +49,7 @@ const SINE: [i16; 64] = [
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -69,7 +69,6 @@ fn main() -> ! {
dma_channel.configure(false, DmaPriority::Priority0), dma_channel.configure(false, DmaPriority::Priority0),
tx_descriptors, tx_descriptors,
rx_descriptors, rx_descriptors,
&clocks,
); );
let mut i2s_tx = i2s let mut i2s_tx = i2s

View File

@ -10,7 +10,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut peripherals = esp_hal::init(esp_hal::Config::default());
let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK);
ieee802154.set_config(Config { ieee802154.set_config(Config {

View File

@ -10,7 +10,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (mut peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let mut peripherals = esp_hal::init(esp_hal::Config::default());
let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK);
ieee802154.set_config(Config { ieee802154.set_config(Config {

View File

@ -19,9 +19,9 @@ use ieee802154::mac::{
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK);

View File

@ -19,9 +19,9 @@ use ieee802154::mac::{
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK); let mut ieee802154 = Ieee802154::new(peripherals.IEEE802154, &mut peripherals.RADIO_CLK);

View File

@ -14,7 +14,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (mut peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let mut peripherals = esp_hal::init(esp_hal::Config::default());
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -28,7 +28,7 @@ fn main() -> ! {
} }
let mut uart0 = let mut uart0 =
Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); Uart::new_with_default_pins(peripherals.UART0, &mut tx_pin, &mut rx_pin).unwrap();
// read two characters which get parsed as the channel // read two characters which get parsed as the channel
let mut cnt = 0; let mut cnt = 0;

View File

@ -42,7 +42,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -77,20 +77,19 @@ fn main() -> ! {
rx_descriptors, rx_descriptors,
cam_data_pins, cam_data_pins,
20u32.MHz(), 20u32.MHz(),
&clocks,
) )
.with_master_clock(cam_xclk) .with_master_clock(cam_xclk)
.with_pixel_clock(cam_pclk) .with_pixel_clock(cam_pclk)
.with_ctrl_pins(cam_vsync, cam_href); .with_ctrl_pins(cam_vsync, cam_href);
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut buffer = rx_buffer; let mut buffer = rx_buffer;
buffer.fill(0u8); buffer.fill(0u8);
delay.delay_millis(500u32); delay.delay_millis(500u32);
let i2c = I2C::new(peripherals.I2C0, cam_siod, cam_sioc, 100u32.kHz(), &clocks); let i2c = I2C::new(peripherals.I2C0, cam_siod, cam_sioc, 100u32.kHz());
let mut sccb = Sccb::new(i2c); let mut sccb = Sccb::new(i2c);

View File

@ -37,7 +37,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -54,7 +54,7 @@ fn main() -> ! {
let channel = channel.configure(false, DmaPriority::Priority0); let channel = channel.configure(false, DmaPriority::Priority0);
let delay = Delay::new(&clocks); let delay = Delay::new();
let mut backlight = Output::new(lcd_backlight, Level::Low); let mut backlight = Output::new(lcd_backlight, Level::Low);
let mut reset = Output::new(lcd_reset, Level::Low); let mut reset = Output::new(lcd_reset, Level::Low);
@ -78,7 +78,6 @@ fn main() -> ! {
tx_pins, tx_pins,
20.MHz(), 20.MHz(),
Config::default(), Config::default(),
&clocks,
) )
.with_ctrl_pins(lcd_rs, lcd_wr); .with_ctrl_pins(lcd_rs, lcd_wr);

View File

@ -24,12 +24,12 @@ use esp_hal::{
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let led = io.pins.gpio0; let led = io.pins.gpio0;
let mut ledc = Ledc::new(peripherals.LEDC, &clocks); let mut ledc = Ledc::new(peripherals.LEDC);
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);

View File

@ -23,7 +23,7 @@ use esp_println::{print, println};
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
// configure GPIO 1 as LP output pin // configure GPIO 1 as LP output pin
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -25,7 +25,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

View File

@ -28,7 +28,7 @@ use esp_println::println;
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
@ -37,7 +37,6 @@ fn main() -> ! {
let mut uart1 = Uart::new_with_config( let mut uart1 = Uart::new_with_config(
peripherals.UART1, peripherals.UART1,
Config::default(), Config::default(),
&clocks,
io.pins.gpio6, io.pins.gpio6,
io.pins.gpio7, io.pins.gpio7,
) )

View File

@ -18,7 +18,7 @@ use esp_hal::{
#[entry] #[entry]
fn main() -> ! { 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 io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
let pin = io.pins.gpio0; let pin = io.pins.gpio0;
@ -32,7 +32,7 @@ fn main() -> ! {
} }
} }
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, freq).unwrap(); let clock_cfg = PeripheralClockConfig::with_frequency(freq).unwrap();
let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);

View File

@ -23,9 +23,9 @@ static mut APP_CORE_STACK: Stack<8192> = Stack::new();
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default()); let peripherals = esp_hal::init(esp_hal::Config::default());
let delay = Delay::new(&clocks); let delay = Delay::new();
let counter = Mutex::new(RefCell::new(0u32)); let counter = Mutex::new(RefCell::new(0u32));

Some files were not shown because too many files have changed in this diff Show More