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.
pull/12477/head
Filip Jagodzinski 2020-02-18 16:39:26 +01:00
parent c12b433026
commit bcfca4fa5e
2 changed files with 25 additions and 2 deletions

View File

@ -2,7 +2,7 @@
/** \addtogroup hal */
/** @{*/
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -46,6 +46,8 @@ extern "C" {
* * ::gpio_init_out_ex inits the pin as an output and sets the output value
* * ::gpio_init_inout inits the pin to be input/output and set pin mode and value
* * The GPIO operations ::gpio_write, ::gpio_read take less than 20us to complete
* * The function ::gpio_get_capabilities fills the given
* `gpio_capabilities_t` instance according to pin capabilities.
*
* # Undefined behavior
* * 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" {
*
*/
/** GPIO capabilities for a given pin
*/
typedef struct {
uint8_t pull_none : 1;
uint8_t pull_down : 1;
uint8_t pull_up : 1;
} gpio_capabilities_t;
/** Set the given pin as GPIO
*
* @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);
*/
void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);
/** Fill the given gpio_capabilities_t instance according to pin capabilities.
*/
void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap);
/** Get the pins that support all GPIO tests
*
* Return a PinMap array of pins that support GPIO. The

View File

@ -1,5 +1,5 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
* Copyright (c) 2006-2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* 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
}
}
// To be re-implemented in the target layer if required.
MBED_WEAK void gpio_get_capabilities(gpio_t *gpio, gpio_capabilities_t *cap)
{
(void)gpio; // By default, every pin supports all basic input pull modes.
cap->pull_none = 1;
cap->pull_down = 1;
cap->pull_up = 1;
}
#ifdef TARGET_FF_ARDUINO
typedef enum {