@@ -309,6 +309,14 @@ public:
309
309
%% endif
310
310
};
311
311
312
+ enum class ExternalTriggerPolarity
313
+ {
314
+ NoTriggerDetection = 0x0u,
315
+ RisingEdge = 0x1u,
316
+ FallingEdge = 0x2u,
317
+ RisingAndFallingEdge = 0x3u,
318
+ };
319
+
312
320
enum class Interrupt : uint32_t
313
321
{
314
322
Ready = ADC_IER_ADRDYIE,
@@ -342,6 +350,57 @@ public:
342
350
};
343
351
MODM_FLAGS32(InterruptFlag);
344
352
353
+ /**
354
+ * Enum mapping all events on a external trigger converter.
355
+ * The source mapped to each event varies on controller family,
356
+ * refer to the ADC external trigger section on reference manual
357
+ * of your controller for more information
358
+ */
359
+ enum class RegularConversionExternalTrigger
360
+ {
361
+ Event0 = 0x00u,
362
+ Event1 = 0x01u,
363
+ Event2 = 0x02u,
364
+ Event3 = 0x03u,
365
+ Event4 = 0x04u,
366
+ Event5 = 0x05u,
367
+ Event6 = 0x06u,
368
+ Event7 = 0x07u,
369
+ Event9 = 0x09u,
370
+ Event10 = 0x0Au,
371
+ Event11 = 0x0Bu,
372
+ Event12 = 0x0Cu,
373
+ Event13 = 0x0Du,
374
+ Event14 = 0x0Eu,
375
+ Event15 = 0x0Fu,
376
+ %% if target["family"] in ["g4"]
377
+ Event16 = 0x10u,
378
+ Event17 = 0x11u,
379
+ Event18 = 0x12u,
380
+ Event19 = 0x13u,
381
+ Event20 = 0x14u,
382
+ Event21 = 0x15u,
383
+ Event22 = 0x16u,
384
+ Event23 = 0x17u,
385
+ Event24 = 0x18u,
386
+ Event25 = 0x19u,
387
+ Event26 = 0x1Au,
388
+ Event27 = 0x1Bu,
389
+ Event28 = 0x1Cu,
390
+ Event29 = 0x1Du,
391
+ Event30 = 0x1Eu,
392
+ Event31 = 0x1Fu,
393
+ %% endif
394
+ };
395
+
396
+ enum class OffsetSlot : uint8_t
397
+ {
398
+ Slot0 = 0,
399
+ Slot1 = 1,
400
+ Slot2 = 2,
401
+ Slot3 = 3,
402
+ };
403
+
345
404
public:
346
405
template< class... Signals >
347
406
static void
@@ -499,6 +558,23 @@ public:
499
558
static inline void
500
559
stopConversion();
501
560
561
+ /**
562
+ * enable regular conversions on external trigger.
563
+ *
564
+ * @param externalTriggerPolarity
565
+ * Polarity of the external trigger signal.
566
+ * @param regularConversionExternalTrigger
567
+ * Regular conversion external trigger source.
568
+ */
569
+ static inline void enableRegularConversionExternalTrigger(
570
+ ExternalTriggerPolarity externalTriggerPolarity,
571
+ RegularConversionExternalTrigger regularConversionExternalTrigger);
572
+
573
+ /**
574
+ * Disable regular conversions external trigger.
575
+ */
576
+ static inline void disableRegularConversionExternalTrigger( void );
577
+
502
578
/**
503
579
* @return If the conversion is finished.
504
580
* @pre A conversion should have been started with startConversion()
@@ -539,6 +615,23 @@ public:
539
615
static inline bool
540
616
setInjectedConversionSequenceLength(uint8_t length);
541
617
618
+ /**
619
+ * enable injected conversions on external trigger.
620
+ *
621
+ * @param externalTriggerPolarity
622
+ * Polarity of the external trigger signal.
623
+ * @param regularConversionExternalTrigger
624
+ * Regular conversion external trigger source.
625
+ */
626
+ static inline void enableInjectedConversionExternalTrigger(
627
+ ExternalTriggerPolarity externalTriggerPolarity,
628
+ RegularConversionExternalTrigger regularConversionExternalTrigger);
629
+
630
+ /**
631
+ * Disable injected conversions external trigger.
632
+ */
633
+ static inline void disableInjectedConversionExternalTrigger();
634
+
542
635
/**
543
636
* @return If the injected conversion sequence is finished.
544
637
* @pre An injected conversion should have been started with startInjectedConversionSequence()
@@ -585,6 +678,76 @@ public:
585
678
}
586
679
}
587
680
681
+ %% if target["family"] in ["f3", "l4", "l5"] or (target["family"] in ["h7"] and target["name"][0] in ["4", "5", "a", "b"]):
682
+ /**
683
+ * @arg slot for the offset register (0..3)
684
+ * @arg channel channel to which the offset is applied
685
+ * @arg offset offset value to be applied to the channel
686
+ * @return true if the offset was successfully enabled, false if the slot is invalid
687
+ * @note The offset can only be applied when the adc is stopped!
688
+ */
689
+ static inline bool
690
+ enableChannelOffset(const OffsetSlot slot, const Channel channel, const uint16_t offset);
691
+
692
+ /**
693
+ * @arg slot for the offset register (0..3)
694
+ * @arg offset value applied to the channel
695
+ * @return true if the offset was successfully enabled, false if the slot is invalid
696
+ * @note The channel is determined by the GPIO pin type.
697
+ * @note The offset can only be applied when the adc is stopped!
698
+ */
699
+ template<class Gpio>
700
+ static inline bool enableChannelOffset(const OffsetSlot slot, const uint16_t offset)
701
+ {
702
+ return enableChannelOffset(slot, getPinChannel<Gpio>(), offset);
703
+ }
704
+
705
+ %% else
706
+ /**
707
+ * @arg slot for the offset register (0..3)
708
+ * @arg channel channel to which the offset is applied
709
+ * @arg offset offset value to be applied to the channel
710
+ * @arg saturate if true, the adc result value is saturated to the range of the ADC
711
+ * @return true if the offset was successfully enabled, false if the slot is invalid
712
+ * @note The offset can only be applied when the adc is stopped!
713
+ */
714
+ static inline bool
715
+ enableChannelOffset(const OffsetSlot slot, const Channel channel, const int16_t offset, const bool saturate = false);
716
+
717
+ /**
718
+ * @arg slot for the offset register (0..3)
719
+ * @arg offset value applied to the channel
720
+ * @arg saturate if true, the adc result value is saturated to the range of the ADC
721
+ * @return true if the offset was successfully enabled, false if the slot is invalid
722
+ * @note The channel is determined by the GPIO pin type.
723
+ * @note The offset can only be applied when the adc is stopped!
724
+ */
725
+ template<class Gpio>
726
+ static inline bool enableChannelOffset(const OffsetSlot slot, const int16_t offset, const bool saturate = false)
727
+ {
728
+ return enableChannelOffset(slot, getPinChannel<Gpio>(), offset, saturate);
729
+ }
730
+ %% endif
731
+
732
+ /**
733
+ * @arg slot for the offset register (0..3)
734
+ * @return true if the offset was successfully disabled, false if the slot is invalid
735
+ * @note The offset can only be disabled when the adc is stopped!
736
+ */
737
+ static inline bool disableChannelOffset(OffsetSlot slot);
738
+
739
+ /**
740
+ * @arg slot for the offset register (0..3)
741
+ * @return true if the offset was successfully disabled, false if the slot is invalid
742
+ * @note The channel is determined by the GPIO pin type.
743
+ * @note The offset can only be disabled when the adc is stopped!
744
+ */
745
+ template<class Gpio>
746
+ static inline bool disableChannelOffset(OffsetSlot slot)
747
+ {
748
+ return disableChannelOffset(slot);
749
+ }
750
+
588
751
static inline void
589
752
enableInterruptVector(const uint32_t priority, const bool enable = true);
590
753
0 commit comments