YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
include
interface
timer_interface.h
1
// ---------------------------------------------
2
// This file is part of
3
// _ _ __ _ _ __ __
4
// ( \/ ) /__\ ( )_( ) /__\ ( )
5
// \ / /(__)\ ) _ ( /(__)\ )(__
6
// (__)(__)(__)(_) (_)(__)(__)(____)
7
//
8
// Yet Another HW Abstraction Library
9
// Copyright (C) Andreas Terstegge
10
// BSD Licensed (see file LICENSE)
11
//
12
// ---------------------------------------------
13
//
14
// This file defines a generic and abstract C++
15
// interface for a timer. A timer can operate
16
// in a ONE_SHOT mode or can be re-triggered
17
// automatically (PERIODIC). The timeout is
18
// specified in microseconds, but not every timer
19
// implementation might support this resolution.
20
// When the timer expires, a callback handler is
21
// called, which has been set with the setCallback()
22
// method before.
23
24
#ifndef _TIMER_INTERFACE_H_
25
#define _TIMER_INTERFACE_H_
26
27
#include <stdint.h>
28
#include <functional>
29
using
std::function;
30
31
namespace
TIMER {
32
enum
timer_mode { ONE_SHOT, PERIODIC };
33
}
34
35
class
timer_interface
{
36
37
public
:
38
// set the timeout period and the mode of the timer
39
virtual
void
setPeriod(uint32_t us, TIMER::timer_mode mode) = 0;
40
virtual
uint32_t getPeriod() = 0;
41
42
// set the callback function
43
virtual
void
setCallback(function<
void
()> f) = 0;
44
45
// starting and stopping the timer
46
virtual
void
start() = 0;
47
virtual
void
stop() = 0;
48
virtual
bool
isRunning() = 0;
49
50
// reset the timer (if it has not yet triggered)
51
// and start again with the full specified period
52
virtual
void
reset() = 0;
53
54
protected
:
55
virtual
~timer_interface
() =
default
;
56
};
57
58
#endif
// _TIMER_INTERFACE_H_
timer_interface
Definition
timer_interface.h:35
Generated by
1.12.0