STM32: gpio few performance improvements

Those are minor changes to increase performance of widely used
GPIO functions.
pull/3665/head
Laurent MEUNIER 2017-01-18 18:51:07 +01:00
parent 3517eb108e
commit dce2ca75d8
2 changed files with 20 additions and 9 deletions

View File

@ -31,6 +31,9 @@
#include "gpio_api.h"
#include "pinmap.h"
#include "mbed_error.h"
#include "pin_device.h"
extern const uint32_t ll_pin_defines[16];
// Enable GPIO clock and return GPIO base address
GPIO_TypeDef *Set_GPIO_Clock(uint32_t port_idx) {
@ -113,6 +116,7 @@ uint32_t gpio_set(PinName pin) {
return (uint32_t)(1 << ((uint32_t)pin & 0xF)); // Return the pin mask
}
void gpio_init(gpio_t *obj, PinName pin) {
obj->pin = pin;
if (pin == (PinName)NC) {
@ -126,6 +130,8 @@ void gpio_init(gpio_t *obj, PinName pin) {
// Fill GPIO object structure for future use
obj->mask = gpio_set(pin);
obj->gpio = gpio;
obj->ll_pin = ll_pin_defines[STM_PIN(obj->pin)];
obj->reg_in = &gpio->IDR;
obj->reg_set = &gpio->BSRR;
#ifdef GPIO_IP_WITHOUT_BRR
@ -139,11 +145,15 @@ void gpio_mode(gpio_t *obj, PinMode mode) {
pin_mode(obj->pin, mode);
}
void gpio_dir(gpio_t *obj, PinDirection direction) {
MBED_ASSERT(obj->pin != (PinName)NC);
if (direction == PIN_OUTPUT) {
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
} else { // PIN_INPUT
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
inline void gpio_dir(gpio_t *obj, PinDirection direction) {
if (direction == PIN_INPUT)
{
LL_GPIO_SetPinMode(obj->gpio, obj->ll_pin, LL_GPIO_MODE_INPUT);
}
else
{
LL_GPIO_SetPinMode(obj->gpio, obj->ll_pin, LL_GPIO_MODE_OUTPUT);
}
}

View File

@ -46,16 +46,17 @@ extern "C" {
* if BRR does not exist, family shall define GPIO_DOES_NOT_HAVE_BRR
*/
typedef struct {
PinName pin;
uint32_t mask;
__IO uint32_t *reg_in;
__IO uint32_t *reg_set;
__IO uint32_t *reg_clr;
PinName pin;
GPIO_TypeDef *gpio;
uint32_t ll_pin;
} gpio_t;
static inline void gpio_write(gpio_t *obj, int value)
{
MBED_ASSERT(obj->pin != (PinName)NC);
if (value) {
*obj->reg_set = obj->mask;
} else {
@ -69,7 +70,6 @@ static inline void gpio_write(gpio_t *obj, int value)
static inline int gpio_read(gpio_t *obj)
{
MBED_ASSERT(obj->pin != (PinName)NC);
return ((*obj->reg_in & obj->mask) ? 1 : 0);
}
@ -78,6 +78,7 @@ static inline int gpio_is_connected(const gpio_t *obj)
return obj->pin != (PinName)NC;
}
#ifdef __cplusplus
}
#endif