Revision 1345
Final spline code for master/slave
updated outdated libdragonfly and libwireless
dio.c | ||
---|---|---|
1 |
/* |
|
2 |
dio.c |
|
3 |
*/ |
|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
4 | 25 |
|
26 |
|
|
27 |
/** |
|
28 |
* @file dio.c |
|
29 |
* @brief Digital Input and Output |
|
30 |
* |
|
31 |
* Implementation of functions for digital input and output. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
5 | 36 |
#include <avr/interrupt.h> |
6 | 37 |
#include <dio.h> |
7 | 38 |
#include <time.h> |
... | ... | |
41 | 72 |
* |
42 | 73 |
* @return 1 or 0, depending on the value of the portpin. |
43 | 74 |
**/ |
44 |
int digital_input(int portpin){ |
|
75 |
int digital_input(int portpin) {
|
|
45 | 76 |
int pin = portpin & 0x7; |
46 | 77 |
int pin_val = 0; |
47 | 78 |
|
48 |
switch(portpin >> 3){ |
|
79 |
switch(portpin >> 3) {
|
|
49 | 80 |
case _PORT_A: |
50 | 81 |
DDRA &= ~_BV(pin); |
51 | 82 |
pin_val = PINA; |
... | ... | |
67 | 98 |
pin_val = PINE; |
68 | 99 |
return (pin_val >> pin) & 1; |
69 | 100 |
case _PORT_F: |
70 |
if(pin>=4){ |
|
101 |
if(pin>=4) {
|
|
71 | 102 |
MCUSR|=1<<7; |
72 | 103 |
MCUSR|=1<<7; |
73 | 104 |
} |
... | ... | |
163 | 194 |
PORTG &= (0XFF - _BV(pins)); |
164 | 195 |
break; |
165 | 196 |
} |
166 |
}else { /* ( val == 1) */ |
|
197 |
} else { /* ( val == 1) */
|
|
167 | 198 |
switch(portpin >> 3) { |
168 | 199 |
case _PORT_A: |
169 | 200 |
DDRA |= _BV(pins); |
... | ... | |
204 | 235 |
* |
205 | 236 |
* @see button1_wait, button1_click |
206 | 237 |
**/ |
207 |
int button1_read( void ) |
|
208 |
{ |
|
209 |
int pin_val; |
|
210 |
DDRG &= ~_BV(PING0); |
|
211 |
PORTG|= _BV(PING0); |
|
212 |
pin_val = PING; |
|
213 |
return !((pin_val & _BV(PING0))); |
|
214 |
|
|
238 |
int button1_read( void ) { |
|
239 |
int pin_val; |
|
240 |
DDRG &= ~_BV(PING0); |
|
241 |
PORTG|= _BV(PING0); |
|
242 |
pin_val = PING; |
|
243 |
return !((pin_val & _BV(PING0))); |
|
215 | 244 |
} |
216 | 245 |
|
217 | 246 |
/** |
... | ... | |
219 | 248 |
* |
220 | 249 |
* @see button1_read, button1_click |
221 | 250 |
**/ |
222 |
void button1_wait( void ) |
|
223 |
{ |
|
251 |
void button1_wait( void ) { |
|
224 | 252 |
while(!button1_read() ) { |
225 | 253 |
delay_ms(15); |
226 | 254 |
} |
... | ... | |
234 | 262 |
* |
235 | 263 |
* @see button1_read, button1_wait |
236 | 264 |
**/ |
237 |
int button1_click() |
|
238 |
{ |
|
239 |
if(button1_read()){ |
|
265 |
int button1_click() { |
|
266 |
if(button1_read()) { |
|
240 | 267 |
while(button1_read()); |
241 | 268 |
return 1; |
242 |
}else{
|
|
269 |
} else {
|
|
243 | 270 |
return 0; |
244 | 271 |
} |
245 | 272 |
} |
... | ... | |
251 | 278 |
* |
252 | 279 |
* @see button2_wait, button2_click |
253 | 280 |
**/ |
254 |
int button2_read( void ) |
|
255 |
{ |
|
256 |
int pin_val; |
|
257 |
DDRG &= ~_BV(PING1); |
|
258 |
PORTG|= _BV(PING1); |
|
259 |
pin_val = PING; |
|
260 |
return !((pin_val & _BV(PING1))); |
|
281 |
int button2_read( void ) { |
|
282 |
int pin_val; |
|
283 |
DDRG &= ~_BV(PING1); |
|
284 |
PORTG|= _BV(PING1); |
|
285 |
pin_val = PING; |
|
286 |
return !((pin_val & _BV(PING1))); |
|
261 | 287 |
} |
262 | 288 |
|
263 | 289 |
/** |
... | ... | |
265 | 291 |
* |
266 | 292 |
* @see button2_read, button2_click |
267 | 293 |
**/ |
268 |
void button2_wait( void ) |
|
269 |
{ |
|
294 |
void button2_wait( void ) { |
|
270 | 295 |
while(!button2_read()){ |
271 | 296 |
delay_ms(15); |
272 | 297 |
} |
... | ... | |
280 | 305 |
* |
281 | 306 |
* @see button2_read, button2_wait |
282 | 307 |
**/ |
283 |
int button2_click() |
|
284 |
{ |
|
285 |
if(button2_read()){ |
|
308 |
int button2_click() { |
|
309 |
if(button2_read()) { |
|
286 | 310 |
while(button2_read()); |
287 | 311 |
return 1; |
288 |
}else{
|
|
289 |
return 0;
|
|
312 |
} else {
|
|
313 |
return 0;
|
|
290 | 314 |
} |
291 | 315 |
} |
292 | 316 |
|
Also available in: Unified diff