mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-28 04:40:52 +00:00
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:
parent
7688504289
commit
99bf346898
@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed the `clocks` parameter from `esp_hal_embassy::init`. (#1999)
|
||||
|
||||
## 0.3.0 - 2024-08-29
|
||||
|
||||
### Added
|
||||
|
30
esp-hal-embassy/MIGRATING-0.3.md
Normal file
30
esp-hal-embassy/MIGRATING-0.3.md
Normal 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);
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
@ -38,10 +38,7 @@ mod fmt;
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
use esp_hal::timer::systimer::Alarm;
|
||||
use esp_hal::{
|
||||
clock::Clocks,
|
||||
timer::{timg::Timer as TimgTimer, ErasedTimer},
|
||||
};
|
||||
use esp_hal::timer::{timg::Timer as TimgTimer, ErasedTimer};
|
||||
pub use macros::main;
|
||||
|
||||
#[cfg(feature = "executors")]
|
||||
@ -158,12 +155,12 @@ impl_array!(4);
|
||||
#[doc = esp_hal::before_snippet!()]
|
||||
/// use esp_hal::timg::TimerGroup;
|
||||
///
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
/// esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
/// esp_hal_embassy::init(timg0.timer0);
|
||||
///
|
||||
/// // ... now you can spawn embassy tasks or use `Timer::after` etc.
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn init(clocks: &Clocks, time_driver: impl TimerCollection) {
|
||||
EmbassyTimer::init(clocks, time_driver.timers())
|
||||
pub fn init(time_driver: impl TimerCollection) {
|
||||
EmbassyTimer::init(time_driver.timers())
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ use core::cell::{Cell, RefCell};
|
||||
use critical_section::Mutex;
|
||||
use embassy_time_driver::{AlarmHandle, Driver};
|
||||
use esp_hal::{
|
||||
clock::Clocks,
|
||||
interrupt::{InterruptHandler, Priority},
|
||||
prelude::*,
|
||||
time::current_time,
|
||||
@ -45,7 +44,7 @@ embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTime
|
||||
});
|
||||
|
||||
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 {
|
||||
panic!(
|
||||
"Maximum of {} timers can be used.",
|
||||
|
@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed the `clocks` parameter from `SmartLedsAdapter::new` (#1999)
|
||||
|
||||
## 0.13.0 - 2024-08-29
|
||||
|
||||
## 0.12.0 - 2024-07-15
|
||||
|
@ -12,10 +12,10 @@
|
||||
//!
|
||||
//! ```rust,ignore
|
||||
//! 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 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
|
||||
@ -89,7 +89,6 @@ where
|
||||
channel: C,
|
||||
pin: impl Peripheral<P = O> + 'd,
|
||||
rmt_buffer: [u32; BUFFER_SIZE],
|
||||
clocks: &Clocks,
|
||||
) -> SmartLedsAdapter<TX, BUFFER_SIZE>
|
||||
where
|
||||
O: OutputPin + 'd,
|
||||
@ -107,6 +106,7 @@ where
|
||||
let channel = channel.configure(pin, config).unwrap();
|
||||
|
||||
// Assume the RMT peripheral is set up to use the APB clock
|
||||
let clocks = Clocks::get();
|
||||
let src_clock = clocks.apb_clock.to_MHz();
|
||||
|
||||
Self {
|
||||
|
@ -10,10 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
|
||||
- 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
|
||||
|
||||
- `Delay::new()` is now a `const` function (#1999)
|
||||
|
||||
### Fixed
|
||||
|
||||
- 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 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 `Peripherals::take`. Use `esp_hal::init` to obtain `Peripherals` (#1999)
|
||||
|
||||
## [0.20.1] - 2024-08-30
|
||||
|
||||
|
@ -139,6 +139,7 @@ defmt = [
|
||||
"esp32h2?/defmt",
|
||||
"esp32s2?/defmt",
|
||||
"esp32s3?/defmt",
|
||||
"fugit/defmt",
|
||||
]
|
||||
|
||||
#! ### PSRAM Feature Flags
|
||||
|
@ -30,7 +30,7 @@ Instead of manually grabbing peripherals and setting up clocks, you should now c
|
||||
- let peripherals = Peripherals::take();
|
||||
- let system = SystemControl::new(peripherals.SYSTEM);
|
||||
- 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());
|
||||
|
||||
// ...
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
//! );
|
||||
//! let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
|
||||
//!
|
||||
//! let mut delay = Delay::new(&clocks);
|
||||
//! let mut delay = Delay::new();
|
||||
//!
|
||||
//! loop {
|
||||
//! let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut pin)).unwrap();
|
||||
|
@ -27,7 +27,7 @@
|
||||
#![cfg_attr(esp32s2, doc = "let dac1_pin = io.pins.gpio17;")]
|
||||
//! 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;
|
||||
//!
|
||||
|
@ -48,14 +48,14 @@
|
||||
//! # }
|
||||
//! # fn main() {
|
||||
//! // 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();
|
||||
//! config.cpu_clock = CpuClock::max();
|
||||
//! config
|
||||
//! });
|
||||
//!
|
||||
//! // Initialize with custom clock frequency
|
||||
//! // let (peripherals, clocks) = esp_hal::init({
|
||||
//! // let peripherals = esp_hal::init({
|
||||
//! // let mut config = esp_hal::Config::default();
|
||||
#![cfg_attr(
|
||||
not(any(esp32c2, esp32h2)),
|
||||
@ -67,15 +67,11 @@
|
||||
//! // });
|
||||
//! //
|
||||
//! // 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;
|
||||
#[cfg(esp32c2)]
|
||||
use portable_atomic::{AtomicU32, Ordering};
|
||||
|
||||
#[cfg(any(esp32, esp32c2))]
|
||||
use crate::rtc_cntl::RtcClock;
|
||||
@ -275,38 +271,11 @@ impl Clock for ApbClock {
|
||||
}
|
||||
}
|
||||
|
||||
/// Frozen clock frequencies
|
||||
///
|
||||
/// The instantiation of this type indicates that the clock configuration can no
|
||||
/// longer be changed.
|
||||
pub struct Clocks<'a> {
|
||||
_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 {
|
||||
/// Clock frequencies.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
#[non_exhaustive]
|
||||
pub struct Clocks {
|
||||
/// CPU clock frequency
|
||||
pub cpu_clock: HertzU32,
|
||||
|
||||
@ -341,56 +310,53 @@ pub struct RawClocks {
|
||||
pub pll_96m_clock: HertzU32,
|
||||
}
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32c2)] {
|
||||
static XTAL_FREQ_MHZ: AtomicU32 = AtomicU32::new(40);
|
||||
static mut ACTIVE_CLOCKS: Option<Clocks> = None;
|
||||
|
||||
pub(crate) fn xtal_freq_mhz() -> u32 {
|
||||
XTAL_FREQ_MHZ.load(Ordering::Relaxed)
|
||||
}
|
||||
} else if #[cfg(esp32h2)] {
|
||||
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)
|
||||
impl Clocks {
|
||||
pub(crate) fn init(cpu_clock_speed: CpuClock) {
|
||||
critical_section::with(|_| {
|
||||
unsafe { ACTIVE_CLOCKS = Some(Self::configure(cpu_clock_speed)) };
|
||||
})
|
||||
}
|
||||
|
||||
/// Applies the clock configuration and returns a Clocks struct that
|
||||
/// signifies that the clocks are frozen, and contains the frequencies
|
||||
/// used. After this function is called, the clocks can not change
|
||||
pub fn freeze(self) -> Clocks<'static> {
|
||||
Clocks::from_raw_clocks(self.desired_rates)
|
||||
fn try_get() -> Option<&'static Clocks> {
|
||||
unsafe {
|
||||
// Safety: ACTIVE_CLOCKS is only set in `init` and never modified after that.
|
||||
ACTIVE_CLOCKS.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)]
|
||||
impl ClockControl {
|
||||
/// Configure the CPU clock speed.
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
if RtcClock::estimate_xtal_frequency() > 33 {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
} else {
|
||||
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() {
|
||||
let pll_freq = match cpu_clock_speed {
|
||||
@ -405,31 +371,32 @@ impl ClockControl {
|
||||
clocks_ll::set_cpu_freq(cpu_clock_speed);
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: HertzU32::MHz(xtal_freq.mhz()),
|
||||
i2c_clock: HertzU32::MHz(80),
|
||||
// The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock
|
||||
// while simultaneously being fixed at 160 MHz.
|
||||
// Testing showed 160 MHz to be correct for current clock configurations.
|
||||
pwm_clock: HertzU32::MHz(160),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: HertzU32::MHz(xtal_freq.mhz()),
|
||||
i2c_clock: HertzU32::MHz(80),
|
||||
// The docs are unclear here. pwm_clock seems to be tied to clocks.apb_clock
|
||||
// while simultaneously being fixed at 160 MHz.
|
||||
// Testing showed 160 MHz to be correct for current clock configurations.
|
||||
pwm_clock: HertzU32::MHz(160),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32c2)]
|
||||
impl ClockControl {
|
||||
/// Configure the CPU clock speed.
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let xtal_freq = if RtcClock::estimate_xtal_frequency() > 33 {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
if RtcClock::estimate_xtal_frequency() > 33 {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
} else {
|
||||
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;
|
||||
if cpu_clock_speed != CpuClock::default() {
|
||||
@ -450,21 +417,23 @@ impl ClockControl {
|
||||
apb_freq = ApbClock::ApbFreq40MHz;
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32c3)]
|
||||
impl ClockControl {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
}
|
||||
|
||||
/// Configure the CPU clock speed.
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let xtal_freq = XtalClock::RtcXtalFreq40M;
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
|
||||
let xtal_freq = Self::measure_xtal_frequency();
|
||||
|
||||
let apb_freq;
|
||||
if cpu_clock_speed != CpuClock::default() {
|
||||
@ -484,21 +453,23 @@ impl ClockControl {
|
||||
apb_freq = ApbClock::ApbFreq80MHz;
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32c6)]
|
||||
impl ClockControl {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
}
|
||||
|
||||
/// Configure the CPU clock speed.
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let xtal_freq = XtalClock::RtcXtalFreq40M;
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
|
||||
let xtal_freq = Self::measure_xtal_frequency();
|
||||
|
||||
let apb_freq;
|
||||
if cpu_clock_speed != CpuClock::default() {
|
||||
@ -518,22 +489,24 @@ impl ClockControl {
|
||||
apb_freq = ApbClock::ApbFreq80MHz;
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
crypto_clock: HertzU32::MHz(160),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
crypto_clock: HertzU32::MHz(160),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32h2)]
|
||||
impl ClockControl {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
XtalClock::RtcXtalFreq32M
|
||||
}
|
||||
|
||||
/// Configure the CPU clock speed.
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> ClockControl {
|
||||
let xtal_freq = XtalClock::RtcXtalFreq32M;
|
||||
pub(crate) fn configure(cpu_clock_speed: CpuClock) -> Self {
|
||||
let xtal_freq = Self::measure_xtal_frequency();
|
||||
|
||||
let apb_freq;
|
||||
if cpu_clock_speed != CpuClock::default() {
|
||||
@ -553,52 +526,58 @@ impl ClockControl {
|
||||
apb_freq = ApbClock::ApbFreq32MHz;
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
pll_48m_clock: HertzU32::MHz(48),
|
||||
crypto_clock: HertzU32::MHz(96),
|
||||
pll_96m_clock: HertzU32::MHz(96),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: apb_freq.frequency(),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
pll_48m_clock: HertzU32::MHz(48),
|
||||
crypto_clock: HertzU32::MHz(96),
|
||||
pll_96m_clock: HertzU32::MHz(96),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32s2)]
|
||||
impl ClockControl {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
clocks_ll::set_cpu_clock(cpu_clock_speed);
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: HertzU32::MHz(40),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(esp32s3)]
|
||||
impl ClockControl {
|
||||
impl Clocks {
|
||||
fn measure_xtal_frequency() -> XtalClock {
|
||||
XtalClock::RtcXtalFreq40M
|
||||
}
|
||||
|
||||
/// 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() {
|
||||
clocks_ll::set_cpu_clock(cpu_clock_speed);
|
||||
}
|
||||
|
||||
ClockControl {
|
||||
desired_rates: RawClocks {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: HertzU32::MHz(40),
|
||||
crypto_pwm_clock: HertzU32::MHz(160),
|
||||
},
|
||||
Self {
|
||||
cpu_clock: cpu_clock_speed.frequency(),
|
||||
apb_clock: HertzU32::MHz(80),
|
||||
xtal_clock: xtal_freq.frequency(),
|
||||
crypto_pwm_clock: HertzU32::MHz(160),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! # use esp_hal::delay::Delay;
|
||||
//! # use embedded_hal::delay::DelayNs;
|
||||
//! let mut delay = Delay::new(&clocks);
|
||||
//! let mut delay = Delay::new();
|
||||
//!
|
||||
//! delay.delay_ms(1000 as u32);
|
||||
//! # }
|
||||
@ -35,13 +35,11 @@
|
||||
|
||||
pub use fugit::MicrosDurationU64;
|
||||
|
||||
use crate::clock::Clocks;
|
||||
|
||||
/// Delay driver
|
||||
///
|
||||
/// Uses the `SYSTIMER` peripheral internally for RISC-V devices, and the
|
||||
/// built-in Xtensa timer for Xtensa devices.
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct Delay;
|
||||
|
||||
@ -71,8 +69,7 @@ impl embedded_hal::delay::DelayNs for Delay {
|
||||
|
||||
impl Delay {
|
||||
/// Creates a new `Delay` instance.
|
||||
// Do not remove the argument, it makes sure that the clocks are initialized.
|
||||
pub fn new(_clocks: &Clocks<'_>) -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,6 @@
|
||||
//! peripherals.SPI2,
|
||||
//! 100.kHz(),
|
||||
//! SpiMode::Mode0,
|
||||
//! &clocks
|
||||
//! )
|
||||
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
|
||||
//! .with_dma(dma_channel.configure(
|
||||
|
@ -42,7 +42,6 @@
|
||||
//! io.pins.gpio1,
|
||||
//! io.pins.gpio2,
|
||||
//! 100.kHz(),
|
||||
//! &clocks,
|
||||
//! );
|
||||
//!
|
||||
//! loop {
|
||||
@ -303,7 +302,6 @@ where
|
||||
sda: impl Peripheral<P = SDA> + 'd,
|
||||
scl: impl Peripheral<P = SCL> + 'd,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
timeout: Option<u32>,
|
||||
) -> Self {
|
||||
crate::into_ref!(i2c, sda, scl);
|
||||
@ -355,7 +353,7 @@ where
|
||||
crate::private::Internal,
|
||||
);
|
||||
|
||||
i2c.peripheral.setup(frequency, clocks, timeout);
|
||||
i2c.peripheral.setup(frequency, timeout);
|
||||
i2c
|
||||
}
|
||||
|
||||
@ -379,9 +377,8 @@ where
|
||||
sda: impl Peripheral<P = SDA> + 'd,
|
||||
scl: impl Peripheral<P = SCL> + 'd,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> 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.
|
||||
@ -392,10 +389,9 @@ where
|
||||
sda: impl Peripheral<P = SDA> + 'd,
|
||||
scl: impl Peripheral<P = SCL> + 'd,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
timeout: Option<u32>,
|
||||
) -> 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,
|
||||
scl: impl Peripheral<P = SCL> + 'd,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> 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.
|
||||
@ -435,10 +430,9 @@ where
|
||||
sda: impl Peripheral<P = SDA> + 'd,
|
||||
scl: impl Peripheral<P = SCL> + 'd,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
timeout: Option<u32>,
|
||||
) -> 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 {
|
||||
0 => asynch::i2c0_handler,
|
||||
@ -1011,7 +1005,7 @@ pub trait Instance: crate::private::Sealed {
|
||||
|
||||
/// Configures the I2C peripheral with the specified frequency, clocks, and
|
||||
/// 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 {
|
||||
// Clear register
|
||||
w.bits(0)
|
||||
@ -1043,6 +1037,7 @@ pub trait Instance: crate::private::Sealed {
|
||||
self.set_filter(Some(7), Some(7));
|
||||
|
||||
// Configure frequency
|
||||
let clocks = Clocks::get();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32)] {
|
||||
self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout);
|
||||
|
@ -54,7 +54,6 @@
|
||||
//! ),
|
||||
//! tx_descriptors,
|
||||
//! rx_descriptors,
|
||||
//! &clocks,
|
||||
//! );
|
||||
#![cfg_attr(not(esp32), doc = "let i2s = i2s.with_mclk(io.pins.gpio0);")]
|
||||
//! let mut i2s_rx = i2s.i2s_rx
|
||||
@ -88,7 +87,6 @@ use private::*;
|
||||
#[cfg(any(esp32, esp32s3))]
|
||||
use crate::dma::I2s1Peripheral;
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
dma::{
|
||||
dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx},
|
||||
Channel,
|
||||
@ -350,7 +348,6 @@ where
|
||||
mut channel: Channel<'d, CH, DmaMode>,
|
||||
tx_descriptors: &'static mut [DmaDescriptor],
|
||||
rx_descriptors: &'static mut [DmaDescriptor],
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Self {
|
||||
// on ESP32-C3 / ESP32-S3 and later RX and TX are independent and
|
||||
// could be configured totally independently but for now handle all
|
||||
@ -359,12 +356,7 @@ where
|
||||
channel.tx.init_channel();
|
||||
PeripheralClockControl::reset(I::get_peripheral());
|
||||
PeripheralClockControl::enable(I::get_peripheral());
|
||||
I::set_clock(calculate_clock(
|
||||
sample_rate,
|
||||
2,
|
||||
data_format.channel_bits(),
|
||||
clocks,
|
||||
));
|
||||
I::set_clock(calculate_clock(sample_rate, 2, data_format.channel_bits()));
|
||||
I::configure(&standard, &data_format);
|
||||
I::set_master();
|
||||
I::update();
|
||||
@ -457,7 +449,6 @@ where
|
||||
channel: Channel<'d, CH, DmaMode>,
|
||||
tx_descriptors: &'static mut [DmaDescriptor],
|
||||
rx_descriptors: &'static mut [DmaDescriptor],
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Self
|
||||
where
|
||||
I: I2s0Instance,
|
||||
@ -472,7 +463,6 @@ where
|
||||
channel,
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
clocks,
|
||||
)
|
||||
}
|
||||
|
||||
@ -488,7 +478,6 @@ where
|
||||
channel: Channel<'d, CH, DmaMode>,
|
||||
tx_descriptors: &'static mut [DmaDescriptor],
|
||||
rx_descriptors: &'static mut [DmaDescriptor],
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Self
|
||||
where
|
||||
I: I2s1Instance,
|
||||
@ -502,7 +491,6 @@ where
|
||||
channel,
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
clocks,
|
||||
)
|
||||
}
|
||||
|
||||
@ -901,7 +889,6 @@ mod private {
|
||||
#[cfg(any(esp32, esp32s3))]
|
||||
use crate::peripherals::{i2s1::RegisterBlock, I2S1};
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
dma::{ChannelRx, ChannelTx, DmaChannel, DmaDescriptor, DmaPeripheral},
|
||||
gpio::{InputPin, InputSignal, OutputPin, OutputSignal},
|
||||
interrupt::InterruptHandler,
|
||||
@ -2114,7 +2101,6 @@ mod private {
|
||||
sample_rate: impl Into<fugit::HertzU32>,
|
||||
channels: u8,
|
||||
data_bits: u8,
|
||||
_clocks: &Clocks<'_>,
|
||||
) -> I2sClockDividers {
|
||||
// this loosely corresponds to `i2s_std_calculate_clock` and
|
||||
// `i2s_ll_tx_set_mclk` in esp-idf
|
||||
|
@ -55,7 +55,6 @@
|
||||
//! rx_descriptors,
|
||||
//! data_pins,
|
||||
//! 20u32.MHz(),
|
||||
//! &clocks
|
||||
//! )
|
||||
//! // Remove this for slave mode.
|
||||
//! .with_master_clock(mclk_pin)
|
||||
@ -146,10 +145,10 @@ where
|
||||
descriptors: &'static mut [DmaDescriptor],
|
||||
_pins: P,
|
||||
frequency: HertzU32,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Self {
|
||||
let lcd_cam = cam.lcd_cam;
|
||||
|
||||
let clocks = Clocks::get();
|
||||
let (i, divider) = calculate_clkm(
|
||||
frequency.to_Hz() as _,
|
||||
&[
|
||||
|
@ -50,7 +50,6 @@
|
||||
//! tx_pins,
|
||||
//! 20.MHz(),
|
||||
//! Config::default(),
|
||||
//! &clocks,
|
||||
//! )
|
||||
//! .with_ctrl_pins(io.pins.gpio0, io.pins.gpio47);
|
||||
//!
|
||||
@ -113,16 +112,15 @@ where
|
||||
mut pins: P,
|
||||
frequency: HertzU32,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Self {
|
||||
let is_2byte_mode = size_of::<P::Word>() == 2;
|
||||
|
||||
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
|
||||
// the LCD_PCLK divider must be at least 2. To make up for this the user
|
||||
// provided frequency is doubled to match.
|
||||
|
||||
let (i, divider) = calculate_clkm(
|
||||
(frequency.to_Hz() * 2) as _,
|
||||
&[
|
||||
|
@ -33,7 +33,7 @@
|
||||
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
//! # 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);
|
||||
//!
|
||||
//! let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);
|
||||
@ -65,7 +65,6 @@ use self::{
|
||||
timer::{Timer, TimerSpeed},
|
||||
};
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
gpio::OutputPin,
|
||||
peripheral::{Peripheral, PeripheralRef},
|
||||
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
|
||||
@ -85,7 +84,6 @@ pub enum LSGlobalClkSource {
|
||||
pub struct Ledc<'d> {
|
||||
_instance: PeripheralRef<'d, crate::peripherals::LEDC>,
|
||||
ledc: &'d crate::peripherals::ledc::RegisterBlock,
|
||||
clock_control_config: &'d Clocks<'d>,
|
||||
}
|
||||
|
||||
#[cfg(esp32)]
|
||||
@ -112,21 +110,14 @@ impl Speed for LowSpeed {
|
||||
|
||||
impl<'d> Ledc<'d> {
|
||||
/// Return a new LEDC
|
||||
pub fn new(
|
||||
_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd,
|
||||
clock_control_config: &'d Clocks<'d>,
|
||||
) -> Self {
|
||||
pub fn new(_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd) -> Self {
|
||||
crate::into_ref!(_instance);
|
||||
|
||||
PeripheralClockControl::reset(PeripheralEnable::Ledc);
|
||||
PeripheralClockControl::enable(PeripheralEnable::Ledc);
|
||||
|
||||
let ledc = unsafe { &*crate::peripherals::LEDC::ptr() };
|
||||
Ledc {
|
||||
_instance,
|
||||
ledc,
|
||||
clock_control_config,
|
||||
}
|
||||
Ledc { _instance, ledc }
|
||||
}
|
||||
|
||||
/// Set global slow clock source
|
||||
@ -170,7 +161,7 @@ impl<'d> Ledc<'d> {
|
||||
|
||||
/// Return a new timer
|
||||
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
|
||||
|
@ -184,7 +184,6 @@ pub trait TimerHW<S: TimerSpeed> {
|
||||
/// Timer struct
|
||||
pub struct Timer<'a, S: TimerSpeed> {
|
||||
ledc: &'a crate::peripherals::ledc::RegisterBlock,
|
||||
clock_control_config: &'a Clocks<'a>,
|
||||
number: Number,
|
||||
duty: Option<config::Duty>,
|
||||
frequency: u32,
|
||||
@ -256,15 +255,10 @@ where
|
||||
}
|
||||
|
||||
impl<'a, S: TimerSpeed> Timer<'a, S> {
|
||||
/// Create a new intance of a timer
|
||||
pub fn new(
|
||||
ledc: &'a ledc::RegisterBlock,
|
||||
clock_control_config: &'a Clocks<'a>,
|
||||
number: Number,
|
||||
) -> Self {
|
||||
/// Create a new instance of a timer
|
||||
pub fn new(ledc: &'a ledc::RegisterBlock, number: Number) -> Self {
|
||||
Timer {
|
||||
ledc,
|
||||
clock_control_config,
|
||||
number,
|
||||
duty: None,
|
||||
frequency: 0u32,
|
||||
@ -278,9 +272,12 @@ impl<'a, S: TimerSpeed> Timer<'a, S> {
|
||||
/// Timer HW implementation for LowSpeed timers
|
||||
impl<'a> TimerHW<LowSpeed> for Timer<'a, LowSpeed> {
|
||||
/// Get the current source timer frequency from the HW
|
||||
fn get_freq_hw(&self) -> Option<fugit::HertzU32> {
|
||||
self.clock_source.map(|cs| match cs {
|
||||
LSClockSource::APBClk => self.clock_control_config.apb_clock,
|
||||
fn get_freq_hw(&self) -> Option<HertzU32> {
|
||||
self.clock_source.map(|source| match source {
|
||||
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
|
||||
fn update_hw(&self) {
|
||||
#[cfg(esp32)]
|
||||
let tmr = self.ledc.lstimer(self.number as usize);
|
||||
#[cfg(not(esp32))]
|
||||
let tmr = self.ledc.timer(self.number as usize);
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32)] {
|
||||
let tmr = self.ledc.lstimer(self.number as usize);
|
||||
} else {
|
||||
let tmr = self.ledc.timer(self.number as usize);
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
/// Get the current source timer frequency from the HW
|
||||
fn get_freq_hw(&self) -> Option<HertzU32> {
|
||||
self.clock_source.map(|cs| match cs {
|
||||
HSClockSource::APBClk => self.clock_control_config.apb_clock,
|
||||
self.clock_source.map(|source| match source {
|
||||
HSClockSource::APBClk => {
|
||||
let clocks = Clocks::get();
|
||||
clocks.apb_clock
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,13 @@
|
||||
//!
|
||||
//! #[entry]
|
||||
//! 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.
|
||||
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
//! let mut led = Output::new(io.pins.gpio0, Level::High);
|
||||
//!
|
||||
//! let delay = Delay::new(&clocks);
|
||||
//! let delay = Delay::new();
|
||||
//!
|
||||
//! loop {
|
||||
//! led.toggle();
|
||||
@ -712,13 +712,13 @@ macro_rules! before_snippet {
|
||||
# loop {}
|
||||
# }
|
||||
# fn main() {
|
||||
# let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
# let mut peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
"#
|
||||
};
|
||||
}
|
||||
|
||||
use crate::{
|
||||
clock::{ClockControl, Clocks, CpuClock},
|
||||
clock::{Clocks, CpuClock},
|
||||
peripherals::Peripherals,
|
||||
};
|
||||
|
||||
@ -733,9 +733,10 @@ pub struct Config {
|
||||
/// Initialize the system.
|
||||
///
|
||||
/// 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 clocks = ClockControl::new(config.cpu_clock).freeze();
|
||||
|
||||
(peripherals, clocks)
|
||||
Clocks::init(config.cpu_clock);
|
||||
|
||||
peripherals
|
||||
}
|
||||
|
@ -60,11 +60,11 @@
|
||||
//! // initialize peripheral
|
||||
#![cfg_attr(
|
||||
esp32h2,
|
||||
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();"
|
||||
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();"
|
||||
)]
|
||||
#![cfg_attr(
|
||||
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);
|
||||
//!
|
||||
@ -87,7 +87,7 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
use core::{marker::PhantomData, ops::Deref};
|
||||
use core::ops::Deref;
|
||||
|
||||
use fugit::HertzU32;
|
||||
use operator::Operator;
|
||||
@ -130,7 +130,7 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> {
|
||||
// clocks.crypto_pwm_clock normally is 160 MHz
|
||||
pub fn new(
|
||||
peripheral: impl Peripheral<P = PWM> + 'd,
|
||||
peripheral_clock: PeripheralClockConfig<'d>,
|
||||
peripheral_clock: PeripheralClockConfig,
|
||||
) -> Self {
|
||||
crate::into_ref!(peripheral);
|
||||
|
||||
@ -190,13 +190,12 @@ impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> {
|
||||
|
||||
/// Clock configuration of the MCPWM peripheral
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct PeripheralClockConfig<'a> {
|
||||
pub struct PeripheralClockConfig {
|
||||
frequency: HertzU32,
|
||||
prescaler: u8,
|
||||
phantom: PhantomData<&'a Clocks<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> PeripheralClockConfig<'a> {
|
||||
impl PeripheralClockConfig {
|
||||
/// Get a clock configuration with the given prescaler.
|
||||
///
|
||||
/// 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:
|
||||
/// `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! {
|
||||
if #[cfg(esp32)] {
|
||||
let source_clock = clocks.pwm_clock;
|
||||
@ -220,7 +220,6 @@ impl<'a> PeripheralClockConfig<'a> {
|
||||
Self {
|
||||
frequency: source_clock / (prescaler as u32 + 1),
|
||||
prescaler,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,10 +237,8 @@ impl<'a> PeripheralClockConfig<'a> {
|
||||
/// Only divisors of the input clock (`160 Mhz / 1`, `160 Mhz / 2`, ...,
|
||||
/// `160 Mhz / 256`) are representable exactly. Other target frequencies
|
||||
/// will be rounded up to the next divisor.
|
||||
pub fn with_frequency(
|
||||
clocks: &'a Clocks<'a>,
|
||||
target_freq: HertzU32,
|
||||
) -> Result<Self, FrequencyError> {
|
||||
pub fn with_frequency(target_freq: HertzU32) -> Result<Self, FrequencyError> {
|
||||
let clocks = Clocks::get();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32)] {
|
||||
let source_clock = clocks.pwm_clock;
|
||||
@ -263,7 +260,7 @@ impl<'a> PeripheralClockConfig<'a> {
|
||||
return Err(FrequencyError);
|
||||
}
|
||||
|
||||
Ok(Self::with_prescaler(clocks, prescaler as u8))
|
||||
Ok(Self::with_prescaler(prescaler as u8))
|
||||
}
|
||||
|
||||
/// Get the peripheral clock frequency.
|
||||
@ -288,7 +285,7 @@ impl<'a> PeripheralClockConfig<'a> {
|
||||
period: u16,
|
||||
mode: timer::PwmWorkingMode,
|
||||
prescaler: u8,
|
||||
) -> timer::TimerClockConfig<'a> {
|
||||
) -> timer::TimerClockConfig {
|
||||
timer::TimerClockConfig::with_prescaler(self, period, mode, prescaler)
|
||||
}
|
||||
|
||||
@ -306,7 +303,7 @@ impl<'a> PeripheralClockConfig<'a> {
|
||||
period: u16,
|
||||
mode: timer::PwmWorkingMode,
|
||||
target_freq: HertzU32,
|
||||
) -> Result<timer::TimerClockConfig<'a>, FrequencyError> {
|
||||
) -> Result<timer::TimerClockConfig, FrequencyError> {
|
||||
timer::TimerClockConfig::with_frequency(self, period, mode, target_freq)
|
||||
}
|
||||
}
|
||||
|
@ -491,11 +491,11 @@ impl<'d, Pin: OutputPin, PWM: PwmPeripheral, const OP: u8, const IS_A: bool>
|
||||
/// true);
|
||||
#[cfg_attr(
|
||||
esp32h2,
|
||||
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();"
|
||||
doc = "let clock_cfg = PeripheralClockConfig::with_frequency(40.MHz()).unwrap();"
|
||||
)]
|
||||
#[cfg_attr(
|
||||
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);
|
||||
///
|
||||
|
@ -8,10 +8,7 @@ use core::marker::PhantomData;
|
||||
|
||||
use fugit::HertzU32;
|
||||
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral},
|
||||
};
|
||||
use crate::mcpwm::{FrequencyError, PeripheralClockConfig, PwmPeripheral};
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
self.cfg0().write(|w| unsafe {
|
||||
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
|
||||
/// [`PeripheralClockConfig::timer_clock_with_frequency`](super::PeripheralClockConfig::timer_clock_with_frequency) to it.
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct TimerClockConfig<'a> {
|
||||
pub struct TimerClockConfig {
|
||||
frequency: HertzU32,
|
||||
period: u16,
|
||||
period_updating_method: PeriodUpdatingMethod,
|
||||
prescaler: u8,
|
||||
mode: PwmWorkingMode,
|
||||
phantom: PhantomData<&'a Clocks<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> TimerClockConfig<'a> {
|
||||
impl TimerClockConfig {
|
||||
pub(super) fn with_prescaler(
|
||||
clock: &PeripheralClockConfig<'a>,
|
||||
clock: &PeripheralClockConfig,
|
||||
period: u16,
|
||||
mode: PwmWorkingMode,
|
||||
prescaler: u8,
|
||||
@ -144,12 +140,11 @@ impl<'a> TimerClockConfig<'a> {
|
||||
period,
|
||||
period_updating_method: PeriodUpdatingMethod::Immediately,
|
||||
mode,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn with_frequency(
|
||||
clock: &PeripheralClockConfig<'a>,
|
||||
clock: &PeripheralClockConfig,
|
||||
period: u16,
|
||||
mode: PwmWorkingMode,
|
||||
target_freq: HertzU32,
|
||||
@ -178,7 +173,6 @@ impl<'a> TimerClockConfig<'a> {
|
||||
period,
|
||||
period_updating_method: PeriodUpdatingMethod::Immediately,
|
||||
mode,
|
||||
phantom: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@ use peripheral::PeripheralRef;
|
||||
use private::*;
|
||||
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
dma::{
|
||||
dma_private::{DmaSupport, DmaSupportRx, DmaSupportTx},
|
||||
Channel,
|
||||
@ -1123,7 +1122,6 @@ where
|
||||
tx_descriptors: &'static mut [DmaDescriptor],
|
||||
rx_descriptors: &'static mut [DmaDescriptor],
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> Result<Self, Error> {
|
||||
internal_init(&mut dma_channel, frequency)?;
|
||||
|
||||
@ -1217,7 +1215,6 @@ where
|
||||
mut dma_channel: Channel<'d, CH, DM>,
|
||||
descriptors: &'static mut [DmaDescriptor],
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> Result<Self, Error> {
|
||||
internal_init(&mut dma_channel, frequency)?;
|
||||
|
||||
@ -1306,7 +1303,6 @@ where
|
||||
mut dma_channel: Channel<'d, CH, DM>,
|
||||
descriptors: &'static mut [DmaDescriptor],
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> Result<Self, Error> {
|
||||
internal_init(&mut dma_channel, frequency)?;
|
||||
|
||||
|
@ -287,8 +287,7 @@ mod peripheral_macros {
|
||||
impl Peripherals {
|
||||
/// Returns all the peripherals *once*
|
||||
#[inline]
|
||||
pub fn take() -> Self {
|
||||
|
||||
pub(crate) fn take() -> Self {
|
||||
#[no_mangle]
|
||||
static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false;
|
||||
|
||||
|
@ -55,12 +55,11 @@
|
||||
//! # use esp_hal::rmt::TxChannelConfig;
|
||||
//! # use esp_hal::rmt::Rmt;
|
||||
//! # use esp_hal::gpio::Io;
|
||||
//! # use esp_hal::clock::ClockControl;
|
||||
//! # use crate::esp_hal::rmt::TxChannelCreator;
|
||||
//! # let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
#![cfg_attr(esp32h2, doc = "let freq = 32.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
|
||||
//! .channel0
|
||||
//! .configure(
|
||||
@ -86,7 +85,6 @@ use core::marker::PhantomData;
|
||||
use fugit::HertzU32;
|
||||
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
gpio::{InputPin, OutputPin},
|
||||
interrupt::InterruptHandler,
|
||||
peripheral::Peripheral,
|
||||
@ -217,7 +215,6 @@ where
|
||||
pub(crate) fn new_internal(
|
||||
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> Result<Self, Error> {
|
||||
let me = Rmt::create(peripheral);
|
||||
|
||||
@ -233,7 +230,7 @@ where
|
||||
if #[cfg(any(esp32, esp32s2))] {
|
||||
self::chip_specific::configure_clock();
|
||||
} else {
|
||||
me.configure_clock(frequency, _clocks)?;
|
||||
me.configure_clock(frequency)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +246,7 @@ where
|
||||
}
|
||||
|
||||
#[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;
|
||||
|
||||
if frequency > src_clock {
|
||||
@ -273,9 +270,8 @@ impl<'d> Rmt<'d, crate::Blocking> {
|
||||
pub fn new(
|
||||
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> 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(
|
||||
peripheral: impl Peripheral<P = crate::peripherals::RMT> + 'd,
|
||||
frequency: HertzU32,
|
||||
_clocks: &Clocks<'d>,
|
||||
) -> 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);
|
||||
Ok(this)
|
||||
}
|
||||
|
@ -143,7 +143,6 @@ impl rand_core::RngCore for Rng {
|
||||
/// # use esp_hal::analog::adc::{AdcConfig, Attenuation, Adc};
|
||||
/// # use esp_hal::gpio::Io;
|
||||
///
|
||||
/// let mut peripherals = Peripherals::take();
|
||||
/// let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
/// let mut buf = [0u8; 16];
|
||||
///
|
||||
|
@ -36,7 +36,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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 d: md5::Digest = md5::compute(&data);
|
||||
//! writeln!(uart0, "{}", d);
|
||||
@ -52,7 +52,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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 data1 = "Dummy";
|
||||
//! #
|
||||
|
@ -29,7 +29,7 @@
|
||||
//! # use crate::esp_hal::prelude::_fugit_ExtU64;
|
||||
//! # use crate::esp_hal::InterruptConfigurable;
|
||||
//! 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);
|
||||
//!
|
||||
|
@ -15,7 +15,7 @@
|
||||
//! # use esp_hal::prelude::*;
|
||||
//! 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));
|
||||
//!
|
||||
|
@ -29,7 +29,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -26,7 +26,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -27,7 +27,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -27,7 +27,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -27,7 +27,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -29,7 +29,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -13,7 +13,7 @@
|
||||
//! # use esp_hal::cpu_control::{CpuControl, Stack};
|
||||
//! # use core::{cell::RefCell, ptr::addr_of_mut};
|
||||
//! # use critical_section::Mutex;
|
||||
//! # let delay = Delay::new(&clocks);
|
||||
//! # let delay = Delay::new();
|
||||
//! static mut APP_CORE_STACK: Stack<8192> = Stack::new();
|
||||
//!
|
||||
//! let counter = Mutex::new(RefCell::new(0));
|
||||
|
@ -27,7 +27,7 @@
|
||||
//! # use core::writeln;
|
||||
//! # use core::fmt::Write;
|
||||
//! # 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();
|
||||
//! writeln!(
|
||||
//! serial_tx,
|
||||
|
@ -50,7 +50,6 @@
|
||||
//! peripherals.SPI2,
|
||||
//! 100.kHz(),
|
||||
//! SpiMode::Mode0,
|
||||
//! &clocks,
|
||||
//! )
|
||||
//! .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs));
|
||||
//! # }
|
||||
@ -509,10 +508,9 @@ where
|
||||
spi: impl Peripheral<P = T> + 'd,
|
||||
frequency: HertzU32,
|
||||
mode: SpiMode,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Spi<'d, T, FullDuplexMode> {
|
||||
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.
|
||||
@ -612,7 +610,6 @@ where
|
||||
spi: PeripheralRef<'d, T>,
|
||||
frequency: HertzU32,
|
||||
mode: SpiMode,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Spi<'d, T, FullDuplexMode> {
|
||||
spi.reset_peripheral();
|
||||
spi.enable_peripheral();
|
||||
@ -621,7 +618,7 @@ where
|
||||
spi,
|
||||
_mode: PhantomData,
|
||||
};
|
||||
spi.spi.setup(frequency, clocks);
|
||||
spi.spi.setup(frequency);
|
||||
spi.spi.init();
|
||||
spi.spi.set_data_mode(mode);
|
||||
|
||||
@ -632,8 +629,8 @@ where
|
||||
///
|
||||
/// This method allows user to update the bus frequency for the SPI
|
||||
/// communication after the instance has been created.
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) {
|
||||
self.spi.ch_bus_freq(frequency, clocks);
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
|
||||
self.spi.ch_bus_freq(frequency);
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,10 +646,9 @@ where
|
||||
spi: impl Peripheral<P = T> + 'd,
|
||||
frequency: HertzU32,
|
||||
mode: SpiMode,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Spi<'d, T, HalfDuplexMode> {
|
||||
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.
|
||||
@ -820,7 +816,6 @@ where
|
||||
spi: PeripheralRef<'d, T>,
|
||||
frequency: HertzU32,
|
||||
mode: SpiMode,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Spi<'d, T, HalfDuplexMode> {
|
||||
spi.reset_peripheral();
|
||||
spi.enable_peripheral();
|
||||
@ -829,7 +824,7 @@ where
|
||||
spi,
|
||||
_mode: PhantomData,
|
||||
};
|
||||
spi.spi.setup(frequency, clocks);
|
||||
spi.spi.setup(frequency);
|
||||
spi.spi.init();
|
||||
spi.spi.set_data_mode(mode);
|
||||
|
||||
@ -840,8 +835,8 @@ where
|
||||
///
|
||||
/// This method allows you to update the bus frequency for the SPI
|
||||
/// communication after the instance has been created.
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) {
|
||||
self.spi.ch_bus_freq(frequency, clocks);
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
|
||||
self.spi.ch_bus_freq(frequency);
|
||||
}
|
||||
|
||||
/// Set the bit order for the SPI instance.
|
||||
@ -1127,8 +1122,8 @@ mod dma {
|
||||
M: Mode,
|
||||
{
|
||||
/// Changes the SPI bus frequency for the DMA-enabled SPI instance.
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32, clocks: &Clocks<'d>) {
|
||||
self.spi.ch_bus_freq(frequency, clocks);
|
||||
pub fn change_bus_frequency(&mut self, frequency: HertzU32) {
|
||||
self.spi.ch_bus_freq(frequency);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1645,9 +1640,9 @@ mod dma {
|
||||
}
|
||||
|
||||
/// 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();
|
||||
spi_dma.change_bus_frequency(frequency, clocks);
|
||||
spi_dma.change_bus_frequency(frequency);
|
||||
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
|
||||
fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) {
|
||||
fn setup(&mut self, frequency: HertzU32) {
|
||||
let clocks = Clocks::get();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32h2)] {
|
||||
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
|
||||
@ -3033,7 +3029,7 @@ pub trait Instance: private::Sealed {
|
||||
self
|
||||
}
|
||||
|
||||
fn ch_bus_freq(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) {
|
||||
fn ch_bus_freq(&mut self, frequency: HertzU32) {
|
||||
// Disable clock source
|
||||
#[cfg(not(any(esp32, esp32s2)))]
|
||||
self.register_block().clk_gate().modify(|_, w| {
|
||||
@ -3046,7 +3042,7 @@ pub trait Instance: private::Sealed {
|
||||
});
|
||||
|
||||
// Change clock frequency
|
||||
self.setup(frequency, clocks);
|
||||
self.setup(frequency);
|
||||
|
||||
// Enable clock source
|
||||
#[cfg(not(any(esp32, esp32s2)))]
|
||||
|
@ -18,7 +18,7 @@
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! # 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);
|
||||
//!
|
||||
//! one_shot.delay_millis(500);
|
||||
@ -30,7 +30,7 @@
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! # 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);
|
||||
//!
|
||||
//! periodic.start(1.secs());
|
||||
|
@ -129,21 +129,21 @@ impl<'d> SystemTimer<'d> {
|
||||
pub fn ticks_per_second() -> u64 {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32s2)] {
|
||||
80_000_000
|
||||
const MULTIPLIER: u64 = 2_000_000;
|
||||
} else if #[cfg(esp32h2)] {
|
||||
// The counters and comparators are driven using `XTAL_CLK`.
|
||||
// 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.
|
||||
const MULTIPLIER: u64 = 10_000_000 / 20;
|
||||
crate::clock::xtal_freq_mhz() as u64 * MULTIPLIER
|
||||
} else {
|
||||
// The counters and comparators are driven using `XTAL_CLK`.
|
||||
// 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.
|
||||
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.
|
||||
|
@ -28,7 +28,7 @@
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! # use esp_hal::timer::timg::TimerGroup;
|
||||
//!
|
||||
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
//! let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
//! let timer0 = timg0.timer0;
|
||||
//!
|
||||
//! // Get the current timestamp, in microseconds:
|
||||
@ -51,7 +51,7 @@
|
||||
#![doc = crate::before_snippet!()]
|
||||
//! # use esp_hal::timer::timg::TimerGroup;
|
||||
//!
|
||||
//! let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
//! let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
//! let mut wdt = timg0.wdt;
|
||||
//!
|
||||
//! wdt.set_timeout(5_000.millis());
|
||||
@ -256,7 +256,7 @@ where
|
||||
DM: crate::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);
|
||||
|
||||
T::reset_peripheral();
|
||||
@ -264,6 +264,7 @@ where
|
||||
|
||||
T::configure_src_clk();
|
||||
|
||||
let clocks = Clocks::get();
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(esp32h2)] {
|
||||
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
|
||||
@ -271,7 +272,7 @@ where
|
||||
} else {
|
||||
let apb_clk_freq = clocks.apb_clock;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let timer0 = Timer::new(
|
||||
Timer0 {
|
||||
@ -303,8 +304,8 @@ where
|
||||
T: TimerGroupInstance,
|
||||
{
|
||||
/// Construct a new instance of [`TimerGroup`] in blocking mode
|
||||
pub fn new(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self {
|
||||
Self::new_inner(timer_group, clocks)
|
||||
pub fn new(_timer_group: impl Peripheral<P = T> + 'd) -> Self {
|
||||
Self::new_inner(_timer_group)
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,8 +314,8 @@ where
|
||||
T: TimerGroupInstance,
|
||||
{
|
||||
/// Construct a new instance of [`TimerGroup`] in asynchronous mode
|
||||
pub fn new_async(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self {
|
||||
Self::new_inner(timer_group, clocks)
|
||||
pub fn new_async(_timer_group: impl Peripheral<P = T> + 'd) -> Self {
|
||||
Self::new_inner(_timer_group)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@
|
||||
//! peripherals.TWAI0,
|
||||
//! can_tx_pin,
|
||||
//! can_rx_pin,
|
||||
//! &clocks,
|
||||
//! TWAI_BAUDRATE,
|
||||
//! TwaiMode::Normal
|
||||
//! );
|
||||
@ -105,7 +104,6 @@
|
||||
//! peripherals.TWAI0,
|
||||
//! can_tx_pin,
|
||||
//! can_rx_pin,
|
||||
//! &clocks,
|
||||
//! TWAI_BAUDRATE,
|
||||
//! TwaiMode::SelfTest
|
||||
//! );
|
||||
@ -135,7 +133,6 @@ use core::marker::PhantomData;
|
||||
|
||||
use self::filter::{Filter, FilterType};
|
||||
use crate::{
|
||||
clock::Clocks,
|
||||
gpio::{InputPin, InputSignal, OutputPin, OutputSignal},
|
||||
interrupt::InterruptHandler,
|
||||
peripheral::{Peripheral, PeripheralRef},
|
||||
@ -723,7 +720,6 @@ where
|
||||
_peripheral: impl Peripheral<P = T> + 'd,
|
||||
tx_pin: impl Peripheral<P = TX> + 'd,
|
||||
rx_pin: impl Peripheral<P = RX> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
baud_rate: BaudRate,
|
||||
no_transceiver: bool,
|
||||
mode: TwaiMode,
|
||||
@ -787,7 +783,7 @@ where
|
||||
phantom: PhantomData,
|
||||
};
|
||||
|
||||
cfg.set_baud_rate(baud_rate, clocks);
|
||||
cfg.set_baud_rate(baud_rate);
|
||||
cfg
|
||||
}
|
||||
|
||||
@ -801,11 +797,14 @@ where
|
||||
/// Set the bitrate of the bus.
|
||||
///
|
||||
/// 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)
|
||||
// Included timings are all for 80MHz so assert that we are running at 80MHz.
|
||||
#[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
|
||||
// register. Many of the registers have a minimum value of 1 which is
|
||||
@ -908,11 +907,10 @@ where
|
||||
peripheral: impl Peripheral<P = T> + 'd,
|
||||
tx_pin: impl Peripheral<P = TX> + 'd,
|
||||
rx_pin: impl Peripheral<P = RX> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
baud_rate: BaudRate,
|
||||
mode: TwaiMode,
|
||||
) -> 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
|
||||
@ -924,11 +922,10 @@ where
|
||||
peripheral: impl Peripheral<P = T> + 'd,
|
||||
tx_pin: impl Peripheral<P = TX> + 'd,
|
||||
rx_pin: impl Peripheral<P = RX> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
baud_rate: BaudRate,
|
||||
mode: TwaiMode,
|
||||
) -> 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,
|
||||
tx_pin: impl Peripheral<P = TX> + 'd,
|
||||
rx_pin: impl Peripheral<P = RX> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
baud_rate: BaudRate,
|
||||
mode: TwaiMode,
|
||||
) -> Self {
|
||||
let mut this =
|
||||
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, false, mode);
|
||||
let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, false, mode);
|
||||
this.internal_set_interrupt_handler(T::async_handler());
|
||||
this
|
||||
}
|
||||
@ -973,12 +968,10 @@ where
|
||||
peripheral: impl Peripheral<P = T> + 'd,
|
||||
tx_pin: impl Peripheral<P = TX> + 'd,
|
||||
rx_pin: impl Peripheral<P = RX> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
baud_rate: BaudRate,
|
||||
mode: TwaiMode,
|
||||
) -> Self {
|
||||
let mut this =
|
||||
Self::new_internal(peripheral, tx_pin, rx_pin, clocks, baud_rate, true, mode);
|
||||
let mut this = Self::new_internal(peripheral, tx_pin, rx_pin, baud_rate, true, mode);
|
||||
this.internal_set_interrupt_handler(T::async_handler());
|
||||
this
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
//!
|
||||
//! let mut uart1 = Uart::new(
|
||||
//! peripherals.UART1,
|
||||
//! &clocks,
|
||||
//! io.pins.gpio1,
|
||||
//! io.pins.gpio2,
|
||||
//! ).unwrap();
|
||||
@ -62,7 +61,6 @@
|
||||
//! # let mut uart1 = Uart::new_with_config(
|
||||
//! # peripherals.UART1,
|
||||
//! # Config::default(),
|
||||
//! # &clocks,
|
||||
//! # io.pins.gpio1,
|
||||
//! # io.pins.gpio2,
|
||||
//! # ).unwrap();
|
||||
@ -80,7 +78,6 @@
|
||||
//! # let mut uart1 = Uart::new_with_config(
|
||||
//! # peripherals.UART1,
|
||||
//! # Config::default(),
|
||||
//! # &clocks,
|
||||
//! # io.pins.gpio1,
|
||||
//! # io.pins.gpio2,
|
||||
//! # ).unwrap();
|
||||
@ -105,7 +102,6 @@
|
||||
//! let rx = AnyPin::new_inverted(io.pins.gpio2);
|
||||
//! let mut uart1 = Uart::new(
|
||||
//! peripherals.UART1,
|
||||
//! &clocks,
|
||||
//! tx,
|
||||
//! rx,
|
||||
//! ).unwrap();
|
||||
@ -120,10 +116,8 @@
|
||||
//!
|
||||
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
//!
|
||||
//! let tx = UartTx::new(peripherals.UART0, &clocks,
|
||||
//! io.pins.gpio1).unwrap();
|
||||
//! let rx = UartRx::new(peripherals.UART1, &clocks,
|
||||
//! io.pins.gpio2).unwrap();
|
||||
//! let tx = UartTx::new(peripherals.UART0, io.pins.gpio1).unwrap();
|
||||
//! let rx = UartRx::new(peripherals.UART1, io.pins.gpio2).unwrap();
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
@ -579,10 +573,9 @@ where
|
||||
/// Create a new UART TX instance in [`Blocking`] mode.
|
||||
pub fn new<TX: OutputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
) -> 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
|
||||
@ -590,15 +583,13 @@ where
|
||||
pub fn new_with_config<TX: OutputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
crate::into_ref!(tx);
|
||||
tx.set_to_push_pull_output(Internal);
|
||||
tx.connect_peripheral_to_output(T::tx_signal(), Internal);
|
||||
|
||||
let (uart_tx, _) =
|
||||
Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split();
|
||||
let (uart_tx, _) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split();
|
||||
|
||||
Ok(uart_tx)
|
||||
}
|
||||
@ -787,10 +778,9 @@ where
|
||||
/// Create a new UART RX instance in [`Blocking`] mode.
|
||||
pub fn new<RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> 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
|
||||
@ -798,15 +788,13 @@ where
|
||||
pub fn new_with_config<RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
crate::into_ref!(rx);
|
||||
rx.set_to_input(Internal);
|
||||
rx.connect_input_to_peripheral(T::rx_signal(), Internal);
|
||||
|
||||
let (_, uart_rx) =
|
||||
Uart::<'d, T, Blocking>::new_with_config_inner(uart, config, clocks)?.split();
|
||||
let (_, uart_rx) = Uart::<'d, T, Blocking>::new_with_config_inner(uart, config)?.split();
|
||||
|
||||
Ok(uart_rx)
|
||||
}
|
||||
@ -821,7 +809,6 @@ where
|
||||
pub fn new_with_config<TX: OutputPin, RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
@ -832,13 +819,12 @@ where
|
||||
|
||||
rx.set_to_input(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.
|
||||
pub fn new<TX: OutputPin, RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
@ -849,14 +835,13 @@ where
|
||||
|
||||
rx.set_to_input(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.
|
||||
/// Verify that the default pins (DefaultTxPin and DefaultRxPin) are used.
|
||||
pub fn new_with_default_pins(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: &mut DefaultTxPin,
|
||||
rx: &mut DefaultRxPin,
|
||||
) -> Result<Self, Error> {
|
||||
@ -865,7 +850,7 @@ where
|
||||
|
||||
rx.set_to_input(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(
|
||||
_uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
) -> Result<Self, Error> {
|
||||
Self::init();
|
||||
|
||||
@ -893,7 +877,7 @@ where
|
||||
.rx
|
||||
.set_rx_fifo_full_threshold(config.rx_fifo_full_threshold)?;
|
||||
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_parity(config.parity);
|
||||
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> {
|
||||
Self::new_with_config_inner(uart, Default::default(), clocks)
|
||||
fn new_inner(uart: impl Peripheral<P = T> + 'd) -> Result<Self, Error> {
|
||||
Self::new_with_config_inner(uart, Default::default())
|
||||
}
|
||||
|
||||
/// Configure CTS pin
|
||||
@ -1157,7 +1141,8 @@ where
|
||||
}
|
||||
|
||||
#[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 {
|
||||
ClockSource::Apb => clocks.apb_clock.to_Hz(),
|
||||
ClockSource::Xtal => clocks.xtal_clock.to_Hz(),
|
||||
@ -1194,7 +1179,8 @@ where
|
||||
}
|
||||
|
||||
#[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 {
|
||||
ClockSource::Apb => clocks.apb_clock.to_Hz(),
|
||||
ClockSource::Xtal => clocks.xtal_clock.to_Hz(),
|
||||
@ -1265,7 +1251,8 @@ where
|
||||
}
|
||||
|
||||
#[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 {
|
||||
ClockSource::Apb => clocks.apb_clock.to_Hz(),
|
||||
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.
|
||||
pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource, clocks: &Clocks<'d>) {
|
||||
self.change_baud_internal(baudrate, clock_source, clocks);
|
||||
pub fn change_baud(&mut self, baudrate: u32, clock_source: ClockSource) {
|
||||
self.change_baud_internal(baudrate, clock_source);
|
||||
self.txfifo_reset();
|
||||
self.rxfifo_reset();
|
||||
}
|
||||
@ -2146,7 +2133,6 @@ mod asynch {
|
||||
pub fn new_async_with_config<TX: OutputPin, RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
@ -2157,7 +2143,7 @@ mod asynch {
|
||||
|
||||
rx.set_to_input(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() {
|
||||
#[cfg(uart0)]
|
||||
@ -2175,21 +2161,19 @@ mod asynch {
|
||||
/// Create a new UART instance with defaults in [`Async`] mode.
|
||||
pub fn new_async<TX: OutputPin, RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> 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.
|
||||
pub fn new_async_with_default_pins(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: DefaultTxPin,
|
||||
rx: DefaultRxPin,
|
||||
) -> 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.
|
||||
pub fn new_async<TX: OutputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
) -> 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
|
||||
@ -2232,14 +2215,13 @@ mod asynch {
|
||||
pub fn new_async_with_config<TX: OutputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
tx: impl Peripheral<P = TX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
crate::into_ref!(tx);
|
||||
tx.set_to_push_pull_output(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() {
|
||||
#[cfg(uart0)]
|
||||
@ -2308,10 +2290,9 @@ mod asynch {
|
||||
/// Create a new UART RX instance in [`Async`] mode.
|
||||
pub fn new_async<RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
clocks: &Clocks<'d>,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> 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
|
||||
@ -2319,14 +2300,13 @@ mod asynch {
|
||||
pub fn new_async_with_config<RX: InputPin>(
|
||||
uart: impl Peripheral<P = T> + 'd,
|
||||
config: Config,
|
||||
clocks: &Clocks<'d>,
|
||||
rx: impl Peripheral<P = RX> + 'd,
|
||||
) -> Result<Self, Error> {
|
||||
crate::into_ref!(rx);
|
||||
rx.set_to_input(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() {
|
||||
#[cfg(uart0)]
|
||||
|
@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Removed
|
||||
|
||||
- Removed the `clocks` parameter from `esp_wifi::initialize` (#1999)
|
||||
|
||||
## 0.8.0 - 2024-08-29
|
||||
|
||||
### Added
|
||||
|
41
esp-wifi/MIGRATING-0.9.md
Normal file
41
esp-wifi/MIGRATING-0.9.md
Normal 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();
|
||||
|
||||
// ...
|
||||
}
|
||||
```
|
@ -293,13 +293,12 @@ impl EspWifiTimerSource for TimeBase {
|
||||
/// use esp_hal::{rng::Rng, timg::TimerGroup};
|
||||
/// use esp_wifi::EspWifiInitFor;
|
||||
///
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
/// let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
/// let init = esp_wifi::initialize(
|
||||
/// EspWifiInitFor::Wifi,
|
||||
/// timg0.timer0,
|
||||
/// Rng::new(peripherals.RNG),
|
||||
/// peripherals.RADIO_CLK,
|
||||
/// &clocks,
|
||||
/// )
|
||||
/// .unwrap();
|
||||
/// # }
|
||||
@ -309,10 +308,10 @@ pub fn initialize(
|
||||
timer: impl EspWifiTimerSource,
|
||||
rng: hal::rng::Rng,
|
||||
radio_clocks: hal::peripherals::RADIO_CLK,
|
||||
clocks: &Clocks,
|
||||
) -> Result<EspWifiInitialization, InitializationError> {
|
||||
// A minimum clock of 80MHz is required to operate WiFi module.
|
||||
const MIN_CLOCK: u32 = 80;
|
||||
let clocks = Clocks::get();
|
||||
if clocks.cpu_clock < MegahertzU32::MHz(MIN_CLOCK) {
|
||||
return Err(InitializationError::WrongClockConfig);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
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 = Adc::new(peripherals.ADC1, adc1_config);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
let pin_value: u16 = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
|
||||
|
@ -23,7 +23,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
cfg_if::cfg_if! {
|
||||
@ -49,7 +49,7 @@ fn main() -> ! {
|
||||
adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB);
|
||||
let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
let pin_mv = nb::block!(adc1.read_oneshot(&mut adc1_pin)).unwrap();
|
||||
|
@ -19,13 +19,13 @@ use nb::block;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
let mut 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");
|
||||
loop {
|
||||
|
@ -17,13 +17,13 @@ use esp_hal::{
|
||||
|
||||
#[entry]
|
||||
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.
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut led = Output::new(io.pins.gpio0, Level::High);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
led.toggle();
|
||||
|
@ -20,7 +20,7 @@ use esp_hal::{
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -39,7 +39,7 @@ fn main() -> ! {
|
||||
|
||||
let mut pins = [led1, led2, led3];
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
toggle_pins(&mut pins, &button);
|
||||
|
@ -23,7 +23,7 @@ use esp_hal::{analog::dac::Dac, delay::Delay, gpio::Io, prelude::*};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -41,7 +41,7 @@ fn main() -> ! {
|
||||
let mut dac1 = Dac::new(peripherals.DAC1, dac1_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_dac2: u8 = 255;
|
||||
|
@ -18,7 +18,7 @@ static DA: Mutex<RefCell<Option<DebugAssist>>> = Mutex::new(RefCell::new(None));
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
da.set_interrupt_handler(interrupt_handler);
|
||||
|
@ -62,10 +62,10 @@ fn init_heap(psram: impl esp_hal::peripheral::Peripheral<P = esp_hal::peripheral
|
||||
fn main() -> ! {
|
||||
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);
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
let mut extram_buffer: &mut [u8] = dma_alloc_buffer!(DATA_SIZE, 64);
|
||||
let mut intram_buffer = dma_buffer_aligned!(DATA_SIZE, A64);
|
||||
|
@ -21,9 +21,9 @@ const DATA_SIZE: usize = 1024 * 10;
|
||||
fn main() -> ! {
|
||||
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);
|
||||
|
||||
|
@ -25,12 +25,12 @@ async fn run() {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
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!");
|
||||
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
spawner.spawn(run()).ok();
|
||||
|
||||
|
@ -24,20 +24,14 @@ use lis3dh_async::{Lis3dh, Range, SlaveAddr};
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
let i2c0 = I2C::new_async(
|
||||
peripherals.I2C0,
|
||||
io.pins.gpio4,
|
||||
io.pins.gpio5,
|
||||
400.kHz(),
|
||||
&clocks,
|
||||
);
|
||||
let i2c0 = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz());
|
||||
|
||||
let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap();
|
||||
lis3dh.set_range(Range::G8).await.unwrap();
|
||||
|
@ -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
|
||||
//! 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]
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
let mut i2c = I2C::new_async(
|
||||
peripherals.I2C0,
|
||||
io.pins.gpio4,
|
||||
io.pins.gpio5,
|
||||
400.kHz(),
|
||||
&clocks,
|
||||
);
|
||||
let mut i2c = I2C::new_async(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 400.kHz());
|
||||
|
||||
loop {
|
||||
let mut data = [0u8; 22];
|
||||
|
@ -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
|
||||
//! 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]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
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),
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
&clocks,
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
|
@ -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
|
||||
//! and DOUT with a logic analyzer.
|
||||
@ -54,10 +54,10 @@ const SINE: [i16; 64] = [
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
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),
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
&clocks,
|
||||
);
|
||||
|
||||
let i2s_tx = i2s
|
||||
|
@ -51,14 +51,14 @@ async fn control_led(
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
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 timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
let timer0: ErasedTimer = timg0.timer0.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);
|
||||
|
||||
|
@ -71,16 +71,16 @@ async fn enable_disable_led(control: &'static Signal<CriticalSectionRawMutex, bo
|
||||
|
||||
#[entry]
|
||||
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 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 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);
|
||||
|
||||
|
@ -71,11 +71,11 @@ async fn main(low_prio_spawner: Spawner) {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
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 timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
let timer0: ErasedTimer = timg0.timer0.into();
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@ -84,12 +84,12 @@ async fn main(low_prio_spawner: Spawner) {
|
||||
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
|
||||
let timer1: ErasedTimer = systimer.alarm0.into();
|
||||
} else {
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
|
||||
let timg1 = TimerGroup::new(peripherals.TIMG1);
|
||||
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();
|
||||
let executor = InterruptExecutor::new(sw_ints.software_interrupt2);
|
||||
|
@ -26,10 +26,10 @@ use esp_println::println;
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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>();
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
esp_hal_embassy::init(systimer.alarm0);
|
||||
|
||||
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),
|
||||
rx_descriptors,
|
||||
1.MHz(),
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -37,10 +37,10 @@ use esp_println::println;
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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>();
|
||||
esp_hal_embassy::init(&clocks, systimer.alarm0);
|
||||
esp_hal_embassy::init(systimer.alarm0);
|
||||
|
||||
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),
|
||||
tx_descriptors,
|
||||
1.MHz(),
|
||||
&clocks,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -39,10 +39,10 @@ async fn signal_task(mut pin: Output<'static, GpioPin<5>>) {
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
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 {
|
||||
clk_divider: 255,
|
||||
idle_threshold: 10000,
|
||||
|
@ -25,10 +25,10 @@ use esp_println::println;
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
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
|
||||
.channel0
|
||||
|
@ -78,10 +78,10 @@ async fn reader(
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
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 mut uart0 =
|
||||
Uart::new_async_with_config(peripherals.UART0, config, &clocks, tx_pin, rx_pin).unwrap();
|
||||
let mut uart0 = Uart::new_async_with_config(peripherals.UART0, config, tx_pin, rx_pin).unwrap();
|
||||
uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None));
|
||||
|
||||
let (tx, rx) = uart0.split();
|
||||
|
@ -33,10 +33,10 @@ use esp_hal::{
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
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_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_dma(dma_channel.configure_for_async(false, DmaPriority::Priority0))
|
||||
.with_buffers(dma_tx_buf, dma_rx_buf);
|
||||
|
@ -27,10 +27,10 @@ use esp_println::println;
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut rtc = Rtc::new(peripherals.LPWR);
|
||||
|
@ -82,10 +82,10 @@ async fn transmitter(
|
||||
|
||||
#[esp_hal_embassy::main]
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -103,7 +103,6 @@ async fn main(spawner: Spawner) {
|
||||
peripherals.TWAI0,
|
||||
can_tx_pin,
|
||||
can_rx_pin,
|
||||
&clocks,
|
||||
CAN_BAUDRATE,
|
||||
TwaiMode::Normal,
|
||||
);
|
||||
|
@ -32,10 +32,10 @@ use esp_hal::{
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -63,10 +63,10 @@ async fn reader(
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let (tx, rx) = UsbSerialJtag::new_async(peripherals.USB_DEVICE).split();
|
||||
|
||||
|
@ -19,10 +19,10 @@ use esp_hal::{
|
||||
#[esp_hal_embassy::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
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);
|
||||
esp_hal_embassy::init(&clocks, timg0.timer0);
|
||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||
esp_hal_embassy::init(timg0.timer0);
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -24,7 +24,7 @@ use fugit::ExtU32;
|
||||
|
||||
#[entry]
|
||||
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_alarms = syst.split::<Periodic>();
|
||||
|
@ -22,7 +22,7 @@ use esp_hal::{
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let mut led = io.pins.gpio1;
|
||||
|
@ -28,9 +28,9 @@ static TIMER0: Mutex<RefCell<Option<Timer<Timer0<TIMG0>, esp_hal::Blocking>>>> =
|
||||
|
||||
#[entry]
|
||||
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;
|
||||
timer0.set_interrupt_handler(tg0_t0_level);
|
||||
|
||||
@ -55,7 +55,7 @@ fn main() -> ! {
|
||||
TIMER0.borrow_ref_mut(cs).replace(timer0);
|
||||
});
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
delay.delay_millis(500u32);
|
||||
|
@ -34,7 +34,7 @@ static BUTTON: Mutex<RefCell<Option<Input<GpioPin<BUTTON_PIN>>>>> = Mutex::new(R
|
||||
|
||||
#[entry]
|
||||
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.
|
||||
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
@ -57,7 +57,7 @@ fn main() -> ! {
|
||||
});
|
||||
led.set_high();
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
led.toggle();
|
||||
|
@ -36,7 +36,7 @@ use smart_leds::{
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -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
|
||||
// be used directly with all `smart_led` implementations
|
||||
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 {
|
||||
hue: 0,
|
||||
|
@ -19,9 +19,9 @@ use esp_hal::{delay::Delay, gpio::Io, prelude::*, uart::Uart};
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
@ -43,7 +43,7 @@ fn main() -> ! {
|
||||
}
|
||||
|
||||
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 {
|
||||
writeln!(uart0, "Hello world!").unwrap();
|
||||
|
@ -73,7 +73,7 @@ type HmacSha256 = HmacSw<Sha256>;
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
|
@ -17,19 +17,13 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
// Create a new peripheral object with the described wiring and standard
|
||||
// I2C clock speed:
|
||||
let mut i2c = I2C::new(
|
||||
peripherals.I2C0,
|
||||
io.pins.gpio4,
|
||||
io.pins.gpio5,
|
||||
100.kHz(),
|
||||
&clocks,
|
||||
);
|
||||
let mut i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz());
|
||||
|
||||
loop {
|
||||
let mut data = [0u8; 22];
|
||||
|
@ -27,20 +27,14 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
// Create a new peripheral object with the described wiring
|
||||
// and standard I2C clock speed
|
||||
let i2c = I2C::new(
|
||||
peripherals.I2C0,
|
||||
io.pins.gpio4,
|
||||
io.pins.gpio5,
|
||||
100.kHz(),
|
||||
&clocks,
|
||||
);
|
||||
let i2c = I2C::new(peripherals.I2C0, io.pins.gpio4, io.pins.gpio5, 100.kHz());
|
||||
|
||||
// Initialize display
|
||||
let interface = I2CDisplayInterface::new(i2c);
|
||||
|
@ -28,7 +28,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -52,7 +52,6 @@ fn main() -> ! {
|
||||
dma_channel.configure(false, DmaPriority::Priority0),
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
&clocks,
|
||||
);
|
||||
|
||||
#[cfg(not(feature = "esp32"))]
|
||||
|
@ -49,7 +49,7 @@ const SINE: [i16; 64] = [
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -69,7 +69,6 @@ fn main() -> ! {
|
||||
dma_channel.configure(false, DmaPriority::Priority0),
|
||||
tx_descriptors,
|
||||
rx_descriptors,
|
||||
&clocks,
|
||||
);
|
||||
|
||||
let mut i2s_tx = i2s
|
||||
|
@ -10,7 +10,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
ieee802154.set_config(Config {
|
||||
|
@ -10,7 +10,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
ieee802154.set_config(Config {
|
||||
|
@ -19,9 +19,9 @@ use ieee802154::mac::{
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
|
@ -19,9 +19,9 @@ use ieee802154::mac::{
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
|
@ -14,7 +14,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
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);
|
||||
|
||||
@ -28,7 +28,7 @@ fn main() -> ! {
|
||||
}
|
||||
|
||||
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
|
||||
let mut cnt = 0;
|
||||
|
@ -42,7 +42,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -77,20 +77,19 @@ fn main() -> ! {
|
||||
rx_descriptors,
|
||||
cam_data_pins,
|
||||
20u32.MHz(),
|
||||
&clocks,
|
||||
)
|
||||
.with_master_clock(cam_xclk)
|
||||
.with_pixel_clock(cam_pclk)
|
||||
.with_ctrl_pins(cam_vsync, cam_href);
|
||||
|
||||
let delay = Delay::new(&clocks);
|
||||
let delay = Delay::new();
|
||||
|
||||
let mut buffer = rx_buffer;
|
||||
buffer.fill(0u8);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -37,7 +37,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -54,7 +54,7 @@ fn main() -> ! {
|
||||
|
||||
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 reset = Output::new(lcd_reset, Level::Low);
|
||||
@ -78,7 +78,6 @@ fn main() -> ! {
|
||||
tx_pins,
|
||||
20.MHz(),
|
||||
Config::default(),
|
||||
&clocks,
|
||||
)
|
||||
.with_ctrl_pins(lcd_rs, lcd_wr);
|
||||
|
||||
|
@ -24,12 +24,12 @@ use esp_hal::{
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let 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);
|
||||
|
||||
|
@ -23,7 +23,7 @@ use esp_println::{print, println};
|
||||
|
||||
#[entry]
|
||||
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
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
@ -25,7 +25,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, _clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
|
@ -28,7 +28,7 @@ use esp_println::println;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
|
||||
@ -37,7 +37,6 @@ fn main() -> ! {
|
||||
let mut uart1 = Uart::new_with_config(
|
||||
peripherals.UART1,
|
||||
Config::default(),
|
||||
&clocks,
|
||||
io.pins.gpio6,
|
||||
io.pins.gpio7,
|
||||
)
|
||||
|
@ -18,7 +18,7 @@ use esp_hal::{
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
||||
let peripherals = esp_hal::init(esp_hal::Config::default());
|
||||
|
||||
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||
let 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);
|
||||
|
||||
|
@ -23,9 +23,9 @@ static mut APP_CORE_STACK: Stack<8192> = Stack::new();
|
||||
|
||||
#[entry]
|
||||
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));
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user