aboutsummaryrefslogtreecommitdiff
path: root/quantum/pincontrol.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/pincontrol.h')
-rw-r--r--quantum/pincontrol.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/quantum/pincontrol.h b/quantum/pincontrol.h
new file mode 100644
index 000000000..36ce29ef2
--- /dev/null
+++ b/quantum/pincontrol.h
@@ -0,0 +1,37 @@
1#pragma once
2// Some helpers for controlling gpio pins
3#include <avr/io.h>
4
5enum {
6 PinDirectionInput = 0,
7 PinDirectionOutput = 1,
8 PinLevelHigh = 1,
9 PinLevelLow = 0,
10};
11
12// ex: pinMode(B0, PinDirectionOutput);
13static inline void pinMode(uint8_t pin, int mode) {
14 uint8_t bv = _BV(pin & 0xf);
15 if (mode == PinDirectionOutput) {
16 _SFR_IO8((pin >> 4) + 1) |= bv;
17 } else {
18 _SFR_IO8((pin >> 4) + 1) &= ~bv;
19 _SFR_IO8((pin >> 4) + 2) &= ~bv;
20 }
21}
22
23// ex: digitalWrite(B0, PinLevelHigh);
24static inline void digitalWrite(uint8_t pin, int mode) {
25 uint8_t bv = _BV(pin & 0xf);
26 if (mode == PinLevelHigh) {
27 _SFR_IO8((pin >> 4) + 2) |= bv;
28 } else {
29 _SFR_IO8((pin >> 4) + 2) &= ~bv;
30 }
31}
32
33// Return true if the pin is HIGH
34// digitalRead(B0)
35static inline bool digitalRead(uint8_t pin) {
36 return _SFR_IO8(pin >> 4) & _BV(pin & 0xf);
37}