-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunLoopHardwareTimer0.hpp
More file actions
83 lines (70 loc) · 2.83 KB
/
Copy pathRunLoopHardwareTimer0.hpp
File metadata and controls
83 lines (70 loc) · 2.83 KB
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
80
81
82
83
/*
* RunLoopHardwareTimer0.hpp
*
* Copyright (c) 2017 by Sebastien MARCHAND (Web:www.marscaper.com, Email:sebastien@marscaper.com)
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RunLoopHardwareTimer0_hpp
#define RunLoopHardwareTimer0_hpp
// Model
#include "RunLoopObject.hpp"
#include "RunLoopHardwareTimer.hpp"
/*!
* The class deals with the hardware Timer0 (8bits) of the arduino.
*
* "Timer0 is an 8-bit that counts from 0 to 255 and generates an interrupt
* it overflows. It uses a clock divisor of 64 by default to give us an
* interrupt rate of 976.5625 Hz (close enough to a 1KHz for our purposes).
* We won't mess with the freqency of Timer0, because that would break millis()!<br>
* <br>
* We'll set up a up a comparison register for Timer 0 (this register is known as
* OCR0A) to generate another interrupt somewhere in the middle of that count. On
* every tick, the timer counter is compared with the comparison register and when
* they are equal an interrupt will be generated.<br>"
* Source:"https://learn.adafruit.com/multi-tasking-the-arduino-part-2/timers"
* <br>
* There is three ways to use this class:
* - Create a sublcass, inherit from RunLoopHardwareTimer0 and overwrite fire().
* - Instantiate a RunLoopHardwareTimer0 object and use a delegate which conforms to RunLoopTimerDelegate protocol.
* - Use attachInterrupt() to set a simple C function as call back.
*
* @ingroup Model
*/
class RunLoopHardwareTimer0 : public RunLoopHardwareTimer
{
public:
#pragma mark -
#pragma mark Create and destroy
RunLoopHardwareTimer0();
~RunLoopHardwareTimer0();
#pragma mark -
#pragma mark Usuals
#if RUN_LOOP_FULL || RUN_LOOP_INHERITANCE
/*! Method executed each time delay is elapsed if delegate is not set. Subclasses need to overwrite this method. */
virtual void fire() {};
#endif
/*! Set delay in milliseconds. */
void setDelay(unsigned long delay);
/*! Set delay in microseconds. */
void setMicroDelay(unsigned long delay);
/*! Start or stop the loop. */
void setIdle(bool state);
/*! Presets DO NOT WORK with Timer0. */
TimerPreset timerPresetForMicroDelay(unsigned long delay);
/*! Presets DO NOT WORK with Timer0. */
void setTimerPreset(TimerPreset *timer) {};
};
#endif