-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
43 lines (30 loc) · 758 Bytes
/
Utils.cpp
File metadata and controls
43 lines (30 loc) · 758 Bytes
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
#include "Utils.h"
namespace ACRobot {
void setDigitalPin(uint8_t pin)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out = portOutputRegister(port);
register uint8_t oldSREG = SREG;
cli();
*out |= bit;
SREG = oldSREG;
}
void clearDigitalPin(uint8_t pin)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out = portOutputRegister(port);
register uint8_t oldSREG = SREG;
cli();
*out &= ~bit;
SREG = oldSREG;
}
uint8_t getDigitalPin(uint8_t pin)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}
} // ACRobot namespace