-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGPIO.c
44 lines (38 loc) · 1.01 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
#include <stdio.h>
#include <string.h>
#include "File.h"
#include "Terminal.h"
#define MAX_SIZE 1024
typedef struct {
char* bbgPinNumber;
int linuxGPIONumber;
char* directionPath;
char* valuePath;
} gpioDevice_t;
static gpioDevice_t gpioDevices[] = {
{"P8.43",
72,
"/sys/class/gpio/gpio72/direction",
"/sys/class/gpio/gpio72/value"
}
};
void GPIO_configurePin(const int INDEX)
{
const char* PIN = gpioDevices[INDEX].bbgPinNumber;
char command[MAX_SIZE];
snprintf(command, MAX_SIZE, "config-pin %s gpio", PIN);
Terminal_runCommand(command);
}
void GPIO_setInput(const int INDEX)
{
FILE* pFile = File_getFilePointer(gpioDevices[INDEX].directionPath, "w", "direction");
fprintf(pFile, "%s", "in");
fclose(pFile);
}
char *GPIO_readValue(const int INDEX) {
char* valuePath = gpioDevices[INDEX].valuePath;
FILE* pFile = File_getFilePointer(valuePath, "r", "value");
char* value = File_extractFileContents(pFile);
fclose(pFile);
return value;
}