OSHW-DEIMOS/SOFTWARE/A64-TERES/teres1-debug/teres1-debug.c

86 lines
1.8 KiB
C
Raw Normal View History

2018-03-14 10:47:47 +01:00
/* 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>
2018-03-14 13:54:59 +01:00
#include <unistd.h>
#include <sys/types.h>
2018-03-14 10:47:47 +01:00
#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);
2018-03-14 13:54:59 +01:00
2018-03-14 10:47:47 +01:00
}
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);
2018-03-14 13:54:59 +01:00
2018-03-14 10:47:47 +01:00
}
void usage(void)
{
extern char *program_invocation_short_name;
printf("USAGE:\n");
2018-03-14 13:54:59 +01:00
printf(" sudo %s on|off\n", program_invocation_short_name);
2018-03-14 10:47:47 +01:00
printf("\n");
}
int main (int argc, char **argv)
{
int mode;
2018-03-14 13:54:59 +01:00
uid_t uid=getuid(), euid=geteuid();
if (uid!=0 || uid!=euid || !argv[1]) {
usage();
2018-03-14 10:47:47 +01:00
exit(0);
2018-03-14 13:54:59 +01:00
}else{
2018-03-14 10:47:47 +01:00
if (strcmp(argv[1],"off")==0) mode = 1;
else if (strcmp(argv[1],"on")==0) mode = 0;
else { usage(); exit(0); }
export_gpio(DEBUGEN);
set_gpio(DEBUGEN, mode);
2018-05-04 07:19:13 +02:00
printf("Debuging via serial cable on headphone port is %s\r\n",argv[1]);
2018-03-14 10:47:47 +01:00
return 0;
}
2018-03-14 13:54:59 +01:00
}