Skip to content

Commit 4acbca7

Browse files
committed
Resolve some of the comments
* Rename struct Timer to TimerDriver * Fix typo in fn attach_timerX * Remove OptionalOutputPin
1 parent d786f05 commit 4acbca7

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

examples/mcpwm-simple.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() -> anyhow::Result<()> {
6161
use embedded_hal::delay::DelayUs;
6262

6363
use esp_idf_hal::delay::FreeRtos;
64-
use esp_idf_hal::mcpwm::{OperatorConfig, Timer, TimerConfig};
64+
use esp_idf_hal::mcpwm::{OperatorConfig, TimerConfig, TimerDriver};
6565
use esp_idf_hal::prelude::Peripherals;
6666

6767
esp_idf_sys::link_patches();
@@ -71,11 +71,11 @@ fn main() -> anyhow::Result<()> {
7171
let peripherals = Peripherals::take().unwrap();
7272
let timer_config = TimerConfig::default().period_ticks(8_000); // 10kHz
7373
let operator_config = OperatorConfig::default(peripherals.pins.gpio4, peripherals.pins.gpio5);
74-
let timer = Timer::new(peripherals.mcpwm0.timer0, timer_config);
74+
let timer = TimerDriver::new(peripherals.mcpwm0.timer0, timer_config);
7575

7676
let mut timer = timer
7777
.into_connection()
78-
.attatch_operator0(peripherals.mcpwm0.operator0, operator_config);
78+
.attach_operator0(peripherals.mcpwm0.operator0, operator_config);
7979

8080
// Borrow references to the contained timer and operator
8181
let (timer, operator, _, _) = timer.split();

src/mcpwm/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub use self::{
8989
generator::{GeneratorAction, GeneratorConfig},
9090
operator::{Operator, OPERATOR},
9191
operator_config::OperatorConfig,
92-
timer::{Timer, TimerConfig, TIMER},
92+
timer::{TimerConfig, TimerDriver, TIMER},
9393
timer_connection::TimerConnection,
9494
};
9595

src/mcpwm/timer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl TimerConfig {
7575
}
7676
}
7777

78-
pub struct Timer<const N: u8, G: Group> {
78+
pub struct TimerDriver<const N: u8, G: Group> {
7979
_group: G,
8080
handle: mcpwm_timer_handle_t,
8181
_timer: TIMER<N, G>,
@@ -90,7 +90,7 @@ pub struct Timer<const N: u8, G: Group> {
9090
period_peak: u16,
9191
}
9292

93-
impl<const N: u8, G: Group> Timer<N, G> {
93+
impl<const N: u8, G: Group> TimerDriver<N, G> {
9494
pub fn new(timer: TIMER<N, G>, config: TimerConfig) -> Self {
9595
let mut flags: mcpwm_timer_config_t__bindgen_ty_1 = Default::default();
9696

@@ -186,7 +186,7 @@ impl<const N: u8, G: Group> Timer<N, G> {
186186

187187
// TODO: Should this be done in TimerConnection instead to ensure everything is taken down
188188
// in the correct order?
189-
impl<const N: u8, G: Group> Drop for Timer<N, G> {
189+
impl<const N: u8, G: Group> Drop for TimerDriver<N, G> {
190190
fn drop(&mut self) {
191191
unsafe {
192192
esp!(mcpwm_del_timer(self.handle)).unwrap();

src/mcpwm/timer_connection.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{
44
comparator::OptionalCmpCfg,
55
generator::OptionalGenCfg,
66
operator::{self, NoOperator, OptionalOperator, OPERATOR},
7-
timer::Timer,
7+
timer::TimerDriver,
88
Operator, OperatorConfig,
99
};
1010

@@ -16,14 +16,14 @@ where
1616
O1: OptionalOperator<1, G>,
1717
O2: OptionalOperator<2, G>,
1818
{
19-
timer: Timer<N, G>,
19+
timer: TimerDriver<N, G>,
2020
operator0: O0,
2121
operator1: O1,
2222
operator2: O2,
2323
}
2424

2525
impl<const N: u8, G: Group> TimerConnection<N, G, NoOperator, NoOperator, NoOperator> {
26-
pub(crate) fn new(timer: Timer<N, G>) -> Self {
26+
pub(crate) fn new(timer: TimerDriver<N, G>) -> Self {
2727
Self {
2828
timer,
2929
operator0: NoOperator,
@@ -46,7 +46,7 @@ impl<
4646
O2: OptionalOperator<2, G>,
4747
> TimerConnection<N, G, O0, O1, O2>
4848
{
49-
pub fn split(&mut self) -> (&mut Timer<N, G>, &mut O0, &mut O1, &mut O2) {
49+
pub fn split(&mut self) -> (&mut TimerDriver<N, G>, &mut O0, &mut O1, &mut O2) {
5050
(
5151
&mut self.timer,
5252
&mut self.operator0,
@@ -63,7 +63,7 @@ where
6363
O2: OptionalOperator<2, G>,
6464
{
6565
#[allow(clippy::type_complexity)]
66-
pub fn attatch_operator0<CMPX, CMPY, GENA, GENB>(
66+
pub fn attach_operator0<CMPX, CMPY, GENA, GENB>(
6767
self,
6868
operator_handle: OPERATOR<0, G>,
6969
operator_cfg: OperatorConfig<CMPX, CMPY, GENA, GENB>,
@@ -91,7 +91,7 @@ where
9191
O2: OptionalOperator<2, G>,
9292
{
9393
#[allow(clippy::type_complexity)]
94-
pub fn attatch_operator1<CMPX, CMPY, GENA, GENB>(
94+
pub fn attach_operator1<CMPX, CMPY, GENA, GENB>(
9595
self,
9696
operator_handle: OPERATOR<1, G>,
9797
operator_cfg: OperatorConfig<CMPX, CMPY, GENA, GENB>,
@@ -119,7 +119,7 @@ where
119119
O1: OptionalOperator<1, G>,
120120
{
121121
#[allow(clippy::type_complexity)]
122-
pub fn attatch_operator2<CMPX, CMPY, GENA, GENB>(
122+
pub fn attach_operator2<CMPX, CMPY, GENA, GENB>(
123123
self,
124124
operator_handle: OPERATOR<2, G>,
125125
operator_cfg: OperatorConfig<CMPX, CMPY, GENA, GENB>,
@@ -154,8 +154,3 @@ impl<const N: u8, G, O0, O1, O2> Drop for TimerConnection<N, G, O0, O1, O2>
154154
}
155155
}
156156
*/
157-
158-
// TODO: Should this be moved somewhere else?
159-
pub trait OptionalOutputPin {}
160-
161-
impl<P: crate::gpio::OutputPin> OptionalOutputPin for P {}

src/peripherals.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,17 @@ impl Peripherals {
180180
can: can::CAN::new(),
181181
#[cfg(not(feature = "riscv-ulp-hal"))]
182182
ledc: ledc::LEDC::new(),
183-
#[cfg(all(any(esp32, esp32s3), esp_idf_version_major = "5"))]
183+
#[cfg(all(
184+
any(esp32, esp32s3),
185+
not(feature = "riscv-ulp-hal"),
186+
esp_idf_version_major = "5"
187+
))]
184188
mcpwm0: mcpwm::MCPWM::<mcpwm::Group0>::new(),
185-
#[cfg(all(any(esp32, esp32s3), esp_idf_version_major = "5"))]
189+
#[cfg(all(
190+
any(esp32, esp32s3),
191+
not(feature = "riscv-ulp-hal"),
192+
esp_idf_version_major = "5"
193+
))]
186194
mcpwm1: mcpwm::MCPWM::<mcpwm::Group1>::new(),
187195
#[cfg(not(feature = "riscv-ulp-hal"))]
188196
rmt: rmt::RMT::new(),

0 commit comments

Comments
 (0)