Skip to content

Fix for Cypress GPIO driver (fix for issue #11835) #11867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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