mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 12:41:31 +11:00
migrate rp2040-hal from embedded_time to fugit
This commit is contained in:
parent
6a29b3bb73
commit
93ec18be07
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
fugit = "0.3.5"
|
||||
nb = "1.0.0"
|
||||
smart-leds = "0.3.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
|
|
|
@ -15,7 +15,6 @@ use adafruit_feather_rp2040::{
|
|||
Pins, XOSC_CRYSTAL_FREQ,
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::rate::*;
|
||||
use panic_halt as _;
|
||||
|
||||
#[entry]
|
||||
|
@ -37,7 +36,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let sio = Sio::new(pac.SIO);
|
||||
let pins = Pins::new(
|
||||
|
|
|
@ -20,7 +20,7 @@ use adafruit_feather_rp2040::{
|
|||
};
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
use ws2812_pio::Ws2812;
|
||||
|
@ -71,7 +71,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
panic-halt= "0.2.0"
|
||||
|
@ -23,6 +22,7 @@ embedded-hal ="0.2.5"
|
|||
smart-leds = "0.3"
|
||||
nb = "1.0.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["rt", "boot2"]
|
||||
|
|
|
@ -18,7 +18,6 @@ use panic_halt as _;
|
|||
|
||||
// Some traits we need
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
|
||||
use adafruit_itsy_bitsy_rp2040::{
|
||||
hal::{
|
||||
|
@ -61,7 +60,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = Sio::new(pac.SIO);
|
||||
|
|
|
@ -6,7 +6,7 @@ use adafruit_itsy_bitsy_rp2040::entry;
|
|||
use core::iter::once;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
use ws2812_pio::Ws2812;
|
||||
|
@ -72,7 +72,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ rt = ["cortex-m-rt","rp2040-hal/rt"]
|
|||
panic-halt = "0.2.0"
|
||||
rp2040-boot2 = "0.2"
|
||||
smart-leds = "0.3.0"
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
nb = "1.0.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use adafruit_kb2040::entry;
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
|
||||
use adafruit_kb2040::{
|
||||
|
@ -84,7 +84,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
embedded-time = "0.12.0"
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ use adafruit_macropad::{
|
|||
Pins, XOSC_CRYSTAL_FREQ,
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::rate::*;
|
||||
use panic_halt as _;
|
||||
|
||||
/// Entry point to our bare-metal application.
|
||||
|
@ -40,7 +39,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let sio = Sio::new(pac.SIO);
|
||||
let pins = Pins::new(
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ repository = "https://github.com/rp-rs/rp-hal.git"
|
|||
cortex-m = "0.7.2"
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -23,6 +22,7 @@ embedded-hal ="0.2.5"
|
|||
smart-leds = "0.3"
|
||||
nb = "1.0.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["boot2", "rt"]
|
||||
|
|
|
@ -6,7 +6,7 @@ use adafruit_qt_py_rp2040::entry;
|
|||
use core::iter::once;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
use ws2812_pio::Ws2812;
|
||||
|
@ -72,7 +72,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25u32.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
13
boards/adafruit-trinkey-qt2040/CHANGELOG.md
Normal file
13
boards/adafruit-trinkey-qt2040/CHANGELOG.md
Normal 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`
|
||||
|
|
@ -18,10 +18,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
|
|||
[dev-dependencies]
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
embedded-time = "0.12.0"
|
||||
smart-leds = "0.3"
|
||||
nb = "1.0.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["boot2", "rt"]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
use adafruit_trinkey_qt2040::entry;
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
|
||||
use adafruit_trinkey_qt2040::{
|
||||
|
@ -84,7 +84,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
|
|
|
@ -17,12 +17,12 @@ rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
|||
cortex-m-rt = { version = "0.7.0", optional = true }
|
||||
embedded-hal = { version = "0.2.4", features = ["unproven"] }
|
||||
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
|
||||
embedded-time = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
nb = "1.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["boot2", "rt"]
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
#![no_main]
|
||||
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
// // Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
|
@ -64,7 +62,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0"}
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
embedded-hal ="0.2.5"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -28,7 +28,7 @@ use pimoroni_badger2040::hal;
|
|||
|
||||
// A few traits required for using the CountDown timer
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -75,12 +75,12 @@ fn main() -> ! {
|
|||
loop {
|
||||
// LED on, and wait for 500ms
|
||||
led_pin.set_high().unwrap();
|
||||
delay.start(500.milliseconds());
|
||||
delay.start(500.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
|
||||
// LED off, and wait for 500ms
|
||||
led_pin.set_low().unwrap();
|
||||
delay.start(500.milliseconds());
|
||||
delay.start(500.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true }
|
|||
embedded-hal = { version = "0.2.4", features = ["unproven"] }
|
||||
st7789 = "0.6.1"
|
||||
display-interface-spi = "0.4.1"
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
embedded-graphics = "0.7.1"
|
||||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ use embedded_graphics::{
|
|||
text::{Alignment, Text},
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::rate::*;
|
||||
use hal::{adc::Adc, clocks::*, watchdog::Watchdog, Sio};
|
||||
use panic_halt as _;
|
||||
use pimoroni_pico_explorer::entry;
|
||||
|
@ -41,7 +40,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(cp.SYST, clocks.system_clock.get_freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(cp.SYST, clocks.system_clock.get_freq().to_Hz());
|
||||
|
||||
// Enable adc
|
||||
let mut adc = Adc::new(p.ADC, &mut p.RESETS);
|
||||
|
|
|
@ -30,7 +30,7 @@ use embedded_hal::{
|
|||
digital::v2::{InputPin, OutputPin},
|
||||
spi::MODE_0,
|
||||
};
|
||||
use embedded_time::rate::*;
|
||||
use fugit::RateExtU32;
|
||||
pub use hal::pac;
|
||||
use hal::{
|
||||
adc::Adc,
|
||||
|
@ -211,12 +211,7 @@ impl PicoExplorer {
|
|||
let spi_sclk = internal_pins.spi_sclk.into_mode::<FunctionSpi>();
|
||||
let spi_mosi = internal_pins.spi_mosi.into_mode::<FunctionSpi>();
|
||||
|
||||
let spi_screen = Spi::<_, _, 8>::new(spi0).init(
|
||||
resets,
|
||||
125_000_000u32.Hz(),
|
||||
16_000_000u32.Hz(),
|
||||
&MODE_0,
|
||||
);
|
||||
let spi_screen = Spi::<_, _, 8>::new(spi0).init(resets, 125u32.MHz(), 16u32.MHz(), &MODE_0);
|
||||
|
||||
let spii_screen = SPIInterface::new(spi_screen, dc, cs);
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ cortex-m-rt = { version = "0.7", optional = true }
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
embedded-time = "0.12.0"
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
nb = "1.0"
|
||||
|
|
|
@ -16,9 +16,6 @@ use pimoroni_pico_lipo_16mb::entry;
|
|||
// GPIO traits
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -67,7 +64,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -10,4 +10,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] }
|
||||
|
@ -23,6 +22,7 @@ panic-halt= "0.2.0"
|
|||
embedded-hal ="0.2.5"
|
||||
smart-leds = "0.3.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
defmt = "0.3.0"
|
||||
defmt-rtt = "0.3.0"
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use defmt::*;
|
||||
use defmt_rtt as _;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use panic_halt as _;
|
||||
|
||||
use pimoroni_plasma_2040 as bsp;
|
||||
|
@ -41,7 +40,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let pins = bsp::Pins::new(
|
||||
pac.IO_BANK0,
|
||||
|
|
|
@ -13,9 +13,6 @@ use panic_halt as _;
|
|||
// Pull in any important traits
|
||||
use pimoroni_plasma_2040::hal::prelude::*;
|
||||
|
||||
// Embed the `Hz` function/trait:
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
// register access
|
||||
use pimoroni_plasma_2040::hal::pac;
|
||||
|
@ -82,7 +79,7 @@ fn main() -> ! {
|
|||
|
||||
// Setup a delay for the LED blink signals:
|
||||
let mut frame_delay =
|
||||
cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Import the `sin` function for a smooth hue animation from the
|
||||
// Pico rp2040 ROM:
|
||||
|
|
13
boards/pimoroni-tiny2040/CHANGELOG.md
Normal file
13
boards/pimoroni-tiny2040/CHANGELOG.md
Normal 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`
|
||||
|
|
@ -15,12 +15,12 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
|
||||
[dev-dependencies]
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0", features = [ "defmt" ] }
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
fugit = "0.3.5"
|
||||
|
||||
defmt = "0.3.0"
|
||||
defmt-rtt = "0.3.0"
|
||||
|
|
|
@ -6,7 +6,6 @@ use bsp::entry;
|
|||
use defmt::*;
|
||||
use defmt_rtt as _;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use panic_halt as _;
|
||||
|
||||
use pimoroni_tiny2040 as bsp;
|
||||
|
@ -38,7 +37,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let pins = bsp::Pins::new(
|
||||
pac.IO_BANK0,
|
||||
|
|
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.4.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
usb-device= "0.2.9"
|
||||
usbd-serial = "0.1.1"
|
||||
usbd-hid = "0.5.1"
|
||||
|
|
|
@ -16,9 +16,6 @@ use rp_pico::entry;
|
|||
// GPIO traits
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -67,7 +64,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -19,7 +19,7 @@ use cortex_m::prelude::*;
|
|||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
// Traits for converting integers to amounts of time
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
|
@ -77,12 +77,12 @@ fn main() -> ! {
|
|||
loop {
|
||||
// LED on, and wait for 500ms
|
||||
led_pin.set_high().unwrap();
|
||||
count_down.start(500.milliseconds());
|
||||
count_down.start(500.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
|
||||
// LED off, and wait for 500ms
|
||||
led_pin.set_low().unwrap();
|
||||
count_down.start(500.milliseconds());
|
||||
count_down.start(500.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,6 @@ use rp_pico::hal::prelude::*;
|
|||
// GPIO traits
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// For LCD display
|
||||
use hd44780_driver::HD44780;
|
||||
|
||||
|
@ -95,7 +92,7 @@ fn main() -> ! {
|
|||
let mut led_pin = pins.led.into_push_pull_output();
|
||||
|
||||
// The delay object lets us wait for specified amounts of time
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Init pins
|
||||
let rs = pins.gpio7.into_push_pull_output();
|
||||
|
|
|
@ -48,8 +48,7 @@ use core::fmt::Write;
|
|||
use rp_pico::entry;
|
||||
|
||||
// Time handling traits:
|
||||
use embedded_time::duration::*;
|
||||
use embedded_time::rate::Extensions;
|
||||
use fugit::{ExtU32, RateExtU32};
|
||||
|
||||
// CountDown timer for the counter on the display:
|
||||
use embedded_hal::timer::CountDown;
|
||||
|
@ -182,7 +181,7 @@ fn main() -> ! {
|
|||
display.flush().unwrap();
|
||||
|
||||
// Wait a bit:
|
||||
delay.start(500.milliseconds());
|
||||
delay.start(500.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ use rp_pico::entry;
|
|||
use embedded_hal::blocking::i2c::{Operation, Read, Transactional, Write};
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
use fugit::RateExtU32;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
|
@ -109,7 +109,7 @@ fn main() -> ! {
|
|||
pins.gpio20,
|
||||
pins.gpio21,
|
||||
sm0,
|
||||
100_000.Hz(),
|
||||
100.kHz(),
|
||||
clocks.system_clock.freq(),
|
||||
);
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@ use defmt_rtt as _;
|
|||
// The macro for our start-up function
|
||||
use rp_pico::entry;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -125,7 +122,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let (mut pio0, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS);
|
||||
|
||||
|
|
|
@ -16,9 +16,6 @@ use rp_pico::entry;
|
|||
// GPIO traits
|
||||
use embedded_hal::PwmPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -84,7 +81,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Init PWMs
|
||||
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
|
||||
|
|
|
@ -15,7 +15,7 @@ use cortex_m::prelude::*;
|
|||
use embedded_hal::PwmPin;
|
||||
|
||||
// Traits for converting integers to amounts of time
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
|
@ -93,22 +93,22 @@ fn main() -> ! {
|
|||
loop {
|
||||
// move to 0°
|
||||
channel.set_duty(2500);
|
||||
count_down.start(400.milliseconds());
|
||||
count_down.start(400.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
|
||||
// 0° to 90°
|
||||
channel.set_duty(3930);
|
||||
count_down.start(400.milliseconds());
|
||||
count_down.start(400.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
|
||||
// 90° to 180°
|
||||
channel.set_duty(7860);
|
||||
count_down.start(400.milliseconds());
|
||||
count_down.start(400.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
|
||||
// 180° to 90°
|
||||
channel.set_duty(3930);
|
||||
count_down.start(400.milliseconds());
|
||||
count_down.start(400.millis());
|
||||
let _ = nb::block!(count_down.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ use panic_halt as _;
|
|||
mod app {
|
||||
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::SecsDurationU32;
|
||||
use rp_pico::{
|
||||
hal::{self, clocks::init_clocks_and_plls, timer::Alarm, watchdog::Watchdog, Sio},
|
||||
XOSC_CRYSTAL_FREQ,
|
||||
};
|
||||
|
||||
const SCAN_TIME_US: u32 = 1000000;
|
||||
const SCAN_TIME_US: SecsDurationU32 = SecsDurationU32::secs(1);
|
||||
|
||||
#[shared]
|
||||
struct Shared {
|
||||
|
@ -58,7 +58,7 @@ mod app {
|
|||
|
||||
let mut timer = hal::Timer::new(c.device.TIMER, &mut resets);
|
||||
let mut alarm = timer.alarm_0().unwrap();
|
||||
let _ = alarm.schedule(SCAN_TIME_US.microseconds());
|
||||
let _ = alarm.schedule(SCAN_TIME_US);
|
||||
alarm.enable_interrupt();
|
||||
|
||||
(Shared { timer, alarm, led }, Local {}, init::Monotonics())
|
||||
|
@ -81,7 +81,7 @@ mod app {
|
|||
let mut alarm = c.shared.alarm;
|
||||
(alarm).lock(|a| {
|
||||
a.clear_interrupt();
|
||||
let _ = a.schedule(SCAN_TIME_US.microseconds());
|
||||
let _ = a.schedule(SCAN_TIME_US);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ use panic_halt as _;
|
|||
use rp_pico::hal::prelude::*;
|
||||
|
||||
// Embed the `Hz` function/trait:
|
||||
use embedded_time::rate::*;
|
||||
use fugit::RateExtU32;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
// register access
|
||||
|
@ -236,7 +236,7 @@ fn main() -> ! {
|
|||
let mut led_pin = pins.led.into_push_pull_output();
|
||||
|
||||
// Setup a delay for the LED blink signals:
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// These are implicitly used by the spi driver if they are in the correct mode
|
||||
let _spi_sclk = pins.gpio2.into_mode::<gpio::FunctionSpi>();
|
||||
|
|
|
@ -21,9 +21,6 @@
|
|||
// objects as generic embedded devices.
|
||||
use embedded_hal::{digital::v2::OutputPin, serial::Write as UartWrite};
|
||||
|
||||
// We need this for the 'Delay' object to work.
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
|
||||
// The writeln! trait.
|
||||
use core::fmt::Write;
|
||||
|
||||
|
@ -114,7 +111,7 @@ fn main() -> ! {
|
|||
.unwrap();
|
||||
|
||||
// Lets us wait for fixed periods of time
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -22,9 +22,6 @@ use embedded_hal::{
|
|||
serial::{Read, Write},
|
||||
};
|
||||
|
||||
// We need this for the 'Delay' object to work.
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
|
||||
// We also need this for the 'Delay' object to work.
|
||||
use rp2040_hal::Clock;
|
||||
|
||||
|
@ -98,7 +95,7 @@ fn main() -> ! {
|
|||
.unwrap();
|
||||
|
||||
// Lets us wait for fixed periods of time
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -21,9 +21,6 @@ use rp_pico::hal::pac::interrupt;
|
|||
// GPIO traits
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -131,7 +128,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -25,7 +25,6 @@ use rp_pico::hal::pac::interrupt;
|
|||
use panic_halt as _;
|
||||
|
||||
// Pull in any important traits
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp_pico::hal::prelude::*;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
|
@ -136,7 +135,7 @@ fn main() -> ! {
|
|||
pac::NVIC::unmask(hal::pac::Interrupt::USBCTRL_IRQ);
|
||||
};
|
||||
let core = pac::CorePeripherals::take().unwrap();
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Move the cursor up and down every 200ms
|
||||
loop {
|
||||
|
|
|
@ -50,9 +50,6 @@ use panic_halt as _;
|
|||
// Pull in any important traits
|
||||
use rp_pico::hal::prelude::*;
|
||||
|
||||
// Embed the `Hz` function/trait:
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
// register access
|
||||
use rp_pico::hal::pac;
|
||||
|
@ -115,7 +112,7 @@ fn main() -> ! {
|
|||
|
||||
// Setup a delay for the LED blink signals:
|
||||
let mut frame_delay =
|
||||
cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Import the `sin` function for a smooth hue animation from the
|
||||
// Pico rp2040 ROM:
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.1.0 - 2022-06-26
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ cortex-m-rt = { version = "0.7", optional = true }
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
panic-halt= "0.2.0"
|
||||
embedded-hal ="0.2.5"
|
||||
nb = "1.0"
|
||||
|
|
|
@ -17,9 +17,6 @@ use seeeduino_xiao_rp2040::entry;
|
|||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::PwmPin;
|
||||
|
||||
// Time handling traits
|
||||
use embedded_time::rate::*;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
// be linked)
|
||||
use panic_halt as _;
|
||||
|
@ -85,7 +82,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Init PWMs
|
||||
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
|
||||
|
|
13
boards/solderparty-rp2040-stamp/CHANGELOG.md
Normal file
13
boards/solderparty-rp2040-stamp/CHANGELOG.md
Normal 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`
|
||||
|
|
@ -28,4 +28,4 @@ nb = "1.0.0"
|
|||
smart-leds = "0.3.0"
|
||||
pio = "0.1.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
use solderparty_rp2040_stamp::entry;
|
||||
|
@ -71,7 +71,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25u32.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.3.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
|
|||
[dev-dependencies]
|
||||
panic-halt = "0.2.0"
|
||||
smart-leds = "0.3.0"
|
||||
embedded-time = "0.12.0"
|
||||
nb = "1.0.0"
|
||||
pio = "0.1.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["boot2", "rt"]
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use sparkfun_pro_micro_rp2040::entry;
|
||||
|
||||
|
@ -83,7 +83,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.2.0 - 2022-06-13
|
||||
|
||||
|
|
|
@ -20,10 +20,10 @@ rp2040-boot2 = { version = "0.2.0", optional = true }
|
|||
[dev-dependencies]
|
||||
panic-halt = "0.2.0"
|
||||
smart-leds = "0.3.0"
|
||||
embedded-time = "0.12.0"
|
||||
nb = "1.0.0"
|
||||
pio = "0.1.0"
|
||||
ws2812-pio = "0.3.0"
|
||||
fugit = "0.3.5"
|
||||
|
||||
[features]
|
||||
default = ["boot2", "rt"]
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
|
@ -82,7 +82,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Changed
|
||||
|
||||
- None
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## 0.1.0 - 2022-07-17
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ cortex-m = "0.7.2"
|
|||
rp2040-boot2 = { version = "0.2.0", optional = true }
|
||||
rp2040-hal = { path = "../../rp2040-hal", version = "0.5.0" }
|
||||
cortex-m-rt = { version = "0.7", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.5"
|
||||
usb-device= "0.2.9"
|
||||
usbd-serial = "0.1.1"
|
||||
usbd-hid = "0.5.1"
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#![no_main]
|
||||
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::rate::*;
|
||||
use panic_halt as _;
|
||||
use vcc_gnd_yd_rp2040::entry;
|
||||
use vcc_gnd_yd_rp2040::{
|
||||
|
@ -37,7 +36,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
let sio = Sio::new(pac.SIO);
|
||||
let pins = Pins::new(
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
use core::iter::once;
|
||||
use embedded_hal::timer::CountDown;
|
||||
use embedded_time::duration::Extensions;
|
||||
use fugit::ExtU32;
|
||||
use panic_halt as _;
|
||||
use smart_leds::{brightness, SmartLedsWrite, RGB8};
|
||||
use vcc_gnd_yd_rp2040::entry;
|
||||
|
@ -71,7 +71,7 @@ fn main() -> ! {
|
|||
ws.write(brightness(once(wheel(n)), 32)).unwrap();
|
||||
n = n.wrapping_add(1);
|
||||
|
||||
delay.start(25.milliseconds());
|
||||
delay.start(25.millis());
|
||||
let _ = nb::block!(delay.wait());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
for the clocks in `rp2040_hal::clocks`.
|
||||
- Use `rp2040-hal`'s entry function.
|
||||
- Migrate from `embedded-time` to `fugit`
|
||||
|
||||
## [0.5.0] - 2022-06-13
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ cortex-m = "0.7.2"
|
|||
cortex-m-rt = ">=0.6.15,<0.8"
|
||||
embedded-hal = { version = "0.2.5", features = ["unproven"] }
|
||||
eh1_0_alpha = { package = "embedded-hal", version = "=1.0.0-alpha.8", optional = true }
|
||||
embedded-time = "0.12.0"
|
||||
fugit = "0.3.6"
|
||||
itertools = { version = "0.10.1", default-features = false }
|
||||
nb = "1.0"
|
||||
rp2040-pac = "0.3.0"
|
||||
|
|
|
@ -20,7 +20,6 @@ use rp2040_hal as hal;
|
|||
// Some traits we need
|
||||
use core::fmt::Write;
|
||||
use embedded_hal::adc::OneShot;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp2040_hal::Clock;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
|
@ -68,7 +67,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -22,7 +22,6 @@ use hal::pac;
|
|||
|
||||
// Some traits we need
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
/// The linker will place this boot block at the start of our program image. We
|
||||
|
@ -64,7 +63,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -26,7 +26,6 @@ use hal::pac;
|
|||
// Some traits we need
|
||||
use embedded_hal::digital::v2::InputPin;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use hal::gpio::dynpin::DynPin;
|
||||
use hal::Clock;
|
||||
|
||||
|
@ -124,7 +123,7 @@ fn main() -> ! {
|
|||
&mut pac.RESETS,
|
||||
);
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Use GPIO 28 as an InOutPin
|
||||
let mut pin = InOutPin::new(pins.gpio28.into());
|
||||
|
|
|
@ -15,7 +15,7 @@ use panic_halt as _;
|
|||
|
||||
// Some traits we need
|
||||
use embedded_hal::blocking::i2c::Write;
|
||||
use embedded_time::rate::Extensions;
|
||||
use fugit::RateExtU32;
|
||||
|
||||
// Alias for our HAL crate
|
||||
use rp2040_hal as hal;
|
||||
|
|
|
@ -23,7 +23,6 @@ use rp2040_hal as hal;
|
|||
use hd44780_driver as hd44780;
|
||||
|
||||
// Some traits we need
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
|
@ -71,7 +70,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use hal::clocks::Clock;
|
||||
use hal::multicore::{Multicore, Stack};
|
||||
use hal::sio::Sio;
|
||||
|
@ -107,7 +106,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let sys_freq = clocks.system_clock.freq().integer();
|
||||
let sys_freq = clocks.system_clock.freq().to_Hz();
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let mut sio = hal::sio::Sio::new(pac.SIO);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
use cortex_m::delay::Delay;
|
||||
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use hal::clocks::Clock;
|
||||
use hal::gpio::Pins;
|
||||
use hal::multicore::{Multicore, Stack};
|
||||
|
@ -98,7 +97,7 @@ fn main() -> ! {
|
|||
let mut led2 = pins.gpio3.into_push_pull_output();
|
||||
|
||||
// Set up the delay for the first core.
|
||||
let sys_freq = clocks.system_clock.freq().integer();
|
||||
let sys_freq = clocks.system_clock.freq().to_Hz();
|
||||
let mut delay = Delay::new(core.SYST, sys_freq);
|
||||
|
||||
// Start up the second core to blink the second LED
|
||||
|
|
|
@ -19,7 +19,6 @@ use rp2040_hal as hal;
|
|||
|
||||
// Some traits we need
|
||||
use embedded_hal::PwmPin;
|
||||
use embedded_time::rate::*;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
|
@ -86,7 +85,7 @@ fn main() -> ! {
|
|||
|
||||
// The delay object lets us wait for specified amounts of time (in
|
||||
// milliseconds)
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Init PWMs
|
||||
let mut pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS);
|
||||
|
|
|
@ -21,7 +21,7 @@ use rp2040_hal as hal;
|
|||
|
||||
// Some traits we need
|
||||
use cortex_m::prelude::*;
|
||||
use embedded_time::rate::Extensions;
|
||||
use fugit::RateExtU32;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
// A shorter alias for the Peripheral Access Crate, which provides low-level
|
||||
|
@ -87,7 +87,7 @@ fn main() -> ! {
|
|||
let mut spi = spi.init(
|
||||
&mut pac.RESETS,
|
||||
clocks.peripheral_clock.freq(),
|
||||
16_000_000u32.Hz(),
|
||||
16.MHz(),
|
||||
&embedded_hal::spi::MODE_0,
|
||||
);
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ use hal::pac;
|
|||
|
||||
// Some traits we need
|
||||
use core::fmt::Write;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
/// The linker will place this boot block at the start of our program image. We
|
||||
|
@ -66,7 +65,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -22,8 +22,7 @@ use hal::pac;
|
|||
use core::cell::RefCell;
|
||||
use critical_section::Mutex;
|
||||
use embedded_hal::digital::v2::ToggleableOutputPin;
|
||||
use embedded_time::duration::Microseconds;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use fugit::MicrosDurationU32;
|
||||
use pac::interrupt;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
use rp2040_hal::timer::Alarm;
|
||||
|
@ -42,8 +41,8 @@ type LedAndAlarm = (
|
|||
static mut LED_AND_ALARM: Mutex<RefCell<Option<LedAndAlarm>>> = Mutex::new(RefCell::new(None));
|
||||
|
||||
// Period that each of the alarms will be set for - 1 second and 300ms respectively
|
||||
const SLOW_BLINK_INTERVAL_US: u32 = 1_000_000;
|
||||
const FAST_BLINK_INTERVAL_US: u32 = 300_000;
|
||||
const SLOW_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::secs(1);
|
||||
const FAST_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::millis(300);
|
||||
|
||||
/// The linker will place this boot block at the start of our program image. We
|
||||
/// need this to help the ROM bootloader get our code up and running.
|
||||
|
@ -96,7 +95,7 @@ fn main() -> ! {
|
|||
.unwrap();
|
||||
|
||||
// Create simple delay
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// Set the pins to their default state
|
||||
let pins = hal::gpio::Pins::new(
|
||||
|
@ -113,7 +112,7 @@ fn main() -> ! {
|
|||
critical_section::with(|cs| {
|
||||
let mut alarm = timer.alarm_0().unwrap();
|
||||
// Schedule an alarm in 1 second
|
||||
let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US));
|
||||
let _ = alarm.schedule(SLOW_BLINK_INTERVAL_US);
|
||||
// Enable generating an interrupt on alarm
|
||||
alarm.enable_interrupt();
|
||||
// Move alarm into ALARM, so that it can be accessed from interrupts
|
||||
|
@ -151,7 +150,7 @@ fn TIMER_IRQ_0() {
|
|||
// Clear the alarm interrupt or this interrupt service routine will keep firing
|
||||
alarm.clear_interrupt();
|
||||
// Schedule a new alarm after SLOW_BLINK_INTERVAL_US have passed (1 second)
|
||||
let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US));
|
||||
let _ = alarm.schedule(SLOW_BLINK_INTERVAL_US);
|
||||
// Blink the LED so we know we hit this interrupt
|
||||
led.toggle().unwrap();
|
||||
// Return LED_AND_ALARM into our static variable
|
||||
|
@ -172,7 +171,7 @@ extern "C" fn timer_irq0_replacement() {
|
|||
// Clear the alarm interrupt or this interrupt service routine will keep firing
|
||||
alarm.clear_interrupt();
|
||||
// Schedule a new alarm after FAST_BLINK_INTERVAL_US have passed (300 milliseconds)
|
||||
let _ = alarm.schedule(Microseconds(FAST_BLINK_INTERVAL_US));
|
||||
let _ = alarm.schedule(FAST_BLINK_INTERVAL_US);
|
||||
led.toggle().unwrap();
|
||||
// Return LED_AND_ALARM into our static variable
|
||||
unsafe {
|
||||
|
|
|
@ -23,8 +23,7 @@ use hal::pac;
|
|||
// Some traits we need
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use embedded_hal::watchdog::{Watchdog, WatchdogEnable};
|
||||
use embedded_time::duration::Extensions;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use fugit::ExtU32;
|
||||
use rp2040_hal::clocks::Clock;
|
||||
|
||||
/// The linker will place this boot block at the start of our program image. We
|
||||
|
@ -67,7 +66,7 @@ fn main() -> ! {
|
|||
.ok()
|
||||
.unwrap();
|
||||
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().integer());
|
||||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
@ -88,7 +87,7 @@ fn main() -> ! {
|
|||
delay.delay_ms(2000);
|
||||
|
||||
// Set to watchdog to reset if it's not reloaded within 1.05 seconds, and start it
|
||||
watchdog.start(1_050_000u32.microseconds());
|
||||
watchdog.start(1_050.millis());
|
||||
|
||||
// Blink once a second for 5 seconds, refreshing the watchdog timer once a second to avoid a reset
|
||||
for _ in 1..=5 {
|
||||
|
|
|
@ -16,7 +16,7 @@ use pac::{PLL_SYS, PLL_USB};
|
|||
pub(crate) type PllSys = PhaseLockedLoop<Locked, PLL_SYS>;
|
||||
impl Sealed for PllSys {}
|
||||
impl ClockSource for PllSys {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.operating_frequency()
|
||||
}
|
||||
}
|
||||
|
@ -24,37 +24,37 @@ impl ClockSource for PllSys {
|
|||
pub(crate) type PllUsb = PhaseLockedLoop<Locked, PLL_USB>;
|
||||
impl Sealed for PllUsb {}
|
||||
impl ClockSource for PllUsb {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.operating_frequency()
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockSource for UsbClock {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockSource for AdcClock {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockSource for RtcClock {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockSource for SystemClock {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
}
|
||||
|
||||
impl ClockSource for ReferenceClock {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ impl ClockSource for ReferenceClock {
|
|||
pub(crate) type Xosc = CrystalOscillator<Stable>;
|
||||
impl Sealed for Xosc {}
|
||||
impl ClockSource for Xosc {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.operating_frequency()
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ pub(crate) type Rosc = RingOscillator<Enabled>;
|
|||
impl Sealed for Rosc {}
|
||||
// We are assuming the second output is never phase shifted (see 2.17.4)
|
||||
impl ClockSource for RingOscillator<Enabled> {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
self.operating_frequency()
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ impl ClockSource for RingOscillator<Enabled> {
|
|||
// GPIN0
|
||||
pub(crate) type GPin0 = Pin<Gpio20, FunctionClock>;
|
||||
impl ClockSource for GPin0 {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ impl ClockSource for GPin0 {
|
|||
// GPIN1
|
||||
pub(crate) type GPin1 = Pin<Gpio22, FunctionClock>;
|
||||
impl ClockSource for Pin<Gpio22, FunctionClock> {
|
||||
fn get_freq(&self) -> Hertz {
|
||||
fn get_freq(&self) -> HertzU32 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,8 @@ macro_rules! clock {
|
|||
w.src().variant(self.get_default_clock_source())
|
||||
});
|
||||
|
||||
self.frequency = 12_000_000.Hz(); //TODO Get actual clock source.. Most likely 12 MHz though
|
||||
use fugit::RateExtU32;
|
||||
self.frequency = 12.MHz(); //TODO Get actual clock source.. Most likely 12 MHz though
|
||||
|
||||
self.await_select(&ChangingClockToken{clock_nr:0, clock: PhantomData::<Self>})
|
||||
}
|
||||
|
@ -174,19 +175,19 @@ macro_rules! clock {
|
|||
type Variant = [<$reg:camel SrcType>];
|
||||
|
||||
#[doc = "Get operating frequency for `"$name"`"]
|
||||
fn freq(&self) -> Hertz {
|
||||
fn freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
|
||||
#[doc = "Configure `"$name"`"]
|
||||
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{
|
||||
let src_freq: Hertz<u32> = src.get_freq().into();
|
||||
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{
|
||||
let src_freq: HertzU32 = src.get_freq().into();
|
||||
|
||||
if freq.gt(&src_freq){
|
||||
return Err(ClockError::CantIncreaseFreq);
|
||||
}
|
||||
|
||||
let div = fractional_div(src_freq.integer(), freq.integer()).ok_or(ClockError::FrequencyTooLow)?;
|
||||
let div = fractional_div(src_freq.to_Hz(), freq.to_Hz()).ok_or(ClockError::FrequencyTooLow)?;
|
||||
|
||||
// If increasing divisor, set divisor before source. Otherwise set source
|
||||
// before divisor. This avoids a momentary overspeed when e.g. switching
|
||||
|
@ -217,7 +218,8 @@ macro_rules! clock {
|
|||
self.set_div(div);
|
||||
|
||||
// Store the configured frequency
|
||||
self.frequency = fractional_div(src_freq.integer(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz();
|
||||
use fugit::RateExtU32;
|
||||
self.frequency = fractional_div(src_freq.to_Hz(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -324,19 +326,19 @@ macro_rules! stoppable_clock {
|
|||
type Variant = [<$reg:camel SrcType>];
|
||||
|
||||
#[doc = "Get operating frequency for `"$name"`"]
|
||||
fn freq(&self) -> Hertz {
|
||||
fn freq(&self) -> HertzU32 {
|
||||
self.frequency
|
||||
}
|
||||
|
||||
#[doc = "Configure `"$name"`"]
|
||||
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: Hertz) -> Result<(), ClockError>{
|
||||
let src_freq: Hertz<u32> = src.get_freq().into();
|
||||
fn configure_clock<S: ValidSrc<$name>>(&mut self, src: &S, freq: HertzU32) -> Result<(), ClockError>{
|
||||
let src_freq: HertzU32 = src.get_freq().into();
|
||||
|
||||
if freq.gt(&src_freq){
|
||||
return Err(ClockError::CantIncreaseFreq);
|
||||
}
|
||||
|
||||
let div = fractional_div(src_freq.integer(), freq.integer()).ok_or(ClockError::FrequencyTooLow)?;
|
||||
let div = fractional_div(src_freq.to_Hz(), freq.to_Hz()).ok_or(ClockError::FrequencyTooLow)?;
|
||||
|
||||
// If increasing divisor, set divisor before source. Otherwise set source
|
||||
// before divisor. This avoids a momentary overspeed when e.g. switching
|
||||
|
@ -352,12 +354,12 @@ macro_rules! stoppable_clock {
|
|||
// Disable clock. On clk_ref and clk_sys this does nothing,
|
||||
// all other clocks have the ENABLE bit in the same position.
|
||||
self.disable();
|
||||
if (self.frequency > 0u32.Hz()) {
|
||||
if self.frequency > HertzU32::Hz(0) {
|
||||
// Delay for 3 cycles of the target clock, for ENABLE propagation.
|
||||
// Note XOSC_COUNT is not helpful here because XOSC is not
|
||||
// necessarily running, nor is timer... so, 3 cycles per loop:
|
||||
let sys_freq = 125_000_000; // TODO get actual sys_clk frequency
|
||||
let delay_cyc = sys_freq / self.frequency.integer() + 1u32;
|
||||
let delay_cyc = sys_freq / self.frequency.to_Hz() + 1u32;
|
||||
cortex_m::asm::delay(delay_cyc);
|
||||
}
|
||||
|
||||
|
@ -373,7 +375,8 @@ macro_rules! stoppable_clock {
|
|||
self.set_div(div);
|
||||
|
||||
// Store the configured frequency
|
||||
self.frequency = fractional_div(src_freq.integer(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz();
|
||||
use fugit::RateExtU32;
|
||||
self.frequency = fractional_div(src_freq.to_Hz(), div).ok_or(ClockError::FrequencyTooHigh)?.Hz();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -402,7 +405,7 @@ macro_rules! base_clock {
|
|||
$(#[$attr])*
|
||||
pub struct $name {
|
||||
shared_dev: ShareableClocks,
|
||||
frequency: Hertz,
|
||||
frequency: HertzU32,
|
||||
}
|
||||
|
||||
impl $name {
|
||||
|
@ -417,9 +420,9 @@ macro_rules! base_clock {
|
|||
|
||||
impl Sealed for $name {}
|
||||
|
||||
impl From<&$name> for Hertz
|
||||
impl From<&$name> for HertzU32
|
||||
{
|
||||
fn from(value: &$name) -> Hertz {
|
||||
fn from(value: &$name) -> HertzU32 {
|
||||
value.frequency
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
//!
|
||||
//! ## Usage extended
|
||||
//! ```no_run
|
||||
//! use embedded_time::rate::*;
|
||||
//! use fugit::RateExtU32;
|
||||
//! use rp2040_hal::{clocks::{Clock, ClocksManager, ClockSource, InitError}, gpio::Pins, pac, pll::{common_configs::{PLL_SYS_125MHZ, PLL_USB_48MHZ}, setup_pll_blocking}, Sio, watchdog::Watchdog, xosc::setup_xosc_blocking};
|
||||
//!
|
||||
//! # fn func() -> Result<(), InitError> {
|
||||
|
@ -72,7 +72,8 @@ use crate::{
|
|||
xosc::{setup_xosc_blocking, CrystalOscillator, Error as XoscError, Stable},
|
||||
};
|
||||
use core::{convert::Infallible, marker::PhantomData};
|
||||
use embedded_time::rate::*;
|
||||
use fugit::HertzU32;
|
||||
use fugit::RateExtU32;
|
||||
use pac::{CLOCKS, PLL_SYS, PLL_USB, RESETS, XOSC};
|
||||
|
||||
#[macro_use]
|
||||
|
@ -117,13 +118,13 @@ pub trait Clock: Sealed + Sized {
|
|||
type Variant;
|
||||
|
||||
/// Get operating frequency
|
||||
fn freq(&self) -> Hertz;
|
||||
fn freq(&self) -> HertzU32;
|
||||
|
||||
/// Configure this clock based on a clock source and desired frequency
|
||||
fn configure_clock<S: ValidSrc<Self>>(
|
||||
&mut self,
|
||||
src: &S,
|
||||
freq: Hertz,
|
||||
freq: HertzU32,
|
||||
) -> Result<(), ClockError>;
|
||||
}
|
||||
|
||||
|
@ -170,7 +171,7 @@ pub trait ClockSource: Sealed {
|
|||
/// Get the operating frequency for this source
|
||||
///
|
||||
/// Used to determine the divisor
|
||||
fn get_freq(&self) -> Hertz;
|
||||
fn get_freq(&self) -> HertzU32;
|
||||
}
|
||||
|
||||
/// Trait to contrain which ClockSource is valid for which Clock
|
||||
|
@ -336,7 +337,7 @@ pub fn init_clocks_and_plls(
|
|||
|
||||
let pll_sys = setup_pll_blocking(
|
||||
pll_sys_dev,
|
||||
xosc.operating_frequency().into(),
|
||||
xosc.operating_frequency(),
|
||||
PLL_SYS_125MHZ,
|
||||
&mut clocks,
|
||||
resets,
|
||||
|
@ -344,7 +345,7 @@ pub fn init_clocks_and_plls(
|
|||
.map_err(InitError::PllError)?;
|
||||
let pll_usb = setup_pll_blocking(
|
||||
pll_usb_dev,
|
||||
xosc.operating_frequency().into(),
|
||||
xosc.operating_frequency(),
|
||||
PLL_USB_48MHZ,
|
||||
&mut clocks,
|
||||
resets,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//!
|
||||
//! ## Usage
|
||||
//! ```no_run
|
||||
//! use embedded_time::rate::Extensions;
|
||||
//! use fugit::RateExtU32;
|
||||
//! use rp2040_hal::{i2c::I2C, gpio::Pins, pac, Sio};
|
||||
//! let mut peripherals = pac::Peripherals::take().unwrap();
|
||||
//! let sio = Sio::new(peripherals.SIO);
|
||||
|
@ -55,7 +55,7 @@ use crate::{
|
|||
resets::SubsystemReset,
|
||||
typelevel::Sealed,
|
||||
};
|
||||
use embedded_time::rate::Hertz;
|
||||
use fugit::HertzU32;
|
||||
use pac::{i2c0::RegisterBlock as I2CBlock, I2C0, I2C1, RESETS};
|
||||
|
||||
/// Controller implementaion
|
||||
|
@ -294,12 +294,12 @@ macro_rules! hal {
|
|||
resets: &mut RESETS,
|
||||
system_clock: SystemF) -> Self
|
||||
where
|
||||
F: Into<Hertz<u64>>,
|
||||
F: Into<HertzU32>,
|
||||
Sda: SdaPin<$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())
|
||||
}
|
||||
}
|
||||
)+
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
gpio::pin::{FunctionI2C, Pin, PinId},
|
||||
resets::SubsystemReset,
|
||||
};
|
||||
use embedded_time::rate::Hertz;
|
||||
use fugit::HertzU32;
|
||||
use hal::blocking::i2c::{Read, Write, WriteRead};
|
||||
use pac::{i2c0::RegisterBlock as Block, RESETS};
|
||||
|
||||
|
@ -18,24 +18,21 @@ impl<T: SubsystemReset + Deref<Target = Block>, Sda: PinId + BankPinId, Scl: Pin
|
|||
I2C<T, (Pin<Sda, FunctionI2C>, Pin<Scl, FunctionI2C>), Controller>
|
||||
{
|
||||
/// Configures the I2C peripheral to work in controller mode
|
||||
pub fn new_controller<F, SystemF>(
|
||||
pub fn new_controller(
|
||||
i2c: T,
|
||||
sda_pin: Pin<Sda, FunctionI2C>,
|
||||
scl_pin: Pin<Scl, FunctionI2C>,
|
||||
freq: F,
|
||||
freq: HertzU32,
|
||||
resets: &mut RESETS,
|
||||
system_clock: SystemF,
|
||||
system_clock: HertzU32,
|
||||
) -> Self
|
||||
where
|
||||
F: Into<Hertz<u64>>,
|
||||
Sda: SdaPin<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 > 0);
|
||||
let freq = freq as u32;
|
||||
|
||||
i2c.reset_bring_down(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_rx_tl.write(|w| unsafe { w.rx_tl().bits(0) });
|
||||
|
||||
let freq_in = system_clock.into().0;
|
||||
let freq_in = system_clock.to_Hz();
|
||||
|
||||
// There are some subtleties to I2C timing which we are completely ignoring here
|
||||
// See: https://github.com/raspberrypi/pico-sdk/blob/bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7/src/rp2_common/hardware_i2c/i2c.c#L69
|
||||
|
|
|
@ -2,15 +2,12 @@
|
|||
// See [Chapter 2 Section 18](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
|
||||
|
||||
use core::{
|
||||
convert::{Infallible, TryFrom, TryInto},
|
||||
convert::{Infallible, TryInto},
|
||||
marker::PhantomData,
|
||||
ops::{Deref, Range, RangeInclusive},
|
||||
};
|
||||
|
||||
use embedded_time::{
|
||||
fixed_point::FixedPoint,
|
||||
rate::{Generic, Hertz, Rate},
|
||||
};
|
||||
use fugit::{HertzU32, RateExtU32};
|
||||
|
||||
use nb::Error::WouldBlock;
|
||||
use pac::RESETS;
|
||||
|
@ -26,19 +23,19 @@ pub struct Disabled {
|
|||
fbdiv: u16,
|
||||
post_div1: u8,
|
||||
post_div2: u8,
|
||||
frequency: Hertz,
|
||||
frequency: HertzU32,
|
||||
}
|
||||
|
||||
/// PLL is configured, started and locking into its designated frequency.
|
||||
pub struct Locking {
|
||||
post_div1: u8,
|
||||
post_div2: u8,
|
||||
frequency: Hertz,
|
||||
frequency: HertzU32,
|
||||
}
|
||||
|
||||
/// PLL is locked : it delivers a steady frequency.
|
||||
pub struct Locked {
|
||||
frequency: Hertz,
|
||||
frequency: HertzU32,
|
||||
}
|
||||
|
||||
impl State for Disabled {}
|
||||
|
@ -94,9 +91,9 @@ pub enum Error {
|
|||
}
|
||||
|
||||
/// Parameters for a PLL.
|
||||
pub struct PLLConfig<R: Rate> {
|
||||
pub struct PLLConfig {
|
||||
/// Voltage Controlled Oscillator frequency.
|
||||
pub vco_freq: R,
|
||||
pub vco_freq: HertzU32,
|
||||
|
||||
/// Reference divider
|
||||
pub refdiv: u8,
|
||||
|
@ -112,19 +109,19 @@ pub struct PLLConfig<R: Rate> {
|
|||
/// See Chapter 2, Section 18, §2
|
||||
pub mod common_configs {
|
||||
use super::PLLConfig;
|
||||
use embedded_time::rate::Megahertz;
|
||||
use fugit::HertzU32;
|
||||
|
||||
/// Default, nominal configuration for PLL_SYS
|
||||
pub const PLL_SYS_125MHZ: PLLConfig<Megahertz> = PLLConfig {
|
||||
vco_freq: Megahertz(1500),
|
||||
pub const PLL_SYS_125MHZ: PLLConfig = PLLConfig {
|
||||
vco_freq: HertzU32::MHz(1500),
|
||||
refdiv: 1,
|
||||
post_div1: 6,
|
||||
post_div2: 2,
|
||||
};
|
||||
|
||||
/// Default, nominal configuration for PLL_USB.
|
||||
pub const PLL_USB_48MHZ: PLLConfig<Megahertz> = PLLConfig {
|
||||
vco_freq: Megahertz(480),
|
||||
pub const PLL_USB_48MHZ: PLLConfig = PLLConfig {
|
||||
vco_freq: HertzU32::MHz(480),
|
||||
refdiv: 1,
|
||||
post_div1: 5,
|
||||
post_div2: 2,
|
||||
|
@ -133,24 +130,16 @@ pub mod common_configs {
|
|||
|
||||
impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
|
||||
/// Instantiates a new Phase-Locked-Loop device.
|
||||
pub fn new<R: Rate>(
|
||||
pub fn new(
|
||||
dev: D,
|
||||
xosc_frequency: Generic<u32>,
|
||||
config: PLLConfig<R>,
|
||||
) -> Result<PhaseLockedLoop<Disabled, D>, Error>
|
||||
where
|
||||
R: Into<Hertz<u64>>,
|
||||
{
|
||||
const VCO_FREQ_RANGE: RangeInclusive<Hertz<u32>> =
|
||||
Hertz(400_000_000)..=Hertz(1_600_000_000);
|
||||
xosc_frequency: HertzU32,
|
||||
config: PLLConfig,
|
||||
) -> Result<PhaseLockedLoop<Disabled, D>, Error> {
|
||||
const VCO_FREQ_RANGE: RangeInclusive<HertzU32> = HertzU32::MHz(400)..=HertzU32::MHz(1_600);
|
||||
const POSTDIV_RANGE: Range<u8> = 1..7;
|
||||
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: 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)?;
|
||||
let vco_freq = config.vco_freq;
|
||||
|
||||
if !VCO_FREQ_RANGE.contains(&vco_freq) {
|
||||
return Err(Error::VcoFreqOutOfRange);
|
||||
|
@ -161,24 +150,25 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
|
|||
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)
|
||||
.map_err(|_| Error::BadArgument)?
|
||||
.checked_div(&(config.refdiv as u32))
|
||||
.ok_or(Error::BadArgument)?;
|
||||
let ref_freq_hz: HertzU32 = xosc_frequency
|
||||
.to_Hz()
|
||||
.checked_div(u32::from(config.refdiv))
|
||||
.ok_or(Error::BadArgument)?
|
||||
.Hz();
|
||||
|
||||
if !ref_freq_range.contains(&ref_freq_hz) {
|
||||
return Err(Error::RefFreqOutOfRange);
|
||||
}
|
||||
|
||||
let fbdiv = vco_freq
|
||||
.checked_div(&ref_freq_hz.integer())
|
||||
.to_Hz()
|
||||
.checked_div(ref_freq_hz.to_Hz())
|
||||
.ok_or(Error::BadArgument)?;
|
||||
|
||||
let fbdiv: u16 = (fbdiv.integer())
|
||||
.try_into()
|
||||
.map_err(|_| Error::BadArgument)?;
|
||||
let fbdiv: u16 = fbdiv.try_into().map_err(|_| Error::BadArgument)?;
|
||||
|
||||
if !FBDIV_RANGE.contains(&fbdiv) {
|
||||
return Err(Error::FeedbackDivOutOfRange);
|
||||
|
@ -187,8 +177,8 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Disabled, D> {
|
|||
let refdiv = config.refdiv;
|
||||
let post_div1 = config.post_div1;
|
||||
let post_div2 = config.post_div2;
|
||||
let frequency: Hertz =
|
||||
(ref_freq_hz / refdiv as u32) * fbdiv as u32 / (post_div1 as u32 * post_div2 as u32);
|
||||
let frequency: HertzU32 = ((ref_freq_hz / u32::from(refdiv)) * u32::from(fbdiv))
|
||||
/ (u32::from(post_div1) * u32::from(post_div2));
|
||||
|
||||
Ok(PhaseLockedLoop {
|
||||
state: Disabled {
|
||||
|
@ -279,28 +269,26 @@ impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Locking, D> {
|
|||
|
||||
impl<D: PhaseLockedLoopDevice> PhaseLockedLoop<Locked, D> {
|
||||
/// Get the operating frequency for the PLL
|
||||
pub fn operating_frequency(&self) -> Hertz {
|
||||
pub fn operating_frequency(&self) -> HertzU32 {
|
||||
self.state.frequency
|
||||
}
|
||||
}
|
||||
|
||||
/// Blocking helper method to setup the PLL without going through all the steps.
|
||||
pub fn setup_pll_blocking<D: PhaseLockedLoopDevice, R: Rate>(
|
||||
pub fn setup_pll_blocking<D: PhaseLockedLoopDevice>(
|
||||
dev: D,
|
||||
xosc_frequency: Generic<u32>,
|
||||
config: PLLConfig<R>,
|
||||
xosc_frequency: HertzU32,
|
||||
config: PLLConfig,
|
||||
clocks: &mut ClocksManager,
|
||||
resets: &mut RESETS,
|
||||
) -> Result<PhaseLockedLoop<Locked, D>, Error>
|
||||
where
|
||||
R: Into<Hertz<u64>>,
|
||||
{
|
||||
) -> Result<PhaseLockedLoop<Locked, D>, Error> {
|
||||
// Before we touch PLLs, switch sys and ref cleanly away from their aux sources.
|
||||
nb::block!(clocks.system_clock.reset_source_await()).unwrap();
|
||||
|
||||
nb::block!(clocks.reference_clock.reset_source_await()).unwrap();
|
||||
|
||||
let initialized_pll = PhaseLockedLoop::new(dev, xosc_frequency, config)?.initialize(resets);
|
||||
let initialized_pll =
|
||||
PhaseLockedLoop::new(dev, xosc_frequency.convert(), config)?.initialize(resets);
|
||||
|
||||
let locked_pll_token = nb::block!(initialized_pll.await_lock()).unwrap();
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
//! Ring Oscillator (ROSC)
|
||||
// See [Chapter 2 Section 17](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) for more details
|
||||
|
||||
use embedded_time::rate::Extensions;
|
||||
use embedded_time::rate::Hertz;
|
||||
use fugit::HertzU32;
|
||||
|
||||
/// State of the Ring Oscillator (typestate trait)
|
||||
pub trait State {}
|
||||
|
@ -12,7 +11,7 @@ pub struct Disabled;
|
|||
|
||||
/// ROSC is initialized, ie we've given parameters (typestate)
|
||||
pub struct Enabled {
|
||||
freq_hz: Hertz,
|
||||
freq_hz: HertzU32,
|
||||
}
|
||||
|
||||
/// ROSC is in dormant mode (see Chapter 2, Section 17, §7)
|
||||
|
@ -56,6 +55,7 @@ impl RingOscillator<Disabled> {
|
|||
pub fn initialize(self) -> RingOscillator<Enabled> {
|
||||
self.device.ctrl.write(|w| w.enable().enable());
|
||||
|
||||
use fugit::RateExtU32;
|
||||
self.transition(Enabled {
|
||||
freq_hz: 6_500_000u32.Hz(),
|
||||
})
|
||||
|
@ -64,7 +64,7 @@ impl RingOscillator<Disabled> {
|
|||
|
||||
impl RingOscillator<Enabled> {
|
||||
/// Approx operating frequency of the ROSC in hertz
|
||||
pub fn operating_frequency(&self) -> Hertz {
|
||||
pub fn operating_frequency(&self) -> HertzU32 {
|
||||
self.state.freq_hz
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
use crate::clocks::Clock;
|
||||
use crate::clocks::RtcClock;
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use rp2040_pac::{RESETS, RTC};
|
||||
|
||||
mod filter;
|
||||
|
@ -66,7 +65,7 @@ impl RealTimeClock {
|
|||
}
|
||||
|
||||
// Set the RTC divider
|
||||
let freq = clock.freq().integer() - 1;
|
||||
let freq = clock.freq().to_Hz() - 1;
|
||||
rtc.clkdiv_m1.write(|w| unsafe { w.bits(freq) });
|
||||
|
||||
let mut result = Self { rtc };
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//!
|
||||
//! ```no_run
|
||||
//! use embedded_hal::spi::MODE_0;
|
||||
//! use embedded_time::rate::*;
|
||||
//! use fugit::RateExtU32;
|
||||
//! use rp2040_hal::{spi::Spi, gpio::{Pins, FunctionSpi}, pac, Sio};
|
||||
//!
|
||||
//! let mut peripherals = pac::Peripherals::take().unwrap();
|
||||
|
@ -25,7 +25,7 @@ use core::{convert::Infallible, marker::PhantomData, ops::Deref};
|
|||
use eh1_0_alpha::spi as eh1;
|
||||
use embedded_hal::blocking::spi;
|
||||
use embedded_hal::spi::{FullDuplex, Mode, Phase, Polarity};
|
||||
use embedded_time::rate::*;
|
||||
use fugit::HertzU32;
|
||||
use pac::RESETS;
|
||||
|
||||
/// State of the SPI
|
||||
|
@ -78,13 +78,13 @@ impl<S: State, D: SpiDevice, const DS: u8> Spi<S, D, DS> {
|
|||
/// Set baudrate based on peripheral clock
|
||||
///
|
||||
/// 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,
|
||||
peri_frequency: F,
|
||||
baudrate: B,
|
||||
) -> Hertz {
|
||||
let freq_in = peri_frequency.into().integer();
|
||||
let baudrate = baudrate.into().integer();
|
||||
) -> HertzU32 {
|
||||
let freq_in = peri_frequency.into().to_Hz();
|
||||
let baudrate = baudrate.into().to_Hz();
|
||||
let mut prescale: u8 = u8::MAX;
|
||||
let mut postdiv: u8 = 0;
|
||||
|
||||
|
@ -120,6 +120,7 @@ impl<S: State, D: SpiDevice, const DS: u8> Spi<S, D, DS> {
|
|||
.modify(|_, w| unsafe { w.scr().bits(postdiv) });
|
||||
|
||||
// Return the frequency we were able to achieve
|
||||
use fugit::RateExtU32;
|
||||
(freq_in / (prescale as u32 * (1 + postdiv as u32))).Hz()
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +147,7 @@ impl<D: SpiDevice, const DS: u8> Spi<Disabled, D, DS> {
|
|||
}
|
||||
|
||||
/// 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,
|
||||
resets: &mut RESETS,
|
||||
peri_frequency: F,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//!
|
||||
//! See [Chapter 4 Section 6](https://datasheets.raspberrypi.org/rp2040/rp2040_datasheet.pdf) of the datasheet for more details.
|
||||
|
||||
use embedded_time::duration::Microseconds;
|
||||
use fugit::{Duration, MicrosDurationU64};
|
||||
|
||||
use crate::atomic_register_access::{write_bitmask_clear, write_bitmask_set};
|
||||
use crate::pac::{RESETS, TIMER};
|
||||
|
@ -53,7 +53,7 @@ impl Timer {
|
|||
pub fn count_down(&self) -> CountDown<'_> {
|
||||
CountDown {
|
||||
timer: self,
|
||||
period: Microseconds::new(0),
|
||||
period: MicrosDurationU64::nanos(0),
|
||||
next_end: None,
|
||||
}
|
||||
}
|
||||
|
@ -104,43 +104,47 @@ impl Timer {
|
|||
/// ## Usage
|
||||
/// ```no_run
|
||||
/// use embedded_hal::timer::{CountDown, Cancel};
|
||||
/// use embedded_time::duration::Extensions;
|
||||
/// use fugit::ExtU32;
|
||||
/// use rp2040_hal;
|
||||
/// let mut pac = rp2040_hal::pac::Peripherals::take().unwrap();
|
||||
/// // Configure the Timer peripheral in count-down mode
|
||||
/// let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS);
|
||||
/// let mut count_down = timer.count_down();
|
||||
/// // Create a count_down timer for 500 milliseconds
|
||||
/// count_down.start(500.milliseconds());
|
||||
/// count_down.start(500.millis());
|
||||
/// // Block until timer has elapsed
|
||||
/// let _ = nb::block!(count_down.wait());
|
||||
/// // Restart the count_down timer with a period of 100 milliseconds
|
||||
/// count_down.start(100.milliseconds());
|
||||
/// count_down.start(100.millis());
|
||||
/// // Cancel it immediately
|
||||
/// count_down.cancel();
|
||||
/// ```
|
||||
pub struct CountDown<'timer> {
|
||||
timer: &'timer Timer,
|
||||
period: embedded_time::duration::Microseconds<u64>,
|
||||
period: MicrosDurationU64,
|
||||
next_end: Option<u64>,
|
||||
}
|
||||
|
||||
impl embedded_hal::timer::CountDown for CountDown<'_> {
|
||||
type Time = embedded_time::duration::Microseconds<u64>;
|
||||
type Time = MicrosDurationU64;
|
||||
|
||||
fn start<T>(&mut self, count: T)
|
||||
where
|
||||
T: Into<Self::Time>,
|
||||
{
|
||||
self.period = count.into();
|
||||
self.next_end = Some(self.timer.get_counter().wrapping_add(self.period.0));
|
||||
self.next_end = Some(
|
||||
self.timer
|
||||
.get_counter()
|
||||
.wrapping_add(self.period.to_micros()),
|
||||
);
|
||||
}
|
||||
|
||||
fn wait(&mut self) -> nb::Result<(), void::Void> {
|
||||
if let Some(end) = self.next_end {
|
||||
let ts = self.timer.get_counter();
|
||||
if ts >= end {
|
||||
self.next_end = Some(end.wrapping_add(self.period.0));
|
||||
self.next_end = Some(end.wrapping_add(self.period.to_micros()));
|
||||
Ok(())
|
||||
} else {
|
||||
Err(nb::Error::WouldBlock)
|
||||
|
@ -187,12 +191,12 @@ pub trait Alarm {
|
|||
/// this will trigger interrupt whenever this time elapses.
|
||||
///
|
||||
/// The RP2040 has been observed to take a little while to schedule an alarm. For this
|
||||
/// reason, the minimum time that this function accepts is `10.microseconds()`
|
||||
/// reason, the minimum time that this function accepts is `10.micros()`
|
||||
///
|
||||
/// [enable_interrupt]: #method.enable_interrupt
|
||||
fn schedule<TIME: Into<Microseconds>>(
|
||||
fn schedule<const NOM: u32, const DENOM: u32>(
|
||||
&mut self,
|
||||
countdown: TIME,
|
||||
countdown: Duration<u32, NOM, DENOM>,
|
||||
) -> Result<(), ScheduleAlarmError>;
|
||||
|
||||
/// Return true if this alarm is finished.
|
||||
|
@ -255,14 +259,14 @@ macro_rules! impl_alarm {
|
|||
#[doc = $int_name]
|
||||
/// ` whenever this time elapses.
|
||||
///
|
||||
/// The RP2040 has been observed to take a little while to schedule an alarm. For this reason, the minimum time that this function accepts is `10.microseconds()`
|
||||
/// The RP2040 has been observed to take a little while to schedule an alarm. For this reason, the minimum time that this function accepts is `10.micros()`
|
||||
///
|
||||
/// [enable_interrupt]: #method.enable_interrupt
|
||||
fn schedule<TIME: Into<Microseconds>>(
|
||||
fn schedule<const NOM: u32, const DENOM: u32>(
|
||||
&mut self,
|
||||
countdown: TIME,
|
||||
countdown: Duration<u32, NOM, DENOM>,
|
||||
) -> Result<(), ScheduleAlarmError> {
|
||||
let duration = countdown.into().0;
|
||||
let duration = countdown.to_micros();
|
||||
|
||||
const MIN_MICROSECONDS: u32 = 10;
|
||||
if duration < MIN_MICROSECONDS {
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use fugit::HertzU32;
|
||||
|
||||
use super::{DataBits, StopBits, UartConfig};
|
||||
use embedded_time::rate::Baud;
|
||||
|
||||
/// 9600 baud, 8 data bits, no parity, 1 stop bit
|
||||
pub const _9600_8_N_1: UartConfig = UartConfig {
|
||||
baudrate: Baud(9600),
|
||||
baudrate: HertzU32::from_raw(9600),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
@ -11,7 +12,7 @@ pub const _9600_8_N_1: UartConfig = UartConfig {
|
|||
|
||||
/// 19200 baud, 8 data bits, no parity, 1 stop bit
|
||||
pub const _19200_8_N_1: UartConfig = UartConfig {
|
||||
baudrate: Baud(19200),
|
||||
baudrate: HertzU32::from_raw(19200),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
@ -19,7 +20,7 @@ pub const _19200_8_N_1: UartConfig = UartConfig {
|
|||
|
||||
/// 38400 baud, 8 data bits, no parity, 1 stop bit
|
||||
pub const _38400_8_N_1: UartConfig = UartConfig {
|
||||
baudrate: Baud(38400),
|
||||
baudrate: HertzU32::from_raw(38400),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
@ -27,7 +28,7 @@ pub const _38400_8_N_1: UartConfig = UartConfig {
|
|||
|
||||
/// 57600 baud, 8 data bits, no parity, 1 stop bit
|
||||
pub const _57600_8_N_1: UartConfig = UartConfig {
|
||||
baudrate: Baud(57600),
|
||||
baudrate: HertzU32::from_raw(57600),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
@ -35,7 +36,7 @@ pub const _57600_8_N_1: UartConfig = UartConfig {
|
|||
|
||||
/// 115200 baud, 8 data bits, no parity, 1 stop bit
|
||||
pub const _115200_8_N_1: UartConfig = UartConfig {
|
||||
baudrate: Baud(115200),
|
||||
baudrate: HertzU32::from_raw(115200),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
|
|
@ -8,9 +8,7 @@ use crate::pac::uart0::uartlcr_h::W as UART_LCR_H_Writer;
|
|||
use core::convert::Infallible;
|
||||
use core::fmt;
|
||||
use embedded_hal::serial::{Read, Write};
|
||||
use embedded_time::fixed_point::FixedPoint;
|
||||
use embedded_time::rate::Baud;
|
||||
use embedded_time::rate::Hertz;
|
||||
use fugit::HertzU32;
|
||||
use nb::Error::{Other, WouldBlock};
|
||||
use rp2040_pac::{UART0, UART1};
|
||||
|
||||
|
@ -57,10 +55,10 @@ impl<D: UartDevice, P: ValidUartPinout<D>> UartPeripheral<Disabled, D, P> {
|
|||
pub fn enable(
|
||||
self,
|
||||
config: UartConfig,
|
||||
frequency: Hertz,
|
||||
frequency: HertzU32,
|
||||
) -> Result<UartPeripheral<Enabled, D, P>, Error> {
|
||||
let (mut device, pins) = self.free();
|
||||
configure_baudrate(&mut device, &config.baudrate, &frequency)?;
|
||||
configure_baudrate(&mut device, config.baudrate, frequency)?;
|
||||
|
||||
device.uartlcr_h.write(|w| {
|
||||
// FIFOs are enabled
|
||||
|
@ -229,15 +227,15 @@ impl<P: ValidUartPinout<UART1>> UartPeripheral<Enabled, UART1, P> {
|
|||
/// From the wanted baudrate, we calculate the divider's two parts: integer and fractional parts.
|
||||
/// Code inspired from the C SDK.
|
||||
fn calculate_baudrate_dividers(
|
||||
wanted_baudrate: &Baud,
|
||||
frequency: &Hertz,
|
||||
wanted_baudrate: HertzU32,
|
||||
frequency: HertzU32,
|
||||
) -> Result<(u16, u16), Error> {
|
||||
// See Chapter 4, Section 2 §7.1 from the datasheet for an explanation of how baudrate is
|
||||
// calculated
|
||||
let baudrate_div = frequency
|
||||
.integer()
|
||||
.to_Hz()
|
||||
.checked_mul(8)
|
||||
.and_then(|r| r.checked_div(wanted_baudrate.integer()))
|
||||
.and_then(|r| r.checked_div(wanted_baudrate.to_Hz()))
|
||||
.ok_or(Error::BadArgument)?;
|
||||
|
||||
Ok(match (baudrate_div >> 7, ((baudrate_div & 0x7F) + 1) / 2) {
|
||||
|
@ -252,9 +250,9 @@ fn calculate_baudrate_dividers(
|
|||
/// Baudrate configuration. Code loosely inspired from the C SDK.
|
||||
fn configure_baudrate(
|
||||
device: &mut dyn UartDevice,
|
||||
wanted_baudrate: &Baud,
|
||||
frequency: &Hertz,
|
||||
) -> Result<Baud, Error> {
|
||||
wanted_baudrate: HertzU32,
|
||||
frequency: HertzU32,
|
||||
) -> Result<HertzU32, Error> {
|
||||
let (baud_div_int, baud_div_frac) = calculate_baudrate_dividers(wanted_baudrate, frequency)?;
|
||||
|
||||
// First we load the integer part of the divider.
|
||||
|
@ -273,8 +271,8 @@ fn configure_baudrate(
|
|||
// divisors. We don't want to actually change LCR contents here.
|
||||
device.uartlcr_h.modify(|_, w| w);
|
||||
|
||||
Ok(Baud(
|
||||
(4 * frequency.integer()) / (64 * baud_div_int + baud_div_frac) as u32,
|
||||
Ok(HertzU32::from_raw(
|
||||
(4 * frequency.to_Hz()) / (64 * baud_div_int + baud_div_frac) as u32,
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use fugit::HertzU32;
|
||||
|
||||
use crate::pac::{uart0::RegisterBlock, UART0, UART1};
|
||||
use crate::resets::SubsystemReset;
|
||||
use core::ops::Deref;
|
||||
use embedded_time::rate::Baud;
|
||||
|
||||
/// Error type for UART operations.
|
||||
#[derive(Debug)]
|
||||
|
@ -73,7 +74,7 @@ pub enum Parity {
|
|||
#[non_exhaustive]
|
||||
pub struct UartConfig {
|
||||
/// The baudrate the uart will run at.
|
||||
pub baudrate: Baud,
|
||||
pub baudrate: HertzU32,
|
||||
|
||||
/// The amount of data bits the uart should be configured to.
|
||||
pub data_bits: DataBits,
|
||||
|
@ -88,7 +89,7 @@ pub struct UartConfig {
|
|||
impl Default for UartConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
baudrate: Baud(115_200),
|
||||
baudrate: HertzU32::from_raw(115_200),
|
||||
data_bits: DataBits::Eight,
|
||||
stop_bits: StopBits::One,
|
||||
parity: None,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue