-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmuxtable.h
96 lines (85 loc) · 3.45 KB
/
muxtable.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
#include <stdbool.h>
#define DONT_CARE -1
#define INPUT_FUNC true
#define OUTPUT_FUNC false
struct pin_conf{
int pin;
int level;
};
struct conf {
struct pin_conf gpio_pin;
struct pin_conf direction_pin;
struct pin_conf function_pin_1;
struct pin_conf function_pin_2;
};
struct hcsr_muxtable {
int pin;
bool is_interrupt;
bool is_in_use;
struct conf config;
bool function;
};
static struct hcsr_muxtable mux_table[24] = {
{0, true, false, {{11,DONT_CARE},{32,0},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{0, true, false, {{11,DONT_CARE},{32,1},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{1, true, false, {{12,DONT_CARE},{28,0},{45,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{1, true, false, {{12,DONT_CARE},{28,1},{45,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{2, true, false, {{13,DONT_CARE},{34,0},{77,0},{DONT_CARE,DONT_CARE}}, OUTPUT_FUNC},
{2, true, false, {{13,DONT_CARE},{34,1},{77,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{4, true, false, {{6,DONT_CARE},{36,0},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{4, true, false, {{6,DONT_CARE},{36,1},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{5, true, false, {{0,DONT_CARE},{18,0},{66,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{5, true, false, {{0,DONT_CARE},{18,1},{66,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{6, true, false, {{1,DONT_CARE},{20,0},{68,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{6, true, false, {{1,DONT_CARE},{20,1},{68,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{9, true, false, {{4,DONT_CARE},{22,0},{70,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{9, true, false, {{4,DONT_CARE},{22,1},{70,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{10, true, false, {{10,DONT_CARE},{26,0},{74,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{10, true, false, {{10,DONT_CARE},{26,1},{74,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{11, true, false, {{5,DONT_CARE},{24,0},{44,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{11, true, false, {{5,DONT_CARE},{24,1},{44,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{12, true, false, {{15,DONT_CARE},{18,0},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{12, true, false, {{15,DONT_CARE},{18,1},{DONT_CARE,DONT_CARE},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{13, true, false, {{7,DONT_CARE},{30,0},{46,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{13, true, false, {{7,DONT_CARE},{30,1},{46,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC},
{14, true, false, {{48,DONT_CARE},{24,0},{44,0},{DONT_CARE,DONT_CARE}},OUTPUT_FUNC},
{14, true, false, {{48,DONT_CARE},{24,1},{44,0},{DONT_CARE,DONT_CARE}},INPUT_FUNC}
};
void* get_used_pins(int pin, bool function){
int i = 0;
for(i=0;i<24;i++){
if(function == INPUT_FUNC && !mux_table[i].is_interrupt){
continue;
}
if(mux_table[i].pin == pin && mux_table[i].is_in_use && function == mux_table[i].function){
mux_table[i].is_in_use = false;
return (void *)&mux_table[i].config;
}
}
return NULL;
}
bool check_pin(int pin, bool function){
int i = 0;
for(i=0;i<24;i++){
if(function == INPUT_FUNC && !mux_table[i].is_interrupt){
continue;
}
if(mux_table[i].pin == pin && !mux_table[i].is_in_use && function == mux_table[i].function){
return true;
}
}
return false;
}
void* get_pin(int pin, bool function){
int i = 0;
for(i=0;i<24;i++){
if(function == INPUT_FUNC && !mux_table[i].is_interrupt){
continue;
}
if(mux_table[i].pin == pin && !mux_table[i].is_in_use && function == mux_table[i].function){
mux_table[i].is_in_use = true;
return (void *)&mux_table[i].config;
}
}
return NULL;
}