~ruther/uni-mam-arm

ref: 54e9f8d2af25b11710e86886f09b07975bd3e9cc uni-mam-arm/arm07/include/timer.h -rw-r--r-- 1.3 KiB
54e9f8d2 — Rutherther feat(arm07): implement most 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stm32f4xx.h>
#include <stdbool.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);

typedef enum {
  TIMER_MMS_RESET = 0,
  TIMER_MMS_ENABLE = 1,
  TIMER_MMS_UPDATE = 2,
  TIMER_MMS_COMPARE_PULSE1 = 3,
  TIMER_MMS_COMPARE_OC1REF = 4,
  TIMER_MMS_COMPARE_OC2REF = 5,
  TIMER_MMS_COMPARE_OC3REF = 6,
  TIMER_MMS_COMPARE_OC4REF = 7,
} timer_master_mode_t;

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

uint16_t timer_count(timer_t* timer);

void timer_enable_interrupt(timer_t *timer, bool update, bool capture1);
void timer_disable_interrupt(timer_t* timer);
uint32_t timer_is_update_interrupt(timer_t* timer);
uint32_t timer_is_capture1_interrupt(timer_t *timer);
void timer_clear_capture1_interrupt(timer_t* timer);
void timer_clear_update_interrupt(timer_t* timer);

#endif // TIMER_H
Do not follow this link