diff options
author | Joshua T <joshua@sonofone.net> | 2017-01-07 14:01:21 -0600 |
---|---|---|
committer | Joshua T <joshua@sonofone.net> | 2017-01-07 14:01:21 -0600 |
commit | 8f8d10475956a17953f6db4db3f3b50bd795c0d8 (patch) | |
tree | 90c80474baa080e5743ee745ec98254e1a2faadd /quantum/pincontrol.h | |
parent | b7b44dc481430438552d91b7069d5e37a5e3a649 (diff) | |
parent | e7df488a92da56cf160ac64c8cc7302ab717e145 (diff) |
Merged from upstream
Diffstat (limited to 'quantum/pincontrol.h')
-rw-r--r-- | quantum/pincontrol.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/quantum/pincontrol.h b/quantum/pincontrol.h new file mode 100644 index 0000000000..36ce29ef22 --- /dev/null +++ b/quantum/pincontrol.h @@ -0,0 +1,37 @@ +#pragma once +// Some helpers for controlling gpio pins +#include <avr/io.h> + +enum { + PinDirectionInput = 0, + PinDirectionOutput = 1, + PinLevelHigh = 1, + PinLevelLow = 0, +}; + +// ex: pinMode(B0, PinDirectionOutput); +static inline void pinMode(uint8_t pin, int mode) { + uint8_t bv = _BV(pin & 0xf); + if (mode == PinDirectionOutput) { + _SFR_IO8((pin >> 4) + 1) |= bv; + } else { + _SFR_IO8((pin >> 4) + 1) &= ~bv; + _SFR_IO8((pin >> 4) + 2) &= ~bv; + } +} + +// ex: digitalWrite(B0, PinLevelHigh); +static inline void digitalWrite(uint8_t pin, int mode) { + uint8_t bv = _BV(pin & 0xf); + if (mode == PinLevelHigh) { + _SFR_IO8((pin >> 4) + 2) |= bv; + } else { + _SFR_IO8((pin >> 4) + 2) &= ~bv; + } +} + +// Return true if the pin is HIGH +// digitalRead(B0) +static inline bool digitalRead(uint8_t pin) { + return _SFR_IO8(pin >> 4) & _BV(pin & 0xf); +} |