From 6c801a0dba93680c8e41e611eada0576eab0f861 Mon Sep 17 00:00:00 2001 From: Dion Dokter Date: Thu, 18 Sep 2025 11:04:13 +0200 Subject: [PATCH] Add clone impl on shared i2c --- .../src/shared_bus/asynch/i2c.rs | 18 ++++++++++++++++++ .../src/shared_bus/blocking/i2c.rs | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) 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> { } } +impl<'a, M: RawMutex, BUS> Clone for I2cDevice<'a, M, BUS> { + fn clone(&self) -> Self { + Self { bus: self.bus } + } +} + impl<'a, M: RawMutex, BUS> i2c::ErrorType for I2cDevice<'a, M, BUS> where BUS: i2c::ErrorType, @@ -113,6 +119,18 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { } } +impl<'a, M: RawMutex, BUS: SetConfig> Clone for I2cDeviceWithConfig<'a, M, BUS> +where + BUS::Config: Clone, +{ + fn clone(&self) -> Self { + Self { + bus: self.bus, + config: self.config.clone(), + } + } +} + impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS> where BUS: i2c::ErrorType, diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 627767c8a..fa34cd416 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> { } } +impl<'a, M: RawMutex, BUS> Clone for I2cDevice<'a, M, BUS> { + fn clone(&self) -> Self { + Self { bus: self.bus } + } +} + impl<'a, M: RawMutex, BUS> ErrorType for I2cDevice<'a, M, BUS> where BUS: ErrorType, @@ -139,6 +145,18 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { } } +impl<'a, M: RawMutex, BUS: SetConfig> Clone for I2cDeviceWithConfig<'a, M, BUS> +where + BUS::Config: Clone, +{ + fn clone(&self) -> Self { + Self { + bus: self.bus, + config: self.config.clone(), + } + } +} + impl<'a, M, BUS> ErrorType for I2cDeviceWithConfig<'a, M, BUS> where M: RawMutex,