@@ -8,28 +8,14 @@ use crate::gpio;
88use crate :: rcc:: Clocks ;
99use fugit:: { HertzU32 as Hertz , RateExtU32 } ;
1010
11+ mod common;
1112mod hal_02;
1213mod hal_1;
1314
14- pub mod dma;
15-
16- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
17- pub enum Address {
18- Seven ( u8 ) ,
19- Ten ( u16 ) ,
20- }
15+ pub use common:: { Address , Error , NoAcknowledgeSource } ;
16+ use common:: { Hal02Operation , Hal1Operation } ;
2117
22- impl From < u8 > for Address {
23- fn from ( value : u8 ) -> Self {
24- Self :: Seven ( value)
25- }
26- }
27-
28- impl From < u16 > for Address {
29- fn from ( value : u16 ) -> Self {
30- Self :: Ten ( value)
31- }
32- }
18+ pub mod dma;
3319
3420#[ derive( Debug , Eq , PartialEq ) ]
3521pub enum DutyCycle {
@@ -88,52 +74,6 @@ pub struct I2c<I2C: Instance> {
8874 pins : ( I2C :: Scl , I2C :: Sda ) ,
8975}
9076
91- pub use embedded_hal:: i2c:: NoAcknowledgeSource ;
92-
93- #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
94- #[ non_exhaustive]
95- pub enum Error {
96- Overrun ,
97- NoAcknowledge ( NoAcknowledgeSource ) ,
98- Timeout ,
99- // Note: The Bus error type is not currently returned, but is maintained for compatibility.
100- Bus ,
101- Crc ,
102- ArbitrationLoss ,
103- }
104-
105- impl Error {
106- pub ( crate ) fn nack_addr ( self ) -> Self {
107- match self {
108- Error :: NoAcknowledge ( NoAcknowledgeSource :: Unknown ) => {
109- Error :: NoAcknowledge ( NoAcknowledgeSource :: Address )
110- }
111- e => e,
112- }
113- }
114- pub ( crate ) fn nack_data ( self ) -> Self {
115- match self {
116- Error :: NoAcknowledge ( NoAcknowledgeSource :: Unknown ) => {
117- Error :: NoAcknowledge ( NoAcknowledgeSource :: Data )
118- }
119- e => e,
120- }
121- }
122- }
123-
124- use embedded_hal:: i2c:: ErrorKind ;
125- impl embedded_hal:: i2c:: Error for Error {
126- fn kind ( & self ) -> ErrorKind {
127- match * self {
128- Self :: Overrun => ErrorKind :: Overrun ,
129- Self :: Bus => ErrorKind :: Bus ,
130- Self :: ArbitrationLoss => ErrorKind :: ArbitrationLoss ,
131- Self :: NoAcknowledge ( nack) => ErrorKind :: NoAcknowledge ( nack) ,
132- Self :: Crc | Self :: Timeout => ErrorKind :: Other ,
133- }
134- }
135- }
136-
13777pub trait Instance :
13878 crate :: Sealed + Deref < Target = i2c1:: RegisterBlock > + Enable + Reset + gpio:: alt:: I2cCommon
13979{
@@ -727,9 +667,6 @@ macro_rules! transaction_impl {
727667}
728668use transaction_impl;
729669
730- pub ( crate ) type Hal1Operation < ' a > = embedded_hal:: i2c:: Operation < ' a > ;
731- pub ( crate ) type Hal02Operation < ' a > = embedded_hal_02:: blocking:: i2c:: Operation < ' a > ;
732-
733670impl < I2C : Instance > embedded_hal_02:: blocking:: i2c:: WriteIter for I2c < I2C > {
734671 type Error = Error ;
735672
0 commit comments