#include <stm32f4xx.h>

#ifndef TIMER_H
#define TIMER_H

typedef struct {
  TIM_TypeDef* periph;
  uint8_t idx;
} timer_t;

void timer_init(timer_t* timer, TIM_TypeDef* peripheral, uint8_t timer_idx);
void timer_enable(timer_t* timer);
void timer_disable(timer_t* timer);
uint32_t timer_is_enabled(timer_t *timer);

void timer_set_refresh(timer_t* timer, uint32_t refresh_value);
void timer_set_counter(timer_t* timer, uint32_t counter);

// TODO: rest of parameters...?
void timer_configure(timer_t* timer, uint8_t buffered_reload, uint16_t prescaler, uint8_t one_pulse_mode);

uint16_t timer_count(timer_t* timer);

void timer_enable_interrupt(timer_t* timer);
void timer_disable_interrupt(timer_t* timer);
uint32_t timer_is_interrupt(timer_t* timer);
void timer_clear_interrupt(timer_t* timer);

#endif // TIMER_H
