diff options
Diffstat (limited to 'embassy-nrf/src/twim.rs')
| -rw-r--r-- | embassy-nrf/src/twim.rs | 115 |
1 files changed, 53 insertions, 62 deletions
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 919bb4ab2..da8e15d02 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -810,81 +810,72 @@ mod eh02 { | |||
| 810 | } | 810 | } |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | #[cfg(feature = "unstable-traits")] | 813 | impl embedded_hal_1::i2c::Error for Error { |
| 814 | mod eh1 { | 814 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { |
| 815 | use super::*; | 815 | match *self { |
| 816 | 816 | Self::TxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other, | |
| 817 | impl embedded_hal_1::i2c::Error for Error { | 817 | Self::RxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other, |
| 818 | fn kind(&self) -> embedded_hal_1::i2c::ErrorKind { | 818 | Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, |
| 819 | match *self { | 819 | Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, |
| 820 | Self::TxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other, | 820 | Self::BufferNotInRAM => embedded_hal_1::i2c::ErrorKind::Other, |
| 821 | Self::RxBufferTooLong => embedded_hal_1::i2c::ErrorKind::Other, | 821 | Self::AddressNack => { |
| 822 | Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, | 822 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address) |
| 823 | Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 824 | Self::BufferNotInRAM => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 825 | Self::AddressNack => { | ||
| 826 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address) | ||
| 827 | } | ||
| 828 | Self::DataNack => { | ||
| 829 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data) | ||
| 830 | } | ||
| 831 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 832 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 833 | } | 823 | } |
| 824 | Self::DataNack => { | ||
| 825 | embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data) | ||
| 826 | } | ||
| 827 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | ||
| 828 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 834 | } | 829 | } |
| 835 | } | 830 | } |
| 831 | } | ||
| 836 | 832 | ||
| 837 | impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for Twim<'d, T> { | 833 | impl<'d, T: Instance> embedded_hal_1::i2c::ErrorType for Twim<'d, T> { |
| 838 | type Error = Error; | 834 | type Error = Error; |
| 839 | } | 835 | } |
| 840 | 836 | ||
| 841 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for Twim<'d, T> { | 837 | impl<'d, T: Instance> embedded_hal_1::i2c::I2c for Twim<'d, T> { |
| 842 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { | 838 | fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 843 | self.blocking_read(address, buffer) | 839 | self.blocking_read(address, buffer) |
| 844 | } | 840 | } |
| 845 | 841 | ||
| 846 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { | 842 | fn write(&mut self, address: u8, buffer: &[u8]) -> Result<(), Self::Error> { |
| 847 | self.blocking_write(address, buffer) | 843 | self.blocking_write(address, buffer) |
| 848 | } | 844 | } |
| 849 | 845 | ||
| 850 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { | 846 | fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { |
| 851 | self.blocking_write_read(address, wr_buffer, rd_buffer) | 847 | self.blocking_write_read(address, wr_buffer, rd_buffer) |
| 852 | } | 848 | } |
| 853 | 849 | ||
| 854 | fn transaction<'a>( | 850 | fn transaction<'a>( |
| 855 | &mut self, | 851 | &mut self, |
| 856 | _address: u8, | 852 | _address: u8, |
| 857 | _operations: &mut [embedded_hal_1::i2c::Operation<'a>], | 853 | _operations: &mut [embedded_hal_1::i2c::Operation<'a>], |
| 858 | ) -> Result<(), Self::Error> { | 854 | ) -> Result<(), Self::Error> { |
| 859 | todo!(); | 855 | todo!(); |
| 860 | } | ||
| 861 | } | 856 | } |
| 862 | } | 857 | } |
| 863 | 858 | ||
| 864 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | 859 | impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { |
| 865 | mod eha { | 860 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { |
| 866 | use super::*; | 861 | self.read(address, read).await |
| 867 | impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { | 862 | } |
| 868 | async fn read(&mut self, address: u8, read: &mut [u8]) -> Result<(), Self::Error> { | ||
| 869 | self.read(address, read).await | ||
| 870 | } | ||
| 871 | 863 | ||
| 872 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { | 864 | async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Self::Error> { |
| 873 | self.write(address, write).await | 865 | self.write(address, write).await |
| 874 | } | 866 | } |
| 875 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { | 867 | async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> { |
| 876 | self.write_read(address, write, read).await | 868 | self.write_read(address, write, read).await |
| 877 | } | 869 | } |
| 878 | 870 | ||
| 879 | async fn transaction( | 871 | async fn transaction( |
| 880 | &mut self, | 872 | &mut self, |
| 881 | address: u8, | 873 | address: u8, |
| 882 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], | 874 | operations: &mut [embedded_hal_1::i2c::Operation<'_>], |
| 883 | ) -> Result<(), Self::Error> { | 875 | ) -> Result<(), Self::Error> { |
| 884 | let _ = address; | 876 | let _ = address; |
| 885 | let _ = operations; | 877 | let _ = operations; |
| 886 | todo!() | 878 | todo!() |
| 887 | } | ||
| 888 | } | 879 | } |
| 889 | } | 880 | } |
| 890 | 881 | ||
