Skip to content

Commit c5ef0ff

Browse files
committed
add api to set injected conversion trigger edge and source
1 parent 932f6f2 commit c5ef0ff

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/modm/platform/adc/stm32f3/adc.hpp.in

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,14 @@ public:
309309
%% endif
310310
};
311311

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+
312320
enum class Interrupt : uint32_t
313321
{
314322
Ready = ADC_IER_ADRDYIE,
@@ -539,11 +547,24 @@ public:
539547
static inline bool
540548
setInjectedConversionSequenceLength(uint8_t length);
541549

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+
542563
/**
543564
* @return If the injected conversion sequence is finished.
544565
* @pre An injected conversion should have been started with startInjectedConversionSequence()
545566
*/
546-
static inline bool
567+
static inline bool
547568
isInjectedConversionFinished();
548569

549570
/**

src/modm/platform/adc/stm32f3/adc_impl.hpp.in

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,31 @@ modm::platform::Adc{{ id }}::setInjectedConversionSequenceLength(uint8_t length)
351351
return true;
352352
}
353353

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+
354379
bool
355380
modm::platform::Adc{{ id }}::isInjectedConversionFinished()
356381
{

0 commit comments

Comments
 (0)