Skip to content

Commit 78ae1e0

Browse files
committed
M263: 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 5b7beab commit 78ae1e0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

targets/TARGET_NUVOTON/TARGET_M261/gpio_api.c

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

66+
uint32_t pin_index = NU_PININDEX(obj->pin);
67+
uint32_t port_index = NU_PINPORT(obj->pin);
68+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
69+
6670
switch (mode) {
6771
case PullNone:
72+
if (mode == PullNone) {
73+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
74+
}
6875
case PullDown:
76+
if (mode == PullDown) {
77+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
78+
}
6979
case PullUp:
80+
if (mode == PullUp) {
81+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
82+
}
7083
/* H/W doesn't support separate configuration for input pull mode/direction.
7184
* We translate to input-only/push-pull output I/O mode dependent on direction. */
7285
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;
@@ -111,10 +124,23 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
111124

112125
obj->direction = direction;
113126

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

0 commit comments

Comments
 (0)