aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-embedded-hal/CHANGELOG.md2
-rw-r--r--embassy-embedded-hal/src/flash/partition/asynch.rs6
-rw-r--r--embassy-embedded-hal/src/flash/partition/blocking.rs6
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/i2c.rs18
-rw-r--r--embassy-embedded-hal/src/shared_bus/asynch/spi.rs8
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/i2c.rs28
-rw-r--r--embassy-embedded-hal/src/shared_bus/blocking/spi.rs8
7 files changed, 57 insertions, 19 deletions
diff --git a/embassy-embedded-hal/CHANGELOG.md b/embassy-embedded-hal/CHANGELOG.md
index ec79a5c81..95cd44a3c 100644
--- a/embassy-embedded-hal/CHANGELOG.md
+++ b/embassy-embedded-hal/CHANGELOG.md
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8<!-- next-header --> 8<!-- next-header -->
9## Unreleased - ReleaseDate 9## Unreleased - ReleaseDate
10 10
11- Shared I2c busses now impl `Clone`
12
11## 0.5.0 - 2025-08-27 13## 0.5.0 - 2025-08-27
12 14
13## 0.4.0 - 2025-08-03 15## 0.4.0 - 2025-08-03
diff --git a/embassy-embedded-hal/src/flash/partition/asynch.rs b/embassy-embedded-hal/src/flash/partition/asynch.rs
index 82e27bb7c..a6fa2a562 100644
--- a/embassy-embedded-hal/src/flash/partition/asynch.rs
+++ b/embassy-embedded-hal/src/flash/partition/asynch.rs
@@ -119,7 +119,7 @@ mod tests {
119 let mut read_buf = [0; 8]; 119 let mut read_buf = [0; 8];
120 partition.read(4, &mut read_buf).await.unwrap(); 120 partition.read(4, &mut read_buf).await.unwrap();
121 121
122 assert!(read_buf.iter().position(|&x| x != 0xAA).is_none()); 122 assert!(!read_buf.iter().any(|&x| x != 0xAA));
123 } 123 }
124 124
125 #[futures_test::test] 125 #[futures_test::test]
@@ -133,7 +133,7 @@ mod tests {
133 partition.write(4, &write_buf).await.unwrap(); 133 partition.write(4, &write_buf).await.unwrap();
134 134
135 let flash = flash.try_lock().unwrap(); 135 let flash = flash.try_lock().unwrap();
136 assert!(flash.mem[132..132 + 8].iter().position(|&x| x != 0xAA).is_none()); 136 assert!(!flash.mem[132..132 + 8].iter().any(|&x| x != 0xAA));
137 } 137 }
138 138
139 #[futures_test::test] 139 #[futures_test::test]
@@ -146,6 +146,6 @@ mod tests {
146 partition.erase(0, 128).await.unwrap(); 146 partition.erase(0, 128).await.unwrap();
147 147
148 let flash = flash.try_lock().unwrap(); 148 let flash = flash.try_lock().unwrap();
149 assert!(flash.mem[128..256].iter().position(|&x| x != 0xFF).is_none()); 149 assert!(!flash.mem[128..256].iter().any(|&x| x != 0xFF));
150 } 150 }
151} 151}
diff --git a/embassy-embedded-hal/src/flash/partition/blocking.rs b/embassy-embedded-hal/src/flash/partition/blocking.rs
index 951998166..cb30290a8 100644
--- a/embassy-embedded-hal/src/flash/partition/blocking.rs
+++ b/embassy-embedded-hal/src/flash/partition/blocking.rs
@@ -129,7 +129,7 @@ mod tests {
129 let mut read_buf = [0; 8]; 129 let mut read_buf = [0; 8];
130 partition.read(4, &mut read_buf).unwrap(); 130 partition.read(4, &mut read_buf).unwrap();
131 131
132 assert!(read_buf.iter().position(|&x| x != 0xAA).is_none()); 132 assert!(!read_buf.iter().any(|&x| x != 0xAA));
133 } 133 }
134 134
135 #[test] 135 #[test]
@@ -143,7 +143,7 @@ mod tests {
143 partition.write(4, &write_buf).unwrap(); 143 partition.write(4, &write_buf).unwrap();
144 144
145 let flash = flash.into_inner().take(); 145 let flash = flash.into_inner().take();
146 assert!(flash.mem[132..132 + 8].iter().position(|&x| x != 0xAA).is_none()); 146 assert!(!flash.mem[132..132 + 8].iter().any(|&x| x != 0xAA));
147 } 147 }
148 148
149 #[test] 149 #[test]
@@ -156,6 +156,6 @@ mod tests {
156 partition.erase(0, 128).unwrap(); 156 partition.erase(0, 128).unwrap();
157 157
158 let flash = flash.into_inner().take(); 158 let flash = flash.into_inner().take();
159 assert!(flash.mem[128..256].iter().position(|&x| x != 0xFF).is_none()); 159 assert!(!flash.mem[128..256].iter().any(|&x| x != 0xFF));
160 } 160 }
161} 161}
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
index 6de685ee1..48246270e 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs
@@ -41,6 +41,12 @@ impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> {
41 } 41 }
42} 42}
43 43
44impl<'a, M: RawMutex, BUS> Clone for I2cDevice<'a, M, BUS> {
45 fn clone(&self) -> Self {
46 Self { bus: self.bus }
47 }
48}
49
44impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cDevice<'a, M, BUS> 50impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cDevice<'a, M, BUS>
45where 51where
46 BUS: i2c::ErrorType, 52 BUS: i2c::ErrorType,
@@ -113,6 +119,18 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> {
113 } 119 }
114} 120}
115 121
122impl<'a, M: RawMutex, BUS: SetConfig> Clone for I2cDeviceWithConfig<'a, M, BUS>
123where
124 BUS::Config: Clone,
125{
126 fn clone(&self) -> Self {
127 Self {
128 bus: self.bus,
129 config: self.config.clone(),
130 }
131 }
132}
133
116impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS> 134impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS>
117where 135where
118 BUS: i2c::ErrorType, 136 BUS: i2c::ErrorType,
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
index 78709b7d3..0faefbc1e 100644
--- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs
@@ -112,11 +112,11 @@ where
112 cs_drop.defuse(); 112 cs_drop.defuse();
113 let cs_res = self.cs.set_high(); 113 let cs_res = self.cs.set_high();
114 114
115 let op_res = op_res.map_err(SpiDeviceError::Spi)?; 115 op_res.map_err(SpiDeviceError::Spi)?;
116 flush_res.map_err(SpiDeviceError::Spi)?; 116 flush_res.map_err(SpiDeviceError::Spi)?;
117 cs_res.map_err(SpiDeviceError::Cs)?; 117 cs_res.map_err(SpiDeviceError::Cs)?;
118 118
119 Ok(op_res) 119 Ok(())
120 } 120 }
121} 121}
122 122
@@ -203,10 +203,10 @@ where
203 cs_drop.defuse(); 203 cs_drop.defuse();
204 let cs_res = self.cs.set_high(); 204 let cs_res = self.cs.set_high();
205 205
206 let op_res = op_res.map_err(SpiDeviceError::Spi)?; 206 op_res.map_err(SpiDeviceError::Spi)?;
207 flush_res.map_err(SpiDeviceError::Spi)?; 207 flush_res.map_err(SpiDeviceError::Spi)?;
208 cs_res.map_err(SpiDeviceError::Cs)?; 208 cs_res.map_err(SpiDeviceError::Cs)?;
209 209
210 Ok(op_res) 210 Ok(())
211 } 211 }
212} 212}
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
index 627767c8a..dc634a209 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs
@@ -36,6 +36,12 @@ impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> {
36 } 36 }
37} 37}
38 38
39impl<'a, M: RawMutex, BUS> Clone for I2cDevice<'a, M, BUS> {
40 fn clone(&self) -> Self {
41 Self { bus: self.bus }
42 }
43}
44
39impl<'a, M: RawMutex, BUS> ErrorType for I2cDevice<'a, M, BUS> 45impl<'a, M: RawMutex, BUS> ErrorType for I2cDevice<'a, M, BUS>
40where 46where
41 BUS: ErrorType, 47 BUS: ErrorType,
@@ -75,33 +81,33 @@ where
75 } 81 }
76} 82}
77 83
78impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS> 84impl<M, BUS, E> embedded_hal_02::blocking::i2c::Write for I2cDevice<'_, M, BUS>
79where 85where
80 M: RawMutex, 86 M: RawMutex,
81 BUS: embedded_hal_02::blocking::i2c::Write<Error = E>, 87 BUS: embedded_hal_02::blocking::i2c::Write<Error = E>,
82{ 88{
83 type Error = I2cDeviceError<E>; 89 type Error = I2cDeviceError<E>;
84 90
85 fn write<'w>(&mut self, addr: u8, bytes: &'w [u8]) -> Result<(), Self::Error> { 91 fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
86 self.bus 92 self.bus
87 .lock(|bus| bus.borrow_mut().write(addr, bytes).map_err(I2cDeviceError::I2c)) 93 .lock(|bus| bus.borrow_mut().write(addr, bytes).map_err(I2cDeviceError::I2c))
88 } 94 }
89} 95}
90 96
91impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::Read for I2cDevice<'_, M, BUS> 97impl<M, BUS, E> embedded_hal_02::blocking::i2c::Read for I2cDevice<'_, M, BUS>
92where 98where
93 M: RawMutex, 99 M: RawMutex,
94 BUS: embedded_hal_02::blocking::i2c::Read<Error = E>, 100 BUS: embedded_hal_02::blocking::i2c::Read<Error = E>,
95{ 101{
96 type Error = I2cDeviceError<E>; 102 type Error = I2cDeviceError<E>;
97 103
98 fn read<'w>(&mut self, addr: u8, bytes: &'w mut [u8]) -> Result<(), Self::Error> { 104 fn read(&mut self, addr: u8, bytes: &mut [u8]) -> Result<(), Self::Error> {
99 self.bus 105 self.bus
100 .lock(|bus| bus.borrow_mut().read(addr, bytes).map_err(I2cDeviceError::I2c)) 106 .lock(|bus| bus.borrow_mut().read(addr, bytes).map_err(I2cDeviceError::I2c))
101 } 107 }
102} 108}
103 109
104impl<'a, M, BUS, E> embedded_hal_02::blocking::i2c::WriteRead for I2cDevice<'_, M, BUS> 110impl<M, BUS, E> embedded_hal_02::blocking::i2c::WriteRead for I2cDevice<'_, M, BUS>
105where 111where
106 M: RawMutex, 112 M: RawMutex,
107 BUS: embedded_hal_02::blocking::i2c::WriteRead<Error = E>, 113 BUS: embedded_hal_02::blocking::i2c::WriteRead<Error = E>,
@@ -139,6 +145,18 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> {
139 } 145 }
140} 146}
141 147
148impl<'a, M: RawMutex, BUS: SetConfig> Clone for I2cDeviceWithConfig<'a, M, BUS>
149where
150 BUS::Config: Clone,
151{
152 fn clone(&self) -> Self {
153 Self {
154 bus: self.bus,
155 config: self.config.clone(),
156 }
157 }
158}
159
142impl<'a, M, BUS> ErrorType for I2cDeviceWithConfig<'a, M, BUS> 160impl<'a, M, BUS> ErrorType for I2cDeviceWithConfig<'a, M, BUS>
143where 161where
144 M: RawMutex, 162 M: RawMutex,
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
index eb9c0c4f4..ffe2aa1c6 100644
--- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
+++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs
@@ -82,11 +82,11 @@ where
82 let flush_res = bus.flush(); 82 let flush_res = bus.flush();
83 let cs_res = self.cs.set_high(); 83 let cs_res = self.cs.set_high();
84 84
85 let op_res = op_res.map_err(SpiDeviceError::Spi)?; 85 op_res.map_err(SpiDeviceError::Spi)?;
86 flush_res.map_err(SpiDeviceError::Spi)?; 86 flush_res.map_err(SpiDeviceError::Spi)?;
87 cs_res.map_err(SpiDeviceError::Cs)?; 87 cs_res.map_err(SpiDeviceError::Cs)?;
88 88
89 Ok(op_res) 89 Ok(())
90 }) 90 })
91 } 91 }
92} 92}
@@ -158,10 +158,10 @@ where
158 let flush_res = bus.flush(); 158 let flush_res = bus.flush();
159 let cs_res = self.cs.set_high(); 159 let cs_res = self.cs.set_high();
160 160
161 let op_res = op_res.map_err(SpiDeviceError::Spi)?; 161 op_res.map_err(SpiDeviceError::Spi)?;
162 flush_res.map_err(SpiDeviceError::Spi)?; 162 flush_res.map_err(SpiDeviceError::Spi)?;
163 cs_res.map_err(SpiDeviceError::Cs)?; 163 cs_res.map_err(SpiDeviceError::Cs)?;
164 Ok(op_res) 164 Ok(())
165 }) 165 })
166 } 166 }
167} 167}