Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / libdragonfly / dragonfly_lib.c @ 774

History | View | Annotate | Download (2.99 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 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
/**
39
 * init_dragonfly - Initializes functions based on configuration parameters
40
 * examples:
41
 *
42
 * init_dragonfly (ALL_ON); - Turns on all basic subsystems. More complex ones that require
43
 *                 their own configuration parameters must still be called on their own.
44
 *
45
 * init_dragonfly (ANALOG | SERIAL | BUZZER); 
46
 * Initialize ADC, USB, XBee, and Buzzer
47
 * 
48
 * init_dragonfly (MOTORS | ORB);
49
 * Initialize the motors and ORB. 
50
 **/
51

    
52
/**
53
 * @defgroup dragonfly Dragonfly
54
 * @brief General Dragonfly Functions
55
 * General functions for the dragonfly. Include
56
 * dragonfly_lib.h to access these functions.
57
 *
58
 * @{
59
 **/
60

    
61
/**
62
 * Initializes the components specified by config. Will turn on interrupts
63
 *         automatically.
64
 *
65
 *         @param config The subsystems that you wish to turn on. Check dragonfly_lib.h for
66
 *                         valid values.
67
 * 
68
 * @see analog_init, usb_init, xbee_init, buzzer_init,
69
 * bom_init, orb_init, motors_init, lcd_init
70
 **/
71
void dragonfly_init(int config) {
72
  sei();
73

    
74
  //Enables the hardware buttons on the board as input pins
75
        //        with internal pullups enabled.
76
        //Pin G0 is button 1
77
        //Pin G1 is button 2
78
        DDRG &= ~(_BV(PING0)|_BV(PING1));
79
  PORTG |= _BV(PING0)|_BV(PING1);
80
        
81
  if(config & ANALOG)
82
    analog_init(ADC_START);
83
        
84
  if(config & COMM) {
85
    //Both default to 115200. Check serial.h for more information.
86
    usb_init();
87
    xbee_init();
88
  }
89
        
90
  if(config & BUZZER) {
91
    buzzer_init();
92
  }
93
        
94
  if(config & ORB) {
95
    orb_init();
96
  }
97
        
98
  if(config & MOTORS)
99
    motors_init();
100

    
101
  if(config & LCD)
102
    lcd_init();
103
   
104
  // delay a bit for stability
105
  _delay_ms(1);
106
}
107

    
108

    
109
/** @} **/ //end defgroup
110