migrate rp2040-hal from embedded_time to fugit

This commit is contained in:
Wilfried Chauveau 2022-08-18 20:14:51 +01:00
parent 6a29b3bb73
commit 93ec18be07
102 changed files with 318 additions and 353 deletions

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -15,11 +15,11 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
[dev-dependencies] [dev-dependencies]
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
fugit = "0.3.5"
nb = "1.0.0" nb = "1.0.0"
smart-leds = "0.3.0" smart-leds = "0.3.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"

View file

@ -15,7 +15,6 @@ use adafruit_feather_rp2040::{
Pins, XOSC_CRYSTAL_FREQ, Pins, XOSC_CRYSTAL_FREQ,
}; };
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::rate::*;
use panic_halt as _; use panic_halt as _;
#[entry] #[entry]
@ -37,7 +36,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 sio = Sio::new(pac.SIO);
let pins = Pins::new( let pins = Pins::new(

View file

@ -20,7 +20,7 @@ use adafruit_feather_rp2040::{
}; };
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use ws2812_pio::Ws2812; use ws2812_pio::Ws2812;
@ -71,7 +71,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -15,7 +15,6 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
[dev-dependencies] [dev-dependencies]
panic-halt= "0.2.0" panic-halt= "0.2.0"
@ -23,6 +22,7 @@ embedded-hal ="0.2.5"
smart-leds = "0.3" smart-leds = "0.3"
nb = "1.0.0" nb = "1.0.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
[features] [features]
default = ["rt", "boot2"] default = ["rt", "boot2"]

View file

@ -18,7 +18,6 @@ use panic_halt as _;
// Some traits we need // Some traits we need
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use adafruit_itsy_bitsy_rp2040::{ use adafruit_itsy_bitsy_rp2040::{
hal::{ hal::{
@ -61,7 +60,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // The single-cycle I/O block controls our GPIO pins
let sio = Sio::new(pac.SIO); let sio = Sio::new(pac.SIO);

View file

@ -6,7 +6,7 @@ use adafruit_itsy_bitsy_rp2040::entry;
use core::iter::once; use core::iter::once;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use ws2812_pio::Ws2812; use ws2812_pio::Ws2812;
@ -72,7 +72,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -26,6 +26,6 @@ rt = ["cortex-m-rt","rp2040-hal/rt"]
panic-halt = "0.2.0" panic-halt = "0.2.0"
rp2040-boot2 = "0.2" rp2040-boot2 = "0.2"
smart-leds = "0.3.0" smart-leds = "0.3.0"
embedded-time = "0.12.0" fugit = "0.3.5"
nb = "1.0.0" nb = "1.0.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"

View file

@ -11,7 +11,7 @@
use adafruit_kb2040::entry; use adafruit_kb2040::entry;
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use adafruit_kb2040::{ use adafruit_kb2040::{
@ -84,7 +84,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -15,8 +15,8 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
[dev-dependencies] [dev-dependencies]
embedded-time = "0.12.0"
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"

View file

@ -14,7 +14,6 @@ use adafruit_macropad::{
Pins, XOSC_CRYSTAL_FREQ, Pins, XOSC_CRYSTAL_FREQ,
}; };
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::rate::*;
use panic_halt as _; use panic_halt as _;
/// Entry point to our bare-metal application. /// Entry point to our bare-metal application.
@ -40,7 +39,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 sio = Sio::new(pac.SIO);
let pins = Pins::new( let pins = Pins::new(

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -14,7 +14,6 @@ repository = "https://github.com/rp-rs/rp-hal.git"
cortex-m = "0.7.2" cortex-m = "0.7.2"
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
@ -23,6 +22,7 @@ embedded-hal ="0.2.5"
smart-leds = "0.3" smart-leds = "0.3"
nb = "1.0.0" nb = "1.0.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
[features] [features]
default = ["boot2", "rt"] default = ["boot2", "rt"]

View file

@ -6,7 +6,7 @@ use adafruit_qt_py_rp2040::entry;
use core::iter::once; use core::iter::once;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use ws2812_pio::Ws2812; use ws2812_pio::Ws2812;
@ -72,7 +72,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25u32.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -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`

View file

@ -18,10 +18,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
embedded-time = "0.12.0"
smart-leds = "0.3" smart-leds = "0.3"
nb = "1.0.0" nb = "1.0.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
[features] [features]
default = ["boot2", "rt"] default = ["boot2", "rt"]

View file

@ -11,7 +11,7 @@
use adafruit_trinkey_qt2040::entry; use adafruit_trinkey_qt2040::entry;
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use adafruit_trinkey_qt2040::{ use adafruit_trinkey_qt2040::{
@ -84,7 +84,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`

View file

@ -17,12 +17,12 @@ rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7.0", optional = true } cortex-m-rt = { version = "0.7.0", optional = true }
embedded-hal = { version = "0.2.4", features = ["unproven"] } embedded-hal = { version = "0.2.4", features = ["unproven"] }
panic-probe = { version = "0.3.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
embedded-time = "0.12.0"
[dev-dependencies] [dev-dependencies]
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
nb = "1.0" nb = "1.0"
fugit = "0.3.5"
[features] [features]
default = ["boot2", "rt"] default = ["boot2", "rt"]

View file

@ -11,8 +11,6 @@
#![no_main] #![no_main]
use embedded_hal::digital::v2::OutputPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
@ -64,7 +62,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`

View file

@ -15,7 +15,7 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0"} rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0"}
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0" fugit = "0.3.5"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
[dev-dependencies] [dev-dependencies]

View file

@ -28,7 +28,7 @@ use pimoroni_badger2040::hal;
// A few traits required for using the CountDown timer // A few traits required for using the CountDown timer
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
@ -75,12 +75,12 @@ fn main() -> ! {
loop { loop {
// LED on, and wait for 500ms // LED on, and wait for 500ms
led_pin.set_high().unwrap(); led_pin.set_high().unwrap();
delay.start(500.milliseconds()); delay.start(500.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
// LED off, and wait for 500ms // LED off, and wait for 500ms
led_pin.set_low().unwrap(); led_pin.set_low().unwrap();
delay.start(500.milliseconds()); delay.start(500.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true }
embedded-hal = { version = "0.2.4", features = ["unproven"] } embedded-hal = { version = "0.2.4", features = ["unproven"] }
st7789 = "0.6.1" st7789 = "0.6.1"
display-interface-spi = "0.4.1" display-interface-spi = "0.4.1"
embedded-time = "0.12.0" fugit = "0.3.5"
embedded-graphics = "0.7.1" embedded-graphics = "0.7.1"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }

View file

@ -10,7 +10,6 @@ use embedded_graphics::{
text::{Alignment, Text}, text::{Alignment, Text},
}; };
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::rate::*;
use hal::{adc::Adc, clocks::*, watchdog::Watchdog, Sio}; use hal::{adc::Adc, clocks::*, watchdog::Watchdog, Sio};
use panic_halt as _; use panic_halt as _;
use pimoroni_pico_explorer::entry; use pimoroni_pico_explorer::entry;
@ -41,7 +40,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // Enable adc
let mut adc = Adc::new(p.ADC, &mut p.RESETS); let mut adc = Adc::new(p.ADC, &mut p.RESETS);

View file

@ -30,7 +30,7 @@ use embedded_hal::{
digital::v2::{InputPin, OutputPin}, digital::v2::{InputPin, OutputPin},
spi::MODE_0, spi::MODE_0,
}; };
use embedded_time::rate::*; use fugit::RateExtU32;
pub use hal::pac; pub use hal::pac;
use hal::{ use hal::{
adc::Adc, adc::Adc,
@ -211,12 +211,7 @@ impl PicoExplorer {
let spi_sclk = internal_pins.spi_sclk.into_mode::<FunctionSpi>(); let spi_sclk = internal_pins.spi_sclk.into_mode::<FunctionSpi>();
let spi_mosi = internal_pins.spi_mosi.into_mode::<FunctionSpi>(); let spi_mosi = internal_pins.spi_mosi.into_mode::<FunctionSpi>();
let spi_screen = Spi::<_, _, 8>::new(spi0).init( let spi_screen = Spi::<_, _, 8>::new(spi0).init(resets, 125u32.MHz(), 16u32.MHz(), &MODE_0);
resets,
125_000_000u32.Hz(),
16_000_000u32.Hz(),
&MODE_0,
);
let spii_screen = SPIInterface::new(spi_screen, dc, cs); let spii_screen = SPIInterface::new(spi_screen, dc, cs);

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -17,7 +17,6 @@ cortex-m-rt = { version = "0.7", optional = true }
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
embedded-time = "0.12.0"
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
nb = "1.0" nb = "1.0"

View file

@ -16,9 +16,6 @@ use pimoroni_pico_lipo_16mb::entry;
// GPIO traits // GPIO traits
use embedded_hal::digital::v2::OutputPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -67,7 +64,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`

View file

@ -15,7 +15,6 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
[dev-dependencies] [dev-dependencies]
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] } 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" embedded-hal ="0.2.5"
smart-leds = "0.3.0" smart-leds = "0.3.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
defmt = "0.3.0" defmt = "0.3.0"
defmt-rtt = "0.3.0" defmt-rtt = "0.3.0"

View file

@ -5,7 +5,6 @@
use defmt::*; use defmt::*;
use defmt_rtt as _; use defmt_rtt as _;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use panic_halt as _; use panic_halt as _;
use pimoroni_plasma_2040 as bsp; use pimoroni_plasma_2040 as bsp;
@ -41,7 +40,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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( let pins = bsp::Pins::new(
pac.IO_BANK0, pac.IO_BANK0,

View file

@ -13,9 +13,6 @@ use panic_halt as _;
// Pull in any important traits // Pull in any important traits
use pimoroni_plasma_2040::hal::prelude::*; 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 // A shorter alias for the Peripheral Access Crate, which provides low-level
// register access // register access
use pimoroni_plasma_2040::hal::pac; use pimoroni_plasma_2040::hal::pac;
@ -82,7 +79,7 @@ fn main() -> ! {
// Setup a delay for the LED blink signals: // Setup a delay for the LED blink signals:
let mut frame_delay = 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 // Import the `sin` function for a smooth hue animation from the
// Pico rp2040 ROM: // Pico rp2040 ROM:

View file

@ -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`

View file

@ -15,12 +15,12 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0"
[dev-dependencies] [dev-dependencies]
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] }
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
fugit = "0.3.5"
defmt = "0.3.0" defmt = "0.3.0"
defmt-rtt = "0.3.0" defmt-rtt = "0.3.0"

View file

@ -6,7 +6,6 @@ use bsp::entry;
use defmt::*; use defmt::*;
use defmt_rtt as _; use defmt_rtt as _;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use panic_halt as _; use panic_halt as _;
use pimoroni_tiny2040 as bsp; use pimoroni_tiny2040 as bsp;
@ -38,7 +37,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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( let pins = bsp::Pins::new(
pac.IO_BANK0, pac.IO_BANK0,

View file

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`
## 0.4.0 - 2022-06-13 ## 0.4.0 - 2022-06-13

View file

@ -15,7 +15,7 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0" fugit = "0.3.5"
usb-device= "0.2.9" usb-device= "0.2.9"
usbd-serial = "0.1.1" usbd-serial = "0.1.1"
usbd-hid = "0.5.1" usbd-hid = "0.5.1"

View file

@ -16,9 +16,6 @@ use rp_pico::entry;
// GPIO traits // GPIO traits
use embedded_hal::digital::v2::OutputPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -67,7 +64,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -19,7 +19,7 @@ use cortex_m::prelude::*;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
// Traits for converting integers to amounts of time // 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
@ -77,12 +77,12 @@ fn main() -> ! {
loop { loop {
// LED on, and wait for 500ms // LED on, and wait for 500ms
led_pin.set_high().unwrap(); led_pin.set_high().unwrap();
count_down.start(500.milliseconds()); count_down.start(500.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
// LED off, and wait for 500ms // LED off, and wait for 500ms
led_pin.set_low().unwrap(); led_pin.set_low().unwrap();
count_down.start(500.milliseconds()); count_down.start(500.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
} }
} }

View file

@ -48,9 +48,6 @@ use rp_pico::hal::prelude::*;
// GPIO traits // GPIO traits
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
// Time handling traits
use embedded_time::rate::*;
// For LCD display // For LCD display
use hd44780_driver::HD44780; use hd44780_driver::HD44780;
@ -95,7 +92,7 @@ fn main() -> ! {
let mut led_pin = pins.led.into_push_pull_output(); let mut led_pin = pins.led.into_push_pull_output();
// The delay object lets us wait for specified amounts of time // 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 // Init pins
let rs = pins.gpio7.into_push_pull_output(); let rs = pins.gpio7.into_push_pull_output();

View file

@ -48,8 +48,7 @@ use core::fmt::Write;
use rp_pico::entry; use rp_pico::entry;
// Time handling traits: // Time handling traits:
use embedded_time::duration::*; use fugit::{ExtU32, RateExtU32};
use embedded_time::rate::Extensions;
// CountDown timer for the counter on the display: // CountDown timer for the counter on the display:
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
@ -182,7 +181,7 @@ fn main() -> ! {
display.flush().unwrap(); display.flush().unwrap();
// Wait a bit: // Wait a bit:
delay.start(500.milliseconds()); delay.start(500.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -21,7 +21,7 @@ use rp_pico::entry;
use embedded_hal::blocking::i2c::{Operation, Read, Transactional, Write}; use embedded_hal::blocking::i2c::{Operation, Read, Transactional, Write};
// Time handling traits // 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
@ -109,7 +109,7 @@ fn main() -> ! {
pins.gpio20, pins.gpio20,
pins.gpio21, pins.gpio21,
sm0, sm0,
100_000.Hz(), 100.kHz(),
clocks.system_clock.freq(), clocks.system_clock.freq(),
); );

View file

@ -17,9 +17,6 @@ use defmt_rtt as _;
// The macro for our start-up function // The macro for our start-up function
use rp_pico::entry; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -125,7 +122,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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); let (mut pio0, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);

View file

@ -16,9 +16,6 @@ use rp_pico::entry;
// GPIO traits // GPIO traits
use embedded_hal::PwmPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -84,7 +81,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // Init PWMs
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);

View file

@ -15,7 +15,7 @@ use cortex_m::prelude::*;
use embedded_hal::PwmPin; use embedded_hal::PwmPin;
// Traits for converting integers to amounts of time // 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
@ -93,22 +93,22 @@ fn main() -> ! {
loop { loop {
// move to 0° // move to 0°
channel.set_duty(2500); channel.set_duty(2500);
count_down.start(400.milliseconds()); count_down.start(400.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
// 0° to 90° // 0° to 90°
channel.set_duty(3930); channel.set_duty(3930);
count_down.start(400.milliseconds()); count_down.start(400.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
// 90° to 180° // 90° to 180°
channel.set_duty(7860); channel.set_duty(7860);
count_down.start(400.milliseconds()); count_down.start(400.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
// 180° to 90° // 180° to 90°
channel.set_duty(3930); channel.set_duty(3930);
count_down.start(400.milliseconds()); count_down.start(400.millis());
let _ = nb::block!(count_down.wait()); let _ = nb::block!(count_down.wait());
} }
} }

View file

@ -7,13 +7,13 @@ use panic_halt as _;
mod app { mod app {
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::duration::Extensions; use fugit::SecsDurationU32;
use rp_pico::{ use rp_pico::{
hal::{self, clocks::init_clocks_and_plls, timer::Alarm, watchdog::Watchdog, Sio}, hal::{self, clocks::init_clocks_and_plls, timer::Alarm, watchdog::Watchdog, Sio},
XOSC_CRYSTAL_FREQ, XOSC_CRYSTAL_FREQ,
}; };
const SCAN_TIME_US: u32 = 1000000; const SCAN_TIME_US: SecsDurationU32 = SecsDurationU32::secs(1);
#[shared] #[shared]
struct Shared { struct Shared {
@ -58,7 +58,7 @@ mod app {
let mut timer = hal::Timer::new(c.device.TIMER, &mut resets); let mut timer = hal::Timer::new(c.device.TIMER, &mut resets);
let mut alarm = timer.alarm_0().unwrap(); let mut alarm = timer.alarm_0().unwrap();
let _ = alarm.schedule(SCAN_TIME_US.microseconds()); let _ = alarm.schedule(SCAN_TIME_US);
alarm.enable_interrupt(); alarm.enable_interrupt();
(Shared { timer, alarm, led }, Local {}, init::Monotonics()) (Shared { timer, alarm, led }, Local {}, init::Monotonics())
@ -81,7 +81,7 @@ mod app {
let mut alarm = c.shared.alarm; let mut alarm = c.shared.alarm;
(alarm).lock(|a| { (alarm).lock(|a| {
a.clear_interrupt(); a.clear_interrupt();
let _ = a.schedule(SCAN_TIME_US.microseconds()); let _ = a.schedule(SCAN_TIME_US);
}); });
} }
} }

View file

@ -107,7 +107,7 @@ use panic_halt as _;
use rp_pico::hal::prelude::*; use rp_pico::hal::prelude::*;
// Embed the `Hz` function/trait: // Embed the `Hz` function/trait:
use embedded_time::rate::*; use fugit::RateExtU32;
// A shorter alias for the Peripheral Access Crate, which provides low-level // A shorter alias for the Peripheral Access Crate, which provides low-level
// register access // register access
@ -236,7 +236,7 @@ fn main() -> ! {
let mut led_pin = pins.led.into_push_pull_output(); let mut led_pin = pins.led.into_push_pull_output();
// Setup a delay for the LED blink signals: // 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 // These are implicitly used by the spi driver if they are in the correct mode
let _spi_sclk = pins.gpio2.into_mode::<gpio::FunctionSpi>(); let _spi_sclk = pins.gpio2.into_mode::<gpio::FunctionSpi>();

View file

@ -21,9 +21,6 @@
// objects as generic embedded devices. // objects as generic embedded devices.
use embedded_hal::{digital::v2::OutputPin, serial::Write as UartWrite}; 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. // The writeln! trait.
use core::fmt::Write; use core::fmt::Write;
@ -114,7 +111,7 @@ fn main() -> ! {
.unwrap(); .unwrap();
// Lets us wait for fixed periods of time // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -22,9 +22,6 @@ use embedded_hal::{
serial::{Read, Write}, 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. // We also need this for the 'Delay' object to work.
use rp2040_hal::Clock; use rp2040_hal::Clock;
@ -98,7 +95,7 @@ fn main() -> ! {
.unwrap(); .unwrap();
// Lets us wait for fixed periods of time // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -21,9 +21,6 @@ use rp_pico::hal::pac::interrupt;
// GPIO traits // GPIO traits
use embedded_hal::digital::v2::OutputPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -131,7 +128,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -25,7 +25,6 @@ use rp_pico::hal::pac::interrupt;
use panic_halt as _; use panic_halt as _;
// Pull in any important traits // Pull in any important traits
use embedded_time::fixed_point::FixedPoint;
use rp_pico::hal::prelude::*; use rp_pico::hal::prelude::*;
// A shorter alias for the Peripheral Access Crate, which provides low-level // 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); pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ);
}; };
let core = pac::CorePeripherals::take().unwrap(); 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 // Move the cursor up and down every 200ms
loop { loop {

View file

@ -50,9 +50,6 @@ use panic_halt as _;
// Pull in any important traits // Pull in any important traits
use rp_pico::hal::prelude::*; 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 // A shorter alias for the Peripheral Access Crate, which provides low-level
// register access // register access
use rp_pico::hal::pac; use rp_pico::hal::pac;
@ -115,7 +112,7 @@ fn main() -> ! {
// Setup a delay for the LED blink signals: // Setup a delay for the LED blink signals:
let mut frame_delay = 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 // Import the `sin` function for a smooth hue animation from the
// Pico rp2040 ROM: // Pico rp2040 ROM:

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.1.0 - 2022-06-26 ## 0.1.0 - 2022-06-26

View file

@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true }
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
embedded-time = "0.12.0" fugit = "0.3.5"
panic-halt= "0.2.0" panic-halt= "0.2.0"
embedded-hal ="0.2.5" embedded-hal ="0.2.5"
nb = "1.0" nb = "1.0"

View file

@ -17,9 +17,6 @@ use seeeduino_xiao_rp2040::entry;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_hal::PwmPin; 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 // Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked) // be linked)
use panic_halt as _; use panic_halt as _;
@ -85,7 +82,7 @@ fn main() -> ! {
// The delay object lets us wait for specified amounts of time (in // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // Init PWMs
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);

View file

@ -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`

View file

@ -28,4 +28,4 @@ nb = "1.0.0"
smart-leds = "0.3.0" smart-leds = "0.3.0"
pio = "0.1.0" pio = "0.1.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
embedded-time = "0.12.0" fugit = "0.3.5"

View file

@ -8,7 +8,7 @@
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use solderparty_rp2040_stamp::entry; use solderparty_rp2040_stamp::entry;
@ -71,7 +71,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25u32.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.3.0 - 2022-06-13 ## 0.3.0 - 2022-06-13

View file

@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
panic-halt = "0.2.0" panic-halt = "0.2.0"
smart-leds = "0.3.0" smart-leds = "0.3.0"
embedded-time = "0.12.0"
nb = "1.0.0" nb = "1.0.0"
pio = "0.1.0" pio = "0.1.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
[features] [features]
default = ["boot2", "rt"] default = ["boot2", "rt"]

View file

@ -10,7 +10,7 @@
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use sparkfun_pro_micro_rp2040::entry; use sparkfun_pro_micro_rp2040::entry;
@ -83,7 +83,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`
## 0.2.0 - 2022-06-13 ## 0.2.0 - 2022-06-13

View file

@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
[dev-dependencies] [dev-dependencies]
panic-halt = "0.2.0" panic-halt = "0.2.0"
smart-leds = "0.3.0" smart-leds = "0.3.0"
embedded-time = "0.12.0"
nb = "1.0.0" nb = "1.0.0"
pio = "0.1.0" pio = "0.1.0"
ws2812-pio = "0.3.0" ws2812-pio = "0.3.0"
fugit = "0.3.5"
[features] [features]
default = ["boot2", "rt"] default = ["boot2", "rt"]

View file

@ -10,7 +10,7 @@
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
@ -82,7 +82,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- None - Migrate from `embedded-time` to `fugit`
## 0.1.0 - 2022-07-17 ## 0.1.0 - 2022-07-17

View file

@ -15,7 +15,7 @@ cortex-m = "0.7.2"
rp2040-boot2 = { version = "0.2.0", optional = true } rp2040-boot2 = { version = "0.2.0", optional = true }
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" } rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
cortex-m-rt = { version = "0.7", optional = true } cortex-m-rt = { version = "0.7", optional = true }
embedded-time = "0.12.0" fugit = "0.3.5"
usb-device= "0.2.9" usb-device= "0.2.9"
usbd-serial = "0.1.1" usbd-serial = "0.1.1"
usbd-hid = "0.5.1" usbd-hid = "0.5.1"

View file

@ -5,7 +5,6 @@
#![no_main] #![no_main]
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::rate::*;
use panic_halt as _; use panic_halt as _;
use vcc_gnd_yd_rp2040::entry; use vcc_gnd_yd_rp2040::entry;
use vcc_gnd_yd_rp2040::{ use vcc_gnd_yd_rp2040::{
@ -37,7 +36,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 sio = Sio::new(pac.SIO);
let pins = Pins::new( let pins = Pins::new(

View file

@ -8,7 +8,7 @@
use core::iter::once; use core::iter::once;
use embedded_hal::timer::CountDown; use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions; use fugit::ExtU32;
use panic_halt as _; use panic_halt as _;
use smart_leds::{brightness, SmartLedsWrite, RGB8}; use smart_leds::{brightness, SmartLedsWrite, RGB8};
use vcc_gnd_yd_rp2040::entry; use vcc_gnd_yd_rp2040::entry;
@ -71,7 +71,7 @@ fn main() -> ! {
ws.write(brightness(once(wheel(n)), 32)).unwrap(); ws.write(brightness(once(wheel(n)), 32)).unwrap();
n = n.wrapping_add(1); n = n.wrapping_add(1);
delay.start(25.milliseconds()); delay.start(25.millis());
let _ = nb::block!(delay.wait()); let _ = nb::block!(delay.wait());
} }
} }

View file

@ -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<SomeClock> for Hertz` - Implement `From<&SomeClock> for Hertz` instead of `From<SomeClock> for Hertz`
for the clocks in `rp2040_hal::clocks`. for the clocks in `rp2040_hal::clocks`.
- Use `rp2040-hal`'s entry function. - Use `rp2040-hal`'s entry function.
- Migrate from `embedded-time` to `fugit`
## [0.5.0] - 2022-06-13 ## [0.5.0] - 2022-06-13

View file

@ -14,7 +14,7 @@ cortex-m = "0.7.2"
cortex-m-rt = ">=0.6.15,<0.8" cortex-m-rt = ">=0.6.15,<0.8"
embedded-hal = { version = "0.2.5", features = ["unproven"] } embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-alpha.8", optional = true } 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 } itertools = { version = "0.10.1", default-features = false }
nb = "1.0" nb = "1.0"
rp2040-pac = "0.3.0" rp2040-pac = "0.3.0"

View file

@ -20,7 +20,6 @@ use rp2040_hal as hal;
// Some traits we need // Some traits we need
use core::fmt::Write; use core::fmt::Write;
use embedded_hal::adc::OneShot; use embedded_hal::adc::OneShot;
use embedded_time::fixed_point::FixedPoint;
use rp2040_hal::Clock; use rp2040_hal::Clock;
// A shorter alias for the Peripheral Access Crate, which provides low-level // 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 // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -22,7 +22,6 @@ use hal::pac;
// Some traits we need // Some traits we need
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
/// The linker will place this boot block at the start of our program image. We /// The linker will place this boot block at the start of our program image. We
@ -64,7 +63,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -26,7 +26,6 @@ use hal::pac;
// Some traits we need // Some traits we need
use embedded_hal::digital::v2::InputPin; use embedded_hal::digital::v2::InputPin;
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use hal::gpio::dynpin::DynPin; use hal::gpio::dynpin::DynPin;
use hal::Clock; use hal::Clock;
@ -124,7 +123,7 @@ fn main() -> ! {
&mut pac.RESETS, &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 // Use GPIO 28 as an InOutPin
let mut pin = InOutPin::new(pins.gpio28.into()); let mut pin = InOutPin::new(pins.gpio28.into());

View file

@ -15,7 +15,7 @@ use panic_halt as _;
// Some traits we need // Some traits we need
use embedded_hal::blocking::i2c::Write; use embedded_hal::blocking::i2c::Write;
use embedded_time::rate::Extensions; use fugit::RateExtU32;
// Alias for our HAL crate // Alias for our HAL crate
use rp2040_hal as hal; use rp2040_hal as hal;

View file

@ -23,7 +23,6 @@ use rp2040_hal as hal;
use hd44780_driver as hd44780; use hd44780_driver as hd44780;
// Some traits we need // Some traits we need
use embedded_time::fixed_point::FixedPoint;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
// A shorter alias for the Peripheral Access Crate, which provides low-level // 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 // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -12,7 +12,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use embedded_time::fixed_point::FixedPoint;
use hal::clocks::Clock; use hal::clocks::Clock;
use hal::multicore::{Multicore, Stack}; use hal::multicore::{Multicore, Stack};
use hal::sio::Sio; use hal::sio::Sio;
@ -107,7 +106,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // The single-cycle I/O block controls our GPIO pins
let mut sio = hal::sio::Sio::new(pac.SIO); let mut sio = hal::sio::Sio::new(pac.SIO);

View file

@ -10,7 +10,6 @@
use cortex_m::delay::Delay; use cortex_m::delay::Delay;
use embedded_time::fixed_point::FixedPoint;
use hal::clocks::Clock; use hal::clocks::Clock;
use hal::gpio::Pins; use hal::gpio::Pins;
use hal::multicore::{Multicore, Stack}; use hal::multicore::{Multicore, Stack};
@ -98,7 +97,7 @@ fn main() -> ! {
let mut led2 = pins.gpio3.into_push_pull_output(); let mut led2 = pins.gpio3.into_push_pull_output();
// Set up the delay for the first core. // 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); let mut delay = Delay::new(core.SYST, sys_freq);
// Start up the second core to blink the second LED // Start up the second core to blink the second LED

View file

@ -19,7 +19,6 @@ use rp2040_hal as hal;
// Some traits we need // Some traits we need
use embedded_hal::PwmPin; use embedded_hal::PwmPin;
use embedded_time::rate::*;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
// A shorter alias for the Peripheral Access Crate, which provides low-level // 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 // The delay object lets us wait for specified amounts of time (in
// milliseconds) // 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 // Init PWMs
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);

View file

@ -21,7 +21,7 @@ use rp2040_hal as hal;
// Some traits we need // Some traits we need
use cortex_m::prelude::*; use cortex_m::prelude::*;
use embedded_time::rate::Extensions; use fugit::RateExtU32;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
// A shorter alias for the Peripheral Access Crate, which provides low-level // A shorter alias for the Peripheral Access Crate, which provides low-level
@ -87,7 +87,7 @@ fn main() -> ! {
let mut spi = spi.init( let mut spi = spi.init(
&mut pac.RESETS, &mut pac.RESETS,
clocks.peripheral_clock.freq(), clocks.peripheral_clock.freq(),
16_000_000u32.Hz(), 16.MHz(),
&embedded_hal::spi::MODE_0, &embedded_hal::spi::MODE_0,
); );

View file

@ -24,7 +24,6 @@ use hal::pac;
// Some traits we need // Some traits we need
use core::fmt::Write; use core::fmt::Write;
use embedded_time::fixed_point::FixedPoint;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
/// The linker will place this boot block at the start of our program image. We /// The linker will place this boot block at the start of our program image. We
@ -66,7 +65,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);

View file

@ -22,8 +22,7 @@ use hal::pac;
use core::cell::RefCell; use core::cell::RefCell;
use critical_section::Mutex; use critical_section::Mutex;
use embedded_hal::digital::v2::ToggleableOutputPin; use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_time::duration::Microseconds; use fugit::MicrosDurationU32;
use embedded_time::fixed_point::FixedPoint;
use pac::interrupt; use pac::interrupt;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
use rp2040_hal::timer::Alarm; use rp2040_hal::timer::Alarm;
@ -42,8 +41,8 @@ type LedAndAlarm = (
static mut LED_AND_ALARM: Mutex<RefCell<Option<LedAndAlarm>>> = Mutex::new(RefCell::new(None)); static mut LED_AND_ALARM: Mutex<RefCell<Option<LedAndAlarm>>> = Mutex::new(RefCell::new(None));
// Period that each of the alarms will be set for - 1 second and 300ms respectively // 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 SLOW_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::secs(1);
const FAST_BLINK_INTERVAL_US: u32 = 300_000; const FAST_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::millis(300);
/// The linker will place this boot block at the start of our program image. We /// 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. /// need this to help the ROM bootloader get our code up and running.
@ -96,7 +95,7 @@ fn main() -> ! {
.unwrap(); .unwrap();
// Create simple delay // 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 // Set the pins to their default state
let pins = hal::gpio::Pins::new( let pins = hal::gpio::Pins::new(
@ -113,7 +112,7 @@ fn main() -> ! {
critical_section::with(|cs| { critical_section::with(|cs| {
let mut alarm = timer.alarm_0().unwrap(); let mut alarm = timer.alarm_0().unwrap();
// Schedule an alarm in 1 second // 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 // Enable generating an interrupt on alarm
alarm.enable_interrupt(); alarm.enable_interrupt();
// Move alarm into ALARM, so that it can be accessed from interrupts // 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 // Clear the alarm interrupt or this interrupt service routine will keep firing
alarm.clear_interrupt(); alarm.clear_interrupt();
// Schedule a new alarm after SLOW_BLINK_INTERVAL_US have passed (1 second) // 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 // Blink the LED so we know we hit this interrupt
led.toggle().unwrap(); led.toggle().unwrap();
// Return LED_AND_ALARM into our static variable // 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 // Clear the alarm interrupt or this interrupt service routine will keep firing
alarm.clear_interrupt(); alarm.clear_interrupt();
// Schedule a new alarm after FAST_BLINK_INTERVAL_US have passed (300 milliseconds) // 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(); led.toggle().unwrap();
// Return LED_AND_ALARM into our static variable // Return LED_AND_ALARM into our static variable
unsafe { unsafe {

View file

@ -23,8 +23,7 @@ use hal::pac;
// Some traits we need // Some traits we need
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use embedded_hal::watchdog::{Watchdog, WatchdogEnable}; use embedded_hal::watchdog::{Watchdog, WatchdogEnable};
use embedded_time::duration::Extensions; use fugit::ExtU32;
use embedded_time::fixed_point::FixedPoint;
use rp2040_hal::clocks::Clock; use rp2040_hal::clocks::Clock;
/// The linker will place this boot block at the start of our program image. We /// The linker will place this boot block at the start of our program image. We
@ -67,7 +66,7 @@ fn main() -> ! {
.ok() .ok()
.unwrap(); .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 // The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO); let sio = hal::Sio::new(pac.SIO);
@ -88,7 +87,7 @@ fn main() -> ! {
delay.delay_ms(2000); delay.delay_ms(2000);
// Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it // 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 // Blink once a second for 5 seconds, refreshing the watchdog timer once a second to avoid a reset
for _ in 1..=5 { for _ in 1..=5 {

View file

@ -16,7 +16,7 @@ use pac::{PLL_SYS, PLL_USB};
pub(crate) type PllSys = PhaseLockedLoop<Locked, PLL_SYS>; pub(crate) type PllSys = PhaseLockedLoop<Locked, PLL_SYS>;
impl Sealed for PllSys {} impl Sealed for PllSys {}
impl ClockSource for PllSys { impl ClockSource for PllSys {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.operating_frequency() self.operating_frequency()
} }
} }
@ -24,37 +24,37 @@ impl ClockSource for PllSys {
pub(crate) type PllUsb = PhaseLockedLoop<Locked, PLL_USB>; pub(crate) type PllUsb = PhaseLockedLoop<Locked, PLL_USB>;
impl Sealed for PllUsb {} impl Sealed for PllUsb {}
impl ClockSource for PllUsb { impl ClockSource for PllUsb {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.operating_frequency() self.operating_frequency()
} }
} }
impl ClockSource for UsbClock { impl ClockSource for UsbClock {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
} }
impl ClockSource for AdcClock { impl ClockSource for AdcClock {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
} }
impl ClockSource for RtcClock { impl ClockSource for RtcClock {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
} }
impl ClockSource for SystemClock { impl ClockSource for SystemClock {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
} }
impl ClockSource for ReferenceClock { impl ClockSource for ReferenceClock {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
} }
@ -62,7 +62,7 @@ impl ClockSource for ReferenceClock {
pub(crate) type Xosc = CrystalOscillator<Stable>; pub(crate) type Xosc = CrystalOscillator<Stable>;
impl Sealed for Xosc {} impl Sealed for Xosc {}
impl ClockSource for Xosc { impl ClockSource for Xosc {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.operating_frequency() self.operating_frequency()
} }
} }
@ -71,7 +71,7 @@ pub(crate) type Rosc = RingOscillator<Enabled>;
impl Sealed for Rosc {} impl Sealed for Rosc {}
// We are assuming the second output is never phase shifted (see 2.17.4) // We are assuming the second output is never phase shifted (see 2.17.4)
impl ClockSource for RingOscillator<Enabled> { impl ClockSource for RingOscillator<Enabled> {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
self.operating_frequency() self.operating_frequency()
} }
} }
@ -79,7 +79,7 @@ impl ClockSource for RingOscillator<Enabled> {
// GPIN0 // GPIN0
pub(crate) type GPin0 = Pin<Gpio20, FunctionClock>; pub(crate) type GPin0 = Pin<Gpio20, FunctionClock>;
impl ClockSource for GPin0 { impl ClockSource for GPin0 {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
todo!() todo!()
} }
} }
@ -87,7 +87,7 @@ impl ClockSource for GPin0 {
// GPIN1 // GPIN1
pub(crate) type GPin1 = Pin<Gpio22, FunctionClock>; pub(crate) type GPin1 = Pin<Gpio22, FunctionClock>;
impl ClockSource for Pin<Gpio22, FunctionClock> { impl ClockSource for Pin<Gpio22, FunctionClock> {
fn get_freq(&self) -> Hertz { fn get_freq(&self) -> HertzU32 {
todo!() todo!()
} }
} }

View file

@ -140,7 +140,8 @@ macro_rules! clock {
w.src().variant(self.get_default_clock_source()) 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::<Self>}) self.await_select(&ChangingClockToken{clock_nr:0, clock: PhantomData::<Self>})
} }
@ -174,19 +175,19 @@ macro_rules! clock {
type Variant = [<$reg:camel SrcType>]; type Variant = [<$reg:camel SrcType>];
#[doc = "Get operating frequency for `"$name"`"] #[doc = "Get operating frequency for `"$name"`"]
fn freq(&self) -> Hertz { fn freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
#[doc = "Configure `"$name"`"] #[doc = "Configure `"$name"`"]
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{ fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{
let src_freq: Hertz<u32> = src.get_freq().into(); let src_freq: HertzU32 = src.get_freq().into();
if freq.gt(&src_freq){ if freq.gt(&src_freq){
return Err(ClockError::CantIncreaseFreq); 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 // If increasing divisor, set divisor before source. Otherwise set source
// before divisor. This avoids a momentary overspeed when e.g. switching // before divisor. This avoids a momentary overspeed when e.g. switching
@ -217,7 +218,8 @@ macro_rules! clock {
self.set_div(div); self.set_div(div);
// Store the configured frequency // 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(()) Ok(())
} }
@ -324,19 +326,19 @@ macro_rules! stoppable_clock {
type Variant = [<$reg:camel SrcType>]; type Variant = [<$reg:camel SrcType>];
#[doc = "Get operating frequency for `"$name"`"] #[doc = "Get operating frequency for `"$name"`"]
fn freq(&self) -> Hertz { fn freq(&self) -> HertzU32 {
self.frequency self.frequency
} }
#[doc = "Configure `"$name"`"] #[doc = "Configure `"$name"`"]
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{ fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{
let src_freq: Hertz<u32> = src.get_freq().into(); let src_freq: HertzU32 = src.get_freq().into();
if freq.gt(&src_freq){ if freq.gt(&src_freq){
return Err(ClockError::CantIncreaseFreq); 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 // If increasing divisor, set divisor before source. Otherwise set source
// before divisor. This avoids a momentary overspeed when e.g. switching // 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, // Disable clock. On clk_ref and clk_sys this does nothing,
// all other clocks have the ENABLE bit in the same position. // all other clocks have the ENABLE bit in the same position.
self.disable(); self.disable();
if (self.frequency > 0u32.Hz()) { if self.frequency > HertzU32::Hz(0) {
// Delay for 3 cycles of the target clock, for ENABLE propagation. // Delay for 3 cycles of the target clock, for ENABLE propagation.
// Note XOSC_COUNT is not helpful here because XOSC is not // Note XOSC_COUNT is not helpful here because XOSC is not
// necessarily running, nor is timer... so, 3 cycles per loop: // necessarily running, nor is timer... so, 3 cycles per loop:
let sys_freq = 125_000_000; // TODO get actual sys_clk frequency 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); cortex_m::asm::delay(delay_cyc);
} }
@ -373,7 +375,8 @@ macro_rules! stoppable_clock {
self.set_div(div); self.set_div(div);
// Store the configured frequency // 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(()) Ok(())
} }
@ -402,7 +405,7 @@ macro_rules! base_clock {
$(#[$attr])* $(#[$attr])*
pub struct $name { pub struct $name {
shared_dev: ShareableClocks, shared_dev: ShareableClocks,
frequency: Hertz, frequency: HertzU32,
} }
impl $name { impl $name {
@ -417,9 +420,9 @@ macro_rules! base_clock {
impl Sealed for $name {} 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 value.frequency
} }
} }

View file

@ -14,7 +14,7 @@
//! //!
//! ## Usage extended //! ## Usage extended
//! ```no_run //! ```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}; //! 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> { //! # fn func() -> Result<(), InitError> {
@ -72,7 +72,8 @@ use crate::{
xosc::{setup_xosc_blocking, CrystalOscillator, Error as XoscError, Stable}, xosc::{setup_xosc_blocking, CrystalOscillator, Error as XoscError, Stable},
}; };
use core::{convert::Infallible, marker::PhantomData}; 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}; use pac::{CLOCKS, PLL_SYS, PLL_USB, RESETS, XOSC};
#[macro_use] #[macro_use]
@ -117,13 +118,13 @@ pub trait Clock: Sealed + Sized {
type Variant; type Variant;
/// Get operating frequency /// Get operating frequency
fn freq(&self) -> Hertz; fn freq(&self) -> HertzU32;
/// Configure this clock based on a clock source and desired frequency /// Configure this clock based on a clock source and desired frequency
fn configure_clock<S: ValidSrc<Self>>( fn configure_clock<S: ValidSrc<Self>>(
&mut self, &mut self,
src: &S, src: &S,
freq: Hertz, freq: HertzU32,
) -> Result<(), ClockError>; ) -> Result<(), ClockError>;
} }
@ -170,7 +171,7 @@ pub trait ClockSource: Sealed {
/// Get the operating frequency for this source /// Get the operating frequency for this source
/// ///
/// Used to determine the divisor /// 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 /// 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( let pll_sys = setup_pll_blocking(
pll_sys_dev, pll_sys_dev,
xosc.operating_frequency().into(), xosc.operating_frequency(),
PLL_SYS_125MHZ, PLL_SYS_125MHZ,
&mut clocks, &mut clocks,
resets, resets,
@ -344,7 +345,7 @@ pub fn init_clocks_and_plls(
.map_err(InitError::PllError)?; .map_err(InitError::PllError)?;
let pll_usb = setup_pll_blocking( let pll_usb = setup_pll_blocking(
pll_usb_dev, pll_usb_dev,
xosc.operating_frequency().into(), xosc.operating_frequency(),
PLL_USB_48MHZ, PLL_USB_48MHZ,
&mut clocks, &mut clocks,
resets, resets,

View file

@ -4,7 +4,7 @@
//! //!
//! ## Usage //! ## Usage
//! ```no_run //! ```no_run
//! use embedded_time::rate::Extensions; //! use fugit::RateExtU32;
//! use rp2040_hal::{i2c::I2C, gpio::Pins, pac, Sio}; //! use rp2040_hal::{i2c::I2C, gpio::Pins, pac, Sio};
//! let mut peripherals = pac::Peripherals::take().unwrap(); //! let mut peripherals = pac::Peripherals::take().unwrap();
//! let sio = Sio::new(peripherals.SIO); //! let sio = Sio::new(peripherals.SIO);
@ -55,7 +55,7 @@ use crate::{
resets::SubsystemReset, resets::SubsystemReset,
typelevel::Sealed, typelevel::Sealed,
}; };
use embedded_time::rate::Hertz; use fugit::HertzU32;
use pac::{i2c0::RegisterBlock as I2CBlock, I2C0, I2C1, RESETS}; use pac::{i2c0::RegisterBlock as I2CBlock, I2C0, I2C1, RESETS};
/// Controller implementaion /// Controller implementaion
@ -294,12 +294,12 @@ macro_rules! hal {
resets: &mut RESETS, resets: &mut RESETS,
system_clock: SystemF) -> Self system_clock: SystemF) -> Self
where where
F: Into<Hertz<u64>>, F: Into<HertzU32>,
Sda: SdaPin<$I2CX>, Sda: SdaPin<$I2CX>,
Scl: SclPin<$I2CX>, Scl: SclPin<$I2CX>,
SystemF: Into<Hertz<u32>>, SystemF: Into<HertzU32>,
{ {
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())
} }
} }
)+ )+

View file

@ -5,7 +5,7 @@ use crate::{
gpio::pin::{FunctionI2C, Pin, PinId}, gpio::pin::{FunctionI2C, Pin, PinId},
resets::SubsystemReset, resets::SubsystemReset,
}; };
use embedded_time::rate::Hertz; use fugit::HertzU32;
use hal::blocking::i2c::{Read, Write, WriteRead}; use hal::blocking::i2c::{Read, Write, WriteRead};
use pac::{i2c0::RegisterBlock as Block, RESETS}; use pac::{i2c0::RegisterBlock as Block, RESETS};
@ -18,24 +18,21 @@ impl<T: SubsystemReset + Deref<Target = Block>, Sda: PinId + BankPinId, Scl: Pin
I2C<T, (Pin<Sda, FunctionI2C>, Pin<Scl, FunctionI2C>), Controller> I2C<T, (Pin<Sda, FunctionI2C>, Pin<Scl, FunctionI2C>), Controller>
{ {
/// Configures the I2C peripheral to work in controller mode /// Configures the I2C peripheral to work in controller mode
pub fn new_controller<F, SystemF>( pub fn new_controller(
i2c: T, i2c: T,
sda_pin: Pin<Sda, FunctionI2C>, sda_pin: Pin<Sda, FunctionI2C>,
scl_pin: Pin<Scl, FunctionI2C>, scl_pin: Pin<Scl, FunctionI2C>,
freq: F, freq: HertzU32,
resets: &mut RESETS, resets: &mut RESETS,
system_clock: SystemF, system_clock: HertzU32,
) -> Self ) -> Self
where where
F: Into<Hertz<u64>>,
Sda: SdaPin<T>, Sda: SdaPin<T>,
Scl: SclPin<T>, Scl: SclPin<T>,
SystemF: Into<Hertz<u32>>,
{ {
let freq = freq.into().0; let freq = freq.to_Hz();
assert!(freq <= 1_000_000); assert!(freq <= 1_000_000);
assert!(freq > 0); assert!(freq > 0);
let freq = freq as u32;
i2c.reset_bring_down(resets); i2c.reset_bring_down(resets);
i2c.reset_bring_up(resets); i2c.reset_bring_up(resets);
@ -55,7 +52,7 @@ impl<T: SubsystemReset + Deref<Target = Block>, Sda: PinId + BankPinId, Scl: Pin
i2c.ic_tx_tl.write(|w| unsafe { w.tx_tl().bits(0) }); i2c.ic_tx_tl.write(|w| unsafe { w.tx_tl().bits(0) });
i2c.ic_rx_tl.write(|w| unsafe { w.rx_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 // 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 // See: https://github.com/raspberrypi/pico-sdk/blob/bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7/src/rp2_common/hardware_i2c/i2c.c#L69

View file

@ -2,15 +2,12 @@
// See [Chapter 2 Section 18](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details // See [Chapter 2 Section 18](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
use core::{ use core::{
convert::{Infallible, TryFrom, TryInto}, convert::{Infallible, TryInto},
marker::PhantomData, marker::PhantomData,
ops::{Deref, Range, RangeInclusive}, ops::{Deref, Range, RangeInclusive},
}; };
use embedded_time::{ use fugit::{HertzU32, RateExtU32};
fixed_point::FixedPoint,
rate::{Generic, Hertz, Rate},
};
use nb::Error::WouldBlock; use nb::Error::WouldBlock;
use pac::RESETS; use pac::RESETS;
@ -26,19 +23,19 @@ pub struct Disabled {
fbdiv: u16, fbdiv: u16,
post_div1: u8, post_div1: u8,
post_div2: u8, post_div2: u8,
frequency: Hertz, frequency: HertzU32,
} }
/// PLL is configured, started and locking into its designated frequency. /// PLL is configured, started and locking into its designated frequency.
pub struct Locking { pub struct Locking {
post_div1: u8, post_div1: u8,
post_div2: u8, post_div2: u8,
frequency: Hertz, frequency: HertzU32,
} }
/// PLL is locked : it delivers a steady frequency. /// PLL is locked : it delivers a steady frequency.
pub struct Locked { pub struct Locked {
frequency: Hertz, frequency: HertzU32,
} }
impl State for Disabled {} impl State for Disabled {}
@ -94,9 +91,9 @@ pub enum Error {
} }
/// Parameters for a PLL. /// Parameters for a PLL.
pub struct PLLConfig<R: Rate> { pub struct PLLConfig {
/// Voltage Controlled Oscillator frequency. /// Voltage Controlled Oscillator frequency.
pub vco_freq: R, pub vco_freq: HertzU32,
/// Reference divider /// Reference divider
pub refdiv: u8, pub refdiv: u8,
@ -112,19 +109,19 @@ pub struct PLLConfig<R: Rate> {
/// See Chapter 2, Section 18, §2 /// See Chapter 2, Section 18, §2
pub mod common_configs { pub mod common_configs {
use super::PLLConfig; use super::PLLConfig;
use embedded_time::rate::Megahertz; use fugit::HertzU32;
/// Default, nominal configuration for PLL_SYS /// Default, nominal configuration for PLL_SYS
pub const PLL_SYS_125MHZ: PLLConfig<Megahertz> = PLLConfig { pub const PLL_SYS_125MHZ: PLLConfig = PLLConfig {
vco_freq: Megahertz(1500), vco_freq: HertzU32::MHz(1500),
refdiv: 1, refdiv: 1,
post_div1: 6, post_div1: 6,
post_div2: 2, post_div2: 2,
}; };
/// Default, nominal configuration for PLL_USB. /// Default, nominal configuration for PLL_USB.
pub const PLL_USB_48MHZ: PLLConfig<Megahertz> = PLLConfig { pub const PLL_USB_48MHZ: PLLConfig = PLLConfig {
vco_freq: Megahertz(480), vco_freq: HertzU32::MHz(480),
refdiv: 1, refdiv: 1,
post_div1: 5, post_div1: 5,
post_div2: 2, post_div2: 2,
@ -133,24 +130,16 @@ pub mod common_configs {
impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> { impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
/// Instantiates a new Phase-Locked-Loop device. /// Instantiates a new Phase-Locked-Loop device.
pub fn new<R: Rate>( pub fn new(
dev: D, dev: D,
xosc_frequency: Generic<u32>, xosc_frequency: HertzU32,
config: PLLConfig<R>, config: PLLConfig,
) -> Result<PhaseLockedLoop<Disabled, D>, Error> ) -> Result<PhaseLockedLoop<Disabled, D>, Error> {
where const VCO_FREQ_RANGE: RangeInclusive<HertzU32> = HertzU32::MHz(400)..=HertzU32::MHz(1_600);
R: Into<Hertz<u64>>,
{
const VCO_FREQ_RANGE: RangeInclusive<Hertz<u32>> =
Hertz(400_000_000)..=Hertz(1_600_000_000);
const POSTDIV_RANGE: Range<u8> = 1..7; const POSTDIV_RANGE: Range<u8> = 1..7;
const FBDIV_RANGE: Range<u16> = 16..320; const FBDIV_RANGE: Range<u16> = 16..320;
//First we convert our rate to Hertz<u64> as all other rates can be converted to that. let vco_freq = config.vco_freq;
let vco_freq: Hertz<u64> = config.vco_freq.into();
//Then we try to downscale to u32.
let vco_freq: Hertz<u32> = vco_freq.try_into().map_err(|_| Error::BadArgument)?;
if !VCO_FREQ_RANGE.contains(&vco_freq) { if !VCO_FREQ_RANGE.contains(&vco_freq) {
return Err(Error::VcoFreqOutOfRange); return Err(Error::VcoFreqOutOfRange);
@ -161,24 +150,25 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
return Err(Error::PostDivOutOfRage); return Err(Error::PostDivOutOfRage);
} }
let ref_freq_range: Range<Hertz<u32>> = 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> = HertzU32::MHz(5)..ref_freq_max_vco;
let ref_freq_hz = Hertz::<u32>::try_from(xosc_frequency) let ref_freq_hz: HertzU32 = xosc_frequency
.map_err(|_| Error::BadArgument)? .to_Hz()
.checked_div(&(config.refdiv as u32)) .checked_div(u32::from(config.refdiv))
.ok_or(Error::BadArgument)?; .ok_or(Error::BadArgument)?
.Hz();
if !ref_freq_range.contains(&ref_freq_hz) { if !ref_freq_range.contains(&ref_freq_hz) {
return Err(Error::RefFreqOutOfRange); return Err(Error::RefFreqOutOfRange);
} }
let fbdiv = vco_freq let fbdiv = vco_freq
.checked_div(&ref_freq_hz.integer()) .to_Hz()
.checked_div(ref_freq_hz.to_Hz())
.ok_or(Error::BadArgument)?; .ok_or(Error::BadArgument)?;
let fbdiv: u16 = (fbdiv.integer()) let fbdiv: u16 = fbdiv.try_into().map_err(|_| Error::BadArgument)?;
.try_into()
.map_err(|_| Error::BadArgument)?;
if !FBDIV_RANGE.contains(&fbdiv) { if !FBDIV_RANGE.contains(&fbdiv) {
return Err(Error::FeedbackDivOutOfRange); return Err(Error::FeedbackDivOutOfRange);
@ -187,8 +177,8 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
let refdiv = config.refdiv; let refdiv = config.refdiv;
let post_div1 = config.post_div1; let post_div1 = config.post_div1;
let post_div2 = config.post_div2; let post_div2 = config.post_div2;
let frequency: Hertz = let frequency: HertzU32 = ((ref_freq_hz / u32::from(refdiv)) * u32::from(fbdiv))
(ref_freq_hz / refdiv as u32) * fbdiv as u32 / (post_div1 as u32 * post_div2 as u32); / (u32::from(post_div1) * u32::from(post_div2));
Ok(PhaseLockedLoop { Ok(PhaseLockedLoop {
state: Disabled { state: Disabled {
@ -279,28 +269,26 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Locking, D> {
impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Locked, D> { impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Locked, D> {
/// Get the operating frequency for the PLL /// Get the operating frequency for the PLL
pub fn operating_frequency(&self) -> Hertz { pub fn operating_frequency(&self) -> HertzU32 {
self.state.frequency self.state.frequency
} }
} }
/// Blocking helper method to setup the PLL without going through all the steps. /// Blocking helper method to setup the PLL without going through all the steps.
pub fn setup_pll_blocking<D: PhaseLockedLoopDevice, R: Rate>( pub fn setup_pll_blocking<D: PhaseLockedLoopDevice>(
dev: D, dev: D,
xosc_frequency: Generic<u32>, xosc_frequency: HertzU32,
config: PLLConfig<R>, config: PLLConfig,
clocks: &mut ClocksManager, clocks: &mut ClocksManager,
resets: &mut RESETS, resets: &mut RESETS,
) -> Result<PhaseLockedLoop<Locked, D>, Error> ) -> Result<PhaseLockedLoop<Locked, D>, Error> {
where
R: Into<Hertz<u64>>,
{
// Before we touch PLLs, switch sys and ref cleanly away from their aux sources. // 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.system_clock.reset_source_await()).unwrap();
nb::block!(clocks.reference_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(); let locked_pll_token = nb::block!(initialized_pll.await_lock()).unwrap();

View file

@ -1,8 +1,7 @@
//! Ring Oscillator (ROSC) //! Ring Oscillator (ROSC)
// See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details // See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
use embedded_time::rate::Extensions; use fugit::HertzU32;
use embedded_time::rate::Hertz;
/// State of the Ring Oscillator (typestate trait) /// State of the Ring Oscillator (typestate trait)
pub trait State {} pub trait State {}
@ -12,7 +11,7 @@ pub struct Disabled;
/// ROSC is initialized, ie we've given parameters (typestate) /// ROSC is initialized, ie we've given parameters (typestate)
pub struct Enabled { pub struct Enabled {
freq_hz: Hertz, freq_hz: HertzU32,
} }
/// ROSC is in dormant mode (see Chapter 2, Section 17, §7) /// ROSC is in dormant mode (see Chapter 2, Section 17, §7)
@ -56,6 +55,7 @@ impl RingOscillator<Disabled> {
pub fn initialize(self) -> RingOscillator<Enabled> { pub fn initialize(self) -> RingOscillator<Enabled> {
self.device.ctrl.write(|w| w.enable().enable()); self.device.ctrl.write(|w| w.enable().enable());
use fugit::RateExtU32;
self.transition(Enabled { self.transition(Enabled {
freq_hz: 6_500_000u32.Hz(), freq_hz: 6_500_000u32.Hz(),
}) })
@ -64,7 +64,7 @@ impl RingOscillator<Disabled> {
impl RingOscillator<Enabled> { impl RingOscillator<Enabled> {
/// Approx operating frequency of the ROSC in hertz /// Approx operating frequency of the ROSC in hertz
pub fn operating_frequency(&self) -> Hertz { pub fn operating_frequency(&self) -> HertzU32 {
self.state.freq_hz self.state.freq_hz
} }

View file

@ -23,7 +23,6 @@
use crate::clocks::Clock; use crate::clocks::Clock;
use crate::clocks::RtcClock; use crate::clocks::RtcClock;
use embedded_time::fixed_point::FixedPoint;
use rp2040_pac::{RESETS, RTC}; use rp2040_pac::{RESETS, RTC};
mod filter; mod filter;
@ -66,7 +65,7 @@ impl RealTimeClock {
} }
// Set the RTC divider // 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) }); rtc.clkdiv_m1.write(|w| unsafe { w.bits(freq) });
let mut result = Self { rtc }; let mut result = Self { rtc };

View file

@ -6,7 +6,7 @@
//! //!
//! ```no_run //! ```no_run
//! use embedded_hal::spi::MODE_0; //! use embedded_hal::spi::MODE_0;
//! use embedded_time::rate::*; //! use fugit::RateExtU32;
//! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio}; //! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio};
//! //!
//! let mut peripherals = pac::Peripherals::take().unwrap(); //! 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 eh1_0_alpha::spi as eh1;
use embedded_hal::blocking::spi; use embedded_hal::blocking::spi;
use embedded_hal::spi::{FullDuplex, Mode, Phase, Polarity}; use embedded_hal::spi::{FullDuplex, Mode, Phase, Polarity};
use embedded_time::rate::*; use fugit::HertzU32;
use pac::RESETS; use pac::RESETS;
/// State of the SPI /// State of the SPI
@ -78,13 +78,13 @@ impl<S: State, D: SpiDevice, const DS: u8> Spi<S, D, DS> {
/// Set baudrate based on peripheral clock /// Set baudrate based on peripheral clock
/// ///
/// Typically the peripheral clock is set to 125_000_000 /// Typically the peripheral clock is set to 125_000_000
pub fn set_baudrate<F: Into<Hertz<u32>>, B: Into<Hertz<u32>>>( pub fn set_baudrate<F: Into<HertzU32>, B: Into<HertzU32>>(
&mut self, &mut self,
peri_frequency: F, peri_frequency: F,
baudrate: B, baudrate: B,
) -> Hertz { ) -> HertzU32 {
let freq_in = peri_frequency.into().integer(); let freq_in = peri_frequency.into().to_Hz();
let baudrate = baudrate.into().integer(); let baudrate = baudrate.into().to_Hz();
let mut prescale: u8 = u8::MAX; let mut prescale: u8 = u8::MAX;
let mut postdiv: u8 = 0; let mut postdiv: u8 = 0;
@ -120,6 +120,7 @@ impl<S: State, D: SpiDevice, const DS: u8> Spi<S, D, DS> {
.modify(|_, w| unsafe { w.scr().bits(postdiv) }); .modify(|_, w| unsafe { w.scr().bits(postdiv) });
// Return the frequency we were able to achieve // Return the frequency we were able to achieve
use fugit::RateExtU32;
(freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz() (freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz()
} }
} }
@ -146,7 +147,7 @@ impl<D: SpiDevice, const DS: u8> Spi<Disabled, D, DS> {
} }
/// Initialize the SPI /// Initialize the SPI
pub fn init<F: Into<Hertz<u32>>, B: Into<Hertz<u32>>>( pub fn init<F: Into<HertzU32>, B: Into<HertzU32>>(
mut self, mut self,
resets: &mut RESETS, resets: &mut RESETS,
peri_frequency: F, peri_frequency: F,

View file

@ -8,7 +8,7 @@
//! //!
//! See [Chapter 4 Section 6](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) of the datasheet for more details. //! 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::atomic_register_access::{write_bitmask_clear, write_bitmask_set};
use crate::pac::{RESETS, TIMER}; use crate::pac::{RESETS, TIMER};
@ -53,7 +53,7 @@ impl Timer {
pub fn count_down(&self) -> CountDown<'_> { pub fn count_down(&self) -> CountDown<'_> {
CountDown { CountDown {
timer: self, timer: self,
period: Microseconds::new(0), period: MicrosDurationU64::nanos(0),
next_end: None, next_end: None,
} }
} }
@ -104,43 +104,47 @@ impl Timer {
/// ## Usage /// ## Usage
/// ```no_run /// ```no_run
/// use embedded_hal::timer::{CountDown, Cancel}; /// use embedded_hal::timer::{CountDown, Cancel};
/// use embedded_time::duration::Extensions; /// use fugit::ExtU32;
/// use rp2040_hal; /// use rp2040_hal;
/// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap(); /// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap();
/// // Configure the Timer peripheral in count-down mode /// // Configure the Timer peripheral in count-down mode
/// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS); /// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS);
/// let mut count_down = timer.count_down(); /// let mut count_down = timer.count_down();
/// // Create a count_down timer for 500 milliseconds /// // Create a count_down timer for 500 milliseconds
/// count_down.start(500.milliseconds()); /// count_down.start(500.millis());
/// // Block until timer has elapsed /// // Block until timer has elapsed
/// let _ = nb::block!(count_down.wait()); /// let _ = nb::block!(count_down.wait());
/// // Restart the count_down timer with a period of 100 milliseconds /// // Restart the count_down timer with a period of 100 milliseconds
/// count_down.start(100.milliseconds()); /// count_down.start(100.millis());
/// // Cancel it immediately /// // Cancel it immediately
/// count_down.cancel(); /// count_down.cancel();
/// ``` /// ```
pub struct CountDown<'timer> { pub struct CountDown<'timer> {
timer: &'timer Timer, timer: &'timer Timer,
period: embedded_time::duration::Microseconds<u64>, period: MicrosDurationU64,
next_end: Option<u64>, next_end: Option<u64>,
} }
impl embedded_hal::timer::CountDown for CountDown<'_> { impl embedded_hal::timer::CountDown for CountDown<'_> {
type Time = embedded_time::duration::Microseconds<u64>; type Time = MicrosDurationU64;
fn start<T>(&mut self, count: T) fn start<T>(&mut self, count: T)
where where
T: Into<Self::Time>, T: Into<Self::Time>,
{ {
self.period = count.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> { fn wait(&mut self) -> nb::Result<(), void::Void> {
if let Some(end) = self.next_end { if let Some(end) = self.next_end {
let ts = self.timer.get_counter(); let ts = self.timer.get_counter();
if ts >= end { 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(()) Ok(())
} else { } else {
Err(nb::Error::WouldBlock) Err(nb::Error::WouldBlock)
@ -187,12 +191,12 @@ pub trait Alarm {
/// this will trigger interrupt whenever this time elapses. /// this will trigger interrupt whenever this time elapses.
/// ///
/// The RP2040 has been observed to take a little while to schedule an alarm. For this /// 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 /// [enable_interrupt]: #method.enable_interrupt
fn schedule<TIME: Into<Microseconds>>( fn schedule<const NOM: u32, const DENOM: u32>(
&mut self, &mut self,
countdown: TIME, countdown: Duration<u32, NOM, DENOM>,
) -> Result<(), ScheduleAlarmError>; ) -> Result<(), ScheduleAlarmError>;
/// Return true if this alarm is finished. /// Return true if this alarm is finished.
@ -255,14 +259,14 @@ macro_rules! impl_alarm {
#[doc = $int_name] #[doc = $int_name]
/// ` whenever this time elapses. /// ` 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 /// [enable_interrupt]: #method.enable_interrupt
fn schedule<TIME: Into<Microseconds>>( fn schedule<const NOM: u32, const DENOM: u32>(
&mut self, &mut self,
countdown: TIME, countdown: Duration<u32, NOM, DENOM>,
) -> Result<(), ScheduleAlarmError> { ) -> Result<(), ScheduleAlarmError> {
let duration = countdown.into().0; let duration = countdown.to_micros();
const MIN_MICROSECONDS: u32 = 10; const MIN_MICROSECONDS: u32 = 10;
if duration < MIN_MICROSECONDS { if duration < MIN_MICROSECONDS {

View file

@ -1,9 +1,10 @@
use fugit::HertzU32;
use super::{DataBits, StopBits, UartConfig}; use super::{DataBits, StopBits, UartConfig};
use embedded_time::rate::Baud;
/// 9600 baud, 8 data bits, no parity, 1 stop bit /// 9600 baud, 8 data bits, no parity, 1 stop bit
pub const _9600_8_N_1: UartConfig = UartConfig { pub const _9600_8_N_1: UartConfig = UartConfig {
baudrate: Baud(9600), baudrate: HertzU32::from_raw(9600),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,
@ -11,7 +12,7 @@ pub const _9600_8_N_1: UartConfig = UartConfig {
/// 19200 baud, 8 data bits, no parity, 1 stop bit /// 19200 baud, 8 data bits, no parity, 1 stop bit
pub const _19200_8_N_1: UartConfig = UartConfig { pub const _19200_8_N_1: UartConfig = UartConfig {
baudrate: Baud(19200), baudrate: HertzU32::from_raw(19200),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,
@ -19,7 +20,7 @@ pub const _19200_8_N_1: UartConfig = UartConfig {
/// 38400 baud, 8 data bits, no parity, 1 stop bit /// 38400 baud, 8 data bits, no parity, 1 stop bit
pub const _38400_8_N_1: UartConfig = UartConfig { pub const _38400_8_N_1: UartConfig = UartConfig {
baudrate: Baud(38400), baudrate: HertzU32::from_raw(38400),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,
@ -27,7 +28,7 @@ pub const _38400_8_N_1: UartConfig = UartConfig {
/// 57600 baud, 8 data bits, no parity, 1 stop bit /// 57600 baud, 8 data bits, no parity, 1 stop bit
pub const _57600_8_N_1: UartConfig = UartConfig { pub const _57600_8_N_1: UartConfig = UartConfig {
baudrate: Baud(57600), baudrate: HertzU32::from_raw(57600),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,
@ -35,7 +36,7 @@ pub const _57600_8_N_1: UartConfig = UartConfig {
/// 115200 baud, 8 data bits, no parity, 1 stop bit /// 115200 baud, 8 data bits, no parity, 1 stop bit
pub const _115200_8_N_1: UartConfig = UartConfig { pub const _115200_8_N_1: UartConfig = UartConfig {
baudrate: Baud(115200), baudrate: HertzU32::from_raw(115200),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,

View file

@ -8,9 +8,7 @@ use crate::pac::uart0::uartlcr_h::W as UART_LCR_H_Writer;
use core::convert::Infallible; use core::convert::Infallible;
use core::fmt; use core::fmt;
use embedded_hal::serial::{Read, Write}; use embedded_hal::serial::{Read, Write};
use embedded_time::fixed_point::FixedPoint; use fugit::HertzU32;
use embedded_time::rate::Baud;
use embedded_time::rate::Hertz;
use nb::Error::{Other, WouldBlock}; use nb::Error::{Other, WouldBlock};
use rp2040_pac::{UART0, UART1}; use rp2040_pac::{UART0, UART1};
@ -57,10 +55,10 @@ impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Disabled, D, P> {
pub fn enable( pub fn enable(
self, self,
config: UartConfig, config: UartConfig,
frequency: Hertz, frequency: HertzU32,
) -> Result<UartPeripheral<Enabled, D, P>, Error> { ) -> Result<UartPeripheral<Enabled, D, P>, Error> {
let (mut device, pins) = self.free(); 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| { device.uartlcr_h.write(|w| {
// FIFOs are enabled // FIFOs are enabled
@ -229,15 +227,15 @@ impl<P: ValidUartPinout<UART1>> UartPeripheral<Enabled, UART1, P> {
/// From the wanted baudrate, we calculate the divider's two parts: integer and fractional parts. /// From the wanted baudrate, we calculate the divider's two parts: integer and fractional parts.
/// Code inspired from the C SDK. /// Code inspired from the C SDK.
fn calculate_baudrate_dividers( fn calculate_baudrate_dividers(
wanted_baudrate: &Baud, wanted_baudrate: HertzU32,
frequency: &Hertz, frequency: HertzU32,
) -> Result<(u16, u16), Error> { ) -> Result<(u16, u16), Error> {
// See Chapter 4, Section 2 §7.1 from the datasheet for an explanation of how baudrate is // See Chapter 4, Section 2 §7.1 from the datasheet for an explanation of how baudrate is
// calculated // calculated
let baudrate_div = frequency let baudrate_div = frequency
.integer() .to_Hz()
.checked_mul(8) .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_or(Error::BadArgument)?;
Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) { 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. /// Baudrate configuration. Code loosely inspired from the C SDK.
fn configure_baudrate( fn configure_baudrate(
device: &mut dyn UartDevice, device: &mut dyn UartDevice,
wanted_baudrate: &Baud, wanted_baudrate: HertzU32,
frequency: &Hertz, frequency: HertzU32,
) -> Result<Baud, Error> { ) -> Result<HertzU32, Error> {
let (baud_div_int, baud_div_frac) = calculate_baudrate_dividers(wanted_baudrate, frequency)?; let (baud_div_int, baud_div_frac) = calculate_baudrate_dividers(wanted_baudrate, frequency)?;
// First we load the integer part of the divider. // 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. // divisors. We don't want to actually change LCR contents here.
device.uartlcr_h.modify(|_, w| w); device.uartlcr_h.modify(|_, w| w);
Ok(Baud( Ok(HertzU32::from_raw(
(4 * frequency.integer()) / (64 * baud_div_int + baud_div_frac) as u32, (4 * frequency.to_Hz()) / (64 * baud_div_int + baud_div_frac) as u32,
)) ))
} }

View file

@ -1,7 +1,8 @@
use fugit::HertzU32;
use crate::pac::{uart0::RegisterBlock, UART0, UART1}; use crate::pac::{uart0::RegisterBlock, UART0, UART1};
use crate::resets::SubsystemReset; use crate::resets::SubsystemReset;
use core::ops::Deref; use core::ops::Deref;
use embedded_time::rate::Baud;
/// Error type for UART operations. /// Error type for UART operations.
#[derive(Debug)] #[derive(Debug)]
@ -73,7 +74,7 @@ pub enum Parity {
#[non_exhaustive] #[non_exhaustive]
pub struct UartConfig { pub struct UartConfig {
/// The baudrate the uart will run at. /// The baudrate the uart will run at.
pub baudrate: Baud, pub baudrate: HertzU32,
/// The amount of data bits the uart should be configured to. /// The amount of data bits the uart should be configured to.
pub data_bits: DataBits, pub data_bits: DataBits,
@ -88,7 +89,7 @@ pub struct UartConfig {
impl Default for UartConfig { impl Default for UartConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
baudrate: Baud(115_200), baudrate: HertzU32::from_raw(115_200),
data_bits: DataBits::Eight, data_bits: DataBits::Eight,
stop_bits: StopBits::One, stop_bits: StopBits::One,
parity: None, parity: None,

Some files were not shown because too many files have changed in this diff Show more