Skip to content

Commit bcfca4f

Browse files
author
Filip Jagodzinski
committed
HAL: GPIO: Add the get_capabilities function
Add the gpio_get_capabilities() to GPIO HAL API. Add a default, weak implementation, that every target can override.
1 parent c12b433 commit bcfca4f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

hal/gpio_api.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** \addtogroup hal */
33
/** @{*/
44
/* mbed Microcontroller Library
5-
* Copyright (c) 2006-2013 ARM Limited
5+
* Copyright (c) 2006-2020 ARM Limited
66
* SPDX-License-Identifier: Apache-2.0
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -46,6 +46,8 @@ extern "C" {
4646
* * ::gpio_init_out_ex inits the pin as an output and sets the output value
4747
* * ::gpio_init_inout inits the pin to be input/output and set pin mode and value
4848
* * The GPIO operations ::gpio_write, ::gpio_read take less than 20us to complete
49+
* * The function ::gpio_get_capabilities fills the given
50+
* `gpio_capabilities_t` instance according to pin capabilities.
4951
*
5052
* # Undefined behavior
5153
* * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized
@@ -65,6 +67,14 @@ extern "C" {
6567
*
6668
*/
6769

70+
/** GPIO capabilities for a given pin
71+
*/
72+
typedef struct {
73+
uint8_t pull_none : 1;
74+
uint8_t pull_down : 1;
75+
uint8_t pull_up : 1;
76+
} gpio_capabilities_t;
77+
6878
/** Set the given pin as GPIO
6979
*
7080
* @param pin The pin to be set as GPIO
@@ -164,6 +174,10 @@ void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
164174
*/
165175
void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
166176

177+
/** Fill the given gpio_capabilities_t instance according to pin capabilities.
178+
*/
179+
void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap);
180+
167181
/** Get the pins that support all GPIO tests
168182
*
169183
* Return a PinMap array of pins that support GPIO. The

hal/mbed_gpio.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2006-2013 ARM Limited
2+
* Copyright (c) 2006-2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -68,6 +68,15 @@ void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode
6868
}
6969
}
7070

71+
// To be re-implemented in the target layer if required.
72+
MBED_WEAK void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap)
73+
{
74+
(void)gpio; // By default, every pin supports all basic input pull modes.
75+
cap->pull_none = 1;
76+
cap->pull_down = 1;
77+
cap->pull_up = 1;
78+
}
79+
7180
#ifdef TARGET_FF_ARDUINO
7281

7382
typedef enum {

0 commit comments

Comments
 (0)