Prefer cfg_if (#2003)

This commit is contained in:
Dániel Buga 2024-08-27 13:53:55 +02:00 committed by GitHub
parent 1003ce0c0f
commit 8aa1a88a23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
54 changed files with 517 additions and 386 deletions

View File

@ -53,6 +53,7 @@ The following paragraphs contain additional recommendations.
- If necessary provide further context as comments (consider linking to code, PRs, TRM - make sure to use permanent links, e.g. include the hash when linking to a Git repository, include the revision, page number etc. when linking to TRMs) - If necessary provide further context as comments (consider linking to code, PRs, TRM - make sure to use permanent links, e.g. include the hash when linking to a Git repository, include the revision, page number etc. when linking to TRMs)
- Generally, follow common "good practices" and idiomatic Rust style - Generally, follow common "good practices" and idiomatic Rust style
- All `Future` objects (public or private) must be marked with ``#[must_use = "futures do nothing unless you `.await` or poll them"]``. - All `Future` objects (public or private) must be marked with ``#[must_use = "futures do nothing unless you `.await` or poll them"]``.
- Prefer `cfg_if!` over multiple exclusive `#[cfg]` attributes. `cfg_if!` visually divides the options, often results in simpler conditions and simplifies adding new branches in the future.
## Modules Documentation ## Modules Documentation

View File

@ -71,6 +71,7 @@ impl Executor {
#[cfg_attr( #[cfg_attr(
multi_core, multi_core,
doc = r#" doc = r#"
This will use software-interrupt 3 which isn't This will use software-interrupt 3 which isn't
available for anything else to wake the other core(s). available for anything else to wake the other core(s).
"# "#

View File

@ -1,12 +1,14 @@
//! # Advanced Encryption Standard (AES). //! # Advanced Encryption Standard (AES).
//! //!
//! ## Overview //! ## Overview
//!
//! The AES accelerator is a hardware device that speeds up computation //! The AES accelerator is a hardware device that speeds up computation
//! using AES algorithm significantly, compared to AES algorithms implemented //! using AES algorithm significantly, compared to AES algorithms implemented
//! solely in software. The AES accelerator has two working modes, which are //! solely in software. The AES accelerator has two working modes, which are
//! Typical AES and AES-DMA. //! Typical AES and AES-DMA.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The AES peripheral can be configured to encrypt or decrypt data using //! The AES peripheral can be configured to encrypt or decrypt data using
//! different encryption/decryption modes. //! different encryption/decryption modes.
//! //!
@ -14,8 +16,11 @@
//! cipher modes such as ECB, CBC, OFB, CTR, CFB8, and CFB128. //! cipher modes such as ECB, CBC, OFB, CTR, CFB8, and CFB128.
//! //!
//! ## Examples //! ## Examples
//! ### Encrypting and Decrypting a Message //!
//! ### Encrypting and decrypting a message
//!
//! Simple example of encrypting and decrypting a message using AES-128: //! Simple example of encrypting and decrypting a message using AES-128:
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::aes::{Aes, Mode}; //! # use esp_hal::aes::{Aes, Mode};

View File

@ -1,11 +1,13 @@
//! # Analog to Digital Converter (ADC) //! # Analog to Digital Converter (ADC)
//! //!
//! ## Overview //! ## Overview
//!
//! The ADC is integrated on the chip, and is capable of measuring analog //! The ADC is integrated on the chip, and is capable of measuring analog
//! signals from specific analog I/O pins. One or more ADC units are available, //! signals from specific analog I/O pins. One or more ADC units are available,
//! depending on the device being used. //! depending on the device being used.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The ADC can be configured to measure analog signals from specific pins. The //! The ADC can be configured to measure analog signals from specific pins. The
//! configuration includes the resolution of the ADC, the attenuation of the //! configuration includes the resolution of the ADC, the attenuation of the
//! input signal, and the pins to be measured. //! input signal, and the pins to be measured.
@ -15,10 +17,13 @@
//! schemes can be used to improve the accuracy of the ADC readings. //! schemes can be used to improve the accuracy of the ADC readings.
//! //!
//! ## Usage //! ## Usage
//!
//! The ADC driver implements the `embedded-hal@0.2.x` ADC traits. //! The ADC driver implements the `embedded-hal@0.2.x` ADC traits.
//! //!
//! ## Examples //! ## Example
//! #### Read an analog signal from a pin //!
//! ### Read an analog signal from a pin
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::analog::adc::AdcConfig; //! # use esp_hal::analog::adc::AdcConfig;

View File

@ -1,6 +1,7 @@
//! # Clock Control //! # CPU Clock Control
//! //!
//! ## Overview //! ## Overview
//!
//! Clocks are mainly sourced from oscillator (OSC), RC, and PLL circuits, and //! Clocks are mainly sourced from oscillator (OSC), RC, and PLL circuits, and
//! then processed by the dividers or selectors, which allows most functional //! then processed by the dividers or selectors, which allows most functional
//! modules to select their working clock according to their power consumption //! modules to select their working clock according to their power consumption

View File

@ -1,6 +1,7 @@
//! # Direct Memory Access (DMA) //! # Direct Memory Access (DMA)
//! //!
//! ## Overview //! ## Overview
//!
//! The DMA driver provides an interface to efficiently transfer data between //! The DMA driver provides an interface to efficiently transfer data between
//! different memory regions and peripherals within the ESP microcontroller //! different memory regions and peripherals within the ESP microcontroller
//! without involving the CPU. The DMA controller is responsible for managing //! without involving the CPU. The DMA controller is responsible for managing
@ -10,8 +11,10 @@
//! `ESP32-S2` are using older `PDMA` controller, whenever other chips are using //! `ESP32-S2` are using older `PDMA` controller, whenever other chips are using
//! newer `GDMA` controller. //! newer `GDMA` controller.
//! //!
//! ## Examples //! ## Example
//! ### Initialize and Utilize DMA Controller in `SPI` //!
//! ### Initialize and utilize DMA controller in `SPI`
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::dma_buffers; //! # use esp_hal::dma_buffers;

View File

@ -1,16 +1,19 @@
//! # General Purpose I/Os (GPIO) //! # General Purpose I/Os (GPIO)
//! //!
//! ## Overview //! ## Overview
//!
//! Each pin can be used as a general-purpose I/O, or be connected to an //! Each pin can be used as a general-purpose I/O, or be connected to an
//! internal peripheral signal. //! internal peripheral signal.
//! //!
//! ## Configuration //! ## Configuration
//!
//! This driver supports various operations on GPIO pins, including setting the //! This driver supports various operations on GPIO pins, including setting the
//! pin mode, direction, and manipulating the pin state (setting high/low, //! pin mode, direction, and manipulating the pin state (setting high/low,
//! toggling). It provides an interface to interact with GPIO pins on ESP chips, //! toggling). It provides an interface to interact with GPIO pins on ESP chips,
//! allowing developers to control and read the state of the pins. //! allowing developers to control and read the state of the pins.
//! //!
//! ## Usage //! ## Usage
//!
//! This module also implements a number of traits from [embedded-hal] to //! This module also implements a number of traits from [embedded-hal] to
//! provide a common interface for GPIO pins. //! provide a common interface for GPIO pins.
//! //!
@ -18,6 +21,7 @@
//! designed struct from the pac struct `GPIO` and `IO_MUX` using `Io::new`. //! designed struct from the pac struct `GPIO` and `IO_MUX` using `Io::new`.
//! //!
//! ### Pin Types //! ### Pin Types
//!
//! - [Input] pins can be used as digital inputs. //! - [Input] pins can be used as digital inputs.
//! - [Output] and [OutputOpenDrain] pins can be used as digital outputs. //! - [Output] and [OutputOpenDrain] pins can be used as digital outputs.
//! - [Flex] pin is a pin that can be used as an input and output pin. //! - [Flex] pin is a pin that can be used as an input and output pin.
@ -27,7 +31,9 @@
//! but real pin cannot be used. //! but real pin cannot be used.
//! //!
//! ## Examples //! ## Examples
//!
//! ### Set up a GPIO as an Output //! ### Set up a GPIO as an Output
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::gpio::{Io, Level, Output}; //! # use esp_hal::gpio::{Io, Level, Output};
@ -37,6 +43,7 @@
//! ``` //! ```
//! //!
//! ### Blink an LED //! ### Blink an LED
//!
//! See the [Commonly Used Setup] section of the crate documentation. //! See the [Commonly Used Setup] section of the crate documentation.
//! //!
//! ### Inverting a signal using `AnyPin` //! ### Inverting a signal using `AnyPin`

View File

@ -1068,12 +1068,15 @@ pub trait Instance: crate::private::Sealed {
self.set_filter(Some(7), Some(7)); self.set_filter(Some(7), Some(7));
// Configure frequency // Configure frequency
#[cfg(esp32)] cfg_if::cfg_if! {
self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout); if #[cfg(esp32)] {
#[cfg(esp32s2)] self.set_frequency(clocks.i2c_clock.convert(), frequency, timeout);
self.set_frequency(clocks.apb_clock.convert(), frequency, timeout); } else if #[cfg(esp32s2)] {
#[cfg(not(any(esp32, esp32s2)))] self.set_frequency(clocks.apb_clock.convert(), frequency, timeout);
self.set_frequency(clocks.xtal_clock.convert(), frequency, timeout); } else {
self.set_frequency(clocks.xtal_clock.convert(), frequency, timeout);
}
}
self.update_config(); self.update_config();

View File

@ -24,8 +24,10 @@
//! We reserve a number of CPU interrupts, which cannot be used; see //! We reserve a number of CPU interrupts, which cannot be used; see
//! [`RESERVED_INTERRUPTS`]. //! [`RESERVED_INTERRUPTS`].
//! //!
//! ## Examples //! ## Example
//! ### Using the Peripheral Driver to Register an Interrupt Handler //!
//! ### Using the peripheral driver to register an interrupt handler
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use core::cell::RefCell; //! # use core::cell::RefCell;

View File

@ -1,6 +1,7 @@
//! # LED Controller (LEDC) //! # LED Controller (LEDC)
//! //!
//! ## Overview //! ## Overview
//!
//! The LEDC peripheral is primarily designed to control the intensity of LEDs, //! The LEDC peripheral is primarily designed to control the intensity of LEDs,
//! although it can also be used to generate PWM signals for other purposes. It //! although it can also be used to generate PWM signals for other purposes. It
//! has multiple channels which can generate independent waveforms that can be //! has multiple channels which can generate independent waveforms that can be
@ -15,6 +16,7 @@
//! supported chips. //! supported chips.
//! //!
//! ## Examples //! ## Examples
//!
//! ### Low Speed Channel //! ### Low Speed Channel
//! The following will configure the Low Speed Channel0 to 24kHz output with //! The following will configure the Low Speed Channel0 to 24kHz output with
//! 10% duty using the ABPClock //! 10% duty using the ABPClock

View File

@ -1,6 +1,7 @@
//! # Motor Control Pulse Width Modulator (MCPWM) //! # Motor Control Pulse Width Modulator (MCPWM)
//! //!
//! ## Overview //! ## Overview
//!
//! The MCPWM peripheral is a versatile PWM generator, which contains various //! The MCPWM peripheral is a versatile PWM generator, which contains various
//! submodules to make it a key element in power electronic applications like //! submodules to make it a key element in power electronic applications like
//! motor control, digital power, and so on. Typically, the MCPWM peripheral can //! motor control, digital power, and so on. Typically, the MCPWM peripheral can
@ -13,6 +14,7 @@
//! - Generate Space Vector PWM (SVPWM) signals for Field Oriented Control (FOC) //! - Generate Space Vector PWM (SVPWM) signals for Field Oriented Control (FOC)
//! //!
//! ## Configuration //! ## Configuration
//!
//! * PWM Timers 0, 1 and 2 //! * PWM Timers 0, 1 and 2
//! * Every PWM timer has a dedicated 8-bit clock prescaler. //! * Every PWM timer has a dedicated 8-bit clock prescaler.
//! * The 16-bit counter in the PWM timer can work in count-up mode, //! * The 16-bit counter in the PWM timer can work in count-up mode,
@ -201,14 +203,17 @@ impl<'a> PeripheralClockConfig<'a> {
/// The peripheral clock frequency is calculated as: /// The peripheral clock frequency is calculated as:
/// `peripheral_clock = input_clock / (prescaler + 1)` /// `peripheral_clock = input_clock / (prescaler + 1)`
pub fn with_prescaler(clocks: &'a Clocks<'a>, prescaler: u8) -> Self { pub fn with_prescaler(clocks: &'a Clocks<'a>, prescaler: u8) -> Self {
#[cfg(esp32)] cfg_if::cfg_if! {
let source_clock = clocks.pwm_clock; if #[cfg(esp32)] {
#[cfg(esp32c6)] let source_clock = clocks.pwm_clock;
let source_clock = clocks.crypto_clock; } else if #[cfg(esp32c6)] {
#[cfg(esp32s3)] let source_clock = clocks.crypto_clock;
let source_clock = clocks.crypto_pwm_clock; } else if #[cfg(esp32s3)] {
#[cfg(esp32h2)] let source_clock = clocks.crypto_pwm_clock;
let source_clock = clocks.xtal_clock; } else if #[cfg(esp32h2)] {
let source_clock = clocks.xtal_clock;
}
}
Self { Self {
frequency: source_clock / (prescaler as u32 + 1), frequency: source_clock / (prescaler as u32 + 1),
@ -235,14 +240,17 @@ impl<'a> PeripheralClockConfig<'a> {
clocks: &'a Clocks<'a>, clocks: &'a Clocks<'a>,
target_freq: HertzU32, target_freq: HertzU32,
) -> Result<Self, FrequencyError> { ) -> Result<Self, FrequencyError> {
#[cfg(esp32)] cfg_if::cfg_if! {
let source_clock = clocks.pwm_clock; if #[cfg(esp32)] {
#[cfg(esp32c6)] let source_clock = clocks.pwm_clock;
let source_clock = clocks.crypto_clock; } else if #[cfg(esp32c6)] {
#[cfg(esp32s3)] let source_clock = clocks.crypto_clock;
let source_clock = clocks.crypto_pwm_clock; } else if #[cfg(esp32s3)] {
#[cfg(esp32h2)] let source_clock = clocks.crypto_pwm_clock;
let source_clock = clocks.xtal_clock; } else if #[cfg(esp32h2)] {
let source_clock = clocks.xtal_clock;
}
}
if target_freq.raw() == 0 || target_freq > source_clock { if target_freq.raw() == 0 || target_freq > source_clock {
return Err(FrequencyError); return Err(FrequencyError);

View File

@ -1,12 +1,14 @@
//! # Exclusive peripheral access //! # Exclusive peripheral access
//! //!
//! ## Overview //! ## Overview
//!
//! The Peripheral module provides an exclusive access mechanism to peripherals //! The Peripheral module provides an exclusive access mechanism to peripherals
//! on ESP chips. It includes the `PeripheralRef` struct, which represents an //! on ESP chips. It includes the `PeripheralRef` struct, which represents an
//! exclusive reference to a peripheral. It offers memory efficiency benefits //! exclusive reference to a peripheral. It offers memory efficiency benefits
//! for zero-sized types. //! for zero-sized types.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The `PeripheralRef` struct is used to access and interact with peripherals. //! The `PeripheralRef` struct is used to access and interact with peripherals.
//! It implements the `Deref` and `DerefMut` traits, allowing you to dereference //! It implements the `Deref` and `DerefMut` traits, allowing you to dereference
//! it to access the underlying peripheral. It also provides methods for cloning //! it to access the underlying peripheral. It also provides methods for cloning

View File

@ -228,11 +228,13 @@ where
PeripheralClockControl::reset(crate::system::Peripheral::Rmt); PeripheralClockControl::reset(crate::system::Peripheral::Rmt);
PeripheralClockControl::enable(crate::system::Peripheral::Rmt); PeripheralClockControl::enable(crate::system::Peripheral::Rmt);
#[cfg(not(any(esp32, esp32s2)))] cfg_if::cfg_if! {
me.configure_clock(frequency, _clocks)?; if #[cfg(any(esp32, esp32s2))] {
self::chip_specific::configure_clock();
#[cfg(any(esp32, esp32s2))] } else {
self::chip_specific::configure_clock(); me.configure_clock(frequency, _clocks)?;
}
}
Ok(me) Ok(me)
} }

View File

@ -25,7 +25,9 @@
//! than it would be if you included an MD5 implementation in your project. //! than it would be if you included an MD5 implementation in your project.
//! //!
//! ## Examples //! ## Examples
//! ## Compute a Full Digest From a Single Buffer //!
//! ### Compute a Full Digest From a Single Buffer
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::rom::md5; //! # use esp_hal::rom::md5;
@ -40,7 +42,8 @@
//! writeln!(uart0, "{}", d); //! writeln!(uart0, "{}", d);
//! # } //! # }
//! ``` //! ```
//! ## Compute a Digest Over Multiple Buffers //!
//! ### Compute a Digest Over Multiple Buffers
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::rom::md5; //! # use esp_hal::rom::md5;

View File

@ -1,13 +1,16 @@
//! # Real-Time Clock Control and Low-power Management (RTC_CNTL) //! # Real-Time Control and Low-power Management (RTC_CNTL)
//! //!
//! ## Overview //! ## Overview
//! The RTC_CNTL peripheral is responsible for managing the real-time clock and //!
//! low-power modes on the chip. //! The RTC_CNTL peripheral is responsible for managing the low-power modes on
//! the chip.
//! //!
//! ## Configuration //! ## Configuration
//! It also includes the necessary configurations and constants for clock //!
//! It also includes the necessary configurations and constants for clock
//! sources and low-power management. The driver provides the following features //! sources and low-power management. The driver provides the following features
//! and functionalities: //! and functionalities:
//!
//! * Clock Configuration //! * Clock Configuration
//! * Calibration //! * Calibration
//! * Low-Power Management //! * Low-Power Management

View File

@ -1,13 +1,15 @@
//! # Reading of eFuses (ESP32) //! # Reading of eFuses (ESP32)
//! //!
//! ## Overview //! ## Overview
//!
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32` chip, allowing access to various chip-specific information //! from the `ESP32` chip, allowing access to various chip-specific information
//! such as : //! such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * Chip type, revision
//! * CPU frequency //! * Core count
//! * chip type //! * Max CPU frequency
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +17,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -3,11 +3,10 @@
//! ## Overview //! ## Overview
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-C2` chip, allowing access to various chip-specific //! from the `ESP32-C2` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * ADC calibration information
//! * CPU frequency
//! * chip type
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +14,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -1,13 +1,13 @@
//! # Reading of eFuses (ESP32-C3) //! # Reading of eFuses (ESP32-C3)
//! //!
//! ## Overview //! ## Overview
//!
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-C3` chip, allowing access to various chip-specific //! from the `ESP32-C3` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * ADC calibration data
//! * CPU frequency
//! * chip type
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +15,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -3,11 +3,11 @@
//! ## Overview //! ## Overview
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-C6` chip, allowing access to various chip-specific //! from the `ESP32-C6` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * ADC calibration data
//! * CPU frequency //! * Chip version
//! * chip type
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +15,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -1,13 +1,13 @@
//! # Reading of eFuses (ESP32-H2) //! # Reading of eFuses (ESP32-H2)
//! //!
//! ## Overview //! ## Overview
//!
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-H2` chip, allowing access to various chip-specific //! from the `ESP32-H2` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * ADC calibration data
//! * CPU frequency
//! * chip type
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +15,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -1,9 +1,11 @@
//! # Reading of eFuses (ESP32-S2) //! # Reading of eFuses (ESP32-S2)
//! //!
//! ## Overview //! ## Overview
//!
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-S2` chip, allowing access to various chip-specific //! from the `ESP32-S2` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * core count
//! * CPU frequency //! * CPU frequency
@ -15,8 +17,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -1,13 +1,13 @@
//! # Reading of eFuses (ESP32-S3) //! # Reading of eFuses (ESP32-S3)
//! //!
//! ## Overview //! ## Overview
//!
//! The `efuse` module provides functionality for reading eFuse data //! The `efuse` module provides functionality for reading eFuse data
//! from the `ESP32-S3` chip, allowing access to various chip-specific //! from the `ESP32-S3` chip, allowing access to various chip-specific
//! information such as : //! information such as:
//!
//! * MAC address //! * MAC address
//! * core count //! * Chip revision
//! * CPU frequency
//! * chip type
//! //!
//! and more. It is useful for retrieving chip-specific configuration and //! and more. It is useful for retrieving chip-specific configuration and
//! identification data during runtime. //! identification data during runtime.
@ -15,8 +15,10 @@
//! The `Efuse` struct represents the eFuse peripheral and is responsible for //! The `Efuse` struct represents the eFuse peripheral and is responsible for
//! reading various eFuse fields and values. //! reading various eFuse fields and values.
//! //!
//! ## Examples //! ## Example
//!
//! ### Read chip's MAC address from the eFuse storage. //! ### Read chip's MAC address from the eFuse storage.
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::efuse::Efuse; //! # use esp_hal::efuse::Efuse;

View File

@ -1,13 +1,16 @@
//! # Serial Peripheral Interface - Master Mode //! # Serial Peripheral Interface - Master Mode
//! //!
//! ## Overview //! ## Overview
//!
//! In this mode, the SPI acts as master and initiates the SPI transactions. //! In this mode, the SPI acts as master and initiates the SPI transactions.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The peripheral can be used in full-duplex and half-duplex mode and can //! The peripheral can be used in full-duplex and half-duplex mode and can
//! leverage DMA for data transfers. It can also be used in blocking or async. //! leverage DMA for data transfers. It can also be used in blocking or async.
//! //!
//! ### Exclusive access to the SPI bus //! ### Exclusive access to the SPI bus
//!
//! If all you want to do is to communicate to a single device, and you initiate //! If all you want to do is to communicate to a single device, and you initiate
//! transactions yourself, there are a number of ways to achieve this: //! transactions yourself, there are a number of ways to achieve this:
//! //!
@ -19,17 +22,19 @@
//! - Use the `ExclusiveDevice` struct from [`embedded-hal-bus`] or `SpiDevice` //! - Use the `ExclusiveDevice` struct from [`embedded-hal-bus`] or `SpiDevice`
//! from [`embassy-embedded-hal`]. //! from [`embassy-embedded-hal`].
//! //!
//!
//! ### Shared SPI access //! ### Shared SPI access
//!
//! If you have multiple devices on the same SPI bus that each have their own CS //! If you have multiple devices on the same SPI bus that each have their own CS
//! line, you may want to have a look at the implementations provided by //! line, you may want to have a look at the implementations provided by
//! [`embedded-hal-bus`] and [`embassy-embedded-hal`]. //! [`embedded-hal-bus`] and [`embassy-embedded-hal`].
//! //!
//! ## Usage //! ## Usage
//!
//! The module implements several third-party traits from embedded-hal@0.2.x, //! The module implements several third-party traits from embedded-hal@0.2.x,
//! embedded-hal@1.x.x and embassy-embedded-hal //! embedded-hal@1.x.x and embassy-embedded-hal
//! //!
//! ## Example //! ## Example
//!
//! ### SPI Initialization //! ### SPI Initialization
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
@ -2740,11 +2745,14 @@ pub trait Instance: private::Sealed {
// taken from https://github.com/apache/incubator-nuttx/blob/8267a7618629838231256edfa666e44b5313348e/arch/risc-v/src/esp32c3/esp32c3_spi.c#L496 // taken from https://github.com/apache/incubator-nuttx/blob/8267a7618629838231256edfa666e44b5313348e/arch/risc-v/src/esp32c3/esp32c3_spi.c#L496
fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) { fn setup(&mut self, frequency: HertzU32, clocks: &Clocks<'_>) {
#[cfg(not(esp32h2))] cfg_if::cfg_if! {
let apb_clk_freq: HertzU32 = HertzU32::Hz(clocks.apb_clock.to_Hz()); if #[cfg(esp32h2)] {
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK // ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
#[cfg(esp32h2)] let apb_clk_freq = HertzU32::Hz(clocks.pll_48m_clock.to_Hz());
let apb_clk_freq: HertzU32 = HertzU32::Hz(clocks.pll_48m_clock.to_Hz()); } else {
let apb_clk_freq = HertzU32::Hz(clocks.apb_clock.to_Hz());
}
}
let reg_val: u32; let reg_val: u32;
let duty_cycle = 128; let duty_cycle = 128;

View File

@ -1,14 +1,18 @@
//! # Serial Peripheral Interface - Slave Mode //! # Serial Peripheral Interface - Slave Mode
//! //!
//! ## Overview //! ## Overview
//!
//! In this mode, the SPI acts as slave and transfers data with its master when //! In this mode, the SPI acts as slave and transfers data with its master when
//! its CS is asserted. //! its CS is asserted.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The SPI slave driver allows using full-duplex and can only be used with DMA. //! The SPI slave driver allows using full-duplex and can only be used with DMA.
//! //!
//! ## Example //! ## Example
//!
//! ### SPI Slave with DMA //! ### SPI Slave with DMA
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::dma::DmaPriority; //! # use esp_hal::dma::DmaPriority;
@ -52,6 +56,7 @@
//! ``` //! ```
//! //!
//! ## Implementation State //! ## Implementation State
//!
//! There are several options for working with the SPI peripheral in slave mode, //! There are several options for working with the SPI peripheral in slave mode,
//! but the code currently only supports single transfers (not segmented //! but the code currently only supports single transfers (not segmented
//! transfers), full duplex, single bit (not dual or quad SPI), and DMA mode //! transfers), full duplex, single bit (not dual or quad SPI), and DMA mode

View File

@ -11,7 +11,9 @@
)] )]
#![cfg_attr(feature = "esp32", doc = "See the [timg] module for more information.")] #![cfg_attr(feature = "esp32", doc = "See the [timg] module for more information.")]
//! ## Examples //! ## Examples
//!
//! ### One-shot Timer //! ### One-shot Timer
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup}; //! # use esp_hal::timer::{OneShotTimer, PeriodicTimer, timg::TimerGroup};

View File

@ -8,6 +8,7 @@
//! operating system, or simply as a general-purpose timer. //! operating system, or simply as a general-purpose timer.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The timer consists of two counters, `UNIT0` and `UNIT1`. The counter values //! The timer consists of two counters, `UNIT0` and `UNIT1`. The counter values
//! can be monitored by 3 comparators, `COMP0`, `COMP1`, and `COMP2`. //! can be monitored by 3 comparators, `COMP0`, `COMP1`, and `COMP2`.
//! //!
@ -1121,9 +1122,9 @@ pub mod etm {
//! //!
//! ## Overview //! ## Overview
//! //!
//! The system timer supports the Event Task Matrix (ETM) function, which //! The system timer supports the Event Task Matrix (ETM) function, which
//! allows the system timers ETM events to trigger any //! allows the system timers ETM events to trigger any peripherals ETM
//! peripherals ETM tasks. //! tasks.
//! //!
//! The system timer can generate the following ETM events: //! The system timer can generate the following ETM events:
//! - SYSTIMER_EVT_CNT_CMPx: Indicates the alarm pulses generated by //! - SYSTIMER_EVT_CNT_CMPx: Indicates the alarm pulses generated by
@ -1137,7 +1138,7 @@ pub mod etm {
//! let syst = SystemTimer::new(peripherals.SYSTIMER); //! let syst = SystemTimer::new(peripherals.SYSTIMER);
//! let syst_alarms = syst.split(); //! let syst_alarms = syst.split();
//! let mut alarm0 = syst_alarms.alarm0.into_periodic(); //! let mut alarm0 = syst_alarms.alarm0.into_periodic();
//! alarm0.set_period(1.secs()); //! alarm0.set_period(1u32.secs());
//! //!
//! let timer_event = SysTimerEtmEvent::new(&mut alarm0); //! let timer_event = SysTimerEtmEvent::new(&mut alarm0);
//! # } //! # }

View File

@ -1,6 +1,7 @@
//! # Timer Group (TIMG) //! # Timer Group (TIMG)
//! //!
//! ## Overview //! ## Overview
//!
//! The Timer Group (TIMG) peripherals contain one or more general-purpose //! The Timer Group (TIMG) peripherals contain one or more general-purpose
//! timers, plus one or more watchdog timers. //! timers, plus one or more watchdog timers.
//! //!
@ -8,6 +9,7 @@
//! auto-reload-capable up-down counter. //! auto-reload-capable up-down counter.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The timers have configurable alarms, which are triggered when the internal //! The timers have configurable alarms, which are triggered when the internal
//! counter of the timers reaches a specific target value. The timers are //! counter of the timers reaches a specific target value. The timers are
//! clocked using the APB clock source. //! clocked using the APB clock source.
@ -18,9 +20,10 @@
//! - Generate one-shot alarms; trigger events once //! - Generate one-shot alarms; trigger events once
//! - Free-running; fetching a high-resolution timestamp on demand //! - Free-running; fetching a high-resolution timestamp on demand
//! //!
//!
//! ## Examples //! ## Examples
//!
//! ### General-purpose Timer //! ### General-purpose Timer
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::timg::TimerGroup; //! # use esp_hal::timer::timg::TimerGroup;
@ -42,7 +45,7 @@
//! # } //! # }
//! ``` //! ```
//! //!
//! #### Watchdog Timer //! ### Watchdog Timer
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::timer::timg::TimerGroup; //! # use esp_hal::timer::timg::TimerGroup;
@ -242,12 +245,13 @@ impl TimerGroupInstance for TIMG1 {
} }
} }
impl<'d, T> TimerGroup<'d, T, Blocking> impl<'d, T, DM> TimerGroup<'d, T, DM>
where where
T: TimerGroupInstance, T: TimerGroupInstance,
DM: crate::Mode,
{ {
/// Construct a new instance of [`TimerGroup`] in blocking mode /// Construct a new instance of [`TimerGroup`] in blocking mode
pub fn new(_timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self { pub fn new_inner(_timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self {
crate::into_ref!(_timer_group); crate::into_ref!(_timer_group);
T::reset_peripheral(); T::reset_peripheral();
@ -255,15 +259,20 @@ where
T::configure_src_clk(); T::configure_src_clk();
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK cfg_if::cfg_if! {
if #[cfg(esp32h2)] {
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
let apb_clk_freq = clocks.pll_48m_clock;
} else {
let apb_clk_freq = clocks.apb_clock;
}
};
let timer0 = Timer::new( let timer0 = Timer::new(
Timer0 { Timer0 {
phantom: PhantomData, phantom: PhantomData,
}, },
#[cfg(not(esp32h2))] apb_clk_freq,
clocks.apb_clock,
#[cfg(esp32h2)]
clocks.pll_48m_clock,
); );
#[cfg(timg_timer1)] #[cfg(timg_timer1)]
@ -271,7 +280,7 @@ where
Timer1 { Timer1 {
phantom: PhantomData, phantom: PhantomData,
}, },
clocks.apb_clock, apb_clk_freq,
); );
Self { Self {
@ -284,45 +293,23 @@ where
} }
} }
impl<'d, T> TimerGroup<'d, T, Blocking>
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)
}
}
impl<'d, T> TimerGroup<'d, T, Async> impl<'d, T> TimerGroup<'d, T, Async>
where where
T: TimerGroupInstance, T: TimerGroupInstance,
{ {
/// Construct a new instance of [`TimerGroup`] in asynchronous mode /// Construct a new instance of [`TimerGroup`] in asynchronous mode
pub fn new_async(_timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self { pub fn new_async(timer_group: impl Peripheral<P = T> + 'd, clocks: &Clocks<'d>) -> Self {
crate::into_ref!(_timer_group); Self::new_inner(timer_group, clocks)
T::reset_peripheral();
T::enable_peripheral();
T::configure_src_clk();
// ESP32-H2 is using PLL_48M_CLK source instead of APB_CLK
let timer0 = Timer::new(
Timer0 {
phantom: PhantomData,
},
#[cfg(not(esp32h2))]
clocks.apb_clock,
#[cfg(esp32h2)]
clocks.pll_48m_clock,
);
#[cfg(timg_timer1)]
let timer1 = Timer::new(
Timer1 {
phantom: PhantomData,
},
clocks.apb_clock,
);
Self {
_timer_group,
timer0,
#[cfg(timg_timer1)]
timer1,
wdt: Wdt::new(),
}
} }
} }

View File

@ -1,6 +1,7 @@
//! Two-wire Automotive Interface (TWAI) Filters //! Two-wire Automotive Interface (TWAI) Filters
//! //!
//! ## Overview //! ## Overview
//!
//! The TWAI controller contains a hardware acceptance filter which can be used //! The TWAI controller contains a hardware acceptance filter which can be used
//! to filter messages of a particular ID. A node that filters out a message //! to filter messages of a particular ID. A node that filters out a message
//! does not receive the message, but will still acknowledge it. Acceptance //! does not receive the message, but will still acknowledge it. Acceptance
@ -8,6 +9,7 @@
//! the bus that are irrelevant to the node. //! the bus that are irrelevant to the node.
//! //!
//! ## Configuration //! ## Configuration
//!
//! The acceptance filters are configured using two 32-bit values known as the //! The acceptance filters are configured using two 32-bit values known as the
//! acceptance code and the acceptance mask. //! acceptance code and the acceptance mask.
@ -106,9 +108,16 @@ impl SingleStandardFilter {
/// ///
/// Example matching only even IDs, allowing any rtr value and any payload /// Example matching only even IDs, allowing any rtr value and any payload
/// data: /// data:
/// ```rust, ignore /// ```rust, no_run
#[doc = crate::before_snippet!()]
/// # use esp_hal::twai::filter::SingleStandardFilter;
/// const FILTER: SingleStandardFilter = /// const FILTER: SingleStandardFilter =
/// SingleStandardFilter::new(b"xxxxxxxxxx0", b"x", [b"xxxxxxxx", b"xxxxxxxx"]); /// SingleStandardFilter::new(
/// b"xxxxxxxxxx0",
/// b"x",
/// [b"xxxxxxxx", b"xxxxxxxx"]
/// );
/// # }
/// ``` /// ```
pub const fn new(id: &BitFilter<11>, rtr: &BitFilter<1>, payload: [&BitFilter<8>; 2]) -> Self { pub const fn new(id: &BitFilter<11>, rtr: &BitFilter<1>, payload: [&BitFilter<8>; 2]) -> Self {
// The bit values we desire to match against. This determines whether we want a // The bit values we desire to match against. This determines whether we want a

View File

@ -1,6 +1,7 @@
//! # Two-wire Automotive Interface (TWAI) //! # Two-wire Automotive Interface (TWAI)
//! //!
//! ## Overview //! ## Overview
//!
//! The TWAI is a multi-master, multi-cast communication protocol with error //! The TWAI is a multi-master, multi-cast communication protocol with error
//! detection and signaling and inbuilt message priorities and arbitration. The //! detection and signaling and inbuilt message priorities and arbitration. The
//! TWAI protocol is suited for automotive and industrial applications. //! TWAI protocol is suited for automotive and industrial applications.
@ -18,14 +19,16 @@
//! controllers. It supports Standard Frame Format (11-bit) and Extended Frame //! controllers. It supports Standard Frame Format (11-bit) and Extended Frame
//! Format (29-bit) frame identifiers. //! Format (29-bit) frame identifiers.
//! //!
//! ## Example //! ## Examples
//!
//! ### Transmitting and Receiving Messages //! ### Transmitting and Receiving Messages
//!
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::twai;
//! # use embedded_can::Id; //! # use embedded_can::Id;
//! # use esp_hal::twai::filter::SingleStandardFilter; //! # use esp_hal::twai;
//! # use esp_hal::twai::filter; //! # use esp_hal::twai::filter;
//! # use esp_hal::twai::filter::SingleStandardFilter;
//! # use esp_hal::twai::TwaiConfiguration; //! # use esp_hal::twai::TwaiConfiguration;
//! # use esp_hal::twai::BaudRate; //! # use esp_hal::twai::BaudRate;
//! # use esp_hal::twai::TwaiMode; //! # use esp_hal::twai::TwaiMode;
@ -72,13 +75,14 @@
//! } //! }
//! # } //! # }
//! ``` //! ```
//!
//! ### Self-testing (self reception of transmitted messages) //! ### Self-testing (self reception of transmitted messages)
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]
//! # use esp_hal::twai;
//! # use embedded_can::Id; //! # use embedded_can::Id;
//! # use esp_hal::twai::filter::SingleStandardFilter; //! # use esp_hal::twai;
//! # use esp_hal::twai::filter; //! # use esp_hal::twai::filter;
//! # use esp_hal::twai::filter::SingleStandardFilter;
//! # use esp_hal::twai::TwaiConfiguration; //! # use esp_hal::twai::TwaiConfiguration;
//! # use esp_hal::twai::BaudRate; //! # use esp_hal::twai::BaudRate;
//! # use esp_hal::twai::EspTwaiFrame; //! # use esp_hal::twai::EspTwaiFrame;
@ -123,7 +127,7 @@
//! // Wait for a frame to be received. //! // Wait for a frame to be received.
//! let frame = block!(can.receive()).unwrap(); //! let frame = block!(can.receive()).unwrap();
//! //!
//! loop {} //! # loop {}
//! # } //! # }
//! ``` //! ```

View File

@ -1,6 +1,7 @@
//! USB Serial/JTAG Controller (USB_SERIAL_JTAG) //! USB Serial/JTAG Controller (USB_SERIAL_JTAG)
//! //!
//! ## Overview //! ## Overview
//!
//! The USB Serial/JTAG controller can be used to program the SoC's flash, read //! The USB Serial/JTAG controller can be used to program the SoC's flash, read
//! program output, or attach a debugger to the running program. This is //! program output, or attach a debugger to the running program. This is
//! possible for any computer with a USB host (hereafter referred to as 'host'), //! possible for any computer with a USB host (hereafter referred to as 'host'),
@ -27,6 +28,7 @@
//! connect to a host computer //! connect to a host computer
//! //!
//! ## Usage //! ## Usage
//!
//! The USB Serial/JTAG driver implements a number of third-party traits, with //! The USB Serial/JTAG driver implements a number of third-party traits, with
//! the intention of making the HAL inter-compatible with various device drivers //! the intention of making the HAL inter-compatible with various device drivers
//! from the community. This includes, but is not limited to, the [embedded-hal] //! from the community. This includes, but is not limited to, the [embedded-hal]
@ -38,6 +40,7 @@
//! with this driver. //! with this driver.
//! //!
//! ## Examples //! ## Examples
//!
//! ### Sending and Receiving Data //! ### Sending and Receiving Data
//! ```rust, no_run //! ```rust, no_run
#![doc = crate::before_snippet!()] #![doc = crate::before_snippet!()]

View File

@ -91,19 +91,18 @@ async fn main(low_prio_spawner: Spawner) {
let timer0: ErasedTimer = timg0.timer0.into(); let timer0: ErasedTimer = timg0.timer0.into();
let timer0 = OneShotTimer::new(timer0); let timer0 = OneShotTimer::new(timer0);
#[cfg(not(feature = "esp32c2"))] cfg_if::cfg_if! {
let timer1 = { if #[cfg(feature = "esp32c2")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); use esp_hal::timer::systimer::{SystemTimer, Target};
let timer0: ErasedTimer = timg1.timer0.into(); let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
OneShotTimer::new(timer0) let alarm0: ErasedTimer = systimer.alarm0.into();
}; let timer1 = OneShotTimer::new(alarm0);
#[cfg(feature = "esp32c2")] } else {
let timer1 = { let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) let timer1: ErasedTimer = timg1.timer0.into();
.split::<esp_hal::timer::systimer::Target>(); let timer1 = OneShotTimer::new(timer1);
let alarm0: ErasedTimer = systimer.alarm0.into(); }
OneShotTimer::new(alarm0) }
};
let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], [timer0, timer1]); let timers = mk_static!([OneShotTimer<ErasedTimer>; 2], [timer0, timer1]);
esp_hal_embassy::init(&clocks, timers); esp_hal_embassy::init(&clocks, timers);

View File

@ -90,20 +90,21 @@ async fn main(spawner: Spawner) {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Default pins for Uart/Serial communication // Default pins for Uart/Serial communication
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
let (tx_pin, rx_pin) = (io.pins.gpio1, io.pins.gpio3); if #[cfg(feature = "esp32")] {
#[cfg(feature = "esp32c2")] let (tx_pin, rx_pin) = (io.pins.gpio1, io.pins.gpio3);
let (tx_pin, rx_pin) = (io.pins.gpio20, io.pins.gpio19); } else if #[cfg(feature = "esp32c2")] {
#[cfg(feature = "esp32c3")] let (tx_pin, rx_pin) = (io.pins.gpio20, io.pins.gpio19);
let (tx_pin, rx_pin) = (io.pins.gpio21, io.pins.gpio20); } else if #[cfg(feature = "esp32c3")] {
#[cfg(feature = "esp32c6")] let (tx_pin, rx_pin) = (io.pins.gpio21, io.pins.gpio20);
let (tx_pin, rx_pin) = (io.pins.gpio16, io.pins.gpio17); } else if #[cfg(feature = "esp32c6")] {
#[cfg(feature = "esp32h2")] let (tx_pin, rx_pin) = (io.pins.gpio16, io.pins.gpio17);
let (tx_pin, rx_pin) = (io.pins.gpio24, io.pins.gpio23); } else if #[cfg(feature = "esp32h2")] {
#[cfg(feature = "esp32s2")] let (tx_pin, rx_pin) = (io.pins.gpio24, io.pins.gpio23);
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44); } else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(feature = "esp32s3")] let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44);
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44); }
}
let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16); let config = Config::default().rx_fifo_full_threshold(READ_BUF_SIZE as u16);

View File

@ -51,10 +51,13 @@ async fn main(_spawner: Spawner) {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
#[cfg(any(feature = "esp32", feature = "esp32s2"))] cfg_if::cfg_if! {
let dma_channel = dma.spi2channel; if #[cfg(any(feature = "esp32", feature = "esp32s2"))] {
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.spi2channel;
let dma_channel = dma.channel0; } else {
let dma_channel = dma.channel0;
}
}
let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000); let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000);
let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();

View File

@ -25,10 +25,13 @@ use esp_hal::{
system::SystemControl, system::SystemControl,
}; };
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] cfg_if::cfg_if! {
static BUTTON: Mutex<RefCell<Option<Input<gpio::Gpio0>>>> = Mutex::new(RefCell::new(None)); if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] static BUTTON: Mutex<RefCell<Option<Input<gpio::Gpio0>>>> = Mutex::new(RefCell::new(None));
static BUTTON: Mutex<RefCell<Option<Input<gpio::Gpio9>>>> = Mutex::new(RefCell::new(None)); } else {
static BUTTON: Mutex<RefCell<Option<Input<gpio::Gpio9>>>> = Mutex::new(RefCell::new(None));
}
}
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -41,10 +44,13 @@ fn main() -> ! {
io.set_interrupt_handler(handler); io.set_interrupt_handler(handler);
let mut led = Output::new(io.pins.gpio2, Level::Low); let mut led = Output::new(io.pins.gpio2, Level::Low);
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] cfg_if::cfg_if! {
let button = io.pins.gpio0; if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] let button = io.pins.gpio0;
let button = io.pins.gpio9; } else {
let button = io.pins.gpio9;
}
}
let mut button = Input::new(button, Pull::Up); let mut button = Input::new(button, Pull::Up);
@ -65,13 +71,16 @@ fn main() -> ! {
#[handler] #[handler]
#[ram] #[ram]
fn handler() { fn handler() {
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] cfg_if::cfg_if! {
esp_println::println!( if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
"GPIO Interrupt with priority {}", esp_println::println!(
esp_hal::xtensa_lx::interrupt::get_level() "GPIO Interrupt with priority {}",
); esp_hal::xtensa_lx::interrupt::get_level()
#[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] );
esp_println::println!("GPIO Interrupt"); } else {
esp_println::println!("GPIO Interrupt");
}
}
if critical_section::with(|cs| { if critical_section::with(|cs| {
BUTTON BUTTON

View File

@ -67,10 +67,15 @@ fn main() -> ! {
} }
// Configure RMT peripheral globally // Configure RMT peripheral globally
#[cfg(not(feature = "esp32h2"))] cfg_if::cfg_if! {
let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks).unwrap(); if #[cfg(feature = "esp32h2")] {
#[cfg(feature = "esp32h2")] let freq = 32.MHz();
let rmt = Rmt::new(peripherals.RMT, 32.MHz(), &clocks).unwrap(); } else {
let freq = 80.MHz();
}
}
let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap();
// We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can
// be used directly with all `smart_led` implementations // be used directly with all `smart_led` implementations

View File

@ -36,20 +36,21 @@ fn main() -> ! {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Default pins for Uart/Serial communication // Default pins for Uart/Serial communication
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
let (mut tx_pin, mut rx_pin) = (io.pins.gpio1, io.pins.gpio3); if #[cfg(feature = "esp32")] {
#[cfg(feature = "esp32c2")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio1, io.pins.gpio3);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio20, io.pins.gpio19); } else if #[cfg(feature = "esp32c2")] {
#[cfg(feature = "esp32c3")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio20, io.pins.gpio19);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio21, io.pins.gpio20); } else if #[cfg(feature = "esp32c3")] {
#[cfg(feature = "esp32c6")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio21, io.pins.gpio20);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio16, io.pins.gpio17); } else if #[cfg(feature = "esp32c6")] {
#[cfg(feature = "esp32h2")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio16, io.pins.gpio17);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio24, io.pins.gpio23); } else if #[cfg(feature = "esp32h2")] {
#[cfg(feature = "esp32s2")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio24, io.pins.gpio23);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio43, io.pins.gpio44); } else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(feature = "esp32s3")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio43, io.pins.gpio44);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio43, io.pins.gpio44); }
}
let mut uart0 = let mut uart0 =
Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap();

View File

@ -29,10 +29,13 @@ fn main() -> ! {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Default pins for Uart/Serial communication // Default pins for Uart/Serial communication
#[cfg(feature = "esp32c6")] cfg_if::cfg_if! {
let (mut tx_pin, mut rx_pin) = (io.pins.gpio16, io.pins.gpio17); if #[cfg(feature = "esp32c6")] {
#[cfg(feature = "esp32h2")] let (mut tx_pin, mut rx_pin) = (io.pins.gpio16, io.pins.gpio17);
let (mut tx_pin, mut rx_pin) = (io.pins.gpio24, io.pins.gpio23); } else if #[cfg(feature = "esp32h2")] {
let (mut tx_pin, mut rx_pin) = (io.pins.gpio24, io.pins.gpio23);
}
}
let mut uart0 = let mut uart0 =
Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap(); Uart::new_with_default_pins(peripherals.UART0, &clocks, &mut tx_pin, &mut rx_pin).unwrap();

View File

@ -29,10 +29,15 @@ fn main() -> ! {
let pin = io.pins.gpio0; let pin = io.pins.gpio0;
// initialize peripheral // initialize peripheral
#[cfg(feature = "esp32h2")] cfg_if::cfg_if! {
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap(); if #[cfg(feature = "esp32h2")] {
#[cfg(not(feature = "esp32h2"))] let freq = 40.MHz();
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap(); } else {
let freq = 32.MHz();
}
}
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, freq).unwrap();
let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg); let mut mcpwm = McPwm::new(peripherals.MCPWM0, clock_cfg);

View File

@ -71,10 +71,14 @@ fn main() -> ! {
} }
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
#[cfg(any(feature = "esp32", feature = "esp32s2"))]
let dma_channel = dma.spi2channel; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))] if #[cfg(any(feature = "esp32", feature = "esp32s2"))] {
let dma_channel = dma.channel0; let dma_channel = dma.spi2channel;
} else {
let dma_channel = dma.channel0;
}
}
let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(256, 320); let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(256, 320);
let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();

View File

@ -38,20 +38,21 @@ fn main() -> ! {
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
// Default pins for Uart/Serial communication // Default pins for Uart/Serial communication
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
let (tx_pin, rx_pin) = (io.pins.gpio1, io.pins.gpio3); if #[cfg(feature = "esp32")] {
#[cfg(feature = "esp32c2")] let (tx_pin, rx_pin) = (io.pins.gpio1, io.pins.gpio3);
let (tx_pin, rx_pin) = (io.pins.gpio20, io.pins.gpio19); } else if #[cfg(feature = "esp32c2")] {
#[cfg(feature = "esp32c3")] let (tx_pin, rx_pin) = (io.pins.gpio20, io.pins.gpio19);
let (tx_pin, rx_pin) = (io.pins.gpio21, io.pins.gpio20); } else if #[cfg(feature = "esp32c3")] {
#[cfg(feature = "esp32c6")] let (tx_pin, rx_pin) = (io.pins.gpio21, io.pins.gpio20);
let (tx_pin, rx_pin) = (io.pins.gpio16, io.pins.gpio17); } else if #[cfg(feature = "esp32c6")] {
#[cfg(feature = "esp32h2")] let (tx_pin, rx_pin) = (io.pins.gpio16, io.pins.gpio17);
let (tx_pin, rx_pin) = (io.pins.gpio24, io.pins.gpio23); } else if #[cfg(feature = "esp32h2")] {
#[cfg(feature = "esp32s2")] let (tx_pin, rx_pin) = (io.pins.gpio24, io.pins.gpio23);
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44); } else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(feature = "esp32s3")] let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44);
let (tx_pin, rx_pin) = (io.pins.gpio43, io.pins.gpio44); }
}
let config = Config::default().rx_fifo_full_threshold(30); let config = Config::default().rx_fifo_full_threshold(30);
let mut uart0 = let mut uart0 =

View File

@ -52,15 +52,18 @@ fn main() -> ! {
let delay = Delay::new(&clocks); let delay = Delay::new(&clocks);
let timer = TimerWakeupSource::new(Duration::from_secs(10)); let timer = TimerWakeupSource::new(Duration::from_secs(10));
#[cfg(feature = "esp32c3")] cfg_if::cfg_if! {
let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [ if #[cfg(feature = "esp32c3")] {
(&mut io.pins.gpio2, WakeupLevel::Low), let wakeup_pins: &mut [(&mut dyn gpio::RtcPinWithResistors, WakeupLevel)] = &mut [
(&mut io.pins.gpio3, WakeupLevel::High), (&mut io.pins.gpio2, WakeupLevel::Low),
]; (&mut io.pins.gpio3, WakeupLevel::High),
];
#[cfg(feature = "esp32s3")] } else if #[cfg(feature = "esp32s3")] {
let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = let wakeup_pins: &mut [(&mut dyn gpio::RtcPin, WakeupLevel)] = &mut [
&mut [(&mut io.pins.gpio18, WakeupLevel::Low)]; (&mut io.pins.gpio18, WakeupLevel::Low)
];
}
}
let rtcio = RtcioWakeupSource::new(wakeup_pins); let rtcio = RtcioWakeupSource::new(wakeup_pins);
println!("sleeping!"); println!("sleeping!");

View File

@ -46,10 +46,13 @@ fn main() -> ! {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
#[cfg(any(feature = "esp32", feature = "esp32s2"))] cfg_if::cfg_if! {
let dma_channel = dma.spi2channel; if #[cfg(any(feature = "esp32", feature = "esp32s2"))] {
#[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.spi2channel;
let dma_channel = dma.channel0; } else {
let dma_channel = dma.channel0;
}
}
let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000); let (tx_buffer, tx_descriptors, rx_buffer, rx_descriptors) = dma_buffers!(32000);
let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(); let mut dma_tx_buf = DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap();

View File

@ -56,15 +56,14 @@ fn main() -> ! {
.unwrap(); .unwrap();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))]
let button = Input::new(io.pins.gpio0, Pull::Down); cfg_if::cfg_if! {
#[cfg(any( if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
feature = "esp32c2", let button = Input::new(io.pins.gpio0, Pull::Down);
feature = "esp32c3", } else {
feature = "esp32c6", let button = Input::new(io.pins.gpio9, Pull::Down);
feature = "esp32h2" }
))] }
let button = Input::new(io.pins.gpio9, Pull::Down);
let mut debounce_cnt = 500; let mut debounce_cnt = 500;

View File

@ -83,17 +83,15 @@ async fn main(spawner: Spawner) -> ! {
let (wifi_interface, controller) = let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap(); esp_wifi::wifi::new_with_mode(&init, wifi, WifiApDevice).unwrap();
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let config = Config::ipv4_static(StaticConfigV4 { let config = Config::ipv4_static(StaticConfigV4 {

View File

@ -91,17 +91,15 @@ async fn main(spawner: Spawner) -> ! {
let (wifi_ap_interface, wifi_sta_interface, mut controller) = let (wifi_ap_interface, wifi_sta_interface, mut controller) =
esp_wifi::wifi::new_ap_sta(&init, wifi).unwrap(); esp_wifi::wifi::new_ap_sta(&init, wifi).unwrap();
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let ap_config = Config::ipv4_static(StaticConfigV4 { let ap_config = Config::ipv4_static(StaticConfigV4 {

View File

@ -95,17 +95,15 @@ async fn main(spawner: Spawner) -> ! {
let (wifi_interface, controller) = let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let config = Config::dhcpv4(Default::default()); let config = Config::dhcpv4(Default::default());

View File

@ -58,27 +58,23 @@ async fn main(_spawner: Spawner) -> ! {
.unwrap(); .unwrap();
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] cfg_if::cfg_if! {
let button = Input::new(io.pins.gpio0, Pull::Down); if #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] {
#[cfg(any( let button = Input::new(io.pins.gpio0, Pull::Down);
feature = "esp32c2", } else {
feature = "esp32c3", let button = Input::new(io.pins.gpio9, Pull::Down);
feature = "esp32c6", }
feature = "esp32h2"
))]
let button = Input::new(io.pins.gpio9, Pull::Down);
#[cfg(feature = "esp32")]
{
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0);
} }
#[cfg(not(feature = "esp32"))] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
.split::<esp_hal::timer::systimer::Target>(); esp_hal_embassy::init(&clocks, timg1.timer0);
esp_hal_embassy::init(&clocks, systimer.alarm0); } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
}
} }
let mut bluetooth = peripherals.BT; let mut bluetooth = peripherals.BT;

View File

@ -76,17 +76,15 @@ async fn main(spawner: Spawner) -> ! {
let (wifi_interface, controller) = let (wifi_interface, controller) =
esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap(); esp_wifi::wifi::new_with_mode(&init, wifi, WifiStaDevice).unwrap();
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let config = Config::dhcpv4(Default::default()); let config = Config::dhcpv4(Default::default());

View File

@ -52,17 +52,15 @@ async fn main(_spawner: Spawner) -> ! {
let mut esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap(); let mut esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap();
println!("esp-now version {}", esp_now.get_version().unwrap()); println!("esp-now version {}", esp_now.get_version().unwrap());
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let mut ticker = Ticker::every(Duration::from_secs(5)); let mut ticker = Ticker::every(Duration::from_secs(5));

View File

@ -62,17 +62,15 @@ async fn main(spawner: Spawner) -> ! {
let esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap(); let esp_now = esp_wifi::esp_now::EspNow::new(&init, wifi).unwrap();
println!("esp-now version {}", esp_now.get_version().unwrap()); println!("esp-now version {}", esp_now.get_version().unwrap());
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks);
esp_hal_embassy::init(&clocks, timg1.timer0); esp_hal_embassy::init(&clocks, timg1.timer0);
} } else {
use esp_hal::timer::systimer::{SystemTimer, Target};
#[cfg(not(feature = "esp32"))] let systimer = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
{ esp_hal_embassy::init(&clocks, systimer.alarm0);
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER) }
.split::<esp_hal::timer::systimer::Target>();
esp_hal_embassy::init(&clocks, systimer.alarm0);
} }
let (manager, sender, receiver) = esp_now.split(); let (manager, sender, receiver) = esp_now.split();

View File

@ -41,11 +41,24 @@ mod tests {
#[test] #[test]
fn test_estimated_clock(mut ctx: Context<'static>) { fn test_estimated_clock(mut ctx: Context<'static>) {
#[cfg(feature = "esp32c2")] // 26 MHz cfg_if::cfg_if! {
defmt::assert!((23..=29).contains(&ctx.rtc.estimate_xtal_frequency())); if #[cfg(feature = "esp32c2")] {
#[cfg(feature = "esp32h2")] // 32 MHz // 26 MHz
defmt::assert!((29..=35).contains(&ctx.rtc.estimate_xtal_frequency())); let expected_range = 23..=29;
#[cfg(not(any(feature = "esp32h2", feature = "esp32c2")))] // 40 MHz } else if #[cfg(feature = "esp32h2")] {
defmt::assert!((35..=45).contains(&ctx.rtc.estimate_xtal_frequency())); // 32 MHz
let expected_range = 29..=35;
} else {
// 40 MHz
let expected_range = 35..=45;
}
}
let measured_frequency = ctx.rtc.estimate_xtal_frequency();
defmt::assert!(
expected_range.contains(&measured_frequency),
"Measured frequency: {}",
measured_frequency
);
} }
} }

View File

@ -38,10 +38,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let mut mem2mem = let mut mem2mem =
Mem2Mem::new(channel, dma_peripheral, tx_descriptors, rx_descriptors).unwrap(); Mem2Mem::new(channel, dma_peripheral, tx_descriptors, rx_descriptors).unwrap();
@ -68,10 +72,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let mut mem2mem = Mem2Mem::new_with_chunk_size( let mut mem2mem = Mem2Mem::new_with_chunk_size(
channel, channel,
@ -102,10 +110,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let (tx_descriptors, rx_descriptors) = dma_descriptors!(0, 1024); let (tx_descriptors, rx_descriptors) = dma_descriptors!(0, 1024);
match Mem2Mem::new_with_chunk_size( match Mem2Mem::new_with_chunk_size(
@ -130,10 +142,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 0); let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 0);
match Mem2Mem::new_with_chunk_size( match Mem2Mem::new_with_chunk_size(
@ -156,10 +172,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024); let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024);
match Mem2Mem::new_with_chunk_size( match Mem2Mem::new_with_chunk_size(
@ -182,10 +202,14 @@ mod tests {
let dma = Dma::new(peripherals.DMA); let dma = Dma::new(peripherals.DMA);
let channel = dma.channel0.configure(false, DmaPriority::Priority0); let channel = dma.channel0.configure(false, DmaPriority::Priority0);
#[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))]
let dma_peripheral = peripherals.SPI2; cfg_if::cfg_if! {
#[cfg(not(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3")))] if #[cfg(any(feature = "esp32c2", feature = "esp32c3", feature = "esp32s3"))] {
let dma_peripheral = peripherals.MEM2MEM1; let dma_peripheral = peripherals.SPI2;
} else {
let dma_peripheral = peripherals.MEM2MEM1;
}
}
let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024); let (tx_descriptors, rx_descriptors) = dma_descriptors!(1024, 1024);
match Mem2Mem::new_with_chunk_size( match Mem2Mem::new_with_chunk_size(

View File

@ -25,15 +25,6 @@ use esp_hal::{
}; };
use hil_test as _; use hil_test as _;
macro_rules! mk_static {
($t:ty,$val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
#[deny(unused_attributes)]
let x = STATIC_CELL.uninit().write(($val));
x
}};
}
static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0)); static COUNTER: Mutex<RefCell<u32>> = Mutex::new(RefCell::new(0));
static INPUT_PIN: Mutex<RefCell<Option<Input<'static, Gpio2>>>> = Mutex::new(RefCell::new(None)); static INPUT_PIN: Mutex<RefCell<Option<Input<'static, Gpio2>>>> = Mutex::new(RefCell::new(None));

View File

@ -145,21 +145,20 @@ mod tests {
let operand_a = BIGNUM_1.as_words(); let operand_a = BIGNUM_1.as_words();
let operand_b = BIGNUM_2.as_words(); let operand_b = BIGNUM_2.as_words();
#[cfg(feature = "esp32")] cfg_if::cfg_if! {
{ if #[cfg(feature = "esp32")] {
let mut rsamulti = let mut rsamulti =
RsaMultiplication::<operand_sizes::Op512, esp_hal::Blocking>::new(&mut ctx.rsa); RsaMultiplication::<operand_sizes::Op512, esp_hal::Blocking>::new(&mut ctx.rsa);
rsamulti.start_multiplication(operand_a, operand_b); rsamulti.start_multiplication(operand_a, operand_b);
rsamulti.read_results(&mut outbuf); rsamulti.read_results(&mut outbuf);
} } else {
#[cfg(not(feature = "esp32"))] let mut rsamulti = RsaMultiplication::<operand_sizes::Op512, esp_hal::Blocking>::new(
{ &mut ctx.rsa,
let mut rsamulti = RsaMultiplication::<operand_sizes::Op512, esp_hal::Blocking>::new( operand_a,
&mut ctx.rsa, );
operand_a, rsamulti.start_multiplication(operand_b);
); rsamulti.read_results(&mut outbuf);
rsamulti.start_multiplication(operand_b); }
rsamulti.read_results(&mut outbuf);
} }
assert_eq!(EXPECTED_OUTPUT, outbuf) assert_eq!(EXPECTED_OUTPUT, outbuf)
} }