aboutsummaryrefslogtreecommitdiff
path: root/platforms/arm_atsam/gpio.h
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/arm_atsam/gpio.h')
-rw-r--r--platforms/arm_atsam/gpio.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/platforms/arm_atsam/gpio.h b/platforms/arm_atsam/gpio.h
new file mode 100644
index 000000000..915ed0ef4
--- /dev/null
+++ b/platforms/arm_atsam/gpio.h
@@ -0,0 +1,77 @@
1/* Copyright 2021 QMK
2 *
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
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#include "stdint.h"
19#include "samd51j18a.h"
20
21#include "pin_defs.h"
22
23typedef uint8_t pin_t;
24
25#define SAMD_PORT(pin) ((pin & 0x20) >> 5)
26#define SAMD_PIN(pin) (pin & 0x1f)
27#define SAMD_PIN_MASK(pin) (1 << (pin & 0x1f))
28
29#define setPinInput(pin) \
30 do { \
31 PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \
32 PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \
33 } while (0)
34
35#define setPinInputHigh(pin) \
36 do { \
37 PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \
38 PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \
39 PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \
40 PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \
41 } while (0)
42
43#define setPinInputLow(pin) \
44 do { \
45 PORT->Group[SAMD_PORT(pin)].DIRCLR.reg = SAMD_PIN_MASK(pin); \
46 PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \
47 PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.INEN = 1; \
48 PORT->Group[SAMD_PORT(pin)].PINCFG[SAMD_PIN(pin)].bit.PULLEN = 1; \
49 } while (0)
50
51#define setPinOutput(pin) \
52 do { \
53 PORT->Group[SAMD_PORT(pin)].DIRSET.reg = SAMD_PIN_MASK(pin); \
54 PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \
55 } while (0)
56
57#define writePinHigh(pin) \
58 do { \
59 PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \
60 } while (0)
61
62#define writePinLow(pin) \
63 do { \
64 PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \
65 } while (0)
66
67#define writePin(pin, level) \
68 do { \
69 if (level) \
70 PORT->Group[SAMD_PORT(pin)].OUTSET.reg = SAMD_PIN_MASK(pin); \
71 else \
72 PORT->Group[SAMD_PORT(pin)].OUTCLR.reg = SAMD_PIN_MASK(pin); \
73 } while (0)
74
75#define readPin(pin) ((PORT->Group[SAMD_PORT(pin)].IN.reg & SAMD_PIN_MASK(pin)) != 0)
76
77#define togglePin(pin) (PORT->Group[SAMD_PORT(pin)].OUTTGL.reg = SAMD_PIN_MASK(pin))