forked from saul-rodriguez/Qtraspberrylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcp23017_isr.cpp
146 lines (109 loc) · 4.34 KB
/
mcp23017_isr.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
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
137
138
139
140
141
142
143
144
145
#include "mcp23017_isr.h"
#include "mcp23017.h"
#include <wiringPi.h>
#include "hardware_conf.h"
Mcp23017* p_extender_1;
Mcp23017* p_extender_2;
Mcp23017* p_extender_3;
/*
* Function: setupMcp23017_isr_1
*-------------------------------
* Configures the interrupt service routine. First, it registers an Mcp23017 object.
* This object will be tied to the interrupt. Then it calls the setISR public function
* which setups the pins that are going to be used as interrupts. This is done by
* using the INTA_PINS constant which should be degined in the hardware_conf.h file.
* Finally, it assings an input pin from the Raspberry to an interrupt function.
* This pin is MCP23017_INTA and must be also defined in hardware_conf.
*/
void setupMcp23017_isr_ext1(Mcp23017* pMcp23017)
{
p_extender_1 = pMcp23017;
p_extender_1->setISR(PORTA,INTA_PINS1); //Only PORTA configured!
p_extender_1->setISR(PORTB,INTB_PINS1); //Only PORTB configured!
//Wire MCP interrupt pin in the raspberry to a function
wiringPiISR(MCP23017_1_INTA, INT_EDGE_FALLING, &extender1_isrA); //Only INTA configured!
wiringPiISR(MCP23017_1_INTB, INT_EDGE_FALLING, &extender1_isrB); //Only INTA configured!
p_extender_1->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_1->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
p_extender_1->porta = p_extender_1->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_1->portb =p_extender_1->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
}
/*
* Function extender1_isrA
* ----------------------
* This function is the interrupt service routing that is triggered when INTA signal
* is activated. It calls the virtual function ISRA.
*/
void extender1_isrA(void)
{
//int change;
p_extender_1->ISRA();
//qDebug("extender1_isr");
//Here glue your logic
}
/*
* Function extender1_isrB
* ----------------------
* This function is the interrupt service routing that is triggered when INTA signal
* is activated. It calls the virtual function ISRB.
*/
void extender1_isrB(void)
{
//int change;
p_extender_1->ISRB();
//qDebug("extender2_isr called");
//Here glue your logic
}
/*
* Extender2
*/
void setupMcp23017_isr_ext2(Mcp23017* pMcp23017)
{
p_extender_2 = pMcp23017;
p_extender_2->setISR(PORTA,INTA_PINS2); //Only PORTA configured!
p_extender_2->setISR(PORTB,INTB_PINS2); //Only PORTB configured!
//Wire MCP interrupt pin in the raspberry to a function
wiringPiISR(MCP23017_2_INTA, INT_EDGE_FALLING, &extender2_isrA); //Only INTA configured!
wiringPiISR(MCP23017_2_INTB, INT_EDGE_FALLING, &extender2_isrB); //Only INTA configured!
p_extender_2->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_2->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
p_extender_2->porta = p_extender_2->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_2->portb =p_extender_2->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
}
void extender2_isrA(void)
{
//int change;
p_extender_2->ISRA();
}
void extender2_isrB(void)
{
//int change;
p_extender_2->ISRB();
}
/*
* Extender3
*/
void setupMcp23017_isr_ext3(Mcp23017* pMcp23017)
{
p_extender_3 = pMcp23017;
p_extender_3->setISR(PORTA,INTA_PINS3); //Only PORTA configured!
p_extender_3->setISR(PORTB,INTB_PINS3); //Only PORTB configured!
//Wire MCP interrupt pin in the raspberry to a function
wiringPiISR(MCP23017_3_INTA, INT_EDGE_FALLING, &extender3_isrA); //Only INTA configured!
wiringPiISR(MCP23017_3_INTB, INT_EDGE_FALLING, &extender3_isrB); //Only INTA configured!
p_extender_3->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_3->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
p_extender_3->porta = p_extender_2->readPort(PORTA); // Dummy read to reset any glitch interrupt during setup
p_extender_3->portb =p_extender_2->readPort(PORTB); // Dummy read to reset any glitch interrupt during setup
}
void extender3_isrA(void)
{
//int change;
p_extender_3->ISRA();
}
void extender3_isrB(void)
{
//int change;
qDebug("EXT 3 INTB called");
p_extender_3->ISRB();
}