diff options
| author | HybridChild <[email protected]> | 2025-08-07 10:34:29 +0200 |
|---|---|---|
| committer | HybridChild <[email protected]> | 2025-08-23 08:52:01 +0200 |
| commit | c531af42c8dd2eaeb56ef1891396ac559918560e (patch) | |
| tree | 767a41bde0b6b0a117d7fba5932b481bef45ca82 /embassy-stm32/src/i2c | |
| parent | 392548997ab65e5654a32848d93a05d5fb695a79 (diff) | |
Revert "stm32/i2c: Add temporary trait for version-specific initialization during v1 rework"
This reverts commit d38e1de962b92d1d48f1991ce09e494ea46d3f7f.
Diffstat (limited to 'embassy-stm32/src/i2c')
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v1.rs | 38 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v2.rs | 4 |
3 files changed, 9 insertions, 54 deletions
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 660b8144a..675a392f9 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -29,21 +29,6 @@ use crate::rcc::{RccInfo, SealedRccPeripheral}; | |||
| 29 | use crate::time::Hertz; | 29 | use crate::time::Hertz; |
| 30 | use crate::{interrupt, peripherals}; | 30 | use crate::{interrupt, peripherals}; |
| 31 | 31 | ||
| 32 | /// Temporary trait for version-specific initialization during I2C v1 async rework. | ||
| 33 | /// | ||
| 34 | /// This trait allows the shared constructor in mod.rs to call version-specific | ||
| 35 | /// initialization while we incrementally migrate v1 async operations to use | ||
| 36 | /// the new event-driven interrupt pattern. Will be removed once the rework | ||
| 37 | /// is complete and both blocking/async modes use unified initialization. | ||
| 38 | pub trait VersionSpecificInit { | ||
| 39 | /// Performs version and mode-specific initialization. | ||
| 40 | /// | ||
| 41 | /// For v1: Sets interrupt pattern flag based on blocking vs async mode. | ||
| 42 | /// For v2: No-op, does nothing. | ||
| 43 | fn version_specific_init(&mut self); | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | /// I2C error. | 32 | /// I2C error. |
| 48 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] | 33 | #[derive(Debug, PartialEq, Eq, Copy, Clone)] |
| 49 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 34 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| @@ -207,10 +192,7 @@ impl<'d> I2c<'d, Blocking, Master> { | |||
| 207 | } | 192 | } |
| 208 | } | 193 | } |
| 209 | 194 | ||
| 210 | impl<'d, M: Mode> I2c<'d, M, Master> | 195 | impl<'d, M: Mode> I2c<'d, M, Master> { |
| 211 | where | ||
| 212 | Self: VersionSpecificInit | ||
| 213 | { | ||
| 214 | /// Create a new I2C driver. | 196 | /// Create a new I2C driver. |
| 215 | fn new_inner<T: Instance>( | 197 | fn new_inner<T: Instance>( |
| 216 | _peri: Peri<'d, T>, | 198 | _peri: Peri<'d, T>, |
| @@ -241,7 +223,6 @@ where | |||
| 241 | }; | 223 | }; |
| 242 | 224 | ||
| 243 | this.enable_and_init(config); | 225 | this.enable_and_init(config); |
| 244 | this.version_specific_init(); | ||
| 245 | 226 | ||
| 246 | this | 227 | this |
| 247 | } | 228 | } |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index ef5624d97..f2fd0147e 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -6,7 +6,6 @@ | |||
| 6 | 6 | ||
| 7 | use core::future::poll_fn; | 7 | use core::future::poll_fn; |
| 8 | use core::task::Poll; | 8 | use core::task::Poll; |
| 9 | use core::sync::atomic::{AtomicBool, Ordering}; | ||
| 10 | 9 | ||
| 11 | use embassy_embedded_hal::SetConfig; | 10 | use embassy_embedded_hal::SetConfig; |
| 12 | use embassy_futures::select::{select, Either}; | 11 | use embassy_futures::select::{select, Either}; |
| @@ -23,14 +22,12 @@ use embassy_sync::waitqueue::AtomicWaker; | |||
| 23 | /// I2C v2 peripheral state | 22 | /// I2C v2 peripheral state |
| 24 | pub(crate) struct State { | 23 | pub(crate) struct State { |
| 25 | pub(crate) waker: AtomicWaker, | 24 | pub(crate) waker: AtomicWaker, |
| 26 | pub use_new_interrupt_pattern: AtomicBool, | ||
| 27 | } | 25 | } |
| 28 | 26 | ||
| 29 | impl State { | 27 | impl State { |
| 30 | pub(crate) const fn new() -> Self { | 28 | pub(crate) const fn new() -> Self { |
| 31 | Self { | 29 | Self { |
| 32 | waker: AtomicWaker::new(), | 30 | waker: AtomicWaker::new(), |
| 33 | use_new_interrupt_pattern: AtomicBool::new(false), | ||
| 34 | } | 31 | } |
| 35 | } | 32 | } |
| 36 | } | 33 | } |
| @@ -47,25 +44,17 @@ impl State { | |||
| 47 | // There's some more details there, and we might have a fix for you. But please let us know if you | 44 | // There's some more details there, and we might have a fix for you. But please let us know if you |
| 48 | // hit a case like this! | 45 | // hit a case like this! |
| 49 | pub unsafe fn on_interrupt<T: Instance>() { | 46 | pub unsafe fn on_interrupt<T: Instance>() { |
| 47 | let regs = T::info().regs; | ||
| 50 | // i2c v2 only woke the task on transfer complete interrupts. v1 uses interrupts for a bunch of | 48 | // i2c v2 only woke the task on transfer complete interrupts. v1 uses interrupts for a bunch of |
| 51 | // other stuff, so we wake the task on every interrupt. | 49 | // other stuff, so we wake the task on every interrupt. |
| 52 | 50 | T::state().waker.wake(); | |
| 53 | let regs = T::info().regs; | 51 | critical_section::with(|_| { |
| 54 | let state = T::state(); | 52 | // Clear event interrupt flag. |
| 55 | 53 | regs.cr2().modify(|w| { | |
| 56 | if state.use_new_interrupt_pattern.load(Ordering::Relaxed) { | 54 | w.set_itevten(false); |
| 57 | 55 | w.set_iterren(false); | |
| 58 | } else { | ||
| 59 | critical_section::with(|_| { | ||
| 60 | // Clear event interrupt flag. | ||
| 61 | regs.cr2().modify(|w| { | ||
| 62 | w.set_itevten(false); | ||
| 63 | w.set_iterren(false); | ||
| 64 | }); | ||
| 65 | }); | 56 | }); |
| 66 | } | 57 | }); |
| 67 | |||
| 68 | state.waker.wake(); | ||
| 69 | } | 58 | } |
| 70 | 59 | ||
| 71 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { | 60 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { |
| @@ -727,17 +716,6 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 727 | } | 716 | } |
| 728 | } | 717 | } |
| 729 | 718 | ||
| 730 | impl<'d> VersionSpecificInit for I2c<'d, Blocking, Master> { | ||
| 731 | fn version_specific_init(&mut self) { | ||
| 732 | self.state.use_new_interrupt_pattern.store(false, Ordering::Relaxed); | ||
| 733 | } | ||
| 734 | } | ||
| 735 | |||
| 736 | impl<'d> VersionSpecificInit for I2c<'d, Async, Master> { | ||
| 737 | fn version_specific_init(&mut self) { | ||
| 738 | self.state.use_new_interrupt_pattern.store(true, Ordering::Relaxed); | ||
| 739 | } | ||
| 740 | } | ||
| 741 | 719 | ||
| 742 | /// Timing configuration for I2C v1 hardware | 720 | /// Timing configuration for I2C v1 hardware |
| 743 | /// | 721 | /// |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index f23c58c9e..72a7d05ab 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -107,10 +107,6 @@ pub(crate) unsafe fn on_interrupt<T: Instance>() { | |||
| 107 | }); | 107 | }); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | impl<'d, M: Mode> VersionSpecificInit for I2c<'d, M, Master> { | ||
| 111 | fn version_specific_init(&mut self) {} | ||
| 112 | } | ||
| 113 | |||
| 114 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { | 110 | impl<'d, M: Mode, IM: MasterMode> I2c<'d, M, IM> { |
| 115 | pub(crate) fn init(&mut self, config: Config) { | 111 | pub(crate) fn init(&mut self, config: Config) { |
| 116 | self.info.regs.cr1().modify(|reg| { | 112 | self.info.regs.cr1().modify(|reg| { |
