29
29
30
30
/* Private functions ------------------------------------------------------------*/
31
31
32
- static void nu_gpio_mode (struct rt_device * device , rt_base_t pin , rt_base_t mode );
33
- static void nu_gpio_write (struct rt_device * device , rt_base_t pin , rt_base_t value );
34
- static int nu_gpio_read (struct rt_device * device , rt_base_t pin );
35
- static rt_err_t nu_gpio_attach_irq (struct rt_device * device , rt_int32_t pin , rt_uint32_t mode , void (* hdr )(void * args ), void * args );
32
+ static void nu_gpio_mode (struct rt_device * device , rt_base_t pin , rt_uint8_t mode );
33
+ static void nu_gpio_write (struct rt_device * device , rt_base_t pin , rt_uint8_t value );
34
+ static rt_int8_t nu_gpio_read (struct rt_device * device , rt_base_t pin );
35
+ static rt_err_t nu_gpio_attach_irq (struct rt_device * device , rt_int32_t pin , rt_uint8_t mode , void (* hdr )(void * args ), void * args );
36
36
static rt_err_t nu_gpio_detach_irq (struct rt_device * device , rt_int32_t pin );
37
- static rt_err_t nu_gpio_irq_enable (struct rt_device * device , rt_base_t pin , rt_uint32_t enabled );
38
- static rt_base_t nu_gpio_get (const char * name );
37
+ static rt_err_t nu_gpio_irq_enable (struct rt_device * device , rt_base_t pin , rt_uint8_t enabled );
38
+ static rt_base_t nu_gpio_pin_get (const char * name );
39
39
40
40
/* Private variables ------------------------------------------------------------*/
41
41
static struct rt_pin_irq_hdr pin_irq_hdr_tab [IRQ_MAX_NUM ];
@@ -47,7 +47,7 @@ static struct rt_pin_ops nu_gpio_ops =
47
47
nu_gpio_attach_irq ,
48
48
nu_gpio_detach_irq ,
49
49
nu_gpio_irq_enable ,
50
- nu_gpio_get ,
50
+ nu_gpio_pin_get ,
51
51
};
52
52
53
53
static rt_uint32_t g_u32PinIrqMask = 0x0 ;
@@ -102,7 +102,32 @@ static void pin_irq_hdr(rt_uint32_t irq_status, rt_uint32_t port_index)
102
102
}
103
103
}
104
104
105
- static void nu_gpio_mode (struct rt_device * device , rt_base_t pin , rt_base_t mode )
105
+ static rt_base_t nu_gpio_pin_get (const char * name )
106
+ {
107
+ /* Get pin number by name,such as PA.0, PF12 */
108
+ if ((name [2 ] == '\0' ) || ((name [2 ] == '.' ) && (name [3 ] == '\0' )))
109
+ return - (RT_EINVAL );
110
+
111
+ long number ;
112
+
113
+ if ((name [2 ] == '.' ))
114
+ number = atol (& name [3 ]);
115
+ else
116
+ number = atol (& name [2 ]);
117
+
118
+ if (number > 15 )
119
+ return - (RT_EINVAL );
120
+
121
+ if (name [1 ] >= 'A' && name [1 ] <= 'H' )
122
+ return ((name [1 ] - 'A' ) * 0x10 ) + number ;
123
+
124
+ if (name [1 ] >= 'a' && name [1 ] <= 'h' )
125
+ return ((name [1 ] - 'a' ) * 0x10 ) + number ;
126
+
127
+ return - (RT_EINVAL );
128
+ }
129
+
130
+ static void nu_gpio_mode (struct rt_device * device , rt_base_t pin , rt_uint8_t mode )
106
131
{
107
132
GPIO_T * PORT ;
108
133
@@ -140,23 +165,23 @@ static void nu_gpio_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode
140
165
#endif
141
166
}
142
167
143
- static void nu_gpio_write (struct rt_device * device , rt_base_t pin , rt_base_t value )
168
+ static void nu_gpio_write (struct rt_device * device , rt_base_t pin , rt_uint8_t value )
144
169
{
145
170
if (nu_port_check (pin ))
146
171
return ;
147
172
148
173
GPIO_PIN_DATA (NU_GET_PORT (pin ), NU_GET_PINS (pin )) = value ;
149
174
}
150
175
151
- static int nu_gpio_read (struct rt_device * device , rt_base_t pin )
176
+ static rt_int8_t nu_gpio_read (struct rt_device * device , rt_base_t pin )
152
177
{
153
178
if (nu_port_check (pin ))
154
179
return PIN_LOW ;
155
180
156
181
return GPIO_PIN_DATA (NU_GET_PORT (pin ), NU_GET_PINS (pin ));
157
182
}
158
183
159
- static rt_err_t nu_gpio_attach_irq (struct rt_device * device , rt_int32_t pin , rt_uint32_t mode , void (* hdr )(void * args ), void * args )
184
+ static rt_err_t nu_gpio_attach_irq (struct rt_device * device , rt_int32_t pin , rt_uint8_t mode , void (* hdr )(void * args ), void * args )
160
185
{
161
186
rt_base_t level ;
162
187
rt_int32_t irqindex ;
@@ -223,7 +248,7 @@ static rt_err_t nu_gpio_detach_irq(struct rt_device *device, rt_int32_t pin)
223
248
return RT_EOK ;
224
249
}
225
250
226
- static rt_err_t nu_gpio_irq_enable (struct rt_device * device , rt_base_t pin , rt_uint32_t enabled )
251
+ static rt_err_t nu_gpio_irq_enable (struct rt_device * device , rt_base_t pin , rt_uint8_t enabled )
227
252
{
228
253
GPIO_T * PORT ;
229
254
rt_base_t level ;
@@ -282,32 +307,6 @@ static rt_err_t nu_gpio_irq_enable(struct rt_device *device, rt_base_t pin, rt_u
282
307
return - (ret );
283
308
}
284
309
285
- static rt_base_t nu_gpio_get (const char * name )
286
- {
287
- /* Get pin number by name,such as PA.0, PF12 */
288
- if ((name [2 ] == '\0' )|| ((name [2 ] == '.' )&& (name [3 ] == '\0' )))
289
- return - (RT_EINVAL );
290
-
291
- long number ;
292
-
293
- if ((name [2 ] == '.' ))
294
- number = atol (& name [3 ]);
295
- else
296
- number = atol (& name [2 ]);
297
-
298
- if (number > 15 )
299
- return - (RT_EINVAL );
300
-
301
- if (name [1 ] >= 'A' && name [1 ] <= 'H' )
302
- return ((name [1 ] - 'A' ) * 0x10 ) + number ;
303
-
304
- if (name [1 ] >= 'a' && name [1 ] <= 'h' )
305
- return ((name [1 ] - 'a' ) * 0x10 ) + number ;
306
-
307
- return - (RT_EINVAL );
308
-
309
- }
310
-
311
310
int rt_hw_gpio_init (void )
312
311
{
313
312
rt_int32_t irqindex ;
0 commit comments