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 <ben@smart-cactus.org>
This commit is contained in:
commit
2f637b7be2
@ -131,7 +131,7 @@ impl<'d, T: Instance> Dac<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> {
|
fn set_channel_enable(&mut self, ch: Channel, on: bool) -> Result<(), Error> {
|
||||||
match ch {
|
match ch {
|
||||||
Channel::Ch1 => {
|
Channel::Ch1 => {
|
||||||
if self.ch1.is_none() {
|
if self.ch1.is_none() {
|
||||||
@ -139,7 +139,7 @@ impl<'d, T: Instance> Dac<'d, T> {
|
|||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
T::regs().cr().modify(|reg| {
|
T::regs().cr().modify(|reg| {
|
||||||
reg.set_en1(true);
|
reg.set_en1(on);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -151,7 +151,7 @@ impl<'d, T: Instance> Dac<'d, T> {
|
|||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
T::regs().cr().modify(|reg| {
|
T::regs().cr().modify(|reg| {
|
||||||
reg.set_en2(true);
|
reg.set_en2(on);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -160,33 +160,12 @@ impl<'d, T: Instance> Dac<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> {
|
||||||
|
self.set_channel_enable(ch, true)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn disable_channel(&mut self, ch: Channel) -> Result<(), Error> {
|
pub fn disable_channel(&mut self, ch: Channel) -> Result<(), Error> {
|
||||||
match ch {
|
self.set_channel_enable(ch, false)
|
||||||
Channel::Ch1 => {
|
|
||||||
if self.ch1.is_none() {
|
|
||||||
Err(Error::UnconfiguredChannel)
|
|
||||||
} else {
|
|
||||||
unsafe {
|
|
||||||
T::regs().cr().modify(|reg| {
|
|
||||||
reg.set_en1(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Channel::Ch2 => {
|
|
||||||
if self.ch2.is_none() {
|
|
||||||
Err(Error::UnconfiguredChannel)
|
|
||||||
} else {
|
|
||||||
unsafe {
|
|
||||||
T::regs().cr().modify(|reg| {
|
|
||||||
reg.set_en2(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_trigger_ch1(&mut self, trigger: Ch1Trigger) -> Result<(), Error> {
|
pub fn select_trigger_ch1(&mut self, trigger: Ch1Trigger) -> Result<(), Error> {
|
||||||
|
Loading…
Reference in New Issue
Block a user