forked from ivanseidel/DueTimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DueTimer.h
79 lines (59 loc) · 1.66 KB
/
DueTimer.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
DueTimer.h - DueTimer header file, definition of methods and attributes...
For instructions, go to https://github.com/ivanseidel/DueTimer
Created by Ivan Seidel Gomes, March, 2013.
Modified by Philipp Klaus, June 2013.
Released into the public domain.
*/
#ifdef __arm__
#ifndef DueTimer_h
#define DueTimer_h
#include "Arduino.h"
#include <inttypes.h>
class DueTimer
{
protected:
// Represents the timer id (index for the array of Timer structs)
int timer;
// Stores the object timer frequency
// (allows to access current timer period and frequency):
static double _frequency[9];
// Picks the best clock to lower the error
static uint8_t bestClock(double frequency, uint32_t& retRC);
public:
struct Timer
{
Tc *tc;
uint32_t channel;
IRQn_Type irq;
};
static DueTimer getAvailable();
// Store timer configuration (static, as it's fix for every object)
static const Timer Timers[9];
// Needs to be public, because the handlers are outside class:
static void (*callbacks[9])();
DueTimer(int _timer);
DueTimer attachInterrupt(void (*isr)());
DueTimer detachInterrupt();
DueTimer start(long microseconds = -1);
DueTimer stop();
DueTimer setFrequency(double frequency);
DueTimer setPeriod(long microseconds);
double getFrequency();
long getPeriod();
};
// Just to call Timer.getAvailable instead of Timer::getAvailable() :
extern DueTimer Timer;
extern DueTimer Timer0;
extern DueTimer Timer1;
extern DueTimer Timer2;
extern DueTimer Timer3;
extern DueTimer Timer4;
extern DueTimer Timer5;
extern DueTimer Timer6;
extern DueTimer Timer7;
extern DueTimer Timer8;
#endif
#else
#error Oops! Trying to include DueTimer on another device?
#endif