aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-08 15:09:49 +0000
committerGitHub <[email protected]>2022-07-08 15:09:49 +0000
commitd2a622b3d0ed4dfd2932f9059a70dc82a64d761e (patch)
tree533c51b8426951c75976a795ef2329ba78d0a83d
parent1fb70e2fac11afb4139ec2ed89293ce7ae1f6e65 (diff)
parent43aec9083c601478f300795aa55effad0f9ee41c (diff)
Merge #849
849: Add EH 1.0 impls for stm32 i2c r=Dirbaio a=kalkyl Add missing stm32 impls for embedded-hal 1.0 i2c traits Co-authored-by: Henrik Alsér <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
-rw-r--r--embassy-stm32/src/i2c/v1.rs68
-rw-r--r--embassy-stm32/src/i2c/v2.rs46
2 files changed, 112 insertions, 2 deletions
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index 87a4f9699..f56e50f9b 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -280,6 +280,74 @@ impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> {
280 } 280 }
281} 281}
282 282
283#[cfg(feature = "unstable-traits")]
284mod eh1 {
285 use super::*;
286
287 impl embedded_hal_1::i2c::Error for Error {
288 fn kind(&self) -> embedded_hal_1::i2c::ErrorKind {
289 match *self {
290 Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus,
291 Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss,
292 Self::Nack => {
293 embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown)
294 }
295 Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other,
296 Self::Crc => embedded_hal_1::i2c::ErrorKind::Other,
297 Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun,
298 Self::ZeroLengthTransfer => embedded_hal_1::i2c::ErrorKind::Other,
299 }
300 }
301 }
302
303 impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for I2c<'d, T> {
304 type Error = Error;
305 }
306
307 impl<'d, T: Instance> embedded_hal_1::i2c::blocking::I2c for I2c<'d, T> {
308 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
309 self.blocking_read(address, buffer)
310 }
311
312 fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> {
313 self.blocking_write(address, buffer)
314 }
315
316 fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error>
317 where
318 B: IntoIterator<Item = u8>,
319 {
320 todo!();
321 }
322
323 fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error>
324 where
325 B: IntoIterator<Item = u8>,
326 {
327 todo!();
328 }
329
330 fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> {
331 self.blocking_write_read(address, wr_buffer, rd_buffer)
332 }
333
334 fn transaction<'a>(
335 &mut self,
336 _address: u8,
337 _operations: &mut [embedded_hal_1::i2c::blocking::Operation<'a>],
338 ) -> Result<(), Self::Error> {
339 todo!();
340 }
341
342 fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error>
343 where
344 O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>,
345 {
346 todo!();
347 }
348 }
349}
350
283enum Mode { 351enum Mode {
284 Fast, 352 Fast,
285 Standard, 353 Standard,
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 1a085e782..08b43bebd 100644
--- a/embassy-stm32/src/i2c/v2.rs
+++ b/embassy-stm32/src/i2c/v2.rs
@@ -832,7 +832,6 @@ impl Timings {
832 832
833#[cfg(feature = "unstable-traits")] 833#[cfg(feature = "unstable-traits")]
834mod eh1 { 834mod eh1 {
835 use super::super::{RxDma, TxDma};
836 use super::*; 835 use super::*;
837 836
838 impl embedded_hal_1::i2c::Error for Error { 837 impl embedded_hal_1::i2c::Error for Error {
@@ -851,9 +850,52 @@ mod eh1 {
851 } 850 }
852 } 851 }
853 852
854 impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { 853 impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> {
855 type Error = Error; 854 type Error = Error;
856 } 855 }
856
857 impl<'d, T: Instance> embedded_hal_1::i2c::blocking::I2c for I2c<'d, T, NoDma, NoDma> {
858 fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
859 self.blocking_read(address, buffer)
860 }
861
862 fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> {
863 self.blocking_write(address, buffer)
864 }
865
866 fn write_iter<B>(&mut self, _address: u8, _bytes: B) -> Result<(), Self::Error>
867 where
868 B: IntoIterator<Item = u8>,
869 {
870 todo!();
871 }
872
873 fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error>
874 where
875 B: IntoIterator<Item = u8>,
876 {
877 todo!();
878 }
879
880 fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> {
881 self.blocking_write_read(address, wr_buffer, rd_buffer)
882 }
883
884 fn transaction<'a>(
885 &mut self,
886 _address: u8,
887 _operations: &mut [embedded_hal_1::i2c::blocking::Operation<'a>],
888 ) -> Result<(), Self::Error> {
889 todo!();
890 }
891
892 fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error>
893 where
894 O: IntoIterator<Item = embedded_hal_1::i2c::blocking::Operation<'a>>,
895 {
896 todo!();
897 }
898 }
857} 899}
858 900
859cfg_if::cfg_if! { 901cfg_if::cfg_if! {