Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move PllSetup in pll mod #798

Merged
merged 5 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Allow different lengths of buffers in hal_1 SpiBus impl [#566]
- Clean SPI write impls [#774]
- move `ptr()` to `Ptr` trait [#773]
- make `I2sFreq` trait similar to `BusClock` [#796]
- make `I2sFreq` trait similar to `BusClock`, refactor `rcc::Pll` [#796] [#798]
- `steal` UART peripheral on `Rx::new` [#768]

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

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

Expand Down
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ gpio-f401 = [
"tim9",
"tim10",
"tim11",
"rcc_shared_m"
]
gpio-f410 = [
"dac",
Expand Down Expand Up @@ -230,6 +231,7 @@ gpio-f412 = [
"tim13",
"tim14",
"usart3",
"rcc_i2s_apb",
]
gpio-f413 = [
"gpiod",
Expand Down Expand Up @@ -275,6 +277,7 @@ gpio-f413 = [
"uart8",
"uart9",
"uart10",
"rcc_i2s_apb",
]
gpio-f417 = [
"gpiod",
Expand Down Expand Up @@ -313,6 +316,7 @@ gpio-f417 = [
"usart3",
"uart4",
"uart5",
"rcc_shared_m"
]
gpio-f427 = [
"gpiod",
Expand Down Expand Up @@ -360,6 +364,7 @@ gpio-f427 = [
"uart5",
"uart7",
"uart8",
"rcc_shared_m"
]
gpio-f446 = [
"gpiod",
Expand Down Expand Up @@ -401,6 +406,7 @@ gpio-f446 = [
"usart3",
"uart4",
"uart5",
"rcc_i2s_apb",
]
gpio-f469 = [
"gpiod",
Expand Down Expand Up @@ -451,6 +457,7 @@ gpio-f469 = [
"uart5",
"uart7",
"uart8",
"rcc_shared_m"
]

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

# Next features are for internal use only!!!

dfsdm = []
sai = []
rcc_shared_m = []
rcc_i2s_apb = []

adc2 = []
adc3 = []
Expand Down
7 changes: 3 additions & 4 deletions src/fmpi2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ impl<I2C: Instance> I2c<I2C> {
impl<I2C: Instance> I2c<I2C> {
fn i2c_init(&self, mode: impl Into<Mode>) {
let mode = mode.into();
use core::cmp;

// Make sure the I2C unit is disabled so we can configure it
self.i2c.cr1().modify(|_, w| w.pe().clear_bit());
Expand All @@ -167,21 +166,21 @@ impl<I2C: Instance> I2c<I2C> {
match mode {
Mode::Standard { frequency } => {
presc = 3;
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
sclh = scll - 4;
sdadel = 2;
scldel = 4;
}
Mode::Fast { frequency } => {
presc = 1;
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 1, 255) as u8;
sclh = scll - 6;
sdadel = 2;
scldel = 3;
}
Mode::FastPlus { frequency } => {
presc = 0;
scll = cmp::max((((FREQ >> presc) >> 1) / frequency.raw()) - 4, 255) as u8;
scll = crate::max_u32((((FREQ >> presc) >> 1) / frequency.raw()) - 4, 255) as u8;
sclh = scll - 2;
sdadel = 0;
scldel = 2;
Expand Down
8 changes: 4 additions & 4 deletions src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ where

impl I2sFreq for rcc::APB1 {
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
#[cfg(not(feature = "rcc_i2s_apb"))]
{
clocks.i2s_clk()
}
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
#[cfg(feature = "rcc_i2s_apb")]
{
clocks.i2s_apb1_clk()
}
Expand All @@ -69,11 +69,11 @@ impl I2sFreq for rcc::APB1 {

impl I2sFreq for rcc::APB2 {
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
#[cfg(not(feature = "rcc_i2s_apb"))]
{
clocks.i2s_clk()
}
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
#[cfg(feature = "rcc_i2s_apb")]
{
clocks.i2s_apb2_clk()
}
Expand Down
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,20 @@ pub trait Steal {
/// no stolen instances are passed to such software.
unsafe fn steal() -> Self;
}

#[allow(unused)]
const fn max_u32(first: u32, second: u32) -> u32 {
if second > first {
second
} else {
first
}
}

const fn min_u32(first: u32, second: u32) -> u32 {
if second < first {
second
} else {
first
}
}
Loading