File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
src/modm/platform/adc/stm32f3 Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -309,6 +309,14 @@ public:
309
309
%% endif
310
310
};
311
311
312
+ enum class ExternalTriggerEdge : uint32_t
313
+ {
314
+ Disabled = 0,
315
+ Rising = ADC_JSQR_JEXTEN_0,
316
+ Falling = ADC_JSQR_JEXTEN_1,
317
+ RisingAndFalling = ADC_JSQR_JEXTEN_0 | ADC_JSQR_JEXTEN_1,
318
+ };
319
+
312
320
enum class Interrupt : uint32_t
313
321
{
314
322
Ready = ADC_IER_ADRDYIE,
@@ -539,11 +547,24 @@ public:
539
547
static inline bool
540
548
setInjectedConversionSequenceLength(uint8_t length);
541
549
550
+ /**
551
+ * @arg edge Edge of the trigger signal selected in setInjectedTriggerSource()
552
+ */
553
+ static inline void
554
+ setInjectedConversionTriggerEdge(ExternalTriggerEdge edge);
555
+
556
+ /**
557
+ * @arg source Source of the trigger signal for injected conversion.
558
+ * @return true if configuration is successful, false if arguments are invalid
559
+ */
560
+ static inline bool
561
+ setInjectedConversionTriggerSource(uint32_t source);
562
+
542
563
/**
543
564
* @return If the injected conversion sequence is finished.
544
565
* @pre An injected conversion should have been started with startInjectedConversionSequence()
545
566
*/
546
- static inline bool
567
+ static inline bool
547
568
isInjectedConversionFinished();
548
569
549
570
/**
Original file line number Diff line number Diff line change @@ -351,6 +351,31 @@ modm::platform::Adc{{ id }}::setInjectedConversionSequenceLength(uint8_t length)
351
351
return true;
352
352
}
353
353
354
+ void
355
+ modm::platform::Adc{{ id }}::setInjectedConversionTriggerEdge(ExternalTriggerEdge edge)
356
+ {
357
+ static_assert(std::to_underlying(ExternalTriggerEdge::Disabled) == 0);
358
+ static_assert(std::to_underlying(ExternalTriggerEdge::Rising) == ADC_JSQR_JEXTEN_0);
359
+ static_assert(std::to_underlying(ExternalTriggerEdge::Falling) == ADC_JSQR_JEXTEN_1);
360
+ static_assert(std::to_underlying(ExternalTriggerEdge::RisingAndFalling) == (ADC_JSQR_JEXTEN_0 | ADC_JSQR_JEXTEN_1));
361
+
362
+ ADC{{ id }}->JSQR = (ADC{{ id }}->JSQR & ~ADC_JSQR_JEXTEN_Msk)
363
+ | std::to_underlying(edge);
364
+ }
365
+
366
+ bool
367
+ modm::platform::Adc{{ id }}::setInjectedConversionTriggerSource(uint32_t source)
368
+ {
369
+ if (source > 31) {
370
+ return false; // Invalid source
371
+ }
372
+
373
+ // Set the trigger source for injected conversions
374
+ ADC{{ id }}->JSQR = (ADC{{ id }}->JSQR & ~ADC_JSQR_JEXTSEL_Msk)
375
+ | (source << ADC_JSQR_JEXTSEL_Pos);
376
+ return true;
377
+ }
378
+
354
379
bool
355
380
modm::platform::Adc{{ id }}::isInjectedConversionFinished()
356
381
{
You can’t perform that action at this time.
0 commit comments