@@ -64,10 +64,23 @@ void gpio_mode(gpio_t *obj, PinMode mode)
64
64
return ;
65
65
}
66
66
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
+
67
71
switch (mode ) {
68
72
case PullNone :
73
+ if (mode == PullNone ) {
74
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_DISABLE );
75
+ }
69
76
case PullDown :
77
+ if (mode == PullDown ) {
78
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_PULL_DOWN );
79
+ }
70
80
case PullUp :
81
+ if (mode == PullUp ) {
82
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_PULL_UP );
83
+ }
71
84
/* H/W doesn't support separate configuration for input pull mode/direction.
72
85
* We translate to input-only/push-pull output I/O mode dependent on direction. */
73
86
obj -> mode = (obj -> direction == PIN_INPUT ) ? InputOnly : PushPullOutput ;
@@ -112,10 +125,23 @@ void gpio_dir(gpio_t *obj, PinDirection direction)
112
125
113
126
obj -> direction = direction ;
114
127
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
+
115
132
switch (obj -> mode ) {
116
133
case PullNone :
134
+ if (obj -> mode == PullNone ) {
135
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_DISABLE );
136
+ }
117
137
case PullDown :
138
+ if (obj -> mode == PullDown ) {
139
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_PULL_DOWN );
140
+ }
118
141
case PullUp :
142
+ if (obj -> mode == PullUp ) {
143
+ GPIO_SetPullCtl (gpio_base , 1 << pin_index , GPIO_PUSEL_PULL_UP );
144
+ }
119
145
/* H/W doesn't support separate configuration for input pull mode/direction.
120
146
* We translate to input-only/push-pull output I/O mode dependent on direction. */
121
147
obj -> mode = (obj -> direction == PIN_INPUT ) ? InputOnly : PushPullOutput ;
0 commit comments