diff options
Diffstat (limited to 'embassy-stm32/src/i2c/mod.rs')
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 142 |
1 files changed, 64 insertions, 78 deletions
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 19346d707..d2a50cf7e 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | 4 | ||
| 5 | use crate::dma::NoDma; | ||
| 5 | use crate::interrupt; | 6 | use crate::interrupt; |
| 6 | 7 | ||
| 7 | #[cfg_attr(i2c_v1, path = "v1.rs")] | 8 | #[cfg_attr(i2c_v1, path = "v1.rs")] |
| @@ -97,107 +98,92 @@ foreach_peripheral!( | |||
| 97 | }; | 98 | }; |
| 98 | ); | 99 | ); |
| 99 | 100 | ||
| 100 | mod eh02 { | 101 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { |
| 101 | use super::*; | 102 | type Error = Error; |
| 102 | |||
| 103 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Read for I2c<'d, T> { | ||
| 104 | type Error = Error; | ||
| 105 | 103 | ||
| 106 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 104 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 107 | self.blocking_read(address, buffer) | 105 | self.blocking_read(address, buffer) |
| 108 | } | ||
| 109 | } | 106 | } |
| 107 | } | ||
| 110 | 108 | ||
| 111 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { | 109 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::Write for I2c<'d, T> { |
| 112 | type Error = Error; | 110 | type Error = Error; |
| 113 | 111 | ||
| 114 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 112 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 115 | self.blocking_write(address, write) | 113 | self.blocking_write(address, write) |
| 116 | } | ||
| 117 | } | 114 | } |
| 115 | } | ||
| 118 | 116 | ||
| 119 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { | 117 | impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { |
| 120 | type Error = Error; | 118 | type Error = Error; |
| 121 | 119 | ||
| 122 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 120 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 123 | self.blocking_write_read(address, write, read) | 121 | self.blocking_write_read(address, write, read) |
| 124 | } | ||
| 125 | } | 122 | } |
| 126 | } | 123 | } |
| 127 | 124 | ||
| 128 | #[cfg(feature = "unstable-traits")] | 125 | impl embedded_hal_1::i2c::Error for Error { |
| 129 | mod eh1 { | 126 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { |
| 130 | use super::*; | 127 | match *self { |
| 131 | use crate::dma::NoDma; | 128 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, |
| 132 | 129 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, | |
| 133 | impl embedded_hal_1::i2c::Error for Error { | 130 | Self::Nack => { |
| 134 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { | 131 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) |
| 135 | match *self { | ||
| 136 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, | ||
| 137 | Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, | ||
| 138 | Self::Nack => { | ||
| 139 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) | ||
| 140 | } | ||
| 141 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 142 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 143 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 144 | Self::ZeroLengthTransfer => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 145 | } | 132 | } |
| 133 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 134 | Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 135 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 136 | Self::ZeroLengthTransfer => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 146 | } | 137 | } |
| 147 | } | 138 | } |
| 139 | } | ||
| 148 | 140 | ||
| 149 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { | 141 | impl<'d, T: Instance, TXDMA, RXDMA> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { |
| 150 | type Error = Error; | 142 | type Error = Error; |
| 151 | } | 143 | } |
| 152 | 144 | ||
| 153 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { | 145 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for I2c<'d, T, NoDma, NoDma> { |
| 154 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | 146 | fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 155 | self.blocking_read(address, read) | 147 | self.blocking_read(address, read) |
| 156 | } | 148 | } |
| 157 | 149 | ||
| 158 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 150 | fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 159 | self.blocking_write(address, write) | 151 | self.blocking_write(address, write) |
| 160 | } | 152 | } |
| 161 | 153 | ||
| 162 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 154 | fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 163 | self.blocking_write_read(address, write, read) | 155 | self.blocking_write_read(address, write, read) |
| 164 | } | 156 | } |
| 165 | 157 | ||
| 166 | fn transaction( | 158 | fn transaction( |
| 167 | &mut self, | 159 | &mut self, |
| 168 | _address: u8, | 160 | _address: u8, |
| 169 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 161 | _operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 170 | ) -> Result<(), Self::Error> { | 162 | ) -> Result<(), Self::Error> { |
| 171 | todo!(); | 163 | todo!(); |
| 172 | } | ||
| 173 | } | 164 | } |
| 174 | } | 165 | } |
| 175 | 166 | ||
| 176 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 167 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { |
| 177 | mod eha { | 168 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 178 | use super::*; | 169 | self.read(address, read).await |
| 179 | 170 | } | |
| 180 | impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> { | ||
| 181 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | ||
| 182 | self.read(address, read).await | ||
| 183 | } | ||
| 184 | 171 | ||
| 185 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 172 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 186 | self.write(address, write).await | 173 | self.write(address, write).await |
| 187 | } | 174 | } |
| 188 | 175 | ||
| 189 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 176 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 190 | self.write_read(address, write, read).await | 177 | self.write_read(address, write, read).await |
| 191 | } | 178 | } |
| 192 | 179 | ||
| 193 | async fn transaction( | 180 | async fn transaction( |
| 194 | &mut self, | 181 | &mut self, |
| 195 | address: u8, | 182 | address: u8, |
| 196 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 183 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 197 | ) -> Result<(), Self::Error> { | 184 | ) -> Result<(), Self::Error> { |
| 198 | let _ = address; | 185 | let _ = address; |
| 199 | let _ = operations; | 186 | let _ = operations; |
| 200 | todo!() | 187 | todo!() |
| 201 | } | ||
| 202 | } | 188 | } |
| 203 | } | 189 | } |
