Delay::delay (#1298)

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
This commit is contained in:
Zgarbul Andrey 2024-03-21 02:45:02 +03:00 committed by GitHub
parent e98cf71b67
commit 4a0a19e253
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
64 changed files with 130 additions and 110 deletions

View File

@ -12,7 +12,7 @@
//! //!
//! ```rust,ignore //! ```rust,ignore
//! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); //! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
//! let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); //! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &clocks).unwrap();
//! //!
//! let rmt_buffer = smartLedBuffer!(1); //! let rmt_buffer = smartLedBuffer!(1);
//! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer); //! let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer);

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ESP32-C6 / ESP32-H2: Implement `ETM` for general purpose timers (#1274) - ESP32-C6 / ESP32-H2: Implement `ETM` for general purpose timers (#1274)
- `interrupt::enable` now has a direct CPU enable counter part, `interrupt::enable_direct` (#1310) - `interrupt::enable` now has a direct CPU enable counter part, `interrupt::enable_direct` (#1310)
- `Delay::delay(time: fugit::MicrosDurationU64)`
### Fixed ### Fixed
@ -21,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Remove `Ext32` and `RateExtU64` from prelude
- Prefer mutable references over moving for DMA transactions (#1238) - Prefer mutable references over moving for DMA transactions (#1238)
- Support runtime interrupt binding, adapt GPIO driver (#1231) - Support runtime interrupt binding, adapt GPIO driver (#1231)
- Renamed `eh1` feature to `embedded-hal`, feature-gated `embedded-hal@0.2.x` trait implementations (#1273) - Renamed `eh1` feature to `embedded-hal`, feature-gated `embedded-hal@0.2.x` trait implementations (#1273)

View File

@ -23,6 +23,7 @@
//! [embedded-hal]: https://docs.rs/embedded-hal/0.2.7/embedded_hal/index.html //! [embedded-hal]: https://docs.rs/embedded-hal/0.2.7/embedded_hal/index.html
use fugit::HertzU64; use fugit::HertzU64;
pub use fugit::MicrosDurationU64;
/// Delay driver /// Delay driver
/// ///
@ -37,7 +38,7 @@ impl Delay {
/// Delay for the specified number of milliseconds /// Delay for the specified number of milliseconds
pub fn delay_millis(&self, ms: u32) { pub fn delay_millis(&self, ms: u32) {
for _ in 0..ms { for _ in 0..ms {
self.delay_micros(1000u32); self.delay_micros(1000);
} }
} }
} }
@ -49,7 +50,7 @@ where
{ {
fn delay_ms(&mut self, ms: T) { fn delay_ms(&mut self, ms: T) {
for _ in 0..ms.into() { for _ in 0..ms.into() {
self.delay_micros(1000u32); self.delay_micros(1000);
} }
} }
} }
@ -87,6 +88,15 @@ mod implementation {
} }
} }
/// Delay for the specified time
pub fn delay(&self, time: MicrosDurationU64) {
let t0 = SystemTimer::now();
let rate: HertzU64 = MicrosDurationU64::from_ticks(1).into_rate();
let clocks = time.ticks() * (self.freq / rate);
while SystemTimer::now().wrapping_sub(t0) & SystemTimer::BIT_MASK <= clocks {}
}
/// Delay for the specified number of microseconds /// Delay for the specified number of microseconds
pub fn delay_micros(&self, us: u32) { pub fn delay_micros(&self, us: u32) {
let t0 = SystemTimer::now(); let t0 = SystemTimer::now();
@ -118,6 +128,13 @@ mod implementation {
} }
} }
/// Delay for the specified time
pub fn delay(&self, time: MicrosDurationU64) {
let rate: HertzU64 = MicrosDurationU64::from_ticks(1).into_rate();
let clocks = time.ticks() * (self.freq / rate);
xtensa_lx::timer::delay(clocks as u32);
}
/// Delay for the specified number of microseconds /// Delay for the specified number of microseconds
pub fn delay_micros(&self, us: u32) { pub fn delay_micros(&self, us: u32) {
let clocks = us as u64 * (self.freq / HertzU64::MHz(1)); let clocks = us as u64 * (self.freq / HertzU64::MHz(1));

View File

@ -51,7 +51,7 @@
//! mosi, //! mosi,
//! miso, //! miso,
//! cs, //! cs,
//! 100u32.kHz(), //! 100.kHz(),
//! SpiMode::Mode0, //! SpiMode::Mode0,
//! &clocks, //! &clocks,
//! ) //! )

View File

@ -21,7 +21,7 @@
//! peripherals.I2C0, //! peripherals.I2C0,
//! io.pins.gpio1, //! io.pins.gpio1,
//! io.pins.gpio2, //! io.pins.gpio2,
//! 100u32.kHz(), //! 100.kHz(),
//! &clocks, //! &clocks,
//! ); //! );
//! loop { //! loop {

View File

@ -27,7 +27,7 @@
//! peripherals.I2S0, //! peripherals.I2S0,
//! Standard::Philips, //! Standard::Philips,
//! DataFormat::Data16Channel16, //! DataFormat::Data16Channel16,
//! 44100u32.Hz(), //! 44100.Hz(),
//! dma_channel.configure( //! dma_channel.configure(
//! false, //! false,
//! &mut tx_descriptors, //! &mut tx_descriptors,

View File

@ -26,7 +26,7 @@
//! lcd_cam.lcd, //! lcd_cam.lcd,
//! channel.tx, //! channel.tx,
//! tx_pins, //! tx_pins,
//! 20u32.MHz(), //! 20.MHz(),
//! Config::default(), //! Config::default(),
//! &clocks, //! &clocks,
//! ) //! )

View File

@ -18,7 +18,7 @@
//! .configure(timer::config::Config { //! .configure(timer::config::Config {
//! duty: timer::config::Duty::Duty5Bit, //! duty: timer::config::Duty::Duty5Bit,
//! clock_source: timer::LSClockSource::APBClk, //! clock_source: timer::LSClockSource::APBClk,
//! frequency: 24u32.kHz(), //! frequency: 24.kHz(),
//! }) //! })
//! .unwrap(); //! .unwrap();
//! //!
@ -44,7 +44,7 @@
//! .configure(timer::config::Config { //! .configure(timer::config::Config {
//! duty: timer::config::Duty::Duty5Bit, //! duty: timer::config::Duty::Duty5Bit,
//! clock_source: timer::HSClockSource::APBClk, //! clock_source: timer::HSClockSource::APBClk,
//! frequency: 24u32.kHz(), //! frequency: 24.kHz(),
//! }) //! })
//! .unwrap(); //! .unwrap();
//! //!

View File

@ -32,7 +32,7 @@
//! use mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}; //! use mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM};
//! //!
//! // initialize peripheral //! // initialize peripheral
//! let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap(); //! let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();
//! let mut mcpwm = MCPWM::new(peripherals.PWM0, clock_cfg); //! let mut mcpwm = MCPWM::new(peripherals.PWM0, clock_cfg);
//! //!
//! // connect operator0 to timer0 //! // connect operator0 to timer0
@ -44,7 +44,7 @@
//! //!
//! // start timer with timestamp values in the range of 0..=99 and a frequency of 20 kHz //! // start timer with timestamp values in the range of 0..=99 and a frequency of 20 kHz
//! let timer_clock_cfg = clock_cfg //! let timer_clock_cfg = clock_cfg
//! .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) //! .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20.kHz())
//! .unwrap(); //! .unwrap();
//! mcpwm.timer0.start(timer_clock_cfg); //! mcpwm.timer0.start(timer_clock_cfg);
//! //!

View File

@ -27,7 +27,7 @@
//! &mut rx_descriptors, //! &mut rx_descriptors,
//! DmaPriority::Priority0, //! DmaPriority::Priority0,
//! ), //! ),
//! 1u32.MHz(), //! 1.MHz(),
//! &clocks, //! &clocks,
//! ) //! )
//! .unwrap(); //! .unwrap();
@ -60,7 +60,7 @@
//! &mut rx_descriptors, //! &mut rx_descriptors,
//! DmaPriority::Priority0, //! DmaPriority::Priority0,
//! ), //! ),
//! 1u32.MHz(), //! 1.MHz(),
//! &clocks, //! &clocks,
//! ) //! )
//! .unwrap(); //! .unwrap();

View File

@ -10,12 +10,7 @@ pub use embedded_dma::{
WriteBuffer as _embedded_dma_WriteBuffer, WriteBuffer as _embedded_dma_WriteBuffer,
WriteTarget as _embedded_dma_WriteTarget, WriteTarget as _embedded_dma_WriteTarget,
}; };
pub use fugit::{ pub use fugit::{ExtU64 as _fugit_ExtU64, RateExtU32 as _fugit_RateExtU32};
ExtU32 as _fugit_ExtU32,
ExtU64 as _fugit_ExtU64,
RateExtU32 as _fugit_RateExtU32,
RateExtU64 as _fugit_RateExtU64,
};
pub use nb; pub use nb;
#[cfg(any(dport, pcr, system))] #[cfg(any(dport, pcr, system))]

View File

@ -41,7 +41,7 @@
//! ### Initialization //! ### Initialization
//! //!
//! ```no_run //! ```no_run
//! let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &mut clock_control, &clocks).unwrap(); //! let rmt = Rmt::new(peripherals.RMT, 80.MHz(), &mut clock_control, &clocks).unwrap();
//! let mut channel = rmt //! let mut channel = rmt
//! .channel0 //! .channel0
//! .configure( //! .configure(

View File

@ -296,7 +296,7 @@ impl<'d> Rtc<'d> {
} }
config.apply(); config.apply();
delay.delay_millis(100u32); delay.delay_millis(100);
config.start_sleep(wakeup_triggers); config.start_sleep(wakeup_triggers);
config.finish_sleep(); config.finish_sleep();

View File

@ -79,9 +79,9 @@ impl Efuse {
let has_low_rating = Self::read_field_le::<bool>(CHIP_CPU_FREQ_LOW); let has_low_rating = Self::read_field_le::<bool>(CHIP_CPU_FREQ_LOW);
if has_rating && has_low_rating { if has_rating && has_low_rating {
160u32.MHz() 160.MHz()
} else { } else {
240u32.MHz() 240.MHz()
} }
} }

View File

@ -16,7 +16,7 @@
//! //!
//! let mut spi = hal::spi::Spi::new( //! let mut spi = hal::spi::Spi::new(
//! peripherals.SPI2, //! peripherals.SPI2,
//! 100u32.kHz(), //! 100.kHz(),
//! SpiMode::Mode0, //! SpiMode::Mode0,
//! &mut peripheral_clock_control, //! &mut peripheral_clock_control,
//! &mut clocks, //! &mut clocks,

View File

@ -418,7 +418,7 @@ pub mod etm {
//! ```no_run //! ```no_run
//! let syst = SystemTimer::new(peripherals.SYSTIMER); //! let syst = SystemTimer::new(peripherals.SYSTIMER);
//! let mut alarm0 = syst.alarm0.into_periodic(); //! let mut alarm0 = syst.alarm0.into_periodic();
//! alarm0.set_period(1u32.secs()); //! alarm0.set_period(1.secs());
//! //!
//! let timer_event = SysTimerEtmEvent::new(&mut alarm0); //! let timer_event = SysTimerEtmEvent::new(&mut alarm0);
//! ``` //! ```

View File

@ -27,6 +27,7 @@ esp-backtrace = { version = "0.11.1", features = ["exception-handler", "pa
esp-hal = { version = "0.16.0", path = "../esp-hal", features = ["log"] } esp-hal = { version = "0.16.0", path = "../esp-hal", features = ["log"] }
esp-hal-smartled = { version = "0.9.0", path = "../esp-hal-smartled", optional = true } esp-hal-smartled = { version = "0.9.0", path = "../esp-hal-smartled", optional = true }
esp-println = { version = "0.9.1", features = ["log"] } esp-println = { version = "0.9.1", features = ["log"] }
fugit = "0.3.7"
heapless = "0.8.0" heapless = "0.8.0"
hex-literal = "0.4.1" hex-literal = "0.4.1"
hmac = { version = "0.12.1", default-features = false } hmac = { version = "0.12.1", default-features = false }

View File

@ -49,6 +49,6 @@ fn main() -> ! {
loop { loop {
let pin_value: u16 = nb::block!(adc1.read(&mut adc1_pin)).unwrap(); let pin_value: u16 = nb::block!(adc1.read(&mut adc1_pin)).unwrap();
println!("ADC reading = {}", pin_value); println!("ADC reading = {}", pin_value);
delay.delay_millis(1500u32); delay.delay_millis(1500);
} }
} }

View File

@ -55,6 +55,6 @@ fn main() -> ! {
loop { loop {
let pin_mv = nb::block!(adc1.read(&mut adc1_pin)).unwrap(); let pin_mv = nb::block!(adc1.read(&mut adc1_pin)).unwrap();
println!("PIN2 ADC reading = {pin_mv} mV"); println!("PIN2 ADC reading = {pin_mv} mV");
delay.delay_millis(1500u32); delay.delay_millis(1500);
} }
} }

View File

@ -63,6 +63,6 @@ fn main() -> ! {
Err(err) => println!("Error {:?}", err), Err(err) => println!("Error {:?}", err),
} }
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -30,6 +30,9 @@ fn main() -> ! {
loop { loop {
led.toggle().unwrap(); led.toggle().unwrap();
delay.delay_millis(500u32); delay.delay_millis(500);
led.toggle().unwrap();
// or using `fugit` duration
delay.delay(2.secs());
} }
} }

View File

@ -46,7 +46,7 @@ fn main() -> ! {
loop { loop {
toggle_pins(&mut pins, &button); toggle_pins(&mut pins, &button);
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

@ -31,7 +31,7 @@ fn main() -> ! {
let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(peripherals.LPWR); let mut rtc = Rtc::new(peripherals.LPWR);
rtc.rwdt.start(2000u64.millis()); rtc.rwdt.start(2000.millis());
rtc.rwdt.listen(); rtc.rwdt.listen();
println!( println!(

View File

@ -54,6 +54,6 @@ fn main() -> ! {
voltage_dac2 = voltage_dac2.wrapping_sub(1); voltage_dac2 = voltage_dac2.wrapping_sub(1);
dac2.write(voltage_dac2); dac2.write(voltage_dac2);
delay.delay_millis(50u32); delay.delay_millis(50);
} }
} }

View File

@ -46,7 +46,7 @@ async fn main(_spawner: Spawner) {
peripherals.I2C0, peripherals.I2C0,
io.pins.gpio4, io.pins.gpio4,
io.pins.gpio5, io.pins.gpio5,
400u32.kHz(), 400.kHz(),
&clocks, &clocks,
); );

View File

@ -57,7 +57,7 @@ async fn main(_spawner: Spawner) {
peripherals.I2S0, peripherals.I2S0,
Standard::Philips, Standard::Philips,
DataFormat::Data16Channel16, DataFormat::Data16Channel16,
44100u32.Hz(), 44100.Hz(),
dma_channel.configure( dma_channel.configure(
false, false,
&mut tx_descriptors, &mut tx_descriptors,

View File

@ -80,7 +80,7 @@ async fn main(_spawner: Spawner) {
peripherals.I2S0, peripherals.I2S0,
Standard::Philips, Standard::Philips,
DataFormat::Data16Channel16, DataFormat::Data16Channel16,
44100u32.Hz(), 44100.Hz(),
dma_channel.configure( dma_channel.configure(
false, false,
&mut tx_descriptors, &mut tx_descriptors,

View File

@ -53,7 +53,7 @@ async fn main(_spawner: Spawner) {
&mut rx_descriptors, &mut rx_descriptors,
DmaPriority::Priority0, DmaPriority::Priority0,
), ),
1u32.MHz(), 1.MHz(),
&clocks, &clocks,
) )
.unwrap(); .unwrap();

View File

@ -66,7 +66,7 @@ async fn main(_spawner: Spawner) {
&mut rx_descriptors, &mut rx_descriptors,
DmaPriority::Priority0, DmaPriority::Priority0,
), ),
1u32.MHz(), 1.MHz(),
&clocks, &clocks,
) )
.unwrap(); .unwrap();

View File

@ -52,9 +52,9 @@ async fn main(spawner: Spawner) {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "esp32h2")] { if #[cfg(feature = "esp32h2")] {
let freq = 32u32.MHz(); let freq = 32.MHz();
} else { } else {
let freq = 80u32.MHz(); let freq = 80.MHz();
} }
}; };

View File

@ -37,9 +37,9 @@ async fn main(_spawner: Spawner) {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "esp32h2")] { if #[cfg(feature = "esp32h2")] {
let freq = 32u32.MHz(); let freq = 32.MHz();
} else { } else {
let freq = 80u32.MHz(); let freq = 80.MHz();
} }
}; };

View File

@ -64,7 +64,7 @@ async fn main(_spawner: Spawner) {
let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000);
let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
.with_dma(dma_channel.configure( .with_dma(dma_channel.configure(
false, false,

View File

@ -13,6 +13,7 @@ use esp_hal::{
prelude::*, prelude::*,
systimer::{etm::SysTimerEtmEvent, SystemTimer}, systimer::{etm::SysTimerEtmEvent, SystemTimer},
}; };
use fugit::ExtU32;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {

View File

@ -60,7 +60,7 @@ fn main() -> ! {
loop { loop {
led.toggle().unwrap(); led.toggle().unwrap();
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

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

View File

@ -31,7 +31,7 @@ fn main() -> ! {
peripherals.I2C0, peripherals.I2C0,
io.pins.gpio4, io.pins.gpio4,
io.pins.gpio5, io.pins.gpio5,
100u32.kHz(), 100.kHz(),
&clocks, &clocks,
); );

View File

@ -52,7 +52,7 @@ fn main() -> ! {
peripherals.I2C0, peripherals.I2C0,
io.pins.gpio4, io.pins.gpio4,
io.pins.gpio5, io.pins.gpio5,
100u32.kHz(), 100.kHz(),
&clocks, &clocks,
); );

View File

@ -52,7 +52,7 @@ fn main() -> ! {
peripherals.I2S0, peripherals.I2S0,
Standard::Philips, Standard::Philips,
DataFormat::Data16Channel16, DataFormat::Data16Channel16,
44100u32.Hz(), 44100.Hz(),
dma_channel.configure( dma_channel.configure(
false, false,
&mut tx_descriptors, &mut tx_descriptors,

View File

@ -70,7 +70,7 @@ fn main() -> ! {
peripherals.I2S0, peripherals.I2S0,
Standard::Philips, Standard::Philips,
DataFormat::Data16Channel16, DataFormat::Data16Channel16,
44100u32.Hz(), 44100.Hz(),
dma_channel.configure( dma_channel.configure(
false, false,
&mut tx_descriptors, &mut tx_descriptors,

View File

@ -87,7 +87,7 @@ fn main() -> ! {
lcd_cam.lcd, lcd_cam.lcd,
channel.tx, channel.tx,
tx_pins, tx_pins,
20u32.MHz(), 20.MHz(),
Config::default(), Config::default(),
&clocks, &clocks,
) )
@ -98,9 +98,9 @@ fn main() -> ! {
// https://github.com/lovyan03/LovyanGFX/blob/302169a6f23e9a2a6451f03311c366d182193831/src/lgfx/v1/panel/Panel_ST7796.hpp#L28 // https://github.com/lovyan03/LovyanGFX/blob/302169a6f23e9a2a6451f03311c366d182193831/src/lgfx/v1/panel/Panel_ST7796.hpp#L28
reset.set_low().unwrap(); reset.set_low().unwrap();
delay.delay_micros(8_000u32); delay.delay_micros(8_000);
reset.set_high().unwrap(); reset.set_high().unwrap();
delay.delay_micros(64_000u32); delay.delay_micros(64_000);
// const CMD_FRMCTR1: u8 = 0xB1; // const CMD_FRMCTR1: u8 = 0xB1;
// const CMD_FRMCTR2: u8 = 0xB2; // const CMD_FRMCTR2: u8 = 0xB2;
@ -151,7 +151,7 @@ fn main() -> ! {
i8080.send(CMD_PWCTR3, 0, &[0xA7]).unwrap(); // Power control 3 //Source driving current level=low, Gamma driving current i8080.send(CMD_PWCTR3, 0, &[0xA7]).unwrap(); // Power control 3 //Source driving current level=low, Gamma driving current
// level=High // level=High
i8080.send(CMD_VMCTR, 0, &[0x18]).unwrap(); // VCOM Control //VCOM=0.9 i8080.send(CMD_VMCTR, 0, &[0x18]).unwrap(); // VCOM Control //VCOM=0.9
delay.delay_micros(120_000u32); delay.delay_micros(120_000);
i8080 i8080
.send( .send(
CMD_GMCTRP1, CMD_GMCTRP1,
@ -172,13 +172,13 @@ fn main() -> ! {
], ],
) )
.unwrap(); .unwrap();
delay.delay_micros(120_000u32); delay.delay_micros(120_000);
i8080.send(CMD_CSCON, 0, &[0x3C]).unwrap(); // Command Set control // Disable extension command 2 partI i8080.send(CMD_CSCON, 0, &[0x3C]).unwrap(); // Command Set control // Disable extension command 2 partI
i8080.send(CMD_CSCON, 0, &[0x69]).unwrap(); // Command Set control // Disable i8080.send(CMD_CSCON, 0, &[0x69]).unwrap(); // Command Set control // Disable
// extension command 2 partII // extension command 2 partII
i8080.send(0x11, 0, &[]).unwrap(); // ExitSleepMode i8080.send(0x11, 0, &[]).unwrap(); // ExitSleepMode
delay.delay_micros(130_000u32); delay.delay_micros(130_000);
i8080.send(0x38, 0, &[]).unwrap(); // ExitIdleMode i8080.send(0x38, 0, &[]).unwrap(); // ExitIdleMode
i8080.send(0x29, 0, &[]).unwrap(); // SetDisplayOn i8080.send(0x29, 0, &[]).unwrap(); // SetDisplayOn
@ -241,10 +241,10 @@ fn main() -> ! {
transfer.wait().unwrap(); transfer.wait().unwrap();
} }
delay.delay_millis(1_000u32); delay.delay_millis(1_000);
} }
loop { loop {
delay.delay_millis(1_000u32); delay.delay_millis(1_000);
} }
} }

View File

@ -42,7 +42,7 @@ fn main() -> ! {
.configure(timer::config::Config { .configure(timer::config::Config {
duty: timer::config::Duty::Duty5Bit, duty: timer::config::Duty::Duty5Bit,
clock_source: timer::LSClockSource::APBClk, clock_source: timer::LSClockSource::APBClk,
frequency: 24u32.kHz(), frequency: 24.kHz(),
}) })
.unwrap(); .unwrap();

View File

@ -29,7 +29,7 @@ fn main() -> ! {
let lp_sda = io.pins.gpio6.into_low_power().into_open_drain_output(); let lp_sda = io.pins.gpio6.into_low_power().into_open_drain_output();
let lp_scl = io.pins.gpio7.into_low_power().into_open_drain_output(); let lp_scl = io.pins.gpio7.into_low_power().into_open_drain_output();
let lp_i2c = LpI2c::new(peripherals.LP_I2C0, lp_sda, lp_scl, 100u32.kHz()); let lp_i2c = LpI2c::new(peripherals.LP_I2C0, lp_sda, lp_scl, 100.kHz());
let mut lp_core = LpCore::new(peripherals.LP_CORE); let mut lp_core = LpCore::new(peripherals.LP_CORE);
lp_core.stop(); lp_core.stop();

View File

@ -28,9 +28,9 @@ fn main() -> ! {
// initialize peripheral // initialize peripheral
#[cfg(feature = "esp32h2")] #[cfg(feature = "esp32h2")]
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap(); let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40.MHz()).unwrap();
#[cfg(not(feature = "esp32h2"))] #[cfg(not(feature = "esp32h2"))]
let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32u32.MHz()).unwrap(); let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32.MHz()).unwrap();
let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg); let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg);
@ -44,7 +44,7 @@ fn main() -> ! {
// start timer with timestamp values in the range of 0..=99 and a frequency of // start timer with timestamp values in the range of 0..=99 and a frequency of
// 20 kHz // 20 kHz
let timer_clock_cfg = clock_cfg let timer_clock_cfg = clock_cfg
.timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20.kHz())
.unwrap(); .unwrap();
mcpwm.timer0.start(timer_clock_cfg); mcpwm.timer0.start(timer_clock_cfg);

View File

@ -44,7 +44,7 @@ fn main() -> ! {
&mut rx_descriptors, &mut rx_descriptors,
DmaPriority::Priority0, DmaPriority::Priority0,
), ),
1u32.MHz(), 1.MHz(),
&clocks, &clocks,
) )
.unwrap(); .unwrap();
@ -64,6 +64,6 @@ fn main() -> ! {
transfer.wait().unwrap(); transfer.wait().unwrap();
println!("Received: {:02x?} ...", &buffer[..30]); println!("Received: {:02x?} ...", &buffer[..30]);
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

@ -57,7 +57,7 @@ fn main() -> ! {
&mut rx_descriptors, &mut rx_descriptors,
DmaPriority::Priority0, DmaPriority::Priority0,
), ),
1u32.MHz(), 1.MHz(),
&clocks, &clocks,
) )
.unwrap(); .unwrap();
@ -87,6 +87,6 @@ fn main() -> ! {
transfer.wait().unwrap(); transfer.wait().unwrap();
println!("Transferred {} bytes", buffer.len()); println!("Transferred {} bytes", buffer.len());
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

@ -77,7 +77,7 @@ fn main() -> ! {
let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320);
let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks)
.with_pins( .with_pins(
Some(sclk), Some(sclk),
Some(mosi), Some(mosi),
@ -111,7 +111,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
transfer.wait().unwrap(); transfer.wait().unwrap();
delay.delay_millis(250u32); delay.delay_millis(250);
// erase sector // erase sector
let transfer = spi let transfer = spi
@ -124,7 +124,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
transfer.wait().unwrap(); transfer.wait().unwrap();
delay.delay_millis(250u32); delay.delay_millis(250);
// write enable // write enable
let transfer = spi let transfer = spi
@ -137,7 +137,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
transfer.wait().unwrap(); transfer.wait().unwrap();
delay.delay_millis(250u32); delay.delay_millis(250);
// write data / program page // write data / program page
send.fill(b'!'); send.fill(b'!');
@ -152,7 +152,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
transfer.wait().unwrap(); transfer.wait().unwrap();
delay.delay_millis(250u32); delay.delay_millis(250);
loop { loop {
// quad fast read // quad fast read
@ -181,6 +181,6 @@ fn main() -> ! {
} }
println!(); println!();
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -32,9 +32,9 @@ fn main() -> ! {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "esp32h2")] { if #[cfg(feature = "esp32h2")] {
let freq = 32u32.MHz(); let freq = 32.MHz();
} else { } else {
let freq = 80u32.MHz(); let freq = 80.MHz();
} }
}; };
@ -127,6 +127,6 @@ fn main() -> ! {
} }
} }
delay.delay_millis(1500u32); delay.delay_millis(1500);
} }
} }

View File

@ -27,9 +27,9 @@ fn main() -> ! {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "esp32h2")] { if #[cfg(feature = "esp32h2")] {
let freq = 32u32.MHz(); let freq = 32.MHz();
} else { } else {
let freq = 80u32.MHz(); let freq = 80.MHz();
} }
}; };
@ -62,6 +62,6 @@ fn main() -> ! {
loop { loop {
let transaction = channel.transmit(&data); let transaction = channel.transmit(&data);
channel = transaction.wait().unwrap(); channel = transaction.wait().unwrap();
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

@ -25,6 +25,6 @@ fn main() -> ! {
loop { loop {
esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms());
delay.delay_millis(1000u32); delay.delay_millis(1000);
} }
} }

View File

@ -29,7 +29,7 @@ fn main() -> ! {
let peripherals = Peripherals::take(); let peripherals = Peripherals::take();
let mut rtc = Rtc::new(peripherals.LPWR); let mut rtc = Rtc::new(peripherals.LPWR);
rtc.rwdt.start(2000u64.millis()); rtc.rwdt.start(2000.millis());
rtc.rwdt.listen(); rtc.rwdt.listen();
critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt));
@ -52,7 +52,7 @@ fn interrupt_handler() {
esp_println::println!("Restarting in 5 seconds..."); esp_println::println!("Restarting in 5 seconds...");
rwdt.start(5000u64.millis()); rwdt.start(5000.millis());
rwdt.unlisten(); rwdt.unlisten();
}); });
} }

View File

@ -36,6 +36,6 @@ fn main() -> ! {
let timer = TimerWakeupSource::new(Duration::from_secs(5)); let timer = TimerWakeupSource::new(Duration::from_secs(5));
println!("sleeping!"); println!("sleeping!");
delay.delay_millis(100u32); delay.delay_millis(100);
rtc.sleep_deep(&[&timer], &mut delay); rtc.sleep_deep(&[&timer], &mut delay);
} }

View File

@ -48,6 +48,6 @@ fn main() -> ! {
let timer = TimerWakeupSource::new(Duration::from_secs(30)); let timer = TimerWakeupSource::new(Duration::from_secs(30));
let ext0 = Ext0WakeupSource::new(&mut ext0_pin, WakeupLevel::High); let ext0 = Ext0WakeupSource::new(&mut ext0_pin, WakeupLevel::High);
println!("sleeping!"); println!("sleeping!");
delay.delay_millis(100u32); delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &ext0], &mut delay); rtc.sleep_deep(&[&timer, &ext0], &mut delay);
} }

View File

@ -50,6 +50,6 @@ fn main() -> ! {
let mut wakeup_pins: [&mut dyn RTCPin; 2] = [&mut pin_0, &mut pin_2]; let mut wakeup_pins: [&mut dyn RTCPin; 2] = [&mut pin_0, &mut pin_2];
let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High); let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High);
println!("sleeping!"); println!("sleeping!");
delay.delay_millis(100u32); delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &ext1], &mut delay); rtc.sleep_deep(&[&timer, &ext1], &mut delay);
} }

View File

@ -54,6 +54,6 @@ fn main() -> ! {
let rtcio = Ext1WakeupSource::new(wakeup_pins); let rtcio = Ext1WakeupSource::new(wakeup_pins);
println!("sleeping!"); println!("sleeping!");
delay.delay_millis(100u32); delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &rtcio], &mut delay); rtc.sleep_deep(&[&timer, &rtcio], &mut delay);
} }

View File

@ -58,6 +58,6 @@ fn main() -> ! {
let rtcio = RtcioWakeupSource::new(wakeup_pins); let rtcio = RtcioWakeupSource::new(wakeup_pins);
println!("sleeping!"); println!("sleeping!");
delay.delay_millis(100u32); delay.delay_millis(100);
rtc.sleep_deep(&[&timer, &rtcio], &mut delay); rtc.sleep_deep(&[&timer, &rtcio], &mut delay);
} }

View File

@ -42,7 +42,7 @@ fn main() -> ! {
let mut counter = 0; let mut counter = 0;
loop { loop {
delay.delay_millis(500u32); delay.delay_millis(500);
match counter { match counter {
0 => critical_section::with(|cs| { 0 => critical_section::with(|cs| {
SWINT SWINT

View File

@ -55,7 +55,7 @@ fn main() -> ! {
let miso = io.pins.gpio2; let miso = io.pins.gpio2;
let mosi = io.pins.gpio4; let mosi = io.pins.gpio4;
let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( let spi_bus = Spi::new(peripherals.SPI2, 1000.kHz(), SpiMode::Mode0, &clocks).with_pins(
Some(sclk), Some(sclk),
Some(mosi), Some(mosi),
Some(miso), Some(miso),
@ -93,7 +93,7 @@ fn main() -> ! {
spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); spi_device_2.transfer(&mut read[..], &write[..]).unwrap();
spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); spi_device_3.transfer(&mut read[..], &write[..]).unwrap();
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Asymmetric transfer (Read more than we write) --- // --- Asymmetric transfer (Read more than we write) ---
print!("Starting asymetric transfer (read > write)..."); print!("Starting asymetric transfer (read > write)...");
@ -111,7 +111,7 @@ fn main() -> ! {
.transfer(&mut read[0..2], &write[..]) .transfer(&mut read[0..2], &write[..])
.expect("Asymmetric transfer failed"); .expect("Asymmetric transfer failed");
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Symmetric transfer with huge buffer --- // --- Symmetric transfer with huge buffer ---
// Only your RAM is the limit! // Only your RAM is the limit!
@ -133,7 +133,7 @@ fn main() -> ! {
.transfer(&mut read[..], &write[..]) .transfer(&mut read[..], &write[..])
.expect("Huge transfer failed"); .expect("Huge transfer failed");
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Symmetric transfer with huge buffer in-place (No additional allocation // --- Symmetric transfer with huge buffer in-place (No additional allocation
// needed) --- // needed) ---
@ -156,6 +156,6 @@ fn main() -> ! {
.transfer_in_place(&mut write[..]) .transfer_in_place(&mut write[..])
.expect("Huge transfer failed"); .expect("Huge transfer failed");
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -43,7 +43,7 @@ fn main() -> ! {
let mosi = io.pins.gpio4; let mosi = io.pins.gpio4;
let cs = io.pins.gpio5; let cs = io.pins.gpio5;
let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( let mut spi = Spi::new(peripherals.SPI2, 1000.kHz(), SpiMode::Mode0, &clocks).with_pins(
Some(sclk), Some(sclk),
Some(mosi), Some(mosi),
Some(miso), Some(miso),
@ -62,7 +62,7 @@ fn main() -> ! {
SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed");
assert_eq!(write, read); assert_eq!(write, read);
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Asymmetric transfer (Read more than we write) --- // --- Asymmetric transfer (Read more than we write) ---
print!("Starting asymetric transfer (read > write)..."); print!("Starting asymetric transfer (read > write)...");
@ -73,7 +73,7 @@ fn main() -> ! {
assert_eq!(write[0], read[0]); assert_eq!(write[0], read[0]);
assert_eq!(read[2], 0x00u8); assert_eq!(read[2], 0x00u8);
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Symmetric transfer with huge buffer --- // --- Symmetric transfer with huge buffer ---
// Only your RAM is the limit! // Only your RAM is the limit!
@ -87,7 +87,7 @@ fn main() -> ! {
SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed");
assert_eq!(write, read); assert_eq!(write, read);
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
// --- Symmetric transfer with huge buffer in-place (No additional allocation // --- Symmetric transfer with huge buffer in-place (No additional allocation
// needed) --- // needed) ---
@ -102,6 +102,6 @@ fn main() -> ! {
assert_eq!(write[byte], byte as u8); assert_eq!(write[byte], byte as u8);
} }
println!(" SUCCESS"); println!(" SUCCESS");
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -67,7 +67,7 @@ fn main() -> ! {
} }
} }
let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks)
.with_pins( .with_pins(
Some(sclk), Some(sclk),
Some(mosi), Some(mosi),
@ -91,7 +91,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
println!("Single {:x?}", data); println!("Single {:x?}", data);
delay.delay_millis(250u32); delay.delay_millis(250);
// READ MANUFACTURER ID FROM FLASH CHIP // READ MANUFACTURER ID FROM FLASH CHIP
let mut data = [0u8; 2]; let mut data = [0u8; 2];
@ -104,7 +104,7 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
println!("Dual {:x?}", data); println!("Dual {:x?}", data);
delay.delay_millis(250u32); delay.delay_millis(250);
// READ MANUFACTURER ID FROM FLASH CHIP // READ MANUFACTURER ID FROM FLASH CHIP
let mut data = [0u8; 2]; let mut data = [0u8; 2];
@ -117,6 +117,6 @@ fn main() -> ! {
) )
.unwrap(); .unwrap();
println!("Quad {:x?}", data); println!("Quad {:x?}", data);
delay.delay_millis(1500u32); delay.delay_millis(1500);
} }
} }

View File

@ -43,7 +43,7 @@ fn main() -> ! {
let mosi = io.pins.gpio4; let mosi = io.pins.gpio4;
let cs = io.pins.gpio5; let cs = io.pins.gpio5;
let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks).with_pins(
Some(sclk), Some(sclk),
Some(mosi), Some(mosi),
Some(miso), Some(miso),
@ -57,6 +57,6 @@ fn main() -> ! {
spi.transfer(&mut data).unwrap(); spi.transfer(&mut data).unwrap();
println!("{:x?}", data); println!("{:x?}", data);
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -55,7 +55,7 @@ fn main() -> ! {
let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000);
let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) let mut spi = Spi::new(peripherals.SPI2, 100.kHz(), SpiMode::Mode0, &clocks)
.with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs))
.with_dma(dma_channel.configure( .with_dma(dma_channel.configure(
false, false,
@ -86,7 +86,7 @@ fn main() -> ! {
// Check is_done until the transfer is almost done (32000 bytes at 100kHz is // Check is_done until the transfer is almost done (32000 bytes at 100kHz is
// 2.56 seconds), then move to wait(). // 2.56 seconds), then move to wait().
while !transfer.is_done() && n < 10 { while !transfer.is_done() && n < 10 {
delay.delay_millis(250u32); delay.delay_millis(250);
n += 1; n += 1;
} }
@ -97,6 +97,6 @@ fn main() -> ! {
&receive[receive.len() - 10..] &receive[receive.len() - 10..]
); );
delay.delay_millis(250u32); delay.delay_millis(250);
} }
} }

View File

@ -151,7 +151,7 @@ fn main() -> ! {
&master_receive[master_receive.len() - 10..] &master_receive[master_receive.len() - 10..]
); );
delay.delay_millis(250u32); delay.delay_millis(250);
slave_receive.fill(0xff); slave_receive.fill(0xff);
let transfer = spi.dma_read(&mut slave_receive).unwrap(); let transfer = spi.dma_read(&mut slave_receive).unwrap();
@ -179,7 +179,7 @@ fn main() -> ! {
&slave_receive[slave_receive.len() - 10..], &slave_receive[slave_receive.len() - 10..],
); );
delay.delay_millis(250u32); delay.delay_millis(250);
let transfer = spi.dma_write(&mut slave_send).unwrap(); let transfer = spi.dma_write(&mut slave_send).unwrap();
master_receive.fill(0); master_receive.fill(0);

View File

@ -20,6 +20,7 @@ use esp_hal::{
systimer::{Alarm, Periodic, SystemTimer, Target}, systimer::{Alarm, Periodic, SystemTimer, Target},
}; };
use esp_println::println; use esp_println::println;
use fugit::ExtU32;
static ALARM0: Mutex<RefCell<Option<Alarm<Periodic, 0>>>> = Mutex::new(RefCell::new(None)); static ALARM0: Mutex<RefCell<Option<Alarm<Periodic, 0>>>> = Mutex::new(RefCell::new(None));
static ALARM1: Mutex<RefCell<Option<Alarm<Target, 1>>>> = Mutex::new(RefCell::new(None)); static ALARM1: Mutex<RefCell<Option<Alarm<Target, 1>>>> = Mutex::new(RefCell::new(None));
@ -62,7 +63,7 @@ fn main() -> ! {
let delay = Delay::new(&clocks); let delay = Delay::new(&clocks);
loop { loop {
delay.delay_millis(500u32); delay.delay_millis(500);
} }
} }

View File

@ -35,7 +35,7 @@ fn main() -> ! {
let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut timer0 = timg0.timer0; let mut timer0 = timg0.timer0;
timer0.start(1u64.secs()); timer0.start(1.secs());
let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE);
usb_serial.listen_rx_packet_recv_interrupt(); usb_serial.listen_rx_packet_recv_interrupt();