aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi ISHII <2170248+mtei@users.noreply.github.com>2021-06-07 18:23:21 +0900
committerGitHub <noreply@github.com>2021-06-07 18:23:21 +0900
commitb72f10c6357eee628ab1f3762f66ba8a0a279a4e (patch)
tree3aab1305662ac8ae25d2c6326801aa15fb4291fe
parent59862d30d08224f4cf23828f94e1ea8134208a0a (diff)
downloadqmk_firmware-b72f10c6357eee628ab1f3762f66ba8a0a279a4e.tar.gz
qmk_firmware-b72f10c6357eee628ab1f3762f66ba8a0a279a4e.zip
Add readPort() and some API to 'tmk_core/common/*/gpio.h' (#12754)
* add readPort() and some API to 'tmk_core/common/*/gpio.h' The following macros have been added to gpio.h. * readPort(port) * setPortBitInput(port, bit) * setPortBitInputHigh(port, bit) * setPortBitOutput(port, bit) * writePortBitLow(port, bit) * writePortBitHigh(port, bit) * add data type 'port_data_t' into gpio.h * rename qmk_pin to pin
-rw-r--r--tmk_core/common/avr/gpio.h15
-rw-r--r--tmk_core/common/chibios/gpio.h16
2 files changed, 31 insertions, 0 deletions
diff --git a/tmk_core/common/avr/gpio.h b/tmk_core/common/avr/gpio.h
index 231556c29..e9be68491 100644
--- a/tmk_core/common/avr/gpio.h
+++ b/tmk_core/common/avr/gpio.h
@@ -20,6 +20,8 @@
20 20
21typedef uint8_t pin_t; 21typedef uint8_t pin_t;
22 22
23/* Operation of GPIO by pin. */
24
23#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF)) 25#define setPinInput(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
24#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF)) 26#define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
25#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low") 27#define setPinInputLow(pin) _Static_assert(0, "AVR processors cannot implement an input as pull low")
@@ -32,3 +34,16 @@ typedef uint8_t pin_t;
32#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF))) 34#define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
33 35
34#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF)) 36#define togglePin(pin) (PORTx_ADDRESS(pin) ^= _BV((pin)&0xF))
37
38/* Operation of GPIO by port. */
39
40typedef uint8_t port_data_t;
41
42#define readPort(port) PINx_ADDRESS(port)
43
44#define setPortBitInput(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
45#define setPortBitInputHigh(port, bit) (DDRx_ADDRESS(port) &= ~_BV((bit)&0xF), PORTx_ADDRESS(port) |= _BV((bit)&0xF))
46#define setPortBitOutput(port, bit) (DDRx_ADDRESS(port) |= _BV((bit)&0xF))
47
48#define writePortBitLow(port, bit) (PORTx_ADDRESS(port) &= ~_BV((bit)&0xF))
49#define writePortBitHigh(port, bit) (PORTx_ADDRESS(port) |= _BV((bit)&0xF))
diff --git a/tmk_core/common/chibios/gpio.h b/tmk_core/common/chibios/gpio.h
index 5d0e142ab..4d057f1ca 100644
--- a/tmk_core/common/chibios/gpio.h
+++ b/tmk_core/common/chibios/gpio.h
@@ -20,6 +20,8 @@
20 20
21typedef ioline_t pin_t; 21typedef ioline_t pin_t;
22 22
23/* Operation of GPIO by pin. */
24
23#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) 25#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT)
24#define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) 26#define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP)
25#define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) 27#define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN)
@@ -32,3 +34,17 @@ typedef ioline_t pin_t;
32#define readPin(pin) palReadLine(pin) 34#define readPin(pin) palReadLine(pin)
33 35
34#define togglePin(pin) palToggleLine(pin) 36#define togglePin(pin) palToggleLine(pin)
37
38/* Operation of GPIO by port. */
39
40typedef uint16_t port_data_t;
41
42#define readPort(pin) palReadPort(PAL_PORT(pin))
43
44#define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT)
45#define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLUP)
46#define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLDOWN)
47#define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_OUTPUT_PUSHPULL)
48
49#define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), bit))
50#define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), bit))