Skip to content

Commit be526aa

Browse files
committed
[M252KG] 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 7f562e6 commit be526aa

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

targets/TARGET_NUVOTON/TARGET_M251/gpio_api.c

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

67+
uint32_t pin_index = NU_PININDEX(obj->pin);
68+
uint32_t port_index = NU_PINPORT(obj->pin);
69+
GPIO_T *gpio_base = NU_PORT_BASE(port_index);
70+
6771
switch (mode) {
6872
case PullNone:
73+
if (mode == PullNone) {
74+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_DISABLE);
75+
}
6976
case PullDown:
77+
if (mode == PullDown) {
78+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_DOWN);
79+
}
7080
case PullUp:
81+
if (mode == PullUp) {
82+
GPIO_SetPullCtl(gpio_base, 1 << pin_index, GPIO_PUSEL_PULL_UP);
83+
}
7184
/* H/W doesn't support separate configuration for input pull mode/direction.
7285
* We translate to input-only/push-pull output I/O mode dependent on direction. */
7386
obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput;
@@ -112,10 +125,23 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
112125

113126
obj->direction = direction;
114127

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

0 commit comments

Comments
 (0)