1- use  std :: borrow :: Borrow ; 
1+ use  esp_idf_sys :: { EspError ,  mcpwm_oper_handle_t } ; 
22
3- use  esp_idf_sys:: { mcpwm_io_signals_t,  mcpwm_unit_t,  mcpwm_operator_t, 
4-     mcpwm_io_signals_t_MCPWM0A,  mcpwm_io_signals_t_MCPWM0B, 
5-     mcpwm_io_signals_t_MCPWM1A,  mcpwm_io_signals_t_MCPWM1B, 
6-     mcpwm_io_signals_t_MCPWM2A,  mcpwm_io_signals_t_MCPWM2B,  EspError 
7- } ; 
8- 
9- use  crate :: { mcpwm:: { Unit ,  UnitZero ,  UnitOne } ,  gpio:: OutputPin } ; 
3+ use  crate :: { mcpwm:: { Group ,  Group0 ,  Group1 } ,  gpio:: OutputPin } ; 
104
115use  super :: { Duty ,  timer_connection:: OptionalOutputPin } ; 
126
7+ use  core:: ffi; 
8+ 
139// The hardware for ESP32 and ESP32-S3 can associate any operator(within the mcpwm module) with any 
1410// timer(within the mcpwm module) for example allowing using the same timer for all three operators. 
15- pub  trait  HwOperator < U :  Unit >  { 
16-     const  SIGNAL_A :  mcpwm_io_signals_t ; 
17-     const  SIGNAL_B :  mcpwm_io_signals_t ; 
18-     const  UNIT_ID :  mcpwm_unit_t  = U :: ID ; 
11+ pub  trait  HwOperator < U :  Group >  { 
12+     const  GROUP_ID :  ffi:: c_int  = U :: ID ; 
1913} 
2014
21- macro_rules!  impl_operator_helper { 
22-     ( $instance: ident:  $timer: expr,  $signal_a: expr,  $signal_b: expr,  $unit: ty)  => { 
23-         impl  HwOperator <$unit> for  $instance<$unit> { 
24-             const  SIGNAL_A :  mcpwm_io_signals_t = $signal_a; 
25-             const  SIGNAL_B :  mcpwm_io_signals_t = $signal_b; 
26-         } 
15+ macro_rules!  impl_operator { 
16+     ( $t: ident,  $g: ty)  => { 
17+         crate :: impl_peripheral!( $t) ; 
18+ 
19+         impl  HwOperator <$g> for  $t { } 
2720    } ; 
2821} 
2922
30- macro_rules!  impl_operator { 
31-     ( $instance: ident:  $timer: expr,  $signal_a: expr,  $signal_b: expr)  => { 
32-         pub  struct  $instance<U :  Unit > { 
33-             _unit:  U , 
34-         } 
23+ pub  trait  HwOperator0 < G :  Group > :  HwOperator < G >  { } 
24+ pub  trait  HwOperator1 < G :  Group > :  HwOperator < G >  { } 
25+ pub  trait  HwOperator2 < G :  Group > :  HwOperator < G >  { } 
3526
36-         impl <U :  Unit > $instance<U > { 
37-             /// # Safety 
38-              /// 
39-              /// It is safe to instantiate this operator exactly one time per Unit. 
40-              pub  unsafe  fn  new( )  -> Self  { 
41-                 $instance { 
42-                     _unit:  U :: default ( ) , 
43-                 } 
44-             } 
45-         } 
27+ // Group 0 
28+ impl_operator ! ( OPERATOR00 ,  Group0 ) ; 
29+ impl_operator ! ( OPERATOR01 ,  Group0 ) ; 
30+ impl_operator ! ( OPERATOR02 ,  Group0 ) ; 
4631
47-         impl_operator_helper!( $instance:  $timer,  $signal_a,  $signal_b,  UnitZero ) ; 
48-         impl_operator_helper!( $instance:  $timer,  $signal_a,  $signal_b,  UnitOne ) ; 
49-     } ; 
50- } 
32+ // Group 1 
33+ impl_operator ! ( OPERATOR10 ,  Group1 ) ; 
34+ impl_operator ! ( OPERATOR11 ,  Group1 ) ; 
35+ impl_operator ! ( OPERATOR12 ,  Group1 ) ; 
36+ 
37+ impl  HwOperator0 < Group0 >  for  OPERATOR00  { } 
38+ impl  HwOperator0 < Group1 >  for  OPERATOR10  { } 
39+ 
40+ impl  HwOperator1 < Group0 >  for  OPERATOR01  { } 
41+ impl  HwOperator1 < Group1 >  for  OPERATOR11  { } 
5142
52- impl_operator ! ( 
53-     OPERATOR0 :  mcpwm_timer_t_MCPWM_TIMER_0, 
54-     mcpwm_io_signals_t_MCPWM0A, 
55-     mcpwm_io_signals_t_MCPWM0B
56- ) ; 
57- impl_operator ! ( 
58-     OPERATOR1 :  mcpwm_timer_t_MCPWM_TIMER_1, 
59-     mcpwm_io_signals_t_MCPWM1A, 
60-     mcpwm_io_signals_t_MCPWM1B
61- ) ; 
62- impl_operator ! ( 
63-     OPERATOR2 :  mcpwm_timer_t_MCPWM_TIMER_2, 
64-     mcpwm_io_signals_t_MCPWM2A, 
65-     mcpwm_io_signals_t_MCPWM2B
66- ) ; 
43+ impl  HwOperator2 < Group0 >  for  OPERATOR02  { } 
44+ impl  HwOperator2 < Group1 >  for  OPERATOR12  { } 
6745
6846// TODO: How do we want syncing to fit in to this? 
6947// TODO: How do we want carrier to fit into this? 
@@ -73,8 +51,8 @@ impl_operator!(
7351/// 
7452/// Every Motor Control module has three operators. Every operator can generate two output signals called A and B. 
7553/// A and B share the same timer and thus frequency and phase but can have induvidual duty set. 
76- pub  struct  Operator < U :  Unit ,  O :  HwOperator < U > ,  PA :  OptionalOutputPin ,  PB :  OptionalOutputPin >  { 
77-     handle :  mcpwm_operator_t , 
54+ pub  struct  Operator < U :  Group ,  O :  HwOperator < U > ,  PA :  OptionalOutputPin ,  PB :  OptionalOutputPin >  { 
55+     handle :  mcpwm_oper_handle_t , 
7856    _instance :  O , 
7957
8058    _pin_a :  PA , 
@@ -85,7 +63,7 @@ pub struct Operator<U: Unit, O: HwOperator<U>, PA: OptionalOutputPin, PB: Option
8563
8664impl < U ,  O ,  PA ,  PB >  Operator < U ,  O ,  PA ,  PB > 
8765where 
88-     U :  Unit , 
66+     U :  Group , 
8967    O :  HwOperator < U > , 
9068    PA :  OutputPin , 
9169    PB :  OptionalOutputPin , 
10381
10482impl < U ,  O ,  PA ,  PB >  Operator < U ,  O ,  PA ,  PB > 
10583where 
106-     U :  Unit , 
84+     U :  Group , 
10785    O :  HwOperator < U > , 
10886    PA :  OptionalOutputPin , 
10987    PB :  OutputPin , 
@@ -187,10 +165,10 @@ pub enum DutyMode {
187165     ActiveLow , 
188166} 
189167
190- pub  trait  OptionalOperator < U :  Unit ,  O :  HwOperator < U > >  { } 
168+ pub  trait  OptionalOperator < U :  Group ,  O :  HwOperator < U > >  { } 
191169
192170pub  struct  NoOperator ; 
193- impl < U :  Unit ,  O :  HwOperator < U > >  OptionalOperator < U ,  O >  for  NoOperator  { } 
171+ impl < U :  Group ,  O :  HwOperator < U > >  OptionalOperator < U ,  O >  for  NoOperator  { } 
194172
195173/* 
196174
0 commit comments