diff options
23 files changed, 77 insertions, 177 deletions
diff --git a/embassy-stm32/src/i2c/config.rs b/embassy-stm32/src/i2c/config.rs index daae43bcd..b27bb778c 100644 --- a/embassy-stm32/src/i2c/config.rs +++ b/embassy-stm32/src/i2c/config.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #[cfg(gpio_v2)] | 1 | #[cfg(gpio_v2)] |
| 2 | use crate::gpio::Pull; | 2 | use crate::gpio::Pull; |
| 3 | use crate::gpio::{AfType, OutputType, Speed}; | 3 | use crate::gpio::{AfType, OutputType, Speed}; |
| 4 | use crate::time::Hertz; | ||
| 4 | 5 | ||
| 5 | #[repr(u8)] | 6 | #[repr(u8)] |
| 6 | #[derive(Copy, Clone)] | 7 | #[derive(Copy, Clone)] |
| @@ -109,6 +110,10 @@ impl SlaveAddrConfig { | |||
| 109 | #[non_exhaustive] | 110 | #[non_exhaustive] |
| 110 | #[derive(Copy, Clone)] | 111 | #[derive(Copy, Clone)] |
| 111 | pub struct Config { | 112 | pub struct Config { |
| 113 | /// Frequency | ||
| 114 | pub frequency: Hertz, | ||
| 115 | /// GPIO Speed | ||
| 116 | pub gpio_speed: Speed, | ||
| 112 | /// Enable internal pullup on SDA. | 117 | /// Enable internal pullup on SDA. |
| 113 | /// | 118 | /// |
| 114 | /// Using external pullup resistors is recommended for I2C. If you do | 119 | /// Using external pullup resistors is recommended for I2C. If you do |
| @@ -129,6 +134,8 @@ pub struct Config { | |||
| 129 | impl Default for Config { | 134 | impl Default for Config { |
| 130 | fn default() -> Self { | 135 | fn default() -> Self { |
| 131 | Self { | 136 | Self { |
| 137 | frequency: Hertz::khz(100), | ||
| 138 | gpio_speed: Speed::Medium, | ||
| 132 | #[cfg(gpio_v2)] | 139 | #[cfg(gpio_v2)] |
| 133 | sda_pullup: false, | 140 | sda_pullup: false, |
| 134 | #[cfg(gpio_v2)] | 141 | #[cfg(gpio_v2)] |
| @@ -142,11 +149,11 @@ impl Default for Config { | |||
| 142 | impl Config { | 149 | impl Config { |
| 143 | pub(super) fn scl_af(&self) -> AfType { | 150 | pub(super) fn scl_af(&self) -> AfType { |
| 144 | #[cfg(gpio_v1)] | 151 | #[cfg(gpio_v1)] |
| 145 | return AfType::output(OutputType::OpenDrain, Speed::Medium); | 152 | return AfType::output(OutputType::OpenDrain, self.gpio_speed); |
| 146 | #[cfg(gpio_v2)] | 153 | #[cfg(gpio_v2)] |
| 147 | return AfType::output_pull( | 154 | return AfType::output_pull( |
| 148 | OutputType::OpenDrain, | 155 | OutputType::OpenDrain, |
| 149 | Speed::Medium, | 156 | self.gpio_speed, |
| 150 | match self.scl_pullup { | 157 | match self.scl_pullup { |
| 151 | true => Pull::Up, | 158 | true => Pull::Up, |
| 152 | false => Pull::Down, | 159 | false => Pull::Down, |
| @@ -156,11 +163,11 @@ impl Config { | |||
| 156 | 163 | ||
| 157 | pub(super) fn sda_af(&self) -> AfType { | 164 | pub(super) fn sda_af(&self) -> AfType { |
| 158 | #[cfg(gpio_v1)] | 165 | #[cfg(gpio_v1)] |
| 159 | return AfType::output(OutputType::OpenDrain, Speed::Medium); | 166 | return AfType::output(OutputType::OpenDrain, self.gpio_speed); |
| 160 | #[cfg(gpio_v2)] | 167 | #[cfg(gpio_v2)] |
| 161 | return AfType::output_pull( | 168 | return AfType::output_pull( |
| 162 | OutputType::OpenDrain, | 169 | OutputType::OpenDrain, |
| 163 | Speed::Medium, | 170 | self.gpio_speed, |
| 164 | match self.sda_pullup { | 171 | match self.sda_pullup { |
| 165 | true => Pull::Up, | 172 | true => Pull::Up, |
| 166 | false => Pull::Down, | 173 | false => Pull::Down, |
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 825dd240c..5fb49f943 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -158,7 +158,6 @@ impl<'d> I2c<'d, Async, Master> { | |||
| 158 | + 'd, | 158 | + 'd, |
| 159 | tx_dma: Peri<'d, impl TxDma<T>>, | 159 | tx_dma: Peri<'d, impl TxDma<T>>, |
| 160 | rx_dma: Peri<'d, impl RxDma<T>>, | 160 | rx_dma: Peri<'d, impl RxDma<T>>, |
| 161 | freq: Hertz, | ||
| 162 | config: Config, | 161 | config: Config, |
| 163 | ) -> Self { | 162 | ) -> Self { |
| 164 | Self::new_inner( | 163 | Self::new_inner( |
| @@ -167,7 +166,6 @@ impl<'d> I2c<'d, Async, Master> { | |||
| 167 | new_pin!(sda, config.sda_af()), | 166 | new_pin!(sda, config.sda_af()), |
| 168 | new_dma!(tx_dma), | 167 | new_dma!(tx_dma), |
| 169 | new_dma!(rx_dma), | 168 | new_dma!(rx_dma), |
| 170 | freq, | ||
| 171 | config, | 169 | config, |
| 172 | ) | 170 | ) |
| 173 | } | 171 | } |
| @@ -179,7 +177,6 @@ impl<'d> I2c<'d, Blocking, Master> { | |||
| 179 | peri: Peri<'d, T>, | 177 | peri: Peri<'d, T>, |
| 180 | scl: Peri<'d, impl SclPin<T>>, | 178 | scl: Peri<'d, impl SclPin<T>>, |
| 181 | sda: Peri<'d, impl SdaPin<T>>, | 179 | sda: Peri<'d, impl SdaPin<T>>, |
| 182 | freq: Hertz, | ||
| 183 | config: Config, | 180 | config: Config, |
| 184 | ) -> Self { | 181 | ) -> Self { |
| 185 | Self::new_inner( | 182 | Self::new_inner( |
| @@ -188,7 +185,6 @@ impl<'d> I2c<'d, Blocking, Master> { | |||
| 188 | new_pin!(sda, config.sda_af()), | 185 | new_pin!(sda, config.sda_af()), |
| 189 | None, | 186 | None, |
| 190 | None, | 187 | None, |
| 191 | freq, | ||
| 192 | config, | 188 | config, |
| 193 | ) | 189 | ) |
| 194 | } | 190 | } |
| @@ -202,7 +198,6 @@ impl<'d, M: Mode> I2c<'d, M, Master> { | |||
| 202 | sda: Option<Peri<'d, AnyPin>>, | 198 | sda: Option<Peri<'d, AnyPin>>, |
| 203 | tx_dma: Option<ChannelAndRequest<'d>>, | 199 | tx_dma: Option<ChannelAndRequest<'d>>, |
| 204 | rx_dma: Option<ChannelAndRequest<'d>>, | 200 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 205 | freq: Hertz, | ||
| 206 | config: Config, | 201 | config: Config, |
| 207 | ) -> Self { | 202 | ) -> Self { |
| 208 | unsafe { T::EventInterrupt::enable() }; | 203 | unsafe { T::EventInterrupt::enable() }; |
| @@ -224,14 +219,14 @@ impl<'d, M: Mode> I2c<'d, M, Master> { | |||
| 224 | sda, | 219 | sda, |
| 225 | }, | 220 | }, |
| 226 | }; | 221 | }; |
| 227 | this.enable_and_init(freq, config); | 222 | this.enable_and_init(config); |
| 228 | 223 | ||
| 229 | this | 224 | this |
| 230 | } | 225 | } |
| 231 | 226 | ||
| 232 | fn enable_and_init(&mut self, freq: Hertz, config: Config) { | 227 | fn enable_and_init(&mut self, config: Config) { |
| 233 | self.info.rcc.enable_and_reset(); | 228 | self.info.rcc.enable_and_reset(); |
| 234 | self.init(freq, config); | 229 | self.init(config); |
| 235 | } | 230 | } |
| 236 | } | 231 | } |
| 237 | 232 | ||
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 35f13ab46..081eb1191 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -43,7 +43,7 @@ pub unsafe fn on_interrupt<T: Instance>() { | |||
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | impl<'d, M: PeriMode, IM: MasterMode> I2c<'d, M, IM> { | 45 | impl<'d, M: PeriMode, IM: MasterMode> I2c<'d, M, IM> { |
| 46 | pub(crate) fn init(&mut self, freq: Hertz, _config: Config) { | 46 | pub(crate) fn init(&mut self, config: Config) { |
| 47 | self.info.regs.cr1().modify(|reg| { | 47 | self.info.regs.cr1().modify(|reg| { |
| 48 | reg.set_pe(false); | 48 | reg.set_pe(false); |
| 49 | //reg.set_anfoff(false); | 49 | //reg.set_anfoff(false); |
| @@ -75,7 +75,7 @@ impl<'d, M: PeriMode, IM: MasterMode> I2c<'d, M, IM> { | |||
| 75 | reg.set_swrst(false); | 75 | reg.set_swrst(false); |
| 76 | }); | 76 | }); |
| 77 | 77 | ||
| 78 | let timings = Timings::new(self.kernel_clock, freq); | 78 | let timings = Timings::new(self.kernel_clock, config.frequency); |
| 79 | 79 | ||
| 80 | self.info.regs.cr2().modify(|reg| { | 80 | self.info.regs.cr2().modify(|reg| { |
| 81 | reg.set_freq(timings.freq); | 81 | reg.set_freq(timings.freq); |
| @@ -738,15 +738,15 @@ struct Timings { | |||
| 738 | } | 738 | } |
| 739 | 739 | ||
| 740 | impl Timings { | 740 | impl Timings { |
| 741 | fn new(i2cclk: Hertz, speed: Hertz) -> Self { | 741 | fn new(i2cclk: Hertz, frequency: Hertz) -> Self { |
| 742 | // Calculate settings for I2C speed modes | 742 | // Calculate settings for I2C speed modes |
| 743 | let speed = speed.0; | 743 | let frequency = frequency.0; |
| 744 | let clock = i2cclk.0; | 744 | let clock = i2cclk.0; |
| 745 | let freq = clock / 1_000_000; | 745 | let freq = clock / 1_000_000; |
| 746 | assert!((2..=50).contains(&freq)); | 746 | assert!((2..=50).contains(&freq)); |
| 747 | 747 | ||
| 748 | // Configure bus frequency into I2C peripheral | 748 | // Configure bus frequency into I2C peripheral |
| 749 | let trise = if speed <= 100_000 { | 749 | let trise = if frequency <= 100_000 { |
| 750 | freq + 1 | 750 | freq + 1 |
| 751 | } else { | 751 | } else { |
| 752 | (freq * 300) / 1000 + 1 | 752 | (freq * 300) / 1000 + 1 |
| @@ -757,11 +757,11 @@ impl Timings { | |||
| 757 | let mode; | 757 | let mode; |
| 758 | 758 | ||
| 759 | // I2C clock control calculation | 759 | // I2C clock control calculation |
| 760 | if speed <= 100_000 { | 760 | if frequency <= 100_000 { |
| 761 | duty = Duty::Duty2_1; | 761 | duty = Duty::Duty2_1; |
| 762 | mode = Mode::Standard; | 762 | mode = Mode::Standard; |
| 763 | ccr = { | 763 | ccr = { |
| 764 | let ccr = clock / (speed * 2); | 764 | let ccr = clock / (frequency * 2); |
| 765 | if ccr < 4 { | 765 | if ccr < 4 { |
| 766 | 4 | 766 | 4 |
| 767 | } else { | 767 | } else { |
| @@ -773,13 +773,13 @@ impl Timings { | |||
| 773 | mode = Mode::Fast; | 773 | mode = Mode::Fast; |
| 774 | if DUTYCYCLE == 0 { | 774 | if DUTYCYCLE == 0 { |
| 775 | duty = Duty::Duty2_1; | 775 | duty = Duty::Duty2_1; |
| 776 | ccr = clock / (speed * 3); | 776 | ccr = clock / (frequency * 3); |
| 777 | ccr = if ccr < 1 { 1 } else { ccr }; | 777 | ccr = if ccr < 1 { 1 } else { ccr }; |
| 778 | 778 | ||
| 779 | // Set clock to fast mode with appropriate parameters for selected speed (2:1 duty cycle) | 779 | // Set clock to fast mode with appropriate parameters for selected speed (2:1 duty cycle) |
| 780 | } else { | 780 | } else { |
| 781 | duty = Duty::Duty16_9; | 781 | duty = Duty::Duty16_9; |
| 782 | ccr = clock / (speed * 25); | 782 | ccr = clock / (frequency * 25); |
| 783 | ccr = if ccr < 1 { 1 } else { ccr }; | 783 | ccr = if ccr < 1 { 1 } else { ccr }; |
| 784 | 784 | ||
| 785 | // Set clock to fast mode with appropriate parameters for selected speed (16:9 duty cycle) | 785 | // Set clock to fast mode with appropriate parameters for selected speed (16:9 duty cycle) |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index e24cce5c6..4d341bab1 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -93,13 +93,13 @@ pub(crate) unsafe fn on_interrupt<T: Instance>() { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { | 95 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { |
| 96 | pub(crate) fn init(&mut self, freq: Hertz, _config: Config) { | 96 | pub(crate) fn init(&mut self, config: Config) { |
| 97 | self.info.regs.cr1().modify(|reg| { | 97 | self.info.regs.cr1().modify(|reg| { |
| 98 | reg.set_pe(false); | 98 | reg.set_pe(false); |
| 99 | reg.set_anfoff(false); | 99 | reg.set_anfoff(false); |
| 100 | }); | 100 | }); |
| 101 | 101 | ||
| 102 | let timings = Timings::new(self.kernel_clock, freq.into()); | 102 | let timings = Timings::new(self.kernel_clock, config.frequency.into()); |
| 103 | 103 | ||
| 104 | self.info.regs.timingr().write(|reg| { | 104 | self.info.regs.timingr().write(|reg| { |
| 105 | reg.set_presc(timings.prescale); | 105 | reg.set_presc(timings.prescale); |
| @@ -1320,9 +1320,9 @@ struct Timings { | |||
| 1320 | } | 1320 | } |
| 1321 | 1321 | ||
| 1322 | impl Timings { | 1322 | impl Timings { |
| 1323 | fn new(i2cclk: Hertz, freq: Hertz) -> Self { | 1323 | fn new(i2cclk: Hertz, frequency: Hertz) -> Self { |
| 1324 | let i2cclk = i2cclk.0; | 1324 | let i2cclk = i2cclk.0; |
| 1325 | let freq = freq.0; | 1325 | let frequency = frequency.0; |
| 1326 | // Refer to RM0433 Rev 7 Figure 539 for setup and hold timing: | 1326 | // Refer to RM0433 Rev 7 Figure 539 for setup and hold timing: |
| 1327 | // | 1327 | // |
| 1328 | // t_I2CCLK = 1 / PCLK1 | 1328 | // t_I2CCLK = 1 / PCLK1 |
| @@ -1332,13 +1332,13 @@ impl Timings { | |||
| 1332 | // | 1332 | // |
| 1333 | // t_SYNC1 + t_SYNC2 > 4 * t_I2CCLK | 1333 | // t_SYNC1 + t_SYNC2 > 4 * t_I2CCLK |
| 1334 | // t_SCL ~= t_SYNC1 + t_SYNC2 + t_SCLL + t_SCLH | 1334 | // t_SCL ~= t_SYNC1 + t_SYNC2 + t_SCLL + t_SCLH |
| 1335 | let ratio = i2cclk / freq; | 1335 | let ratio = i2cclk / frequency; |
| 1336 | 1336 | ||
| 1337 | // For the standard-mode configuration method, we must have a ratio of 4 | 1337 | // For the standard-mode configuration method, we must have a ratio of 4 |
| 1338 | // or higher | 1338 | // or higher |
| 1339 | assert!(ratio >= 4, "The I2C PCLK must be at least 4 times the bus frequency!"); | 1339 | assert!(ratio >= 4, "The I2C PCLK must be at least 4 times the bus frequency!"); |
| 1340 | 1340 | ||
| 1341 | let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 { | 1341 | let (presc_reg, scll, sclh, sdadel, scldel) = if frequency > 100_000 { |
| 1342 | // Fast-mode (Fm) or Fast-mode Plus (Fm+) | 1342 | // Fast-mode (Fm) or Fast-mode Plus (Fm+) |
| 1343 | // here we pick SCLL + 1 = 2 * (SCLH + 1) | 1343 | // here we pick SCLL + 1 = 2 * (SCLH + 1) |
| 1344 | 1344 | ||
| @@ -1352,7 +1352,7 @@ impl Timings { | |||
| 1352 | let sclh = ((ratio / presc) - 3) / 3; | 1352 | let sclh = ((ratio / presc) - 3) / 3; |
| 1353 | let scll = (2 * (sclh + 1)) - 1; | 1353 | let scll = (2 * (sclh + 1)) - 1; |
| 1354 | 1354 | ||
| 1355 | let (sdadel, scldel) = if freq > 400_000 { | 1355 | let (sdadel, scldel) = if frequency > 400_000 { |
| 1356 | // Fast-mode Plus (Fm+) | 1356 | // Fast-mode Plus (Fm+) |
| 1357 | assert!(i2cclk >= 17_000_000); // See table in datsheet | 1357 | assert!(i2cclk >= 17_000_000); // See table in datsheet |
| 1358 | 1358 | ||
diff --git a/embassy-stm32/src/i2s.rs b/embassy-stm32/src/i2s.rs index 5005a5cdb..a51d21bb0 100644 --- a/embassy-stm32/src/i2s.rs +++ b/embassy-stm32/src/i2s.rs | |||
| @@ -155,6 +155,10 @@ impl ClockPolarity { | |||
| 155 | #[non_exhaustive] | 155 | #[non_exhaustive] |
| 156 | #[derive(Copy, Clone)] | 156 | #[derive(Copy, Clone)] |
| 157 | pub struct Config { | 157 | pub struct Config { |
| 158 | /// Frequency | ||
| 159 | pub frequency: Hertz, | ||
| 160 | /// GPIO Speed | ||
| 161 | pub gpio_speed: Speed, | ||
| 158 | /// Mode | 162 | /// Mode |
| 159 | pub mode: Mode, | 163 | pub mode: Mode, |
| 160 | /// Which I2S standard to use. | 164 | /// Which I2S standard to use. |
| @@ -170,6 +174,8 @@ pub struct Config { | |||
| 170 | impl Default for Config { | 174 | impl Default for Config { |
| 171 | fn default() -> Self { | 175 | fn default() -> Self { |
| 172 | Self { | 176 | Self { |
| 177 | frequency: Hertz::khz(48), | ||
| 178 | gpio_speed: Speed::VeryHigh, | ||
| 173 | mode: Mode::Master, | 179 | mode: Mode::Master, |
| 174 | standard: Standard::Philips, | 180 | standard: Standard::Philips, |
| 175 | format: Format::Data16Channel16, | 181 | format: Format::Data16Channel16, |
| @@ -243,7 +249,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 243 | mck: Peri<'d, impl MckPin<T>>, | 249 | mck: Peri<'d, impl MckPin<T>>, |
| 244 | txdma: Peri<'d, impl TxDma<T>>, | 250 | txdma: Peri<'d, impl TxDma<T>>, |
| 245 | txdma_buf: &'d mut [W], | 251 | txdma_buf: &'d mut [W], |
| 246 | freq: Hertz, | ||
| 247 | config: Config, | 252 | config: Config, |
| 248 | ) -> Self { | 253 | ) -> Self { |
| 249 | Self::new_inner( | 254 | Self::new_inner( |
| @@ -255,7 +260,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 255 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 260 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 256 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 261 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 257 | None, | 262 | None, |
| 258 | freq, | ||
| 259 | config, | 263 | config, |
| 260 | Function::Transmit, | 264 | Function::Transmit, |
| 261 | ) | 265 | ) |
| @@ -269,7 +273,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 269 | ck: Peri<'d, impl CkPin<T>>, | 273 | ck: Peri<'d, impl CkPin<T>>, |
| 270 | txdma: Peri<'d, impl TxDma<T>>, | 274 | txdma: Peri<'d, impl TxDma<T>>, |
| 271 | txdma_buf: &'d mut [W], | 275 | txdma_buf: &'d mut [W], |
| 272 | freq: Hertz, | ||
| 273 | config: Config, | 276 | config: Config, |
| 274 | ) -> Self { | 277 | ) -> Self { |
| 275 | Self::new_inner( | 278 | Self::new_inner( |
| @@ -281,7 +284,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 281 | None, | 284 | None, |
| 282 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 285 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 283 | None, | 286 | None, |
| 284 | freq, | ||
| 285 | config, | 287 | config, |
| 286 | Function::Transmit, | 288 | Function::Transmit, |
| 287 | ) | 289 | ) |
| @@ -296,7 +298,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 296 | mck: Peri<'d, impl MckPin<T>>, | 298 | mck: Peri<'d, impl MckPin<T>>, |
| 297 | rxdma: Peri<'d, impl RxDma<T>>, | 299 | rxdma: Peri<'d, impl RxDma<T>>, |
| 298 | rxdma_buf: &'d mut [W], | 300 | rxdma_buf: &'d mut [W], |
| 299 | freq: Hertz, | ||
| 300 | config: Config, | 301 | config: Config, |
| 301 | ) -> Self { | 302 | ) -> Self { |
| 302 | Self::new_inner( | 303 | Self::new_inner( |
| @@ -308,7 +309,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 308 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 309 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 309 | None, | 310 | None, |
| 310 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), | 311 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), |
| 311 | freq, | ||
| 312 | config, | 312 | config, |
| 313 | Function::Receive, | 313 | Function::Receive, |
| 314 | ) | 314 | ) |
| @@ -327,7 +327,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 327 | txdma_buf: &'d mut [W], | 327 | txdma_buf: &'d mut [W], |
| 328 | rxdma: Peri<'d, impl RxDma<T>>, | 328 | rxdma: Peri<'d, impl RxDma<T>>, |
| 329 | rxdma_buf: &'d mut [W], | 329 | rxdma_buf: &'d mut [W], |
| 330 | freq: Hertz, | ||
| 331 | config: Config, | 330 | config: Config, |
| 332 | ) -> Self { | 331 | ) -> Self { |
| 333 | Self::new_inner( | 332 | Self::new_inner( |
| @@ -339,7 +338,6 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 339 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), | 338 | new_pin!(mck, AfType::output(OutputType::PushPull, Speed::VeryHigh)), |
| 340 | new_dma!(txdma).map(|d| (d, txdma_buf)), | 339 | new_dma!(txdma).map(|d| (d, txdma_buf)), |
| 341 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), | 340 | new_dma!(rxdma).map(|d| (d, rxdma_buf)), |
| 342 | freq, | ||
| 343 | config, | 341 | config, |
| 344 | Function::FullDuplex, | 342 | Function::FullDuplex, |
| 345 | ) | 343 | ) |
| @@ -473,17 +471,16 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 473 | mck: Option<Peri<'d, AnyPin>>, | 471 | mck: Option<Peri<'d, AnyPin>>, |
| 474 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 472 | txdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 475 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, | 473 | rxdma: Option<(ChannelAndRequest<'d>, &'d mut [W])>, |
| 476 | freq: Hertz, | ||
| 477 | config: Config, | 474 | config: Config, |
| 478 | function: Function, | 475 | function: Function, |
| 479 | ) -> Self { | 476 | ) -> Self { |
| 480 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 477 | ws.set_as_af(ws.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 481 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, Speed::VeryHigh)); | 478 | ck.set_as_af(ck.af_num(), AfType::output(OutputType::PushPull, config.gpio_speed)); |
| 482 | 479 | ||
| 483 | let spi = Spi::new_internal(peri, None, None, { | 480 | let spi = Spi::new_internal(peri, None, None, { |
| 484 | let mut config = SpiConfig::default(); | 481 | let mut spi_config = SpiConfig::default(); |
| 485 | config.frequency = freq; | 482 | spi_config.frequency = config.frequency; |
| 486 | config | 483 | spi_config |
| 487 | }); | 484 | }); |
| 488 | 485 | ||
| 489 | let regs = T::info().regs; | 486 | let regs = T::info().regs; |
| @@ -493,7 +490,7 @@ impl<'d, W: Word> I2S<'d, W> { | |||
| 493 | #[cfg(not(all(rcc_f4, not(stm32f410))))] | 490 | #[cfg(not(all(rcc_f4, not(stm32f410))))] |
| 494 | let pclk = T::frequency(); | 491 | let pclk = T::frequency(); |
| 495 | 492 | ||
| 496 | let (odd, div) = compute_baud_rate(pclk, freq, config.master_clock, config.format); | 493 | let (odd, div) = compute_baud_rate(pclk, config.frequency, config.master_clock, config.format); |
| 497 | 494 | ||
| 498 | #[cfg(any(spi_v1, spi_v3, spi_f1))] | 495 | #[cfg(any(spi_v1, spi_v3, spi_f1))] |
| 499 | { | 496 | { |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index c8d83f07e..4c5308eba 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -71,7 +71,7 @@ pub struct Config { | |||
| 71 | pub miso_pull: Pull, | 71 | pub miso_pull: Pull, |
| 72 | /// signal rise/fall speed (slew rate) - defaults to `Medium`. | 72 | /// signal rise/fall speed (slew rate) - defaults to `Medium`. |
| 73 | /// Increase for high SPI speeds. Change to `Low` to reduce ringing. | 73 | /// Increase for high SPI speeds. Change to `Low` to reduce ringing. |
| 74 | pub rise_fall_speed: Speed, | 74 | pub gpio_speed: Speed, |
| 75 | } | 75 | } |
| 76 | 76 | ||
| 77 | impl Default for Config { | 77 | impl Default for Config { |
| @@ -81,7 +81,7 @@ impl Default for Config { | |||
| 81 | bit_order: BitOrder::MsbFirst, | 81 | bit_order: BitOrder::MsbFirst, |
| 82 | frequency: Hertz(1_000_000), | 82 | frequency: Hertz(1_000_000), |
| 83 | miso_pull: Pull::None, | 83 | miso_pull: Pull::None, |
| 84 | rise_fall_speed: Speed::VeryHigh, | 84 | gpio_speed: Speed::VeryHigh, |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| @@ -110,14 +110,14 @@ impl Config { | |||
| 110 | 110 | ||
| 111 | #[cfg(gpio_v1)] | 111 | #[cfg(gpio_v1)] |
| 112 | fn sck_af(&self) -> AfType { | 112 | fn sck_af(&self) -> AfType { |
| 113 | AfType::output(OutputType::PushPull, self.rise_fall_speed) | 113 | AfType::output(OutputType::PushPull, self.gpio_speed) |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | #[cfg(gpio_v2)] | 116 | #[cfg(gpio_v2)] |
| 117 | fn sck_af(&self) -> AfType { | 117 | fn sck_af(&self) -> AfType { |
| 118 | AfType::output_pull( | 118 | AfType::output_pull( |
| 119 | OutputType::PushPull, | 119 | OutputType::PushPull, |
| 120 | self.rise_fall_speed, | 120 | self.gpio_speed, |
| 121 | match self.mode.polarity { | 121 | match self.mode.polarity { |
| 122 | Polarity::IdleLow => Pull::Down, | 122 | Polarity::IdleLow => Pull::Down, |
| 123 | Polarity::IdleHigh => Pull::Up, | 123 | Polarity::IdleHigh => Pull::Up, |
| @@ -136,7 +136,7 @@ pub struct Spi<'d, M: PeriMode> { | |||
| 136 | rx_dma: Option<ChannelAndRequest<'d>>, | 136 | rx_dma: Option<ChannelAndRequest<'d>>, |
| 137 | _phantom: PhantomData<M>, | 137 | _phantom: PhantomData<M>, |
| 138 | current_word_size: word_impl::Config, | 138 | current_word_size: word_impl::Config, |
| 139 | rise_fall_speed: Speed, | 139 | gpio_speed: Speed, |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | impl<'d, M: PeriMode> Spi<'d, M> { | 142 | impl<'d, M: PeriMode> Spi<'d, M> { |
| @@ -159,7 +159,7 @@ impl<'d, M: PeriMode> Spi<'d, M> { | |||
| 159 | rx_dma, | 159 | rx_dma, |
| 160 | current_word_size: <u8 as SealedWord>::CONFIG, | 160 | current_word_size: <u8 as SealedWord>::CONFIG, |
| 161 | _phantom: PhantomData, | 161 | _phantom: PhantomData, |
| 162 | rise_fall_speed: config.rise_fall_speed, | 162 | gpio_speed: config.gpio_speed, |
| 163 | }; | 163 | }; |
| 164 | this.enable_and_init(config); | 164 | this.enable_and_init(config); |
| 165 | this | 165 | this |
| @@ -265,12 +265,12 @@ impl<'d, M: PeriMode> Spi<'d, M> { | |||
| 265 | 265 | ||
| 266 | #[cfg(gpio_v2)] | 266 | #[cfg(gpio_v2)] |
| 267 | { | 267 | { |
| 268 | self.rise_fall_speed = config.rise_fall_speed; | 268 | self.gpio_speed = config.gpio_speed; |
| 269 | if let Some(sck) = self.sck.as_ref() { | 269 | if let Some(sck) = self.sck.as_ref() { |
| 270 | sck.set_speed(config.rise_fall_speed); | 270 | sck.set_speed(config.gpio_speed); |
| 271 | } | 271 | } |
| 272 | if let Some(mosi) = self.mosi.as_ref() { | 272 | if let Some(mosi) = self.mosi.as_ref() { |
| 273 | mosi.set_speed(config.rise_fall_speed); | 273 | mosi.set_speed(config.gpio_speed); |
| 274 | } | 274 | } |
| 275 | } | 275 | } |
| 276 | 276 | ||
| @@ -347,7 +347,7 @@ impl<'d, M: PeriMode> Spi<'d, M> { | |||
| 347 | bit_order, | 347 | bit_order, |
| 348 | frequency, | 348 | frequency, |
| 349 | miso_pull, | 349 | miso_pull, |
| 350 | rise_fall_speed: self.rise_fall_speed, | 350 | gpio_speed: self.gpio_speed, |
| 351 | } | 351 | } |
| 352 | } | 352 | } |
| 353 | 353 | ||
| @@ -481,7 +481,7 @@ impl<'d> Spi<'d, Blocking> { | |||
| 481 | Self::new_inner( | 481 | Self::new_inner( |
| 482 | peri, | 482 | peri, |
| 483 | new_pin!(sck, config.sck_af()), | 483 | new_pin!(sck, config.sck_af()), |
| 484 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 484 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 485 | new_pin!(miso, AfType::input(config.miso_pull)), | 485 | new_pin!(miso, AfType::input(config.miso_pull)), |
| 486 | None, | 486 | None, |
| 487 | None, | 487 | None, |
| @@ -517,7 +517,7 @@ impl<'d> Spi<'d, Blocking> { | |||
| 517 | Self::new_inner( | 517 | Self::new_inner( |
| 518 | peri, | 518 | peri, |
| 519 | new_pin!(sck, config.sck_af()), | 519 | new_pin!(sck, config.sck_af()), |
| 520 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 520 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 521 | None, | 521 | None, |
| 522 | None, | 522 | None, |
| 523 | None, | 523 | None, |
| @@ -536,7 +536,7 @@ impl<'d> Spi<'d, Blocking> { | |||
| 536 | Self::new_inner( | 536 | Self::new_inner( |
| 537 | peri, | 537 | peri, |
| 538 | None, | 538 | None, |
| 539 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 539 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 540 | None, | 540 | None, |
| 541 | None, | 541 | None, |
| 542 | None, | 542 | None, |
| @@ -559,7 +559,7 @@ impl<'d> Spi<'d, Async> { | |||
| 559 | Self::new_inner( | 559 | Self::new_inner( |
| 560 | peri, | 560 | peri, |
| 561 | new_pin!(sck, config.sck_af()), | 561 | new_pin!(sck, config.sck_af()), |
| 562 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 562 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 563 | new_pin!(miso, AfType::input(config.miso_pull)), | 563 | new_pin!(miso, AfType::input(config.miso_pull)), |
| 564 | new_dma!(tx_dma), | 564 | new_dma!(tx_dma), |
| 565 | new_dma!(rx_dma), | 565 | new_dma!(rx_dma), |
| @@ -601,7 +601,7 @@ impl<'d> Spi<'d, Async> { | |||
| 601 | Self::new_inner( | 601 | Self::new_inner( |
| 602 | peri, | 602 | peri, |
| 603 | new_pin!(sck, config.sck_af()), | 603 | new_pin!(sck, config.sck_af()), |
| 604 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 604 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 605 | None, | 605 | None, |
| 606 | new_dma!(tx_dma), | 606 | new_dma!(tx_dma), |
| 607 | None, | 607 | None, |
| @@ -621,7 +621,7 @@ impl<'d> Spi<'d, Async> { | |||
| 621 | Self::new_inner( | 621 | Self::new_inner( |
| 622 | peri, | 622 | peri, |
| 623 | None, | 623 | None, |
| 624 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.rise_fall_speed)), | 624 | new_pin!(mosi, AfType::output(OutputType::PushPull, config.gpio_speed)), |
| 625 | None, | 625 | None, |
| 626 | new_dma!(tx_dma), | 626 | new_dma!(tx_dma), |
| 627 | None, | 627 | None, |
diff --git a/examples/stm32f4/src/bin/i2c.rs b/examples/stm32f4/src/bin/i2c.rs index 4a96357a4..49710a92a 100644 --- a/examples/stm32f4/src/bin/i2c.rs +++ b/examples/stm32f4/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::{Error, I2c}; | 6 | use embassy_stm32::i2c::{Error, I2c}; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 8 | ||
| 10 | const ADDRESS: u8 = 0x5F; | 9 | const ADDRESS: u8 = 0x5F; |
| @@ -15,7 +14,7 @@ async fn main(_spawner: Spawner) { | |||
| 15 | info!("Hello world!"); | 14 | info!("Hello world!"); |
| 16 | let p = embassy_stm32::init(Default::default()); | 15 | let p = embassy_stm32::init(Default::default()); |
| 17 | 16 | ||
| 18 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Hertz(100_000), Default::default()); | 17 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Default::default()); |
| 19 | 18 | ||
| 20 | let mut data = [0u8; 1]; | 19 | let mut data = [0u8; 1]; |
| 21 | 20 | ||
diff --git a/examples/stm32f4/src/bin/i2c_async.rs b/examples/stm32f4/src/bin/i2c_async.rs index 90d11d4b4..0065e92f3 100644 --- a/examples/stm32f4/src/bin/i2c_async.rs +++ b/examples/stm32f4/src/bin/i2c_async.rs | |||
| @@ -7,7 +7,6 @@ | |||
| 7 | use defmt::*; | 7 | use defmt::*; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::i2c::I2c; | 9 | use embassy_stm32::i2c::I2c; |
| 10 | use embassy_stm32::time::Hertz; | ||
| 11 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 10 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 12 | ||
| @@ -23,16 +22,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | info!("Hello world!"); | 22 | info!("Hello world!"); |
| 24 | let p = embassy_stm32::init(Default::default()); | 23 | let p = embassy_stm32::init(Default::default()); |
| 25 | 24 | ||
| 26 | let mut i2c = I2c::new( | 25 | let mut i2c = I2c::new(p.I2C1, p.PB8, p.PB7, Irqs, p.DMA1_CH6, p.DMA1_CH0, Default::default()); |
| 27 | p.I2C1, | ||
| 28 | p.PB8, | ||
| 29 | p.PB7, | ||
| 30 | Irqs, | ||
| 31 | p.DMA1_CH6, | ||
| 32 | p.DMA1_CH0, | ||
| 33 | Hertz(100_000), | ||
| 34 | Default::default(), | ||
| 35 | ); | ||
| 36 | 26 | ||
| 37 | loop { | 27 | loop { |
| 38 | let a1454_read_sensor_command = [0x1F]; | 28 | let a1454_read_sensor_command = [0x1F]; |
diff --git a/examples/stm32f4/src/bin/i2c_comparison.rs b/examples/stm32f4/src/bin/i2c_comparison.rs index 55c4891e3..59bdb8b67 100644 --- a/examples/stm32f4/src/bin/i2c_comparison.rs +++ b/examples/stm32f4/src/bin/i2c_comparison.rs | |||
| @@ -10,7 +10,6 @@ | |||
| 10 | use defmt::*; | 10 | use defmt::*; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_stm32::i2c::I2c; | 12 | use embassy_stm32::i2c::I2c; |
| 13 | use embassy_stm32::time::Hertz; | ||
| 14 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 13 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 15 | use embassy_time::Instant; | 14 | use embassy_time::Instant; |
| 16 | use futures_util::future::try_join3; | 15 | use futures_util::future::try_join3; |
| @@ -48,38 +47,11 @@ async fn main(_spawner: Spawner) { | |||
| 48 | info!("Setting up peripherals."); | 47 | info!("Setting up peripherals."); |
| 49 | let p = embassy_stm32::init(Default::default()); | 48 | let p = embassy_stm32::init(Default::default()); |
| 50 | 49 | ||
| 51 | let mut i2c1 = I2c::new( | 50 | let mut i2c1 = I2c::new(p.I2C1, p.PB8, p.PB7, Irqs, p.DMA1_CH6, p.DMA1_CH0, Default::default()); |
| 52 | p.I2C1, | ||
| 53 | p.PB8, | ||
| 54 | p.PB7, | ||
| 55 | Irqs, | ||
| 56 | p.DMA1_CH6, | ||
| 57 | p.DMA1_CH0, | ||
| 58 | Hertz(100_000), | ||
| 59 | Default::default(), | ||
| 60 | ); | ||
| 61 | 51 | ||
| 62 | let mut i2c2 = I2c::new( | 52 | let mut i2c2 = I2c::new(p.I2C2, p.PB10, p.PB11, Irqs, p.DMA1_CH7, p.DMA1_CH3, Default::default()); |
| 63 | p.I2C2, | ||
| 64 | p.PB10, | ||
| 65 | p.PB11, | ||
| 66 | Irqs, | ||
| 67 | p.DMA1_CH7, | ||
| 68 | p.DMA1_CH3, | ||
| 69 | Hertz(100_000), | ||
| 70 | Default::default(), | ||
| 71 | ); | ||
| 72 | 53 | ||
| 73 | let mut i2c3 = I2c::new( | 54 | let mut i2c3 = I2c::new(p.I2C3, p.PA8, p.PC9, Irqs, p.DMA1_CH4, p.DMA1_CH2, Default::default()); |
| 74 | p.I2C3, | ||
| 75 | p.PA8, | ||
| 76 | p.PC9, | ||
| 77 | Irqs, | ||
| 78 | p.DMA1_CH4, | ||
| 79 | p.DMA1_CH2, | ||
| 80 | Hertz(100_000), | ||
| 81 | Default::default(), | ||
| 82 | ); | ||
| 83 | 55 | ||
| 84 | let a1454_read_sensor_command = [0x1F]; | 56 | let a1454_read_sensor_command = [0x1F]; |
| 85 | let mut i2c1_buffer: [u8; 4] = [0, 0, 0, 0]; | 57 | let mut i2c1_buffer: [u8; 4] = [0, 0, 0, 0]; |
diff --git a/examples/stm32f4/src/bin/i2s_dma.rs b/examples/stm32f4/src/bin/i2s_dma.rs index db5103d0f..6051a3c5a 100644 --- a/examples/stm32f4/src/bin/i2s_dma.rs +++ b/examples/stm32f4/src/bin/i2s_dma.rs | |||
| @@ -72,7 +72,6 @@ async fn main(_spawner: Spawner) { | |||
| 72 | p.PB3, // ck | 72 | p.PB3, // ck |
| 73 | p.DMA1_CH7, | 73 | p.DMA1_CH7, |
| 74 | &mut dma_buffer, | 74 | &mut dma_buffer, |
| 75 | Hertz(48_000), | ||
| 76 | i2s_config, | 75 | i2s_config, |
| 77 | ); | 76 | ); |
| 78 | i2s.start(); | 77 | i2s.start(); |
diff --git a/examples/stm32g0/src/bin/i2c_async.rs b/examples/stm32g0/src/bin/i2c_async.rs index 7e3189b05..e62d9266b 100644 --- a/examples/stm32g0/src/bin/i2c_async.rs +++ b/examples/stm32g0/src/bin/i2c_async.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::{self, I2c}; | 6 | use embassy_stm32::i2c::{self, I2c}; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::{bind_interrupts, peripherals}; | 7 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 9 | use embassy_time::{Duration, Timer}; | 8 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -23,16 +22,7 @@ async fn main(_spawner: Spawner) { | |||
| 23 | let p = embassy_stm32::init(Default::default()); | 22 | let p = embassy_stm32::init(Default::default()); |
| 24 | 23 | ||
| 25 | let mut data = [0u8; 2]; | 24 | let mut data = [0u8; 2]; |
| 26 | let mut i2c = I2c::new( | 25 | let mut i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, p.DMA1_CH1, p.DMA1_CH2, Default::default()); |
| 27 | p.I2C1, | ||
| 28 | p.PB8, | ||
| 29 | p.PB9, | ||
| 30 | Irqs, | ||
| 31 | p.DMA1_CH1, | ||
| 32 | p.DMA1_CH2, | ||
| 33 | Hertz(100_000), | ||
| 34 | Default::default(), | ||
| 35 | ); | ||
| 36 | 26 | ||
| 37 | loop { | 27 | loop { |
| 38 | match i2c.write_read(TMP117_ADDR, &[TMP117_TEMP_RESULT], &mut data).await { | 28 | match i2c.write_read(TMP117_ADDR, &[TMP117_TEMP_RESULT], &mut data).await { |
diff --git a/examples/stm32g4/src/bin/i2c_slave.rs b/examples/stm32g4/src/bin/i2c_slave.rs index a723a0e18..8b255b0e6 100644 --- a/examples/stm32g4/src/bin/i2c_slave.rs +++ b/examples/stm32g4/src/bin/i2c_slave.rs | |||
| @@ -127,8 +127,8 @@ async fn main(spawner: Spawner) { | |||
| 127 | let p = embassy_stm32::init(Default::default()); | 127 | let p = embassy_stm32::init(Default::default()); |
| 128 | info!("Hello World!"); | 128 | info!("Hello World!"); |
| 129 | 129 | ||
| 130 | let speed = Hertz::khz(400); | 130 | let mut config = i2c::Config::default(); |
| 131 | let config = i2c::Config::default(); | 131 | config.frequency = Hertz::khz(400); |
| 132 | 132 | ||
| 133 | let d_addr_config = i2c::SlaveAddrConfig { | 133 | let d_addr_config = i2c::SlaveAddrConfig { |
| 134 | addr: OwnAddresses::OA1(Address::SevenBit(DEV_ADDR)), | 134 | addr: OwnAddresses::OA1(Address::SevenBit(DEV_ADDR)), |
| @@ -136,14 +136,14 @@ async fn main(spawner: Spawner) { | |||
| 136 | }; | 136 | }; |
| 137 | let d_sda = p.PA8; | 137 | let d_sda = p.PA8; |
| 138 | let d_scl = p.PA9; | 138 | let d_scl = p.PA9; |
| 139 | let device = i2c::I2c::new(p.I2C2, d_scl, d_sda, Irqs, p.DMA1_CH1, p.DMA1_CH2, speed, config) | 139 | let device = |
| 140 | .into_slave_multimaster(d_addr_config); | 140 | i2c::I2c::new(p.I2C2, d_scl, d_sda, Irqs, p.DMA1_CH1, p.DMA1_CH2, config).into_slave_multimaster(d_addr_config); |
| 141 | 141 | ||
| 142 | unwrap!(spawner.spawn(device_task(device))); | 142 | unwrap!(spawner.spawn(device_task(device))); |
| 143 | 143 | ||
| 144 | let c_sda = p.PB8; | 144 | let c_sda = p.PB8; |
| 145 | let c_scl = p.PB7; | 145 | let c_scl = p.PB7; |
| 146 | let controller = i2c::I2c::new(p.I2C1, c_sda, c_scl, Irqs, p.DMA1_CH3, p.DMA1_CH4, speed, config); | 146 | let controller = i2c::I2c::new(p.I2C1, c_sda, c_scl, Irqs, p.DMA1_CH3, p.DMA1_CH4, config); |
| 147 | 147 | ||
| 148 | unwrap!(spawner.spawn(controller_task(controller))); | 148 | unwrap!(spawner.spawn(controller_task(controller))); |
| 149 | } | 149 | } |
diff --git a/examples/stm32h5/src/bin/i2c.rs b/examples/stm32h5/src/bin/i2c.rs index 31e83cbb5..870c57e0f 100644 --- a/examples/stm32h5/src/bin/i2c.rs +++ b/examples/stm32h5/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::{Error, I2c}; | 6 | use embassy_stm32::i2c::{Error, I2c}; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 7 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| @@ -28,7 +27,6 @@ async fn main(_spawner: Spawner) { | |||
| 28 | Irqs, | 27 | Irqs, |
| 29 | p.GPDMA1_CH4, | 28 | p.GPDMA1_CH4, |
| 30 | p.GPDMA1_CH5, | 29 | p.GPDMA1_CH5, |
| 31 | Hertz(100_000), | ||
| 32 | Default::default(), | 30 | Default::default(), |
| 33 | ); | 31 | ); |
| 34 | 32 | ||
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 170a5aa28..8f2e265d6 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs | |||
| @@ -6,7 +6,6 @@ use embassy_stm32::dcmi::{self, *}; | |||
| 6 | use embassy_stm32::gpio::{Level, Output, Speed}; | 6 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 7 | use embassy_stm32::i2c::I2c; | 7 | use embassy_stm32::i2c::I2c; |
| 8 | use embassy_stm32::rcc::{Mco, Mco1Source, McoPrescaler}; | 8 | use embassy_stm32::rcc::{Mco, Mco1Source, McoPrescaler}; |
| 9 | use embassy_stm32::time::khz; | ||
| 10 | use embassy_stm32::{bind_interrupts, i2c, peripherals, Config}; | 9 | use embassy_stm32::{bind_interrupts, i2c, peripherals, Config}; |
| 11 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 12 | use ov7725::*; | 11 | use ov7725::*; |
| @@ -52,16 +51,7 @@ async fn main(_spawner: Spawner) { | |||
| 52 | let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV3); | 51 | let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::HSI, McoPrescaler::DIV3); |
| 53 | 52 | ||
| 54 | let mut led = Output::new(p.PE3, Level::High, Speed::Low); | 53 | let mut led = Output::new(p.PE3, Level::High, Speed::Low); |
| 55 | let cam_i2c = I2c::new( | 54 | let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, p.DMA1_CH1, p.DMA1_CH2, Default::default()); |
| 56 | p.I2C1, | ||
| 57 | p.PB8, | ||
| 58 | p.PB9, | ||
| 59 | Irqs, | ||
| 60 | p.DMA1_CH1, | ||
| 61 | p.DMA1_CH2, | ||
| 62 | khz(100), | ||
| 63 | Default::default(), | ||
| 64 | ); | ||
| 65 | 55 | ||
| 66 | let mut camera = Ov7725::new(cam_i2c, mco); | 56 | let mut camera = Ov7725::new(cam_i2c, mco); |
| 67 | 57 | ||
diff --git a/examples/stm32h7/src/bin/i2c.rs b/examples/stm32h7/src/bin/i2c.rs index 3bf39eb44..c40af4935 100644 --- a/examples/stm32h7/src/bin/i2c.rs +++ b/examples/stm32h7/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::{Error, I2c}; | 6 | use embassy_stm32::i2c::{Error, I2c}; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 7 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| @@ -21,16 +20,7 @@ async fn main(_spawner: Spawner) { | |||
| 21 | info!("Hello world!"); | 20 | info!("Hello world!"); |
| 22 | let p = embassy_stm32::init(Default::default()); | 21 | let p = embassy_stm32::init(Default::default()); |
| 23 | 22 | ||
| 24 | let mut i2c = I2c::new( | 23 | let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, Irqs, p.DMA1_CH4, p.DMA1_CH5, Default::default()); |
| 25 | p.I2C2, | ||
| 26 | p.PB10, | ||
| 27 | p.PB11, | ||
| 28 | Irqs, | ||
| 29 | p.DMA1_CH4, | ||
| 30 | p.DMA1_CH5, | ||
| 31 | Hertz(100_000), | ||
| 32 | Default::default(), | ||
| 33 | ); | ||
| 34 | 24 | ||
| 35 | let mut data = [0u8; 1]; | 25 | let mut data = [0u8; 1]; |
| 36 | 26 | ||
diff --git a/examples/stm32h7/src/bin/i2c_shared.rs b/examples/stm32h7/src/bin/i2c_shared.rs index 655ff901f..560f97aa3 100644 --- a/examples/stm32h7/src/bin/i2c_shared.rs +++ b/examples/stm32h7/src/bin/i2c_shared.rs | |||
| @@ -8,7 +8,6 @@ use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; | |||
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::i2c::{self, I2c}; | 9 | use embassy_stm32::i2c::{self, I2c}; |
| 10 | use embassy_stm32::mode::Async; | 10 | use embassy_stm32::mode::Async; |
| 11 | use embassy_stm32::time::Hertz; | ||
| 12 | use embassy_stm32::{bind_interrupts, peripherals}; | 11 | use embassy_stm32::{bind_interrupts, peripherals}; |
| 13 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; | 12 | use embassy_sync::blocking_mutex::raw::NoopRawMutex; |
| 14 | use embassy_sync::blocking_mutex::NoopMutex; | 13 | use embassy_sync::blocking_mutex::NoopMutex; |
| @@ -90,16 +89,7 @@ async fn humidity(mut i2c: I2cDevice<'static, NoopRawMutex, I2c<'static, Async, | |||
| 90 | async fn main(spawner: Spawner) { | 89 | async fn main(spawner: Spawner) { |
| 91 | let p = embassy_stm32::init(Default::default()); | 90 | let p = embassy_stm32::init(Default::default()); |
| 92 | 91 | ||
| 93 | let i2c = I2c::new( | 92 | let i2c = I2c::new(p.I2C1, p.PB8, p.PB9, Irqs, p.DMA1_CH4, p.DMA1_CH5, Default::default()); |
| 94 | p.I2C1, | ||
| 95 | p.PB8, | ||
| 96 | p.PB9, | ||
| 97 | Irqs, | ||
| 98 | p.DMA1_CH4, | ||
| 99 | p.DMA1_CH5, | ||
| 100 | Hertz(100_000), | ||
| 101 | Default::default(), | ||
| 102 | ); | ||
| 103 | let i2c_bus = NoopMutex::new(RefCell::new(i2c)); | 93 | let i2c_bus = NoopMutex::new(RefCell::new(i2c)); |
| 104 | let i2c_bus = I2C_BUS.init(i2c_bus); | 94 | let i2c_bus = I2C_BUS.init(i2c_bus); |
| 105 | 95 | ||
diff --git a/examples/stm32h7rs/src/bin/i2c.rs b/examples/stm32h7rs/src/bin/i2c.rs index 31e83cbb5..870c57e0f 100644 --- a/examples/stm32h7rs/src/bin/i2c.rs +++ b/examples/stm32h7rs/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::{Error, I2c}; | 6 | use embassy_stm32::i2c::{Error, I2c}; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 7 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| @@ -28,7 +27,6 @@ async fn main(_spawner: Spawner) { | |||
| 28 | Irqs, | 27 | Irqs, |
| 29 | p.GPDMA1_CH4, | 28 | p.GPDMA1_CH4, |
| 30 | p.GPDMA1_CH5, | 29 | p.GPDMA1_CH5, |
| 31 | Hertz(100_000), | ||
| 32 | Default::default(), | 30 | Default::default(), |
| 33 | ); | 31 | ); |
| 34 | 32 | ||
diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs index 2861bc091..3c42ba8f5 100644 --- a/examples/stm32l4/src/bin/i2c.rs +++ b/examples/stm32l4/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::I2c; | 6 | use embassy_stm32::i2c::I2c; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 8 | ||
| 10 | const ADDRESS: u8 = 0x5F; | 9 | const ADDRESS: u8 = 0x5F; |
| @@ -13,7 +12,7 @@ const WHOAMI: u8 = 0x0F; | |||
| 13 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| 15 | let p = embassy_stm32::init(Default::default()); | 14 | let p = embassy_stm32::init(Default::default()); |
| 16 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Hertz(100_000), Default::default()); | 15 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Default::default()); |
| 17 | 16 | ||
| 18 | let mut data = [0u8; 1]; | 17 | let mut data = [0u8; 1]; |
| 19 | unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); | 18 | unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); |
diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs index a014b23e0..62153bfc8 100644 --- a/examples/stm32l4/src/bin/i2c_blocking_async.rs +++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs | |||
| @@ -5,7 +5,6 @@ use defmt::*; | |||
| 5 | use embassy_embedded_hal::adapter::BlockingAsync; | 5 | use embassy_embedded_hal::adapter::BlockingAsync; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::i2c::I2c; | 7 | use embassy_stm32::i2c::I2c; |
| 8 | use embassy_stm32::time::Hertz; | ||
| 9 | use embedded_hal_async::i2c::I2c as I2cTrait; | 8 | use embedded_hal_async::i2c::I2c as I2cTrait; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 10 | ||
| @@ -15,7 +14,7 @@ const WHOAMI: u8 = 0x0F; | |||
| 15 | #[embassy_executor::main] | 14 | #[embassy_executor::main] |
| 16 | async fn main(_spawner: Spawner) { | 15 | async fn main(_spawner: Spawner) { |
| 17 | let p = embassy_stm32::init(Default::default()); | 16 | let p = embassy_stm32::init(Default::default()); |
| 18 | let i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Hertz(100_000), Default::default()); | 17 | let i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Default::default()); |
| 19 | let mut i2c = BlockingAsync::new(i2c); | 18 | let mut i2c = BlockingAsync::new(i2c); |
| 20 | 19 | ||
| 21 | let mut data = [0u8; 1]; | 20 | let mut data = [0u8; 1]; |
diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs index 794972a33..0f5690e37 100644 --- a/examples/stm32l4/src/bin/i2c_dma.rs +++ b/examples/stm32l4/src/bin/i2c_dma.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::I2c; | 6 | use embassy_stm32::i2c::I2c; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; | 7 | use embassy_stm32::{bind_interrupts, i2c, peripherals}; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 8 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 9 | ||
| @@ -19,16 +18,7 @@ bind_interrupts!(struct Irqs { | |||
| 19 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| 20 | async fn main(_spawner: Spawner) { | 19 | async fn main(_spawner: Spawner) { |
| 21 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 22 | let mut i2c = I2c::new( | 21 | let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, Irqs, p.DMA1_CH4, p.DMA1_CH5, Default::default()); |
| 23 | p.I2C2, | ||
| 24 | p.PB10, | ||
| 25 | p.PB11, | ||
| 26 | Irqs, | ||
| 27 | p.DMA1_CH4, | ||
| 28 | p.DMA1_CH5, | ||
| 29 | Hertz(100_000), | ||
| 30 | Default::default(), | ||
| 31 | ); | ||
| 32 | 22 | ||
| 33 | let mut data = [0u8; 1]; | 23 | let mut data = [0u8; 1]; |
| 34 | unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); | 24 | unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); |
diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs index dc90a3b85..516badcb2 100644 --- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs +++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs | |||
| @@ -115,7 +115,6 @@ async fn main(spawner: Spawner) { | |||
| 115 | Irqs, | 115 | Irqs, |
| 116 | dp.DMA1_CH6, | 116 | dp.DMA1_CH6, |
| 117 | dp.DMA1_CH7, | 117 | dp.DMA1_CH7, |
| 118 | Hertz(100_000), | ||
| 119 | I2C_Config::default(), | 118 | I2C_Config::default(), |
| 120 | ); | 119 | ); |
| 121 | 120 | ||
diff --git a/examples/stm32u0/src/bin/i2c.rs b/examples/stm32u0/src/bin/i2c.rs index 2861bc091..3c42ba8f5 100644 --- a/examples/stm32u0/src/bin/i2c.rs +++ b/examples/stm32u0/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::I2c; | 6 | use embassy_stm32::i2c::I2c; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 8 | ||
| 10 | const ADDRESS: u8 = 0x5F; | 9 | const ADDRESS: u8 = 0x5F; |
| @@ -13,7 +12,7 @@ const WHOAMI: u8 = 0x0F; | |||
| 13 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| 15 | let p = embassy_stm32::init(Default::default()); | 14 | let p = embassy_stm32::init(Default::default()); |
| 16 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Hertz(100_000), Default::default()); | 15 | let mut i2c = I2c::new_blocking(p.I2C2, p.PB10, p.PB11, Default::default()); |
| 17 | 16 | ||
| 18 | let mut data = [0u8; 1]; | 17 | let mut data = [0u8; 1]; |
| 19 | unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); | 18 | unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data)); |
diff --git a/examples/stm32u5/src/bin/i2c.rs b/examples/stm32u5/src/bin/i2c.rs index d5f5d6f60..5577f7211 100644 --- a/examples/stm32u5/src/bin/i2c.rs +++ b/examples/stm32u5/src/bin/i2c.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | use defmt::{info, unwrap}; | 4 | use defmt::{info, unwrap}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::i2c::I2c; | 6 | use embassy_stm32::i2c::I2c; |
| 7 | use embassy_stm32::time::Hertz; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 7 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 8 | ||
| 10 | const HTS221_ADDRESS: u8 = 0x5F; | 9 | const HTS221_ADDRESS: u8 = 0x5F; |
| @@ -13,7 +12,7 @@ const WHOAMI: u8 = 0x0F; | |||
| 13 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 14 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| 15 | let p = embassy_stm32::init(Default::default()); | 14 | let p = embassy_stm32::init(Default::default()); |
| 16 | let mut i2c = I2c::new_blocking(p.I2C2, p.PF1, p.PF0, Hertz(100_000), Default::default()); | 15 | let mut i2c = I2c::new_blocking(p.I2C2, p.PF1, p.PF0, Default::default()); |
| 17 | 16 | ||
| 18 | let mut data = [0u8; 1]; | 17 | let mut data = [0u8; 1]; |
| 19 | unwrap!(i2c.blocking_write_read(HTS221_ADDRESS, &[WHOAMI], &mut data)); | 18 | unwrap!(i2c.blocking_write_read(HTS221_ADDRESS, &[WHOAMI], &mut data)); |
