Skip to content

Commit fa4aed4

Browse files
committed
Some cleanup
1 parent a6b804d commit fa4aed4

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/mcpwm.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ impl<U: Unit> Mcpwm<U> {
659659
MAX_PWM_TIMER_PRESCALE * MAX_PWM_TIMER_PERIOD * u32::from(lowest_frequency);
660660
let group_pre_scale = MCPWM_CLOCK_SOURCE_FREQUENCY / operator_source_frequency;
661661
if !(1..=256).contains(&group_pre_scale) {
662-
return Err(EspError::from(ESP_ERR_INVALID_ARG).unwrap());
662+
esp!(ESP_ERR_INVALID_ARG)?;
663663
}
664664

665665
esp!(unsafe { mcpwm_group_set_resolution(U::unit(), operator_source_frequency) })?;
@@ -686,7 +686,7 @@ impl<U: Unit> Mcpwm<U> {
686686
// TODO: Do we care about frequency < 1Hz?
687687
let group_pre_scale = MCPWM_CLOCK_SOURCE_FREQUENCY / frequency;
688688
if !(1..=256).contains(&group_pre_scale) {
689-
return Err(EspError::from(ESP_ERR_INVALID_ARG).unwrap());
689+
esp!(ESP_ERR_INVALID_ARG)?;
690690
}
691691

692692
esp!(unsafe { mcpwm_group_set_resolution(U::unit(), frequency) })?;
@@ -803,13 +803,13 @@ where
803803
// Can not specify a clock frequency lower then what has
804804
// been configured as the lowest clock frequency
805805
// Use `OperatorConfig::lowest_frequency` to enable lower frequencies
806-
return Err(EspError::from(ESP_ERR_INVALID_ARG).unwrap());
806+
esp!(ESP_ERR_INVALID_ARG)?;
807807
}
808808

809809
if config.lowest_frequency > mcpwm_module.borrow().operator_source_frequency.Hz() {
810810
// Can not specify a lowest_frequency larger than the corresponding value for
811811
// the parent MCPWM module. Use `Mcpwm::lowest_frequency` to enable higher frequencies
812-
return Err(EspError::from(ESP_ERR_INVALID_ARG).unwrap());
812+
esp!(ESP_ERR_INVALID_ARG)?;
813813
}
814814

815815
let resolution = u32::from(config.lowest_frequency) * MAX_PWM_TIMER_PERIOD;
@@ -884,23 +884,18 @@ where
884884
// mcpwm_stop will only fail when invalid args are given
885885
esp!(unsafe { mcpwm_stop(U::unit(), O::timer()) }).unwrap();
886886

887-
// TODO: Test and verify if this is the right way
888-
if self._pin_a.is_some() {
889-
// TODO: How to unset pin?
890-
// let io_signal = O::signal_a();
891-
// mcpwm_gpio_init(U::unit(), io_signal, -1)
892-
// does not seem to be it...
893-
todo!();
887+
// Detatch pins from MCPWM operator
888+
if let Some(_pin) = &self._pin_a {
889+
// TODO
890+
//pin.reset();
894891
}
895892

896-
if self._pin_b.is_some() {
897-
// TODO: How to unset pin?
898-
// let io_signal = O::signal_b();
899-
// mcpwm_gpio_init(U::unit(), io_signal, -1)
900-
// does not seem to be it...
901-
902-
todo!();
893+
// Detatch pins from MCPWM operator
894+
if let Some(_pin) = &self._pin_b {
895+
// TODO
896+
//pin.reset();
903897
}
898+
904899
// TODO: Do we need to reset any more state here such as dead time config?
905900
(self._instance, self._pin_a, self._pin_b)
906901
}

0 commit comments

Comments
 (0)