Skip to content

Commit 55ed9e9

Browse files
committed
FspTimer: add end() and set_frequency() APIs
1 parent 6aa4dea commit 55ed9e9

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cores/arduino/FspTimer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ FspTimer::FspTimer(): init_ok(false), agt_timer(nullptr), gpt_timer(nullptr), ty
1717
}
1818

1919
FspTimer::~FspTimer() {
20+
end();
21+
}
22+
23+
void FspTimer::end() {
24+
close();
2025
if(agt_timer != nullptr) {
2126
agt_used_channel[timer_cfg.channel] = TIMER_FREE;
2227
delete agt_timer;
@@ -430,6 +435,9 @@ bool FspTimer::set_period_us(double us) {
430435
return set_period_ms(us/1000.0);
431436
}
432437

438+
bool FspTimer::set_frequency(float hz) {
439+
return set_period_ms(1000/hz);
440+
}
433441

434442
/* -------------------------------------------------------------------------- */
435443
bool FspTimer::set_period(uint32_t p) {

cores/arduino/FspTimer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class FspTimer {
132132
bool begin(timer_mode_t mode, uint8_t type, uint8_t channel, float freq_hz, float duty_perc, GPTimerCbk_f cbk = nullptr , void *ctx = nullptr );
133133
bool begin(timer_mode_t mode, uint8_t type, uint8_t channel, uint32_t period, uint32_t pulse, timer_source_div_t sd, GPTimerCbk_f cbk = nullptr , void *ctx = nullptr);
134134

135+
void end();
136+
135137
void set_irq_callback(GPTimerCbk_f cbk , void *ctx = nullptr );
136138

137139
bool setup_overflow_irq(uint8_t priority = 12, Irq_f isr_fnc = nullptr );
@@ -149,6 +151,7 @@ class FspTimer {
149151

150152
uint32_t get_period_raw();
151153
void add_pwm_extended_cfg();
154+
bool set_frequency(float hz);
152155
bool set_period_ms(double ms);
153156
bool set_period_us(double us);
154157
bool set_pulse_ms(double ms,TimerPWMChannel_t pwm_ch);

0 commit comments

Comments
 (0)