forked from bitbank2/ArmbianIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharmbianio.h
136 lines (116 loc) · 3.27 KB
/
armbianio.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef _ARMBIANIO_H
#define _ARMBIANIO_H
//
// SPI_LCD using the SPI interface
// Copyright (c) 2017 Larry Bank
// email: [email protected]
// Project started 4/25/2017
//
// 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, either version 3 of the License, or
// (at your option) any later version.
//
// 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.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#define GPIO_OUT 0
#define GPIO_IN 1
#define EDGE_FALLING 0
#define EDGE_RISING 1
#define EDGE_BOTH 2
//
// Initialize the library
// 1 = success, 0 = failure
//
int AIOInit(void);
// Free the resources
void AIOShutdown(void);
//
// Returns the name of the board you're running on
// or "Unknown" for an unsupported board
//
const char * AIOGetBoardName(void);
//
// Returns a file handle to the I2C device and address specified
// -1 if it fails to open
//
int AIOOpenI2C(int iChannel, int iAddress);
//
// Returns a file handle to the SPI device specified
// -1 if it fails to open
//
int AIOOpenSPI(int iChannel, int iSpeed);
//
// Close the file handle for the I2C bus
//
void AIOCloseI2C(int iHandle);
//
// Close the file handle for the SPI bus
//
void AIOCloseSPI(int iHandle);
//
// Read bytes from the I2C device
// Pass the "starting" register number
// Returns the number of bytes read or -1 for error
//
int AIOReadI2C(int iHandle, unsigned char ucRegister, unsigned char *buf, int iCount);
//
// Write data to the I2C device starting at the given register
// returns the number of bytes written or -1 for error
//
int AIOWriteI2C(int iHandle, unsigned char ucRegister, unsigned char *buf, int iCount);
//
// Read data from the SPI device
// returns the number of bytes read or -1 for error
//
int AIOReadSPI(int iHandle, unsigned char *buf, int iCount);
//
// Write data to the SPI device
// returns the number of bytes written or -1 for error
//
int AIOWriteSPI(int iHandle, unsigned char *buf, int iCount);
//
// Perform a simultaneous read and write on the SPI device
// returns the number of bytes transferred or -1 for error
//
int AIOReadWriteSPI(int iHandle, unsigned char *inbuf, unsigned char *outbuf, int iCount);
//
// Boolean indicating if the current PCB has a button/key on it
//
int AIOHasButton(void);
//
// Read the button on the PCB (if present)
//
int AIOReadButton(void);
//
// Configure a GPIO pin for input or output
// (GPIO_IN or GPIO_OUT)
//
int AIOAddGPIO(int iPin, int iDirection);
typedef void (*AIOCALLBACK)(int iState);
//
// Configure a GPIO pin to call a function
// when the state changes (interrupt)
//
int AIOAddGPIOCallback(int iPin, int iEdge, AIOCALLBACK callback);
//
// Release a GPIO pin
//
void AIORemoveGPIO(int iPin);
//
// Read the state of a GPIO input pin
// returns 0 or 1
//
int AIOReadGPIO(int iPin);
//
// Sets the state of a GPIO output pin
// Valid states are 1 (on) or 0 (off)
//
int AIOWriteGPIO(int iPin, int iValue);
#endif // _ARMBIANIO_H