mirror of https://github.com/ARMmbed/mbed-os.git
Added is_connected() method to Digital I/O classes APIs (DigitalIn, DigitalOut and DigitalInOut
parent
b7f4d17aae
commit
a53cd59b51
|
@ -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()
|
||||
*/
|
||||
|
|
|
@ -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()
|
||||
*/
|
||||
|
|
|
@ -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()
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue