Skip to content

Commit 388b0a0

Browse files
authored
Merge pull request #798 from stm32-rs/rcc-i2s
move PllSetup in pll mod
2 parents 513c806 + ea50622 commit 388b0a0

File tree

7 files changed

+347
-317
lines changed

7 files changed

+347
-317
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030
- Allow different lengths of buffers in hal_1 SpiBus impl [#566]
3131
- Clean SPI write impls [#774]
3232
- move `ptr()` to `Ptr` trait [#773]
33-
- make `I2sFreq` trait similar to `BusClock` [#796]
33+
- make `I2sFreq` trait similar to `BusClock`, refactor `rcc::Pll` [#796] [#798]
3434
- `steal` UART peripheral on `Rx::new` [#768]
3535

3636
[#248]: https://github.com/stm32-rs/stm32f4xx-hal/pull/248
@@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5252
[#783]: https://github.com/stm32-rs/stm32f4xx-hal/pull/783
5353
[#785]: https://github.com/stm32-rs/stm32f4xx-hal/pull/785
5454
[#796]: https://github.com/stm32-rs/stm32f4xx-hal/pull/796
55+
[#798]: https://github.com/stm32-rs/stm32f4xx-hal/pull/798
5556

5657
## [v0.21.0] - 2024-05-30
5758

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ gpio-f401 = [
167167
"tim9",
168168
"tim10",
169169
"tim11",
170+
"rcc_shared_m"
170171
]
171172
gpio-f410 = [
172173
"dac",
@@ -230,6 +231,7 @@ gpio-f412 = [
230231
"tim13",
231232
"tim14",
232233
"usart3",
234+
"rcc_i2s_apb",
233235
]
234236
gpio-f413 = [
235237
"gpiod",
@@ -275,6 +277,7 @@ gpio-f413 = [
275277
"uart8",
276278
"uart9",
277279
"uart10",
280+
"rcc_i2s_apb",
278281
]
279282
gpio-f417 = [
280283
"gpiod",
@@ -313,6 +316,7 @@ gpio-f417 = [
313316
"usart3",
314317
"uart4",
315318
"uart5",
319+
"rcc_shared_m"
316320
]
317321
gpio-f427 = [
318322
"gpiod",
@@ -360,6 +364,7 @@ gpio-f427 = [
360364
"uart5",
361365
"uart7",
362366
"uart8",
367+
"rcc_shared_m"
363368
]
364369
gpio-f446 = [
365370
"gpiod",
@@ -401,6 +406,7 @@ gpio-f446 = [
401406
"usart3",
402407
"uart4",
403408
"uart5",
409+
"rcc_i2s_apb",
404410
]
405411
gpio-f469 = [
406412
"gpiod",
@@ -451,6 +457,7 @@ gpio-f469 = [
451457
"uart5",
452458
"uart7",
453459
"uart8",
460+
"rcc_shared_m"
454461
]
455462

456463
## Support monotonic timers and other stuff that can be used by [RTICv1 framework](https://crates.io/crates/cortex-m-rtic)
@@ -490,8 +497,12 @@ fsmc_lcd = ["dep:display-interface", "dep:display-interface-04"]
490497
## SDIO peripheral support. See [sdio-host](https://crates.io/crates/sdio-host)
491498
sdio-host = ["dep:sdio-host"]
492499

500+
# Next features are for internal use only!!!
501+
493502
dfsdm = []
494503
sai = []
504+
rcc_shared_m = []
505+
rcc_i2s_apb = []
495506

496507
adc2 = []
497508
adc3 = []

src/fmpi2c.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ impl<I2C: Instance> I2c<I2C> {
143143
impl<I2C: Instance> I2c<I2C> {
144144
fn i2c_init(&self, mode: impl Into<Mode>) {
145145
let mode = mode.into();
146-
use core::cmp;
147146

148147
// Make sure the I2C unit is disabled so we can configure it
149148
self.i2c.cr1().modify(|_, w| w.pe().clear_bit());
@@ -167,21 +166,21 @@ impl<I2C: Instance> I2c<I2C> {
167166
match mode {
168167
Mode::Standard { frequency } => {
169168
presc = 3;
170-
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
169+
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
171170
sclh = scll - 4;
172171
sdadel = 2;
173172
scldel = 4;
174173
}
175174
Mode::Fast { frequency } => {
176175
presc = 1;
177-
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
176+
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
178177
sclh = scll - 6;
179178
sdadel = 2;
180179
scldel = 3;
181180
}
182181
Mode::FastPlus { frequency } => {
183182
presc = 0;
184-
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 4, 255) as u8;
183+
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 4, 255) as u8;
185184
sclh = scll - 2;
186185
sdadel = 0;
187186
scldel = 2;

src/i2s.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ where
5656

5757
impl I2sFreq for rcc::APB1 {
5858
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
59-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
59+
#[cfg(not(feature = "rcc_i2s_apb"))]
6060
{
6161
clocks.i2s_clk()
6262
}
63-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
63+
#[cfg(feature = "rcc_i2s_apb")]
6464
{
6565
clocks.i2s_apb1_clk()
6666
}
@@ -69,11 +69,11 @@ impl I2sFreq for rcc::APB1 {
6969

7070
impl I2sFreq for rcc::APB2 {
7171
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
72-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
72+
#[cfg(not(feature = "rcc_i2s_apb"))]
7373
{
7474
clocks.i2s_clk()
7575
}
76-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
76+
#[cfg(feature = "rcc_i2s_apb")]
7777
{
7878
clocks.i2s_apb2_clk()
7979
}

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,20 @@ pub trait Steal {
227227
/// no stolen instances are passed to such software.
228228
unsafe fn steal() -> Self;
229229
}
230+
231+
#[allow(unused)]
232+
const fn max_u32(first: u32, second: u32) -> u32 {
233+
if second > first {
234+
second
235+
} else {
236+
first
237+
}
238+
}
239+
240+
const fn min_u32(first: u32, second: u32) -> u32 {
241+
if second < first {
242+
second
243+
} else {
244+
first
245+
}
246+
}

0 commit comments

Comments
 (0)