@@ -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