From a53cd59b51f1244ef21f4ffae13bfb078d280cc8 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Fri, 19 Dec 2014 13:28:47 +0000 Subject: [PATCH] Added is_connected() method to Digital I/O classes APIs (DigitalIn, DigitalOut and DigitalInOut --- libraries/mbed/api/DigitalIn.h | 10 ++++++++++ libraries/mbed/api/DigitalInOut.h | 10 ++++++++++ libraries/mbed/api/DigitalOut.h | 10 ++++++++++ libraries/mbed/hal/gpio_api.h | 3 +-- .../hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c | 10 +++++----- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/libraries/mbed/api/DigitalIn.h b/libraries/mbed/api/DigitalIn.h index d81038b8cf..b089de9faa 100644 --- a/libraries/mbed/api/DigitalIn.h +++ b/libraries/mbed/api/DigitalIn.h @@ -80,6 +80,16 @@ public: gpio_mode(&gpio, pull); } + /** Return the output setting, represented as 0 or 1 (int) + * + * @returns + * Non zero value if pin is connected to uc GPIO + * 0 if gpio object was initialized with NC + */ + int is_connected() { + return gpio_is_connected(&gpio); + } + #ifdef MBED_OPERATORS /** An operator shorthand for read() */ diff --git a/libraries/mbed/api/DigitalInOut.h b/libraries/mbed/api/DigitalInOut.h index 5d9221b5dc..e30be0e638 100644 --- a/libraries/mbed/api/DigitalInOut.h +++ b/libraries/mbed/api/DigitalInOut.h @@ -85,6 +85,16 @@ public: gpio_mode(&gpio, pull); } + /** Return the output setting, represented as 0 or 1 (int) + * + * @returns + * Non zero value if pin is connected to uc GPIO + * 0 if gpio object was initialized with NC + */ + int is_connected() { + return gpio_is_connected(&gpio); + } + #ifdef MBED_OPERATORS /** A shorthand for write() */ diff --git a/libraries/mbed/api/DigitalOut.h b/libraries/mbed/api/DigitalOut.h index 0281770ff8..0d66f907b0 100644 --- a/libraries/mbed/api/DigitalOut.h +++ b/libraries/mbed/api/DigitalOut.h @@ -77,6 +77,16 @@ public: return gpio_read(&gpio); } + /** Return the output setting, represented as 0 or 1 (int) + * + * @returns + * Non zero value if pin is connected to uc GPIO + * 0 if gpio object was initialized with NC + */ + int is_connected() { + return gpio_is_connected(&gpio); + } + #ifdef MBED_OPERATORS /** A shorthand for write() */ diff --git a/libraries/mbed/hal/gpio_api.h b/libraries/mbed/hal/gpio_api.h index ab5206aa93..872b547eaa 100644 --- a/libraries/mbed/hal/gpio_api.h +++ b/libraries/mbed/hal/gpio_api.h @@ -30,8 +30,7 @@ uint32_t gpio_set(PinName pin); /* Checks if gpio object is connected (pin was not initialized with NC) * @param pin The pin to be set as GPIO - * @return Non zero value if port is connected to pin - * 0 if port is initialized with NC + * @return 0 if port is initialized with NC **/ int gpio_is_connected(const gpio_t *obj); diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c index 73259e4dde..cde73ff4fd 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c @@ -30,7 +30,7 @@ uint32_t gpio_set(PinName pin) { } void gpio_init(gpio_t *obj, PinName pin) { - obj->pinName = pin; + obj->pin = pin; if (pin == (PinName)NC) return; @@ -42,14 +42,14 @@ void gpio_init(gpio_t *obj, PinName pin) { } void gpio_mode(gpio_t *obj, PinMode mode) { - pin_mode(obj->pinName, mode); + pin_mode(obj->pin, mode); } void gpio_dir(gpio_t *obj, PinDirection direction) { - MBED_ASSERT(obj->pinName != (PinName)NC); - uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; + MBED_ASSERT(obj->pin != (PinName)NC); + uint32_t port = obj->pin >> GPIO_PORT_SHIFT; uint32_t gpio_addrs[] = GPIO_BASE_ADDRS; - uint32_t pin_num = obj->pinName & 0xFF; + uint32_t pin_num = obj->pin & 0xFF; switch (direction) { case PIN_INPUT: