Skip to content

Commit c949daf

Browse files
committed
examples use std::chrono::duration in Timer**::setPeriod(...)
1 parent 5ddcab3 commit c949daf

File tree

5 files changed

+15
-14
lines changed
  • examples

5 files changed

+15
-14
lines changed

examples/blue_pill_f103/encoder_input_bitbang/main.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,19 @@ MODM_ISR(TIM2)
3838
encoder.update();
3939
}
4040

41+
template<class Timer, class Rep, class Period>
4142
void
42-
init_Timer2(const uint16_t period)
43+
initPeriodicInterrupt(std::chrono::duration<Rep, Period> period)
4344
{
44-
Timer2::enable();
45-
Timer2::setMode(Timer2::Mode::UpCounter);
45+
Timer::enable();
46+
Timer::setMode(Timer::Mode::UpCounter);
4647

47-
Timer2::template setPeriod<Board::SystemClock>(period);
48-
Timer2::enableInterruptVector(true, 10);
49-
Timer2::enableInterrupt(Timer2::Interrupt::Update);
48+
Timer::template setPeriod<Board::SystemClock>(period);
49+
Timer::enableInterruptVector(true, 10);
50+
Timer::enableInterrupt(Timer::Interrupt::Update);
5051

51-
Timer2::applyAndReset();
52-
Timer2::start();
52+
Timer::applyAndReset();
53+
Timer::start();
5354
}
5455

5556
int
@@ -61,7 +62,7 @@ main()
6162
Usart2::initialize<Board::SystemClock, 115200_Bd>();
6263

6364
encoder.initialize();
64-
init_Timer2(1000); // 1ms period
65+
initPeriodicInterrupt<Timer2>(1ms);
6566

6667
int value(0);
6768

examples/nucleo_f042k6/vector_table_ram/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ main()
3838

3939
Timer14::enable();
4040
Timer14::setMode(Timer14::Mode::UpCounter);
41-
Timer14::setPeriod<Board::SystemClock>(500'000 /* us */);
41+
Timer14::setPeriod<Board::SystemClock>(500ms);
4242
Timer14::applyAndReset();
4343
Timer14::start();
4444
Timer14::enableInterrupt(Timer14::Interrupt::Update);

examples/nucleo_l031k6/vector_table_ram/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ main()
3737

3838
Timer2::enable();
3939
Timer2::setMode(Timer2::Mode::UpCounter);
40-
Timer2::setPeriod<Board::SystemClock>(500'000 /* us */);
40+
Timer2::setPeriod<Board::SystemClock>(500ms);
4141
Timer2::applyAndReset();
4242
Timer2::start();
4343
Timer2::enableInterrupt(Timer2::Interrupt::Update);

examples/stm32f3_discovery/timer/basic/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ main()
2424
//Timer1::setMode(Timer1::Mode::CenterAligned3);
2525
Timer1::setMode(Timer1::Mode::UpCounter);
2626
Timer1::setOverflow(0xff);
27-
//Timer1::setPeriod(4);
27+
//Timer1::setPeriod(4us);
2828
Timer1::applyAndReset();
2929
Timer1::start();
3030

examples/stm32f4_discovery/timer_test/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ testTimerAdvancedStart()
3939
TIMER::enable();
4040
TIMER::setMode(TIMER::Mode::UpCounter);
4141

42-
TIMER::template setPeriod<Board::SystemClock>(250000);
42+
TIMER::template setPeriod<Board::SystemClock>(250ms);
4343
TIMER::enableInterruptVector(TIMER::Interrupt::Update, true, 10);
4444
TIMER::enableInterrupt(TIMER::Interrupt::Update);
4545

@@ -54,7 +54,7 @@ testTimerStart()
5454
TIMER::enable();
5555
TIMER::setMode(TIMER::Mode::UpCounter);
5656

57-
TIMER::template setPeriod<Board::SystemClock>(250000);
57+
TIMER::template setPeriod<Board::SystemClock>(250ms);
5858
TIMER::enableInterruptVector(true, 10);
5959
TIMER::enableInterrupt(TIMER::Interrupt::Update);
6060

0 commit comments

Comments
 (0)