aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sam3x8e/gpio.c7
-rw-r--r--src/sam3x8e/internal.h2
-rw-r--r--src/sam3x8e/serial.c4
-rw-r--r--src/sam3x8e/spi.c6
4 files changed, 10 insertions, 9 deletions
diff --git a/src/sam3x8e/gpio.c b/src/sam3x8e/gpio.c
index 2311d41f..b12dc447 100644
--- a/src/sam3x8e/gpio.c
+++ b/src/sam3x8e/gpio.c
@@ -24,14 +24,15 @@ static Pio * const digital_regs[] = {
****************************************************************/
void
-gpio_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up)
+gpio_peripheral(uint32_t gpio, char ptype, int32_t pull_up)
{
- Pio *regs = digital_regs[bank - 'A'];
+ uint32_t bank = GPIO2PORT(gpio), bit = GPIO2BIT(gpio);
+ Pio *regs = digital_regs[bank];
if (ptype == 'A')
regs->PIO_ABSR &= ~bit;
else
regs->PIO_ABSR |= bit;
- if (pull_up)
+ if (pull_up > 0)
regs->PIO_PUER = bit;
else
regs->PIO_PUDR = bit;
diff --git a/src/sam3x8e/internal.h b/src/sam3x8e/internal.h
index 733ef694..8246d7a4 100644
--- a/src/sam3x8e/internal.h
+++ b/src/sam3x8e/internal.h
@@ -8,6 +8,6 @@
#define GPIO2PORT(PIN) ((PIN) / 32)
#define GPIO2BIT(PIN) (1<<((PIN) % 32))
-void gpio_peripheral(char bank, uint32_t bit, char ptype, uint32_t pull_up);
+void gpio_peripheral(uint32_t gpio, char ptype, int32_t pull_up);
#endif // internal.h
diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c
index a118122d..1fe55751 100644
--- a/src/sam3x8e/serial.c
+++ b/src/sam3x8e/serial.c
@@ -13,8 +13,8 @@
void
serial_init(void)
{
- gpio_peripheral('A', PIO_PA8A_URXD, 'A', 1);
- gpio_peripheral('A', PIO_PA9A_UTXD, 'A', 0);
+ gpio_peripheral(GPIO('A', 8), 'A', 1);
+ gpio_peripheral(GPIO('A', 9), 'A', 0);
// Reset uart
PMC->PMC_PCER0 = 1 << ID_UART;
diff --git a/src/sam3x8e/spi.c b/src/sam3x8e/spi.c
index 81e7b653..91b28e34 100644
--- a/src/sam3x8e/spi.c
+++ b/src/sam3x8e/spi.c
@@ -19,9 +19,9 @@ static void
spi_init(void)
{
/* Configure SCK, MISO and MOSI */
- gpio_peripheral('A', PIO_PA25A_SPI0_MISO, 'A', 0); // Arduino 74
- gpio_peripheral('A', PIO_PA26A_SPI0_MOSI, 'A', 0); // Arduino 75
- gpio_peripheral('A', PIO_PA27A_SPI0_SPCK, 'A', 0); // Arduino 76
+ gpio_peripheral(GPIO('A', 25), 'A', 0); // Arduino 74
+ gpio_peripheral(GPIO('A', 26), 'A', 0); // Arduino 75
+ gpio_peripheral(GPIO('A', 27), 'A', 0); // Arduino 76
// Enable SPI clocks
if (!(PMC->PMC_PCSR0 & (1u << PERIPH_ID))) {