Skip to content
Snippets Groups Projects
Commit d9aac6a7 authored by Karl Fessel's avatar Karl Fessel
Browse files

atmega_common/gpio_init: fix pull-up settings for GPIO_IN_PU

This Patch makes gpio_init precalculate the pin mask once,
This Patch makes gpio_init of atmega_common configure the pin as an input and configure the pullup in the case of GPIO_IN_PU.
GPIO_IN_PU and GPIO_IN need to change pullup so they need to change output (this is coverd by the not touching outputs is not guaranteed statement)
(this is a special case for atmega the pull_up is configured by writing 1 to the port_register which is also the level of the output if the pin is configured to output).

This fix makes it more compliant to comments in periph/gpio.h
parent 1e325399
No related branches found
No related tags found
No related merge requests found
......@@ -127,16 +127,18 @@ static inline int8_t _int_num(gpio_t pin)
int gpio_init(gpio_t pin, gpio_mode_t mode)
{
uint8_t pin_mask = (1 << _pin_num(pin));
switch (mode) {
case GPIO_OUT:
_SFR_MEM8(_ddr_addr(pin)) |= (1 << _pin_num(pin));
_SFR_MEM8(_ddr_addr(pin)) |= pin_mask;
break;
case GPIO_IN:
_SFR_MEM8(_ddr_addr(pin)) &= ~(1 << _pin_num(pin));
_SFR_MEM8(_port_addr(pin)) &= ~(1 << _pin_num(pin));
_SFR_MEM8(_ddr_addr(pin)) &= ~pin_mask;
_SFR_MEM8(_port_addr(pin)) &= ~pin_mask;
break;
case GPIO_IN_PU:
_SFR_MEM8(_port_addr(pin)) |= (1 << _pin_num(pin));
_SFR_MEM8(_ddr_addr(pin)) &= ~pin_mask;
_SFR_MEM8(_port_addr(pin)) |= pin_mask;
break;
default:
return -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment