diff --git a/boards/adafruit-feather-rp2040/CHANGELOG.md b/boards/adafruit-feather-rp2040/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/adafruit-feather-rp2040/CHANGELOG.md +++ b/boards/adafruit-feather-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/adafruit-feather-rp2040/Cargo.toml b/boards/adafruit-feather-rp2040/Cargo.toml index 873b8d1..858d6f5 100644 --- a/boards/adafruit-feather-rp2040/Cargo.toml +++ b/boards/adafruit-feather-rp2040/Cargo.toml @@ -15,11 +15,11 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" [dev-dependencies] panic-halt= "0.2.0" embedded-hal ="0.2.5" +fugit = "0.3.5" nb = "1.0.0" smart-leds = "0.3.0" ws2812-pio = "0.3.0" diff --git a/boards/adafruit-feather-rp2040/examples/adafruit_feather_blinky.rs b/boards/adafruit-feather-rp2040/examples/adafruit_feather_blinky.rs index 71467a0..74eb5b3 100644 --- a/boards/adafruit-feather-rp2040/examples/adafruit_feather_blinky.rs +++ b/boards/adafruit-feather-rp2040/examples/adafruit_feather_blinky.rs @@ -15,7 +15,6 @@ use adafruit_feather_rp2040::{ Pins, XOSC_CRYSTAL_FREQ, }; use embedded_hal::digital::v2::OutputPin; -use embedded_time::rate::*; use panic_halt as _; #[entry] @@ -37,7 +36,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let sio = Sio::new(pac.SIO); let pins = Pins::new( diff --git a/boards/adafruit-feather-rp2040/examples/adafruit_feather_neopixel_rainbow.rs b/boards/adafruit-feather-rp2040/examples/adafruit_feather_neopixel_rainbow.rs index 0bfb918..c552531 100644 --- a/boards/adafruit-feather-rp2040/examples/adafruit_feather_neopixel_rainbow.rs +++ b/boards/adafruit-feather-rp2040/examples/adafruit_feather_neopixel_rainbow.rs @@ -20,7 +20,7 @@ use adafruit_feather_rp2040::{ }; use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; use ws2812_pio::Ws2812; @@ -71,7 +71,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md b/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md +++ b/boards/adafruit-itsy-bitsy-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml index cd25de4..7baf745 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml +++ b/boards/adafruit-itsy-bitsy-rp2040/Cargo.toml @@ -15,7 +15,6 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" [dev-dependencies] panic-halt= "0.2.0" @@ -23,6 +22,7 @@ embedded-hal ="0.2.5" smart-leds = "0.3" nb = "1.0.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" [features] default = ["rt", "boot2"] diff --git a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs index 47c7d97..6acf699 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs +++ b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_blinky.rs @@ -18,7 +18,6 @@ use panic_halt as _; // Some traits we need use embedded_hal::digital::v2::OutputPin; -use embedded_time::fixed_point::FixedPoint; use adafruit_itsy_bitsy_rp2040::{ hal::{ @@ -61,7 +60,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = Sio::new(pac.SIO); diff --git a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_rainbow.rs b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_rainbow.rs index 70d81d5..e5b8ef9 100644 --- a/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_rainbow.rs +++ b/boards/adafruit-itsy-bitsy-rp2040/examples/adafruit_itsy_bitsy_rainbow.rs @@ -6,7 +6,7 @@ use adafruit_itsy_bitsy_rp2040::entry; use core::iter::once; use embedded_hal::digital::v2::OutputPin; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; use ws2812_pio::Ws2812; @@ -72,7 +72,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/adafruit-kb2040/CHANGELOG.md b/boards/adafruit-kb2040/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/adafruit-kb2040/CHANGELOG.md +++ b/boards/adafruit-kb2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/adafruit-kb2040/Cargo.toml b/boards/adafruit-kb2040/Cargo.toml index d85a447..1ec0a1e 100644 --- a/boards/adafruit-kb2040/Cargo.toml +++ b/boards/adafruit-kb2040/Cargo.toml @@ -26,6 +26,6 @@ rt = ["cortex-m-rt","rp2040-hal/rt"] panic-halt = "0.2.0" rp2040-boot2 = "0.2" smart-leds = "0.3.0" -embedded-time = "0.12.0" +fugit = "0.3.5" nb = "1.0.0" ws2812-pio = "0.3.0" diff --git a/boards/adafruit-kb2040/examples/adafruit_kb2040_rainbow.rs b/boards/adafruit-kb2040/examples/adafruit_kb2040_rainbow.rs index 9fa15c0..0770220 100644 --- a/boards/adafruit-kb2040/examples/adafruit_kb2040_rainbow.rs +++ b/boards/adafruit-kb2040/examples/adafruit_kb2040_rainbow.rs @@ -11,7 +11,7 @@ use adafruit_kb2040::entry; use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use adafruit_kb2040::{ @@ -84,7 +84,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/adafruit-macropad/CHANGELOG.md b/boards/adafruit-macropad/CHANGELOG.md index 38e08a8..0bb0865 100644 --- a/boards/adafruit-macropad/CHANGELOG.md +++ b/boards/adafruit-macropad/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/adafruit-macropad/Cargo.toml b/boards/adafruit-macropad/Cargo.toml index c63cfae..1a76d0a 100644 --- a/boards/adafruit-macropad/Cargo.toml +++ b/boards/adafruit-macropad/Cargo.toml @@ -15,8 +15,8 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } + [dev-dependencies] -embedded-time = "0.12.0" panic-halt= "0.2.0" embedded-hal ="0.2.5" diff --git a/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs b/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs index 81ae77c..8ef0267 100644 --- a/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs +++ b/boards/adafruit-macropad/examples/adafruit-macropad_blinky.rs @@ -14,7 +14,6 @@ use adafruit_macropad::{ Pins, XOSC_CRYSTAL_FREQ, }; use embedded_hal::digital::v2::OutputPin; -use embedded_time::rate::*; use panic_halt as _; /// Entry point to our bare-metal application. @@ -40,7 +39,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let sio = Sio::new(pac.SIO); let pins = Pins::new( diff --git a/boards/adafruit-qt-py-rp2040/CHANGELOG.md b/boards/adafruit-qt-py-rp2040/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/adafruit-qt-py-rp2040/CHANGELOG.md +++ b/boards/adafruit-qt-py-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/adafruit-qt-py-rp2040/Cargo.toml b/boards/adafruit-qt-py-rp2040/Cargo.toml index 6f54a25..1fa2e4d 100644 --- a/boards/adafruit-qt-py-rp2040/Cargo.toml +++ b/boards/adafruit-qt-py-rp2040/Cargo.toml @@ -14,7 +14,6 @@ repository = "https://github.com/rp-rs/rp-hal.git" cortex-m = "0.7.2" rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] @@ -23,6 +22,7 @@ embedded-hal ="0.2.5" smart-leds = "0.3" nb = "1.0.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" [features] default = ["boot2", "rt"] diff --git a/boards/adafruit-qt-py-rp2040/examples/adafruit_qt_py_rp2040_rainbow.rs b/boards/adafruit-qt-py-rp2040/examples/adafruit_qt_py_rp2040_rainbow.rs index 2d5b30d..3abf636 100644 --- a/boards/adafruit-qt-py-rp2040/examples/adafruit_qt_py_rp2040_rainbow.rs +++ b/boards/adafruit-qt-py-rp2040/examples/adafruit_qt_py_rp2040_rainbow.rs @@ -6,7 +6,7 @@ use adafruit_qt_py_rp2040::entry; use core::iter::once; use embedded_hal::digital::v2::OutputPin; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; use ws2812_pio::Ws2812; @@ -72,7 +72,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25u32.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/adafruit-trinkey-qt2040/CHANGELOG.md b/boards/adafruit-trinkey-qt2040/CHANGELOG.md new file mode 100644 index 0000000..fec5162 --- /dev/null +++ b/boards/adafruit-trinkey-qt2040/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Changed + +- Migrate from `embedded-time` to `fugit` + diff --git a/boards/adafruit-trinkey-qt2040/Cargo.toml b/boards/adafruit-trinkey-qt2040/Cargo.toml index 4c1c32e..bd8701a 100644 --- a/boards/adafruit-trinkey-qt2040/Cargo.toml +++ b/boards/adafruit-trinkey-qt2040/Cargo.toml @@ -18,10 +18,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] panic-halt= "0.2.0" embedded-hal ="0.2.5" -embedded-time = "0.12.0" smart-leds = "0.3" nb = "1.0.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" [features] default = ["boot2", "rt"] diff --git a/boards/adafruit-trinkey-qt2040/examples/adafruit_trinkey_qt2040_rainbow.rs b/boards/adafruit-trinkey-qt2040/examples/adafruit_trinkey_qt2040_rainbow.rs index 95afc55..24391d4 100644 --- a/boards/adafruit-trinkey-qt2040/examples/adafruit_trinkey_qt2040_rainbow.rs +++ b/boards/adafruit-trinkey-qt2040/examples/adafruit_trinkey_qt2040_rainbow.rs @@ -11,7 +11,7 @@ use adafruit_trinkey_qt2040::entry; use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use adafruit_trinkey_qt2040::{ @@ -84,7 +84,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/arduino_nano_connect/CHANGELOG.md b/boards/arduino_nano_connect/CHANGELOG.md index 2ef2c85..30d1451 100644 --- a/boards/arduino_nano_connect/CHANGELOG.md +++ b/boards/arduino_nano_connect/CHANGELOG.md @@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` diff --git a/boards/arduino_nano_connect/Cargo.toml b/boards/arduino_nano_connect/Cargo.toml index 8ecbbc9..58110ed 100644 --- a/boards/arduino_nano_connect/Cargo.toml +++ b/boards/arduino_nano_connect/Cargo.toml @@ -17,12 +17,12 @@ rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7.0", optional = true } embedded-hal = { version = "0.2.4", features = ["unproven"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] } -embedded-time = "0.12.0" [dev-dependencies] panic-halt= "0.2.0" embedded-hal ="0.2.5" nb = "1.0" +fugit = "0.3.5" [features] default = ["boot2", "rt"] diff --git a/boards/arduino_nano_connect/examples/nano_blinky.rs b/boards/arduino_nano_connect/examples/nano_blinky.rs index 82b24ad..7cdb881 100644 --- a/boards/arduino_nano_connect/examples/nano_blinky.rs +++ b/boards/arduino_nano_connect/examples/nano_blinky.rs @@ -11,8 +11,6 @@ #![no_main] use embedded_hal::digital::v2::OutputPin; -// // Time handling traits -use embedded_time::rate::*; // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) @@ -64,7 +62,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/pimoroni-badger2040/CHANGELOG.md b/boards/pimoroni-badger2040/CHANGELOG.md index 2ef2c85..30d1451 100644 --- a/boards/pimoroni-badger2040/CHANGELOG.md +++ b/boards/pimoroni-badger2040/CHANGELOG.md @@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` diff --git a/boards/pimoroni-badger2040/Cargo.toml b/boards/pimoroni-badger2040/Cargo.toml index 2cba52b..d7dd3b1 100644 --- a/boards/pimoroni-badger2040/Cargo.toml +++ b/boards/pimoroni-badger2040/Cargo.toml @@ -15,7 +15,7 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0"} cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" +fugit = "0.3.5" embedded-hal ="0.2.5" [dev-dependencies] diff --git a/boards/pimoroni-badger2040/examples/badger_blinky.rs b/boards/pimoroni-badger2040/examples/badger_blinky.rs index 85d1dfe..0165e7b 100644 --- a/boards/pimoroni-badger2040/examples/badger_blinky.rs +++ b/boards/pimoroni-badger2040/examples/badger_blinky.rs @@ -28,7 +28,7 @@ use pimoroni_badger2040::hal; // A few traits required for using the CountDown timer use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; #[entry] fn main() -> ! { @@ -75,12 +75,12 @@ fn main() -> ! { loop { // LED on, and wait for 500ms led_pin.set_high().unwrap(); - delay.start(500.milliseconds()); + delay.start(500.millis()); let _ = nb::block!(delay.wait()); // LED off, and wait for 500ms led_pin.set_low().unwrap(); - delay.start(500.milliseconds()); + delay.start(500.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/pimoroni-pico-explorer/CHANGELOG.md b/boards/pimoroni-pico-explorer/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/pimoroni-pico-explorer/CHANGELOG.md +++ b/boards/pimoroni-pico-explorer/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/pimoroni-pico-explorer/Cargo.toml b/boards/pimoroni-pico-explorer/Cargo.toml index 1f4db6d..2b25c84 100644 --- a/boards/pimoroni-pico-explorer/Cargo.toml +++ b/boards/pimoroni-pico-explorer/Cargo.toml @@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true } embedded-hal = { version = "0.2.4", features = ["unproven"] } st7789 = "0.6.1" display-interface-spi = "0.4.1" -embedded-time = "0.12.0" +fugit = "0.3.5" embedded-graphics = "0.7.1" rp2040-boot2 = { version = "0.2.0", optional = true } diff --git a/boards/pimoroni-pico-explorer/examples/pimoroni_pico_explorer_showcase.rs b/boards/pimoroni-pico-explorer/examples/pimoroni_pico_explorer_showcase.rs index b4901e0..1e688e9 100644 --- a/boards/pimoroni-pico-explorer/examples/pimoroni_pico_explorer_showcase.rs +++ b/boards/pimoroni-pico-explorer/examples/pimoroni_pico_explorer_showcase.rs @@ -10,7 +10,6 @@ use embedded_graphics::{ text::{Alignment, Text}, }; use embedded_hal::digital::v2::OutputPin; -use embedded_time::rate::*; use hal::{adc::Adc, clocks::*, watchdog::Watchdog, Sio}; use panic_halt as _; use pimoroni_pico_explorer::entry; @@ -41,7 +40,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(cp.SYST, clocks.system_clock.get_freq().integer()); + let mut delay = cortex_m::delay::Delay::new(cp.SYST, clocks.system_clock.get_freq().to_Hz()); // Enable adc let mut adc = Adc::new(p.ADC, &mut p.RESETS); diff --git a/boards/pimoroni-pico-explorer/src/lib.rs b/boards/pimoroni-pico-explorer/src/lib.rs index eaddc8e..9622848 100644 --- a/boards/pimoroni-pico-explorer/src/lib.rs +++ b/boards/pimoroni-pico-explorer/src/lib.rs @@ -30,7 +30,7 @@ use embedded_hal::{ digital::v2::{InputPin, OutputPin}, spi::MODE_0, }; -use embedded_time::rate::*; +use fugit::RateExtU32; pub use hal::pac; use hal::{ adc::Adc, @@ -211,12 +211,7 @@ impl PicoExplorer { let spi_sclk = internal_pins.spi_sclk.into_mode::(); let spi_mosi = internal_pins.spi_mosi.into_mode::(); - let spi_screen = Spi::<_, _, 8>::new(spi0).init( - resets, - 125_000_000u32.Hz(), - 16_000_000u32.Hz(), - &MODE_0, - ); + let spi_screen = Spi::<_, _, 8>::new(spi0).init(resets, 125u32.MHz(), 16u32.MHz(), &MODE_0); let spii_screen = SPIInterface::new(spi_screen, dc, cs); diff --git a/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md b/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md index 8fcc166..88031b4 100644 --- a/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md +++ b/boards/pimoroni-pico-lipo-16mb/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/pimoroni-pico-lipo-16mb/Cargo.toml b/boards/pimoroni-pico-lipo-16mb/Cargo.toml index 2b3de2d..13dfb1f 100644 --- a/boards/pimoroni-pico-lipo-16mb/Cargo.toml +++ b/boards/pimoroni-pico-lipo-16mb/Cargo.toml @@ -17,7 +17,6 @@ cortex-m-rt = { version = "0.7", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] -embedded-time = "0.12.0" panic-halt= "0.2.0" embedded-hal ="0.2.5" nb = "1.0" diff --git a/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs b/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs index 681e941..6bf9bbc 100644 --- a/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs +++ b/boards/pimoroni-pico-lipo-16mb/examples/pimoroni_pico_lipo_16mb_blinky.rs @@ -16,9 +16,6 @@ use pimoroni_pico_lipo_16mb::entry; // GPIO traits use embedded_hal::digital::v2::OutputPin; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -67,7 +64,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/pimoroni-plasma-2040/CHANGELOG.md b/boards/pimoroni-plasma-2040/CHANGELOG.md index 2ef2c85..30d1451 100644 --- a/boards/pimoroni-plasma-2040/CHANGELOG.md +++ b/boards/pimoroni-plasma-2040/CHANGELOG.md @@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` diff --git a/boards/pimoroni-plasma-2040/Cargo.toml b/boards/pimoroni-plasma-2040/Cargo.toml index 3707816..9b86c86 100644 --- a/boards/pimoroni-plasma-2040/Cargo.toml +++ b/boards/pimoroni-plasma-2040/Cargo.toml @@ -15,7 +15,6 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" [dev-dependencies] rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] } @@ -23,6 +22,7 @@ panic-halt= "0.2.0" embedded-hal ="0.2.5" smart-leds = "0.3.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" defmt = "0.3.0" defmt-rtt = "0.3.0" diff --git a/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_blinky.rs b/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_blinky.rs index 086ff02..2587be4 100644 --- a/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_blinky.rs +++ b/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_blinky.rs @@ -5,7 +5,6 @@ use defmt::*; use defmt_rtt as _; use embedded_hal::digital::v2::OutputPin; -use embedded_time::fixed_point::FixedPoint; use panic_halt as _; use pimoroni_plasma_2040 as bsp; @@ -41,7 +40,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let pins = bsp::Pins::new( pac.IO_BANK0, diff --git a/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_ws2812_led.rs b/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_ws2812_led.rs index 31d8ac9..08266a6 100644 --- a/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_ws2812_led.rs +++ b/boards/pimoroni-plasma-2040/examples/pimoroni_plasma_2040_ws2812_led.rs @@ -13,9 +13,6 @@ use panic_halt as _; // Pull in any important traits use pimoroni_plasma_2040::hal::prelude::*; -// Embed the `Hz` function/trait: -use embedded_time::rate::*; - // A shorter alias for the Peripheral Access Crate, which provides low-level // register access use pimoroni_plasma_2040::hal::pac; @@ -82,7 +79,7 @@ fn main() -> ! { // Setup a delay for the LED blink signals: let mut frame_delay = - cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Import the `sin` function for a smooth hue animation from the // Pico rp2040 ROM: diff --git a/boards/pimoroni-tiny2040/CHANGELOG.md b/boards/pimoroni-tiny2040/CHANGELOG.md new file mode 100644 index 0000000..fec5162 --- /dev/null +++ b/boards/pimoroni-tiny2040/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Changed + +- Migrate from `embedded-time` to `fugit` + diff --git a/boards/pimoroni-tiny2040/Cargo.toml b/boards/pimoroni-tiny2040/Cargo.toml index 5b20f70..cf881be 100644 --- a/boards/pimoroni-tiny2040/Cargo.toml +++ b/boards/pimoroni-tiny2040/Cargo.toml @@ -15,12 +15,12 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" [dev-dependencies] rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] } panic-halt= "0.2.0" embedded-hal ="0.2.5" +fugit = "0.3.5" defmt = "0.3.0" defmt-rtt = "0.3.0" diff --git a/boards/pimoroni-tiny2040/examples/tiny2040_blinky.rs b/boards/pimoroni-tiny2040/examples/tiny2040_blinky.rs index 98093ff..57e3ef1 100644 --- a/boards/pimoroni-tiny2040/examples/tiny2040_blinky.rs +++ b/boards/pimoroni-tiny2040/examples/tiny2040_blinky.rs @@ -6,7 +6,6 @@ use bsp::entry; use defmt::*; use defmt_rtt as _; use embedded_hal::digital::v2::OutputPin; -use embedded_time::fixed_point::FixedPoint; use panic_halt as _; use pimoroni_tiny2040 as bsp; @@ -38,7 +37,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let pins = bsp::Pins::new( pac.IO_BANK0, diff --git a/boards/rp-pico/CHANGELOG.md b/boards/rp-pico/CHANGELOG.md index 3c21e89..0d9d3af 100644 --- a/boards/rp-pico/CHANGELOG.md +++ b/boards/rp-pico/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` ## 0.4.0 - 2022-06-13 diff --git a/boards/rp-pico/Cargo.toml b/boards/rp-pico/Cargo.toml index 782a218..74c5927 100644 --- a/boards/rp-pico/Cargo.toml +++ b/boards/rp-pico/Cargo.toml @@ -15,7 +15,7 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" +fugit = "0.3.5" usb-device= "0.2.9" usbd-serial = "0.1.1" usbd-hid = "0.5.1" diff --git a/boards/rp-pico/examples/pico_blinky.rs b/boards/rp-pico/examples/pico_blinky.rs index 0979c5d..1bb43a4 100644 --- a/boards/rp-pico/examples/pico_blinky.rs +++ b/boards/rp-pico/examples/pico_blinky.rs @@ -16,9 +16,6 @@ use rp_pico::entry; // GPIO traits use embedded_hal::digital::v2::OutputPin; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -67,7 +64,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/rp-pico/examples/pico_countdown_blinky.rs b/boards/rp-pico/examples/pico_countdown_blinky.rs index 6402cb9..8eb0548 100644 --- a/boards/rp-pico/examples/pico_countdown_blinky.rs +++ b/boards/rp-pico/examples/pico_countdown_blinky.rs @@ -19,7 +19,7 @@ use cortex_m::prelude::*; use embedded_hal::digital::v2::OutputPin; // Traits for converting integers to amounts of time -use embedded_time::duration::Extensions; +use fugit::ExtU32; // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) @@ -77,12 +77,12 @@ fn main() -> ! { loop { // LED on, and wait for 500ms led_pin.set_high().unwrap(); - count_down.start(500.milliseconds()); + count_down.start(500.millis()); let _ = nb::block!(count_down.wait()); // LED off, and wait for 500ms led_pin.set_low().unwrap(); - count_down.start(500.milliseconds()); + count_down.start(500.millis()); let _ = nb::block!(count_down.wait()); } } diff --git a/boards/rp-pico/examples/pico_hd44780_display.rs b/boards/rp-pico/examples/pico_hd44780_display.rs index e6a27c5..c7e6715 100644 --- a/boards/rp-pico/examples/pico_hd44780_display.rs +++ b/boards/rp-pico/examples/pico_hd44780_display.rs @@ -48,9 +48,6 @@ use rp_pico::hal::prelude::*; // GPIO traits use embedded_hal::digital::v2::OutputPin; -// Time handling traits -use embedded_time::rate::*; - // For LCD display use hd44780_driver::HD44780; @@ -95,7 +92,7 @@ fn main() -> ! { let mut led_pin = pins.led.into_push_pull_output(); // The delay object lets us wait for specified amounts of time - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Init pins let rs = pins.gpio7.into_push_pull_output(); diff --git a/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs b/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs index dd30795..428f28d 100644 --- a/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs +++ b/boards/rp-pico/examples/pico_i2c_oled_display_ssd1306.rs @@ -48,8 +48,7 @@ use core::fmt::Write; use rp_pico::entry; // Time handling traits: -use embedded_time::duration::*; -use embedded_time::rate::Extensions; +use fugit::{ExtU32, RateExtU32}; // CountDown timer for the counter on the display: use embedded_hal::timer::CountDown; @@ -182,7 +181,7 @@ fn main() -> ! { display.flush().unwrap(); // Wait a bit: - delay.start(500.milliseconds()); + delay.start(500.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/rp-pico/examples/pico_i2c_pio.rs b/boards/rp-pico/examples/pico_i2c_pio.rs index 5bb2f18..dad70a8 100644 --- a/boards/rp-pico/examples/pico_i2c_pio.rs +++ b/boards/rp-pico/examples/pico_i2c_pio.rs @@ -21,7 +21,7 @@ use rp_pico::entry; use embedded_hal::blocking::i2c::{Operation, Read, Transactional, Write}; // Time handling traits -use embedded_time::rate::*; +use fugit::RateExtU32; // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) @@ -109,7 +109,7 @@ fn main() -> ! { pins.gpio20, pins.gpio21, sm0, - 100_000.Hz(), + 100.kHz(), clocks.system_clock.freq(), ); diff --git a/boards/rp-pico/examples/pico_pio_pwm.rs b/boards/rp-pico/examples/pico_pio_pwm.rs index 0e27b9a..daf2d29 100644 --- a/boards/rp-pico/examples/pico_pio_pwm.rs +++ b/boards/rp-pico/examples/pico_pio_pwm.rs @@ -17,9 +17,6 @@ use defmt_rtt as _; // The macro for our start-up function use rp_pico::entry; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -125,7 +122,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let (mut pio0, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS); diff --git a/boards/rp-pico/examples/pico_pwm_blink.rs b/boards/rp-pico/examples/pico_pwm_blink.rs index a2c503e..b6c90fb 100644 --- a/boards/rp-pico/examples/pico_pwm_blink.rs +++ b/boards/rp-pico/examples/pico_pwm_blink.rs @@ -16,9 +16,6 @@ use rp_pico::entry; // GPIO traits use embedded_hal::PwmPin; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -84,7 +81,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Init PWMs let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); diff --git a/boards/rp-pico/examples/pico_pwm_servo.rs b/boards/rp-pico/examples/pico_pwm_servo.rs index 4d89600..8a938b5 100644 --- a/boards/rp-pico/examples/pico_pwm_servo.rs +++ b/boards/rp-pico/examples/pico_pwm_servo.rs @@ -15,7 +15,7 @@ use cortex_m::prelude::*; use embedded_hal::PwmPin; // Traits for converting integers to amounts of time -use embedded_time::duration::Extensions; +use fugit::ExtU32; // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) @@ -93,22 +93,22 @@ fn main() -> ! { loop { // move to 0° channel.set_duty(2500); - count_down.start(400.milliseconds()); + count_down.start(400.millis()); let _ = nb::block!(count_down.wait()); // 0° to 90° channel.set_duty(3930); - count_down.start(400.milliseconds()); + count_down.start(400.millis()); let _ = nb::block!(count_down.wait()); // 90° to 180° channel.set_duty(7860); - count_down.start(400.milliseconds()); + count_down.start(400.millis()); let _ = nb::block!(count_down.wait()); // 180° to 90° channel.set_duty(3930); - count_down.start(400.milliseconds()); + count_down.start(400.millis()); let _ = nb::block!(count_down.wait()); } } diff --git a/boards/rp-pico/examples/pico_rtic.rs b/boards/rp-pico/examples/pico_rtic.rs index 05f29ed..1218f47 100644 --- a/boards/rp-pico/examples/pico_rtic.rs +++ b/boards/rp-pico/examples/pico_rtic.rs @@ -7,13 +7,13 @@ use panic_halt as _; mod app { use embedded_hal::digital::v2::OutputPin; - use embedded_time::duration::Extensions; + use fugit::SecsDurationU32; use rp_pico::{ hal::{self, clocks::init_clocks_and_plls, timer::Alarm, watchdog::Watchdog, Sio}, XOSC_CRYSTAL_FREQ, }; - const SCAN_TIME_US: u32 = 1000000; + const SCAN_TIME_US: SecsDurationU32 = SecsDurationU32::secs(1); #[shared] struct Shared { @@ -58,7 +58,7 @@ mod app { let mut timer = hal::Timer::new(c.device.TIMER, &mut resets); let mut alarm = timer.alarm_0().unwrap(); - let _ = alarm.schedule(SCAN_TIME_US.microseconds()); + let _ = alarm.schedule(SCAN_TIME_US); alarm.enable_interrupt(); (Shared { timer, alarm, led }, Local {}, init::Monotonics()) @@ -81,7 +81,7 @@ mod app { let mut alarm = c.shared.alarm; (alarm).lock(|a| { a.clear_interrupt(); - let _ = a.schedule(SCAN_TIME_US.microseconds()); + let _ = a.schedule(SCAN_TIME_US); }); } } diff --git a/boards/rp-pico/examples/pico_spi_sd_card.rs b/boards/rp-pico/examples/pico_spi_sd_card.rs index 5877031..c8e5ae3 100644 --- a/boards/rp-pico/examples/pico_spi_sd_card.rs +++ b/boards/rp-pico/examples/pico_spi_sd_card.rs @@ -107,7 +107,7 @@ use panic_halt as _; use rp_pico::hal::prelude::*; // Embed the `Hz` function/trait: -use embedded_time::rate::*; +use fugit::RateExtU32; // A shorter alias for the Peripheral Access Crate, which provides low-level // register access @@ -236,7 +236,7 @@ fn main() -> ! { let mut led_pin = pins.led.into_push_pull_output(); // Setup a delay for the LED blink signals: - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // These are implicitly used by the spi driver if they are in the correct mode let _spi_sclk = pins.gpio2.into_mode::(); diff --git a/boards/rp-pico/examples/pico_uart_irq_buffer.rs b/boards/rp-pico/examples/pico_uart_irq_buffer.rs index 6e78846..f8114c9 100644 --- a/boards/rp-pico/examples/pico_uart_irq_buffer.rs +++ b/boards/rp-pico/examples/pico_uart_irq_buffer.rs @@ -21,9 +21,6 @@ // objects as generic embedded devices. use embedded_hal::{digital::v2::OutputPin, serial::Write as UartWrite}; -// We need this for the 'Delay' object to work. -use embedded_time::fixed_point::FixedPoint; - // The writeln! trait. use core::fmt::Write; @@ -114,7 +111,7 @@ fn main() -> ! { .unwrap(); // Lets us wait for fixed periods of time - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/rp-pico/examples/pico_uart_irq_echo.rs b/boards/rp-pico/examples/pico_uart_irq_echo.rs index e1ee12b..8de2206 100644 --- a/boards/rp-pico/examples/pico_uart_irq_echo.rs +++ b/boards/rp-pico/examples/pico_uart_irq_echo.rs @@ -22,9 +22,6 @@ use embedded_hal::{ serial::{Read, Write}, }; -// We need this for the 'Delay' object to work. -use embedded_time::fixed_point::FixedPoint; - // We also need this for the 'Delay' object to work. use rp2040_hal::Clock; @@ -98,7 +95,7 @@ fn main() -> ! { .unwrap(); // Lets us wait for fixed periods of time - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/rp-pico/examples/pico_usb_serial_interrupt.rs b/boards/rp-pico/examples/pico_usb_serial_interrupt.rs index 015386b..676d576 100644 --- a/boards/rp-pico/examples/pico_usb_serial_interrupt.rs +++ b/boards/rp-pico/examples/pico_usb_serial_interrupt.rs @@ -21,9 +21,6 @@ use rp_pico::hal::pac::interrupt; // GPIO traits use embedded_hal::digital::v2::OutputPin; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -131,7 +128,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs b/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs index f139d3b..5779b09 100644 --- a/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs +++ b/boards/rp-pico/examples/pico_usb_twitchy_mouse.rs @@ -25,7 +25,6 @@ use rp_pico::hal::pac::interrupt; use panic_halt as _; // Pull in any important traits -use embedded_time::fixed_point::FixedPoint; use rp_pico::hal::prelude::*; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -136,7 +135,7 @@ fn main() -> ! { pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ); }; let core = pac::CorePeripherals::take().unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Move the cursor up and down every 200ms loop { diff --git a/boards/rp-pico/examples/pico_ws2812_led.rs b/boards/rp-pico/examples/pico_ws2812_led.rs index d4ff6fb..6ae2565 100644 --- a/boards/rp-pico/examples/pico_ws2812_led.rs +++ b/boards/rp-pico/examples/pico_ws2812_led.rs @@ -50,9 +50,6 @@ use panic_halt as _; // Pull in any important traits use rp_pico::hal::prelude::*; -// Embed the `Hz` function/trait: -use embedded_time::rate::*; - // A shorter alias for the Peripheral Access Crate, which provides low-level // register access use rp_pico::hal::pac; @@ -115,7 +112,7 @@ fn main() -> ! { // Setup a delay for the LED blink signals: let mut frame_delay = - cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Import the `sin` function for a smooth hue animation from the // Pico rp2040 ROM: diff --git a/boards/seeeduino-xiao-rp2040/CHANGELOG.md b/boards/seeeduino-xiao-rp2040/CHANGELOG.md index 3fc329e..889dc1e 100644 --- a/boards/seeeduino-xiao-rp2040/CHANGELOG.md +++ b/boards/seeeduino-xiao-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.1.0 - 2022-06-26 diff --git a/boards/seeeduino-xiao-rp2040/Cargo.toml b/boards/seeeduino-xiao-rp2040/Cargo.toml index 256778a..c07d509 100644 --- a/boards/seeeduino-xiao-rp2040/Cargo.toml +++ b/boards/seeeduino-xiao-rp2040/Cargo.toml @@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] -embedded-time = "0.12.0" +fugit = "0.3.5" panic-halt= "0.2.0" embedded-hal ="0.2.5" nb = "1.0" diff --git a/boards/seeeduino-xiao-rp2040/examples/seeeduino_xiao_rp2040_blinky.rs b/boards/seeeduino-xiao-rp2040/examples/seeeduino_xiao_rp2040_blinky.rs index 92b5006..5f88bc4 100644 --- a/boards/seeeduino-xiao-rp2040/examples/seeeduino_xiao_rp2040_blinky.rs +++ b/boards/seeeduino-xiao-rp2040/examples/seeeduino_xiao_rp2040_blinky.rs @@ -17,9 +17,6 @@ use seeeduino_xiao_rp2040::entry; use embedded_hal::digital::v2::OutputPin; use embedded_hal::PwmPin; -// Time handling traits -use embedded_time::rate::*; - // Ensure we halt the program on panic (if we don't mention this crate it won't // be linked) use panic_halt as _; @@ -85,7 +82,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Init PWMs let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); diff --git a/boards/solderparty-rp2040-stamp/CHANGELOG.md b/boards/solderparty-rp2040-stamp/CHANGELOG.md new file mode 100644 index 0000000..fec5162 --- /dev/null +++ b/boards/solderparty-rp2040-stamp/CHANGELOG.md @@ -0,0 +1,13 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## Unreleased + +### Changed + +- Migrate from `embedded-time` to `fugit` + diff --git a/boards/solderparty-rp2040-stamp/Cargo.toml b/boards/solderparty-rp2040-stamp/Cargo.toml index f9c44f8..bc6c60d 100644 --- a/boards/solderparty-rp2040-stamp/Cargo.toml +++ b/boards/solderparty-rp2040-stamp/Cargo.toml @@ -28,4 +28,4 @@ nb = "1.0.0" smart-leds = "0.3.0" pio = "0.1.0" ws2812-pio = "0.3.0" -embedded-time = "0.12.0" +fugit = "0.3.5" diff --git a/boards/solderparty-rp2040-stamp/examples/solderparty_stamp_neopixel_rainbow.rs b/boards/solderparty-rp2040-stamp/examples/solderparty_stamp_neopixel_rainbow.rs index 70db5da..21aa0f5 100644 --- a/boards/solderparty-rp2040-stamp/examples/solderparty_stamp_neopixel_rainbow.rs +++ b/boards/solderparty-rp2040-stamp/examples/solderparty_stamp_neopixel_rainbow.rs @@ -8,7 +8,7 @@ use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; use solderparty_rp2040_stamp::entry; @@ -71,7 +71,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25u32.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md b/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md index 3be3b76..1366090 100644 --- a/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md +++ b/boards/sparkfun-pro-micro-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.3.0 - 2022-06-13 diff --git a/boards/sparkfun-pro-micro-rp2040/Cargo.toml b/boards/sparkfun-pro-micro-rp2040/Cargo.toml index 4451199..52910e4 100644 --- a/boards/sparkfun-pro-micro-rp2040/Cargo.toml +++ b/boards/sparkfun-pro-micro-rp2040/Cargo.toml @@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] panic-halt = "0.2.0" smart-leds = "0.3.0" -embedded-time = "0.12.0" nb = "1.0.0" pio = "0.1.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" [features] default = ["boot2", "rt"] diff --git a/boards/sparkfun-pro-micro-rp2040/examples/sparkfun_pro_micro_rainbow.rs b/boards/sparkfun-pro-micro-rp2040/examples/sparkfun_pro_micro_rainbow.rs index db73e64..7fc8b3b 100644 --- a/boards/sparkfun-pro-micro-rp2040/examples/sparkfun_pro_micro_rainbow.rs +++ b/boards/sparkfun-pro-micro-rp2040/examples/sparkfun_pro_micro_rainbow.rs @@ -10,7 +10,7 @@ use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use sparkfun_pro_micro_rp2040::entry; @@ -83,7 +83,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/sparkfun-thing-plus-rp2040/CHANGELOG.md b/boards/sparkfun-thing-plus-rp2040/CHANGELOG.md index 4e9282e..0b12a8b 100644 --- a/boards/sparkfun-thing-plus-rp2040/CHANGELOG.md +++ b/boards/sparkfun-thing-plus-rp2040/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` ## 0.2.0 - 2022-06-13 diff --git a/boards/sparkfun-thing-plus-rp2040/Cargo.toml b/boards/sparkfun-thing-plus-rp2040/Cargo.toml index 08022cd..f458ad1 100644 --- a/boards/sparkfun-thing-plus-rp2040/Cargo.toml +++ b/boards/sparkfun-thing-plus-rp2040/Cargo.toml @@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true } [dev-dependencies] panic-halt = "0.2.0" smart-leds = "0.3.0" -embedded-time = "0.12.0" nb = "1.0.0" pio = "0.1.0" ws2812-pio = "0.3.0" +fugit = "0.3.5" [features] default = ["boot2", "rt"] diff --git a/boards/sparkfun-thing-plus-rp2040/examples/sparkfun_thing_plus_rainbow.rs b/boards/sparkfun-thing-plus-rp2040/examples/sparkfun_thing_plus_rainbow.rs index eb8ef20..26b397e 100644 --- a/boards/sparkfun-thing-plus-rp2040/examples/sparkfun_thing_plus_rainbow.rs +++ b/boards/sparkfun-thing-plus-rp2040/examples/sparkfun_thing_plus_rainbow.rs @@ -10,7 +10,7 @@ use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; @@ -82,7 +82,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/boards/vcc-gnd-yd-rp2040/CHANGELOG.md b/boards/vcc-gnd-yd-rp2040/CHANGELOG.md index 7530e5f..d0b1c60 100644 --- a/boards/vcc-gnd-yd-rp2040/CHANGELOG.md +++ b/boards/vcc-gnd-yd-rp2040/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- None +- Migrate from `embedded-time` to `fugit` ## 0.1.0 - 2022-07-17 diff --git a/boards/vcc-gnd-yd-rp2040/Cargo.toml b/boards/vcc-gnd-yd-rp2040/Cargo.toml index adb91f9..2278192 100644 --- a/boards/vcc-gnd-yd-rp2040/Cargo.toml +++ b/boards/vcc-gnd-yd-rp2040/Cargo.toml @@ -15,7 +15,7 @@ cortex-m = "0.7.2" rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } cortex-m-rt = { version = "0.7", optional = true } -embedded-time = "0.12.0" +fugit = "0.3.5" usb-device= "0.2.9" usbd-serial = "0.1.1" usbd-hid = "0.5.1" diff --git a/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_blinky.rs b/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_blinky.rs index a6f0889..e658832 100644 --- a/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_blinky.rs +++ b/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_blinky.rs @@ -5,7 +5,6 @@ #![no_main] use embedded_hal::digital::v2::OutputPin; -use embedded_time::rate::*; use panic_halt as _; use vcc_gnd_yd_rp2040::entry; use vcc_gnd_yd_rp2040::{ @@ -37,7 +36,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); let sio = Sio::new(pac.SIO); let pins = Pins::new( diff --git a/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_neopixel_rainbow.rs b/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_neopixel_rainbow.rs index e47b1c6..e2af412 100644 --- a/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_neopixel_rainbow.rs +++ b/boards/vcc-gnd-yd-rp2040/examples/yd_rp2040_neopixel_rainbow.rs @@ -8,7 +8,7 @@ use core::iter::once; use embedded_hal::timer::CountDown; -use embedded_time::duration::Extensions; +use fugit::ExtU32; use panic_halt as _; use smart_leds::{brightness, SmartLedsWrite, RGB8}; use vcc_gnd_yd_rp2040::entry; @@ -71,7 +71,7 @@ fn main() -> ! { ws.write(brightness(once(wheel(n)), 32)).unwrap(); n = n.wrapping_add(1); - delay.start(25.milliseconds()); + delay.start(25.millis()); let _ = nb::block!(delay.wait()); } } diff --git a/rp2040-hal/CHANGELOG.md b/rp2040-hal/CHANGELOG.md index 5035eeb..e46adf3 100644 --- a/rp2040-hal/CHANGELOG.md +++ b/rp2040-hal/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Implement `From<&SomeClock> for Hertz` instead of `From for Hertz` for the clocks in `rp2040_hal::clocks`. - Use `rp2040-hal`'s entry function. +- Migrate from `embedded-time` to `fugit` ## [0.5.0] - 2022-06-13 diff --git a/rp2040-hal/Cargo.toml b/rp2040-hal/Cargo.toml index a5ed3e2..60dc621 100644 --- a/rp2040-hal/Cargo.toml +++ b/rp2040-hal/Cargo.toml @@ -14,7 +14,7 @@ cortex-m = "0.7.2" cortex-m-rt = ">=0.6.15,<0.8" embedded-hal = { version = "0.2.5", features = ["unproven"] } eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-alpha.8", optional = true } -embedded-time = "0.12.0" +fugit = "0.3.6" itertools = { version = "0.10.1", default-features = false } nb = "1.0" rp2040-pac = "0.3.0" diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index 6440282..7de3fc7 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -20,7 +20,6 @@ use rp2040_hal as hal; // Some traits we need use core::fmt::Write; use embedded_hal::adc::OneShot; -use embedded_time::fixed_point::FixedPoint; use rp2040_hal::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -68,7 +67,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/rp2040-hal/examples/blinky.rs b/rp2040-hal/examples/blinky.rs index 517ca91..00e911d 100644 --- a/rp2040-hal/examples/blinky.rs +++ b/rp2040-hal/examples/blinky.rs @@ -22,7 +22,6 @@ use hal::pac; // Some traits we need use embedded_hal::digital::v2::OutputPin; -use embedded_time::fixed_point::FixedPoint; use rp2040_hal::clocks::Clock; /// The linker will place this boot block at the start of our program image. We @@ -64,7 +63,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/rp2040-hal/examples/dht11.rs b/rp2040-hal/examples/dht11.rs index 3d49602..13680ee 100644 --- a/rp2040-hal/examples/dht11.rs +++ b/rp2040-hal/examples/dht11.rs @@ -26,7 +26,6 @@ use hal::pac; // Some traits we need use embedded_hal::digital::v2::InputPin; use embedded_hal::digital::v2::OutputPin; -use embedded_time::fixed_point::FixedPoint; use hal::gpio::dynpin::DynPin; use hal::Clock; @@ -124,7 +123,7 @@ fn main() -> ! { &mut pac.RESETS, ); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Use GPIO 28 as an InOutPin let mut pin = InOutPin::new(pins.gpio28.into()); diff --git a/rp2040-hal/examples/i2c.rs b/rp2040-hal/examples/i2c.rs index e0f65cf..ef2f8e9 100644 --- a/rp2040-hal/examples/i2c.rs +++ b/rp2040-hal/examples/i2c.rs @@ -15,7 +15,7 @@ use panic_halt as _; // Some traits we need use embedded_hal::blocking::i2c::Write; -use embedded_time::rate::Extensions; +use fugit::RateExtU32; // Alias for our HAL crate use rp2040_hal as hal; diff --git a/rp2040-hal/examples/lcd_display.rs b/rp2040-hal/examples/lcd_display.rs index 9624875..bf0d151 100644 --- a/rp2040-hal/examples/lcd_display.rs +++ b/rp2040-hal/examples/lcd_display.rs @@ -23,7 +23,6 @@ use rp2040_hal as hal; use hd44780_driver as hd44780; // Some traits we need -use embedded_time::fixed_point::FixedPoint; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -71,7 +70,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/rp2040-hal/examples/multicore_fifo_blink.rs b/rp2040-hal/examples/multicore_fifo_blink.rs index 5a6c408..e117c87 100644 --- a/rp2040-hal/examples/multicore_fifo_blink.rs +++ b/rp2040-hal/examples/multicore_fifo_blink.rs @@ -12,7 +12,6 @@ #![no_std] #![no_main] -use embedded_time::fixed_point::FixedPoint; use hal::clocks::Clock; use hal::multicore::{Multicore, Stack}; use hal::sio::Sio; @@ -107,7 +106,7 @@ fn main() -> ! { .ok() .unwrap(); - let sys_freq = clocks.system_clock.freq().integer(); + let sys_freq = clocks.system_clock.freq().to_Hz(); // The single-cycle I/O block controls our GPIO pins let mut sio = hal::sio::Sio::new(pac.SIO); diff --git a/rp2040-hal/examples/multicore_polyblink.rs b/rp2040-hal/examples/multicore_polyblink.rs index 5459ee5..e4d4a67 100644 --- a/rp2040-hal/examples/multicore_polyblink.rs +++ b/rp2040-hal/examples/multicore_polyblink.rs @@ -10,7 +10,6 @@ use cortex_m::delay::Delay; -use embedded_time::fixed_point::FixedPoint; use hal::clocks::Clock; use hal::gpio::Pins; use hal::multicore::{Multicore, Stack}; @@ -98,7 +97,7 @@ fn main() -> ! { let mut led2 = pins.gpio3.into_push_pull_output(); // Set up the delay for the first core. - let sys_freq = clocks.system_clock.freq().integer(); + let sys_freq = clocks.system_clock.freq().to_Hz(); let mut delay = Delay::new(core.SYST, sys_freq); // Start up the second core to blink the second LED diff --git a/rp2040-hal/examples/pwm_blink.rs b/rp2040-hal/examples/pwm_blink.rs index a1d28b0..e548db1 100644 --- a/rp2040-hal/examples/pwm_blink.rs +++ b/rp2040-hal/examples/pwm_blink.rs @@ -19,7 +19,6 @@ use rp2040_hal as hal; // Some traits we need use embedded_hal::PwmPin; -use embedded_time::rate::*; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -86,7 +85,7 @@ fn main() -> ! { // The delay object lets us wait for specified amounts of time (in // milliseconds) - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Init PWMs let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); diff --git a/rp2040-hal/examples/spi.rs b/rp2040-hal/examples/spi.rs index 4232e39..2d246a9 100644 --- a/rp2040-hal/examples/spi.rs +++ b/rp2040-hal/examples/spi.rs @@ -21,7 +21,7 @@ use rp2040_hal as hal; // Some traits we need use cortex_m::prelude::*; -use embedded_time::rate::Extensions; +use fugit::RateExtU32; use rp2040_hal::clocks::Clock; // A shorter alias for the Peripheral Access Crate, which provides low-level @@ -87,7 +87,7 @@ fn main() -> ! { let mut spi = spi.init( &mut pac.RESETS, clocks.peripheral_clock.freq(), - 16_000_000u32.Hz(), + 16.MHz(), &embedded_hal::spi::MODE_0, ); diff --git a/rp2040-hal/examples/uart.rs b/rp2040-hal/examples/uart.rs index d229756..3f3d289 100644 --- a/rp2040-hal/examples/uart.rs +++ b/rp2040-hal/examples/uart.rs @@ -24,7 +24,6 @@ use hal::pac; // Some traits we need use core::fmt::Write; -use embedded_time::fixed_point::FixedPoint; use rp2040_hal::clocks::Clock; /// The linker will place this boot block at the start of our program image. We @@ -66,7 +65,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); diff --git a/rp2040-hal/examples/vector_table.rs b/rp2040-hal/examples/vector_table.rs index 5e14d3a..facf42c 100644 --- a/rp2040-hal/examples/vector_table.rs +++ b/rp2040-hal/examples/vector_table.rs @@ -22,8 +22,7 @@ use hal::pac; use core::cell::RefCell; use critical_section::Mutex; use embedded_hal::digital::v2::ToggleableOutputPin; -use embedded_time::duration::Microseconds; -use embedded_time::fixed_point::FixedPoint; +use fugit::MicrosDurationU32; use pac::interrupt; use rp2040_hal::clocks::Clock; use rp2040_hal::timer::Alarm; @@ -42,8 +41,8 @@ type LedAndAlarm = ( static mut LED_AND_ALARM: Mutex>> = Mutex::new(RefCell::new(None)); // Period that each of the alarms will be set for - 1 second and 300ms respectively -const SLOW_BLINK_INTERVAL_US: u32 = 1_000_000; -const FAST_BLINK_INTERVAL_US: u32 = 300_000; +const SLOW_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::secs(1); +const FAST_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::millis(300); /// The linker will place this boot block at the start of our program image. We /// need this to help the ROM bootloader get our code up and running. @@ -96,7 +95,7 @@ fn main() -> ! { .unwrap(); // Create simple delay - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // Set the pins to their default state let pins = hal::gpio::Pins::new( @@ -113,7 +112,7 @@ fn main() -> ! { critical_section::with(|cs| { let mut alarm = timer.alarm_0().unwrap(); // Schedule an alarm in 1 second - let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US)); + let _ = alarm.schedule(SLOW_BLINK_INTERVAL_US); // Enable generating an interrupt on alarm alarm.enable_interrupt(); // Move alarm into ALARM, so that it can be accessed from interrupts @@ -151,7 +150,7 @@ fn TIMER_IRQ_0() { // Clear the alarm interrupt or this interrupt service routine will keep firing alarm.clear_interrupt(); // Schedule a new alarm after SLOW_BLINK_INTERVAL_US have passed (1 second) - let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US)); + let _ = alarm.schedule(SLOW_BLINK_INTERVAL_US); // Blink the LED so we know we hit this interrupt led.toggle().unwrap(); // Return LED_AND_ALARM into our static variable @@ -172,7 +171,7 @@ extern "C" fn timer_irq0_replacement() { // Clear the alarm interrupt or this interrupt service routine will keep firing alarm.clear_interrupt(); // Schedule a new alarm after FAST_BLINK_INTERVAL_US have passed (300 milliseconds) - let _ = alarm.schedule(Microseconds(FAST_BLINK_INTERVAL_US)); + let _ = alarm.schedule(FAST_BLINK_INTERVAL_US); led.toggle().unwrap(); // Return LED_AND_ALARM into our static variable unsafe { diff --git a/rp2040-hal/examples/watchdog.rs b/rp2040-hal/examples/watchdog.rs index 69bed46..e9e2a6a 100644 --- a/rp2040-hal/examples/watchdog.rs +++ b/rp2040-hal/examples/watchdog.rs @@ -23,8 +23,7 @@ use hal::pac; // Some traits we need use embedded_hal::digital::v2::OutputPin; use embedded_hal::watchdog::{Watchdog, WatchdogEnable}; -use embedded_time::duration::Extensions; -use embedded_time::fixed_point::FixedPoint; +use fugit::ExtU32; use rp2040_hal::clocks::Clock; /// The linker will place this boot block at the start of our program image. We @@ -67,7 +66,7 @@ fn main() -> ! { .ok() .unwrap(); - let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer()); + let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); // The single-cycle I/O block controls our GPIO pins let sio = hal::Sio::new(pac.SIO); @@ -88,7 +87,7 @@ fn main() -> ! { delay.delay_ms(2000); // Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it - watchdog.start(1_050_000u32.microseconds()); + watchdog.start(1_050.millis()); // Blink once a second for 5 seconds, refreshing the watchdog timer once a second to avoid a reset for _ in 1..=5 { diff --git a/rp2040-hal/src/clocks/clock_sources.rs b/rp2040-hal/src/clocks/clock_sources.rs index 34048de..d466131 100644 --- a/rp2040-hal/src/clocks/clock_sources.rs +++ b/rp2040-hal/src/clocks/clock_sources.rs @@ -16,7 +16,7 @@ use pac::{PLL_SYS, PLL_USB}; pub(crate) type PllSys = PhaseLockedLoop; impl Sealed for PllSys {} impl ClockSource for PllSys { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.operating_frequency() } } @@ -24,37 +24,37 @@ impl ClockSource for PllSys { pub(crate) type PllUsb = PhaseLockedLoop; impl Sealed for PllUsb {} impl ClockSource for PllUsb { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.operating_frequency() } } impl ClockSource for UsbClock { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.frequency } } impl ClockSource for AdcClock { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.frequency } } impl ClockSource for RtcClock { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.frequency } } impl ClockSource for SystemClock { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.frequency } } impl ClockSource for ReferenceClock { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.frequency } } @@ -62,7 +62,7 @@ impl ClockSource for ReferenceClock { pub(crate) type Xosc = CrystalOscillator; impl Sealed for Xosc {} impl ClockSource for Xosc { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.operating_frequency() } } @@ -71,7 +71,7 @@ pub(crate) type Rosc = RingOscillator; impl Sealed for Rosc {} // We are assuming the second output is never phase shifted (see 2.17.4) impl ClockSource for RingOscillator { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { self.operating_frequency() } } @@ -79,7 +79,7 @@ impl ClockSource for RingOscillator { // GPIN0 pub(crate) type GPin0 = Pin; impl ClockSource for GPin0 { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { todo!() } } @@ -87,7 +87,7 @@ impl ClockSource for GPin0 { // GPIN1 pub(crate) type GPin1 = Pin; impl ClockSource for Pin { - fn get_freq(&self) -> Hertz { + fn get_freq(&self) -> HertzU32 { todo!() } } diff --git a/rp2040-hal/src/clocks/macros.rs b/rp2040-hal/src/clocks/macros.rs index ddbd9dc..8cf6b40 100644 --- a/rp2040-hal/src/clocks/macros.rs +++ b/rp2040-hal/src/clocks/macros.rs @@ -140,7 +140,8 @@ macro_rules! clock { w.src().variant(self.get_default_clock_source()) }); - self.frequency = 12_000_000.Hz(); //TODO Get actual clock source.. Most likely 12 MHz though + use fugit::RateExtU32; + self.frequency = 12.MHz(); //TODO Get actual clock source.. Most likely 12 MHz though self.await_select(&ChangingClockToken{clock_nr:0, clock: PhantomData::}) } @@ -174,19 +175,19 @@ macro_rules! clock { type Variant = [<$reg:camel SrcType>]; #[doc = "Get operating frequency for `"$name"`"] - fn freq(&self) -> Hertz { + fn freq(&self) -> HertzU32 { self.frequency } #[doc = "Configure `"$name"`"] - fn configure_clock>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{ - let src_freq: Hertz = src.get_freq().into(); + fn configure_clock>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{ + let src_freq: HertzU32 = src.get_freq().into(); if freq.gt(&src_freq){ return Err(ClockError::CantIncreaseFreq); } - let div = fractional_div(src_freq.integer(), freq.integer()).ok_or(ClockError::FrequencyTooLow)?; + let div = fractional_div(src_freq.to_Hz(), freq.to_Hz()).ok_or(ClockError::FrequencyTooLow)?; // If increasing divisor, set divisor before source. Otherwise set source // before divisor. This avoids a momentary overspeed when e.g. switching @@ -217,7 +218,8 @@ macro_rules! clock { self.set_div(div); // Store the configured frequency - self.frequency = fractional_div(src_freq.integer(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz(); + use fugit::RateExtU32; + self.frequency = fractional_div(src_freq.to_Hz(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz(); Ok(()) } @@ -324,19 +326,19 @@ macro_rules! stoppable_clock { type Variant = [<$reg:camel SrcType>]; #[doc = "Get operating frequency for `"$name"`"] - fn freq(&self) -> Hertz { + fn freq(&self) -> HertzU32 { self.frequency } #[doc = "Configure `"$name"`"] - fn configure_clock>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{ - let src_freq: Hertz = src.get_freq().into(); + fn configure_clock>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{ + let src_freq: HertzU32 = src.get_freq().into(); if freq.gt(&src_freq){ return Err(ClockError::CantIncreaseFreq); } - let div = fractional_div(src_freq.integer(), freq.integer()).ok_or(ClockError::FrequencyTooLow)?; + let div = fractional_div(src_freq.to_Hz(), freq.to_Hz()).ok_or(ClockError::FrequencyTooLow)?; // If increasing divisor, set divisor before source. Otherwise set source // before divisor. This avoids a momentary overspeed when e.g. switching @@ -352,12 +354,12 @@ macro_rules! stoppable_clock { // Disable clock. On clk_ref and clk_sys this does nothing, // all other clocks have the ENABLE bit in the same position. self.disable(); - if (self.frequency > 0u32.Hz()) { + if self.frequency > HertzU32::Hz(0) { // Delay for 3 cycles of the target clock, for ENABLE propagation. // Note XOSC_COUNT is not helpful here because XOSC is not // necessarily running, nor is timer... so, 3 cycles per loop: let sys_freq = 125_000_000; // TODO get actual sys_clk frequency - let delay_cyc = sys_freq / self.frequency.integer() + 1u32; + let delay_cyc = sys_freq / self.frequency.to_Hz() + 1u32; cortex_m::asm::delay(delay_cyc); } @@ -373,7 +375,8 @@ macro_rules! stoppable_clock { self.set_div(div); // Store the configured frequency - self.frequency = fractional_div(src_freq.integer(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz(); + use fugit::RateExtU32; + self.frequency = fractional_div(src_freq.to_Hz(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz(); Ok(()) } @@ -402,7 +405,7 @@ macro_rules! base_clock { $(#[$attr])* pub struct $name { shared_dev: ShareableClocks, - frequency: Hertz, + frequency: HertzU32, } impl $name { @@ -417,9 +420,9 @@ macro_rules! base_clock { impl Sealed for $name {} - impl From<&$name> for Hertz + impl From<&$name> for HertzU32 { - fn from(value: &$name) -> Hertz { + fn from(value: &$name) -> HertzU32 { value.frequency } } diff --git a/rp2040-hal/src/clocks/mod.rs b/rp2040-hal/src/clocks/mod.rs index 5465647..bb6ef65 100644 --- a/rp2040-hal/src/clocks/mod.rs +++ b/rp2040-hal/src/clocks/mod.rs @@ -14,7 +14,7 @@ //! //! ## Usage extended //! ```no_run -//! use embedded_time::rate::*; +//! use fugit::RateExtU32; //! use rp2040_hal::{clocks::{Clock, ClocksManager, ClockSource, InitError}, gpio::Pins, pac, pll::{common_configs::{PLL_SYS_125MHZ, PLL_USB_48MHZ}, setup_pll_blocking}, Sio, watchdog::Watchdog, xosc::setup_xosc_blocking}; //! //! # fn func() -> Result<(), InitError> { @@ -72,7 +72,8 @@ use crate::{ xosc::{setup_xosc_blocking, CrystalOscillator, Error as XoscError, Stable}, }; use core::{convert::Infallible, marker::PhantomData}; -use embedded_time::rate::*; +use fugit::HertzU32; +use fugit::RateExtU32; use pac::{CLOCKS, PLL_SYS, PLL_USB, RESETS, XOSC}; #[macro_use] @@ -117,13 +118,13 @@ pub trait Clock: Sealed + Sized { type Variant; /// Get operating frequency - fn freq(&self) -> Hertz; + fn freq(&self) -> HertzU32; /// Configure this clock based on a clock source and desired frequency fn configure_clock>( &mut self, src: &S, - freq: Hertz, + freq: HertzU32, ) -> Result<(), ClockError>; } @@ -170,7 +171,7 @@ pub trait ClockSource: Sealed { /// Get the operating frequency for this source /// /// Used to determine the divisor - fn get_freq(&self) -> Hertz; + fn get_freq(&self) -> HertzU32; } /// Trait to contrain which ClockSource is valid for which Clock @@ -336,7 +337,7 @@ pub fn init_clocks_and_plls( let pll_sys = setup_pll_blocking( pll_sys_dev, - xosc.operating_frequency().into(), + xosc.operating_frequency(), PLL_SYS_125MHZ, &mut clocks, resets, @@ -344,7 +345,7 @@ pub fn init_clocks_and_plls( .map_err(InitError::PllError)?; let pll_usb = setup_pll_blocking( pll_usb_dev, - xosc.operating_frequency().into(), + xosc.operating_frequency(), PLL_USB_48MHZ, &mut clocks, resets, diff --git a/rp2040-hal/src/i2c.rs b/rp2040-hal/src/i2c.rs index 0391a05..54ce887 100644 --- a/rp2040-hal/src/i2c.rs +++ b/rp2040-hal/src/i2c.rs @@ -4,7 +4,7 @@ //! //! ## Usage //! ```no_run -//! use embedded_time::rate::Extensions; +//! use fugit::RateExtU32; //! use rp2040_hal::{i2c::I2C, gpio::Pins, pac, Sio}; //! let mut peripherals = pac::Peripherals::take().unwrap(); //! let sio = Sio::new(peripherals.SIO); @@ -55,7 +55,7 @@ use crate::{ resets::SubsystemReset, typelevel::Sealed, }; -use embedded_time::rate::Hertz; +use fugit::HertzU32; use pac::{i2c0::RegisterBlock as I2CBlock, I2C0, I2C1, RESETS}; /// Controller implementaion @@ -294,12 +294,12 @@ macro_rules! hal { resets: &mut RESETS, system_clock: SystemF) -> Self where - F: Into>, + F: Into, Sda: SdaPin<$I2CX>, Scl: SclPin<$I2CX>, - SystemF: Into>, + SystemF: Into, { - Self::new_controller(i2c, sda_pin, scl_pin, freq, resets, system_clock) + Self::new_controller(i2c, sda_pin, scl_pin, freq.into(), resets, system_clock.into()) } } )+ diff --git a/rp2040-hal/src/i2c/controller.rs b/rp2040-hal/src/i2c/controller.rs index 0098c9b..862f9f2 100644 --- a/rp2040-hal/src/i2c/controller.rs +++ b/rp2040-hal/src/i2c/controller.rs @@ -5,7 +5,7 @@ use crate::{ gpio::pin::{FunctionI2C, Pin, PinId}, resets::SubsystemReset, }; -use embedded_time::rate::Hertz; +use fugit::HertzU32; use hal::blocking::i2c::{Read, Write, WriteRead}; use pac::{i2c0::RegisterBlock as Block, RESETS}; @@ -18,24 +18,21 @@ impl, Sda: PinId + BankPinId, Scl: Pin I2C, Pin), Controller> { /// Configures the I2C peripheral to work in controller mode - pub fn new_controller( + pub fn new_controller( i2c: T, sda_pin: Pin, scl_pin: Pin, - freq: F, + freq: HertzU32, resets: &mut RESETS, - system_clock: SystemF, + system_clock: HertzU32, ) -> Self where - F: Into>, Sda: SdaPin, Scl: SclPin, - SystemF: Into>, { - let freq = freq.into().0; + let freq = freq.to_Hz(); assert!(freq <= 1_000_000); assert!(freq > 0); - let freq = freq as u32; i2c.reset_bring_down(resets); i2c.reset_bring_up(resets); @@ -55,7 +52,7 @@ impl, Sda: PinId + BankPinId, Scl: Pin i2c.ic_tx_tl.write(|w| unsafe { w.tx_tl().bits(0) }); i2c.ic_rx_tl.write(|w| unsafe { w.rx_tl().bits(0) }); - let freq_in = system_clock.into().0; + let freq_in = system_clock.to_Hz(); // There are some subtleties to I2C timing which we are completely ignoring here // See: https://github.com/raspberrypi/pico-sdk/blob/bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7/src/rp2_common/hardware_i2c/i2c.c#L69 diff --git a/rp2040-hal/src/pll.rs b/rp2040-hal/src/pll.rs index ae579d1..7d5956d 100644 --- a/rp2040-hal/src/pll.rs +++ b/rp2040-hal/src/pll.rs @@ -2,15 +2,12 @@ // See [Chapter 2 Section 18](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details use core::{ - convert::{Infallible, TryFrom, TryInto}, + convert::{Infallible, TryInto}, marker::PhantomData, ops::{Deref, Range, RangeInclusive}, }; -use embedded_time::{ - fixed_point::FixedPoint, - rate::{Generic, Hertz, Rate}, -}; +use fugit::{HertzU32, RateExtU32}; use nb::Error::WouldBlock; use pac::RESETS; @@ -26,19 +23,19 @@ pub struct Disabled { fbdiv: u16, post_div1: u8, post_div2: u8, - frequency: Hertz, + frequency: HertzU32, } /// PLL is configured, started and locking into its designated frequency. pub struct Locking { post_div1: u8, post_div2: u8, - frequency: Hertz, + frequency: HertzU32, } /// PLL is locked : it delivers a steady frequency. pub struct Locked { - frequency: Hertz, + frequency: HertzU32, } impl State for Disabled {} @@ -94,9 +91,9 @@ pub enum Error { } /// Parameters for a PLL. -pub struct PLLConfig { +pub struct PLLConfig { /// Voltage Controlled Oscillator frequency. - pub vco_freq: R, + pub vco_freq: HertzU32, /// Reference divider pub refdiv: u8, @@ -112,19 +109,19 @@ pub struct PLLConfig { /// See Chapter 2, Section 18, §2 pub mod common_configs { use super::PLLConfig; - use embedded_time::rate::Megahertz; + use fugit::HertzU32; /// Default, nominal configuration for PLL_SYS - pub const PLL_SYS_125MHZ: PLLConfig = PLLConfig { - vco_freq: Megahertz(1500), + pub const PLL_SYS_125MHZ: PLLConfig = PLLConfig { + vco_freq: HertzU32::MHz(1500), refdiv: 1, post_div1: 6, post_div2: 2, }; /// Default, nominal configuration for PLL_USB. - pub const PLL_USB_48MHZ: PLLConfig = PLLConfig { - vco_freq: Megahertz(480), + pub const PLL_USB_48MHZ: PLLConfig = PLLConfig { + vco_freq: HertzU32::MHz(480), refdiv: 1, post_div1: 5, post_div2: 2, @@ -133,24 +130,16 @@ pub mod common_configs { impl PhaseLockedLoop { /// Instantiates a new Phase-Locked-Loop device. - pub fn new( + pub fn new( dev: D, - xosc_frequency: Generic, - config: PLLConfig, - ) -> Result, Error> - where - R: Into>, - { - const VCO_FREQ_RANGE: RangeInclusive> = - Hertz(400_000_000)..=Hertz(1_600_000_000); + xosc_frequency: HertzU32, + config: PLLConfig, + ) -> Result, Error> { + const VCO_FREQ_RANGE: RangeInclusive = HertzU32::MHz(400)..=HertzU32::MHz(1_600); const POSTDIV_RANGE: Range = 1..7; const FBDIV_RANGE: Range = 16..320; - //First we convert our rate to Hertz as all other rates can be converted to that. - let vco_freq: Hertz = config.vco_freq.into(); - - //Then we try to downscale to u32. - let vco_freq: Hertz = vco_freq.try_into().map_err(|_| Error::BadArgument)?; + let vco_freq = config.vco_freq; if !VCO_FREQ_RANGE.contains(&vco_freq) { return Err(Error::VcoFreqOutOfRange); @@ -161,24 +150,25 @@ impl PhaseLockedLoop { return Err(Error::PostDivOutOfRage); } - let ref_freq_range: Range> = Hertz(5_000_000)..vco_freq.div(16); + let ref_freq_max_vco = (vco_freq.to_Hz() / 16).Hz(); + let ref_freq_range: Range = HertzU32::MHz(5)..ref_freq_max_vco; - let ref_freq_hz = Hertz::::try_from(xosc_frequency) - .map_err(|_| Error::BadArgument)? - .checked_div(&(config.refdiv as u32)) - .ok_or(Error::BadArgument)?; + let ref_freq_hz: HertzU32 = xosc_frequency + .to_Hz() + .checked_div(u32::from(config.refdiv)) + .ok_or(Error::BadArgument)? + .Hz(); if !ref_freq_range.contains(&ref_freq_hz) { return Err(Error::RefFreqOutOfRange); } let fbdiv = vco_freq - .checked_div(&ref_freq_hz.integer()) + .to_Hz() + .checked_div(ref_freq_hz.to_Hz()) .ok_or(Error::BadArgument)?; - let fbdiv: u16 = (fbdiv.integer()) - .try_into() - .map_err(|_| Error::BadArgument)?; + let fbdiv: u16 = fbdiv.try_into().map_err(|_| Error::BadArgument)?; if !FBDIV_RANGE.contains(&fbdiv) { return Err(Error::FeedbackDivOutOfRange); @@ -187,8 +177,8 @@ impl PhaseLockedLoop { let refdiv = config.refdiv; let post_div1 = config.post_div1; let post_div2 = config.post_div2; - let frequency: Hertz = - (ref_freq_hz / refdiv as u32) * fbdiv as u32 / (post_div1 as u32 * post_div2 as u32); + let frequency: HertzU32 = ((ref_freq_hz / u32::from(refdiv)) * u32::from(fbdiv)) + / (u32::from(post_div1) * u32::from(post_div2)); Ok(PhaseLockedLoop { state: Disabled { @@ -279,28 +269,26 @@ impl PhaseLockedLoop { impl PhaseLockedLoop { /// Get the operating frequency for the PLL - pub fn operating_frequency(&self) -> Hertz { + pub fn operating_frequency(&self) -> HertzU32 { self.state.frequency } } /// Blocking helper method to setup the PLL without going through all the steps. -pub fn setup_pll_blocking( +pub fn setup_pll_blocking( dev: D, - xosc_frequency: Generic, - config: PLLConfig, + xosc_frequency: HertzU32, + config: PLLConfig, clocks: &mut ClocksManager, resets: &mut RESETS, -) -> Result, Error> -where - R: Into>, -{ +) -> Result, Error> { // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. nb::block!(clocks.system_clock.reset_source_await()).unwrap(); nb::block!(clocks.reference_clock.reset_source_await()).unwrap(); - let initialized_pll = PhaseLockedLoop::new(dev, xosc_frequency, config)?.initialize(resets); + let initialized_pll = + PhaseLockedLoop::new(dev, xosc_frequency.convert(), config)?.initialize(resets); let locked_pll_token = nb::block!(initialized_pll.await_lock()).unwrap(); diff --git a/rp2040-hal/src/rosc.rs b/rp2040-hal/src/rosc.rs index e392056..58bcb1b 100644 --- a/rp2040-hal/src/rosc.rs +++ b/rp2040-hal/src/rosc.rs @@ -1,8 +1,7 @@ //! Ring Oscillator (ROSC) // See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details -use embedded_time::rate::Extensions; -use embedded_time::rate::Hertz; +use fugit::HertzU32; /// State of the Ring Oscillator (typestate trait) pub trait State {} @@ -12,7 +11,7 @@ pub struct Disabled; /// ROSC is initialized, ie we've given parameters (typestate) pub struct Enabled { - freq_hz: Hertz, + freq_hz: HertzU32, } /// ROSC is in dormant mode (see Chapter 2, Section 17, §7) @@ -56,6 +55,7 @@ impl RingOscillator { pub fn initialize(self) -> RingOscillator { self.device.ctrl.write(|w| w.enable().enable()); + use fugit::RateExtU32; self.transition(Enabled { freq_hz: 6_500_000u32.Hz(), }) @@ -64,7 +64,7 @@ impl RingOscillator { impl RingOscillator { /// Approx operating frequency of the ROSC in hertz - pub fn operating_frequency(&self) -> Hertz { + pub fn operating_frequency(&self) -> HertzU32 { self.state.freq_hz } diff --git a/rp2040-hal/src/rtc/mod.rs b/rp2040-hal/src/rtc/mod.rs index c28964e..ec21202 100644 --- a/rp2040-hal/src/rtc/mod.rs +++ b/rp2040-hal/src/rtc/mod.rs @@ -23,7 +23,6 @@ use crate::clocks::Clock; use crate::clocks::RtcClock; -use embedded_time::fixed_point::FixedPoint; use rp2040_pac::{RESETS, RTC}; mod filter; @@ -66,7 +65,7 @@ impl RealTimeClock { } // Set the RTC divider - let freq = clock.freq().integer() - 1; + let freq = clock.freq().to_Hz() - 1; rtc.clkdiv_m1.write(|w| unsafe { w.bits(freq) }); let mut result = Self { rtc }; diff --git a/rp2040-hal/src/spi.rs b/rp2040-hal/src/spi.rs index 9dd54b1..3e018b4 100644 --- a/rp2040-hal/src/spi.rs +++ b/rp2040-hal/src/spi.rs @@ -6,7 +6,7 @@ //! //! ```no_run //! use embedded_hal::spi::MODE_0; -//! use embedded_time::rate::*; +//! use fugit::RateExtU32; //! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio}; //! //! let mut peripherals = pac::Peripherals::take().unwrap(); @@ -25,7 +25,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref}; use eh1_0_alpha::spi as eh1; use embedded_hal::blocking::spi; use embedded_hal::spi::{FullDuplex, Mode, Phase, Polarity}; -use embedded_time::rate::*; +use fugit::HertzU32; use pac::RESETS; /// State of the SPI @@ -78,13 +78,13 @@ impl Spi { /// Set baudrate based on peripheral clock /// /// Typically the peripheral clock is set to 125_000_000 - pub fn set_baudrate>, B: Into>>( + pub fn set_baudrate, B: Into>( &mut self, peri_frequency: F, baudrate: B, - ) -> Hertz { - let freq_in = peri_frequency.into().integer(); - let baudrate = baudrate.into().integer(); + ) -> HertzU32 { + let freq_in = peri_frequency.into().to_Hz(); + let baudrate = baudrate.into().to_Hz(); let mut prescale: u8 = u8::MAX; let mut postdiv: u8 = 0; @@ -120,6 +120,7 @@ impl Spi { .modify(|_, w| unsafe { w.scr().bits(postdiv) }); // Return the frequency we were able to achieve + use fugit::RateExtU32; (freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz() } } @@ -146,7 +147,7 @@ impl Spi { } /// Initialize the SPI - pub fn init>, B: Into>>( + pub fn init, B: Into>( mut self, resets: &mut RESETS, peri_frequency: F, diff --git a/rp2040-hal/src/timer.rs b/rp2040-hal/src/timer.rs index 5011cbd..acea851 100644 --- a/rp2040-hal/src/timer.rs +++ b/rp2040-hal/src/timer.rs @@ -8,7 +8,7 @@ //! //! See [Chapter 4 Section 6](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) of the datasheet for more details. -use embedded_time::duration::Microseconds; +use fugit::{Duration, MicrosDurationU64}; use crate::atomic_register_access::{write_bitmask_clear, write_bitmask_set}; use crate::pac::{RESETS, TIMER}; @@ -53,7 +53,7 @@ impl Timer { pub fn count_down(&self) -> CountDown<'_> { CountDown { timer: self, - period: Microseconds::new(0), + period: MicrosDurationU64::nanos(0), next_end: None, } } @@ -104,43 +104,47 @@ impl Timer { /// ## Usage /// ```no_run /// use embedded_hal::timer::{CountDown, Cancel}; -/// use embedded_time::duration::Extensions; +/// use fugit::ExtU32; /// use rp2040_hal; /// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap(); /// // Configure the Timer peripheral in count-down mode /// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS); /// let mut count_down = timer.count_down(); /// // Create a count_down timer for 500 milliseconds -/// count_down.start(500.milliseconds()); +/// count_down.start(500.millis()); /// // Block until timer has elapsed /// let _ = nb::block!(count_down.wait()); /// // Restart the count_down timer with a period of 100 milliseconds -/// count_down.start(100.milliseconds()); +/// count_down.start(100.millis()); /// // Cancel it immediately /// count_down.cancel(); /// ``` pub struct CountDown<'timer> { timer: &'timer Timer, - period: embedded_time::duration::Microseconds, + period: MicrosDurationU64, next_end: Option, } impl embedded_hal::timer::CountDown for CountDown<'_> { - type Time = embedded_time::duration::Microseconds; + type Time = MicrosDurationU64; fn start(&mut self, count: T) where T: Into, { self.period = count.into(); - self.next_end = Some(self.timer.get_counter().wrapping_add(self.period.0)); + self.next_end = Some( + self.timer + .get_counter() + .wrapping_add(self.period.to_micros()), + ); } fn wait(&mut self) -> nb::Result<(), void::Void> { if let Some(end) = self.next_end { let ts = self.timer.get_counter(); if ts >= end { - self.next_end = Some(end.wrapping_add(self.period.0)); + self.next_end = Some(end.wrapping_add(self.period.to_micros())); Ok(()) } else { Err(nb::Error::WouldBlock) @@ -187,12 +191,12 @@ pub trait Alarm { /// this will trigger interrupt whenever this time elapses. /// /// The RP2040 has been observed to take a little while to schedule an alarm. For this - /// reason, the minimum time that this function accepts is `10.microseconds()` + /// reason, the minimum time that this function accepts is `10.micros()` /// /// [enable_interrupt]: #method.enable_interrupt - fn schedule>( + fn schedule( &mut self, - countdown: TIME, + countdown: Duration, ) -> Result<(), ScheduleAlarmError>; /// Return true if this alarm is finished. @@ -255,14 +259,14 @@ macro_rules! impl_alarm { #[doc = $int_name] /// ` whenever this time elapses. /// - /// The RP2040 has been observed to take a little while to schedule an alarm. For this reason, the minimum time that this function accepts is `10.microseconds()` + /// The RP2040 has been observed to take a little while to schedule an alarm. For this reason, the minimum time that this function accepts is `10.micros()` /// /// [enable_interrupt]: #method.enable_interrupt - fn schedule>( + fn schedule( &mut self, - countdown: TIME, + countdown: Duration, ) -> Result<(), ScheduleAlarmError> { - let duration = countdown.into().0; + let duration = countdown.to_micros(); const MIN_MICROSECONDS: u32 = 10; if duration < MIN_MICROSECONDS { diff --git a/rp2040-hal/src/uart/common_configs.rs b/rp2040-hal/src/uart/common_configs.rs index d23869f..3515e72 100644 --- a/rp2040-hal/src/uart/common_configs.rs +++ b/rp2040-hal/src/uart/common_configs.rs @@ -1,9 +1,10 @@ +use fugit::HertzU32; + use super::{DataBits, StopBits, UartConfig}; -use embedded_time::rate::Baud; /// 9600 baud, 8 data bits, no parity, 1 stop bit pub const _9600_8_N_1: UartConfig = UartConfig { - baudrate: Baud(9600), + baudrate: HertzU32::from_raw(9600), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, @@ -11,7 +12,7 @@ pub const _9600_8_N_1: UartConfig = UartConfig { /// 19200 baud, 8 data bits, no parity, 1 stop bit pub const _19200_8_N_1: UartConfig = UartConfig { - baudrate: Baud(19200), + baudrate: HertzU32::from_raw(19200), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, @@ -19,7 +20,7 @@ pub const _19200_8_N_1: UartConfig = UartConfig { /// 38400 baud, 8 data bits, no parity, 1 stop bit pub const _38400_8_N_1: UartConfig = UartConfig { - baudrate: Baud(38400), + baudrate: HertzU32::from_raw(38400), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, @@ -27,7 +28,7 @@ pub const _38400_8_N_1: UartConfig = UartConfig { /// 57600 baud, 8 data bits, no parity, 1 stop bit pub const _57600_8_N_1: UartConfig = UartConfig { - baudrate: Baud(57600), + baudrate: HertzU32::from_raw(57600), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, @@ -35,7 +36,7 @@ pub const _57600_8_N_1: UartConfig = UartConfig { /// 115200 baud, 8 data bits, no parity, 1 stop bit pub const _115200_8_N_1: UartConfig = UartConfig { - baudrate: Baud(115200), + baudrate: HertzU32::from_raw(115200), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index 878fb0c..4a41768 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -8,9 +8,7 @@ use crate::pac::uart0::uartlcr_h::W as UART_LCR_H_Writer; use core::convert::Infallible; use core::fmt; use embedded_hal::serial::{Read, Write}; -use embedded_time::fixed_point::FixedPoint; -use embedded_time::rate::Baud; -use embedded_time::rate::Hertz; +use fugit::HertzU32; use nb::Error::{Other, WouldBlock}; use rp2040_pac::{UART0, UART1}; @@ -57,10 +55,10 @@ impl> UartPeripheral { pub fn enable( self, config: UartConfig, - frequency: Hertz, + frequency: HertzU32, ) -> Result, Error> { let (mut device, pins) = self.free(); - configure_baudrate(&mut device, &config.baudrate, &frequency)?; + configure_baudrate(&mut device, config.baudrate, frequency)?; device.uartlcr_h.write(|w| { // FIFOs are enabled @@ -229,15 +227,15 @@ impl> UartPeripheral { /// From the wanted baudrate, we calculate the divider's two parts: integer and fractional parts. /// Code inspired from the C SDK. fn calculate_baudrate_dividers( - wanted_baudrate: &Baud, - frequency: &Hertz, + wanted_baudrate: HertzU32, + frequency: HertzU32, ) -> Result<(u16, u16), Error> { // See Chapter 4, Section 2 §7.1 from the datasheet for an explanation of how baudrate is // calculated let baudrate_div = frequency - .integer() + .to_Hz() .checked_mul(8) - .and_then(|r| r.checked_div(wanted_baudrate.integer())) + .and_then(|r| r.checked_div(wanted_baudrate.to_Hz())) .ok_or(Error::BadArgument)?; Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) { @@ -252,9 +250,9 @@ fn calculate_baudrate_dividers( /// Baudrate configuration. Code loosely inspired from the C SDK. fn configure_baudrate( device: &mut dyn UartDevice, - wanted_baudrate: &Baud, - frequency: &Hertz, -) -> Result { + wanted_baudrate: HertzU32, + frequency: HertzU32, +) -> Result { let (baud_div_int, baud_div_frac) = calculate_baudrate_dividers(wanted_baudrate, frequency)?; // First we load the integer part of the divider. @@ -273,8 +271,8 @@ fn configure_baudrate( // divisors. We don't want to actually change LCR contents here. device.uartlcr_h.modify(|_, w| w); - Ok(Baud( - (4 * frequency.integer()) / (64 * baud_div_int + baud_div_frac) as u32, + Ok(HertzU32::from_raw( + (4 * frequency.to_Hz()) / (64 * baud_div_int + baud_div_frac) as u32, )) } diff --git a/rp2040-hal/src/uart/utils.rs b/rp2040-hal/src/uart/utils.rs index f96a2cb..367683c 100644 --- a/rp2040-hal/src/uart/utils.rs +++ b/rp2040-hal/src/uart/utils.rs @@ -1,7 +1,8 @@ +use fugit::HertzU32; + use crate::pac::{uart0::RegisterBlock, UART0, UART1}; use crate::resets::SubsystemReset; use core::ops::Deref; -use embedded_time::rate::Baud; /// Error type for UART operations. #[derive(Debug)] @@ -73,7 +74,7 @@ pub enum Parity { #[non_exhaustive] pub struct UartConfig { /// The baudrate the uart will run at. - pub baudrate: Baud, + pub baudrate: HertzU32, /// The amount of data bits the uart should be configured to. pub data_bits: DataBits, @@ -88,7 +89,7 @@ pub struct UartConfig { impl Default for UartConfig { fn default() -> Self { Self { - baudrate: Baud(115_200), + baudrate: HertzU32::from_raw(115_200), data_bits: DataBits::Eight, stop_bits: StopBits::One, parity: None, diff --git a/rp2040-hal/src/watchdog.rs b/rp2040-hal/src/watchdog.rs index 286275d..533d863 100644 --- a/rp2040-hal/src/watchdog.rs +++ b/rp2040-hal/src/watchdog.rs @@ -9,7 +9,7 @@ //! ## Usage //! ```no_run //! use cortex_m::prelude::{_embedded_hal_watchdog_Watchdog, _embedded_hal_watchdog_WatchdogEnable}; -//! use embedded_time::duration::units::*; +//! use fugit::ExtU32; //! use rp2040_hal::{clocks::init_clocks_and_plls, pac, watchdog::Watchdog}; //! let mut pac = pac::Peripherals::take().unwrap(); //! let mut watchdog = Watchdog::new(pac.WATCHDOG); @@ -23,7 +23,7 @@ //! &mut watchdog, //! ).ok().unwrap(); //! // Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it -//! watchdog.start(1_050_000.microseconds()); +//! watchdog.start(1_050_000.micros()); //! // Feed the watchdog once per cycle to avoid reset //! for _ in 1..=10000 { //! cortex_m::asm::delay(100_000); @@ -36,7 +36,7 @@ use crate::pac::WATCHDOG; use embedded_hal::watchdog; -use embedded_time::{duration, fixed_point::FixedPoint}; +use fugit::MicrosDurationU32; /// Watchdog peripheral pub struct Watchdog { @@ -114,14 +114,14 @@ impl watchdog::Watchdog for Watchdog { } impl watchdog::WatchdogEnable for Watchdog { - type Time = duration::Microseconds; + type Time = MicrosDurationU32; fn start>(&mut self, period: T) { const MAX_PERIOD: u32 = 0xFFFFFF; // Due to a logic error, the watchdog decrements by 2 and // the load value must be compensated; see RP2040-E1 - self.delay_ms = period.into().integer() * 2; + self.delay_ms = period.into().to_millis() * 2; if self.delay_ms > MAX_PERIOD { panic!("Period cannot exceed maximum load value of {}", MAX_PERIOD); diff --git a/rp2040-hal/src/xosc.rs b/rp2040-hal/src/xosc.rs index 31f8aa3..328d7d9 100644 --- a/rp2040-hal/src/xosc.rs +++ b/rp2040-hal/src/xosc.rs @@ -4,13 +4,7 @@ use core::convert::TryInto; use core::{convert::Infallible, ops::RangeInclusive}; -use embedded_time::{ - duration::{Duration, Milliseconds}, - fixed_point::FixedPoint, - fraction::Fraction, - rate::{Hertz, Megahertz, Rate}, -}; - +use fugit::HertzU32; use nb::Error::WouldBlock; /// State of the Crystal Oscillator (typestate trait) @@ -21,12 +15,12 @@ pub struct Disabled; /// XOSC is initialized, ie we've given parameters (typestate) pub struct Initialized { - freq_hz: Hertz, + freq_hz: HertzU32, } /// Stable state (typestate) pub struct Stable { - freq_hz: Hertz, + freq_hz: HertzU32, } /// XOSC is in dormant mode (see Chapter 2, Section 16, §5) @@ -49,7 +43,7 @@ pub enum Error { /// Blocking helper method to setup the XOSC without going through all the steps. pub fn setup_xosc_blocking( xosc_dev: rp2040_pac::XOSC, - frequency: Hertz, + frequency: HertzU32, ) -> Result, Error> { let initialized_xosc = CrystalOscillator::new(xosc_dev).initialize(frequency)?; @@ -89,15 +83,14 @@ impl CrystalOscillator { } /// Initializes the XOSC : frequency range is set, startup delay is calculated and set. - pub fn initialize(self, frequency: Hertz) -> Result, Error> { - const ALLOWED_FREQUENCY_RANGE: RangeInclusive> = - Megahertz(1)..=Megahertz(15); - const STABLE_DELAY: Milliseconds = Milliseconds(1_u32); - const DIVIDER: Fraction = Fraction::new(256, 1); + pub fn initialize(self, frequency: HertzU32) -> Result, Error> { + const ALLOWED_FREQUENCY_RANGE: RangeInclusive = + HertzU32::MHz(1)..=HertzU32::MHz(15); + //1 ms = 10e-3 sec and Freq = 1/T where T is in seconds so 1ms converts to 1000Hz + const STABLE_DELAY_AS_HZ: HertzU32 = HertzU32::Hz(1000); + const DIVIDER: u32 = 256; - let freq_mhz: Megahertz = frequency.into(); - - if !ALLOWED_FREQUENCY_RANGE.contains(&freq_mhz) { + if !ALLOWED_FREQUENCY_RANGE.contains(&frequency) { return Err(Error::FrequencyOutOfRange); } @@ -106,21 +99,14 @@ impl CrystalOscillator { w }); - //1 ms = 10e-3 sec and Freq = 1/T where T is in seconds so 1ms converts to 1000Hz - let delay_to_hz: Hertz = STABLE_DELAY.to_rate().map_err(|_| Error::BadArgument)?; - - //startup_delay = ((freq_hz * 10e-3) / 256) = ((freq_hz / 1000) / 256) + //startup_delay = ((freq_hz * STABLE_DELAY) / 256) = ((freq_hz / delay_to_hz) / 256) + // = freq_hz / (delay_to_hz * 256) //See Chapter 2, Section 16, §3) //We do the calculation first. - let startup_delay = frequency - .checked_div(&delay_to_hz.integer()) - .and_then(|r| r.to_generic::(DIVIDER).ok()) - .ok_or(Error::BadArgument)?; + let startup_delay = frequency.to_Hz() / (STABLE_DELAY_AS_HZ.to_Hz() * DIVIDER); //Then we check if it fits into an u16. - let startup_delay: u16 = (startup_delay.integer()) - .try_into() - .map_err(|_| Error::BadArgument)?; + let startup_delay: u16 = startup_delay.try_into().map_err(|_| Error::BadArgument)?; self.device.startup.write(|w| unsafe { w.delay().bits(startup_delay); @@ -160,7 +146,7 @@ impl CrystalOscillator { impl CrystalOscillator { /// Operating frequency of the XOSC in hertz - pub fn operating_frequency(&self) -> Hertz { + pub fn operating_frequency(&self) -> HertzU32 { self.state.freq_hz }