aboutsummaryrefslogtreecommitdiffstats
path: root/src/sam3x8e/gpio.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-08-20 16:27:46 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-08-27 12:40:38 -0400
commit109eff0191fef3b4e939b3d506d6c31fcbd6ab0c (patch)
treefffc38b4117c24310fa4e72510d829ebe055f2b8 /src/sam3x8e/gpio.c
parent5a993b743ed25bf9228afdf2dc5fa8836d1dbb1b (diff)
downloadkutter-109eff0191fef3b4e939b3d506d6c31fcbd6ab0c.tar.gz
kutter-109eff0191fef3b4e939b3d506d6c31fcbd6ab0c.tar.xz
kutter-109eff0191fef3b4e939b3d506d6c31fcbd6ab0c.zip
sam3x8e: Add support for gpio_x_reset()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/sam3x8e/gpio.c')
-rw-r--r--src/sam3x8e/gpio.c52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/sam3x8e/gpio.c b/src/sam3x8e/gpio.c
index acfe0d90..9b7cca65 100644
--- a/src/sam3x8e/gpio.c
+++ b/src/sam3x8e/gpio.c
@@ -53,19 +53,27 @@ gpio_out_setup(uint8_t pin, uint8_t val)
if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs))
goto fail;
Pio *regs = digital_regs[GPIO2PORT(pin)];
- uint32_t bit = GPIO2BIT(pin);
+ struct gpio_out g = { .regs=regs, .bit=GPIO2BIT(pin) };
+ gpio_out_reset(g, val);
+ return g;
+fail:
+ shutdown("Not an output pin");
+}
+
+void
+gpio_out_reset(struct gpio_out g, uint8_t val)
+{
+ Pio *regs = g.regs;
irqstatus_t flag = irq_save();
if (val)
- regs->PIO_SODR = bit;
+ regs->PIO_SODR = g.bit;
else
- regs->PIO_CODR = bit;
- regs->PIO_OER = bit;
- regs->PIO_OWER = bit;
- regs->PIO_PER = bit;
+ regs->PIO_CODR = g.bit;
+ regs->PIO_OER = g.bit;
+ regs->PIO_OWER = g.bit;
+ regs->PIO_PER = g.bit;
+ regs->PIO_PUDR = g.bit;
irq_restore(flag);
- return (struct gpio_out){ .regs=regs, .bit=bit };
-fail:
- shutdown("Not an output pin");
}
void
@@ -100,20 +108,26 @@ gpio_in_setup(uint8_t pin, int8_t pull_up)
if (GPIO2PORT(pin) >= ARRAY_SIZE(digital_regs))
goto fail;
uint32_t port = GPIO2PORT(pin);
- Pio *regs = digital_regs[port];
- uint32_t bit = GPIO2BIT(pin);
- irqstatus_t flag = irq_save();
PMC->PMC_PCER0 = 1 << (ID_PIOA + port);
+ struct gpio_in g = { .regs=digital_regs[port], .bit=GPIO2BIT(pin) };
+ gpio_in_reset(g, pull_up);
+ return g;
+fail:
+ shutdown("Not an input pin");
+}
+
+void
+gpio_in_reset(struct gpio_in g, int8_t pull_up)
+{
+ Pio *regs = g.regs;
+ irqstatus_t flag = irq_save();
if (pull_up)
- regs->PIO_PUER = bit;
+ regs->PIO_PUER = g.bit;
else
- regs->PIO_PUDR = bit;
- regs->PIO_ODR = bit;
- regs->PIO_PER = bit;
+ regs->PIO_PUDR = g.bit;
+ regs->PIO_ODR = g.bit;
+ regs->PIO_PER = g.bit;
irq_restore(flag);
- return (struct gpio_in){ .regs=regs, .bit=bit };
-fail:
- shutdown("Not an input pin");
}
uint8_t