aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <[email protected]>2021-12-28 23:27:59 -0500
committerBen Gamari <[email protected]>2021-12-28 23:27:59 -0500
commit8da6471a50ac613919e5e6fcc9d1aefdde3af638 (patch)
treef12927c173f85813a6060b7ceea471d879d70107
parent7561fa19348530ce85e2645e0be8801b9b2bbe13 (diff)
stm32/dac: Fix disable_channel
Previously disable_channel enabled rather than disabled the requested channel due to an apparent copy-paste error. Refactor to eliminate this sort of issue by construction.
-rw-r--r--embassy-stm32/src/dac/v2.rs37
1 files changed, 8 insertions, 29 deletions
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs
index 55a881d89..49da48e88 100644
--- a/embassy-stm32/src/dac/v2.rs
+++ b/embassy-stm32/src/dac/v2.rs
@@ -131,7 +131,7 @@ impl<'d, T: Instance> Dac<'d, T> {
131 } 131 }
132 } 132 }
133 133
134 pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> { 134 fn set_channel_enable(&mut self, ch: Channel, on: bool) -> Result<(), Error> {
135 match ch { 135 match ch {
136 Channel::Ch1 => { 136 Channel::Ch1 => {
137 if self.ch1.is_none() { 137 if self.ch1.is_none() {
@@ -139,7 +139,7 @@ impl<'d, T: Instance> Dac<'d, T> {
139 } else { 139 } else {
140 unsafe { 140 unsafe {
141 T::regs().cr().modify(|reg| { 141 T::regs().cr().modify(|reg| {
142 reg.set_en1(true); 142 reg.set_en1(on);
143 }); 143 });
144 } 144 }
145 Ok(()) 145 Ok(())
@@ -151,7 +151,7 @@ impl<'d, T: Instance> Dac<'d, T> {
151 } else { 151 } else {
152 unsafe { 152 unsafe {
153 T::regs().cr().modify(|reg| { 153 T::regs().cr().modify(|reg| {
154 reg.set_en2(true); 154 reg.set_en2(on);
155 }); 155 });
156 } 156 }
157 Ok(()) 157 Ok(())
@@ -160,33 +160,12 @@ impl<'d, T: Instance> Dac<'d, T> {
160 } 160 }
161 } 161 }
162 162
163 pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> {
164 self.set_channel_enable(ch, true)
165 }
166
163 pub fn disable_channel(&mut self, ch: Channel) -> Result<(), Error> { 167 pub fn disable_channel(&mut self, ch: Channel) -> Result<(), Error> {
164 match ch { 168 self.set_channel_enable(ch, false)
165 Channel::Ch1 => {
166 if self.ch1.is_none() {
167 Err(Error::UnconfiguredChannel)
168 } else {
169 unsafe {
170 T::regs().cr().modify(|reg| {
171 reg.set_en1(true);
172 });
173 }
174 Ok(())
175 }
176 }
177 Channel::Ch2 => {
178 if self.ch2.is_none() {
179 Err(Error::UnconfiguredChannel)
180 } else {
181 unsafe {
182 T::regs().cr().modify(|reg| {
183 reg.set_en2(true);
184 });
185 }
186 Ok(())
187 }
188 }
189 }
190 } 169 }
191 170
192 pub fn select_trigger_ch1(&mut self, trigger: Ch1Trigger) -> Result<(), Error> { 171 pub fn select_trigger_ch1(&mut self, trigger: Ch1Trigger) -> Result<(), Error> {