Skip to content

Commit 01c2e2b

Browse files
authored
embedded-time: move to a non-default feature
This reduces the compile time from 17.6s to 16.2s when not used.
1 parent ccdb043 commit 01c2e2b

File tree

13 files changed

+53
-32
lines changed

13 files changed

+53
-32
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
env: {"RUSTFLAGS": "-D warnings"}
129129
strategy:
130130
matrix:
131-
feature:
131+
mcu:
132132
- "stm32wl5x_cm0p"
133133
- "stm32wl5x_cm4"
134134
- "stm32wle5"
@@ -139,17 +139,16 @@ jobs:
139139
toolchain: stable
140140

141141
- name: Test HAL
142-
run: cargo test --features ${{ matrix.feature }}
142+
run: cargo test --features ${{ matrix.mcu }},embedded-time
143143

144144
- name: Test nucleo BSP
145145
if: ${{ startsWith(matrix.mcu, 'stm32wl5x') }}
146146
run: |
147-
cargo test -p nucleo-wl55jc-bsp --features ${{ matrix.feature }}
147+
cargo test -p nucleo-wl55jc-bsp --features ${{ matrix.mcu }},embedded-time
148148
149149
- name: Test LoRa E5 BSP
150150
if: ${{ matrix.mcu == 'stm32wle5' }}
151-
run: |
152-
cargo test -p lora-e5-bsp --features ${{ matrix.feature }}
151+
run: cargo test -p lora-e5-bsp --features embedded-time
153152

154153
clippy:
155154
name: Clippy
@@ -203,7 +202,7 @@ jobs:
203202
run: |
204203
cd hal
205204
cargo +nightly rustdoc \
206-
--features rt,stm32wl5x_cm4 \
205+
--features embedded-time,rt,stm32wl5x_cm4 \
207206
-- -Z unstable-options --enable-index-page
208207
- name: deploy
209208
if: ${{ github.ref == 'refs/heads/main' }}

CHANGELOG.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- `info::UID64`
1818
- Moved to `info::Uid64::PTR`.
1919
- Changed the type from `*const u8` to `*const u32`.
20-
- Moved `info::uid64` to `info::Uid64::from_device`.
21-
- Moved `info::uid64_devnum` to `info::Uid64::read_devnum`.
22-
- Moved `info::package` to `info::Package::from_device`.
23-
- Moved `info::uid` to `info::Uid::from_device`.
20+
- Moved functions in `info` into the associated structs/enums.
21+
- Moved `info::uid64` to `info::Uid64::from_device`.
22+
- Moved `info::uid64_devnum` to `info::Uid64::read_devnum`.
23+
- Moved `info::package` to `info::Package::from_device`.
24+
- Moved `info::uid` to `info::Uid::from_device`.
2425
- Added `#[inline]` to `util::new_delay` and `util::reset_cycle_count`.
26+
- `embedded-time` is now an optional feature.
27+
- Changed `I2C::new` to use `u32` instead of `embedded_time::Hertz`.
2528

2629
## [0.2.1] - 2021-11-20
2730
### Fixed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ features = [
3838
"rt",
3939
# optional: use defmt
4040
"defmt",
41+
# optional: enable conversions with embedded-time types
42+
"embedded-time",
4143
]
4244
```
4345

hal/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cortex-m = "0.7.2"
2525
cortex-m-rt = { version = "0.7", optional = true }
2626
defmt = { version = "0.3", optional = true }
2727
embedded-hal = { version = "0.2.6", features = ["unproven"] }
28-
embedded-time = "0.12"
28+
embedded-time = { version = "0.12", optional = true }
2929
nb = "1"
3030
num-traits = { version = "0.2", default-features = false }
3131
paste = "1"
@@ -38,5 +38,5 @@ static_assertions = "1"
3838

3939
[package.metadata.docs.rs]
4040
all-features = false
41-
features = ["stm32wl5x_cm4", "rt"]
41+
features = ["stm32wl5x_cm4", "rt", "embedded-time"]
4242
rustdoc-args = ["--cfg", "docsrs"]

hal/src/i2c.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ use crate::{
88
};
99

1010
use cortex_m::interrupt::CriticalSection;
11-
use embedded_time::{
12-
fixed_point::FixedPoint,
13-
rate::{Extensions, Hertz},
14-
};
1511

1612
/// I2C error
1713
#[derive(Debug)]
@@ -347,12 +343,12 @@ macro_rules! impl_clocks_reset {
347343
}
348344

349345
/// Returns the frequency of the peripheral clock driver
350-
fn clock(rcc: &RCC) -> Hertz {
346+
fn clock(rcc: &RCC) -> u32 {
351347
// NOTE(unsafe) atomic read with no side effects
352348
match rcc.ccipr.read().$i2cXsel().variant().unwrap() {
353-
I2C3SEL_A::HSI16 => Hertz(16_000_000),
354-
I2C3SEL_A::SYSCLK => Hertz(sysclk_hz(rcc)), // TODO move the HAL to embedded-time?
355-
I2C3SEL_A::PCLK => Hertz(pclk1_hz(rcc)),
349+
I2C3SEL_A::HSI16 => 16_000_000,
350+
I2C3SEL_A::SYSCLK => sysclk_hz(rcc),
351+
I2C3SEL_A::PCLK => pclk1_hz(rcc),
356352
}
357353
}
358354
}
@@ -373,12 +369,12 @@ macro_rules! impl_new_free {
373369
///
374370
/// * Frequency is greater than 1 MHz
375371
/// * Resulting TIMINGR fields PRESC, SCLDEL, SCADEL, SCLH, SCLL are out of range
376-
pub fn new(i2c: $I2CX, mut pins: (SCL, SDA), freq: Hertz, rcc: &mut RCC, pullup: bool, cs: &CriticalSection) -> Self
372+
pub fn new(i2c: $I2CX, mut pins: (SCL, SDA), freq_hz: u32, rcc: &mut RCC, pullup: bool, cs: &CriticalSection) -> Self
377373
where
378374
SCL: crate::gpio::sealed::$I2cXScl + crate::gpio::sealed::PinOps,
379375
SDA: crate::gpio::sealed::$I2cXSda + crate::gpio::sealed::PinOps,
380376
{
381-
assert!(freq.integer() <= 1_000_000); // TODO Return Error instead of panic
377+
assert!(freq_hz <= 1_000_000); // TODO Return Error instead of panic
382378

383379
Self::enable_clock(rcc);
384380
Self::pulse_reset(rcc);
@@ -395,7 +391,7 @@ macro_rules! impl_new_free {
395391
pins.1.set_pull(cs, Pull::None);
396392
}
397393

398-
let (presc, scll, sclh, sdadel, scldel) = i2c_clocks(Self::clock(rcc), freq);
394+
let (presc, scll, sclh, sdadel, scldel) = i2c_clocks(Self::clock(rcc), freq_hz);
399395

400396
// Configure for "fast mode" (400 KHz)
401397
// NOTE(write): writes all non-reserved bits.
@@ -505,18 +501,18 @@ i2c!([1, 2, 3]);
505501
/// * SCLH
506502
/// * SDADEL
507503
/// * SCLDEL
508-
fn i2c_clocks(clock: Hertz, freq: Hertz) -> (u8, u8, u8, u8, u8) {
509-
let i2cclk = clock.integer();
510-
let ratio = i2cclk / freq.integer() - 4;
511-
let (presc, scll, sclh, sdadel, scldel) = if freq >= 100.kHz() {
504+
fn i2c_clocks(clock_hz: u32, freq_hz: u32) -> (u8, u8, u8, u8, u8) {
505+
let i2cclk = clock_hz;
506+
let ratio = i2cclk / freq_hz - 4;
507+
let (presc, scll, sclh, sdadel, scldel) = if freq_hz >= 100_000 {
512508
// fast-mode or fast-mode plus
513509
// here we pick SCLL + 1 = 2 * (SCLH + 1)
514510
let presc = ratio / 387;
515511

516512
let sclh = ((ratio / (presc + 1)) - 3) / 3;
517513
let scll = 2 * (sclh + 1) - 1;
518514

519-
let (sdadel, scldel) = if freq > 400.kHz() {
515+
let (sdadel, scldel) = if freq_hz > 400_000 {
520516
// fast-mode plus
521517
let sdadel = 0;
522518
let scldel = i2cclk / 4_000_000 / (presc + 1) - 1;

hal/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,6 @@ pub use cortex_m_rt;
7474
pub use chrono;
7575
pub use cortex_m;
7676
pub use embedded_hal;
77+
78+
#[cfg(feature = "embedded_time")]
7779
pub use embedded_time;

hal/src/subghz/timeout.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,21 @@ impl From<Timeout> for [u8; 3] {
412412
}
413413
}
414414

415+
#[cfg(feature = "embedded_time")]
415416
impl From<Timeout> for embedded_time::duration::Seconds {
416417
fn from(to: Timeout) -> Self {
417418
embedded_time::duration::Seconds(to.as_secs().into())
418419
}
419420
}
420421

422+
#[cfg(feature = "embedded_time")]
421423
impl From<Timeout> for embedded_time::duration::Milliseconds {
422424
fn from(to: Timeout) -> Self {
423425
embedded_time::duration::Milliseconds(to.as_millis())
424426
}
425427
}
426428

429+
#[cfg(feature = "embedded_time")]
427430
impl From<Timeout> for embedded_time::duration::Microseconds {
428431
fn from(to: Timeout) -> Self {
429432
embedded_time::duration::Microseconds(to.as_micros())

hal/src/subghz/tx_params.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl From<RampTime> for core::time::Duration {
4444
}
4545
}
4646

47+
#[cfg(feature = "embedded_time")]
4748
impl From<RampTime> for embedded_time::duration::Microseconds {
4849
fn from(rt: RampTime) -> Self {
4950
match rt {

lora-e5-bsp/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ repository = "https://github.com/stm32-rs/stm32wlxx-hal"
1414

1515
[features]
1616
defmt = ["stm32wlxx-hal/defmt", "dfmt"]
17+
embedded-time = ["stm32wlxx-hal/embedded-time"]
1718
rt = ["stm32wlxx-hal/rt"]
1819

1920
[dependencies.stm32wlxx-hal]
@@ -25,3 +26,8 @@ features = ["stm32wle5"]
2526
package = "defmt"
2627
version = "0.3"
2728
optional = true
29+
30+
[package.metadata.docs.rs]
31+
all-features = false
32+
features = ["rt", "embedded-time"]
33+
rustdoc-args = ["--cfg", "docsrs"]

lora-e5-bsp/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ features = [
1414
"rt",
1515
# optional: use defmt
1616
"defmt",
17+
# optional: enable conversions with embedded-time types
18+
"embedded-time",
1719
]
1820
```
1921

0 commit comments

Comments
 (0)