-
Notifications
You must be signed in to change notification settings - Fork 6
/
gpioInterface.cpp
64 lines (49 loc) · 1.63 KB
/
gpioInterface.cpp
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
54
55
56
57
58
59
60
61
62
63
64
//============================================================================
// Description : SidBerry wrapper to GPIO ports
// Author : Alessio Lombardo
//============================================================================
#include "gpioInterface.h"
#if BOARD == RASPBERRYPI //Raspberry Pi (GPIO library: <wiringPi.h>)
void gpioWrite(int pin, int level){
digitalWrite(pin, level);
}
int gpioSetup(){
wiringPiSetup();
}
void gpioMode(int pin, int mode){
pinMode(pin, mode);
}
#elif BOARD == ARIETTAG25 //Acme Systems Arietta G25 (GPIO library: <wiringSam.h>)
void gpioWrite(int pin, int level){
if (pin>=0 && pin<32) digitalWrite(WSAM_PIO_A, pin, level);
else if (pin>=32 && pin<64) digitalWrite(WSAM_PIO_B, pin-32, level);
else if (pin>=64 && pin<96) digitalWrite(WSAM_PIO_C, pin-64, level);
}
int gpioSetup(){
wiringSamSetup();
}
void gpioMode(int pin, int mode){
FILE *fp=fopen("/sys/class/gpio/export","w");
fprintf(fp,"%d",pin);
fclose(fp);
if (pin>=0 && pin<32) pinMode(WSAM_PIO_A, pin, mode);
else if (pin>=32 && pin<64) pinMode(WSAM_PIO_B, pin-32, mode);
else if (pin>=64 && pin<96) pinMode(WSAM_PIO_C, pin-64, mode);
}
#elif BOARD == CUSTOM //Custom Board
/*
* Function to WRITE to a GPIO port. Map this function to the equivalent GPIO library function or write it.
*/
void gpioWrite(int pin, int level){
}
/*
* Function to SETUP the GPIO ports. Map this function to the equivalent GPIO library function or write it.
*/
int gpioSetup(){
}
/*
* Function to set the MODE of a GPIO port. Map this function to the equivalent GPIO library function or write it.
*/
void gpioMode(int pin, int mode){
}
#endif