root / trunk / code / lib / src / libdragonfly / dragonfly_lib.c @ 277
History | View | Annotate | Download (2.73 KB)
1 | 276 | emarinel | /**
|
---|---|---|---|
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 dragonfly_lib.c
|
||
29 | * @brief Dragonfly initialization
|
||
30 | *
|
||
31 | * Contains implementation of dragonfly_init.
|
||
32 | *
|
||
33 | * @author Colony Project, CMU Robotics Club
|
||
34 | **/
|
||
35 | |||
36 | #include <dragonfly_lib.h> |
||
37 | |||
38 | /* init_dragonfly - Initializes functions based on configuration parameters
|
||
39 | 277 | emarinel | * examples:
|
40 | *
|
||
41 | * init_dragonfly (0, 0, 0); - just initialize the digital IO (buttons, potentiometer)
|
||
42 | *
|
||
43 | * init_dragonfly (ANALOG | SERIAL | BUZZER, C0_C1_ANALOG, BAUD115200);
|
||
44 | * Initialize ADC and set C0 and C1 as analog inputs. Initialize serial and set baud rate
|
||
45 | * to 115200 bps. Initialize the buzzer.
|
||
46 | *
|
||
47 | * init_dragonfly (MOTORS | ORB, 0, 0);
|
||
48 | * Initialize motor driving and the color fading abilities of the ORB.
|
||
49 | */
|
||
50 | 276 | emarinel | |
51 | /**
|
||
52 | * @defgroup dragonfly Dragonfly
|
||
53 | * @brief General Dragonfly Functions
|
||
54 | * General functions for the dragonfly. Include
|
||
55 | * dragonfly_lib.h to access these functions.
|
||
56 | *
|
||
57 | * @{
|
||
58 | **/
|
||
59 | |||
60 | /**
|
||
61 | * Initializes the components specified by config.
|
||
62 | *
|
||
63 | * @see analog_init, usb_init, xbee_init, buzzer_init,
|
||
64 | * bom_init, orb_init, motors_init, lcd_init
|
||
65 | **/
|
||
66 | void dragonfly_init(int config) |
||
67 | { |
||
68 | 277 | emarinel | // Set directionality of various IO pins
|
69 | DDRG &= ~(_BV(PING0)|_BV(PING1)); |
||
70 | PORTG |= _BV(PING0)|_BV(PING1); |
||
71 | 276 | emarinel | |
72 | 277 | emarinel | if (config & ANALOG) {
|
73 | analog_init(); |
||
74 | } |
||
75 | 276 | emarinel | |
76 | 277 | emarinel | if (config & COMM) {
|
77 | //Defaults to 115200. Check serial.h for more information.
|
||
78 | sei(); |
||
79 | usb_init(); |
||
80 | xbee_init(); |
||
81 | } |
||
82 | 276 | emarinel | |
83 | 277 | emarinel | if (config & BUZZER) {
|
84 | sei(); |
||
85 | buzzer_init(); |
||
86 | } |
||
87 | 276 | emarinel | |
88 | 277 | emarinel | if (config & ORB) {
|
89 | sei(); |
||
90 | orb_init(); |
||
91 | } |
||
92 | 276 | emarinel | |
93 | 277 | emarinel | if (config & MOTORS) {
|
94 | motors_init(); |
||
95 | } |
||
96 | 276 | emarinel | |
97 | 277 | emarinel | if (config & LCD) {
|
98 | lcd_init(); |
||
99 | } |
||
100 | 276 | emarinel | |
101 | 277 | emarinel | // delay a bit for stability
|
102 | _delay_ms(1);
|
||
103 | 276 | emarinel | } |
104 | |||
105 | /** @} **/ //end defgroup |