Skip to content

Commit a183033

Browse files
authored
Merge pull request #11867 from mprse/cypress_gpio_fix
Fix for Cypress GPIO driver (fix for issue #11835)
2 parents 2e96145 + 48b02af commit a183033

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

targets/TARGET_Cypress/TARGET_PSOC6/cy_gpio_api.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ void apply_config(gpio_t *obj)
3939
}
4040

4141
if (obj->drive_mode == PullUp) {
42-
gpio_write(obj, 1);
42+
gpio_set_pull(obj, 1);
4343
} else if (obj->drive_mode == PullDown) {
44-
gpio_write(obj, 0);
44+
gpio_set_pull(obj, 0);
4545
}
4646
}
4747

@@ -80,6 +80,7 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
8080
} else if (direction == PIN_OUTPUT) {
8181
// mbed reads from input buffer instead of DR even for output pins so always leave input buffer enabled
8282
obj->direction = CYHAL_GPIO_DIR_BIDIRECTIONAL;
83+
gpio_write(obj, obj->output_val);
8384
if (obj->drive_mode == CYHAL_GPIO_DRIVE_NONE || obj->drive_mode == CYHAL_GPIO_DRIVE_ANALOG) {
8485
obj->drive_mode = CYHAL_GPIO_DRIVE_STRONG;
8586
}

targets/TARGET_Cypress/TARGET_PSOC6/gpio_object.h

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef struct {
3535
cyhal_gpio_t pin;
3636
cyhal_gpio_direction_t direction;
3737
cyhal_gpio_drive_mode_t drive_mode;
38+
int output_val;
3839
} gpio_t;
3940

4041
struct gpio_irq_s {
@@ -57,6 +58,21 @@ struct port_s {
5758
* @param value The value to be set
5859
*/
5960
static inline void gpio_write(gpio_t *obj, int value)
61+
{
62+
if (obj->direction != CYHAL_GPIO_DIR_INPUT) {
63+
MBED_ASSERT(obj->pin != CYHAL_NC_PIN_VALUE);
64+
cyhal_gpio_write(obj->pin, value != 0);
65+
} else {
66+
obj->output_val = value;
67+
}
68+
}
69+
70+
/** Set the pull value
71+
*
72+
* @param obj The GPIO object
73+
* @param value The pull value to be set
74+
*/
75+
static inline void gpio_set_pull(gpio_t *obj, int value)
6076
{
6177
MBED_ASSERT(obj->pin != CYHAL_NC_PIN_VALUE);
6278
cyhal_gpio_write(obj->pin, value != 0);

0 commit comments

Comments
 (0)