From 33b06d41094267b86ebbb13b15135e7b11918ef1 Mon Sep 17 00:00:00 2001 From: Kyle Kearney Date: Wed, 31 Jul 2019 11:51:04 -0700 Subject: [PATCH] Fix inout pins not functioning correctly Update the drive mode when setting the GPIO direction. --- targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c b/targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c index f6a5921750..7c57d780fe 100644 --- a/targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c +++ b/targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c @@ -60,9 +60,16 @@ void gpio_mode(gpio_t *obj, PinMode mode) } } -void gpio_dir(MBED_UNUSED gpio_t *obj, MBED_UNUSED PinDirection direction) +void gpio_dir(gpio_t *obj, PinDirection direction) { - // mbed reads from input buffer instead of DR even for output pins so always leave input buffer enabled + if (direction == PIN_INPUT) { + cyhal_gpio_direction(obj->pin, CYHAL_GPIO_DIR_INPUT); + gpio_mode(obj, CYHAL_GPIO_DRIVE_ANALOG); + } else if (direction == PIN_OUTPUT) { + // mbed reads from input buffer instead of DR even for output pins so always leave input buffer enabled + cyhal_gpio_direction(obj->pin, CYHAL_GPIO_DIR_BIDIRECTIONAL); + gpio_mode(obj, CYHAL_GPIO_DRIVE_STRONG); + } } #ifdef __cplusplus