Skip to content

Commit

Permalink
Merge pull request #11867 from mprse/cypress_gpio_fix
Browse files Browse the repository at this point in the history
Fix for Cypress GPIO driver (fix for issue #11835)
  • Loading branch information
0xc0170 authored Nov 19, 2019
2 parents 2e96145 + 48b02af commit a183033
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit a183033

Please sign in to comment.