-
Notifications
You must be signed in to change notification settings - Fork 6
/
gpio.c
53 lines (47 loc) · 1.12 KB
/
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
53
#include <stdlib.h>
#include <stdio.h>
#include "gpio_lib.c"
#include <string.h>
int dy(int port,int tf)
{
//printf("SUNXI GPIO tool\n");
if(SETUP_OK!=sunxi_gpio_init()){
printf("Failed to initialize GPIO\n");
return 1;
}
if(SETUP_OK!=sunxi_gpio_set_cfgpin(SUNXI_GPD(port),OUTPUT)){
printf("Failed to config GPIO pin\n");
return 1;
}
int i;
if(tf == 0){
if(sunxi_gpio_output(SUNXI_GPD(port),LOW)){
printf("Failed to set GPIO pin value\n");
return 1;
}
}else{
if(sunxi_gpio_output(SUNXI_GPD(port),HIGH)){
printf("Failed to set GPIO pin value\n");
return 1;
}
}
sunxi_gpio_cleanup();
return 0;
}
int main(int argc,char* argv[]){
if(argc != 3){
printf("gpio [port] [1 or 0]\n");
return 1;
}else{
int a = 0;
int i = 0;
for(i=0;i<strlen(argv[1]);i++){
a*=10;
a+=argv[1][i]-'0';
}
//dy(a,argv[2][0]-'0');
//printf("%d \\ %d \n",argv[1][0]-'0',argv[2][0]-'0');
//printf("%c\n",argv[1][0]);
return dy(a,argv[2][0]-'0');
}
}