diff --git a/platform/nrf52xxx/gpio.c b/platform/nrf52xxx/gpio.c index f027cab9..b6736713 100644 --- a/platform/nrf52xxx/gpio.c +++ b/platform/nrf52xxx/gpio.c @@ -5,55 +5,44 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT */ -#include + #include +#include +#include #include -#include -#include +#include +#include int gpio_config(unsigned nr, unsigned flags) { - DEBUG_ASSERT(nr <= NRF_MAX_PIN_NUMBER); - - unsigned init; + if (!nrf_gpio_pin_present_check(nr)) { + return ERR_INVALID_ARGS; + } if (flags & GPIO_OUTPUT) { - - NRF_P0->PIN_CNF[nr] = GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos | \ - GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos | \ - GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos | \ - GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos; + nrf_gpio_cfg_output(nr); } else { // GPIO_INPUT + nrf_gpio_pin_pull_t pull; if (flags & GPIO_PULLUP) { - init = GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos; + pull = NRF_GPIO_PIN_PULLUP; } else if (flags & GPIO_PULLDOWN) { - init = GPIO_PIN_CNF_PULL_Pulldown << GPIO_PIN_CNF_PULL_Pos; + pull = NRF_GPIO_PIN_PULLDOWN; } else { - init = GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos; + pull = NRF_GPIO_PIN_NOPULL; } - NRF_P0->PIN_CNF[nr] = GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos | \ - GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos | \ - init; + nrf_gpio_cfg_input(nr, pull); } - return 0; + return NO_ERROR; } void gpio_set(unsigned nr, unsigned on) { - DEBUG_ASSERT(nr <= NRF_MAX_PIN_NUMBER); + DEBUG_ASSERT(nrf_gpio_pin_present_check(nr)); - if (on > 0) { - NRF_P0->OUTSET = 1 << nr; - } else { - NRF_P0->OUTCLR = 1 << nr; - } + nrf_gpio_pin_write(nr, on); } int gpio_get(unsigned nr) { - DEBUG_ASSERT( nr <= NRF_MAX_PIN_NUMBER ); + DEBUG_ASSERT(nrf_gpio_pin_present_check(nr)); - if ( NRF_P0->IN & ( 1 << nr) ) { - return 1; - } else { - return 0; - } + return (int)nrf_gpio_pin_read(nr); } diff --git a/platform/nrf52xxx/include/platform/gpio.h b/platform/nrf52xxx/include/platform/gpio.h deleted file mode 100644 index f1738dc5..00000000 --- a/platform/nrf52xxx/include/platform/gpio.h +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (c) 2016 Eric Holland - * - * Use of this source code is governed by a MIT-style - * license that can be found in the LICENSE file or at - * https://opensource.org/licenses/MIT - */ -#pragma once - -#define NRF_MAX_PIN_NUMBER 31 - diff --git a/platform/nrf52xxx/uart.c b/platform/nrf52xxx/uart.c index 64e14c89..4e9ece19 100644 --- a/platform/nrf52xxx/uart.c +++ b/platform/nrf52xxx/uart.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/target/nrf-pca10056/include/target/gpioconfig.h b/target/nrf-pca10056/include/target/gpioconfig.h index 43b0a406..21255c4e 100644 --- a/target/nrf-pca10056/include/target/gpioconfig.h +++ b/target/nrf-pca10056/include/target/gpioconfig.h @@ -8,8 +8,6 @@ #ifndef __TARGET_GPIOCONFIG_H #define __TARGET_GPIOCONFIG_H -#include - #define GPIO_LED1 13 #define GPIO_LED2 14 #define GPIO_LED3 15 diff --git a/target/nrf-pca10056/init.c b/target/nrf-pca10056/init.c index cfb753b6..63b28cb1 100644 --- a/target/nrf-pca10056/init.c +++ b/target/nrf-pca10056/init.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include