Add files via upload
This commit is contained in:
parent
e6db699dec
commit
8e96f3f837
9
SOFTWARE/A64-TERES/teres1-debug/Makefile
Normal file
9
SOFTWARE/A64-TERES/teres1-debug/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
all:
|
||||
$(CC) teres1-debug.c -o teres1-debug
|
||||
|
||||
clean:
|
||||
$(RM) teres1-debug
|
||||
|
||||
install: all
|
||||
install -m0755 teres1-debug /usr/local/sbin
|
||||
|
76
SOFTWARE/A64-TERES/teres1-debug/teres1-debug.c
Normal file
76
SOFTWARE/A64-TERES/teres1-debug/teres1-debug.c
Normal file
@ -0,0 +1,76 @@
|
||||
/* teres1-debug.c - debug mode switch
|
||||
|
||||
Copyright (C) 2018 Chris Boudacoff
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 2 of the License.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#define DEBUGEN 361
|
||||
|
||||
|
||||
void export_gpio(int gpio)
|
||||
{
|
||||
int fd;
|
||||
char buf[255];
|
||||
|
||||
fd = open("/sys/class/gpio/export", O_WRONLY);
|
||||
sprintf(buf, "%d", gpio);
|
||||
write(fd, buf, strlen(buf));
|
||||
close(fd);
|
||||
|
||||
sprintf(buf, "/sys/class/gpio/gpio%d/direction", gpio);
|
||||
fd = open(buf, O_WRONLY);
|
||||
write(fd, "out", 3);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void set_gpio(int gpio, int value)
|
||||
{
|
||||
char buf[255];
|
||||
sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
|
||||
int fd = open(buf, O_WRONLY);
|
||||
sprintf(buf, "%d", value);
|
||||
write(fd, buf, 1);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
extern char *program_invocation_short_name;
|
||||
printf("USAGE:\n");
|
||||
printf(" %s on|off\n", program_invocation_short_name);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int mode;
|
||||
if (!argv[1])
|
||||
{
|
||||
usage();
|
||||
exit(0);
|
||||
}
|
||||
if (strcmp(argv[1],"off")==0) mode = 1;
|
||||
else if (strcmp(argv[1],"on")==0) mode = 0;
|
||||
else { usage(); exit(0); }
|
||||
//printf("Debug %d\r\n",mode);
|
||||
export_gpio(DEBUGEN);
|
||||
set_gpio(DEBUGEN, mode);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user