3232//!
3333//! For non-blocking slave operations, see `openprot-hal-nb::i2c_hardware`.
3434
35- use embedded_hal:: i2c:: { Operation , SevenBitAddress } ;
35+ use embedded_hal:: i2c:: { AddressMode , Operation , SevenBitAddress } ;
3636
3737/// Core I2C hardware interface providing basic operations
3838///
@@ -45,11 +45,38 @@ pub trait I2cHardwareCore {
4545 /// Hardware-specific configuration type for I2C initialization and setup
4646 type Config ;
4747
48+ /// I2C speed configuration type
49+ type I2cSpeed ;
50+
51+ /// Timing configuration type
52+ type TimingConfig ;
53+
4854 /// Initialize the I2C hardware with the given configuration
4955 fn init ( & mut self , config : & mut Self :: Config ) ;
5056
5157 /// Configure timing parameters (clock speed, setup/hold times)
52- fn configure_timing ( & mut self , config : & mut Self :: Config ) ;
58+ ///
59+ /// Takes timing parameters as input and returns the calculated clock source frequency.
60+ /// This provides type safety by making clear what is read vs. what is computed/returned.
61+ ///
62+ /// # Arguments
63+ ///
64+ /// * `speed` - Target I2C bus speed (Standard, Fast, FastPlus, etc.)
65+ /// * `timing` - Timing configuration parameters for setup/hold times
66+ ///
67+ /// # Returns
68+ ///
69+ /// Returns the actual calculated clock source frequency in Hz.
70+ ///
71+ /// # Errors
72+ ///
73+ /// Returns an error if the requested timing cannot be achieved with the
74+ /// available hardware clock sources or if parameters are invalid.
75+ fn configure_timing (
76+ & mut self ,
77+ speed : Self :: I2cSpeed ,
78+ timing : & Self :: TimingConfig ,
79+ ) -> Result < u32 , Self :: Error > ;
5380
5481 /// Enable hardware interrupts with the specified mask
5582 fn enable_interrupts ( & mut self , mask : u32 ) ;
@@ -137,9 +164,9 @@ pub mod slave {
137164 /// This trait provides the fundamental slave operations that all slave
138165 /// implementations need: setting slave address and enabling/disabling slave mode.
139166 /// This is the minimal trait for any I2C slave implementation.
140- pub trait I2cSlaveCore : super :: I2cHardwareCore {
167+ pub trait I2cSlaveCore < A : AddressMode = SevenBitAddress > : super :: I2cHardwareCore {
141168 /// Configure the slave address for this I2C controller
142- fn configure_slave_address ( & mut self , addr : SevenBitAddress ) -> Result < ( ) , Self :: Error > ;
169+ fn configure_slave_address ( & mut self , addr : A ) -> Result < ( ) , Self :: Error > ;
143170
144171 /// Enable slave mode operation
145172 fn enable_slave_mode ( & mut self ) -> Result < ( ) , Self :: Error > ;
@@ -160,7 +187,7 @@ pub mod slave {
160187 /// Separate from core to allow different buffer management strategies.
161188 /// Implementations can choose different buffering approaches (ring buffer,
162189 /// simple array, DMA, etc.) while maintaining the same interface.
163- pub trait I2cSlaveBuffer : I2cSlaveCore {
190+ pub trait I2cSlaveBuffer < A : AddressMode = SevenBitAddress > : I2cSlaveCore < A > {
164191 /// Read received data from the slave buffer
165192 ///
166193 /// Returns the number of bytes actually read. The buffer is filled
@@ -204,7 +231,7 @@ pub mod slave {
204231 ///
205232 /// Common interrupt and status operations shared by both async and sync event patterns.
206233 /// This provides the foundation for event-driven slave operations.
207- pub trait I2cSlaveInterrupts : I2cSlaveCore {
234+ pub trait I2cSlaveInterrupts < A : AddressMode = SevenBitAddress > : I2cSlaveCore < A > {
208235 /// Enable slave-specific hardware interrupts
209236 ///
210237 /// Configures the hardware to generate interrupts for slave events.
@@ -219,26 +246,26 @@ pub mod slave {
219246 /// that the interrupt has been handled.
220247 fn clear_slave_interrupts ( & mut self , mask : u32 ) ;
221248
222- /// Get current slave hardware status
249+ /// Current slave hardware status
223250 ///
224251 /// Returns comprehensive status information about the slave controller
225252 /// including enabled state, address, buffer counts, and error conditions.
226- fn get_slave_status ( & self ) -> Result < SlaveStatus , Self :: Error > ;
253+ fn slave_status ( & self ) -> Result < SlaveStatus , Self :: Error > ;
227254
228- /// Get the last slave event that occurred
255+ /// Last slave event that occurred
229256 ///
230257 /// Returns the most recent slave event, useful for debugging
231258 /// and state tracking. May return None if no events have occurred
232259 /// since reset or if the hardware doesn't track this information.
233- fn get_last_slave_event ( & self ) -> Option < I2cSEvent > ;
260+ fn last_slave_event ( & self ) -> Option < I2cSEvent > ;
234261 }
235262
236263 /// Blocking slave event handling (sync pattern)
237264 ///
238265 /// This trait provides blocking operations suitable for synchronous code
239266 /// that can afford to wait for events. Operations may block the calling
240267 /// thread until the requested condition is met or timeout occurs.
241- pub trait I2cSlaveEventSync : I2cSlaveInterrupts {
268+ pub trait I2cSlaveEventSync < A : AddressMode = SevenBitAddress > : I2cSlaveInterrupts < A > {
242269 /// Wait for a specific slave event with timeout
243270 ///
244271 /// Blocks until the specified event occurs or the timeout expires.
@@ -272,20 +299,29 @@ pub mod slave {
272299 /// This trait represents a basic slave implementation that combines
273300 /// core setup and buffer operations. It's suitable for most simple
274301 /// slave use cases without requiring event handling.
275- pub trait I2cSlaveBasic : I2cSlaveCore + I2cSlaveBuffer { }
302+ pub trait I2cSlaveBasic < A : AddressMode = SevenBitAddress > :
303+ I2cSlaveCore < A > + I2cSlaveBuffer < A >
304+ {
305+ }
276306
277307 /// Blanket implementation: any type implementing core + buffer gets basic slave
278- impl < T > I2cSlaveBasic for T where T : I2cSlaveCore + I2cSlaveBuffer { }
308+ impl < T , A : AddressMode > I2cSlaveBasic < A > for T where T : I2cSlaveCore < A > + I2cSlaveBuffer < A > { }
279309
280310 /// Complete sync slave implementation
281311 ///
282312 /// This trait represents a full sync slave implementation that supports
283313 /// all blocking slave operations. Perfect for traditional blocking
284314 /// implementations that can afford to wait.
285- pub trait I2cSlaveSync : I2cSlaveCore + I2cSlaveBuffer + I2cSlaveEventSync { }
315+ pub trait I2cSlaveSync < A : AddressMode = SevenBitAddress > :
316+ I2cSlaveCore < A > + I2cSlaveBuffer < A > + I2cSlaveEventSync < A >
317+ {
318+ }
286319
287320 /// Blanket implementation: any type implementing core + buffer + sync events gets sync slave
288- impl < T > I2cSlaveSync for T where T : I2cSlaveCore + I2cSlaveBuffer + I2cSlaveEventSync { }
321+ impl < T , A : AddressMode > I2cSlaveSync < A > for T where
322+ T : I2cSlaveCore < A > + I2cSlaveBuffer < A > + I2cSlaveEventSync < A >
323+ {
324+ }
289325
290326 /// Combined trait for controllers supporting both master and slave modes
291327 ///
0 commit comments