aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.h')
-rw-r--r--quantum/quantum.h69
1 files changed, 57 insertions, 12 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 7cf16d81e..683333211 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -1,4 +1,4 @@
1/* Copyright 2016-2017 Erez Zukerman, Jack Humbert 1/* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar
2 * 2 *
3 * This program is free software: you can redistribute it and/or modify 3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by 4 * it under the terms of the GNU General Public License as published by
@@ -17,9 +17,12 @@
17#define QUANTUM_H 17#define QUANTUM_H
18 18
19#if defined(__AVR__) 19#if defined(__AVR__)
20#include <avr/pgmspace.h> 20 #include <avr/pgmspace.h>
21#include <avr/io.h> 21 #include <avr/io.h>
22#include <avr/interrupt.h> 22 #include <avr/interrupt.h>
23#endif
24#if defined(PROTOCOL_CHIBIOS)
25 #include "hal.h"
23#endif 26#endif
24#include "wait.h" 27#include "wait.h"
25#include "matrix.h" 28#include "matrix.h"
@@ -33,11 +36,11 @@
33#ifdef RGBLIGHT_ENABLE 36#ifdef RGBLIGHT_ENABLE
34 #include "rgblight.h" 37 #include "rgblight.h"
35#else 38#else
36 #ifdef RGB_MATRIX_ENABLE 39 #ifdef RGB_MATRIX_ENABLE
37 /* dummy define RGBLIGHT_MODE_xxxx */ 40 /* dummy define RGBLIGHT_MODE_xxxx */
38 #define RGBLIGHT_H_DUMMY_DEFINE 41 #define RGBLIGHT_H_DUMMY_DEFINE
39 #include "rgblight.h" 42 #include "rgblight.h"
40 #endif 43 #endif
41#endif 44#endif
42 45
43#ifdef SPLIT_KEYBOARD 46#ifdef SPLIT_KEYBOARD
@@ -76,9 +79,9 @@ extern uint32_t default_layer_state;
76#ifdef AUDIO_ENABLE 79#ifdef AUDIO_ENABLE
77 #include "audio.h" 80 #include "audio.h"
78 #include "process_audio.h" 81 #include "process_audio.h"
79 #ifdef AUDIO_CLICKY 82 #ifdef AUDIO_CLICKY
80 #include "process_clicky.h" 83 #include "process_clicky.h"
81 #endif // AUDIO_CLICKY 84 #endif // AUDIO_CLICKY
82#endif 85#endif
83 86
84#ifdef STENO_ENABLE 87#ifdef STENO_ENABLE
@@ -133,6 +136,48 @@ extern uint32_t default_layer_state;
133 #include "hd44780.h" 136 #include "hd44780.h"
134#endif 137#endif
135 138
139//Function substitutions to ease GPIO manipulation
140#ifdef __AVR__
141 #define pin_t uint8_t
142 #define setPinInput(pin) _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF)
143 #define setPinInputHigh(pin) ({\
144 _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF);\
145 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);\
146 })
147 #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low")
148 #define setPinOutput(pin) _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF)
149
150 #define writePinHigh(pin) _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF)
151 #define writePinLow(pin) _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF)
152 static inline void writePin(pin_t pin, uint8_t level){
153 if (level){
154 _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);
155 } else {
156 _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF);
157 }
158 }
159
160 #define readPin(pin) (_SFR_IO8(pin >> 4) & _BV(pin & 0xF))
161#elif defined(PROTOCOL_CHIBIOS)
162 #define pin_t ioline_t
163 #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
164 #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
165 #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
166 #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL)
167
168 #define writePinHigh(pin) palSetLine(pin)
169 #define writePinLow(pin) palClearLine(pin)
170 static inline void writePin(pin_t pin, uint8_t level){
171 if (level){
172 palSetLine(pin);
173 } else {
174 palClearLine(pin);
175 }
176 }
177
178 #define readPin(pin) palReadLine(pin)
179#endif
180
136#define STRINGIZE(z) #z 181#define STRINGIZE(z) #z
137#define ADD_SLASH_X(y) STRINGIZE(\x ## y) 182#define ADD_SLASH_X(y) STRINGIZE(\x ## y)
138#define SYMBOL_STR(x) ADD_SLASH_X(x) 183#define SYMBOL_STR(x) ADD_SLASH_X(x)