stm32f1: Add support for gpio_x_reset()

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-08-20 17:15:04 -04:00
parent 983c84b12f
commit e5d95fdd00
2 changed files with 33 additions and 17 deletions

View File

@ -61,18 +61,25 @@ gpio_out_setup(uint8_t pin, uint8_t val)
goto fail;
GPIO_TypeDef *regs = digital_regs[GPIO2PORT(pin)];
uint32_t bit = digital_pins[pin % 16];
irqstatus_t flag = irq_save();
if (val)
LL_GPIO_SetOutputPin(regs, bit);
else
LL_GPIO_ResetOutputPin(regs, bit);
LL_GPIO_SetPinMode(regs, bit, LL_GPIO_MODE_OUTPUT);
irq_restore(flag);
return (struct gpio_out){ .regs = regs, .bit = bit };
struct gpio_out g = { .regs=regs, .bit=bit };
gpio_out_reset(g, val);
return g;
fail:
shutdown("Not an output pin");
}
void
gpio_out_reset(struct gpio_out g, uint8_t val)
{
irqstatus_t flag = irq_save();
if (val)
LL_GPIO_SetOutputPin(g.regs, g.bit);
else
LL_GPIO_ResetOutputPin(g.regs, g.bit);
LL_GPIO_SetPinMode(g.regs, g.bit, LL_GPIO_MODE_OUTPUT);
irq_restore(flag);
}
void
gpio_out_toggle_noirq(struct gpio_out g)
{
@ -104,19 +111,26 @@ gpio_in_setup(uint8_t pin, int8_t pull_up)
goto fail;
GPIO_TypeDef *regs = digital_regs[GPIO2PORT(pin)];
uint32_t bit = digital_pins[pin % 16];
irqstatus_t flag = irq_save();
if (pull_up) {
LL_GPIO_SetPinMode(regs, bit, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(regs, bit, LL_GPIO_PULL_UP);
} else {
LL_GPIO_SetPinMode(regs, bit, LL_GPIO_MODE_FLOATING);
}
irq_restore(flag);
return (struct gpio_in){ .regs = regs, .bit = bit };
struct gpio_in g = { .regs = regs, .bit = bit };
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)
{
irqstatus_t flag = irq_save();
if (pull_up) {
LL_GPIO_SetPinMode(g.regs, g.bit, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(g.regs, g.bit, LL_GPIO_PULL_UP);
} else {
LL_GPIO_SetPinMode(g.regs, g.bit, LL_GPIO_MODE_FLOATING);
}
irq_restore(flag);
}
uint8_t
gpio_in_read(struct gpio_in g)
{

View File

@ -11,6 +11,7 @@ struct gpio_out {
uint32_t bit;
};
struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val);
void gpio_out_reset(struct gpio_out g, uint8_t val);
void gpio_out_toggle_noirq(struct gpio_out g);
void gpio_out_toggle(struct gpio_out g);
void gpio_out_write(struct gpio_out g, uint8_t val);
@ -20,6 +21,7 @@ struct gpio_in {
uint32_t bit;
};
struct gpio_in gpio_in_setup(uint8_t pin, int8_t pull_up);
void gpio_in_reset(struct gpio_in g, int8_t pull_up);
uint8_t gpio_in_read(struct gpio_in g);
struct gpio_adc {