aboutsummaryrefslogtreecommitdiffstats
path: root/src/lpc176x/gpio.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-02-27 11:07:51 -0500
committerKevin O'Connor <kevin@koconnor.net>2019-02-27 11:13:21 -0500
commitdddfb681c737c5623dc270bf6c8e59fd3b13b092 (patch)
treec295b1c5837c2f1d6f6f569b595b2506cd2f69b7 /src/lpc176x/gpio.c
parentb6589406d46186bc9ae76a3db49363c5168e30e9 (diff)
downloadkutter-dddfb681c737c5623dc270bf6c8e59fd3b13b092.tar.gz
kutter-dddfb681c737c5623dc270bf6c8e59fd3b13b092.tar.xz
kutter-dddfb681c737c5623dc270bf6c8e59fd3b13b092.zip
pins: Add support for pull down resistors
Add initial support for selecting pull down resistors (for micro-controllers that support it). Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/lpc176x/gpio.c')
-rw-r--r--src/lpc176x/gpio.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lpc176x/gpio.c b/src/lpc176x/gpio.c
index 0b5fb1a9..5c76ec55 100644
--- a/src/lpc176x/gpio.c
+++ b/src/lpc176x/gpio.c
@@ -23,7 +23,7 @@ static LPC_GPIO_TypeDef * const digital_regs[] = {
// Set the mode and extended function of a pin
void
-gpio_peripheral(uint32_t gpio, int func, int pullup)
+gpio_peripheral(uint32_t gpio, int func, int pull_up)
{
uint32_t bank_pos = GPIO2PORT(gpio) * 2, pin_pos = (gpio % 32) * 2;
if (pin_pos >= 32) {
@@ -31,12 +31,12 @@ gpio_peripheral(uint32_t gpio, int func, int pullup)
bank_pos++;
}
uint32_t sel_bits = (func & 0x03) << pin_pos, mask = ~(0x03 << pin_pos);
- uint32_t mode_bits = (pullup ? 0x00 : 0x02) << pin_pos;
+ uint32_t mode = (pull_up ? (pull_up > 0 ? 0x00 : 0x03) : 0x02) << pin_pos;
volatile uint32_t *pinsel = &LPC_PINCON->PINSEL0;
volatile uint32_t *pinmode = &LPC_PINCON->PINMODE0;
irqstatus_t flag = irq_save();
pinsel[bank_pos] = (pinsel[bank_pos] & mask) | sel_bits;
- pinmode[bank_pos] = (pinmode[bank_pos] & mask) | mode_bits;
+ pinmode[bank_pos] = (pinmode[bank_pos] & mask) | mode;
irq_restore(flag);
}