Nýjir kóðar og uppfærðir gamlir kóðar fyrir arduino yfir í zephyr
This commit is contained in:
+38
-9
@@ -1,14 +1,43 @@
|
||||
#include "timer_usec.h"
|
||||
|
||||
Timer_usec::Timer_usec() = default;
|
||||
Timer_usec::Timer_usec() //= default;
|
||||
: callback(nullptr),
|
||||
callback_context(nullptr)
|
||||
|
||||
void Timer_usec::init(uint16_t period_us) { // for custom duty cycle duration in ms in part 1
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
TCNT1 = 0;
|
||||
{
|
||||
|
||||
OCR1A = period_us * 2 - 1;
|
||||
TCCR1B |= (1<<WGM12);
|
||||
TIMSK1 |= (1<<OCIE1A);
|
||||
TCCR1B |= (1<<CS11);
|
||||
}
|
||||
|
||||
// void Timer_usec::init(uint16_t period_us) { // for custom duty cycle duration in ms in part 1
|
||||
// TCCR1A = 0;
|
||||
// TCCR1B = 0;
|
||||
// TCNT1 = 0;
|
||||
|
||||
// OCR1A = period_us * 2 - 1;
|
||||
// TCCR1B |= (1<<WGM12);
|
||||
// TIMSK1 |= (1<<OCIE1A);
|
||||
// TCCR1B |= (1<<CS11);
|
||||
// }
|
||||
|
||||
void Timer_usec::init(uint16_t period_us)
|
||||
{
|
||||
if (period_us == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
k_timer_init(&timer, expiry_handler, nullptr);
|
||||
k_timer_user_data_set(&timer, this);
|
||||
|
||||
// The timer fires first after period_us, then repeats every period_us.
|
||||
k_timer_start(&timer, K_USEC(period_us), K_USEC(period_us));
|
||||
}
|
||||
|
||||
void Timer_usec::expiry_handler(struct k_timer *expired_timer)
|
||||
{
|
||||
auto *self =
|
||||
static_cast<Timer_usec *>(k_timer_user_data_get(expired_timer));
|
||||
|
||||
if (self != nullptr && self->callback != nullptr) {
|
||||
self->callback(self->callback_context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user