Skip to content

Commit b7f4d17

Browse files
committed
Added new GPIO HAL function gpio_is_connected() used to check if gpio_t is connected or initialized with NC
Simple gpio_t structure in TARGET_KPSDK_MCUS field name changed to allign to other HALs
1 parent b75dada commit b7f4d17

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

libraries/mbed/hal/gpio_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ extern "C" {
2828
**/
2929
uint32_t gpio_set(PinName pin);
3030

31+
/* Checks if gpio object is connected (pin was not initialized with NC)
32+
* @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
35+
**/
36+
int gpio_is_connected(const gpio_t *obj);
37+
3138
/* GPIO object */
3239
void gpio_init(gpio_t *obj, PinName pin);
3340

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/gpio_object.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,31 @@ extern "C" {
2525
#endif
2626

2727
typedef struct {
28-
PinName pinName;
28+
PinName pin;
2929
} gpio_t;
3030

3131
static inline void gpio_write(gpio_t *obj, int value) {
32-
MBED_ASSERT(obj->pinName != (PinName)NC);
33-
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
34-
uint32_t pin = obj->pinName & 0xFF;
32+
MBED_ASSERT(obj->pin != (PinName)NC);
33+
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
34+
uint32_t pin = obj->pin & 0xFF;
3535
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
3636

3737
GPIO_HAL_WritePinOutput(gpio_addrs[port], pin, value);
3838
}
3939

4040
static inline int gpio_read(gpio_t *obj) {
41-
MBED_ASSERT(obj->pinName != (PinName)NC);
42-
uint32_t port = obj->pinName >> GPIO_PORT_SHIFT;
43-
uint32_t pin = obj->pinName & 0xFF;
41+
MBED_ASSERT(obj->pin != (PinName)NC);
42+
uint32_t port = obj->pin >> GPIO_PORT_SHIFT;
43+
uint32_t pin = obj->pin & 0xFF;
4444
uint32_t gpio_addrs[] = GPIO_BASE_ADDRS;
4545

4646
return (int)GPIO_HAL_ReadPinInput(gpio_addrs[port], pin);
4747
}
4848

49+
static inline int gpio_is_connected(const gpio_t *obj) {
50+
return obj->pin != (PinName)NC;
51+
}
52+
4953
#ifdef __cplusplus
5054
}
5155
#endif

0 commit comments

Comments
 (0)