Skip to content

Commit ef7b41b

Browse files
committed
[Nuvoton] Support GPIO input pull-high/pull-low
In Nuvoton, only new-design chips support GPIO input pull-high/pull-low modes. Targets not supporting this feature are listed below: - NUMAKER_PFM_NANO130 - NUMAKER_PFM_NUC472 - NUMAKER_PFM_M453
1 parent fbefe3f commit ef7b41b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/gpio_api.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,23 @@ void gpio_mode(gpio_t *obj, PinMode mode)
6262
return;
6363
}
6464

65+
uint32_t pin_index = NU_PININDEX(obj->pin);
66+
uint32_t port_index = NU_PINPORT(obj->pin);
67+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
68+
6569
switch (mode) {
6670
case PullNone:
71+
if (mode == PullNone) {
72+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
73+
}
6774
case PullDown:
75+
if (mode == PullDown) {
76+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
77+
}
6878
case PullUp:
79+
if (mode == PullUp) {
80+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
81+
}
6982
/* H/W doesn't support separate configuration for input pull mode/direction.
7083
* We translate to input-only/push-pull output I/O mode dependent on direction. */
7184
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;
@@ -110,10 +123,23 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
110123

111124
obj->direction = direction;
112125

126+
uint32_t pin_index = NU_PININDEX(obj->pin);
127+
uint32_t port_index = NU_PINPORT(obj->pin);
128+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
129+
113130
switch (obj->mode) {
114131
case PullNone:
132+
if (obj->mode == PullNone) {
133+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
134+
}
115135
case PullDown:
136+
if (obj->mode == PullDown) {
137+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
138+
}
116139
case PullUp:
140+
if (obj->mode == PullUp) {
141+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
142+
}
117143
/* H/W doesn't support separate configuration for input pull mode/direction.
118144
* We translate to input-only/push-pull output I/O mode dependent on direction. */
119145
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;

targets/TARGET_NUVOTON/TARGET_M480/gpio_api.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,23 @@ void gpio_mode(gpio_t *obj, PinMode mode)
6262
return;
6363
}
6464

65+
uint32_t pin_index = NU_PININDEX(obj->pin);
66+
uint32_t port_index = NU_PINPORT(obj->pin);
67+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
68+
6569
switch (mode) {
6670
case PullNone:
71+
if (mode == PullNone) {
72+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
73+
}
6774
case PullDown:
75+
if (mode == PullDown) {
76+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
77+
}
6878
case PullUp:
79+
if (mode == PullUp) {
80+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
81+
}
6982
/* H/W doesn't support separate configuration for input pull mode/direction.
7083
* We translate to input-only/push-pull output I/O mode dependent on direction. */
7184
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;
@@ -110,10 +123,23 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
110123

111124
obj->direction = direction;
112125

126+
uint32_t pin_index = NU_PININDEX(obj->pin);
127+
uint32_t port_index = NU_PINPORT(obj->pin);
128+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
129+
113130
switch (obj->mode) {
114131
case PullNone:
132+
if (obj->mode == PullNone) {
133+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
134+
}
115135
case PullDown:
136+
if (obj->mode == PullDown) {
137+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
138+
}
116139
case PullUp:
140+
if (obj->mode == PullUp) {
141+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
142+
}
117143
/* H/W doesn't support separate configuration for input pull mode/direction.
118144
* We translate to input-only/push-pull output I/O mode dependent on direction. */
119145
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;

0 commit comments

Comments
 (0)