From 7fe03d085c2ecaa324779093eceb1a12313ca25d Mon Sep 17 00:00:00 2001 From: yiancar Date: Fri, 28 Sep 2018 17:33:11 +0100 Subject: Update quantum matrix to support both AVR and Chibios ARM (#3968) * Update quantum matrix to support both AVR and Chibios ARM - Addition of STM32 pin definitions - Created abstruction layer defines to control GPIO (This is a bit pointless for Chibios as we are creating a PAL ontop of a PAL but it is necessary for uniformity with AVR) - Modified matrix.c to use the above functions * minor ifdef fix * Rename of functions and docs - Added documentation. - Renamed functions according to Jack's spec. * Massdrop fix * Update matrix.c * Update quantum.h * Update quantum.h * Update quantum.h * Update internals_gpio_control.md --- quantum/quantum.h | 69 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 12 deletions(-) (limited to 'quantum/quantum.h') 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 @@ -/* Copyright 2016-2017 Erez Zukerman, Jack Humbert +/* Copyright 2016-2018 Erez Zukerman, Jack Humbert, Yiancar * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,9 +17,12 @@ #define QUANTUM_H #if defined(__AVR__) -#include -#include -#include + #include + #include + #include +#endif +#if defined(PROTOCOL_CHIBIOS) + #include "hal.h" #endif #include "wait.h" #include "matrix.h" @@ -33,11 +36,11 @@ #ifdef RGBLIGHT_ENABLE #include "rgblight.h" #else - #ifdef RGB_MATRIX_ENABLE - /* dummy define RGBLIGHT_MODE_xxxx */ - #define RGBLIGHT_H_DUMMY_DEFINE - #include "rgblight.h" - #endif + #ifdef RGB_MATRIX_ENABLE + /* dummy define RGBLIGHT_MODE_xxxx */ + #define RGBLIGHT_H_DUMMY_DEFINE + #include "rgblight.h" + #endif #endif #ifdef SPLIT_KEYBOARD @@ -76,9 +79,9 @@ extern uint32_t default_layer_state; #ifdef AUDIO_ENABLE #include "audio.h" #include "process_audio.h" - #ifdef AUDIO_CLICKY - #include "process_clicky.h" - #endif // AUDIO_CLICKY + #ifdef AUDIO_CLICKY + #include "process_clicky.h" + #endif // AUDIO_CLICKY #endif #ifdef STENO_ENABLE @@ -133,6 +136,48 @@ extern uint32_t default_layer_state; #include "hd44780.h" #endif +//Function substitutions to ease GPIO manipulation +#ifdef __AVR__ + #define pin_t uint8_t + #define setPinInput(pin) _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF) + #define setPinInputHigh(pin) ({\ + _SFR_IO8((pin >> 4) + 1) &= ~ _BV(pin & 0xF);\ + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF);\ + }) + #define setPinInputLow(pin) _Static_assert(0, "AVR Processors cannot impliment an input as pull low") + #define setPinOutput(pin) _SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF) + + #define writePinHigh(pin) _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF) + #define writePinLow(pin) _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF) + static inline void writePin(pin_t pin, uint8_t level){ + if (level){ + _SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); + } else { + _SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); + } + } + + #define readPin(pin) (_SFR_IO8(pin >> 4) & _BV(pin & 0xF)) +#elif defined(PROTOCOL_CHIBIOS) + #define pin_t ioline_t + #define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) + #define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) + #define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) + #define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) + + #define writePinHigh(pin) palSetLine(pin) + #define writePinLow(pin) palClearLine(pin) + static inline void writePin(pin_t pin, uint8_t level){ + if (level){ + palSetLine(pin); + } else { + palClearLine(pin); + } + } + + #define readPin(pin) palReadLine(pin) +#endif + #define STRINGIZE(z) #z #define ADD_SLASH_X(y) STRINGIZE(\x ## y) #define SYMBOL_STR(x) ADD_SLASH_X(x) -- cgit v1.2.3-24-g4f1b