forked from NachiketKelkar/AESD-Project_1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.h
104 lines (87 loc) · 3.38 KB
/
gpio.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
/************************************************************************************************
* File name : gpio.h *
* Authors : Nachiket Kelkar and Puneet Bansal *
* Description : The functions used for gpio operations. Setting the direction of pin and *
* the value. *
* Tools used : GNU make, gcc, gcc-linux-gcc. *
************************************************************************************************/
#include <stdbool.h>
#define total_gpio 5
#define access_pin_allowed {53,54,55,56,60}
/**************** Enumerations used for gpio direction and gpio value ****************/
enum gpio_direction{
in = 0,
out,
};
enum gpio_value{
low = 0,
high,
};
typedef enum{
falling,
rising,
both,
none,
}gpio_interrupt;
/********************** Functions for the gpio operations *********************/
/*
* Function name:- gpio_init
* Description:- The function takes the gpio pin number and assignes it as input pin or
* output pin.
* @param:- int (gpio pin number), int (gpio pin direction)
* @return:- void
* gpio pin direction - 0 for in and 1 for out.
*/
void gpio_init(int,int);
/*
* Function name:- gpio_write_value
* Description:- The function takes the gpio pin number and outputs the pin high or low.
* @param:- int (gpio pin number), int (gpio pin value)
* @return:- void
* gpio pin direction - 0 for in and 1 for out.
*/
void gpio_write_value(int,int);
/*
* Function name:- gpio_read_value
* Description:- The function takes the gpio pin number and returns the value on the pin.
* @param:- int (gpio pin number), int (gpio pin value)
* @return:- int (value high or low)
*/
int gpio_read_value(int);
/*
* Function name:- is_pin_valid
* Description:- The function takes the gpio pin number and returns if valid pin no is entered.
* @param:- int (gpio pin number)
* @return:- bool (true if pin number is valid and false if not)
* gpio pin direction - 0 for in and 1 for out.
* Need to maintain pin values and no of valid pins in above define.
*/
bool is_pin_valid(int);
/*
* Function name:- gpio_interrupt_state
* Description:- The function takes the gpio pin number and sets the gpio interrupt as rising
* falling, both or none based on second parameter.
* @param:- int (gpio pin number), gpio_interrupt (which interrupt);
* @return:- void
* Comments:- gpio_interrupt: can be falling, rising, both or none to disable the interrupts.
* Need to maintain pin values and no of valid pins in above define.
*/
void gpio_interrupt_state(int, gpio_interrupt);
/*
* Function name:- gpio_open_value
* Description:- The function takes the gpio pin number and opens the file and returns the
* file descriptor.
* @param:- int (gpio pin number)
* @return:- int (file descriptor)
* Comments:- Need to maintain pin values and no of valid pins in above define.
*/
int gpio_open_value(int);
/*
* Function name:- gpio_read_val_with_fd
* Description:- The function takes the file descriptior of gpio pin and reurnts the state of the
* pin wether high or low.
* @param:- int (file descriptor)
* @return:- int (pin state)
* Comments:- pin state: Pin state can be high or low.
*/
int gpio_read_val_with_fd(int);