Skip to content

Commit a53cd59

Browse files
committed
Added is_connected() method to Digital I/O classes APIs (DigitalIn, DigitalOut and DigitalInOut
1 parent b7f4d17 commit a53cd59

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

libraries/mbed/api/DigitalIn.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ class DigitalIn {
8080
gpio_mode(&gpio, pull);
8181
}
8282

83+
/** Return the output setting, represented as 0 or 1 (int)
84+
*
85+
* @returns
86+
* Non zero value if pin is connected to uc GPIO
87+
* 0 if gpio object was initialized with NC
88+
*/
89+
int is_connected() {
90+
return gpio_is_connected(&gpio);
91+
}
92+
8393
#ifdef MBED_OPERATORS
8494
/** An operator shorthand for read()
8595
*/

libraries/mbed/api/DigitalInOut.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ class DigitalInOut {
8585
gpio_mode(&gpio, pull);
8686
}
8787

88+
/** Return the output setting, represented as 0 or 1 (int)
89+
*
90+
* @returns
91+
* Non zero value if pin is connected to uc GPIO
92+
* 0 if gpio object was initialized with NC
93+
*/
94+
int is_connected() {
95+
return gpio_is_connected(&gpio);
96+
}
97+
8898
#ifdef MBED_OPERATORS
8999
/** A shorthand for write()
90100
*/

libraries/mbed/api/DigitalOut.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ class DigitalOut {
7777
return gpio_read(&gpio);
7878
}
7979

80+
/** Return the output setting, represented as 0 or 1 (int)
81+
*
82+
* @returns
83+
* Non zero value if pin is connected to uc GPIO
84+
* 0 if gpio object was initialized with NC
85+
*/
86+
int is_connected() {
87+
return gpio_is_connected(&gpio);
88+
}
89+
8090
#ifdef MBED_OPERATORS
8191
/** A shorthand for write()
8292
*/

libraries/mbed/hal/gpio_api.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ uint32_t gpio_set(PinName pin);
3030

3131
/* Checks if gpio object is connected (pin was not initialized with NC)
3232
* @param pin The pin to be set as GPIO
33-
* @return Non zero value if port is connected to pin
34-
* 0 if port is initialized with NC
33+
* @return 0 if port is initialized with NC
3534
**/
3635
int gpio_is_connected(const gpio_t *obj);
3736

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_api.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ uint32_t gpio_set(PinName pin) {
3030
}
3131

3232
void gpio_init(gpio_t *obj, PinName pin) {
33-
obj->pinName = pin;
33+
obj->pin = pin;
3434
if (pin == (PinName)NC)
3535
return;
3636

@@ -42,14 +42,14 @@ void gpio_init(gpio_t *obj, PinName pin) {
4242
}
4343

4444
void gpio_mode(gpio_t *obj, PinMode mode) {
45-
pin_mode(obj->pinName, mode);
45+
pin_mode(obj->pin, mode);
4646
}
4747

4848
void gpio_dir(gpio_t *obj, PinDirection direction) {
49-
MBED_ASSERT(obj->pinName != (PinName)NC);
50-
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
49+
MBED_ASSERT(obj->pin != (PinName)NC);
50+
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
5151
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
52-
uint32_t pin_num = obj->pinName & 0xFF;
52+
uint32_t pin_num = obj->pin & 0xFF;
5353

5454
switch (direction) {
5555
case PIN_INPUT:

0 commit comments

Comments
 (0)