-
Notifications
You must be signed in to change notification settings - Fork 0
/
avrpin.hpp
96 lines (75 loc) · 2.34 KB
/
avrpin.hpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef TMP_AVRPIN_HPP
#define TMP_AVRPIN_HPP
#include "avrinputoutput.hpp"
// Struct for handling a single pin in a register conveniently.
template<typename AvrIoRegister, unsigned pinNumber_>
struct AvrPin
{
typedef AvrIoRegister Register;
enum { pinNumber = pinNumber_,
bitMask = _BV(pinNumber) };
static void setType(AvrInputOutput::PinType const pinType)
{
AvrIoRegister::setType(pinType, bitMask);
}
// ----------------------------------------------------------------------------------------------------
static void togglePort()
{
AvrIoRegister::togglePort(bitMask);
}
static void setPort()
{
AvrIoRegister::setPort(bitMask);
}
static void clearPort()
{
AvrIoRegister::clearPort(bitMask);
}
static typename AvrInputOutput::PinState readPort()
{
return checkPinState_(AvrIoRegister::readPort());
}
// ----------------------------------------------------------------------------------------------------
static void togglePin()
{
AvrIoRegister::togglePin(bitMask);
}
static void setPin()
{
AvrIoRegister::setPin(bitMask);
}
static void clearPin()
{
AvrIoRegister::clearPin(bitMask);
}
static typename AvrInputOutput::PinState readPin()
{
return checkPinState_(AvrIoRegister::readPin());
}
// ----------------------------------------------------------------------------------------------------
static void toggleDdr()
{
AvrIoRegister::toggleDdr(bitMask);
}
static void setDdr()
{
AvrIoRegister::setDdr(bitMask);
}
static void clearDdr()
{
AvrIoRegister::clearDdr(bitMask);
}
static typename AvrInputOutput::PinState readDdr()
{
return checkPinState_(AvrIoRegister::readDdr());
}
// ----------------------------------------------------------------------------------------------------
protected:
// this checks, whether the pin is set in the registerValue or not -
// if it is, this method returns HIGH, otherwise LOW.
static typename AvrInputOutput::PinState checkPinState_(typename AvrIoRegister::RegisterType const registerValue)
{
return ((registerValue & bitMask) != 0) ? AvrInputOutput::High : AvrInputOutput::Low;
}
};
#endif // TMP_AVRPIN_HPP