|
| 1 | +/* |
| 2 | + * This file is part of the unicore-mx project. |
| 3 | + * |
| 4 | + * This library is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Lesser General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This library is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Lesser General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Lesser General Public License |
| 15 | + * along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +#ifndef LIBUCMX_GPIO_H |
| 19 | +#define LIBUCMX_GPIO_H |
| 20 | + |
| 21 | +#include <unicore-mx/cm3/common.h> |
| 22 | +#include <unicore-mx/nrf/memorymap.h> |
| 23 | + |
| 24 | +#define GPIO (GPIO_BASE) |
| 25 | + |
| 26 | +#define GPIO_OUT MMIO32(GPIO_BASE + 0x504) |
| 27 | +#define GPIO_OUTSET MMIO32(GPIO_BASE + 0x508) |
| 28 | +#define GPIO_OUTCLR MMIO32(GPIO_BASE + 0x50C) |
| 29 | + |
| 30 | +#define GPIO_IN MMIO32(GPIO_BASE + 0x510) |
| 31 | + |
| 32 | +#define GPIO_DIR MMIO32(GPIO_BASE + 0x514) |
| 33 | +#define GPIO_DIRSET MMIO32(GPIO_BASE + 0x518) |
| 34 | +#define GPIO_DIRCLR MMIO32(GPIO_BASE + 0x51C) |
| 35 | + |
| 36 | +#define GPIO_PIN_CNF(N) MMIO32(GPIO_BASE + 0x700 + 0x4 * (N)) |
| 37 | + |
| 38 | +#define GPIOPIN0 (1 << 0) |
| 39 | +#define GPIOPIN1 (1 << 1) |
| 40 | +#define GPIOPIN2 (1 << 2) |
| 41 | +#define GPIOPIN3 (1 << 3) |
| 42 | +#define GPIOPIN4 (1 << 4) |
| 43 | +#define GPIOPIN5 (1 << 5) |
| 44 | +#define GPIOPIN6 (1 << 6) |
| 45 | +#define GPIOPIN7 (1 << 7) |
| 46 | +#define GPIOPIN8 (1 << 8) |
| 47 | +#define GPIOPIN9 (1 << 9) |
| 48 | +#define GPIOPIN10 (1 << 10) |
| 49 | +#define GPIOPIN11 (1 << 11) |
| 50 | +#define GPIOPIN12 (1 << 12) |
| 51 | +#define GPIOPIN13 (1 << 13) |
| 52 | +#define GPIOPIN14 (1 << 14) |
| 53 | +#define GPIOPIN15 (1 << 15) |
| 54 | +#define GPIOPIN16 (1 << 16) |
| 55 | +#define GPIOPIN17 (1 << 17) |
| 56 | +#define GPIOPIN18 (1 << 18) |
| 57 | +#define GPIOPIN19 (1 << 19) |
| 58 | +#define GPIOPIN20 (1 << 20) |
| 59 | +#define GPIOPIN21 (1 << 21) |
| 60 | +#define GPIOPIN22 (1 << 22) |
| 61 | +#define GPIOPIN23 (1 << 23) |
| 62 | +#define GPIOPIN24 (1 << 24) |
| 63 | +#define GPIOPIN25 (1 << 25) |
| 64 | +#define GPIOPIN26 (1 << 26) |
| 65 | +#define GPIOPIN27 (1 << 27) |
| 66 | +#define GPIOPIN28 (1 << 28) |
| 67 | +#define GPIOPIN29 (1 << 29) |
| 68 | +#define GPIOPIN30 (1 << 30) |
| 69 | +#define GPIOPIN31 (1 << 31) |
| 70 | + |
| 71 | +#define GPIOPINN(n) (1 << (n)) |
| 72 | + |
| 73 | +#define PIN_CNF_DIR (1 << 0) |
| 74 | +#define PIN_CNF_INPUT (1 << 1) |
| 75 | + |
| 76 | +#define PIN_CNF_PULL_SHIFT (2) |
| 77 | +#define PIN_CNF_PULL_MASK (3 << PIN_CNF_PULL_SHIFT) |
| 78 | +#define PIN_CNF_PULL_MASKED(V) (((V) << PIN_CNF_PULL_SHIFT) & PIN_CNF_PULL_MASK) |
| 79 | + |
| 80 | +#define PIN_CNF_DRIVE_SHIFT (8) |
| 81 | +#define PIN_CNF_DRIVE_MASK (7 << PIN_CNF_DRIVE_SHIFT) |
| 82 | +#define PIN_CNF_DRIVE_MASKED(V) (((V) << PIN_CNF_DRIVE_SHIFT) & PIN_CNF_DRIVE_MASK) |
| 83 | + |
| 84 | +#define PIN_CNF_SENSE_SHIFT (16) |
| 85 | +#define PIN_CNF_SENSE_MASK (3 << PIN_CNF_SENSE_SHIFT) |
| 86 | +#define PIN_CNF_SENSE_MASKED(V) (((V) << PIN_CNF_SENSE_SHIFT) & PIN_CNF_SENSE_MASK) |
| 87 | + |
| 88 | +/* GPIO Tasks and Events (GPIOTE) */ |
| 89 | +#define GPIO_TASK_OUT(n) MMIO32(GPIOTE_BASE + 0x4 * (n)) |
| 90 | +#define GPIO_TASK_OUT0 GPIO_TASK_OUT(0) |
| 91 | +#define GPIO_TASK_OUT1 GPIO_TASK_OUT(1) |
| 92 | +#define GPIO_TASK_OUT2 GPIO_TASK_OUT(2) |
| 93 | +#define GPIO_TASK_OUT3 GPIO_TASK_OUT(3) |
| 94 | + |
| 95 | +#define GPIO_EVENT_IN(n) MMIO32(GPIOTE_BASE + 0x100 + 0x4 * (n)) |
| 96 | +#define GPIO_EVENT_IN0 GPIO_EVENT_IN(0) |
| 97 | +#define GPIO_EVENT_IN1 GPIO_EVENT_IN(1) |
| 98 | +#define GPIO_EVENT_IN2 GPIO_EVENT_IN(2) |
| 99 | +#define GPIO_EVENT_IN3 GPIO_EVENT_IN(3) |
| 100 | + |
| 101 | +#define GPIO_EVENT_PORT MMIO32(GPIOTE_BASE + 0x17C) |
| 102 | + |
| 103 | +#define GPIO_INTEN MMIO32(GPIOTE_BASE + 0x300) |
| 104 | +#define GPIO_INTENSET MMIO32(GPIOTE_BASE + 0x304) |
| 105 | +#define GPIO_INTENCLR MMIO32(GPIOTE_BASE + 0x308) |
| 106 | + |
| 107 | +#define GPIO_TE_CONFIG(n) MMIO32(GPIOTE_BASE + 0x510 + 0x4 * (n)) |
| 108 | +#define GPIO_TE_CONFIG0 GPIO_TE_CONFIG(0) |
| 109 | +#define GPIO_TE_CONFIG1 GPIO_TE_CONFIG(1) |
| 110 | +#define GPIO_TE_CONFIG2 GPIO_TE_CONFIG(2) |
| 111 | +#define GPIO_TE_CONFIG3 GPIO_TE_CONFIG(3) |
| 112 | + |
| 113 | +/* Register Details */ |
| 114 | +#define GPIO_INTEN_IN(n) (1 << (n)) |
| 115 | +#define GPIO_INTEN_IN0 (1 << 0) |
| 116 | +#define GPIO_INTEN_IN1 (1 << 1) |
| 117 | +#define GPIO_INTEN_IN2 (1 << 2) |
| 118 | +#define GPIO_INTEN_IN3 (1 << 3) |
| 119 | + |
| 120 | +#define GPIO_INTEN_PORT (1 << 31) |
| 121 | + |
| 122 | +#define GPIO_TE_CONFIG_MODE_SHIFT (0) |
| 123 | +#define GPIO_TE_CONFIG_MODE_MASK (3 << GPIO_TE_CONFIG_MODE_SHIFT) |
| 124 | +#define GPIO_TE_CONFIG_MODE_MASKED(V) (((V) << GPIO_TE_CONFIG_MODE_SHIFT) & GPIO_TE_CONFIG_MODE_MASK) |
| 125 | + |
| 126 | +#define GPIO_TE_CONFIG_PSEL_SHIFT (8) |
| 127 | +#define GPIO_TE_CONFIG_PSEL_MASK (0x1f << GPIO_TE_CONFIG_PSEL_SHIFT) |
| 128 | +#define GPIO_TE_CONFIG_PSEL_MASKED(V) (((V) << GPIO_TE_CONFIG_PSEL_SHIFT) & GPIO_TE_CONFIG_PSEL_MASK) |
| 129 | + |
| 130 | +#define GPIO_TE_CONFIG_POLARITY_SHIFT (16) |
| 131 | +#define GPIO_TE_CONFIG_POLARITY_MASK (3 << GPIO_TE_CONFIG_POLARITY_SHIFT) |
| 132 | +#define GPIO_TE_CONFIG_POLARITY_MASKED(V) (((V) << GPIO_TE_CONFIG_POLARITY_SHIFT) & GPIO_TE_CONFIG_POLARITY_MASK) |
| 133 | + |
| 134 | +#define GPIO_TE_CONFIG_OUTINIT (1 << 20) |
| 135 | + |
| 136 | +#define GPIO_DIR_INPUT (0) |
| 137 | +#define GPIO_DIR_OUTPUT (1) |
| 138 | + |
| 139 | +#define GPIO_INPUT_CONNECT (0) |
| 140 | +#define GPIO_INPUT_DISCONNECT (1) |
| 141 | + |
| 142 | +#define GPIO_PULL_NONE (0) |
| 143 | +#define GPIO_PULL_DOWN (1) |
| 144 | +#define GPIO_PULL_UP (3) |
| 145 | + |
| 146 | +#define GPIO_DRIVE_S0S1 (0) |
| 147 | +#define GPIO_DRIVE_H0S1 (1) |
| 148 | +#define GPIO_DRIVE_S0H1 (2) |
| 149 | +#define GPIO_DRIVE_H0H1 (3) |
| 150 | +#define GPIO_DRIVE_D0S1 (4) |
| 151 | +#define GPIO_DRIVE_D0H1 (5) |
| 152 | +#define GPIO_DRIVE_S0D1 (6) |
| 153 | +#define GPIO_DRIVE_H0D1 (7) |
| 154 | + |
| 155 | +#define GPIO_TE_MODE_DISABLED (0) |
| 156 | +#define GPIO_TE_MODE_EVENT (1) |
| 157 | +#define GPIO_TE_MODE_TASK (3) |
| 158 | + |
| 159 | +#define GPIO_TE_POLARITY_NONE (0) |
| 160 | +#define GPIO_TE_POLARITY_LO_TO_HI (1) |
| 161 | +#define GPIO_TE_POLARITY_HI_TO_LO (2) |
| 162 | +#define GPIO_TE_POLARITY_TOGGLE (3) |
| 163 | + |
| 164 | +#define GPIO_TE_OUTINIT_LOW (1) |
| 165 | +#define GPIO_TE_OUTINIT_HIGH GPIO_TE_CONFIG_OUTINIT |
| 166 | + |
| 167 | +BEGIN_DECLS |
| 168 | + |
| 169 | +void gpio_set(uint32_t gpios); |
| 170 | +void gpio_clear(uint32_t gpios); |
| 171 | +void gpio_toggle(uint32_t gpios); |
| 172 | +uint32_t gpio_get(uint32_t gpios); |
| 173 | + |
| 174 | +void gpio_setup_mode(uint32_t gpios, uint8_t dir, uint8_t pull); |
| 175 | + |
| 176 | +void gpio_configure_task(uint8_t task_num, |
| 177 | + uint8_t pin_num, uint8_t polarity, uint8_t init); |
| 178 | + |
| 179 | +void gpio_configure_event(uint8_t event_num, uint8_t pin_num, uint8_t polarity); |
| 180 | + |
| 181 | +void gpio_enable_interrupts(uint32_t mask); |
| 182 | +void gpio_disable_interrupts(uint32_t mask); |
| 183 | +void gpio_clear_interrupts(void); |
| 184 | + |
| 185 | +END_DECLS |
| 186 | + |
| 187 | +#endif /* LIBUCMX_GPIO_H */ |
0 commit comments