Merge pull request #11867 from mprse/cypress_gpio_fix

Fix for Cypress GPIO driver (fix for issue #11835)
pull/11890/head
Martin Kojtal 2019-11-19 08:31:15 +01:00 committed by GitHub
commit a183033f59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -39,9 +39,9 @@ void apply_config(gpio_t *obj)
}
if (obj->drive_mode == PullUp) {
gpio_write(obj, 1);
gpio_set_pull(obj, 1);
} else if (obj->drive_mode == PullDown) {
gpio_write(obj, 0);
gpio_set_pull(obj, 0);
}
}
@ -80,6 +80,7 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
} else if (direction == PIN_OUTPUT) {
// mbed reads from input buffer instead of DR even for output pins so always leave input buffer enabled
obj->direction = CYHAL_GPIO_DIR_BIDIRECTIONAL;
gpio_write(obj, obj->output_val);
if (obj->drive_mode == CYHAL_GPIO_DRIVE_NONE || obj->drive_mode == CYHAL_GPIO_DRIVE_ANALOG) {
obj->drive_mode = CYHAL_GPIO_DRIVE_STRONG;
}

View File

@ -35,6 +35,7 @@ typedef struct {
cyhal_gpio_t pin;
cyhal_gpio_direction_t direction;
cyhal_gpio_drive_mode_t drive_mode;
int output_val;
} gpio_t;
struct gpio_irq_s {
@ -57,6 +58,21 @@ struct port_s {
* @param value The value to be set
*/
static inline void gpio_write(gpio_t *obj, int value)
{
if (obj->direction != CYHAL_GPIO_DIR_INPUT) {
MBED_ASSERT(obj->pin != CYHAL_NC_PIN_VALUE);
cyhal_gpio_write(obj->pin, value != 0);
} else {
obj->output_val = value;
}
}
/** Set the pull value
*
* @param obj The GPIO object
* @param value The pull value to be set
*/
static inline void gpio_set_pull(gpio_t *obj, int value)
{
MBED_ASSERT(obj->pin != CYHAL_NC_PIN_VALUE);
cyhal_gpio_write(obj->pin, value != 0);