Added is_connected() method to Digital I/O classes APIs (DigitalIn, DigitalOut and DigitalInOut

pull/808/head
Przemek Wirkus 2014-12-19 13:28:47 +00:00
parent b7f4d17aae
commit a53cd59b51
5 changed files with 36 additions and 7 deletions

View File

@ -80,6 +80,16 @@ public:
gpio_mode(&gpio, pull); 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 #ifdef MBED_OPERATORS
/** An operator shorthand for read() /** An operator shorthand for read()
*/ */

View File

@ -85,6 +85,16 @@ public:
gpio_mode(&gpio, pull); 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 #ifdef MBED_OPERATORS
/** A shorthand for write() /** A shorthand for write()
*/ */

View File

@ -77,6 +77,16 @@ public:
return gpio_read(&gpio); 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 #ifdef MBED_OPERATORS
/** A shorthand for write() /** A shorthand for write()
*/ */

View File

@ -30,8 +30,7 @@ uint32_t gpio_set(PinName pin);
/* Checks if gpio object is connected (pin was not initialized with NC) /* Checks if gpio object is connected (pin was not initialized with NC)
* @param pin The pin to be set as GPIO * @param pin The pin to be set as GPIO
* @return Non zero value if port is connected to pin * @return 0 if port is initialized with NC
* 0 if port is initialized with NC
**/ **/
int gpio_is_connected(const gpio_t *obj); int gpio_is_connected(const gpio_t *obj);

View File

@ -30,7 +30,7 @@ uint32_t gpio_set(PinName pin) {
} }
void gpio_init(gpio_t *obj, PinName pin) { void gpio_init(gpio_t *obj, PinName pin) {
obj->pinName = pin; obj->pin = pin;
if (pin == (PinName)NC) if (pin == (PinName)NC)
return; return;
@ -42,14 +42,14 @@ void gpio_init(gpio_t *obj, PinName pin) {
} }
void gpio_mode(gpio_t *obj, PinMode mode) { 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) { void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pinName != (PinName)NC); MBED_ASSERT(obj->pin != (PinName)NC);
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT; uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS; uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
uint32_t pin_num = obj->pinName & 0xFF; uint32_t pin_num = obj->pin & 0xFF;
switch (direction) { switch (direction) {
case PIN_INPUT: case PIN_INPUT: