aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-01-01 10:29:47 +0000
committerGitHub <[email protected]>2022-01-01 10:29:47 +0000
commit2f637b7be2d7dec8a5edb47921b018a41c942cc9 (patch)
treebf61d63ba07bb77a2de126b126f39b4ccf5709c9
parentecb09b7313fa88fb02ac88f39acef0ee555ccd49 (diff)
parent8da6471a50ac613919e5e6fcc9d1aefdde3af638 (diff)
Merge #561
561: stm32/dac: Fix disable_channel r=Dirbaio a=bgamari 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. Co-authored-by: Ben Gamari <[email protected]>
-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> {