@@ -23,6 +23,8 @@ THE SOFTWARE.
23
23
24
24
#include " PinChangeInterrupt.h"
25
25
26
+ #ifdef ARDUINO_ARCH_AVR
27
+
26
28
// manually include cpp files here to save flash if only 1 ISR is present
27
29
// or if the user knows he just wants to compile all enabled ports.
28
30
#if defined(PCINT_ALINKAGE) && defined(PCINT_COMPILE_ENABLED_ISR)
@@ -82,167 +84,177 @@ void PinChangeInterruptEventPCINT31(void) __attribute__((weak, alias("pcint_null
82
84
83
85
// useless function for weak implemented/not used functions, extern c needed for the alias
84
86
extern " C" {
85
- void pcint_null_callback (void ) {
86
- // useless
87
- }
87
+ void pcint_null_callback (void )
88
+ {
89
+ // useless
90
+ }
88
91
}
89
92
90
93
// ================================================================================
91
94
// PinChangeInterrupt User Functions
92
95
// ================================================================================
93
96
94
97
// variables to save the last port states and the interrupt settings
95
- uint8_t oldPorts[PCINT_NUM_USED_PORTS] = { 0 };
96
- uint8_t fallingPorts[PCINT_NUM_USED_PORTS] = { 0 };
97
- uint8_t risingPorts[PCINT_NUM_USED_PORTS] = { 0 };
98
+ uint8_t oldPorts[PCINT_NUM_USED_PORTS] = {0 };
99
+ uint8_t fallingPorts[PCINT_NUM_USED_PORTS] = {0 };
100
+ uint8_t risingPorts[PCINT_NUM_USED_PORTS] = {0 };
98
101
99
- void enablePinChangeInterruptHelper (const uint8_t pcintPort, const uint8_t pcintMask, const uint8_t arrayPos){
100
- // Update the old state to the actual state
101
- switch (pcintPort){
102
+ void enablePinChangeInterruptHelper (const uint8_t pcintPort, const uint8_t pcintMask, const uint8_t arrayPos)
103
+ {
104
+ // Update the old state to the actual state
105
+ switch (pcintPort)
106
+ {
102
107
#ifdef PCINT_INPUT_PORT0_USED
103
- case 0 :
104
- oldPorts[arrayPos] = PCINT_INPUT_PORT0;
105
- break ;
108
+ case 0 :
109
+ oldPorts[arrayPos] = PCINT_INPUT_PORT0;
110
+ break ;
106
111
#endif
107
112
#ifdef PCINT_INPUT_PORT1_USED
108
- case 1 :
109
- oldPorts[arrayPos] = PCINT_INPUT_PORT1;
110
- break ;
113
+ case 1 :
114
+ oldPorts[arrayPos] = PCINT_INPUT_PORT1;
115
+ break ;
111
116
#endif
112
117
#ifdef PCINT_INPUT_PORT2_USED
113
- case 2 :
114
- oldPorts[arrayPos] = PCINT_INPUT_PORT2;
115
- break ;
118
+ case 2 :
119
+ oldPorts[arrayPos] = PCINT_INPUT_PORT2;
120
+ break ;
116
121
#endif
117
122
#ifdef PCINT_INPUT_PORT3_USED
118
- case 3 :
119
- oldPorts[arrayPos] = PCINT_INPUT_PORT3;
120
- break ;
123
+ case 3 :
124
+ oldPorts[arrayPos] = PCINT_INPUT_PORT3;
125
+ break ;
121
126
#endif
122
- }
127
+ }
123
128
124
- // Pin change mask registers decide which pins are ENABLE as triggers
129
+ // Pin change mask registers decide which pins are ENABLE as triggers
125
130
#ifdef PCMSK0
126
131
#ifdef PCMSK1
127
- // Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
128
- if (&PCMSK1 - &PCMSK0 == 1 ){
132
+ // Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
133
+ if (&PCMSK1 - &PCMSK0 == 1 )
134
+ {
129
135
#endif
130
- *(&PCMSK0 + pcintPort) |= pcintMask;
136
+ *(&PCMSK0 + pcintPort) |= pcintMask;
131
137
#ifdef PCMSK1
132
- }
133
- else {
134
- switch (pcintPort){
135
- case 0 :
136
- PCMSK0 |= pcintMask;
137
- break ;
138
- case 1 :
139
- PCMSK1 |= pcintMask;
140
- break ;
138
+ }
139
+ else
140
+ {
141
+ switch (pcintPort)
142
+ {
143
+ case 0 :
144
+ PCMSK0 |= pcintMask;
145
+ break ;
146
+ case 1 :
147
+ PCMSK1 |= pcintMask;
148
+ break ;
141
149
#ifdef PCMSK2
142
- case 2 :
143
- PCMSK2 |= pcintMask;
144
- break ;
150
+ case 2 :
151
+ PCMSK2 |= pcintMask;
152
+ break ;
145
153
#endif
146
154
#ifdef PCMSK3
147
- case 3 :
148
- PCMSK3 |= pcintMask;
149
- break ;
155
+ case 3 :
156
+ PCMSK3 |= pcintMask;
157
+ break ;
150
158
#endif
151
- }
152
159
}
160
+ }
153
161
#endif
154
162
#elif defined(PCMSK)
155
- *(&PCMSK + pcintPort) |= pcintMask;
163
+ *(&PCMSK + pcintPort) |= pcintMask;
156
164
#endif
157
165
158
- // PCICR: Pin Change Interrupt Control Register - enables interrupt vectors
166
+ // PCICR: Pin Change Interrupt Control Register - enables interrupt vectors
159
167
#ifdef PCICR
160
- PCICR |= (1 << (pcintPort + PCIE0));
168
+ PCICR |= (1 << (pcintPort + PCIE0));
161
169
#elif defined(GIMSK) && defined(PCIE0) /* e.g. ATtiny X4 */
162
- GIMSK |= (1 << (pcintPort + PCIE0));
163
- #elif defined(GIMSK) && defined(PCIE) /* e.g. ATtiny X5 */
164
- GIMSK |= (1 << (pcintPort + PCIE));
170
+ GIMSK |= (1 << (pcintPort + PCIE0));
171
+ #elif defined(GIMSK) && defined(PCIE) /* e.g. ATtiny X5 */
172
+ GIMSK |= (1 << (pcintPort + PCIE));
165
173
#else
166
174
#error MCU has no such a register
167
175
#endif
168
176
}
169
177
170
- void disablePinChangeInterruptHelper (const uint8_t pcintPort, const uint8_t pcintMask) {
171
- bool disable = false ;
178
+ void disablePinChangeInterruptHelper (const uint8_t pcintPort, const uint8_t pcintMask)
179
+ {
180
+ bool disable = false ;
172
181
#ifdef PCMSK0
173
182
#ifdef PCMSK1
174
- // Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
175
- if (&PCMSK1 - &PCMSK0 == 1 ){
183
+ // Special case for Attinyx4 where PCMSK1 and PCMSK0 are not next to each other
184
+ if (&PCMSK1 - &PCMSK0 == 1 )
185
+ {
176
186
#endif
177
- // disable the mask.
178
- *(&PCMSK0 + pcintPort) &= ~pcintMask;
187
+ // disable the mask.
188
+ *(&PCMSK0 + pcintPort) &= ~pcintMask;
179
189
180
- // if that's the last one, disable the interrupt.
181
- if (*(&PCMSK0 + pcintPort) == 0 )
182
- disable = true ;
190
+ // if that's the last one, disable the interrupt.
191
+ if (*(&PCMSK0 + pcintPort) == 0 )
192
+ disable = true ;
183
193
#ifdef PCMSK1
184
- }
185
- else {
186
- switch (pcintPort){
187
- case 0 :
188
- // disable the mask.
189
- PCMSK0 &= ~pcintMask;
194
+ }
195
+ else
196
+ {
197
+ switch (pcintPort)
198
+ {
199
+ case 0 :
200
+ // disable the mask.
201
+ PCMSK0 &= ~pcintMask;
190
202
191
- // if that's the last one, disable the interrupt.
192
- if (!PCMSK0)
193
- disable = true ;
194
- break ;
195
- case 1 :
196
- // disable the mask.
197
- PCMSK1 &= ~pcintMask;
203
+ // if that's the last one, disable the interrupt.
204
+ if (!PCMSK0)
205
+ disable = true ;
206
+ break ;
207
+ case 1 :
208
+ // disable the mask.
209
+ PCMSK1 &= ~pcintMask;
198
210
199
- // if that's the last one, disable the interrupt.
200
- if (!PCMSK1)
201
- disable = true ;
202
- break ;
211
+ // if that's the last one, disable the interrupt.
212
+ if (!PCMSK1)
213
+ disable = true ;
214
+ break ;
203
215
#ifdef PCMSK2
204
- case 2 :
205
- // disable the mask.
206
- PCMSK2 &= ~pcintMask;
216
+ case 2 :
217
+ // disable the mask.
218
+ PCMSK2 &= ~pcintMask;
207
219
208
- // if that's the last one, disable the interrupt.
209
- if (!PCMSK2)
210
- disable = true ;
211
- break ;
220
+ // if that's the last one, disable the interrupt.
221
+ if (!PCMSK2)
222
+ disable = true ;
223
+ break ;
212
224
#endif
213
225
#ifdef PCMSK3
214
- case 3 :
215
- // disable the mask.
216
- PCMSK3 &= ~pcintMask;
226
+ case 3 :
227
+ // disable the mask.
228
+ PCMSK3 &= ~pcintMask;
217
229
218
- // if that's the last one, disable the interrupt.
219
- if (!PCMSK3)
220
- disable = true ;
221
- break ;
230
+ // if that's the last one, disable the interrupt.
231
+ if (!PCMSK3)
232
+ disable = true ;
233
+ break ;
222
234
#endif
223
- }
224
235
}
236
+ }
225
237
#endif
226
238
#elif defined(PCMSK)
227
- // disable the mask.
228
- *(&PCMSK + pcintPort) &= ~pcintMask;
239
+ // disable the mask.
240
+ *(&PCMSK + pcintPort) &= ~pcintMask;
229
241
230
- // if that's the last one, disable the interrupt.
231
- if (*(&PCMSK + pcintPort) == 0 )
232
- disable = true ;
242
+ // if that's the last one, disable the interrupt.
243
+ if (*(&PCMSK + pcintPort) == 0 )
244
+ disable = true ;
233
245
#endif
234
- if (disable)
235
- {
246
+ if (disable)
247
+ {
236
248
#ifdef PCICR
237
- PCICR &= ~(1 << (pcintPort + PCIE0));
249
+ PCICR &= ~(1 << (pcintPort + PCIE0));
238
250
#elif defined(GIMSK) && defined(PCIE0) /* e.g. ATtiny X4 */
239
- GIMSK &= ~(1 << (pcintPort + PCIE0));
240
- #elif defined(GIMSK) && defined(PCIE) /* e.g. ATtiny X5 */
241
- GIMSK &= ~(1 << (pcintPort + PCIE));
251
+ GIMSK &= ~(1 << (pcintPort + PCIE0));
252
+ #elif defined(GIMSK) && defined(PCIE) /* e.g. ATtiny X5 */
253
+ GIMSK &= ~(1 << (pcintPort + PCIE));
242
254
#else
243
255
#error MCU has no such a register
244
256
#endif
245
- }
257
+ }
246
258
}
247
259
248
260
/*
@@ -325,3 +337,5 @@ pop r1
325
337
reti
326
338
}
327
339
*/
340
+
341
+ #endif
0 commit comments