diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-12-02 13:12:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-02 13:12:56 -0500 |
commit | 8f0a8cb7a6c001dd07bdf0c701e40a80b16f5c15 (patch) | |
tree | 62d92b69f3939d1aefeafb5d6762eab43e4560be /quantum | |
parent | ead68248c553db5efcb0e2069f94849b8de190d8 (diff) | |
parent | 8485bb34d2e291db5b6c81f892850da1cdca37ba (diff) | |
download | firmware-8f0a8cb7a6c001dd07bdf0c701e40a80b16f5c15.tar.gz firmware-8f0a8cb7a6c001dd07bdf0c701e40a80b16f5c15.tar.bz2 firmware-8f0a8cb7a6c001dd07bdf0c701e40a80b16f5c15.zip |
Merge pull request #914 from wez/ble_2
Add arduino-alike GPIO pin control helpers
Diffstat (limited to 'quantum')
-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 000000000..36ce29ef2 --- /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); +} |