55//! Operations on 10-bit slave addresses are not supported by the API yet (but applications might
66//! be able to emulate some operations).
77
8+ use crate :: private;
9+
10+ /// Address mode (7-bit / 10-bit)
11+ ///
12+ /// Note: This trait is sealed and should not be implemented outside of this crate.
13+ pub trait AddressMode : private:: Sealed {
14+ /// Address value type
15+ type Address ;
16+ }
17+
18+ /// 7-bit address mode type
19+ pub struct SevenBitAddress ( ( ) ) ;
20+
21+ /// 10-bit address mode type
22+ pub struct TenBitAddress ( ( ) ) ;
23+
24+ impl AddressMode for SevenBitAddress {
25+ type Address = u8 ;
26+ }
27+
28+ impl AddressMode for TenBitAddress {
29+ type Address = u16 ;
30+ }
31+
832/// Blocking read
9- pub trait Read {
33+ pub trait Read < A : AddressMode > {
1034 /// Error type
1135 type Error ;
1236
@@ -28,11 +52,11 @@ pub trait Read {
2852 /// - `MAK` = master acknowledge
2953 /// - `NMAK` = master no acknowledge
3054 /// - `SP` = stop condition
31- fn try_read ( & mut self , address : u8 , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
55+ fn try_read ( & mut self , address : A :: Address , buffer : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > ;
3256}
3357
3458/// Blocking write
35- pub trait Write {
59+ pub trait Write < A : AddressMode > {
3660 /// Error type
3761 type Error ;
3862
@@ -52,11 +76,11 @@ pub trait Write {
5276 /// - `SAK` = slave acknowledge
5377 /// - `Bi` = ith byte of data
5478 /// - `SP` = stop condition
55- fn try_write ( & mut self , address : u8 , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
79+ fn try_write ( & mut self , address : A :: Address , bytes : & [ u8 ] ) -> Result < ( ) , Self :: Error > ;
5680}
5781
5882/// Blocking write (iterator version)
59- pub trait WriteIter {
83+ pub trait WriteIter < A : AddressMode > {
6084 /// Error type
6185 type Error ;
6286
@@ -65,13 +89,13 @@ pub trait WriteIter {
6589 /// # I2C Events (contract)
6690 ///
6791 /// Same as `Write`
68- fn try_write < B > ( & mut self , address : u8 , bytes : B ) -> Result < ( ) , Self :: Error >
92+ fn try_write < B > ( & mut self , address : A :: Address , bytes : B ) -> Result < ( ) , Self :: Error >
6993 where
7094 B : IntoIterator < Item = u8 > ;
7195}
7296
7397/// Blocking write + read
74- pub trait WriteRead {
98+ pub trait WriteRead < A : AddressMode > {
7599 /// Error type
76100 type Error ;
77101
@@ -99,14 +123,14 @@ pub trait WriteRead {
99123 /// - `SP` = stop condition
100124 fn try_write_read (
101125 & mut self ,
102- address : u8 ,
126+ address : A :: Address ,
103127 bytes : & [ u8 ] ,
104128 buffer : & mut [ u8 ] ,
105129 ) -> Result < ( ) , Self :: Error > ;
106130}
107131
108132/// Blocking write (iterator version) + read
109- pub trait WriteIterRead {
133+ pub trait WriteIterRead < A : AddressMode > {
110134 /// Error type
111135 type Error ;
112136
@@ -118,7 +142,7 @@ pub trait WriteIterRead {
118142 /// Same as the `WriteRead` trait
119143 fn try_write_iter_read < B > (
120144 & mut self ,
121- address : u8 ,
145+ address : A :: Address ,
122146 bytes : B ,
123147 buffer : & mut [ u8 ] ,
124148 ) -> Result < ( ) , Self :: Error >
0 commit comments