11use esp_idf_sys:: {
2- esp, mcpwm_comparator_config_t, mcpwm_comparator_config_t__bindgen_ty_1,
3- mcpwm_comparator_set_compare_value, mcpwm_gen_timer_event_action_t, mcpwm_generator_config_t,
4- mcpwm_generator_config_t__bindgen_ty_1, mcpwm_generator_set_actions_on_compare_event,
5- mcpwm_generator_set_actions_on_timer_event, mcpwm_new_comparator, mcpwm_new_generator,
6- mcpwm_oper_handle_t, mcpwm_operator_config_t, mcpwm_operator_config_t__bindgen_ty_1,
7- mcpwm_operator_connect_timer, mcpwm_timer_direction_t_MCPWM_TIMER_DIRECTION_DOWN,
8- mcpwm_timer_direction_t_MCPWM_TIMER_DIRECTION_UP, mcpwm_timer_event_t_MCPWM_TIMER_EVENT_EMPTY,
9- mcpwm_timer_event_t_MCPWM_TIMER_EVENT_FULL, mcpwm_timer_handle_t, EspError ,
2+ esp, mcpwm_comparator_set_compare_value, mcpwm_oper_handle_t, mcpwm_operator_config_t,
3+ mcpwm_operator_config_t__bindgen_ty_1, mcpwm_operator_connect_timer, mcpwm_timer_handle_t,
4+ EspError ,
105} ;
116
127use crate :: mcpwm:: Group ;
138
149use super :: {
15- comparator:: { Comparator , ComparatorConfig , NoCmp , OptionalCmp , OptionalCmpCfg } ,
16- generator:: { GenA , GenB , GenInit , NoGen , OptionalGen , OptionalGenCfg } ,
10+ comparator:: { Comparator , OptionalCmp , OptionalCmpCfg } ,
11+ generator:: { OptionalGen , OptionalGenCfg } ,
1712 OperatorConfig ,
1813} ;
1914
@@ -61,45 +56,46 @@ impl<const N: u8, G: Group> crate::peripheral::Peripheral for OPERATOR<N, G> {
6156pub struct Operator <
6257 const N : u8 ,
6358 G : Group ,
64- CMP_X : OptionalCmp ,
65- CMP_Y : OptionalCmp ,
66- GEN_A : OptionalGen ,
67- GEN_B : OptionalGen ,
59+ CMPX : OptionalCmp ,
60+ CMPY : OptionalCmp ,
61+ GENA : OptionalGen ,
62+ GENB : OptionalGen ,
6863> {
6964 _instance : OPERATOR < N , G > ,
7065 _handle : mcpwm_oper_handle_t ,
7166
72- comparator_x : CMP_X , // SOC_MCPWM_COMPARATORS_PER_OPERATOR is 2 for ESP32 and ESP32-S3
73- comparator_y : CMP_Y ,
67+ comparator_x : CMPX , // SOC_MCPWM_COMPARATORS_PER_OPERATOR is 2 for ESP32 and ESP32-S3
68+ comparator_y : CMPY ,
7469
75- _generator_a : GEN_A , // One generator per pin, with a maximum of two generators per Operator
76- _generator_b : GEN_B ,
70+ _generator_a : GENA , // One generator per pin, with a maximum of two generators per Operator
71+ _generator_b : GENB ,
7772 //deadtime: D
7873}
7974
80- pub unsafe fn new < const N : u8 , G , CMP_X , CMP_Y , GEN_A , GEN_B > (
75+ pub unsafe fn new < const N : u8 , G , CMPX , CMPY , GENA , GENB > (
8176 instance : OPERATOR < N , G > ,
8277 timer_handle : mcpwm_timer_handle_t ,
83- cfg : OperatorConfig < CMP_X , CMP_Y , GEN_A , GEN_B > ,
84- ) -> Operator < N , G , CMP_X :: Cmp , CMP_Y :: Cmp , GEN_A :: Gen , GEN_B :: Gen >
78+ cfg : OperatorConfig < CMPX , CMPY , GENA , GENB > ,
79+ ) -> Operator < N , G , CMPX :: Cmp , CMPY :: Cmp , GENA :: Gen , GENB :: Gen >
8580where
8681 G : Group ,
87- CMP_X : OptionalCmpCfg ,
88- CMP_Y : OptionalCmpCfg ,
82+ CMPX : OptionalCmpCfg ,
83+ CMPY : OptionalCmpCfg ,
8984
90- GEN_A : OptionalGenCfg ,
91- GEN_B : OptionalGenCfg ,
85+ GENA : OptionalGenCfg ,
86+ GENB : OptionalGenCfg ,
9287{
9388 let mut handle = ptr:: null_mut ( ) ;
9489 let mut flags: mcpwm_operator_config_t__bindgen_ty_1 = Default :: default ( ) ;
9590
96- flags. set_update_gen_action_on_tez ( todo ! ( ) ) ;
97- flags. set_update_gen_action_on_tep ( todo ! ( ) ) ;
98- flags. set_update_gen_action_on_sync ( todo ! ( ) ) ;
91+ // TODO: What should these be set to?
92+ flags. set_update_gen_action_on_tez ( 1 ) ;
93+ flags. set_update_gen_action_on_tep ( 1 ) ;
94+ flags. set_update_gen_action_on_sync ( 1 ) ;
9995
100- flags. set_update_dead_time_on_tez ( todo ! ( ) ) ;
101- flags. set_update_dead_time_on_tep ( todo ! ( ) ) ;
102- flags. set_update_dead_time_on_sync ( todo ! ( ) ) ;
96+ flags. set_update_dead_time_on_tez ( 1 ) ;
97+ flags. set_update_dead_time_on_tep ( 1 ) ;
98+ flags. set_update_dead_time_on_sync ( 1 ) ;
10399
104100 let config = mcpwm_operator_config_t {
105101 group_id : G :: ID ,
@@ -110,8 +106,8 @@ where
110106 esp ! ( esp_idf_sys:: mcpwm_new_operator( & config, & mut handle, ) ) . unwrap ( ) ;
111107 }
112108
113- let comparator_x = unsafe { cfg. comparator_x . init ( handle) } ;
114- let comparator_y = unsafe { cfg. comparator_y . init ( handle) } ;
109+ let mut comparator_x = unsafe { cfg. comparator_x . init ( handle) } ;
110+ let mut comparator_y = unsafe { cfg. comparator_y . init ( handle) } ;
115111
116112 let generator_a = unsafe {
117113 cfg. generator_a . init (
@@ -144,38 +140,12 @@ where
144140 }
145141}
146142
147- impl < const N : u8 , CMP_Y : OptionalCmp , G : Group > Operator < N , G , NoCmp , CMP_Y , NoGen , NoGen > {
148- fn cmp_x ( self , config : ComparatorConfig ) -> Operator < N , G , Comparator , CMP_Y , NoGen , NoGen > {
149- let mut flags: mcpwm_comparator_config_t__bindgen_ty_1 = Default :: default ( ) ;
150- flags. set_update_cmp_on_tep ( todo ! ( ) ) ;
151- flags. set_update_cmp_on_tez ( todo ! ( ) ) ;
152- flags. set_update_cmp_on_sync ( todo ! ( ) ) ;
153-
154- let cfg = mcpwm_comparator_config_t { flags } ;
155- let mut cmp = ptr:: null_mut ( ) ;
156- unsafe {
157- esp ! ( mcpwm_new_comparator( self . _handle, & cfg, & mut cmp) ) . unwrap ( ) ;
158- }
159- let comparator_x = Comparator ( cmp) ;
160-
161- Operator {
162- _instance : self . _instance ,
163- _handle : self . _handle ,
164- comparator_x,
165- comparator_y : self . comparator_y ,
166-
167- _generator_a : self . _generator_a ,
168- _generator_b : self . _generator_b ,
169- }
170- }
171- }
172-
173- impl < const N : u8 , G , GEN_A , GEN_B , CMP_Y > Operator < N , G , Comparator , CMP_Y , GEN_A , GEN_B >
143+ impl < const N : u8 , G , GENA , GENB , CMPY > Operator < N , G , Comparator , CMPY , GENA , GENB >
174144where
175145 G : Group ,
176- CMP_Y : OptionalCmp ,
177- GEN_A : OptionalGen ,
178- GEN_B : OptionalGen ,
146+ CMPY : OptionalCmp ,
147+ GENA : OptionalGen ,
148+ GENB : OptionalGen ,
179149{
180150 // TODO: Note that this is the comparator we are affecting, not the generator. Generator A may not necessarily have
181151 // anything to do with comparator A. How do we best convay that? Should we call them Generator X/Y and Comparator A/B?
@@ -213,12 +183,12 @@ where
213183 }
214184}
215185
216- impl < const N : u8 , G , GEN_A , GEN_B , CMP_X > Operator < N , G , CMP_X , Comparator , GEN_A , GEN_B >
186+ impl < const N : u8 , G , GENA , GENB , CMPX > Operator < N , G , CMPX , Comparator , GENA , GENB >
217187where
218188 G : Group ,
219- CMP_X : OptionalCmp ,
220- GEN_A : OptionalGen ,
221- GEN_B : OptionalGen ,
189+ CMPX : OptionalCmp ,
190+ GENA : OptionalGen ,
191+ GENB : OptionalGen ,
222192{
223193 /// Get compare value, often times same as the duty for output B.
224194 ///
@@ -247,14 +217,14 @@ where
247217}
248218
249219pub trait OptionalOperator < const N : u8 , G : Group > { }
250- impl < const N : u8 , G , CMP_X , CMP_Y , GEN_A , GEN_B > OptionalOperator < N , G >
251- for Operator < N , G , CMP_X , CMP_Y , GEN_A , GEN_B >
220+ impl < const N : u8 , G , CMPX , CMPY , GENA , GENB > OptionalOperator < N , G >
221+ for Operator < N , G , CMPX , CMPY , GENA , GENB >
252222where
253223 G : Group ,
254- CMP_X : OptionalCmp ,
255- CMP_Y : OptionalCmp ,
256- GEN_A : OptionalGen ,
257- GEN_B : OptionalGen ,
224+ CMPX : OptionalCmp ,
225+ CMPY : OptionalCmp ,
226+ GENA : OptionalGen ,
227+ GENB : OptionalGen ,
258228{
259229}
260230
0 commit comments