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>
This commit is contained in:
Kevin O'Connor
2019-02-27 11:07:51 -05:00
parent b6589406d4
commit dddfb681c7
6 changed files with 40 additions and 20 deletions

View File

@@ -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);
}