diff --git a/esp-hal-common/build.rs b/esp-hal-common/build.rs index 7037f198f..0cceb0159 100644 --- a/esp-hal-common/build.rs +++ b/esp-hal-common/build.rs @@ -55,7 +55,14 @@ fn main() { "uart2", ] } else if esp32c2 { - vec!["esp32c2", "riscv", "single_core", "gdma", "systimer", "timg0"] + vec![ + "esp32c2", + "riscv", + "single_core", + "gdma", + "systimer", + "timg0", + ] } else if esp32c3 { vec![ "esp32c3", diff --git a/esp-hal-common/src/embassy/time_driver_systimer.rs b/esp-hal-common/src/embassy/time_driver_systimer.rs index fbc01d0b0..56c528196 100644 --- a/esp-hal-common/src/embassy/time_driver_systimer.rs +++ b/esp-hal-common/src/embassy/time_driver_systimer.rs @@ -75,7 +75,11 @@ impl EmbassyTimer { } } - pub(crate) fn set_alarm(&self, alarm: embassy_time::driver::AlarmHandle, timestamp: u64) -> bool { + pub(crate) fn set_alarm( + &self, + alarm: embassy_time::driver::AlarmHandle, + timestamp: u64, + ) -> bool { critical_section::with(|cs| { let now = Self::now(); let alarm_state = unsafe { self.alarms.borrow(cs).get_unchecked(alarm.id() as usize) }; @@ -108,7 +112,7 @@ impl EmbassyTimer { } fn disable_interrupt(&self, id: u8) { - match id { + match id { 0 => self.alarm0.interrupt_enable(false), 1 => self.alarm1.interrupt_enable(false), 2 => self.alarm2.interrupt_enable(false), diff --git a/esp-hal-common/src/embassy/time_driver_timg.rs b/esp-hal-common/src/embassy/time_driver_timg.rs index 4695b455d..5462e62b9 100644 --- a/esp-hal-common/src/embassy/time_driver_timg.rs +++ b/esp-hal-common/src/embassy/time_driver_timg.rs @@ -68,7 +68,11 @@ impl EmbassyTimer { } } - pub(crate) fn set_alarm(&self, alarm: embassy_time::driver::AlarmHandle, timestamp: u64) -> bool { + pub(crate) fn set_alarm( + &self, + alarm: embassy_time::driver::AlarmHandle, + timestamp: u64, + ) -> bool { critical_section::with(|cs| { let now = Self::now(); let alarm_state = unsafe { self.alarms.borrow(cs).get_unchecked(alarm.id() as usize) }; @@ -87,7 +91,7 @@ impl EmbassyTimer { tg.set_auto_reload(false); tg.set_counter_active(true); tg.set_alarm_active(true); - + true }) } diff --git a/esp-hal-common/src/interrupt/xtensa.rs b/esp-hal-common/src/interrupt/xtensa.rs index 063cd88a3..cd7e013b7 100644 --- a/esp-hal-common/src/interrupt/xtensa.rs +++ b/esp-hal-common/src/interrupt/xtensa.rs @@ -340,7 +340,9 @@ mod vectored { const CPU_INTERRUPT_EDGE: u32 = 0b_0111_0000_0100_0000_0000_1100_1000_0000; #[inline] - fn cpu_interrupt_nr_to_cpu_interrupt_handler(number: u32) -> Option { + fn cpu_interrupt_nr_to_cpu_interrupt_handler( + number: u32, + ) -> Option { use xtensa_lx_rt::*; // we're fortunate that all esp variants use the same CPU interrupt layout Some(match number { diff --git a/esp-hal-common/src/lib.rs b/esp-hal-common/src/lib.rs index 53971c79d..614beea78 100644 --- a/esp-hal-common/src/lib.rs +++ b/esp-hal-common/src/lib.rs @@ -22,15 +22,23 @@ #![cfg_attr(xtensa, feature(asm_experimental_arch))] #[cfg(esp32)] -pub use esp32 as pac; +pub(crate) use esp32 as pac; #[cfg(esp32c2)] -pub use esp32c2 as pac; +pub(crate) use esp32c2 as pac; #[cfg(esp32c3)] -pub use esp32c3 as pac; +pub(crate) use esp32c3 as pac; #[cfg(esp32s2)] -pub use esp32s2 as pac; +pub(crate) use esp32s2 as pac; #[cfg(esp32s3)] -pub use esp32s3 as pac; +pub(crate) use esp32s3 as pac; + +#[cfg_attr(esp32, path = "peripherals/esp32.rs")] +#[cfg_attr(esp32c3, path = "peripherals/esp32c3.rs")] +#[cfg_attr(esp32c2, path = "peripherals/esp32c2.rs")] +#[cfg_attr(esp32s2, path = "peripherals/esp32s2.rs")] +#[cfg_attr(esp32s3, path = "peripherals/esp32s3.rs")] +pub mod peripherals; + pub use procmacros as macros; #[cfg(rmt)] @@ -43,9 +51,9 @@ pub use self::{ interrupt::*, rng::Rng, rtc_cntl::{Rtc, Rwdt}, - serial::Serial, spi::Spi, timer::Timer, + uart::Uart, }; pub mod analog; @@ -63,19 +71,20 @@ pub mod ledc; pub mod mcpwm; #[cfg(usb_otg)] pub mod otg_fs; +pub mod peripheral; pub mod prelude; #[cfg(rmt)] pub mod pulse_control; pub mod rng; pub mod rom; pub mod rtc_cntl; -pub mod serial; pub mod sha; pub mod spi; pub mod system; #[cfg(systimer)] pub mod systimer; pub mod timer; +pub mod uart; #[cfg(usb_serial_jtag)] pub mod usb_serial_jtag; #[cfg(rmt)] diff --git a/esp-hal-common/src/peripheral.rs b/esp-hal-common/src/peripheral.rs new file mode 100644 index 000000000..52cb5c469 --- /dev/null +++ b/esp-hal-common/src/peripheral.rs @@ -0,0 +1,308 @@ +use core::{ + marker::PhantomData, + ops::{Deref, DerefMut}, +}; + +/// An exclusive reference to a peripheral. +/// +/// This is functionally the same as a `&'a mut T`. The reason for having a +/// dedicated struct is memory efficiency: +/// +/// Peripheral singletons are typically either zero-sized (for concrete +/// peripehrals like `PA9` or `Spi4`) or very small (for example `AnyPin` which +/// is 1 byte). However `&mut T` is always 4 bytes for 32-bit targets, even if T +/// is zero-sized. PeripheralRef stores a copy of `T` instead, so it's the same +/// size. +/// +/// but it is the size of `T` not the size +/// of a pointer. This is useful if T is a zero sized type. +pub struct PeripheralRef<'a, T> { + inner: T, + _lifetime: PhantomData<&'a mut T>, +} + +impl<'a, T> PeripheralRef<'a, T> { + #[inline] + pub fn new(inner: T) -> Self { + Self { + inner, + _lifetime: PhantomData, + } + } + + /// Unsafely clone (duplicate) a peripheral singleton. + /// + /// # Safety + /// + /// This returns an owned clone of the peripheral. You must manually ensure + /// only one copy of the peripheral is in use at a time. For example, don't + /// create two SPI drivers on `SPI1`, because they will "fight" each other. + /// + /// You should strongly prefer using `reborrow()` instead. It returns a + /// `PeripheralRef` that borrows `self`, which allows the borrow checker + /// to enforce this at compile time. + pub unsafe fn clone_unchecked(&mut self) -> PeripheralRef<'a, T> + where + T: Peripheral

, + { + PeripheralRef::new(self.inner.clone_unchecked()) + } + + /// Reborrow into a "child" PeripheralRef. + /// + /// `self` will stay borrowed until the child PeripheralRef is dropped. + pub fn reborrow(&mut self) -> PeripheralRef<'_, T> + where + T: Peripheral

, + { + // safety: we're returning the clone inside a new PeripheralRef that borrows + // self, so user code can't use both at the same time. + PeripheralRef::new(unsafe { self.inner.clone_unchecked() }) + } + + /// Map the inner peripheral using `Into`. + /// + /// This converts from `PeripheralRef<'a, T>` to `PeripheralRef<'a, U>`, + /// using an `Into` impl to convert from `T` to `U`. + /// + /// For example, this can be useful to degrade GPIO pins: converting from + /// PeripheralRef<'a, PB11>` to `PeripheralRef<'a, AnyPin>`. + #[inline] + pub fn map_into(self) -> PeripheralRef<'a, U> + where + T: Into, + { + PeripheralRef { + inner: self.inner.into(), + _lifetime: PhantomData, + } + } +} + +impl<'a, T> Deref for PeripheralRef<'a, T> { + type Target = T; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl<'a, T> DerefMut for PeripheralRef<'a, T> { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.inner + } +} + +/// Trait for any type that can be used as a peripheral of type `P`. +/// +/// This is used in driver constructors, to allow passing either owned +/// peripherals (e.g. `TWISPI0`), or borrowed peripherals (e.g. `&mut TWISPI0`). +/// +/// For example, if you have a driver with a constructor like this: +/// +/// ```ignore +/// impl<'d, T: Instance> Twim<'d, T> { +/// pub fn new( +/// twim: impl Peripheral

+ 'd, +/// irq: impl Peripheral

+ 'd, +/// sda: impl Peripheral

+ 'd, +/// scl: impl Peripheral

+ 'd, +/// config: Config, +/// ) -> Self { .. } +/// } +/// ``` +/// +/// You may call it with owned peripherals, which yields an instance that can +/// live forever (`'static`): +/// +/// ```ignore +/// let mut twi: Twim<'static, ...> = Twim::new(p.TWISPI0, irq, p.P0_03, p.P0_04, config); +/// ``` +/// +/// Or you may call it with borrowed peripherals, which yields an instance that +/// can only live for as long as the borrows last: +/// +/// ```ignore +/// let mut twi: Twim<'_, ...> = Twim::new(&mut p.TWISPI0, &mut irq, &mut p.P0_03, &mut p.P0_04, config); +/// ``` +/// +/// # Implementation details, for HAL authors +/// +/// When writing a HAL, the intended way to use this trait is to take `impl +/// Peripheral

` in the HAL's public API (such as driver constructors), +/// calling `.into_ref()` to obtain a `PeripheralRef`, and storing that in the +/// driver struct. +/// +/// `.into_ref()` on an owned `T` yields a `PeripheralRef<'static, T>`. +/// `.into_ref()` on an `&'a mut T` yields a `PeripheralRef<'a, T>`. +pub trait Peripheral: Sized + sealed::Sealed { + /// Peripheral singleton type + type P; + + /// Unsafely clone (duplicate) a peripheral singleton. + /// + /// # Safety + /// + /// This returns an owned clone of the peripheral. You must manually ensure + /// only one copy of the peripheral is in use at a time. For example, don't + /// create two SPI drivers on `SPI1`, because they will "fight" each other. + /// + /// You should strongly prefer using `into_ref()` instead. It returns a + /// `PeripheralRef`, which allows the borrow checker to enforce this at + /// compile time. + unsafe fn clone_unchecked(&mut self) -> Self::P; + + /// Convert a value into a `PeripheralRef`. + /// + /// When called on an owned `T`, yields a `PeripheralRef<'static, T>`. + /// When called on an `&'a mut T`, yields a `PeripheralRef<'a, T>`. + #[inline] + fn into_ref<'a>(mut self) -> PeripheralRef<'a, Self::P> + where + Self: 'a, + { + PeripheralRef::new(unsafe { self.clone_unchecked() }) + } +} + +impl sealed::Sealed for T {} + +pub(crate) mod sealed { + pub trait Sealed {} +} + +mod peripheral_macros { + #[macro_export] + macro_rules! peripherals { + ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { + #[allow(non_snake_case)] + pub struct Peripherals { + $( + $(#[$cfg])? + pub $name: peripherals::$name, + )* + } + + impl Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Self { + + #[no_mangle] + static mut _ESP_HAL_DEVICE_PERIPHERALS: bool = false; + + critical_section::with(|_| unsafe { + if _ESP_HAL_DEVICE_PERIPHERALS { + panic!("init called more than once!") + } + _ESP_HAL_DEVICE_PERIPHERALS = true; + Self::steal() + }) + } + } + + impl Peripherals { + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a time. + #[inline] + pub unsafe fn steal() -> Self { + Self { + $( + $(#[$cfg])? + // $name: peripherals::$name::steal(), // FIXME add this back once we have removed pac::Peripherals completely + $name: unsafe { core::mem::zeroed() }, // this is well defined for zero sized types: https://github.com/rust-lang/unsafe-code-guidelines/issues/250 + )* + } + } + } + + // expose the new structs + $( + pub use peripherals::$name; + )* + } + } + + #[macro_export] + macro_rules! create_peripherals { + ($($(#[$cfg:meta])? $name:ident),*$(,)?) => { + $( + $(#[$cfg])? + #[derive(Debug)] + #[allow(non_camel_case_types)] + pub struct $name { _inner: () } + + $(#[$cfg])? + impl $name { + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a time. + #[inline] + pub unsafe fn steal() -> Self { + Self { _inner: () } + } + + #[doc = r"Pointer to the register block"] + pub const PTR: *const ::Target = super::pac::$name::PTR; + + #[doc = r"Return the pointer to the register block"] + #[inline(always)] + pub const fn ptr() -> *const ::Target { + super::pac::$name::PTR + } + } + + impl core::ops::Deref for $name { + type Target = ::Target; + + fn deref(&self) -> &Self::Target { + unsafe { &*Self::PTR } + } + } + + impl core::ops::DerefMut for $name { + + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *(Self::PTR as *mut _) } + } + } + + impl crate::peripheral::Peripheral for $name { + type P = $name; + + #[inline] + unsafe fn clone_unchecked(&mut self) -> Self::P { + Self::steal() + } + } + + impl crate::peripheral::Peripheral for &mut $name { + type P = $name; + + #[inline] + unsafe fn clone_unchecked(&mut self) -> Self::P { + $name::steal() + } + } + + + )* + } + } + + #[macro_export] + macro_rules! into_ref { + ($($name:ident),*) => { + $( + let $name = $name.into_ref(); + )* + } +} +} diff --git a/esp-hal-common/src/peripherals/esp32.rs b/esp-hal-common/src/peripherals/esp32.rs new file mode 100644 index 000000000..a785fa76f --- /dev/null +++ b/esp-hal-common/src/peripherals/esp32.rs @@ -0,0 +1,58 @@ +pub use pac::Interrupt; + +use crate::pac; // We need to export this for users to use + +crate::peripherals! { + AES, + APB_CTRL, + BB, + DPORT, + EFUSE, + FLASH_ENCRYPTION, + FRC_TIMER, + GPIO, + GPIO_SD, + HINF, + I2C0, + I2C1, + I2S0, + I2S1, + IO_MUX, + LEDC, + PWM0, + PWM1, + NRX, + PCNT, + RMT, + RNG, + RSA, + RTC_CNTL, + RTCIO, + RTC_I2C, + SDMMC, + SENS, + SHA, + SLC, + SLCHOST, + SPI0, + SPI1, + SPI2, + SPI3, + TIMG0, + TIMG1, + TWAI, + UART0, + UART1, + UART2, + UHCI0, + UHCI1, +} + +mod peripherals { + pub use super::pac::*; + + crate::create_peripherals! { + UART0, + UART1, + } +} diff --git a/esp-hal-common/src/peripherals/esp32c2.rs b/esp-hal-common/src/peripherals/esp32c2.rs new file mode 100644 index 000000000..0ccff88a2 --- /dev/null +++ b/esp-hal-common/src/peripherals/esp32c2.rs @@ -0,0 +1,40 @@ +pub use pac::Interrupt; + +use crate::pac; // We need to export this for users to use + +crate::peripherals! { + APB_CTRL, + APB_SARADC, + ASSIST_DEBUG, + DMA, + ECC, + EFUSE, + EXTMEM, + GPIO, + I2C0, + INTERRUPT_CORE0, + IO_MUX, + LEDC, + RNG, + RTC_CNTL, + SENSITIVE, + SHA, + SPI0, + SPI1, + SPI2, + SYSTEM, + SYSTIMER, + TIMG0, + UART0, + UART1, + XTS_AES, +} + +mod peripherals { + pub use super::pac::*; + + crate::create_peripherals! { + UART0, + UART1, + } +} diff --git a/esp-hal-common/src/peripherals/esp32c3.rs b/esp-hal-common/src/peripherals/esp32c3.rs new file mode 100644 index 000000000..ed6181fc8 --- /dev/null +++ b/esp-hal-common/src/peripherals/esp32c3.rs @@ -0,0 +1,51 @@ +pub use pac::Interrupt; + +use crate::pac; // We need to export this for users to use + +crate::peripherals! { + AES, + APB_CTRL, + APB_SARADC, + ASSIST_DEBUG, + DMA, + DS, + EFUSE, + EXTMEM, + GPIO, + GPIOSD, + HMAC, + I2C0, + I2S, + INTERRUPT_CORE0, + IO_MUX, + LEDC, + RMT, + RNG, + RSA, + RTC_CNTL, + SENSITIVE, + SHA, + SPI0, + SPI1, + SPI2, + SYSTEM, + SYSTIMER, + TIMG0, + TIMG1, + TWAI, + UART0, + UART1, + UHCI0, + UHCI1, + USB_DEVICE, + XTS_AES, +} + +mod peripherals { + pub use super::pac::*; + + crate::create_peripherals! { + UART0, + UART1, + } +} diff --git a/esp-hal-common/src/peripherals/esp32s2.rs b/esp-hal-common/src/peripherals/esp32s2.rs new file mode 100644 index 000000000..7bccc7922 --- /dev/null +++ b/esp-hal-common/src/peripherals/esp32s2.rs @@ -0,0 +1,56 @@ +pub use pac::Interrupt; + +use crate::pac; // We need to export this for users to use + +crate::peripherals! { + AES, + APB_SARADC, + DEDICATED_GPIO, + DS, + EFUSE, + EXTMEM, + GPIO, + GPIO_SD, + HMAC, + I2C0, + I2C1, + I2S, + INTERRUPT, + IO_MUX, + LEDC, + PCNT, + PMS, + RMT, + RNG, + RSA, + RTCIO, + RTC_CNTL, + RTC_I2C, + SENS, + SHA, + SPI0, + SPI1, + SPI2, + SPI3, + SPI4, + SYSTEM, + SYSTIMER, + TIMG0, + TIMG1, + TWAI, + UART0, + UART1, + UHCI0, + USB0, + USB_WRAP, + XTS_AES, +} + +mod peripherals { + pub use super::pac::*; + + crate::create_peripherals! { + UART0, + UART1, + } +} diff --git a/esp-hal-common/src/peripherals/esp32s3.rs b/esp-hal-common/src/peripherals/esp32s3.rs new file mode 100644 index 000000000..8edfe1f41 --- /dev/null +++ b/esp-hal-common/src/peripherals/esp32s3.rs @@ -0,0 +1,67 @@ +pub use pac::Interrupt; + +use crate::pac; // We need to export this for users to use + +crate::peripherals! { + AES, + APB_CTRL, + APB_SARADC, + DEBUG_ASSIST, + DMA, + DS, + EFUSE, + EXTMEM, + GPIO, + GPIOSD, + HMAC, + I2C0, + I2C1, + I2S0, + I2S1, + INTERRUPT_CORE0, + INTERRUPT_CORE1, + IO_MUX, + LCD_CAM, + LEDC, + PCNT, + PERI_BACKUP, + PWM0, + PWM1, + RMT, + RNG, + RSA, + RTC_CNTL, + RTC_I2C, + RTCIO, + SENS, + SENSITIVE, + SHA, + SPI0, + SPI1, + SPI2, + SPI3, + SYSTEM, + SYSTIMER, + TIMG0, + TIMG1, + TWAI, + UART0, + UART1, + UART2, + UHCI0, + UHCI1, + USB0, + USB_DEVICE, + USB_WRAP, + WCL, + XTS_AES, +} + +mod peripherals { + pub use super::pac::*; + + crate::create_peripherals! { + UART0, + UART1, + } +} diff --git a/esp-hal-common/src/prelude.rs b/esp-hal-common/src/prelude.rs index aefd61d1a..93b82971a 100644 --- a/esp-hal-common/src/prelude.rs +++ b/esp-hal-common/src/prelude.rs @@ -54,7 +54,6 @@ pub use crate::{ }, }, macros::*, - serial::{Instance as _esp_hal_serial_Instance, UartPins as _esp_hal_serial_UartPins}, spi::{ dma::WithDmaSpi2 as _esp_hal_spi_dma_WithDmaSpi2, Instance as _esp_hal_spi_Instance, @@ -65,6 +64,7 @@ pub use crate::{ Instance as _esp_hal_timer_Instance, TimerGroupInstance as _esp_hal_timer_TimerGroupInstance, }, + uart::{Instance as _esp_hal_uart_Instance, UartPins as _esp_hal_uart_UartPins}, }; /// All traits required for using the 1.0.0-alpha.x release of embedded-hal @@ -132,7 +132,6 @@ pub mod eh1 { }, }, macros::*, - serial::{Instance as _esp_hal_serial_Instance, UartPins as _esp_hal_serial_UartPins}, spi::{ dma::WithDmaSpi2 as _esp_hal_spi_dma_WithDmaSpi2, Instance as _esp_hal_spi_Instance, @@ -143,5 +142,6 @@ pub mod eh1 { Instance as _esp_hal_timer_Instance, TimerGroupInstance as _esp_hal_timer_TimerGroupInstance, }, + uart::{Instance as _esp_hal_serial_Instance, UartPins as _esp_hal_serial_UartPins}, }; } diff --git a/esp-hal-common/src/pulse_control.rs b/esp-hal-common/src/pulse_control.rs index e0a2e94eb..c36bfc769 100644 --- a/esp-hal-common/src/pulse_control.rs +++ b/esp-hal-common/src/pulse_control.rs @@ -36,7 +36,7 @@ //! //! ### Example (for ESP32-C3) //! ``` -//! let mut peripherals = pac::Peripherals::take().unwrap(); +//! let mut peripherals = peripherals::Peripherals::take(); //! //! // Configure RMT peripheral globally //! let pulse = PulseControl::new( diff --git a/esp-hal-common/src/system.rs b/esp-hal-common/src/system.rs index 4d72c5bbe..7dce05254 100644 --- a/esp-hal-common/src/system.rs +++ b/esp-hal-common/src/system.rs @@ -4,7 +4,7 @@ //! //! Example //! ```no_run -//! let peripherals = Peripherals::take().unwrap(); +//! let peripherals = Peripherals::take(); //! let system = peripherals.SYSTEM.split(); //! let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); //! ``` diff --git a/esp-hal-common/src/systimer.rs b/esp-hal-common/src/systimer.rs index a7c8962db..b1ad9d01d 100644 --- a/esp-hal-common/src/systimer.rs +++ b/esp-hal-common/src/systimer.rs @@ -86,15 +86,9 @@ impl Alarm { pub fn interrupt_enable(&self, val: bool) { let systimer = unsafe { &*SYSTIMER::ptr() }; match CHANNEL { - 0 => systimer - .int_ena - .modify(|_, w| w.target0_int_ena().bit(val)), - 1 => systimer - .int_ena - .modify(|_, w| w.target1_int_ena().bit(val)), - 2 => systimer - .int_ena - .modify(|_, w| w.target2_int_ena().bit(val)), + 0 => systimer.int_ena.modify(|_, w| w.target0_int_ena().bit(val)), + 1 => systimer.int_ena.modify(|_, w| w.target1_int_ena().bit(val)), + 2 => systimer.int_ena.modify(|_, w| w.target2_int_ena().bit(val)), _ => unreachable!(), } } diff --git a/esp-hal-common/src/serial.rs b/esp-hal-common/src/uart.rs similarity index 96% rename from esp-hal-common/src/serial.rs rename to esp-hal-common/src/uart.rs index bd38f8c1d..7e9058071 100644 --- a/esp-hal-common/src/serial.rs +++ b/esp-hal-common/src/uart.rs @@ -5,11 +5,9 @@ use self::config::Config; use crate::pac::UART2; use crate::{ clock::Clocks, - pac::{ - uart0::{fifo::FIFO_SPEC, RegisterBlock}, - UART0, - UART1, - }, + pac::uart0::{fifo::FIFO_SPEC, RegisterBlock}, + peripheral::{Peripheral, PeripheralRef}, + peripherals::{UART0, UART1}, types::{InputSignal, OutputSignal}, InputPin, OutputPin, @@ -233,17 +231,17 @@ impl embedded_hal_1::serial::Error for Error { } /// UART driver -pub struct Serial { - uart: T, +pub struct Uart<'d, T> { + uart: PeripheralRef<'d, T>, } -impl Serial +impl<'d, T> Uart<'d, T> where T: Instance, { /// Create a new UART instance with defaults pub fn new_with_config

( - uart: T, + uart: impl Peripheral

+ 'd, config: Option, mut pins: Option

, clocks: &Clocks, @@ -251,7 +249,8 @@ where where P: UartPins, { - let mut serial = Serial { uart }; + crate::into_ref!(uart); + let mut serial = Uart { uart }; serial.uart.disable_rx_interrupts(); serial.uart.disable_tx_interrupts(); @@ -275,19 +274,15 @@ where } /// Create a new UART instance with defaults - pub fn new(uart: T) -> Self { - let mut serial = Serial { uart }; + pub fn new(uart: impl Peripheral

+ 'd) -> Self { + crate::into_ref!(uart); + let mut serial = Uart { uart }; serial.uart.disable_rx_interrupts(); serial.uart.disable_tx_interrupts(); serial } - /// Return the raw interface to the underlying UART instance - pub fn free(self) -> T { - self.uart - } - /// Writes bytes pub fn write_bytes(&mut self, data: &[u8]) -> Result<(), Error> { data.iter() @@ -767,7 +762,7 @@ impl Instance for UART2 { } #[cfg(feature = "ufmt")] -impl ufmt_write::uWrite for Serial +impl ufmt_write::uWrite for Uart<'_, T> where T: Instance, { @@ -785,7 +780,7 @@ where } } -impl core::fmt::Write for Serial +impl core::fmt::Write for Uart<'_, T> where T: Instance, { @@ -795,7 +790,7 @@ where } } -impl embedded_hal::serial::Write for Serial +impl embedded_hal::serial::Write for Uart<'_, T> where T: Instance, { @@ -810,7 +805,7 @@ where } } -impl embedded_hal::serial::Read for Serial +impl embedded_hal::serial::Read for Uart<'_, T> where T: Instance, { @@ -822,12 +817,12 @@ where } #[cfg(feature = "eh1")] -impl embedded_hal_1::serial::ErrorType for Serial { +impl embedded_hal_1::serial::ErrorType for Uart<'_, T> { type Error = Error; } #[cfg(feature = "eh1")] -impl embedded_hal_nb::serial::Read for Serial +impl embedded_hal_nb::serial::Read for Uart<'_, T> where T: Instance, { @@ -837,7 +832,7 @@ where } #[cfg(feature = "eh1")] -impl embedded_hal_nb::serial::Write for Serial +impl embedded_hal_nb::serial::Write for Uart<'_, T> where T: Instance, { diff --git a/esp-hal-procmacros/src/lib.rs b/esp-hal-procmacros/src/lib.rs index e4e8d2f00..68ba571ae 100644 --- a/esp-hal-procmacros/src/lib.rs +++ b/esp-hal-procmacros/src/lib.rs @@ -199,7 +199,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { f.block.stmts.extend(std::iter::once( syn::parse2(quote! {{ // Check that this interrupt actually exists - self::pac::Interrupt::#ident_s; + crate::peripherals::Interrupt::#ident_s; }}) .unwrap(), )); diff --git a/esp32-hal/examples/adc.rs b/esp32-hal/examples/adc.rs index 31534be1f..3d30252bf 100644 --- a/esp32-hal/examples/adc.rs +++ b/esp32-hal/examples/adc.rs @@ -9,7 +9,7 @@ use esp32_hal::{ adc::{AdcConfig, Attenuation, ADC, ADC2}, clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -21,7 +21,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/advanced_serial.rs b/esp32-hal/examples/advanced_serial.rs index 199b0dc61..c162fcf83 100644 --- a/esp32-hal/examples/advanced_serial.rs +++ b/esp32-hal/examples/advanced_serial.rs @@ -9,16 +9,16 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, - serial::{ + timer::TimerGroup, + uart::{ config::{Config, DataBits, Parity, StopBits}, TxRxPins, }, - timer::TimerGroup, Delay, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use esp_println::println; @@ -27,7 +27,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -52,7 +52,7 @@ fn main() -> ! { io.pins.gpio17.into_floating_input(), ); - let mut serial1 = Serial::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); + let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); let mut delay = Delay::new(&clocks); diff --git a/esp32-hal/examples/blinky.rs b/esp32-hal/examples/blinky.rs index fdec5ff30..6f772da01 100644 --- a/esp32-hal/examples/blinky.rs +++ b/esp32-hal/examples/blinky.rs @@ -8,7 +8,7 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -19,7 +19,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/clock_monitor.rs b/esp32-hal/examples/clock_monitor.rs index 35ae95270..ce0038ef3 100644 --- a/esp32-hal/examples/clock_monitor.rs +++ b/esp32-hal/examples/clock_monitor.rs @@ -11,7 +11,7 @@ use critical_section::Mutex; use esp32_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, }; @@ -22,7 +22,7 @@ static RTC: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -40,7 +40,11 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); diff --git a/esp32-hal/examples/dac.rs b/esp32-hal/examples/dac.rs index 5eaec3be8..e2a6465e0 100644 --- a/esp32-hal/examples/dac.rs +++ b/esp32-hal/examples/dac.rs @@ -9,7 +9,7 @@ use esp32_hal::{ clock::ClockControl, dac, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -20,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/embassy_hello_world.rs b/esp32-hal/examples/embassy_hello_world.rs index 2fedcc9e4..dba912577 100644 --- a/esp32-hal/examples/embassy_hello_world.rs +++ b/esp32-hal/examples/embassy_hello_world.rs @@ -4,12 +4,13 @@ use embassy_executor::Executor; use embassy_time::{Duration, Timer}; - use esp32_hal::{ clock::ClockControl, + embassy, + peripherals::Peripherals, prelude::*, timer::TimerGroup, - Rtc, embassy, pac::Peripherals, + Rtc, }; use esp_backtrace as _; use static_cell::StaticCell; @@ -35,7 +36,7 @@ static EXECUTOR: StaticCell = StaticCell::new(); #[xtensa_lx_rt::entry] fn main() -> ! { esp_println::println!("Init!"); - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,10 +54,9 @@ fn main() -> ! { #[cfg(feature = "embassy-time-timg0")] embassy::init(&clocks, timer_group0.timer0); - let executor = EXECUTOR.init(Executor::new()); executor.run(|spawner| { spawner.spawn(run1()).ok(); spawner.spawn(run2()).ok(); }); -} \ No newline at end of file +} diff --git a/esp32-hal/examples/gpio_interrupt.rs b/esp32-hal/examples/gpio_interrupt.rs index 4cb400a0d..a76405f33 100644 --- a/esp32-hal/examples/gpio_interrupt.rs +++ b/esp32-hal/examples/gpio_interrupt.rs @@ -11,10 +11,10 @@ use core::{borrow::BorrowMut, cell::RefCell}; use critical_section::Mutex; use esp32_hal::{ clock::ClockControl, - gpio::{Gpio0, IO, Event, Input, PullDown,}, + gpio::{Event, Gpio0, Input, PullDown, IO}, interrupt, macros::ram, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, timer::TimerGroup, Delay, @@ -27,7 +27,7 @@ static BUTTON: Mutex>>>> = Mutex::new(RefCe #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -48,7 +48,7 @@ fn main() -> ! { critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(pac::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); led.set_high().unwrap(); diff --git a/esp32-hal/examples/hello_rgb.rs b/esp32-hal/examples/hello_rgb.rs index 3d3a9d82d..2bb5c3360 100644 --- a/esp32-hal/examples/hello_rgb.rs +++ b/esp32-hal/examples/hello_rgb.rs @@ -15,7 +15,7 @@ use esp32_hal::{ clock::ClockControl, - pac, + peripherals, prelude::*, timer::TimerGroup, utils::{smartLedAdapter, SmartLedsAdapter}, @@ -36,7 +36,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = peripherals::Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/hello_world.rs b/esp32-hal/examples/hello_world.rs index 6925b2b00..74a162eb3 100644 --- a/esp32-hal/examples/hello_world.rs +++ b/esp32-hal/examples/hello_world.rs @@ -8,11 +8,11 @@ use core::fmt::Write; use esp32_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; @@ -20,14 +20,14 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); let mut timer0 = timer_group0.timer0; let mut wdt = timer_group0.wdt; - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let mut rtc = Rtc::new(peripherals.RTC_CNTL); // Disable MWDT and RWDT (Watchdog) flash boot protection diff --git a/esp32-hal/examples/i2c_bmp180_calibration_data.rs b/esp32-hal/examples/i2c_bmp180_calibration_data.rs index a7face900..e25a47b3d 100644 --- a/esp32-hal/examples/i2c_bmp180_calibration_data.rs +++ b/esp32-hal/examples/i2c_bmp180_calibration_data.rs @@ -13,7 +13,7 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -24,7 +24,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/i2c_display.rs b/esp32-hal/examples/i2c_display.rs index abb151bad..34c7bfb09 100644 --- a/esp32-hal/examples/i2c_display.rs +++ b/esp32-hal/examples/i2c_display.rs @@ -23,7 +23,7 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -35,7 +35,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/i2s_read.rs b/esp32-hal/examples/i2s_read.rs index a55352888..2f7d09965 100644 --- a/esp32-hal/examples/i2s_read.rs +++ b/esp32-hal/examples/i2s_read.rs @@ -1,5 +1,5 @@ //! This shows how to continously receive data via I2S -//! +//! //! Pins used //! BCLK GPIO12 //! WS GPIO13 @@ -7,7 +7,7 @@ //! //! 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 -//! +//! //! You can also inspect the MCLK, BCLK and WS with a logic analyzer #![no_std] @@ -15,10 +15,10 @@ use esp32_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, + i2s::{DataFormat, I2s, I2s0New, I2sReadDma, NoMclk, PinsBclkWsDin, Standard}, pdma::Dma, - i2s::{DataFormat, I2s, NoMclk, Standard, I2s0New, PinsBclkWsDin, I2sReadDma}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -30,7 +30,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/i2s_sound.rs b/esp32-hal/examples/i2s_sound.rs index 118a6b427..7ecec89eb 100644 --- a/esp32-hal/examples/i2s_sound.rs +++ b/esp32-hal/examples/i2s_sound.rs @@ -32,9 +32,9 @@ use esp32_hal::{ clock::ClockControl, dma::DmaPriority, + i2s::{DataFormat, I2s, I2s0New, I2sWriteDma, NoMclk, PinsBclkWsDout, Standard}, pdma::Dma, - i2s::{DataFormat, I2s, I2sWriteDma, NoMclk, PinsBclkWsDout, Standard, I2s0New}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -53,7 +53,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/ledc.rs b/esp32-hal/examples/ledc.rs index d0db9f415..6c5b2c82a 100644 --- a/esp32-hal/examples/ledc.rs +++ b/esp32-hal/examples/ledc.rs @@ -15,7 +15,7 @@ use esp32_hal::{ HighSpeed, LEDC, }, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -25,7 +25,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/mcpwm.rs b/esp32-hal/examples/mcpwm.rs index 1bc4caf18..0c355e08c 100644 --- a/esp32-hal/examples/mcpwm.rs +++ b/esp32-hal/examples/mcpwm.rs @@ -1,4 +1,5 @@ -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty signal at 20 kHz. +//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty +//! signal at 20 kHz. //! //! The signal will be output to the pin assigned to `pin`. (GPIO4) @@ -8,12 +9,8 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, - mcpwm::{ - {MCPWM, PeripheralClockConfig}, - operator::PwmPinConfig, - timer::PwmWorkingMode, - }, - pac::Peripherals, + mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -23,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,8 +50,11 @@ fn main() -> ! { .operator0 .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH); - // start timer with timestamp values in the range of 0..=99 and a frequency of 20 kHz - let timer_clock_cfg = clock_cfg.timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()).unwrap(); + // start timer with timestamp values in the range of 0..=99 and a frequency of + // 20 kHz + let timer_clock_cfg = clock_cfg + .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) + .unwrap(); mcpwm.timer0.start(timer_clock_cfg); // pin will be high 50% of the time diff --git a/esp32-hal/examples/multicore.rs b/esp32-hal/examples/multicore.rs index baa1f08c7..358c71cb4 100644 --- a/esp32-hal/examples/multicore.rs +++ b/esp32-hal/examples/multicore.rs @@ -10,7 +10,7 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32_hal::{ clock::ClockControl, - pac::{Peripherals, TIMG1}, + peripherals::{Peripherals, TIMG1}, prelude::*, timer::{Timer, Timer0, TimerGroup}, CpuControl, @@ -23,7 +23,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/pulse_control.rs b/esp32-hal/examples/pulse_control.rs index 08613d7b6..7fc6ac6e7 100644 --- a/esp32-hal/examples/pulse_control.rs +++ b/esp32-hal/examples/pulse_control.rs @@ -8,7 +8,7 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode}, timer::TimerGroup, @@ -20,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/ram.rs b/esp32-hal/examples/ram.rs index 0ca5793e9..b52e3a629 100644 --- a/esp32-hal/examples/ram.rs +++ b/esp32-hal/examples/ram.rs @@ -11,7 +11,7 @@ use esp32_hal::{ clock::ClockControl, macros::ram, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, }; @@ -31,7 +31,7 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/read_efuse.rs b/esp32-hal/examples/read_efuse.rs index ea855d852..c0eedee86 100644 --- a/esp32-hal/examples/read_efuse.rs +++ b/esp32-hal/examples/read_efuse.rs @@ -7,7 +7,7 @@ use esp32_hal::{ clock::ClockControl, efuse::Efuse, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -18,7 +18,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/rtc_watchdog.rs b/esp32-hal/examples/rtc_watchdog.rs index 81ef52f28..9054cee0c 100644 --- a/esp32-hal/examples/rtc_watchdog.rs +++ b/esp32-hal/examples/rtc_watchdog.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, Rwdt, @@ -24,7 +24,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -38,7 +38,11 @@ fn main() -> ! { critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); loop {} } diff --git a/esp32-hal/examples/serial_interrupts.rs b/esp32-hal/examples/serial_interrupts.rs index c8c5b9a3a..c7ed2353e 100644 --- a/esp32-hal/examples/serial_interrupts.rs +++ b/esp32-hal/examples/serial_interrupts.rs @@ -11,22 +11,22 @@ use critical_section::Mutex; use esp32_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, UART0}, + peripherals::{self, Peripherals, UART0}, prelude::*, - serial::config::AtCmdConfig, timer::TimerGroup, + uart::config::AtCmdConfig, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; use xtensa_lx_rt::entry; -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); +static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -38,7 +38,7 @@ fn main() -> ! { let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); let mut wdt1 = timer_group1.wdt; - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let mut rtc = Rtc::new(peripherals.RTC_CNTL); // Disable MWDT and RWDT (Watchdog) flash boot protection @@ -51,7 +51,11 @@ fn main() -> ! { serial0.listen_at_cmd(); serial0.listen_rx_fifo_full(); - interrupt::enable(pac::Interrupt::UART0, interrupt::Priority::Priority2).unwrap(); + interrupt::enable( + peripherals::Interrupt::UART0, + interrupt::Priority::Priority2, + ) + .unwrap(); timer0.start(1u64.secs()); diff --git a/esp32-hal/examples/sha.rs b/esp32-hal/examples/sha.rs index 79a1abc95..474910f15 100644 --- a/esp32-hal/examples/sha.rs +++ b/esp32-hal/examples/sha.rs @@ -1,26 +1,26 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of hardware-accelerated and pure software hashing. -//! +//! Demonstrates the use of the SHA peripheral and compares the speed of +//! hardware-accelerated and pure software hashing. #![no_std] #![no_main] use esp32_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, + sha::{Sha, ShaMode}, timer::TimerGroup, Rtc, - sha::{Sha, ShaMode}, }; -use nb::block; use esp_backtrace as _; use esp_println::println; +use nb::block; +use sha2::{Digest, Sha512}; use xtensa_lx_rt::entry; -use sha2::{Sha512, Digest}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -32,30 +32,34 @@ fn main() -> ! { wdt.disable(); rtc.rwdt.disable(); - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data.clone(); let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - // Short hashes can be created by decreasing the output buffer to the desired length + // Short hashes can be created by decreasing the output buffer to the desired + // length let mut output = [0u8; 64]; let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the unprocessed parts - // The unprocessed parts can be input in the next iteration, you can always add more data until - // finish() is called. After finish() is called update()'s will contribute to a new hash which + // The hardware implementation takes a subslice of the input, and returns the + // unprocessed parts The unprocessed parts can be input in the next + // iteration, you can always add more data until finish() is called. After + // finish() is called update()'s will contribute to a new hash which // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of magnitude longer than - // the Sha function itself so not useful for comparing processing time - // println!("Remaining len: {}", remaining.len()); - // All the HW Sha functions are infallible so unwrap is fine to use if you use block! + while remaining.len() > 0 { + // Can add println to view progress, however println takes a few orders of + // magnitude longer than the Sha function itself so not useful for + // comparing processing time println!("Remaining len: {}", + // remaining.len()); + + // All the HW Sha functions are infallible so unwrap is fine to use if you use + // block! remaining = block!(hasher.update(remaining)).unwrap(); } - // Finish can be called as many times as desired to get mutliple copies of the output. + // Finish can be called as many times as desired to get mutliple copies of the + // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); let post_calc = xtensa_lx::timer::get_cycle_count(); @@ -64,7 +68,6 @@ fn main() -> ! { println!("SHA512 Hash output {:02x?}", output); let _usha = hasher.free(); - let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new(); hasher.update(source_data); @@ -74,7 +77,7 @@ fn main() -> ! { println!("Took {} cycles", soft_time); println!("SHA512 Hash output {:02x?}", soft_result); - println!("HW SHA is {}x faster", soft_time/hw_time); + println!("HW SHA is {}x faster", soft_time / hw_time); loop {} } diff --git a/esp32-hal/examples/spi_eh1_device_loopback.rs b/esp32-hal/examples/spi_eh1_device_loopback.rs index cf41e5b52..bd9eb7dc7 100644 --- a/esp32-hal/examples/spi_eh1_device_loopback.rs +++ b/esp32-hal/examples/spi_eh1_device_loopback.rs @@ -22,7 +22,7 @@ use embedded_hal_1::spi::SpiDevice; use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiBusController, SpiMode}, timer::TimerGroup, @@ -35,7 +35,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/spi_eh1_loopback.rs b/esp32-hal/examples/spi_eh1_loopback.rs index 53925de6e..9aab98eee 100644 --- a/esp32-hal/examples/spi_eh1_loopback.rs +++ b/esp32-hal/examples/spi_eh1_loopback.rs @@ -20,7 +20,7 @@ use embedded_hal_1::spi::SpiBus; use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -33,7 +33,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/spi_loopback.rs b/esp32-hal/examples/spi_loopback.rs index ea585d4ba..d85835088 100644 --- a/esp32-hal/examples/spi_loopback.rs +++ b/esp32-hal/examples/spi_loopback.rs @@ -19,7 +19,7 @@ use esp32_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -32,7 +32,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/spi_loopback_dma.rs b/esp32-hal/examples/spi_loopback_dma.rs index 241fbb1db..dea517e4f 100644 --- a/esp32-hal/examples/spi_loopback_dma.rs +++ b/esp32-hal/examples/spi_loopback_dma.rs @@ -18,10 +18,10 @@ use esp32_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, gpio::IO, - pac::Peripherals, pdma::Dma, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -34,7 +34,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/examples/timer_interrupt.rs b/esp32-hal/examples/timer_interrupt.rs index ecf9df047..7b52ce559 100644 --- a/esp32-hal/examples/timer_interrupt.rs +++ b/esp32-hal/examples/timer_interrupt.rs @@ -12,7 +12,7 @@ use esp32_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals, TIMG0, TIMG1}, + peripherals::{self, Peripherals, TIMG0, TIMG1}, prelude::*, timer::{Timer, Timer0, Timer1, TimerGroup}, Rtc, @@ -27,7 +27,7 @@ static TIMER11: Mutex>>>> = Mutex::new(RefCel #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -49,10 +49,10 @@ fn main() -> ! { wdt1.disable(); rtc.rwdt.disable(); - interrupt::enable(pac::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); timer00.start(500u64.millis()); timer00.listen(); timer01.start(2500u64.millis()); diff --git a/esp32-hal/examples/watchdog.rs b/esp32-hal/examples/watchdog.rs index 4e30605df..675e10a03 100644 --- a/esp32-hal/examples/watchdog.rs +++ b/esp32-hal/examples/watchdog.rs @@ -5,7 +5,13 @@ #![no_std] #![no_main] -use esp32_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc}; +use esp32_hal::{ + clock::ClockControl, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, +}; use esp_backtrace as _; use esp_println::println; use nb::block; @@ -13,7 +19,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.DPORT.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32-hal/src/lib.rs b/esp32-hal/src/lib.rs index f513c4e37..a213b5a18 100644 --- a/esp32-hal/src/lib.rs +++ b/esp32-hal/src/lib.rs @@ -1,6 +1,8 @@ #![no_std] pub use embedded_hal as ehal; +#[cfg(feature = "embassy")] +pub use esp_hal_common::embassy; #[doc(inline)] pub use esp_hal_common::{ analog::adc::implementation as adc, @@ -17,13 +19,14 @@ pub use esp_hal_common::{ ledc, macros, mcpwm, - pac, + peripherals, prelude, pulse_control, - serial, + sha, spi, system, timer, + uart, utils, Cpu, Delay, @@ -31,22 +34,18 @@ pub use esp_hal_common::{ Rng, Rtc, Rwdt, - Serial, - sha + Uart, }; pub use self::gpio::IO; -#[cfg(feature = "embassy")] -pub use esp_hal_common::embassy; - /// Common module for analog functions pub mod analog { pub use esp_hal_common::analog::{AvailableAnalog, SensExt}; } #[no_mangle] -extern "C" fn EspDefaultHandler(_level: u32, _interrupt: pac::Interrupt) {} +extern "C" fn EspDefaultHandler(_level: u32, _interrupt: peripherals::Interrupt) {} #[no_mangle] extern "C" fn DefaultHandler() {} diff --git a/esp32c2-hal/examples/adc.rs b/esp32c2-hal/examples/adc.rs index 58581aa8a..720de63c6 100644 --- a/esp32c2-hal/examples/adc.rs +++ b/esp32c2-hal/examples/adc.rs @@ -9,7 +9,7 @@ use esp32c2_hal::{ adc::{AdcConfig, Attenuation, ADC, ADC1}, clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -21,7 +21,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/advanced_serial.rs b/esp32c2-hal/examples/advanced_serial.rs index 0a5cacf98..5f2d11750 100644 --- a/esp32c2-hal/examples/advanced_serial.rs +++ b/esp32c2-hal/examples/advanced_serial.rs @@ -8,15 +8,15 @@ use esp32c2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, - serial::{ + timer::TimerGroup, + uart::{ config::{Config, DataBits, Parity, StopBits}, TxRxPins, }, - timer::TimerGroup, Rtc, - Serial, + Uart, IO, }; use esp_backtrace as _; @@ -26,7 +26,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,7 +53,7 @@ fn main() -> ! { io.pins.gpio2.into_floating_input(), ); - let mut serial1 = Serial::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); + let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); timer0.start(250u64.millis()); diff --git a/esp32c2-hal/examples/blinky.rs b/esp32c2-hal/examples/blinky.rs index 649843f9e..dcef2bbf9 100644 --- a/esp32c2-hal/examples/blinky.rs +++ b/esp32c2-hal/examples/blinky.rs @@ -8,7 +8,7 @@ use esp32c2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -19,7 +19,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/clock_monitor.rs b/esp32c2-hal/examples/clock_monitor.rs index a1f209b5a..3eebc387b 100644 --- a/esp32c2-hal/examples/clock_monitor.rs +++ b/esp32c2-hal/examples/clock_monitor.rs @@ -11,7 +11,7 @@ use critical_section::Mutex; use esp32c2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, }; @@ -22,7 +22,7 @@ static RTC: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -41,7 +41,11 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| { RTC.borrow_ref_mut(cs).replace(rtc); diff --git a/esp32c2-hal/examples/embassy_hello_world.rs b/esp32c2-hal/examples/embassy_hello_world.rs index 280103788..ff827ee95 100644 --- a/esp32c2-hal/examples/embassy_hello_world.rs +++ b/esp32c2-hal/examples/embassy_hello_world.rs @@ -7,7 +7,7 @@ use embassy_time::{Duration, Timer}; use esp32c2_hal::{ clock::ClockControl, embassy, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -36,7 +36,7 @@ static EXECUTOR: StaticCell = StaticCell::new(); #[riscv_rt::entry] fn main() -> ! { esp_println::println!("Init!"); - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -50,7 +50,10 @@ fn main() -> ! { wdt0.disable(); #[cfg(feature = "embassy-time-systick")] - embassy::init(&clocks, esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER)); + embassy::init( + &clocks, + esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); #[cfg(feature = "embassy-time-timg0")] embassy::init(&clocks, timer_group0.timer0); diff --git a/esp32c2-hal/examples/gpio_interrupt.rs b/esp32c2-hal/examples/gpio_interrupt.rs index bf2688020..0ef960a4b 100644 --- a/esp32c2-hal/examples/gpio_interrupt.rs +++ b/esp32c2-hal/examples/gpio_interrupt.rs @@ -11,9 +11,9 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32c2_hal::{ clock::ClockControl, - gpio::{Gpio9, IO, Event, Input, PullDown}, + gpio::{Event, Gpio9, Input, PullDown, IO}, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, timer::TimerGroup, Delay, @@ -26,7 +26,7 @@ static BUTTON: Mutex>>>> = Mutex::new(RefCe #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -50,7 +50,7 @@ fn main() -> ! { critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(pac::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); unsafe { riscv::interrupt::enable(); diff --git a/esp32c2-hal/examples/hello_world.rs b/esp32c2-hal/examples/hello_world.rs index 853991ed1..13cef0f88 100644 --- a/esp32c2-hal/examples/hello_world.rs +++ b/esp32c2-hal/examples/hello_world.rs @@ -8,11 +8,11 @@ use core::fmt::Write; use esp32c2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; @@ -20,12 +20,12 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); let mut timer0 = timer_group0.timer0; let mut wdt0 = timer_group0.wdt; diff --git a/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs b/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs index 6fab21ca1..768fed737 100644 --- a/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs +++ b/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs @@ -13,7 +13,7 @@ use esp32c2_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -24,7 +24,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/i2c_display.rs b/esp32c2-hal/examples/i2c_display.rs index ce302ca7a..fc9b4f2ee 100644 --- a/esp32c2-hal/examples/i2c_display.rs +++ b/esp32c2-hal/examples/i2c_display.rs @@ -23,7 +23,7 @@ use esp32c2_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -35,7 +35,7 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/ledc.rs b/esp32c2-hal/examples/ledc.rs index 0bce2e3d7..e16e69708 100644 --- a/esp32c2-hal/examples/ledc.rs +++ b/esp32c2-hal/examples/ledc.rs @@ -16,7 +16,7 @@ use esp32c2_hal::{ LowSpeed, LEDC, }, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -26,7 +26,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/read_efuse.rs b/esp32c2-hal/examples/read_efuse.rs index 6f3fa669f..b7bfe930b 100644 --- a/esp32c2-hal/examples/read_efuse.rs +++ b/esp32c2-hal/examples/read_efuse.rs @@ -7,7 +7,7 @@ use esp32c2_hal::{ clock::ClockControl, efuse::Efuse, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -18,7 +18,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/rtc_watchdog.rs b/esp32c2-hal/examples/rtc_watchdog.rs index 5b65a897d..45af22c14 100644 --- a/esp32c2-hal/examples/rtc_watchdog.rs +++ b/esp32c2-hal/examples/rtc_watchdog.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32c2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, Rwdt, @@ -24,7 +24,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -37,7 +37,11 @@ fn main() -> ! { rtc.rwdt.start(2000u64.millis()); rtc.rwdt.listen(); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); diff --git a/esp32c2-hal/examples/serial_interrupts.rs b/esp32c2-hal/examples/serial_interrupts.rs index 064a28a4e..cc6e71cd3 100644 --- a/esp32c2-hal/examples/serial_interrupts.rs +++ b/esp32c2-hal/examples/serial_interrupts.rs @@ -11,28 +11,28 @@ use critical_section::Mutex; use esp32c2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, UART0}, + peripherals::{self, Peripherals, UART0}, prelude::*, - serial::config::AtCmdConfig, timer::TimerGroup, + uart::config::AtCmdConfig, Cpu, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; use riscv_rt::entry; -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); +static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); let mut timer0 = timer_group0.timer0; let mut wdt0 = timer_group0.wdt; @@ -51,7 +51,11 @@ fn main() -> ! { critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(serial0)); - interrupt::enable(pac::Interrupt::UART0, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::UART0, + interrupt::Priority::Priority1, + ) + .unwrap(); interrupt::set_kind( Cpu::ProCpu, interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts diff --git a/esp32c2-hal/examples/sha.rs b/esp32c2-hal/examples/sha.rs index 07234e64c..290770886 100644 --- a/esp32c2-hal/examples/sha.rs +++ b/esp32c2-hal/examples/sha.rs @@ -1,26 +1,26 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of hardware-accelerated and pure software hashing. -//! +//! Demonstrates the use of the SHA peripheral and compares the speed of +//! hardware-accelerated and pure software hashing. #![no_std] #![no_main] use esp32c2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, + sha::{Sha, ShaMode}, timer::TimerGroup, Rtc, - sha::{Sha, ShaMode}, }; -use nb::block; use esp_backtrace as _; use esp_println::println; +use nb::block; use riscv_rt::entry; -use sha2::{Sha256, Digest}; +use sha2::{Digest, Sha256}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -32,48 +32,51 @@ fn main() -> ! { wdt.disable(); rtc.rwdt.disable(); - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data.clone(); let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256); - // Short hashes can be created by decreasing the output buffer to the desired length + // Short hashes can be created by decreasing the output buffer to the desired + // length let mut output = [0u8; 32]; - //let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the unprocessed parts - // The unprocessed parts can be input in the next iteration, you can always add more data until - // finish() is called. After finish() is called update()'s will contribute to a new hash which + // let pre_calc = xtensa_lx::timer::get_cycle_count(); + // The hardware implementation takes a subslice of the input, and returns the + // unprocessed parts The unprocessed parts can be input in the next + // iteration, you can always add more data until finish() is called. After + // finish() is called update()'s will contribute to a new hash which // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of magnitude longer than - // the Sha function itself so not useful for comparing processing time - // println!("Remaining len: {}", remaining.len()); - // All the HW Sha functions are infallible so unwrap is fine to use if you use block! + while remaining.len() > 0 { + // Can add println to view progress, however println takes a few orders of + // magnitude longer than the Sha function itself so not useful for + // comparing processing time println!("Remaining len: {}", + // remaining.len()); + + // All the HW Sha functions are infallible so unwrap is fine to use if you use + // block! remaining = block!(hasher.update(remaining)).unwrap(); } - // Finish can be called as many times as desired to get mutliple copies of the output. + // Finish can be called as many times as desired to get mutliple copies of the + // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); - //let post_calc = xtensa_lx::timer::get_cycle_count(); - //let hw_time = post_calc - pre_calc; - //println!("Took {} cycles", hw_time); + // let post_calc = xtensa_lx::timer::get_cycle_count(); + // let hw_time = post_calc - pre_calc; + // println!("Took {} cycles", hw_time); println!("SHA256 Hash output {:02x?}", output); let _usha = hasher.free(); - - //let pre_calc = xtensa_lx::timer::get_cycle_count(); + // let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha256::new(); hasher.update(source_data); let soft_result = hasher.finalize(); - //let post_calc = xtensa_lx::timer::get_cycle_count(); - //let soft_time = post_calc - pre_calc; - //println!("Took {} cycles", soft_time); + // let post_calc = xtensa_lx::timer::get_cycle_count(); + // let soft_time = post_calc - pre_calc; + // println!("Took {} cycles", soft_time); println!("SHA256 Hash output {:02x?}", soft_result); - //println!("HW SHA is {}x faster", soft_time/hw_time); + // println!("HW SHA is {}x faster", soft_time/hw_time); loop {} } diff --git a/esp32c2-hal/examples/spi_eh1_device_loopback.rs b/esp32c2-hal/examples/spi_eh1_device_loopback.rs index 9ef83c06f..1e20bb33a 100644 --- a/esp32c2-hal/examples/spi_eh1_device_loopback.rs +++ b/esp32c2-hal/examples/spi_eh1_device_loopback.rs @@ -22,7 +22,7 @@ use embedded_hal_1::spi::SpiDevice; use esp32c2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiBusController, SpiMode}, timer::TimerGroup, @@ -35,7 +35,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/spi_eh1_loopback.rs b/esp32c2-hal/examples/spi_eh1_loopback.rs index f65b00825..b04447f6e 100644 --- a/esp32c2-hal/examples/spi_eh1_loopback.rs +++ b/esp32c2-hal/examples/spi_eh1_loopback.rs @@ -20,7 +20,7 @@ use embedded_hal_1::spi::SpiBus; use esp32c2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -33,7 +33,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/spi_loopback.rs b/esp32c2-hal/examples/spi_loopback.rs index 0346e7be0..5c6af7637 100644 --- a/esp32c2-hal/examples/spi_loopback.rs +++ b/esp32c2-hal/examples/spi_loopback.rs @@ -19,7 +19,7 @@ use esp32c2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -32,7 +32,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/spi_loopback_dma.rs b/esp32c2-hal/examples/spi_loopback_dma.rs index fecc9977d..f40909187 100644 --- a/esp32c2-hal/examples/spi_loopback_dma.rs +++ b/esp32c2-hal/examples/spi_loopback_dma.rs @@ -18,10 +18,10 @@ use esp32c2_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, gdma::Gdma, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -34,7 +34,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/examples/systimer.rs b/esp32c2-hal/examples/systimer.rs index 9c2e19486..3e98e2b46 100644 --- a/esp32c2-hal/examples/systimer.rs +++ b/esp32c2-hal/examples/systimer.rs @@ -11,7 +11,7 @@ use esp32c2_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, systimer::{Alarm, Periodic, SystemTimer, Target}, timer::TimerGroup, @@ -28,7 +28,7 @@ static ALARM2: Mutex>>> = Mutex::new(RefCell::ne #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -63,9 +63,21 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET0, Priority::Priority1).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET1, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET2, Priority::Priority2).unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET0, + Priority::Priority1, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET1, + Priority::Priority2, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET2, + Priority::Priority2, + ) + .unwrap(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. diff --git a/esp32c2-hal/examples/timer_interrupt.rs b/esp32c2-hal/examples/timer_interrupt.rs index 815ceb49f..b7b51d5ba 100644 --- a/esp32c2-hal/examples/timer_interrupt.rs +++ b/esp32c2-hal/examples/timer_interrupt.rs @@ -10,7 +10,7 @@ use critical_section::Mutex; use esp32c2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, TIMG0}, + peripherals::{self, Peripherals, TIMG0}, prelude::*, timer::{Timer, Timer0, TimerGroup}, Rtc, @@ -22,7 +22,7 @@ static TIMER0: Mutex>>>> = Mutex::new(RefCell #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -37,7 +37,11 @@ fn main() -> ! { rtc.rwdt.disable(); wdt0.disable(); - interrupt::enable(pac::Interrupt::TG0_T0_LEVEL, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::TG0_T0_LEVEL, + interrupt::Priority::Priority1, + ) + .unwrap(); timer0.start(500u64.millis()); timer0.listen(); diff --git a/esp32c2-hal/examples/watchdog.rs b/esp32c2-hal/examples/watchdog.rs index 4f62b7e95..bdc8d8380 100644 --- a/esp32c2-hal/examples/watchdog.rs +++ b/esp32c2-hal/examples/watchdog.rs @@ -5,7 +5,13 @@ #![no_std] #![no_main] -use esp32c2_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc}; +use esp32c2_hal::{ + clock::ClockControl, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, +}; use esp_backtrace as _; use esp_println::println; use nb::block; @@ -13,7 +19,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c2-hal/src/lib.rs b/esp32c2-hal/src/lib.rs index ca89ac9da..8579ced66 100644 --- a/esp32c2-hal/src/lib.rs +++ b/esp32c2-hal/src/lib.rs @@ -16,20 +16,20 @@ pub use esp_hal_common::{ interrupt, ledc, macros, - pac, + peripherals, prelude, - serial, + sha, spi, system, systimer, timer, + uart, Cpu, Delay, Rng, Rtc, Rwdt, - Serial, - sha, + Uart, }; pub use self::gpio::IO; @@ -295,4 +295,4 @@ pub fn mp_hook() -> bool { } #[no_mangle] -extern "C" fn EspDefaultHandler(_interrupt: pac::Interrupt) {} +extern "C" fn EspDefaultHandler(_interrupt: peripherals::Interrupt) {} diff --git a/esp32c3-hal/examples/adc.rs b/esp32c3-hal/examples/adc.rs index 6e3d93bb0..22684762e 100644 --- a/esp32c3-hal/examples/adc.rs +++ b/esp32c3-hal/examples/adc.rs @@ -9,7 +9,7 @@ use esp32c3_hal::{ adc::{AdcConfig, Attenuation, ADC, ADC1}, clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -21,7 +21,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/advanced_serial.rs b/esp32c3-hal/examples/advanced_serial.rs index 5021d0cec..bcc4c43f5 100644 --- a/esp32c3-hal/examples/advanced_serial.rs +++ b/esp32c3-hal/examples/advanced_serial.rs @@ -8,15 +8,15 @@ use esp32c3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, - serial::{ + timer::TimerGroup, + uart::{ config::{Config, DataBits, Parity, StopBits}, TxRxPins, }, - timer::TimerGroup, Rtc, - Serial, + Uart, IO, }; use esp_backtrace as _; @@ -26,7 +26,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -56,7 +56,7 @@ fn main() -> ! { io.pins.gpio2.into_floating_input(), ); - let mut serial1 = Serial::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); + let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); timer0.start(250u64.millis()); diff --git a/esp32c3-hal/examples/blinky.rs b/esp32c3-hal/examples/blinky.rs index 6d71b1971..551944ec5 100644 --- a/esp32c3-hal/examples/blinky.rs +++ b/esp32c3-hal/examples/blinky.rs @@ -8,7 +8,7 @@ use esp32c3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -19,7 +19,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/clock_monitor.rs b/esp32c3-hal/examples/clock_monitor.rs index 925b050cc..777beee0a 100644 --- a/esp32c3-hal/examples/clock_monitor.rs +++ b/esp32c3-hal/examples/clock_monitor.rs @@ -11,7 +11,7 @@ use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, }; @@ -22,7 +22,7 @@ static RTC: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -41,7 +41,11 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| { RTC.borrow_ref_mut(cs).replace(rtc); diff --git a/esp32c3-hal/examples/embassy_hello_world.rs b/esp32c3-hal/examples/embassy_hello_world.rs index f974e23bb..8c22abef0 100644 --- a/esp32c3-hal/examples/embassy_hello_world.rs +++ b/esp32c3-hal/examples/embassy_hello_world.rs @@ -4,12 +4,13 @@ use embassy_executor::Executor; use embassy_time::{Duration, Timer}; - use esp32c3_hal::{ clock::ClockControl, + embassy, + peripherals::Peripherals, prelude::*, timer::TimerGroup, - Rtc, embassy, pac::Peripherals, + Rtc, }; use esp_backtrace as _; use static_cell::StaticCell; @@ -35,7 +36,7 @@ static EXECUTOR: StaticCell = StaticCell::new(); #[riscv_rt::entry] fn main() -> ! { esp_println::println!("Init!"); - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -52,7 +53,10 @@ fn main() -> ! { wdt1.disable(); #[cfg(feature = "embassy-time-systick")] - embassy::init(&clocks, esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER)); + embassy::init( + &clocks, + esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); #[cfg(feature = "embassy-time-timg0")] embassy::init(&clocks, timer_group0.timer0); @@ -62,4 +66,4 @@ fn main() -> ! { spawner.spawn(run1()).ok(); spawner.spawn(run2()).ok(); }); -} \ No newline at end of file +} diff --git a/esp32c3-hal/examples/gpio_interrupt.rs b/esp32c3-hal/examples/gpio_interrupt.rs index 12d3bd2f4..a69e8ce30 100644 --- a/esp32c3-hal/examples/gpio_interrupt.rs +++ b/esp32c3-hal/examples/gpio_interrupt.rs @@ -11,9 +11,9 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, - gpio::{Gpio9, IO, Event, Input, PullDown}, + gpio::{Event, Gpio9, Input, PullDown, IO}, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, timer::TimerGroup, Delay, @@ -26,7 +26,7 @@ static BUTTON: Mutex>>>> = Mutex::new(RefCe #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,7 +53,7 @@ fn main() -> ! { critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(pac::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); unsafe { riscv::interrupt::enable(); diff --git a/esp32c3-hal/examples/hello_rgb.rs b/esp32c3-hal/examples/hello_rgb.rs index f58453000..b1654cb63 100644 --- a/esp32c3-hal/examples/hello_rgb.rs +++ b/esp32c3-hal/examples/hello_rgb.rs @@ -13,7 +13,7 @@ use esp32c3_hal::{ clock::ClockControl, - pac, + peripherals, prelude::*, pulse_control::ClockSource, timer::TimerGroup, @@ -35,7 +35,7 @@ use smart_leds::{ #[entry] fn main() -> ! { - let peripherals = pac::Peripherals::take().unwrap(); + let peripherals = peripherals::Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/hello_world.rs b/esp32c3-hal/examples/hello_world.rs index 70f5ca5ea..95d9701aa 100644 --- a/esp32c3-hal/examples/hello_world.rs +++ b/esp32c3-hal/examples/hello_world.rs @@ -1,4 +1,4 @@ -//! This shows how to write text to serial0. +//! This shows how to write text to uart0. //! You can see the output with `espflash` if you provide the `--monitor` option #![no_std] @@ -8,11 +8,11 @@ use core::fmt::Write; use esp32c3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; @@ -20,12 +20,12 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut uart0 = Uart::new(peripherals.UART0); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); let mut timer0 = timer_group0.timer0; let mut wdt0 = timer_group0.wdt; @@ -41,7 +41,7 @@ fn main() -> ! { timer0.start(1u64.secs()); loop { - writeln!(serial0, "Hello world!").unwrap(); + writeln!(uart0, "Hello world!").unwrap(); block!(timer0.wait()).unwrap(); } } diff --git a/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs b/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs index 184691465..4a6adb0e9 100644 --- a/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs +++ b/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs @@ -13,7 +13,7 @@ use esp32c3_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -24,7 +24,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/i2c_display.rs b/esp32c3-hal/examples/i2c_display.rs index e4eb904ab..0cff14364 100644 --- a/esp32c3-hal/examples/i2c_display.rs +++ b/esp32c3-hal/examples/i2c_display.rs @@ -23,7 +23,7 @@ use esp32c3_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -35,7 +35,7 @@ use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/i2s_read.rs b/esp32c3-hal/examples/i2s_read.rs index ded6e9943..06fd66076 100644 --- a/esp32c3-hal/examples/i2s_read.rs +++ b/esp32c3-hal/examples/i2s_read.rs @@ -1,5 +1,5 @@ //! This shows how to continously receive data via I2S -//! +//! //! Pins used //! MCLK GPIO4 //! BCLK GPIO1 @@ -8,7 +8,7 @@ //! //! 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 -//! +//! //! You can also inspect the MCLK, BCLK and WS with a logic analyzer #![no_std] @@ -18,8 +18,8 @@ use esp32c3_hal::{ clock::ClockControl, dma::DmaPriority, gdma::Gdma, - i2s::{DataFormat, I2s, I2sReadDma, MclkPin, PinsBclkWsDin, Standard, I2s0New}, - pac::Peripherals, + i2s::{DataFormat, I2s, I2s0New, I2sReadDma, MclkPin, PinsBclkWsDin, Standard}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -31,7 +31,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/i2s_sound.rs b/esp32c3-hal/examples/i2s_sound.rs index 8b0845069..8393d5d49 100644 --- a/esp32c3-hal/examples/i2s_sound.rs +++ b/esp32c3-hal/examples/i2s_sound.rs @@ -34,8 +34,8 @@ use esp32c3_hal::{ clock::ClockControl, dma::DmaPriority, gdma::Gdma, - i2s::{DataFormat, I2s, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard, I2s0New}, - pac::Peripherals, + i2s::{DataFormat, I2s, I2s0New, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -54,7 +54,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/ledc.rs b/esp32c3-hal/examples/ledc.rs index 75c0092b1..7be93e456 100644 --- a/esp32c3-hal/examples/ledc.rs +++ b/esp32c3-hal/examples/ledc.rs @@ -16,7 +16,7 @@ use esp32c3_hal::{ LowSpeed, LEDC, }, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -26,7 +26,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/pulse_control.rs b/esp32c3-hal/examples/pulse_control.rs index 5287f21b7..40cdc856a 100644 --- a/esp32c3-hal/examples/pulse_control.rs +++ b/esp32c3-hal/examples/pulse_control.rs @@ -8,7 +8,7 @@ use esp32c3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode}, timer::TimerGroup, @@ -20,7 +20,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/ram.rs b/esp32c3-hal/examples/ram.rs index 6c66c6717..8e4b31518 100644 --- a/esp32c3-hal/examples/ram.rs +++ b/esp32c3-hal/examples/ram.rs @@ -11,7 +11,7 @@ use esp32c3_hal::{ clock::ClockControl, macros::ram, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, }; @@ -31,7 +31,7 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/read_efuse.rs b/esp32c3-hal/examples/read_efuse.rs index 936466650..9ffb6b351 100644 --- a/esp32c3-hal/examples/read_efuse.rs +++ b/esp32c3-hal/examples/read_efuse.rs @@ -7,7 +7,7 @@ use esp32c3_hal::{ clock::ClockControl, efuse::Efuse, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -18,7 +18,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/rtc_watchdog.rs b/esp32c3-hal/examples/rtc_watchdog.rs index a956396ad..035a977e5 100644 --- a/esp32c3-hal/examples/rtc_watchdog.rs +++ b/esp32c3-hal/examples/rtc_watchdog.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, Rwdt, @@ -24,7 +24,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -37,7 +37,11 @@ fn main() -> ! { rtc.rwdt.start(2000u64.millis()); rtc.rwdt.listen(); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); diff --git a/esp32c3-hal/examples/serial_interrupts.rs b/esp32c3-hal/examples/serial_interrupts.rs index e785a6438..a020c1675 100644 --- a/esp32c3-hal/examples/serial_interrupts.rs +++ b/esp32c3-hal/examples/serial_interrupts.rs @@ -11,28 +11,28 @@ use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, UART0}, + peripherals::{self, Peripherals, UART0}, prelude::*, - serial::config::AtCmdConfig, timer::TimerGroup, + uart::config::AtCmdConfig, Cpu, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; use riscv_rt::entry; -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); +static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); let mut timer0 = timer_group0.timer0; let mut wdt0 = timer_group0.wdt; @@ -54,7 +54,11 @@ fn main() -> ! { critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(serial0)); - interrupt::enable(pac::Interrupt::UART0, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::UART0, + interrupt::Priority::Priority1, + ) + .unwrap(); interrupt::set_kind( Cpu::ProCpu, interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts diff --git a/esp32c3-hal/examples/sha.rs b/esp32c3-hal/examples/sha.rs index 27eca891b..88d8e6edd 100644 --- a/esp32c3-hal/examples/sha.rs +++ b/esp32c3-hal/examples/sha.rs @@ -1,26 +1,26 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of hardware-accelerated and pure software hashing. -//! +//! Demonstrates the use of the SHA peripheral and compares the speed of +//! hardware-accelerated and pure software hashing. #![no_std] #![no_main] use esp32c3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, + sha::{Sha, ShaMode}, timer::TimerGroup, Rtc, - sha::{Sha, ShaMode}, }; -use nb::block; use esp_backtrace as _; use esp_println::println; +use nb::block; use riscv_rt::entry; -use sha2::{Sha256, Digest}; +use sha2::{Digest, Sha256}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -32,48 +32,51 @@ fn main() -> ! { wdt.disable(); rtc.rwdt.disable(); - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data.clone(); let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256); - // Short hashes can be created by decreasing the output buffer to the desired length + // Short hashes can be created by decreasing the output buffer to the desired + // length let mut output = [0u8; 32]; - //let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the unprocessed parts - // The unprocessed parts can be input in the next iteration, you can always add more data until - // finish() is called. After finish() is called update()'s will contribute to a new hash which + // let pre_calc = xtensa_lx::timer::get_cycle_count(); + // The hardware implementation takes a subslice of the input, and returns the + // unprocessed parts The unprocessed parts can be input in the next + // iteration, you can always add more data until finish() is called. After + // finish() is called update()'s will contribute to a new hash which // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of magnitude longer than - // the Sha function itself so not useful for comparing processing time - // println!("Remaining len: {}", remaining.len()); - // All the HW Sha functions are infallible so unwrap is fine to use if you use block! + while remaining.len() > 0 { + // Can add println to view progress, however println takes a few orders of + // magnitude longer than the Sha function itself so not useful for + // comparing processing time println!("Remaining len: {}", + // remaining.len()); + + // All the HW Sha functions are infallible so unwrap is fine to use if you use + // block! remaining = block!(hasher.update(remaining)).unwrap(); } - // Finish can be called as many times as desired to get mutliple copies of the output. + // Finish can be called as many times as desired to get mutliple copies of the + // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); - //let post_calc = xtensa_lx::timer::get_cycle_count(); - //let hw_time = post_calc - pre_calc; - //println!("Took {} cycles", hw_time); + // let post_calc = xtensa_lx::timer::get_cycle_count(); + // let hw_time = post_calc - pre_calc; + // println!("Took {} cycles", hw_time); println!("SHA256 Hash output {:02x?}", output); let _usha = hasher.free(); - - //let pre_calc = xtensa_lx::timer::get_cycle_count(); + // let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha256::new(); hasher.update(source_data); let soft_result = hasher.finalize(); - //let post_calc = xtensa_lx::timer::get_cycle_count(); - //let soft_time = post_calc - pre_calc; - //println!("Took {} cycles", soft_time); + // let post_calc = xtensa_lx::timer::get_cycle_count(); + // let soft_time = post_calc - pre_calc; + // println!("Took {} cycles", soft_time); println!("SHA256 Hash output {:02x?}", soft_result); - //println!("HW SHA is {}x faster", soft_time/hw_time); + // println!("HW SHA is {}x faster", soft_time/hw_time); loop {} } diff --git a/esp32c3-hal/examples/spi_eh1_device_loopback.rs b/esp32c3-hal/examples/spi_eh1_device_loopback.rs index a014cd8eb..21bb1bd36 100644 --- a/esp32c3-hal/examples/spi_eh1_device_loopback.rs +++ b/esp32c3-hal/examples/spi_eh1_device_loopback.rs @@ -22,7 +22,7 @@ use embedded_hal_1::spi::SpiDevice; use esp32c3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiBusController, SpiMode}, timer::TimerGroup, @@ -35,7 +35,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/spi_eh1_loopback.rs b/esp32c3-hal/examples/spi_eh1_loopback.rs index b74005f78..94081fee6 100644 --- a/esp32c3-hal/examples/spi_eh1_loopback.rs +++ b/esp32c3-hal/examples/spi_eh1_loopback.rs @@ -20,7 +20,7 @@ use embedded_hal_1::spi::SpiBus; use esp32c3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -33,7 +33,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/spi_loopback.rs b/esp32c3-hal/examples/spi_loopback.rs index 4e53274d2..0dcf27992 100644 --- a/esp32c3-hal/examples/spi_loopback.rs +++ b/esp32c3-hal/examples/spi_loopback.rs @@ -19,7 +19,7 @@ use esp32c3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -32,7 +32,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/spi_loopback_dma.rs b/esp32c3-hal/examples/spi_loopback_dma.rs index ee1bf7a59..5385c82ae 100644 --- a/esp32c3-hal/examples/spi_loopback_dma.rs +++ b/esp32c3-hal/examples/spi_loopback_dma.rs @@ -18,10 +18,10 @@ use esp32c3_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, gdma::Gdma, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -34,7 +34,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/examples/systimer.rs b/esp32c3-hal/examples/systimer.rs index f3b09b94f..fa8c0fdc3 100644 --- a/esp32c3-hal/examples/systimer.rs +++ b/esp32c3-hal/examples/systimer.rs @@ -11,7 +11,7 @@ use esp32c3_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, systimer::{Alarm, Periodic, SystemTimer, Target}, timer::TimerGroup, @@ -28,7 +28,7 @@ static ALARM2: Mutex>>> = Mutex::new(RefCell::ne #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -63,9 +63,21 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET0, Priority::Priority1).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET1, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET2, Priority::Priority2).unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET0, + Priority::Priority1, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET1, + Priority::Priority2, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET2, + Priority::Priority2, + ) + .unwrap(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. diff --git a/esp32c3-hal/examples/timer_interrupt.rs b/esp32c3-hal/examples/timer_interrupt.rs index 096eed2da..ccad344f3 100644 --- a/esp32c3-hal/examples/timer_interrupt.rs +++ b/esp32c3-hal/examples/timer_interrupt.rs @@ -11,7 +11,7 @@ use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, TIMG0, TIMG1}, + peripherals::{self, Peripherals, TIMG0, TIMG1}, prelude::*, timer::{Timer, Timer0, TimerGroup}, Rtc, @@ -24,7 +24,7 @@ static TIMER1: Mutex>>>> = Mutex::new(RefCell #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -43,11 +43,19 @@ fn main() -> ! { wdt0.disable(); wdt1.disable(); - interrupt::enable(pac::Interrupt::TG0_T0_LEVEL, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::TG0_T0_LEVEL, + interrupt::Priority::Priority1, + ) + .unwrap(); timer0.start(500u64.millis()); timer0.listen(); - interrupt::enable(pac::Interrupt::TG1_T0_LEVEL, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::TG1_T0_LEVEL, + interrupt::Priority::Priority1, + ) + .unwrap(); timer1.start(1u64.secs()); timer1.listen(); diff --git a/esp32c3-hal/examples/usb_serial_jtag.rs b/esp32c3-hal/examples/usb_serial_jtag.rs index 39e736bef..35c08a561 100644 --- a/esp32c3-hal/examples/usb_serial_jtag.rs +++ b/esp32c3-hal/examples/usb_serial_jtag.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32c3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, USB_DEVICE}, + peripherals::{self, Peripherals, USB_DEVICE}, prelude::*, timer::TimerGroup, Cpu, @@ -28,7 +28,7 @@ static USB_SERIAL: Mutex>>> = #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -54,7 +54,7 @@ fn main() -> ! { critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); interrupt::enable( - pac::Interrupt::USB_SERIAL_JTAG, + peripherals::Interrupt::USB_SERIAL_JTAG, interrupt::Priority::Priority1, ) .unwrap(); diff --git a/esp32c3-hal/examples/watchdog.rs b/esp32c3-hal/examples/watchdog.rs index a792ecd49..1eb0ce58d 100644 --- a/esp32c3-hal/examples/watchdog.rs +++ b/esp32c3-hal/examples/watchdog.rs @@ -5,7 +5,13 @@ #![no_std] #![no_main] -use esp32c3_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc}; +use esp32c3_hal::{ + clock::ClockControl, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, +}; use esp_backtrace as _; use esp_println::println; use nb::block; @@ -13,7 +19,7 @@ use riscv_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32c3-hal/src/lib.rs b/esp32c3-hal/src/lib.rs index 2d1390957..5601e49c0 100644 --- a/esp32c3-hal/src/lib.rs +++ b/esp32c3-hal/src/lib.rs @@ -5,6 +5,8 @@ use core::arch::{asm, global_asm}; use core::mem::size_of; pub use embedded_hal as ehal; +#[cfg(feature = "embassy")] +pub use esp_hal_common::embassy; #[doc(inline)] pub use esp_hal_common::{ analog::adc::implementation as adc, @@ -18,14 +20,15 @@ pub use esp_hal_common::{ interrupt, ledc, macros, - pac, + peripherals, prelude, pulse_control, - serial, + sha, spi, system, systimer, timer, + uart, utils, Cpu, Delay, @@ -33,14 +36,9 @@ pub use esp_hal_common::{ Rng, Rtc, Rwdt, - Serial, + Uart, UsbSerialJtag, - sha }; - -#[cfg(feature = "embassy")] -pub use esp_hal_common::embassy; - #[cfg(feature = "direct-boot")] use riscv_rt::pre_init; @@ -407,7 +405,7 @@ unsafe fn configure_mmu() { 0, ); - let peripherals = pac::Peripherals::steal(); + let peripherals = peripherals::Peripherals::steal(); peripherals.EXTMEM.icache_ctrl1.modify(|_, w| { w.icache_shut_ibus() .clear_bit() @@ -444,4 +442,4 @@ pub fn mp_hook() -> bool { } #[no_mangle] -extern "C" fn EspDefaultHandler(_interrupt: pac::Interrupt) {} +extern "C" fn EspDefaultHandler(_interrupt: peripherals::Interrupt) {} diff --git a/esp32s2-hal/examples/adc.rs b/esp32s2-hal/examples/adc.rs index 37588c9ab..50c539fa0 100644 --- a/esp32s2-hal/examples/adc.rs +++ b/esp32s2-hal/examples/adc.rs @@ -9,20 +9,20 @@ use esp32s2_hal::{ adc::{AdcConfig, Attenuation, ADC, ADC1}, clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use esp_println::println; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -57,15 +57,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/advanced_serial.rs b/esp32s2-hal/examples/advanced_serial.rs index e10dd1245..36ac70fc3 100644 --- a/esp32s2-hal/examples/advanced_serial.rs +++ b/esp32s2-hal/examples/advanced_serial.rs @@ -9,26 +9,26 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, - serial::{ + timer::TimerGroup, + uart::{ config::{Config, DataBits, Parity, StopBits}, TxRxPins, }, - timer::TimerGroup, Delay, Rtc, - Serial, + Uart, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use esp_println::println; use nb::block; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,7 +53,7 @@ fn main() -> ! { io.pins.gpio2.into_floating_input(), ); - let mut serial1 = Serial::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); + let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); let mut delay = Delay::new(&clocks); @@ -72,15 +72,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/blinky.rs b/esp32s2-hal/examples/blinky.rs index 5fda08184..393c5c8a4 100644 --- a/esp32s2-hal/examples/blinky.rs +++ b/esp32s2-hal/examples/blinky.rs @@ -8,7 +8,7 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -20,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -49,15 +49,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/clock_monitor.rs b/esp32s2-hal/examples/clock_monitor.rs index 3e5f414f0..cbf7a7431 100644 --- a/esp32s2-hal/examples/clock_monitor.rs +++ b/esp32s2-hal/examples/clock_monitor.rs @@ -11,20 +11,20 @@ use critical_section::Mutex; use esp32s2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use esp_println::println; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; static RTC: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -42,7 +42,11 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); @@ -66,15 +70,18 @@ fn RTC_CORE() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/dac.rs b/esp32s2-hal/examples/dac.rs index 6ffc31e27..e0d5b9a6c 100644 --- a/esp32s2-hal/examples/dac.rs +++ b/esp32s2-hal/examples/dac.rs @@ -9,7 +9,7 @@ use esp32s2_hal::{ clock::ClockControl, dac, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -21,7 +21,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -58,15 +58,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/embassy_hello_world.rs b/esp32s2-hal/examples/embassy_hello_world.rs index b013a98f0..fb31b350b 100644 --- a/esp32s2-hal/examples/embassy_hello_world.rs +++ b/esp32s2-hal/examples/embassy_hello_world.rs @@ -4,16 +4,17 @@ use embassy_executor::Executor; use embassy_time::{Duration, Timer}; - use esp32s2_hal::{ clock::ClockControl, + embassy, + peripherals::Peripherals, prelude::*, timer::TimerGroup, - Rtc, embassy, pac::Peripherals, + Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use static_cell::StaticCell; +use xtensa_atomic_emulation_trap as _; #[embassy_executor::task] async fn run1() { @@ -36,7 +37,7 @@ static EXECUTOR: StaticCell = StaticCell::new(); #[xtensa_lx_rt::entry] fn main() -> ! { esp_println::println!("Init!"); - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -62,15 +63,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/gpio_interrupt.rs b/esp32s2-hal/examples/gpio_interrupt.rs index b8b46793c..7e2285a2f 100644 --- a/esp32s2-hal/examples/gpio_interrupt.rs +++ b/esp32s2-hal/examples/gpio_interrupt.rs @@ -11,10 +11,10 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32s2_hal::{ clock::ClockControl, - gpio::{Gpio0, IO, Event, Input, PullDown}, + gpio::{Event, Gpio0, Input, PullDown, IO}, interrupt, macros::ram, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, timer::TimerGroup, Delay, @@ -28,7 +28,7 @@ static BUTTON: Mutex>>>> = Mutex::new(RefCe #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -49,7 +49,7 @@ fn main() -> ! { critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(pac::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); led.set_high().unwrap(); @@ -80,15 +80,18 @@ fn GPIO() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/hello_rgb.rs b/esp32s2-hal/examples/hello_rgb.rs index 02e3bea89..af1f74015 100644 --- a/esp32s2-hal/examples/hello_rgb.rs +++ b/esp32s2-hal/examples/hello_rgb.rs @@ -13,7 +13,7 @@ use esp32s2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, utils::{smartLedAdapter, SmartLedsAdapter}, @@ -24,18 +24,18 @@ use esp32s2_hal::{ }; #[allow(unused_imports)] use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use smart_leds::{ brightness, gamma, hsv::{hsv2rgb, Hsv}, SmartLedsWrite, }; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -84,15 +84,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/hello_world.rs b/esp32s2-hal/examples/hello_world.rs index 0de84b697..952abc7d8 100644 --- a/esp32s2-hal/examples/hello_world.rs +++ b/esp32s2-hal/examples/hello_world.rs @@ -8,20 +8,20 @@ use core::fmt::Write; use esp32s2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, - Serial, + Uart, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use nb::block; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -29,7 +29,7 @@ fn main() -> ! { let mut timer0 = timer_group0.timer0; let mut wdt = timer_group0.wdt; let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); // Disable MWDT and RWDT (Watchdog) flash boot protection wdt.disable(); @@ -44,11 +44,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs b/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs index ea5355c5f..e6ad37fce 100644 --- a/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs +++ b/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs @@ -13,7 +13,7 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -24,7 +24,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s2-hal/examples/i2c_display.rs b/esp32s2-hal/examples/i2c_display.rs index feed528c2..fcb23e552 100644 --- a/esp32s2-hal/examples/i2c_display.rs +++ b/esp32s2-hal/examples/i2c_display.rs @@ -23,20 +23,20 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use nb::block; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -131,15 +131,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/i2s_read.rs b/esp32s2-hal/examples/i2s_read.rs index ccc6ca78b..c08db6d11 100644 --- a/esp32s2-hal/examples/i2s_read.rs +++ b/esp32s2-hal/examples/i2s_read.rs @@ -1,5 +1,5 @@ //! This shows how to continously receive data via I2S -//! +//! //! Pins used //! BCLK GPIO1 //! WS GPIO2 @@ -7,7 +7,7 @@ //! //! 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 -//! +//! //! You can also inspect the MCLK, BCLK and WS with a logic analyzer #![no_std] @@ -15,10 +15,10 @@ use esp32s2_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, + i2s::{DataFormat, I2s, I2s0New, I2sReadDma, NoMclk, PinsBclkWsDin, Standard}, pdma::Dma, - i2s::{DataFormat, I2s, NoMclk, Standard, I2s0New, PinsBclkWsDin, I2sReadDma}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -30,7 +30,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s2-hal/examples/i2s_sound.rs b/esp32s2-hal/examples/i2s_sound.rs index 21cb3216e..94d94df48 100644 --- a/esp32s2-hal/examples/i2s_sound.rs +++ b/esp32s2-hal/examples/i2s_sound.rs @@ -33,9 +33,9 @@ use esp32s2_hal::{ clock::ClockControl, dma::DmaPriority, + i2s::{DataFormat, I2s, I2s0New, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard}, pdma::Dma, - i2s::{DataFormat, I2s, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard, I2s0New}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -54,7 +54,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s2-hal/examples/ledc.rs b/esp32s2-hal/examples/ledc.rs index 6e3510738..fb47e4912 100644 --- a/esp32s2-hal/examples/ledc.rs +++ b/esp32s2-hal/examples/ledc.rs @@ -16,19 +16,19 @@ use esp32s2_hal::{ LowSpeed, LEDC, }, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use esp_println; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -73,15 +73,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/pulse_control.rs b/esp32s2-hal/examples/pulse_control.rs index 977c394ed..cccede5e6 100644 --- a/esp32s2-hal/examples/pulse_control.rs +++ b/esp32s2-hal/examples/pulse_control.rs @@ -8,7 +8,7 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, pulse_control::{ConfiguredChannel, OutputChannel, PulseCode, RepeatMode}, timer::TimerGroup, @@ -21,7 +21,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -78,11 +78,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/ram.rs b/esp32s2-hal/examples/ram.rs index 4fdc19e99..255a22c2d 100644 --- a/esp32s2-hal/examples/ram.rs +++ b/esp32s2-hal/examples/ram.rs @@ -11,14 +11,14 @@ use esp32s2_hal::{ clock::ClockControl, macros::ram, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, }; use esp_backtrace as _; use esp_println::println; -use xtensa_atomic_emulation_trap as _; use nb::block; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[ram(rtc_fast)] @@ -32,7 +32,7 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -99,11 +99,14 @@ fn function_in_rtc_ram() -> u32 { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/read_efuse.rs b/esp32s2-hal/examples/read_efuse.rs index edd8af52f..50a609dd4 100644 --- a/esp32s2-hal/examples/read_efuse.rs +++ b/esp32s2-hal/examples/read_efuse.rs @@ -7,7 +7,7 @@ use esp32s2_hal::{ clock::ClockControl, efuse::Efuse, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -19,7 +19,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -37,15 +37,18 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/rtc_watchdog.rs b/esp32s2-hal/examples/rtc_watchdog.rs index 163feb10e..dd0112323 100644 --- a/esp32s2-hal/examples/rtc_watchdog.rs +++ b/esp32s2-hal/examples/rtc_watchdog.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32s2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, Rwdt, @@ -25,7 +25,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -39,7 +39,11 @@ fn main() -> ! { critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); loop {} } @@ -59,11 +63,14 @@ fn RTC_CORE() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/serial_interrupts.rs b/esp32s2-hal/examples/serial_interrupts.rs index 0f402546e..283247bff 100644 --- a/esp32s2-hal/examples/serial_interrupts.rs +++ b/esp32s2-hal/examples/serial_interrupts.rs @@ -11,23 +11,23 @@ use critical_section::Mutex; use esp32s2_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, UART0}, + peripherals::{self, Peripherals, UART0}, prelude::*, - serial::config::AtCmdConfig, timer::TimerGroup, + uart::config::AtCmdConfig, Rtc, - Serial, + Uart, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use nb::block; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); +static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -39,7 +39,7 @@ fn main() -> ! { let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); let mut wdt1 = timer_group1.wdt; - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let mut rtc = Rtc::new(peripherals.RTC_CNTL); // Disable MWDT and RWDT (Watchdog) flash boot protection @@ -52,7 +52,11 @@ fn main() -> ! { serial0.listen_at_cmd(); serial0.listen_rx_fifo_full(); - interrupt::enable(pac::Interrupt::UART0, interrupt::Priority::Priority2).unwrap(); + interrupt::enable( + peripherals::Interrupt::UART0, + interrupt::Priority::Priority2, + ) + .unwrap(); timer0.start(1u64.secs()); @@ -95,15 +99,18 @@ fn UART0() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/sha.rs b/esp32s2-hal/examples/sha.rs index 1e16b0f48..c9d53c259 100644 --- a/esp32s2-hal/examples/sha.rs +++ b/esp32s2-hal/examples/sha.rs @@ -1,26 +1,26 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of hardware-accelerated and pure software hashing. -//! +//! Demonstrates the use of the SHA peripheral and compares the speed of +//! hardware-accelerated and pure software hashing. #![no_std] #![no_main] use esp32s2_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, + sha::{Sha, ShaMode}, timer::TimerGroup, Rtc, - sha::{Sha, ShaMode}, }; -use nb::block; use esp_backtrace as _; use esp_println::println; +use nb::block; +use sha2::{Digest, Sha512}; use xtensa_lx_rt::entry; -use sha2::{Sha512, Digest}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -32,30 +32,34 @@ fn main() -> ! { wdt.disable(); rtc.rwdt.disable(); - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data.clone(); let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - // Short hashes can be created by decreasing the output buffer to the desired length + // Short hashes can be created by decreasing the output buffer to the desired + // length let mut output = [0u8; 64]; let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the unprocessed parts - // The unprocessed parts can be input in the next iteration, you can always add more data until - // finish() is called. After finish() is called update()'s will contribute to a new hash which + // The hardware implementation takes a subslice of the input, and returns the + // unprocessed parts The unprocessed parts can be input in the next + // iteration, you can always add more data until finish() is called. After + // finish() is called update()'s will contribute to a new hash which // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of magnitude longer than - // the Sha function itself so not useful for comparing processing time - // println!("Remaining len: {}", remaining.len()); - // All the HW Sha functions are infallible so unwrap is fine to use if you use block! + while remaining.len() > 0 { + // Can add println to view progress, however println takes a few orders of + // magnitude longer than the Sha function itself so not useful for + // comparing processing time println!("Remaining len: {}", + // remaining.len()); + + // All the HW Sha functions are infallible so unwrap is fine to use if you use + // block! remaining = block!(hasher.update(remaining)).unwrap(); } - // Finish can be called as many times as desired to get mutliple copies of the output. + // Finish can be called as many times as desired to get mutliple copies of the + // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); let post_calc = xtensa_lx::timer::get_cycle_count(); let hw_time = post_calc - pre_calc; @@ -63,7 +67,6 @@ fn main() -> ! { println!("SHA512 Hash output {:02x?}", output); let _usha = hasher.free(); - let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new(); hasher.update(source_data); @@ -73,7 +76,7 @@ fn main() -> ! { println!("Took {} cycles", soft_time); println!("SHA512 Hash output {:02x?}", soft_result); - println!("HW SHA is {}x faster", soft_time/hw_time); + println!("HW SHA is {}x faster", soft_time / hw_time); loop {} } diff --git a/esp32s2-hal/examples/spi_eh1_device_loopback.rs b/esp32s2-hal/examples/spi_eh1_device_loopback.rs index a0d7c09a9..f515967fa 100644 --- a/esp32s2-hal/examples/spi_eh1_device_loopback.rs +++ b/esp32s2-hal/examples/spi_eh1_device_loopback.rs @@ -22,7 +22,7 @@ use embedded_hal_1::spi::SpiDevice; use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiBusController, SpiMode}, timer::TimerGroup, @@ -36,7 +36,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -150,11 +150,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/spi_eh1_loopback.rs b/esp32s2-hal/examples/spi_eh1_loopback.rs index 64dc7f2dd..3592fc785 100644 --- a/esp32s2-hal/examples/spi_eh1_loopback.rs +++ b/esp32s2-hal/examples/spi_eh1_loopback.rs @@ -20,7 +20,7 @@ use embedded_hal_1::spi::SpiBus; use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -34,7 +34,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -122,11 +122,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/spi_loopback.rs b/esp32s2-hal/examples/spi_loopback.rs index 8360cff63..ff4769516 100644 --- a/esp32s2-hal/examples/spi_loopback.rs +++ b/esp32s2-hal/examples/spi_loopback.rs @@ -19,7 +19,7 @@ use esp32s2_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -33,7 +33,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -76,11 +76,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/spi_loopback_dma.rs b/esp32s2-hal/examples/spi_loopback_dma.rs index a8a72cc09..35ccfbe76 100644 --- a/esp32s2-hal/examples/spi_loopback_dma.rs +++ b/esp32s2-hal/examples/spi_loopback_dma.rs @@ -18,10 +18,10 @@ use esp32s2_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, gpio::IO, - pac::Peripherals, pdma::Dma, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -29,13 +29,13 @@ use esp32s2_hal::{ Rtc, }; use esp_backtrace as _; -use xtensa_atomic_emulation_trap as _; use esp_println::println; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -120,15 +120,18 @@ fn buffer2() -> &'static mut [u8; 32000] { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/systimer.rs b/esp32s2-hal/examples/systimer.rs index e54c467b1..3f4fe809a 100644 --- a/esp32s2-hal/examples/systimer.rs +++ b/esp32s2-hal/examples/systimer.rs @@ -11,7 +11,7 @@ use esp32s2_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, systimer::{Alarm, Periodic, SystemTimer, Target}, timer::TimerGroup, @@ -29,7 +29,7 @@ static ALARM2: Mutex>>> = Mutex::new(RefCell::ne #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -63,9 +63,21 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET0, Priority::Priority1).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET1, Priority::Priority3).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET2, Priority::Priority3).unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET0, + Priority::Priority1, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET1, + Priority::Priority3, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET2, + Priority::Priority3, + ) + .unwrap(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. @@ -113,11 +125,14 @@ fn SYSTIMER_TARGET2() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/examples/timer_interrupt.rs b/esp32s2-hal/examples/timer_interrupt.rs index 3e227ae6b..42acbaf5b 100644 --- a/esp32s2-hal/examples/timer_interrupt.rs +++ b/esp32s2-hal/examples/timer_interrupt.rs @@ -12,7 +12,7 @@ use esp32s2_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals, TIMG0, TIMG1}, + peripherals::{self, Peripherals, TIMG0, TIMG1}, prelude::*, timer::{Timer, Timer0, Timer1, TimerGroup}, Rtc, @@ -29,7 +29,7 @@ static TIMER11: Mutex>>>> = Mutex::new(RefCel #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -51,10 +51,10 @@ fn main() -> ! { wdt1.disable(); rtc.rwdt.disable(); - interrupt::enable(pac::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); timer00.start(500u64.millis()); timer00.listen(); timer01.start(2500u64.millis()); @@ -131,15 +131,18 @@ fn TG1_T1_LEVEL() { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { println!("0x{:x}", addr) } } -} \ No newline at end of file +} diff --git a/esp32s2-hal/examples/usb_serial.rs b/esp32s2-hal/examples/usb_serial.rs index 70dd0c19d..e2b127f28 100644 --- a/esp32s2-hal/examples/usb_serial.rs +++ b/esp32s2-hal/examples/usb_serial.rs @@ -8,7 +8,7 @@ use esp32s2_hal::{ clock::{ClockControl, CpuClock}, otg_fs::{UsbBus, USB}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -22,7 +22,7 @@ static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze(); diff --git a/esp32s2-hal/examples/watchdog.rs b/esp32s2-hal/examples/watchdog.rs index bc0204b27..9fd4d2f55 100644 --- a/esp32s2-hal/examples/watchdog.rs +++ b/esp32s2-hal/examples/watchdog.rs @@ -5,16 +5,22 @@ #![no_std] #![no_main] -use esp32s2_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc}; +use esp32s2_hal::{ + clock::ClockControl, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, +}; use esp_backtrace as _; use esp_println::println; -use xtensa_atomic_emulation_trap as _; use nb::block; +use xtensa_atomic_emulation_trap as _; use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -36,11 +42,14 @@ fn main() -> ! { } #[xtensa_lx_rt::exception] -fn exception(cause: xtensa_lx_rt::exception::ExceptionCause, frame: xtensa_lx_rt::exception::Context) { +fn exception( + cause: xtensa_lx_rt::exception::ExceptionCause, + frame: xtensa_lx_rt::exception::Context, +) { use esp_println::*; println!("\n\nException occured {:?} {:x?}", cause, frame); - + let backtrace = esp_backtrace::arch::backtrace(); for b in backtrace.iter() { if let Some(addr) = b { diff --git a/esp32s2-hal/src/lib.rs b/esp32s2-hal/src/lib.rs index e4f001b95..1c9f481fb 100644 --- a/esp32s2-hal/src/lib.rs +++ b/esp32s2-hal/src/lib.rs @@ -1,6 +1,8 @@ #![no_std] pub use embedded_hal as ehal; +#[cfg(feature = "embassy")] +pub use esp_hal_common::embassy; #[doc(inline)] pub use esp_hal_common::{ analog::adc::implementation as adc, @@ -10,20 +12,21 @@ pub use esp_hal_common::{ dma::pdma, efuse, gpio, - i2s, i2c::{self, I2C}, + i2s, interrupt, ledc, macros, otg_fs, - pac, + peripherals, prelude, pulse_control, - serial, + sha, spi, system, systimer, timer, + uart, utils, Cpu, Delay, @@ -31,13 +34,9 @@ pub use esp_hal_common::{ Rng, Rtc, Rwdt, - Serial, - sha + Uart, }; -#[cfg(feature = "embassy")] -pub use esp_hal_common::embassy; - pub use self::gpio::IO; /// Common module for analog functions @@ -46,7 +45,7 @@ pub mod analog { } #[no_mangle] -extern "C" fn EspDefaultHandler(_level: u32, _interrupt: pac::Interrupt) {} +extern "C" fn EspDefaultHandler(_level: u32, _interrupt: peripherals::Interrupt) {} #[no_mangle] extern "C" fn DefaultHandler() {} diff --git a/esp32s3-hal/examples/adc.rs b/esp32s3-hal/examples/adc.rs index 60e710e6f..826ec5eae 100644 --- a/esp32s3-hal/examples/adc.rs +++ b/esp32s3-hal/examples/adc.rs @@ -9,7 +9,7 @@ use esp32s3_hal::{ adc::{AdcConfig, Attenuation, ADC, ADC1}, clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -21,7 +21,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/advanced_serial.rs b/esp32s3-hal/examples/advanced_serial.rs index 30f4eeec4..fd86b44c5 100644 --- a/esp32s3-hal/examples/advanced_serial.rs +++ b/esp32s3-hal/examples/advanced_serial.rs @@ -9,16 +9,16 @@ use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, - serial::{ + timer::TimerGroup, + uart::{ config::{Config, DataBits, Parity, StopBits}, TxRxPins, }, - timer::TimerGroup, Delay, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use esp_println::println; @@ -27,7 +27,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -52,7 +52,7 @@ fn main() -> ! { io.pins.gpio2.into_floating_input(), ); - let mut serial1 = Serial::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); + let mut serial1 = Uart::new_with_config(peripherals.UART1, Some(config), Some(pins), &clocks); let mut delay = Delay::new(&clocks); diff --git a/esp32s3-hal/examples/blinky.rs b/esp32s3-hal/examples/blinky.rs index 33d51a856..8338c70d4 100644 --- a/esp32s3-hal/examples/blinky.rs +++ b/esp32s3-hal/examples/blinky.rs @@ -8,7 +8,7 @@ use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Delay, @@ -19,7 +19,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/clock_monitor.rs b/esp32s3-hal/examples/clock_monitor.rs index d101a0020..06c3016bf 100644 --- a/esp32s3-hal/examples/clock_monitor.rs +++ b/esp32s3-hal/examples/clock_monitor.rs @@ -11,7 +11,7 @@ use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, }; @@ -23,7 +23,7 @@ static RTC: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -41,7 +41,11 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); diff --git a/esp32s3-hal/examples/embassy_hello_world.rs b/esp32s3-hal/examples/embassy_hello_world.rs index f707a86a5..7d02ef220 100644 --- a/esp32s3-hal/examples/embassy_hello_world.rs +++ b/esp32s3-hal/examples/embassy_hello_world.rs @@ -4,12 +4,13 @@ use embassy_executor::Executor; use embassy_time::{Duration, Timer}; - use esp32s3_hal::{ clock::ClockControl, + embassy, + peripherals::Peripherals, prelude::*, timer::TimerGroup, - Rtc, embassy, pac::Peripherals, + Rtc, }; use esp_backtrace as _; use static_cell::StaticCell; @@ -35,7 +36,7 @@ static EXECUTOR: StaticCell = StaticCell::new(); #[xtensa_lx_rt::entry] fn main() -> ! { esp_println::println!("Init!"); - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -52,7 +53,10 @@ fn main() -> ! { wdt1.disable(); #[cfg(feature = "embassy-time-systick")] - embassy::init(&clocks, esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER)); + embassy::init( + &clocks, + esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), + ); #[cfg(feature = "embassy-time-timg0")] embassy::init(&clocks, timer_group0.timer0); @@ -62,4 +66,4 @@ fn main() -> ! { spawner.spawn(run1()).ok(); spawner.spawn(run2()).ok(); }); -} \ No newline at end of file +} diff --git a/esp32s3-hal/examples/gpio_interrupt.rs b/esp32s3-hal/examples/gpio_interrupt.rs index a56246472..215829cd1 100644 --- a/esp32s3-hal/examples/gpio_interrupt.rs +++ b/esp32s3-hal/examples/gpio_interrupt.rs @@ -11,10 +11,10 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, - gpio::{Gpio0, IO, Event, Input, PullDown}, + gpio::{Event, Gpio0, Input, PullDown, IO}, interrupt, macros::ram, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, timer::TimerGroup, Delay, @@ -27,7 +27,7 @@ static BUTTON: Mutex>>>> = Mutex::new(RefCe #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -48,7 +48,7 @@ fn main() -> ! { critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(pac::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); led.set_high().unwrap(); diff --git a/esp32s3-hal/examples/hello_rgb.rs b/esp32s3-hal/examples/hello_rgb.rs index e7c9c9728..5d5c71d16 100644 --- a/esp32s3-hal/examples/hello_rgb.rs +++ b/esp32s3-hal/examples/hello_rgb.rs @@ -13,7 +13,7 @@ use esp32s3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, pulse_control::ClockSource, timer::TimerGroup, @@ -35,7 +35,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/hello_world.rs b/esp32s3-hal/examples/hello_world.rs index 9ab714e9d..433cd7487 100644 --- a/esp32s3-hal/examples/hello_world.rs +++ b/esp32s3-hal/examples/hello_world.rs @@ -8,11 +8,11 @@ use core::fmt::Write; use esp32s3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; @@ -20,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -28,7 +28,7 @@ fn main() -> ! { let mut timer0 = timer_group0.timer0; let mut wdt = timer_group0.wdt; let mut rtc = Rtc::new(peripherals.RTC_CNTL); - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); // Disable MWDT and RWDT (Watchdog) flash boot protection wdt.disable(); diff --git a/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs b/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs index 5eb692c56..301a5a43d 100644 --- a/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs +++ b/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs @@ -10,7 +10,13 @@ #![no_main] use esp32s3_hal::{ - clock::ClockControl, gpio::IO, i2c::I2C, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc, + clock::ClockControl, + gpio::IO, + i2c::I2C, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, }; use esp_backtrace as _; use esp_println::println; @@ -18,7 +24,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/i2c_display.rs b/esp32s3-hal/examples/i2c_display.rs index 437191794..b61c213ae 100644 --- a/esp32s3-hal/examples/i2c_display.rs +++ b/esp32s3-hal/examples/i2c_display.rs @@ -20,7 +20,13 @@ use embedded_graphics::{ text::{Alignment, Text}, }; use esp32s3_hal::{ - clock::ClockControl, gpio::IO, i2c::I2C, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc, + clock::ClockControl, + gpio::IO, + i2c::I2C, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, }; use esp_backtrace as _; use nb::block; @@ -29,7 +35,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/i2s_read.rs b/esp32s3-hal/examples/i2s_read.rs index 73dc48c21..b711769ff 100644 --- a/esp32s3-hal/examples/i2s_read.rs +++ b/esp32s3-hal/examples/i2s_read.rs @@ -18,8 +18,8 @@ use esp32s3_hal::{ clock::ClockControl, dma::DmaPriority, gdma::Gdma, - i2s::{DataFormat, I2s, I2sReadDma, MclkPin, PinsBclkWsDin, Standard, I2s0New}, - pac::Peripherals, + i2s::{DataFormat, I2s, I2s0New, I2sReadDma, MclkPin, PinsBclkWsDin, Standard}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -31,7 +31,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/i2s_sound.rs b/esp32s3-hal/examples/i2s_sound.rs index 6f790ddc7..a24e1c2e2 100644 --- a/esp32s3-hal/examples/i2s_sound.rs +++ b/esp32s3-hal/examples/i2s_sound.rs @@ -34,8 +34,8 @@ use esp32s3_hal::{ clock::ClockControl, dma::DmaPriority, gdma::Gdma, - i2s::{DataFormat, I2s, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard, I2s0New}, - pac::Peripherals, + i2s::{DataFormat, I2s, I2s0New, I2sWriteDma, MclkPin, PinsBclkWsDout, Standard}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -54,7 +54,7 @@ const SINE: [i16; 64] = [ #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/ledc.rs b/esp32s3-hal/examples/ledc.rs index 412686101..ae5cca47a 100644 --- a/esp32s3-hal/examples/ledc.rs +++ b/esp32s3-hal/examples/ledc.rs @@ -16,7 +16,7 @@ use esp32s3_hal::{ LowSpeed, LEDC, }, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -26,7 +26,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/mcpwm.rs b/esp32s3-hal/examples/mcpwm.rs index 43e62c6b5..56a208323 100644 --- a/esp32s3-hal/examples/mcpwm.rs +++ b/esp32s3-hal/examples/mcpwm.rs @@ -1,4 +1,5 @@ -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty signal at 20 kHz. +//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty +//! signal at 20 kHz. //! //! The signal will be output to the pin assigned to `pin`. (GPIO4) @@ -8,12 +9,8 @@ use esp32s3_hal::{ clock::ClockControl, gpio::IO, - mcpwm::{ - {MCPWM, PeripheralClockConfig}, - operator::PwmPinConfig, - timer::PwmWorkingMode, - }, - pac::Peripherals, + mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -23,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -53,8 +50,11 @@ fn main() -> ! { .operator0 .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH); - // start timer with timestamp values in the range of 0..=99 and a frequency of 20 kHz - let timer_clock_cfg = clock_cfg.timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()).unwrap(); + // start timer with timestamp values in the range of 0..=99 and a frequency of + // 20 kHz + let timer_clock_cfg = clock_cfg + .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) + .unwrap(); mcpwm.timer0.start(timer_clock_cfg); // pin will be high 50% of the time diff --git a/esp32s3-hal/examples/multicore.rs b/esp32s3-hal/examples/multicore.rs index 804c6cc89..d586f101c 100644 --- a/esp32s3-hal/examples/multicore.rs +++ b/esp32s3-hal/examples/multicore.rs @@ -10,7 +10,7 @@ use core::cell::RefCell; use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, - pac::{Peripherals, TIMG1}, + peripherals::{Peripherals, TIMG1}, prelude::*, timer::{Timer, Timer0, TimerGroup}, CpuControl, @@ -23,7 +23,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/pulse_control.rs b/esp32s3-hal/examples/pulse_control.rs index 0288541ea..83ba6a02a 100644 --- a/esp32s3-hal/examples/pulse_control.rs +++ b/esp32s3-hal/examples/pulse_control.rs @@ -8,7 +8,7 @@ use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, pulse_control::{ClockSource, ConfiguredChannel, OutputChannel, PulseCode, RepeatMode}, timer::TimerGroup, @@ -20,7 +20,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/ram.rs b/esp32s3-hal/examples/ram.rs index 2dd277b95..a85231e93 100644 --- a/esp32s3-hal/examples/ram.rs +++ b/esp32s3-hal/examples/ram.rs @@ -11,7 +11,7 @@ use esp32s3_hal::{ clock::ClockControl, macros::ram, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, }; @@ -31,7 +31,7 @@ static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/read_efuse.rs b/esp32s3-hal/examples/read_efuse.rs index c5672d603..9ac89f563 100644 --- a/esp32s3-hal/examples/read_efuse.rs +++ b/esp32s3-hal/examples/read_efuse.rs @@ -7,7 +7,7 @@ use esp32s3_hal::{ clock::ClockControl, efuse::Efuse, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -18,7 +18,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/rtc_watchdog.rs b/esp32s3-hal/examples/rtc_watchdog.rs index 23495d2aa..c588f8981 100644 --- a/esp32s3-hal/examples/rtc_watchdog.rs +++ b/esp32s3-hal/examples/rtc_watchdog.rs @@ -12,7 +12,7 @@ use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, Rtc, Rwdt, @@ -24,7 +24,7 @@ static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -38,7 +38,11 @@ fn main() -> ! { critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - interrupt::enable(pac::Interrupt::RTC_CORE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::RTC_CORE, + interrupt::Priority::Priority1, + ) + .unwrap(); loop {} } diff --git a/esp32s3-hal/examples/serial_interrupts.rs b/esp32s3-hal/examples/serial_interrupts.rs index ce57e8d14..3fdce1270 100644 --- a/esp32s3-hal/examples/serial_interrupts.rs +++ b/esp32s3-hal/examples/serial_interrupts.rs @@ -11,22 +11,22 @@ use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, UART0}, + peripherals::{self, Peripherals, UART0}, prelude::*, - serial::config::AtCmdConfig, timer::TimerGroup, + uart::config::AtCmdConfig, Rtc, - Serial, + Uart, }; use esp_backtrace as _; use nb::block; use xtensa_lx_rt::entry; -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); +static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -38,7 +38,7 @@ fn main() -> ! { let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); let mut wdt1 = timer_group1.wdt; - let mut serial0 = Serial::new(peripherals.UART0); + let mut serial0 = Uart::new(peripherals.UART0); let mut rtc = Rtc::new(peripherals.RTC_CNTL); // Disable MWDT and RWDT (Watchdog) flash boot protection @@ -51,7 +51,11 @@ fn main() -> ! { serial0.listen_at_cmd(); serial0.listen_rx_fifo_full(); - interrupt::enable(pac::Interrupt::UART0, interrupt::Priority::Priority2).unwrap(); + interrupt::enable( + peripherals::Interrupt::UART0, + interrupt::Priority::Priority2, + ) + .unwrap(); timer0.start(1u64.secs()); diff --git a/esp32s3-hal/examples/sha.rs b/esp32s3-hal/examples/sha.rs index b47b11f51..bd81f660e 100644 --- a/esp32s3-hal/examples/sha.rs +++ b/esp32s3-hal/examples/sha.rs @@ -1,26 +1,26 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of hardware-accelerated and pure software hashing. -//! +//! Demonstrates the use of the SHA peripheral and compares the speed of +//! hardware-accelerated and pure software hashing. #![no_std] #![no_main] use esp32s3_hal::{ clock::ClockControl, - pac::Peripherals, + peripherals::Peripherals, prelude::*, + sha::{Sha, ShaMode}, timer::TimerGroup, Rtc, - sha::{Sha, ShaMode}, }; -use nb::block; use esp_backtrace as _; use esp_println::println; +use nb::block; +use sha2::{Digest, Sha512}; use xtensa_lx_rt::entry; -use sha2::{Sha512, Digest}; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -32,30 +32,34 @@ fn main() -> ! { wdt.disable(); rtc.rwdt.disable(); - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data.clone(); let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - // Short hashes can be created by decreasing the output buffer to the desired length + // Short hashes can be created by decreasing the output buffer to the desired + // length let mut output = [0u8; 64]; let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the unprocessed parts - // The unprocessed parts can be input in the next iteration, you can always add more data until - // finish() is called. After finish() is called update()'s will contribute to a new hash which + // The hardware implementation takes a subslice of the input, and returns the + // unprocessed parts The unprocessed parts can be input in the next + // iteration, you can always add more data until finish() is called. After + // finish() is called update()'s will contribute to a new hash which // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of magnitude longer than - // the Sha function itself so not useful for comparing processing time - // println!("Remaining len: {}", remaining.len()); - // All the HW Sha functions are infallible so unwrap is fine to use if you use block! + while remaining.len() > 0 { + // Can add println to view progress, however println takes a few orders of + // magnitude longer than the Sha function itself so not useful for + // comparing processing time println!("Remaining len: {}", + // remaining.len()); + + // All the HW Sha functions are infallible so unwrap is fine to use if you use + // block! remaining = block!(hasher.update(remaining)).unwrap(); } - // Finish can be called as many times as desired to get mutliple copies of the output. + // Finish can be called as many times as desired to get mutliple copies of the + // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); let post_calc = xtensa_lx::timer::get_cycle_count(); let hw_time = post_calc - pre_calc; @@ -63,7 +67,6 @@ fn main() -> ! { println!("SHA512 Hash output {:02x?}", output); let _usha = hasher.free(); - let pre_calc = xtensa_lx::timer::get_cycle_count(); let mut hasher = Sha512::new(); hasher.update(source_data); @@ -73,7 +76,7 @@ fn main() -> ! { println!("Took {} cycles", soft_time); println!("SHA512 Hash output {:02x?}", soft_result); - println!("HW SHA is {}x faster", soft_time/hw_time); + println!("HW SHA is {}x faster", soft_time / hw_time); loop {} } diff --git a/esp32s3-hal/examples/spi_eh1_device_loopback.rs b/esp32s3-hal/examples/spi_eh1_device_loopback.rs index 297e334df..154a4adf6 100644 --- a/esp32s3-hal/examples/spi_eh1_device_loopback.rs +++ b/esp32s3-hal/examples/spi_eh1_device_loopback.rs @@ -22,7 +22,7 @@ use embedded_hal_1::spi::SpiDevice; use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiBusController, SpiMode}, timer::TimerGroup, @@ -35,7 +35,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/spi_eh1_loopback.rs b/esp32s3-hal/examples/spi_eh1_loopback.rs index d48353802..ae85a037f 100644 --- a/esp32s3-hal/examples/spi_eh1_loopback.rs +++ b/esp32s3-hal/examples/spi_eh1_loopback.rs @@ -20,7 +20,7 @@ use embedded_hal_1::spi::SpiBus; use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -33,7 +33,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/spi_loopback.rs b/esp32s3-hal/examples/spi_loopback.rs index 7e7503e13..c1c2ca2ef 100644 --- a/esp32s3-hal/examples/spi_loopback.rs +++ b/esp32s3-hal/examples/spi_loopback.rs @@ -19,7 +19,7 @@ use esp32s3_hal::{ clock::ClockControl, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -32,7 +32,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/spi_loopback_dma.rs b/esp32s3-hal/examples/spi_loopback_dma.rs index 94a3dd963..92b3ebaeb 100644 --- a/esp32s3-hal/examples/spi_loopback_dma.rs +++ b/esp32s3-hal/examples/spi_loopback_dma.rs @@ -18,10 +18,10 @@ use esp32s3_hal::{ clock::ClockControl, - dma::{DmaPriority}, + dma::DmaPriority, gdma::Gdma, gpio::IO, - pac::Peripherals, + peripherals::Peripherals, prelude::*, spi::{Spi, SpiMode}, timer::TimerGroup, @@ -34,7 +34,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/examples/systimer.rs b/esp32s3-hal/examples/systimer.rs index 8c360983e..c6c63175a 100644 --- a/esp32s3-hal/examples/systimer.rs +++ b/esp32s3-hal/examples/systimer.rs @@ -11,7 +11,7 @@ use esp32s3_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals}, + peripherals::{self, Peripherals}, prelude::*, systimer::{Alarm, Periodic, SystemTimer, Target}, timer::TimerGroup, @@ -28,7 +28,7 @@ static ALARM2: Mutex>>> = Mutex::new(RefCell::ne #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -62,9 +62,21 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET0, Priority::Priority1).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET1, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::SYSTIMER_TARGET2, Priority::Priority3).unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET0, + Priority::Priority1, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET1, + Priority::Priority2, + ) + .unwrap(); + interrupt::enable( + peripherals::Interrupt::SYSTIMER_TARGET2, + Priority::Priority3, + ) + .unwrap(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. diff --git a/esp32s3-hal/examples/timer_interrupt.rs b/esp32s3-hal/examples/timer_interrupt.rs index 9a99bf6bd..ab8405f1f 100644 --- a/esp32s3-hal/examples/timer_interrupt.rs +++ b/esp32s3-hal/examples/timer_interrupt.rs @@ -12,7 +12,7 @@ use esp32s3_hal::{ clock::ClockControl, interrupt, interrupt::Priority, - pac::{self, Peripherals, TIMG0, TIMG1}, + peripherals::{self, Peripherals, TIMG0, TIMG1}, prelude::*, timer::{Timer, Timer0, Timer1, TimerGroup}, Rtc, @@ -28,7 +28,7 @@ static TIMER11: Mutex>>>> = Mutex::new(RefCel #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -50,10 +50,10 @@ fn main() -> ! { wdt1.disable(); rtc.rwdt.disable(); - interrupt::enable(pac::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(pac::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); + interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); timer00.start(500u64.millis()); timer00.listen(); timer01.start(2500u64.millis()); diff --git a/esp32s3-hal/examples/usb_serial.rs b/esp32s3-hal/examples/usb_serial.rs index e2f9f8d9a..2df9d099f 100644 --- a/esp32s3-hal/examples/usb_serial.rs +++ b/esp32s3-hal/examples/usb_serial.rs @@ -8,7 +8,7 @@ use esp32s3_hal::{ clock::{ClockControl, CpuClock}, otg_fs::{UsbBus, USB}, - pac::Peripherals, + peripherals::Peripherals, prelude::*, timer::TimerGroup, Rtc, @@ -22,7 +22,7 @@ static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let mut system = peripherals.SYSTEM.split(); let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze(); diff --git a/esp32s3-hal/examples/usb_serial_jtag.rs b/esp32s3-hal/examples/usb_serial_jtag.rs index 82ebb6280..6cc0f48ed 100644 --- a/esp32s3-hal/examples/usb_serial_jtag.rs +++ b/esp32s3-hal/examples/usb_serial_jtag.rs @@ -13,7 +13,7 @@ use critical_section::Mutex; use esp32s3_hal::{ clock::ClockControl, interrupt, - pac::{self, Peripherals, USB_DEVICE}, + peripherals::{self, Peripherals, USB_DEVICE}, prelude::*, timer::TimerGroup, Rtc, @@ -28,7 +28,7 @@ static USB_SERIAL: Mutex>>> = #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); @@ -49,7 +49,11 @@ fn main() -> ! { critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); - interrupt::enable(pac::Interrupt::USB_DEVICE, interrupt::Priority::Priority1).unwrap(); + interrupt::enable( + peripherals::Interrupt::USB_DEVICE, + interrupt::Priority::Priority1, + ) + .unwrap(); loop { critical_section::with(|cs| { diff --git a/esp32s3-hal/examples/watchdog.rs b/esp32s3-hal/examples/watchdog.rs index f1bb092ab..7c6fc4fcf 100644 --- a/esp32s3-hal/examples/watchdog.rs +++ b/esp32s3-hal/examples/watchdog.rs @@ -5,7 +5,13 @@ #![no_std] #![no_main] -use esp32s3_hal::{clock::ClockControl, pac::Peripherals, prelude::*, timer::TimerGroup, Rtc}; +use esp32s3_hal::{ + clock::ClockControl, + peripherals::Peripherals, + prelude::*, + timer::TimerGroup, + Rtc, +}; use esp_backtrace as _; use esp_println::println; use nb::block; @@ -13,7 +19,7 @@ use xtensa_lx_rt::entry; #[entry] fn main() -> ! { - let peripherals = Peripherals::take().unwrap(); + let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); diff --git a/esp32s3-hal/src/lib.rs b/esp32s3-hal/src/lib.rs index 4d584488e..1025c82d5 100644 --- a/esp32s3-hal/src/lib.rs +++ b/esp32s3-hal/src/lib.rs @@ -3,6 +3,8 @@ #![cfg_attr(feature = "direct-boot", feature(asm_experimental_arch))] pub use embedded_hal as ehal; +#[cfg(feature = "embassy")] +pub use esp_hal_common::embassy; #[doc(inline)] pub use esp_hal_common::{ analog::adc::implementation as adc, @@ -18,14 +20,15 @@ pub use esp_hal_common::{ macros, mcpwm, otg_fs, - pac, + peripherals, prelude, pulse_control, - serial, + sha, spi, system, systimer, timer, + uart, utils, Cpu, Delay, @@ -33,14 +36,10 @@ pub use esp_hal_common::{ Rng, Rtc, Rwdt, - Serial, + Uart, UsbSerialJtag, - sha }; -#[cfg(feature = "embassy")] -pub use esp_hal_common::embassy; - pub use self::gpio::IO; /// Common module for analog functions @@ -49,7 +48,7 @@ pub mod analog { } #[no_mangle] -extern "C" fn EspDefaultHandler(_level: u32, _interrupt: pac::Interrupt) {} +extern "C" fn EspDefaultHandler(_level: u32, _interrupt: peripherals::Interrupt) {} #[no_mangle] extern "C" fn DefaultHandler() {} @@ -142,24 +141,24 @@ pub unsafe fn startup_direct_boot() -> ! { // do some configurations for compatability with the 2nd stage bootloader // this is a workaround and ideally we should deal with these settings in other // places - (&*crate::pac::TIMG0::PTR) + (&*crate::peripherals::TIMG0::PTR) .int_ena_timers .modify(|_, w| w.t0_int_ena().set_bit().t1_int_ena().set_bit()); - (&*crate::pac::TIMG1::PTR) + (&*crate::peripherals::TIMG1::PTR) .int_ena_timers .modify(|_, w| w.t0_int_ena().set_bit().t1_int_ena().set_bit()); - (&*crate::pac::RTC_CNTL::PTR) + (&*crate::peripherals::RTC_CNTL::PTR) .swd_wprotect .write(|w| w.bits(0x8f1d312a)); - (&*crate::pac::RTC_CNTL::PTR) + (&*crate::peripherals::RTC_CNTL::PTR) .swd_conf .modify(|_, w| w.swd_disable().set_bit()); - (&*crate::pac::RTC_CNTL::PTR) + (&*crate::peripherals::RTC_CNTL::PTR) .swd_wprotect .write(|w| w.bits(0)); - (&*crate::pac::SYSTEM::PTR) + (&*crate::peripherals::SYSTEM::PTR) .sysclk_conf .modify(|_, w| w.soc_clk_sel().bits(1));