diff options
| author | Caleb Jamison <[email protected]> | 2024-03-23 12:21:13 -0400 |
|---|---|---|
| committer | Caleb Jamison <[email protected]> | 2024-03-23 12:21:13 -0400 |
| commit | 8f1bed3d956c1e2fae2ab11b292c8fe73c7b6a2b (patch) | |
| tree | 2a06ac620dc9cda75b508450e00bf8c9fe0e0a37 /embassy-embedded-hal/src | |
| parent | 1171e116553f6ac43e12505b387b6eabe3037bf9 (diff) | |
Allow changing Spi/I2cDeviceWithConfig's config at runtime
Diffstat (limited to 'embassy-embedded-hal/src')
4 files changed, 20 insertions, 0 deletions
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs index 779c04263..71ce09def 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/i2c.rs | |||
| @@ -106,6 +106,11 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { | |||
| 106 | pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self { | 106 | pub fn new(bus: &'a Mutex<M, BUS>, config: BUS::Config) -> Self { |
| 107 | Self { bus, config } | 107 | Self { bus, config } |
| 108 | } | 108 | } |
| 109 | |||
| 110 | /// Change the device's config at runtime | ||
| 111 | pub fn set_config(&mut self, config: BUS::Config) { | ||
| 112 | self.config = config; | ||
| 113 | } | ||
| 109 | } | 114 | } |
| 110 | 115 | ||
| 111 | impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS> | 116 | impl<'a, M, BUS> i2c::ErrorType for I2cDeviceWithConfig<'a, M, BUS> |
diff --git a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs index 62b2c92a0..9890f218d 100644 --- a/embassy-embedded-hal/src/shared_bus/asynch/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/asynch/spi.rs | |||
| @@ -122,6 +122,11 @@ impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { | |||
| 122 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self { | 122 | pub fn new(bus: &'a Mutex<M, BUS>, cs: CS, config: BUS::Config) -> Self { |
| 123 | Self { bus, cs, config } | 123 | Self { bus, cs, config } |
| 124 | } | 124 | } |
| 125 | |||
| 126 | /// Change the device's config at runtime | ||
| 127 | pub fn set_config(&mut self, config: BUS::Config) { | ||
| 128 | self.config = config; | ||
| 129 | } | ||
| 125 | } | 130 | } |
| 126 | 131 | ||
| 127 | impl<'a, M, BUS, CS> spi::ErrorType for SpiDeviceWithConfig<'a, M, BUS, CS> | 132 | impl<'a, M, BUS, CS> spi::ErrorType for SpiDeviceWithConfig<'a, M, BUS, CS> |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs index 1b08cb28e..627767c8a 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/i2c.rs | |||
| @@ -132,6 +132,11 @@ impl<'a, M: RawMutex, BUS: SetConfig> I2cDeviceWithConfig<'a, M, BUS> { | |||
| 132 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, config: BUS::Config) -> Self { | 132 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, config: BUS::Config) -> Self { |
| 133 | Self { bus, config } | 133 | Self { bus, config } |
| 134 | } | 134 | } |
| 135 | |||
| 136 | /// Change the device's config at runtime | ||
| 137 | pub fn set_config(&mut self, config: BUS::Config) { | ||
| 138 | self.config = config; | ||
| 139 | } | ||
| 135 | } | 140 | } |
| 136 | 141 | ||
| 137 | impl<'a, M, BUS> ErrorType for I2cDeviceWithConfig<'a, M, BUS> | 142 | impl<'a, M, BUS> ErrorType for I2cDeviceWithConfig<'a, M, BUS> |
diff --git a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs index 59b65bfbd..801899f9f 100644 --- a/embassy-embedded-hal/src/shared_bus/blocking/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/blocking/spi.rs | |||
| @@ -147,6 +147,11 @@ impl<'a, M: RawMutex, BUS: SetConfig, CS> SpiDeviceWithConfig<'a, M, BUS, CS> { | |||
| 147 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self { | 147 | pub fn new(bus: &'a Mutex<M, RefCell<BUS>>, cs: CS, config: BUS::Config) -> Self { |
| 148 | Self { bus, cs, config } | 148 | Self { bus, cs, config } |
| 149 | } | 149 | } |
| 150 | |||
| 151 | /// Change the device's config at runtime | ||
| 152 | pub fn set_config(&mut self, config: BUS::Config) { | ||
| 153 | self.config = config; | ||
| 154 | } | ||
| 150 | } | 155 | } |
| 151 | 156 | ||
| 152 | impl<'a, M, BUS, CS> spi::ErrorType for SpiDeviceWithConfig<'a, M, BUS, CS> | 157 | impl<'a, M, BUS, CS> spi::ErrorType for SpiDeviceWithConfig<'a, M, BUS, CS> |
