-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalPin.cpp
51 lines (43 loc) · 1.04 KB
/
DigitalPin.cpp
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
/*
* Created by Steyn Huurman on 02-06-2017
*
* You can ask me questions: zebro@steynhuurman.nl
*/
#include "DigitalPin.h"
ZebroXMega::DigitalPin::DigitalPin(PORT_t *port, uint8_t pin_bm) :
port(port),
pin_bm(pin_bm)
{
}
void ZebroXMega::DigitalPin::setMode(ZebroAvr::PinMode mode)
{
setMode(port, pin_bm, mode);
}
ZebroAvr::PinValue ZebroXMega::DigitalPin::read()
{
return (port->IN & pin_bm) ? ZebroAvr::HIGH : ZebroAvr::LOW;
}
void ZebroXMega::DigitalPin::write(ZebroAvr::PinValue pinValue)
{
write(port, pin_bm, pinValue);
}
void ZebroXMega::DigitalPin::toggle()
{
port->OUTTGL = pin_bm;
}
void ZebroXMega::DigitalPin::write(PORT_t *port, uint8_t pin_bm, ZebroAvr::PinValue pinValue)
{
if (pinValue == ZebroAvr::HIGH) {
port->OUTSET = pin_bm;
} else if (pinValue == ZebroAvr::LOW) {
port->OUTCLR = pin_bm;
}
}
void ZebroXMega::DigitalPin::setMode(PORT_t *port, uint8_t pin_bm, ZebroAvr::PinMode mode)
{
if (mode == ZebroAvr::OUTPUT) {
port->DIRSET = pin_bm;
} else if (mode == ZebroAvr::INPUT) {
port->DIRCLR = pin_bm;
}
}