root / branches / simulator / projects / libdragonfly / include / dio.h @ 891
History | View | Annotate | Download (9.87 KB)
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 |
**/
|
25 |
|
26 |
|
27 |
/**
|
28 |
* @file dio.h
|
29 |
* @brief Definitions for digital input / output
|
30 |
*
|
31 |
* This file contains definitions and functions for dealing
|
32 |
* with digital input and output.
|
33 |
*
|
34 |
* @author Colony Project, CMU Robotics Club
|
35 |
* Based on Tom Lauwer's Firefly Library
|
36 |
**/
|
37 |
|
38 |
#ifndef _DIO_H
|
39 |
#define _DIO_H
|
40 |
|
41 |
/*
|
42 |
these are ALL the pins
|
43 |
don't use unless you know what you're doing
|
44 |
*/
|
45 |
|
46 |
/*
|
47 |
DIO pins on new dragonfly boards are shown below:
|
48 |
-----------------------------------------------
|
49 |
| _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
|
50 |
-----------------------------------------------
|
51 |
| _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
|
52 |
-----------------------------------------------
|
53 |
*/
|
54 |
|
55 |
/** @brief Port A **/
|
56 |
#define _PORT_A 1 |
57 |
/** @brief Port B **/
|
58 |
#define _PORT_B 2 |
59 |
/** @brief Port C **/
|
60 |
#define _PORT_C 3 |
61 |
/** @brief Port D **/
|
62 |
#define _PORT_D 4 |
63 |
/** @brief Port E **/
|
64 |
#define _PORT_E 5 |
65 |
/** @brief Port F **/
|
66 |
#define _PORT_F 6 |
67 |
/** @brief Port G **/
|
68 |
#define _PORT_G 7 |
69 |
|
70 |
/** @brief Pin A0 **/
|
71 |
#define _PIN_A0 8 |
72 |
/** @brief Pin A1 **/
|
73 |
#define _PIN_A1 9 |
74 |
/** @brief Pin A2 **/
|
75 |
#define _PIN_A2 10 |
76 |
/** @brief Pin A3 **/
|
77 |
#define _PIN_A3 11 |
78 |
/** @brief Pin A4 **/
|
79 |
#define _PIN_A4 12 |
80 |
/** @brief Pin A5 **/
|
81 |
#define _PIN_A5 13 |
82 |
/** @brief Pin A6 **/
|
83 |
#define _PIN_A6 14 |
84 |
/** @brief Pin A7 **/
|
85 |
#define _PIN_A7 15 |
86 |
|
87 |
/** @brief Pin B0 **/
|
88 |
#define _PIN_B0 16 |
89 |
/** @brief Pin B1 **/
|
90 |
#define _PIN_B1 17 |
91 |
/** @brief Pin B2 **/
|
92 |
#define _PIN_B2 18 |
93 |
/** @brief Pin B3 **/
|
94 |
#define _PIN_B3 19 |
95 |
/** @brief Pin B4 **/
|
96 |
#define _PIN_B4 20 |
97 |
/** @brief Pin B5 **/
|
98 |
#define _PIN_B5 21 |
99 |
/** @brief Pin B6 **/
|
100 |
#define _PIN_B6 22 |
101 |
/** @brief Pin B7 **/
|
102 |
#define _PIN_B7 23 |
103 |
|
104 |
/** @brief Pin C0 **/
|
105 |
#define _PIN_C0 24 |
106 |
/** @brief Pin C1 **/
|
107 |
#define _PIN_C1 25 |
108 |
/** @brief Pin C2 **/
|
109 |
#define _PIN_C2 26 |
110 |
/** @brief Pin C3 **/
|
111 |
#define _PIN_C3 27 |
112 |
/** @brief Pin C4 **/
|
113 |
#define _PIN_C4 28 |
114 |
/** @brief Pin C5 **/
|
115 |
#define _PIN_C5 29 |
116 |
/** @brief Pin C6 **/
|
117 |
#define _PIN_C6 30 |
118 |
/** @brief Pin C7 **/
|
119 |
#define _PIN_C7 31 |
120 |
|
121 |
/** @brief Pin D0 **/
|
122 |
#define _PIN_D0 32 // pin DIO6 on new dragonfly boards |
123 |
/** @brief Pin D1 **/
|
124 |
#define _PIN_D1 33 // pin DIO7 |
125 |
/** @brief Pin D2 **/
|
126 |
#define _PIN_D2 34 |
127 |
/** @brief Pin D3 **/
|
128 |
#define _PIN_D3 35 |
129 |
/** @brief Pin D4 **/
|
130 |
#define _PIN_D4 36 |
131 |
/** @brief Pin D5 **/
|
132 |
#define _PIN_D5 37 |
133 |
/** @brief Pin D6 **/
|
134 |
#define _PIN_D6 38 |
135 |
/** @brief Pin D7 **/
|
136 |
#define _PIN_D7 39 |
137 |
|
138 |
/** @brief Pin E0 **/
|
139 |
#define _PIN_E0 40 |
140 |
/** @brief Pin E1 **/
|
141 |
#define _PIN_E1 41 |
142 |
/** @brief Pin E2 **/
|
143 |
#define _PIN_E2 42 // pin DIO0 |
144 |
/** @brief Pin E3 **/
|
145 |
#define _PIN_E3 43 // pin DIO1 |
146 |
/** @brief Pin E4 **/
|
147 |
#define _PIN_E4 44 // pin DIO2 |
148 |
/** @brief Pin E5 **/
|
149 |
#define _PIN_E5 45 // pin DIO3 |
150 |
/** @brief Pin E6 **/
|
151 |
#define _PIN_E6 46 // pin DIO4 |
152 |
/** @brief Pin E7 **/
|
153 |
#define _PIN_E7 47 // pin DIO5 |
154 |
|
155 |
/** @brief Pin F0 **/
|
156 |
#define _PIN_F0 48 |
157 |
/** @brief Pin F1 **/
|
158 |
#define _PIN_F1 49 |
159 |
/** @brief Pin F2 **/
|
160 |
#define _PIN_F2 50 |
161 |
/** @brief Pin F3 **/
|
162 |
#define _PIN_F3 51 |
163 |
/** @brief Pin F4 **/
|
164 |
#define _PIN_F4 52 |
165 |
/** @brief Pin F5 **/
|
166 |
#define _PIN_F5 53 |
167 |
/** @brief Pin F6 **/
|
168 |
#define _PIN_F6 54 |
169 |
/** @brief Pin F7 **/
|
170 |
#define _PIN_F7 55 |
171 |
|
172 |
/** @brief Pin G0 **/
|
173 |
#define _PIN_G0 56 |
174 |
/** @brief Pin WR **/
|
175 |
#define _PIN_WR 56 |
176 |
/** @brief Pin G1 **/
|
177 |
#define _PIN_G1 57 |
178 |
/** @brief Pin RD **/
|
179 |
#define _PIN_RD 57 |
180 |
/** @brief Pin G2 **/
|
181 |
#define _PIN_G2 58 |
182 |
/** @brief Pin ALE **/
|
183 |
#define _PIN_ALE 58 |
184 |
/** @brief Pin G3 **/
|
185 |
#define _PIN_G3 59 |
186 |
/** @brief Pin TOSC2 **/
|
187 |
#define _PIN_TOSC2 59 |
188 |
/** @brief Pin G4 **/
|
189 |
#define _PIN_G4 60 |
190 |
/** @brief Pin TOSC1 **/
|
191 |
#define _PIN_TOSC1 60 |
192 |
//#define _PIN_G5 61
|
193 |
//#define _PIN_G6 62
|
194 |
//#define _PIN_G7 63
|
195 |
|
196 |
/*
|
197 |
These are the header pins (the ones you can connect things to)
|
198 |
Feel free to use these
|
199 |
*/
|
200 |
|
201 |
/**
|
202 |
* @defgroup dio Digital Input / Output
|
203 |
* @brief Controls digital input and output
|
204 |
*
|
205 |
* A general note on how port / pin numbers work:<br>
|
206 |
* The portpin is used to select both the bank and which pin is selected.
|
207 |
* 6 bits are used (lower 6, ex: 0b00abcdef).
|
208 |
* The first 3 (abc in this example) are used to select the bank.<br>
|
209 |
* A = 001<br>
|
210 |
* B = 010<br>
|
211 |
* C = 011<br>
|
212 |
* D = 100<br>
|
213 |
* E = 101<br>
|
214 |
* F = 110<br>
|
215 |
* G = 111<br><br>
|
216 |
*
|
217 |
* The bank can be found by doing portpin >> 3. <br>
|
218 |
*
|
219 |
* The next three (def in this example) are used to select the pin number.
|
220 |
* These three bits are just the binary representation of the pin number.<br>
|
221 |
* <br>
|
222 |
* The pin number can be found by doing portpin & 0b111.<br><br>
|
223 |
*
|
224 |
* Include dio.h to access these functions.
|
225 |
**/
|
226 |
/** @brief Pin A0 **/
|
227 |
#define PIN_A0 8 |
228 |
/** @brief Pin A1 **/
|
229 |
#define PIN_A1 9 |
230 |
/** @brief Pin A2 **/
|
231 |
#define PIN_A2 10 |
232 |
/** @brief Pin A3 **/
|
233 |
#define PIN_A3 11 |
234 |
/** @brief Pin A4 **/
|
235 |
#define PIN_A4 12 |
236 |
/** @brief Pin A5 **/
|
237 |
#define PIN_A5 13 |
238 |
/** @brief Pin A6 **/
|
239 |
#define PIN_A6 14 |
240 |
/** @brief Pin A7 **/
|
241 |
#define PIN_A7 15 |
242 |
|
243 |
/** @brief Pin SS **/
|
244 |
#define PIN_SS 16 |
245 |
/** @brief Pin SCK **/
|
246 |
#define PIN_SCK 17 |
247 |
/** @brief Pin MOSI **/
|
248 |
#define PIN_MOSI 18 |
249 |
/** @brief Pin MISO **/
|
250 |
#define PIN_MISO 19 |
251 |
/** @brief LCD Command Pin **/
|
252 |
#define PIN_LCD_COMMAND 20 |
253 |
|
254 |
/** @brief Pin C0 **/
|
255 |
#define PIN_C0 24 |
256 |
/** @brief Pin C1 **/
|
257 |
#define PIN_C1 25 |
258 |
/** @brief Pin C2 **/
|
259 |
#define PIN_C2 26 |
260 |
/** @brief Pin C3 **/
|
261 |
#define PIN_C3 27 |
262 |
/** @brief Pin C4 **/
|
263 |
#define PIN_C4 28 |
264 |
/** @brief Pin C5 **/
|
265 |
#define PIN_C5 29 |
266 |
/** @brief Pin C6 **/
|
267 |
#define PIN_C6 30 |
268 |
/** @brief Pin C7 **/
|
269 |
#define PIN_C7 31 |
270 |
|
271 |
/** @brief Pin SCL **/
|
272 |
#define PIN_SCL 32 |
273 |
/** @brief Pin SDA **/
|
274 |
#define PIN_SDA 33 |
275 |
|
276 |
/** @brief Pin RX0 **/
|
277 |
#define PIN_RX0 40 |
278 |
/** @brief Pin TX0 **/
|
279 |
#define PIN_TX0 41 |
280 |
/** @brief LCD Reset Pin **/
|
281 |
#define PIN_LCD_RESET 42 |
282 |
/** @brief Pin E6 **/
|
283 |
#define PIN_E6 46 |
284 |
/** @brief Pin EXT_DIO1 **/
|
285 |
#define PIN_EXT_DIO1 46 |
286 |
/** @brief Pin E7 **/
|
287 |
#define PIN_E7 47 |
288 |
/** @brief Pin EXT_DIO2 **/
|
289 |
#define PIN_EXT_DIO2 48 |
290 |
|
291 |
/** @brief Pin AN0 **/
|
292 |
#define PIN_AN0 48 |
293 |
/** @brief Pin ADC0 **/
|
294 |
#define PIN_ADC0 48 |
295 |
/** @brief Pin AN1 **/
|
296 |
#define PIN_AN1 49 |
297 |
/** @brief Pin ADC1 **/
|
298 |
#define PIN_ADC1 49 |
299 |
/** @brief Pin AN2 **/
|
300 |
#define PIN_AN2 50 |
301 |
/** @brief Pin ADC2 **/
|
302 |
#define PIN_ADC2 50 |
303 |
/** @brief Pin AN3 **/
|
304 |
#define PIN_AN3 51 |
305 |
/** @brief Pin ADC3 **/
|
306 |
#define PIN_ADC3 51 |
307 |
/** @brief Pin AN4 **/
|
308 |
#define PIN_AN4 52 |
309 |
/** @brief Pin ADC4 **/
|
310 |
#define PIN_ADC4 52 |
311 |
/** @brief Pin AN5 **/
|
312 |
#define PIN_AN5 53 |
313 |
/** @brief Pin ADC5 **/
|
314 |
#define PIN_ADC5 53 |
315 |
/** @brief Pin AN6 **/
|
316 |
#define PIN_AN6 54 |
317 |
/** @brief Pin ADC6 **/
|
318 |
#define PIN_ADC6 54 |
319 |
/** @brief Pin AN7 **/
|
320 |
#define PIN_AN7 55 |
321 |
/** @brief Pin ADC7 **/
|
322 |
#define PIN_ADC7 55 |
323 |
|
324 |
/** @brief Wheel Pin **/
|
325 |
#define PIN_WHEEL 54 |
326 |
/** @brief Battery Voltage Monitor Pin **/
|
327 |
#define PIN_BATT 55 |
328 |
|
329 |
/** @brief button1 Pin **/
|
330 |
#define PIN_BTN1 56 |
331 |
/** @brief button2 Pin **/
|
332 |
#define PIN_BTN2 57 |
333 |
|
334 |
/** @brief LED1 Pin **/
|
335 |
#define PIN_LED1 58 |
336 |
|
337 |
/* Buttons */
|
338 |
/** @brief Button Pin **/
|
339 |
#define PIN_BTN PING
|
340 |
/** @brief button2 Pin **/
|
341 |
#define BTN2 PING1
|
342 |
/** @brief button1 Pin **/
|
343 |
#define BTN1 PING0
|
344 |
|
345 |
/**
|
346 |
* @brief Read a portpin.
|
347 |
*
|
348 |
* Reads the selected portpin.
|
349 |
*
|
350 |
* @param portpin The portpin to be read. See the general description
|
351 |
* for a description of portpins.
|
352 |
*
|
353 |
* @return 1 or 0, depending on the value of the portpin.
|
354 |
**/
|
355 |
int digital_input(int); |
356 |
|
357 |
/**
|
358 |
* @brief Output to a portpin.
|
359 |
*
|
360 |
* Sets portpin to the given value.
|
361 |
*
|
362 |
* @param portpin the portpin to output to. See the general
|
363 |
* description for a discussion of portpins.
|
364 |
*
|
365 |
* @param val the value to set the portpin to. 0 for off,
|
366 |
* nonzero for on.
|
367 |
**/
|
368 |
void digital_output(int bit, int val); |
369 |
|
370 |
/**
|
371 |
* @brief Pullup a portpin.
|
372 |
*
|
373 |
* Enables pullup on a pin. If it is an output pin, the pin will output
|
374 |
* 1.
|
375 |
*
|
376 |
* @param portpin the pin to enable pullup on. See the general description
|
377 |
* for a discussion of portpins.
|
378 |
**/
|
379 |
void digital_pull_up(int); |
380 |
|
381 |
/**
|
382 |
* @brief Check if button1 is pressed.
|
383 |
*
|
384 |
* Checks if button1 is currently pressed.
|
385 |
*
|
386 |
* @return 1 if button1 is pressed, 0 otherwise
|
387 |
*
|
388 |
* @see button1_wait, button1_click
|
389 |
**/
|
390 |
int button1_read( void ); |
391 |
|
392 |
/**
|
393 |
* @brief Check if button1 is clicked.
|
394 |
*
|
395 |
* If button1 is pressed, waits until it is released before returning.
|
396 |
* Otherwise, the function returns immediately.
|
397 |
*
|
398 |
* @return 1 if button1 has been pressed, 0 otherwise
|
399 |
*
|
400 |
* @see button1_read, button1_wait
|
401 |
**/
|
402 |
int button1_click( void ); |
403 |
|
404 |
/**
|
405 |
* @brief Wait until button1 is pressed.
|
406 |
*
|
407 |
* Delays execution until button1 is pressed.
|
408 |
*
|
409 |
* @see button1_read, button1_click
|
410 |
**/
|
411 |
void button1_wait( void ); |
412 |
|
413 |
/**
|
414 |
* @brief Check if button2 is pressed.
|
415 |
*
|
416 |
* Checks if button2 is currently pressed.
|
417 |
*
|
418 |
* @return 1 if button2 is pressed, 0 otherwise
|
419 |
*
|
420 |
* @see button2_wait, button2_click
|
421 |
**/
|
422 |
int button2_read( void ); |
423 |
|
424 |
/**
|
425 |
* Delays execution until button2 is pressed.
|
426 |
*
|
427 |
* @see button2_read, button2_click
|
428 |
**/
|
429 |
int button2_click( void ); |
430 |
|
431 |
/**
|
432 |
* @brief Wait until button2 is pressed.
|
433 |
*
|
434 |
* If button2 is pressed, waits until it is released before returning.
|
435 |
* Otherwise, the function returns immediately.
|
436 |
*
|
437 |
* @return 1 if button2 has been pressed, 0 otherwise
|
438 |
*
|
439 |
* @see button2_read, button2_wait
|
440 |
**/
|
441 |
void button2_wait( void ); |
442 |
|
443 |
/** @} **/ // end addtogroup |
444 |
|
445 |
#endif
|
446 |
|