From 964c145eef5dae28cf81abad1b8ffa9c77203c79 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Fri, 26 Sep 2014 17:25:21 +0200 Subject: [PATCH] cpu/nrf51822: fixed gpio driver --- cpu/nrf51822/periph/gpio.c | 44 +++++++++++--------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/cpu/nrf51822/periph/gpio.c b/cpu/nrf51822/periph/gpio.c index a402e93313..7a7a609820 100644 --- a/cpu/nrf51822/periph/gpio.c +++ b/cpu/nrf51822/periph/gpio.c @@ -143,22 +143,12 @@ int gpio_init_out(gpio_t dev, gpio_pp_t pullup) return pin; } - /* set pin to output mode */ - NRF_GPIO->DIRSET = (1 << pin); - - /* set pin to standard configuration */ - NRF_GPIO->PIN_CNF[pin] = 0; - - /* set pull register configuration */ - switch (pullup) { - case GPIO_NOPULL: - return -1; - case GPIO_PULLUP: - NRF_GPIO->PIN_CNF[dev] |= (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos); - break; - case GPIO_PULLDOWN: - NRF_GPIO->PIN_CNF[dev] |= (GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos); - break; + /* configure pin: output, input buffer disabled */ + NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos) | + (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos); + /* configure pull up value, map 0x1 -> 0x2; 0x2 -> 0x1 */ + if (pullup > 0) { + NRF_GPIO->PIN_CNF[pin] |= ((pullup ^ 0x3) << GPIO_PIN_CNF_PULL_Pos); } return 0; @@ -171,22 +161,12 @@ int gpio_init_in(gpio_t dev, gpio_pp_t pullup) return pin; } - /* set pin to output mode */ - NRF_GPIO->DIRCLR = (1 << pin); - - /* set pin to standard configuration */ - NRF_GPIO->PIN_CNF[pin] = 0; - - /* set pull register configuration */ - switch (pullup) { - case GPIO_NOPULL: - return -1; - case GPIO_PULLUP: - NRF_GPIO->PIN_CNF[dev] |= (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos); - break; - case GPIO_PULLDOWN: - NRF_GPIO->PIN_CNF[dev] |= (GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos); - break; + /* configure pin: output, input buffer disabled */ + NRF_GPIO->PIN_CNF[pin] = (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | + (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos); + /* configure pull up value, map 0x1 -> 0x2; 0x2 -> 0x1 */ + if (pullup > 0) { + NRF_GPIO->PIN_CNF[pin] |= ((pullup ^ 0x3) << GPIO_PIN_CNF_PULL_Pos); } return 0;