2020
2121#include < span>
2222#include < array>
23- #include < initializer_list>
2423
2524#include " ErrorHandler/ErrorHandler.hpp"
2625
@@ -296,11 +295,11 @@ struct TimerDomain {
296295
297296 static constexpr std::array<char , 8 > EMPTY_TIMER_NAME = {0 ,0 ,0 ,0 , 0 ,0 ,0 ,0 };
298297
299- template <typename ... T>
300298 struct Timer {
301299 using domain = TimerDomain;
302300 Entry e;
303301
302+ template <typename ... T>
304303 consteval Timer (TimerRequest request = TimerRequest::AnyGeneralPurpose,
305304 TimerDomain::CountingMode counting_mode = CountingMode::UP,
306305 std::array<char , 8 > name = EMPTY_TIMER_NAME, uint32_t deadtime = 0 ,
@@ -317,15 +316,21 @@ struct TimerDomain {
317316 e.polarity = polarity;
318317 e.negated_polarity = negated_polarity;
319318
320- e.pin_count = sizeof ...(pinargs);
321- if (e.pin_count > 4 ) {
319+ if (sizeof ...(pinargs) > 4 ) {
322320 ST_LIB::compile_error (" Max 4 pins per timer" );
323321 }
322+
324323 int i = 0 ;
325- ((e.pins [i++] = pinargs), ...);
324+ ((this ->e .pins [i++] = pinargs), ...);
325+ for (; i < 4 ; i++) {
326+ this ->e .pins [i] = {
327+ .af = ST_LIB::TimerAF::None,
328+ };
329+ }
326330 }
327331
328- // anything not initialized will be 0
332+ // anything uninitialized will be 0
333+ template <typename ... T>
329334 consteval Timer (Entry e, T... pinargs) {
330335 static_assert ((std::is_same_v<T, TimerPin> && ...),
331336 " All template arguments must be of type TimerPin" );
@@ -336,16 +341,22 @@ struct TimerDomain {
336341 this ->e .deadtime = e.deadtime ;
337342 this ->e .polarity = e.polarity ;
338343 this ->e .negated_polarity = e.negated_polarity ;
339- e.pin_count = sizeof ...(pinargs);
340- if (e. pin_count == 0 ) {
344+ this -> e .pin_count = sizeof ...(pinargs);
345+ if (sizeof ...(pinargs) == 0 ) {
341346 this ->e .pin_count = e.pin_count ;
342347 this ->e .pins = e.pins ;
343348 } else {
344- if (e. pin_count > 4 ) {
349+ if (sizeof ...(pinargs) > 4 ) {
345350 ST_LIB::compile_error (" Max 4 pins per timer" );
346351 }
352+
347353 int i = 0 ;
348- ((e.pins [i++] = pinargs), ...);
354+ ((this ->e .pins [i++] = pinargs), ...);
355+ for (; i < 4 ; i++) {
356+ this ->e .pins [i] = {
357+ .af = ST_LIB::TimerAF::None,
358+ };
359+ }
349360 }
350361 }
351362
0 commit comments