diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-18 20:01:39 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-18 20:02:05 +0200 |
| commit | a3a40bad6c6cb5a3de67234d0206475e9042e8e7 (patch) | |
| tree | 2b92b1187bdb1b732b9058878417dbf03affc3e6 /embassy-embedded-hal/src/shared_bus/asynch | |
| parent | 4dc800710d2269d5baebd62ae5a62205570db365 (diff) | |
Rename XXBusDevice to XXDevice.
Diffstat (limited to 'embassy-embedded-hal/src/shared_bus/asynch')
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | 40 | ||||
| -rw-r--r-- | embassy-embedded-hal/src/shared_bus/asynch/spi.rs | 44 |
2 files changed, 42 insertions, 42 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs index 136117920..5bd3d9bc5 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | //! # Example (nrf52) | 3 | //! # Example (nrf52) |
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::i2c::I2cBusDevice; | 6 | //! use embassy_embedded_hal::shared_bus::i2c::I2cDevice; |
| 7 | //! use embassy::mutex::Mutex; | 7 | //! use embassy::mutex::Mutex; |
| 8 | //! use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 8 | //! use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 9 | //! | 9 | //! |
| @@ -15,11 +15,11 @@ | |||
| 15 | //! let i2c_bus = I2C_BUS.put(i2c_bus); | 15 | //! let i2c_bus = I2C_BUS.put(i2c_bus); |
| 16 | //! | 16 | //! |
| 17 | //! // Device 1, using embedded-hal-async compatible driver for QMC5883L compass | 17 | //! // Device 1, using embedded-hal-async compatible driver for QMC5883L compass |
| 18 | //! let i2c_dev1 = I2cBusDevice::new(i2c_bus); | 18 | //! let i2c_dev1 = I2cDevice::new(i2c_bus); |
| 19 | //! let compass = QMC5883L::new(i2c_dev1).await.unwrap(); | 19 | //! let compass = QMC5883L::new(i2c_dev1).await.unwrap(); |
| 20 | //! | 20 | //! |
| 21 | //! // Device 2, using embedded-hal-async compatible driver for Mpu6050 accelerometer | 21 | //! // Device 2, using embedded-hal-async compatible driver for Mpu6050 accelerometer |
| 22 | //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); | 22 | //! let i2c_dev2 = I2cDevice::new(i2c_bus); |
| 23 | //! let mpu = Mpu6050::new(i2c_dev2); | 23 | //! let mpu = Mpu6050::new(i2c_dev2); |
| 24 | //! ``` | 24 | //! ``` |
| 25 | use core::future::Future; | 25 | use core::future::Future; |
| @@ -28,27 +28,27 @@ use embassy::blocking_mutex::raw::RawMutex; | |||
| 28 | use embassy::mutex::Mutex; | 28 | use embassy::mutex::Mutex; |
| 29 | use embedded_hal_async::i2c; | 29 | use embedded_hal_async::i2c; |
| 30 | 30 | ||
| 31 | use crate::shared_bus::I2cBusDeviceError; | 31 | use crate::shared_bus::I2cDeviceError; |
| 32 | use crate::SetConfig; | 32 | use crate::SetConfig; |
| 33 | 33 | ||
| 34 | pub struct I2cBusDevice<'a, M: RawMutex, BUS> { | 34 | pub struct I2cDevice<'a, M: RawMutex, BUS> { |
| 35 | bus: &'a Mutex<M, BUS>, | 35 | bus: &'a Mutex<M, BUS>, |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | impl<'a, M: RawMutex, BUS> I2cBusDevice<'a, M, BUS> { | 38 | impl<'a, M: RawMutex, BUS> I2cDevice<'a, M, BUS> { |
| 39 | pub fn new(bus: &'a Mutex<M, BUS>) -> Self { | 39 | pub fn new(bus: &'a Mutex<M, BUS>) -> Self { |
| 40 | Self { bus } | 40 | Self { bus } |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cBusDevice<'a, M, BUS> | 44 | impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cDevice<'a, M, BUS> |
| 45 | where | 45 | where |
| 46 | BUS: i2c::ErrorType, | 46 | BUS: i2c::ErrorType, |
| 47 | { | 47 | { |
| 48 | type Error = I2cBusDeviceError<BUS::Error>; | 48 | type Error = I2cDeviceError<BUS::Error>; |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | impl<M, BUS> i2c::I2c for I2cBusDevice<'_, M, BUS> | 51 | impl<M, BUS> i2c::I2c for I2cDevice<'_, M, BUS> |
| 52 | where | 52 | where |
| 53 | M: RawMutex + 'static, | 53 | M: RawMutex + 'static, |
| 54 | BUS: i2c::I2c + 'static, | 54 | BUS: i2c::I2c + 'static, |
| @@ -58,7 +58,7 @@ where | |||
| 58 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { | 58 | fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { |
| 59 | async move { | 59 | async move { |
| 60 | let mut bus = self.bus.lock().await; | 60 | let mut bus = self.bus.lock().await; |
| 61 | bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?; | 61 | bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; |
| 62 | Ok(()) | 62 | Ok(()) |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| @@ -68,7 +68,7 @@ where | |||
| 68 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { | 68 | fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { |
| 69 | async move { | 69 | async move { |
| 70 | let mut bus = self.bus.lock().await; | 70 | let mut bus = self.bus.lock().await; |
| 71 | bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?; | 71 | bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; |
| 72 | Ok(()) | 72 | Ok(()) |
| 73 | } | 73 | } |
| 74 | } | 74 | } |
| @@ -85,7 +85,7 @@ where | |||
| 85 | let mut bus = self.bus.lock().await; | 85 | let mut bus = self.bus.lock().await; |
| 86 | bus.write_read(address, wr_buffer, rd_buffer) | 86 | bus.write_read(address, wr_buffer, rd_buffer) |
| 87 | .await | 87 | .await |
| 88 | .map_err(I2cBusDeviceError::I2c)?; | 88 | .map_err(I2cDeviceError::I2c)?; |
| 89 | Ok(()) | 89 | Ok(()) |
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| @@ -103,27 +103,27 @@ where | |||
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub struct I2cBusDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { | 106 | pub struct I2cDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig> { |
| 107 | bus: &'a Mutex<M, BUS>, | 107 | bus: &'a Mutex<M, BUS>, |
| 108 | config: BUS::Config, | 108 | config: BUS::Config, |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | impl<'a, M: RawMutex, BUS: SetConfig> I2cBusDeviceWithConfig<'a, M, BUS> { | 111 | impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { |
| 112 | pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self { | 112 | pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self { |
| 113 | Self { bus, config } | 113 | Self { bus, config } |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | impl<'a, M, BUS> i2c::ErrorType for I2cBusDeviceWithConfig<'a, M, BUS> | 117 | impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS> |
| 118 | where | 118 | where |
| 119 | BUS: i2c::ErrorType, | 119 | BUS: i2c::ErrorType, |
| 120 | M: RawMutex, | 120 | M: RawMutex, |
| 121 | BUS: SetConfig, | 121 | BUS: SetConfig, |
| 122 | { | 122 | { |
| 123 | type Error = I2cBusDeviceError<BUS::Error>; | 123 | type Error = I2cDeviceError<BUS::Error>; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | impl<M, BUS> i2c::I2c for I2cBusDeviceWithConfig<'_, M, BUS> | 126 | impl<M, BUS> i2c::I2c for I2cDeviceWithConfig<'_, M, BUS> |
| 127 | where | 127 | where |
| 128 | M: RawMutex + 'static, | 128 | M: RawMutex + 'static, |
| 129 | BUS: i2c::I2c + SetConfig + 'static, | 129 | BUS: i2c::I2c + SetConfig + 'static, |
| @@ -134,7 +134,7 @@ where | |||
| 134 | async move { | 134 | async move { |
| 135 | let mut bus = self.bus.lock().await; | 135 | let mut bus = self.bus.lock().await; |
| 136 | bus.set_config(&self.config); | 136 | bus.set_config(&self.config); |
| 137 | bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?; | 137 | bus.read(address, buffer).await.map_err(I2cDeviceError::I2c)?; |
| 138 | Ok(()) | 138 | Ok(()) |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| @@ -145,7 +145,7 @@ where | |||
| 145 | async move { | 145 | async move { |
| 146 | let mut bus = self.bus.lock().await; | 146 | let mut bus = self.bus.lock().await; |
| 147 | bus.set_config(&self.config); | 147 | bus.set_config(&self.config); |
| 148 | bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?; | 148 | bus.write(address, bytes).await.map_err(I2cDeviceError::I2c)?; |
| 149 | Ok(()) | 149 | Ok(()) |
| 150 | } | 150 | } |
| 151 | } | 151 | } |
| @@ -163,7 +163,7 @@ where | |||
| 163 | bus.set_config(&self.config); | 163 | bus.set_config(&self.config); |
| 164 | bus.write_read(address, wr_buffer, rd_buffer) | 164 | bus.write_read(address, wr_buffer, rd_buffer) |
| 165 | .await | 165 | .await |
| 166 | .map_err(I2cBusDeviceError::I2c)?; | 166 | .map_err(I2cDeviceError::I2c)?; |
| 167 | Ok(()) | 167 | Ok(()) |
| 168 | } | 168 | } |
| 169 | } | 169 | } |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 8034c90b5..343184d12 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | //! # Example (nrf52) | 3 | //! # Example (nrf52) |
| 4 | //! | 4 | //! |
| 5 | //! ```rust | 5 | //! ```rust |
| 6 | //! use embassy_embedded_hal::shared_bus::spi::SpiBusDevice; | 6 | //! use embassy_embedded_hal::shared_bus::spi::SpiDevice; |
| 7 | //! use embassy::mutex::Mutex; | 7 | //! use embassy::mutex::Mutex; |
| 8 | //! use embassy::blocking_mutex::raw::ThreadModeRawMutex; | 8 | //! use embassy::blocking_mutex::raw::ThreadModeRawMutex; |
| 9 | //! | 9 | //! |
| @@ -17,12 +17,12 @@ | |||
| 17 | //! | 17 | //! |
| 18 | //! // Device 1, using embedded-hal-async compatible driver for ST7735 LCD display | 18 | //! // Device 1, using embedded-hal-async compatible driver for ST7735 LCD display |
| 19 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); | 19 | //! let cs_pin1 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); |
| 20 | //! let spi_dev1 = SpiBusDevice::new(spi_bus, cs_pin1); | 20 | //! let spi_dev1 = SpiDevice::new(spi_bus, cs_pin1); |
| 21 | //! let display1 = ST7735::new(spi_dev1, dc1, rst1, Default::default(), 160, 128); | 21 | //! let display1 = ST7735::new(spi_dev1, dc1, rst1, Default::default(), 160, 128); |
| 22 | //! | 22 | //! |
| 23 | //! // Device 2 | 23 | //! // Device 2 |
| 24 | //! let cs_pin2 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); | 24 | //! let cs_pin2 = Output::new(p.P0_24, Level::Low, OutputDrive::Standard); |
| 25 | //! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); | 25 | //! let spi_dev2 = SpiDevice::new(spi_bus, cs_pin2); |
| 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); | 26 | //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); |
| 27 | //! ``` | 27 | //! ``` |
| 28 | use core::future::Future; | 28 | use core::future::Future; |
| @@ -33,29 +33,29 @@ use embedded_hal_1::digital::blocking::OutputPin; | |||
| 33 | use embedded_hal_1::spi::ErrorType; | 33 | use embedded_hal_1::spi::ErrorType; |
| 34 | use embedded_hal_async::spi; | 34 | use embedded_hal_async::spi; |
| 35 | 35 | ||
| 36 | use crate::shared_bus::SpiBusDeviceError; | 36 | use crate::shared_bus::SpiDeviceError; |
| 37 | use crate::SetConfig; | 37 | use crate::SetConfig; |
| 38 | 38 | ||
| 39 | pub struct SpiBusDevice<'a, M: RawMutex, BUS, CS> { | 39 | pub struct SpiDevice<'a, M: RawMutex, BUS, CS> { |
| 40 | bus: &'a Mutex<M, BUS>, | 40 | bus: &'a Mutex<M, BUS>, |
| 41 | cs: CS, | 41 | cs: CS, |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | impl<'a, M: RawMutex, BUS, CS> SpiBusDevice<'a, M, BUS, CS> { | 44 | impl<'a, M: RawMutex, BUS, CS> SpiDevice<'a, M, BUS, CS> { |
| 45 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS) -> Self { | 45 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS) -> Self { |
| 46 | Self { bus, cs } | 46 | Self { bus, cs } |
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | impl<'a, M: RawMutex, BUS, CS> spi::ErrorType for SpiBusDevice<'a, M, BUS, CS> | 50 | impl<'a, M: RawMutex, BUS, CS> spi::ErrorType for SpiDevice<'a, M, BUS, CS> |
| 51 | where | 51 | where |
| 52 | BUS: spi::ErrorType, | 52 | BUS: spi::ErrorType, |
| 53 | CS: OutputPin, | 53 | CS: OutputPin, |
| 54 | { | 54 | { |
| 55 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; | 55 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDevice<'_, M, BUS, CS> | 58 | impl<M, BUS, CS> spi::SpiDevice for SpiDevice<'_, M, BUS, CS> |
| 59 | where | 59 | where |
| 60 | M: RawMutex + 'static, | 60 | M: RawMutex + 'static, |
| 61 | BUS: spi::SpiBusFlush + 'static, | 61 | BUS: spi::SpiBusFlush + 'static, |
| @@ -76,7 +76,7 @@ where | |||
| 76 | { | 76 | { |
| 77 | async move { | 77 | async move { |
| 78 | let mut bus = self.bus.lock().await; | 78 | let mut bus = self.bus.lock().await; |
| 79 | self.cs.set_low().map_err(SpiBusDeviceError::Cs)?; | 79 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 80 | 80 | ||
| 81 | let f_res = f(&mut *bus).await; | 81 | let f_res = f(&mut *bus).await; |
| 82 | 82 | ||
| @@ -84,37 +84,37 @@ where | |||
| 84 | let flush_res = bus.flush().await; | 84 | let flush_res = bus.flush().await; |
| 85 | let cs_res = self.cs.set_high(); | 85 | let cs_res = self.cs.set_high(); |
| 86 | 86 | ||
| 87 | let f_res = f_res.map_err(SpiBusDeviceError::Spi)?; | 87 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; |
| 88 | flush_res.map_err(SpiBusDeviceError::Spi)?; | 88 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 89 | cs_res.map_err(SpiBusDeviceError::Cs)?; | 89 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 90 | 90 | ||
| 91 | Ok(f_res) | 91 | Ok(f_res) |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | pub struct SpiBusDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { | 96 | pub struct SpiDeviceWithConfig<'a, M: RawMutex, BUS: SetConfig, CS> { |
| 97 | bus: &'a Mutex<M, BUS>, | 97 | bus: &'a Mutex<M, BUS>, |
| 98 | cs: CS, | 98 | cs: CS, |
| 99 | config: BUS::Config, | 99 | config: BUS::Config, |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiBusDeviceWithConfig<'a, M, BUS, CS> { | 102 | impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { |
| 103 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self { | 103 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self { |
| 104 | Self { bus, cs, config } | 104 | Self { bus, cs, config } |
| 105 | } | 105 | } |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | impl<'a, M, BUS, CS> spi::ErrorType for SpiBusDeviceWithConfig<'a, M, BUS, CS> | 108 | impl<'a, M, BUS, CS> spi::ErrorType for SpiDeviceWithConfig<'a, M, BUS, CS> |
| 109 | where | 109 | where |
| 110 | BUS: spi::ErrorType + SetConfig, | 110 | BUS: spi::ErrorType + SetConfig, |
| 111 | CS: OutputPin, | 111 | CS: OutputPin, |
| 112 | M: RawMutex, | 112 | M: RawMutex, |
| 113 | { | 113 | { |
| 114 | type Error = SpiBusDeviceError<BUS::Error, CS::Error>; | 114 | type Error = SpiDeviceError<BUS::Error, CS::Error>; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | impl<M, BUS, CS> spi::SpiDevice for SpiBusDeviceWithConfig<'_, M, BUS, CS> | 117 | impl<M, BUS, CS> spi::SpiDevice for SpiDeviceWithConfig<'_, M, BUS, CS> |
| 118 | where | 118 | where |
| 119 | M: RawMutex + 'static, | 119 | M: RawMutex + 'static, |
| 120 | BUS: spi::SpiBusFlush + SetConfig + 'static, | 120 | BUS: spi::SpiBusFlush + SetConfig + 'static, |
| @@ -136,7 +136,7 @@ where | |||
| 136 | async move { | 136 | async move { |
| 137 | let mut bus = self.bus.lock().await; | 137 | let mut bus = self.bus.lock().await; |
| 138 | bus.set_config(&self.config); | 138 | bus.set_config(&self.config); |
| 139 | self.cs.set_low().map_err(SpiBusDeviceError::Cs)?; | 139 | self.cs.set_low().map_err(SpiDeviceError::Cs)?; |
| 140 | 140 | ||
| 141 | let f_res = f(&mut *bus).await; | 141 | let f_res = f(&mut *bus).await; |
| 142 | 142 | ||
| @@ -144,9 +144,9 @@ where | |||
| 144 | let flush_res = bus.flush().await; | 144 | let flush_res = bus.flush().await; |
| 145 | let cs_res = self.cs.set_high(); | 145 | let cs_res = self.cs.set_high(); |
| 146 | 146 | ||
| 147 | let f_res = f_res.map_err(SpiBusDeviceError::Spi)?; | 147 | let f_res = f_res.map_err(SpiDeviceError::Spi)?; |
| 148 | flush_res.map_err(SpiBusDeviceError::Spi)?; | 148 | flush_res.map_err(SpiDeviceError::Spi)?; |
| 149 | cs_res.map_err(SpiBusDeviceError::Cs)?; | 149 | cs_res.map_err(SpiDeviceError::Cs)?; |
| 150 | 150 | ||
| 151 | Ok(f_res) | 151 | Ok(f_res) |
| 152 | } | 152 | } |
