@@ -8,28 +8,14 @@ use crate::gpio;
8
8
use crate :: rcc:: Clocks ;
9
9
use fugit:: { HertzU32 as Hertz , RateExtU32 } ;
10
10
11
+ mod common;
11
12
mod hal_02;
12
13
mod hal_1;
13
14
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 } ;
21
17
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;
33
19
34
20
#[ derive( Debug , Eq , PartialEq ) ]
35
21
pub enum DutyCycle {
@@ -88,52 +74,6 @@ pub struct I2c<I2C: Instance> {
88
74
pins : ( I2C :: Scl , I2C :: Sda ) ,
89
75
}
90
76
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
-
137
77
pub trait Instance :
138
78
crate :: Sealed + Deref < Target = i2c1:: RegisterBlock > + Enable + Reset + gpio:: alt:: I2cCommon
139
79
{
@@ -727,9 +667,6 @@ macro_rules! transaction_impl {
727
667
}
728
668
use transaction_impl;
729
669
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
-
733
670
impl < I2C : Instance > embedded_hal_02:: blocking:: i2c:: WriteIter for I2c < I2C > {
734
671
type Error = Error ;
735
672
0 commit comments