aboutsummaryrefslogtreecommitdiffstats
path: root/src/sam3/gpio.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-12-26 16:50:44 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-01-07 19:33:26 -0500
commit94c86d6c6ce85143d47b79f7cc2680c6b0ee6889 (patch)
treea9b8e293c4ba986e306366f039d9b979086bb12b /src/sam3/gpio.c
parente278552d44e2d795e335ec33f898c9d6e1413688 (diff)
downloadkutter-94c86d6c6ce85143d47b79f7cc2680c6b0ee6889.tar.gz
kutter-94c86d6c6ce85143d47b79f7cc2680c6b0ee6889.tar.xz
kutter-94c86d6c6ce85143d47b79f7cc2680c6b0ee6889.zip
sam3: Merge sam4e8e support into sam3 code
Most of the peripherals on the sam4e8e are similar to the ones on the sam3x8e mcu. Merge the code together and use just one code directory. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/sam3/gpio.c')
-rw-r--r--src/sam3/gpio.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/sam3/gpio.c b/src/sam3/gpio.c
index f48c5f0d..a0dfa0a4 100644
--- a/src/sam3/gpio.c
+++ b/src/sam3/gpio.c
@@ -1,4 +1,4 @@
-// GPIO functions on sam3x8e
+// GPIO functions on sam3/sam4
//
// Copyright (C) 2016-2018 Kevin O'Connor <kevin@koconnor.net>
//
@@ -9,11 +9,14 @@
#include "compiler.h" // ARRAY_SIZE
#include "gpio.h" // gpio_out_setup
#include "internal.h" // gpio_peripheral
-#include "sam3x8e.h" // Pio
#include "sched.h" // sched_shutdown
static Pio * const digital_regs[] = {
+#if CONFIG_MACH_SAM3X8E
PIOA, PIOB, PIOC, PIOD
+#elif CONFIG_MACH_SAM4E8E
+ PIOA, PIOB, PIOC, PIOD, PIOE
+#endif
};
@@ -24,12 +27,16 @@ static Pio * const digital_regs[] = {
void
gpio_peripheral(uint32_t gpio, char ptype, int32_t pull_up)
{
- uint32_t bank = GPIO2PORT(gpio), bit = GPIO2BIT(gpio);
+ uint32_t bank = GPIO2PORT(gpio), bit = GPIO2BIT(gpio), pt = ptype - 'A';
Pio *regs = digital_regs[bank];
- if (ptype == 'A')
- regs->PIO_ABSR &= ~bit;
- else
- regs->PIO_ABSR |= bit;
+
+#if CONFIG_MACH_SAM3X8E
+ regs->PIO_ABSR = (regs->PIO_ABSR & ~bit) | (pt & 0x01 ? bit : 0);
+#else
+ regs->PIO_ABCDSR[0] = (regs->PIO_ABCDSR[0] & ~bit) | (pt & 0x01 ? bit : 0);
+ regs->PIO_ABCDSR[1] = (regs->PIO_ABCDSR[1] & ~bit) | (pt & 0x02 ? bit : 0);
+#endif
+
if (pull_up > 0)
regs->PIO_PUER = bit;
else