@@ -9,7 +9,7 @@ use core::marker::PhantomData;
9
9
10
10
use crate :: dac;
11
11
use crate :: exti:: { Event as ExtiEvent , ExtiExt } ;
12
- use crate :: gpio:: { self , Analog , OpenDrain , Output , PushPull , SignalEdge } ;
12
+ use crate :: gpio:: { self , alt :: CompOutput , Analog , SignalEdge } ;
13
13
14
14
use crate :: rcc:: { Clocks , Rcc } ;
15
15
use crate :: stasis;
@@ -157,28 +157,13 @@ positive_input_pin!(COMP2, PA7, PA3);
157
157
positive_input_pin ! ( COMP3 , PA0 , PC1 ) ;
158
158
positive_input_pin ! ( COMP4 , PB0 , PE7 ) ;
159
159
160
- #[ cfg( any(
161
- feature = "stm32g473" ,
162
- feature = "stm32g483" ,
163
- feature = "stm32g474" ,
164
- feature = "stm32g484"
165
- ) ) ]
160
+ #[ cfg( feature = "comp5" ) ]
166
161
positive_input_pin ! ( COMP5 , PB13 , PD12 ) ;
167
162
168
- #[ cfg( any(
169
- feature = "stm32g473" ,
170
- feature = "stm32g483" ,
171
- feature = "stm32g474" ,
172
- feature = "stm32g484"
173
- ) ) ]
163
+ #[ cfg( feature = "comp6" ) ]
174
164
positive_input_pin ! ( COMP6 , PB11 , PD11 ) ;
175
165
176
- #[ cfg( any(
177
- feature = "stm32g473" ,
178
- feature = "stm32g483" ,
179
- feature = "stm32g474" ,
180
- feature = "stm32g484"
181
- ) ) ]
166
+ #[ cfg( feature = "comp7" ) ]
182
167
positive_input_pin ! ( COMP7 , PB14 , PD14 ) ;
183
168
184
169
macro_rules! negative_input_pin_helper {
@@ -207,12 +192,7 @@ negative_input_pin! {
207
192
COMP4 : gpio:: PE8 <Analog >, gpio:: PB2 <Analog >,
208
193
}
209
194
210
- #[ cfg( any(
211
- feature = "stm32g473" ,
212
- feature = "stm32g483" ,
213
- feature = "stm32g474" ,
214
- feature = "stm32g484"
215
- ) ) ]
195
+ #[ cfg( feature = "comp7" ) ]
216
196
negative_input_pin ! {
217
197
COMP5 : gpio:: PB10 <Analog >, gpio:: PD13 <Analog >,
218
198
COMP6 : gpio:: PD10 <Analog >, gpio:: PB15 <Analog >,
@@ -273,12 +253,7 @@ macro_rules! refint_input {
273
253
274
254
refint_input ! ( COMP1 , COMP2 , COMP3 , COMP4 , ) ;
275
255
276
- #[ cfg( any(
277
- feature = "stm32g473" ,
278
- feature = "stm32g483" ,
279
- feature = "stm32g474" ,
280
- feature = "stm32g484"
281
- ) ) ]
256
+ #[ cfg( feature = "comp7" ) ]
282
257
refint_input ! ( COMP5 , COMP6 , COMP7 , ) ;
283
258
284
259
macro_rules! dac_input_helper {
@@ -312,49 +287,19 @@ dac_input!(COMP3: Dac1Ch1, 0b101);
312
287
dac_input ! ( COMP4 : Dac3Ch2 , 0b100 ) ;
313
288
dac_input ! ( COMP4 : Dac1Ch1 , 0b101 ) ;
314
289
315
- #[ cfg( any(
316
- feature = "stm32g473" ,
317
- feature = "stm32g483" ,
318
- feature = "stm32g474" ,
319
- feature = "stm32g484"
320
- ) ) ]
290
+ #[ cfg( feature = "comp5" ) ]
321
291
dac_input ! ( COMP5 : Dac4Ch1 , 0b100 ) ;
322
- #[ cfg( any(
323
- feature = "stm32g473" ,
324
- feature = "stm32g483" ,
325
- feature = "stm32g474" ,
326
- feature = "stm32g484"
327
- ) ) ]
292
+ #[ cfg( feature = "comp5" ) ]
328
293
dac_input ! ( COMP5 : Dac1Ch2 , 0b101 ) ;
329
294
330
- #[ cfg( any(
331
- feature = "stm32g473" ,
332
- feature = "stm32g483" ,
333
- feature = "stm32g474" ,
334
- feature = "stm32g484"
335
- ) ) ]
295
+ #[ cfg( feature = "comp6" ) ]
336
296
dac_input ! ( COMP6 : Dac4Ch2 , 0b100 ) ;
337
- #[ cfg( any(
338
- feature = "stm32g473" ,
339
- feature = "stm32g483" ,
340
- feature = "stm32g474" ,
341
- feature = "stm32g484"
342
- ) ) ]
297
+ #[ cfg( feature = "comp6" ) ]
343
298
dac_input ! ( COMP6 : Dac2Ch1 , 0b101 ) ;
344
299
345
- #[ cfg( any(
346
- feature = "stm32g473" ,
347
- feature = "stm32g483" ,
348
- feature = "stm32g474" ,
349
- feature = "stm32g484"
350
- ) ) ]
300
+ #[ cfg( feature = "comp7" ) ]
351
301
dac_input ! ( COMP7 : Dac4Ch1 , 0b100 ) ;
352
- #[ cfg( any(
353
- feature = "stm32g473" ,
354
- feature = "stm32g483" ,
355
- feature = "stm32g474" ,
356
- feature = "stm32g484"
357
- ) ) ]
302
+ #[ cfg( feature = "comp7" ) ]
358
303
dac_input ! ( COMP7 : Dac2Ch1 , 0b101 ) ;
359
304
360
305
pub struct Comparator < C , ED > {
@@ -400,14 +345,10 @@ macro_rules! impl_comparator {
400
345
let voltage_scaler_delay = clocks. sys_clk. raw( ) / ( 1_000_000 / 200 ) ; // 200us
401
346
cortex_m:: asm:: delay( voltage_scaler_delay) ;
402
347
self . csr( ) . modify( |_, w| unsafe {
403
- w. hyst( )
404
- . bits( config. hysteresis as u8 )
405
- . scalen( )
406
- . bit( NP :: USE_VREFINT )
407
- . brgen( )
408
- . bit( NP :: USE_RESISTOR_DIVIDER )
409
- . pol( )
410
- . bit( config. inverted)
348
+ w. hyst( ) . bits( config. hysteresis as u8 ) ;
349
+ w. scalen( ) . bit( NP :: USE_VREFINT ) ;
350
+ w. brgen( ) . bit( NP :: USE_RESISTOR_DIVIDER ) ;
351
+ w. pol( ) . bit( config. inverted)
411
352
} ) ;
412
353
413
354
Comparator {
@@ -492,60 +433,37 @@ macro_rules! impl_comparator {
492
433
pub fn unpend( & self , exti: & EXTI ) {
493
434
exti. unpend( $Event) ;
494
435
}
495
-
496
- /// Configures a GPIO pin to output the signal of the comparator
497
- ///
498
- /// Multiple GPIO pins may be configured as the output simultaneously.
499
- pub fn output_pin<P : OutputPin <$COMP>>( & self , pin: P ) {
500
- pin. setup( ) ;
501
- }
502
436
}
503
437
} ;
504
438
}
505
439
440
+ impl < COMP : CompOutput , ED > Comparator < COMP , ED > {
441
+ /// Configures a GPIO pin to output the signal of the comparator
442
+ ///
443
+ /// Multiple GPIO pins may be configured as the output simultaneously.
444
+ pub fn output_pin < Otype > ( & self , pin : impl Into < COMP :: Out < Otype > > ) {
445
+ let _pin = pin. into ( ) ;
446
+ }
447
+ }
448
+
506
449
impl_comparator ! ( COMP1 , comp1, ExtiEvent :: COMP1 ) ;
507
450
impl_comparator ! ( COMP2 , comp2, ExtiEvent :: COMP2 ) ;
508
451
impl_comparator ! ( COMP3 , comp1, ExtiEvent :: COMP3 ) ;
509
452
impl_comparator ! ( COMP4 , comp2, ExtiEvent :: COMP4 ) ;
510
453
511
- #[ cfg( any(
512
- feature = "stm32g473" ,
513
- feature = "stm32g483" ,
514
- feature = "stm32g474" ,
515
- feature = "stm32g484"
516
- ) ) ]
454
+ #[ cfg( feature = "comp5" ) ]
517
455
impl_comparator ! ( COMP5 , comp1, ExtiEvent :: COMP5 ) ;
518
456
519
- #[ cfg( any(
520
- feature = "stm32g473" ,
521
- feature = "stm32g483" ,
522
- feature = "stm32g474" ,
523
- feature = "stm32g484"
524
- ) ) ]
457
+ #[ cfg( feature = "comp6" ) ]
525
458
impl_comparator ! ( COMP6 , comp2, ExtiEvent :: COMP6 ) ;
526
459
527
- #[ cfg( any(
528
- feature = "stm32g473" ,
529
- feature = "stm32g483" ,
530
- feature = "stm32g474" ,
531
- feature = "stm32g484"
532
- ) ) ]
460
+ #[ cfg( feature = "comp7" ) ]
533
461
impl_comparator ! ( COMP7 , comp2, ExtiEvent :: COMP7 ) ;
534
462
535
- #[ cfg( not( any(
536
- feature = "stm32g473" ,
537
- feature = "stm32g483" ,
538
- feature = "stm32g474" ,
539
- feature = "stm32g484"
540
- ) ) ) ]
463
+ #[ cfg( not( feature = "comp7" ) ) ]
541
464
type Comparators = ( COMP1 , COMP2 , COMP3 , COMP4 ) ;
542
465
543
- #[ cfg( any(
544
- feature = "stm32g473" ,
545
- feature = "stm32g483" ,
546
- feature = "stm32g474" ,
547
- feature = "stm32g484"
548
- ) ) ]
466
+ #[ cfg( feature = "comp7" ) ]
549
467
type Comparators = ( COMP1 , COMP2 , COMP3 , COMP4 , COMP5 , COMP6 , COMP7 ) ;
550
468
551
469
/// Enables the comparator peripheral, and splits the [`COMP`] into independent [`COMP1`] and [`COMP2`]
@@ -562,26 +480,11 @@ pub fn split(_comp: COMP, rcc: &mut Rcc) -> Comparators {
562
480
COMP2 { _rb : PhantomData } ,
563
481
COMP3 { _rb : PhantomData } ,
564
482
COMP4 { _rb : PhantomData } ,
565
- #[ cfg ( any (
566
- feature = "stm32g473" ,
567
- feature = "stm32g483" ,
568
- feature = "stm32g474" ,
569
- feature = "stm32g484"
570
- ) ) ]
483
+ #[ cfg ( feature = "comp5" ) ]
571
484
COMP5 { _rb : PhantomData } ,
572
- #[ cfg ( any (
573
- feature = "stm32g473" ,
574
- feature = "stm32g483" ,
575
- feature = "stm32g474" ,
576
- feature = "stm32g484"
577
- ) ) ]
485
+ #[ cfg( feature = "comp6" ) ]
578
486
COMP6 { _rb : PhantomData } ,
579
- #[ cfg ( any (
580
- feature = "stm32g473" ,
581
- feature = "stm32g483" ,
582
- feature = "stm32g474" ,
583
- feature = "stm32g484"
584
- ) ) ]
487
+ #[ cfg( feature = "comp7" ) ]
585
488
COMP7 { _rb : PhantomData } ,
586
489
)
587
490
}
@@ -596,56 +499,3 @@ impl ComparatorSplit for COMP {
596
499
split ( self , rcc)
597
500
}
598
501
}
599
-
600
- pub trait OutputPin < COMP > {
601
- fn setup ( self ) ;
602
- }
603
-
604
- #[ allow( unused_macros) ] // TODO: add support for more devices
605
- macro_rules! output_pin {
606
- ( $COMP: ident, $pin: ident, $AF: literal, $mode_t: ident, $into: ident) => {
607
- impl OutputPin <$COMP> for gpio:: $pin<Output <$mode_t>> {
608
- fn setup( self ) {
609
- self . $into:: <$AF>( ) ;
610
- }
611
- }
612
- } ;
613
- ( $( $COMP: ident: $pin: ident, $AF: literal, ) +) => { $(
614
- output_pin!( $COMP, $pin, $AF, PushPull , into_alternate) ;
615
- output_pin!( $COMP, $pin, $AF, OpenDrain , into_alternate_open_drain) ;
616
- ) +} ;
617
- }
618
-
619
- output_pin ! {
620
- COMP1 : PA0 , 8 ,
621
- COMP1 : PA6 , 8 ,
622
- COMP1 : PA11 , 8 ,
623
- COMP1 : PB8 , 8 ,
624
-
625
- COMP2 : PA2 , 8 ,
626
- COMP2 : PA7 , 8 ,
627
- COMP2 : PA12 , 8 ,
628
- COMP2 : PB9 , 8 ,
629
-
630
- COMP3 : PB7 , 8 ,
631
- COMP3 : PB15 , 3 ,
632
- COMP3 : PC2 , 3 ,
633
-
634
- COMP4 : PB1 , 8 ,
635
- COMP4 : PB6 , 8 ,
636
- COMP4 : PB14 , 8 ,
637
- }
638
-
639
- #[ cfg( feature = "gpio-g47x" ) ]
640
- output_pin ! {
641
- COMP1 : PF4 , 2 ,
642
-
643
- COMP5 : PA9 , 8 ,
644
- COMP5 : PC7 , 7 ,
645
-
646
- COMP6 : PA10 , 8 ,
647
- COMP6 : PC6 , 7 ,
648
-
649
- COMP7 : PA8 , 8 ,
650
- COMP7 : PC8 , 7 ,
651
- }
0 commit comments