-
Notifications
You must be signed in to change notification settings - Fork 19
/
spin_gpio.c
52 lines (50 loc) · 1.38 KB
/
spin_gpio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include"spin_gpio.h"
#define local_set(gpio,value) P##gpio=value
#define local_get(gpio) P##gpio
//#define local_set_bit(gpio,index,value) P##gpio##_##index=!!value
void spin_set_gpio_value(GPIOS gpio,uchar value){
switch(gpio){
case 0:local_set(0,value);break;
case 1:local_set(1,value);break;
case 2:local_set(2,value);break;
case 3:local_set(3,value);break;
default:break;
}
}
uchar spin_get_gpio_value(GPIOS gpio){
uchar temp = 0;
switch(gpio){
case 0:temp = local_get(0);break;
case 1:temp = local_get(1);break;
case 2:temp = local_get(2);break;
case 3:temp = local_get(3);break;
default:break;
}
return temp;
}
//index start from 0
void spin_set_gpio_bit_value(GPIOS gpio,uchar index,uchar value){
uchar temp = 0;
if(!!value)
temp=spin_get_gpio_value(gpio) | (0x01<<index);
else
temp=spin_get_gpio_value(gpio)& (~(0x01<<index));
switch(gpio){
case 0:local_set(0,temp);break;
case 1:local_set(1,temp);break;
case 2:local_set(2,temp);break;
case 3:local_set(3,temp);break;
default:break;
}
}
uchar spin_get_gpio_bit_value(GPIOS gpio,uchar index){
uchar temp = 0;
switch(gpio){
case 0:temp = local_get(0);break;
case 1:temp = local_get(1);break;
case 2:temp = local_get(2);break;
case 3:temp = local_get(3);break;
default:break;
}
return !!(temp & (0x01<<index));
}