Revision 322
Copied new analog code into recharging branch.
branches/autonomous_recharging/code/projects/libdragonfly/lights.h | ||
---|---|---|
1 | 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 |
/** |
|
2 | 28 |
* @file lights.h |
3 | 29 |
* @brief Contains declarations for managing the orbs. |
4 | 30 |
* |
branches/autonomous_recharging/code/projects/libdragonfly/motor.c | ||
---|---|---|
1 |
/* |
|
2 |
motor.c - Contains functions necessary for activating and driving the |
|
3 |
H-bridge |
|
4 |
|
|
5 |
|
|
6 |
author: Robotics Club, Colony project |
|
7 |
|
|
8 |
much of this is taken from FWR's library, author: Tom Lauwers |
|
9 |
|
|
10 |
*/ |
|
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 |
**/ |
|
11 | 25 |
|
26 |
|
|
27 |
/** |
|
28 |
* @file motor.c |
|
29 |
* @brief Motors |
|
30 |
* |
|
31 |
* Implementation of functions for controlling the motors. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
* Much of this is taken from FWR's library, author: Tom Lauwers |
|
35 |
**/ |
|
36 |
|
|
12 | 37 |
#include "motor.h" |
13 | 38 |
|
14 | 39 |
/** |
branches/autonomous_recharging/code/projects/libdragonfly/motor.h | ||
---|---|---|
1 | 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 |
/** |
|
2 | 28 |
* @file motor.h |
3 | 29 |
* @brief Contains definitions for controlling the motors |
4 | 30 |
* |
branches/autonomous_recharging/code/projects/libdragonfly/dragonfly_lib.c | ||
---|---|---|
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 |
|
|
1 | 36 |
#include <dragonfly_lib.h> |
2 | 37 |
|
3 | 38 |
/* init_dragonfly - Initializes functions based on configuration parameters |
... | ... | |
29 | 64 |
**/ |
30 | 65 |
void dragonfly_init(int config) |
31 | 66 |
{ |
67 |
sei(); |
|
68 |
|
|
32 | 69 |
// Set directionality of various IO pins |
33 | 70 |
DDRG &= ~(_BV(PING0)|_BV(PING1)); |
34 | 71 |
PORTG |= _BV(PING0)|_BV(PING1); |
35 | 72 |
|
36 |
if(config & ANALOG) { |
|
37 |
analog_init(); |
|
38 |
} |
|
73 |
if(config & ANALOG) |
|
74 |
analog_init(ADC_START); |
|
39 | 75 |
|
40 |
if(config & COMM) {
|
|
41 |
//Defaults to 115200. Check serial.h for more information.
|
|
42 |
sei();
|
|
43 |
usb_init();
|
|
44 |
xbee_init();
|
|
76 |
if(config & COMM) |
|
77 |
{
|
|
78 |
//Defaults to 115200. Check serial.h for more information.
|
|
79 |
usb_init();
|
|
80 |
xbee_init();
|
|
45 | 81 |
} |
46 | 82 |
|
47 |
if(config & BUZZER) { |
|
48 |
sei(); |
|
83 |
if(config & BUZZER) |
|
84 |
{ |
|
85 |
sei(); |
|
49 | 86 |
buzzer_init(); |
50 | 87 |
} |
51 | 88 |
|
52 |
if(config & ORB) { |
|
53 |
sei(); |
|
89 |
if(config & ORB) |
|
90 |
{ |
|
91 |
sei(); |
|
54 | 92 |
orb_init(); |
55 | 93 |
} |
56 | 94 |
|
57 |
if(config & MOTORS) {
|
|
95 |
if(config & MOTORS) |
|
58 | 96 |
motors_init(); |
59 |
} |
|
60 |
|
|
61 |
if(config & SERVOS) { |
|
62 |
sei(); |
|
63 |
//Servos not yet implemented |
|
64 |
//servo_init(); |
|
65 |
} |
|
66 | 97 |
|
67 |
if(config & LCD) {
|
|
98 |
if(config & LCD) |
|
68 | 99 |
lcd_init(); |
69 |
} |
|
70 | 100 |
|
71 |
if(config & (SERVOS | ORB)) {
|
|
72 |
sei();
|
|
73 |
orb_init();
|
|
74 |
//Servos not yet implemented
|
|
101 |
if(config & ORB)
|
|
102 |
{
|
|
103 |
sei();
|
|
104 |
orb_init();
|
|
75 | 105 |
} |
76 | 106 |
|
77 | 107 |
// delay a bit for stability |
branches/autonomous_recharging/code/projects/libdragonfly/i2c.c | ||
---|---|---|
1 |
/* @file i2c.c |
|
2 |
* @brief |
|
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 i2c.c |
|
29 |
* @brief Implemenation of I2C communications protocol |
|
30 |
* |
|
3 | 31 |
* In the case where you have master sends and then a master request to the same |
4 | 32 |
* address, you will not give up control of the line because the send and |
5 | 33 |
* request addresses are seen as different addresses. In between it will send a |
... | ... | |
73 | 101 |
* from the master |
74 | 102 |
* @param slave_send The address of the function to call when you are a slave and the master |
75 | 103 |
* requests data from you. |
104 |
* |
|
105 |
* @return 0 for success, nonzero for failure |
|
76 | 106 |
**/ |
77 | 107 |
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send) { |
78 | 108 |
master_recv_function = master_recv; |
... | ... | |
105 | 135 |
* @param data The pointer to the byte array of data |
106 | 136 |
* @param bytes The amount of bytes long that the byte array is. This is how |
107 | 137 |
* many bytes from the array that the function will send. |
138 |
* |
|
139 |
* @return zero for success, nonzero for failure |
|
108 | 140 |
**/ |
109 | 141 |
int i2c_send(char dest, char *data, size_t bytes) { |
110 | 142 |
int i; |
... | ... | |
144 | 176 |
* to send it. |
145 | 177 |
* |
146 | 178 |
* @param dest The destination that we want to receive information from. |
179 |
* |
|
180 |
* @return 0 for success, nonzero for failure |
|
147 | 181 |
**/ |
148 | 182 |
int i2c_request(char dest) { |
149 | 183 |
if(RING_BUFFER_FULL(i2c_write_buff)) |
... | ... | |
160 | 194 |
|
161 | 195 |
return 0; |
162 | 196 |
} |
197 |
|
|
198 |
/** @} **/ |
|
163 | 199 |
|
164 | 200 |
/** |
165 | 201 |
* @brief Interrupt to handle I2C interrupts from the I2C hardware. |
... | ... | |
175 | 211 |
* |
176 | 212 |
* Errors are handled here as well. |
177 | 213 |
**/ |
178 |
/* @} */ |
|
179 | 214 |
ISR(TWI_vect) { |
180 | 215 |
static char data_to_send; |
181 | 216 |
static char addr_to_send = -1; |
... | ... | |
307 | 342 |
/* Toggle TWINT so that it resets and executes the commands */ |
308 | 343 |
TWCR |= _BV(TWINT); |
309 | 344 |
} |
345 |
|
branches/autonomous_recharging/code/projects/libdragonfly/serial.c | ||
---|---|---|
1 |
/* |
|
2 |
serial.c - Functions for using the RS232 serial port |
|
3 |
|
|
4 |
authors: Robotics Club, Colony Project, pkv |
|
5 |
much code taken from FWR's library, author: Tom Lauwers |
|
6 |
*/ |
|
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 |
**/ |
|
7 | 25 |
|
26 |
|
|
27 |
/** |
|
28 |
* @file serial.c |
|
29 |
* @brief Serial Input and Output |
|
30 |
* |
|
31 |
* Implementation of functions for serial input and output. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
8 | 36 |
#include <avr/io.h> |
9 | 37 |
#include <stdio.h> |
10 | 38 |
#include "serial.h" |
... | ... | |
140 | 168 |
**/ |
141 | 169 |
int usb_getc(void) |
142 | 170 |
{ |
143 |
// Wait for the receive buffer to be filled
|
|
144 |
loop_until_bit_is_set(UCSR0A, RXC0);
|
|
171 |
// Wait for the receive buffer to be filled
|
|
172 |
loop_until_bit_is_set(UCSR0A, RXC0);
|
|
145 | 173 |
|
146 | 174 |
// Read the receive buffer |
147 | 175 |
return UDR0; |
branches/autonomous_recharging/code/projects/libdragonfly/dragonfly_lib.h | ||
---|---|---|
1 |
/** |
|
2 |
* @file dragonfly_lib.h |
|
3 |
* @brief Contains other include files |
|
4 |
* |
|
5 |
* Include this file for all the functionality of libdragonfly. |
|
6 |
* |
|
7 |
* @author Colony Project, CMU Robotics Club |
|
8 |
**/ |
|
9 |
|
|
10 |
#ifndef _DRAGONFLY_LIB_H_ |
|
11 |
#define _DRAGONFLY_LIB_H_ |
|
12 |
|
|
13 |
/** |
|
14 |
* @addtogroup dragonfly |
|
15 |
* @{ |
|
16 |
**/ |
|
17 |
|
|
18 |
// Configuration definitions |
|
19 |
/** @brief Initialize analog **/ |
|
20 |
#define ANALOG 0x01 |
|
21 |
/** @brief Initialize serial communications **/ |
|
22 |
#define SERIAL 0x02 |
|
23 |
/** @brief Initialize USB communications **/ |
|
24 |
#define USB 0x02 |
|
25 |
/** @brief Initialize communications **/ |
|
26 |
#define COMM 0x02 |
|
27 |
/** @brief Initialize the orb **/ |
|
28 |
#define ORB 0x04 |
|
29 |
/** @brief Initialize the motors **/ |
|
30 |
#define MOTORS 0x08 |
|
31 |
/** @brief Initialize the servos **/ |
|
32 |
#define SERVOS 0x10 |
|
33 |
/** @brief Initialize I2C **/ |
|
34 |
#define I2C 0x20 |
|
35 |
/** @brief Initialize the buzzer **/ |
|
36 |
#define BUZZER 0x40 |
|
37 |
/** @brief Initialize the LCD screen **/ |
|
38 |
#define LCD 0x80 |
|
39 |
/** @brief Initialize everything **/ |
|
40 |
#define ALL_ON 0xFF |
|
41 |
|
|
42 |
|
|
43 |
/** @brief Initialize the board **/ |
|
44 |
void dragonfly_init(int config); |
|
45 |
|
|
46 |
/** @} **/ //end addtogroup |
|
47 |
|
|
48 |
#include <inttypes.h> |
|
49 |
#include <stdio.h> |
|
50 |
#include <stdlib.h> |
|
51 |
#include <avr/io.h> |
|
52 |
#include <avr/interrupt.h> |
|
53 |
#include <util/delay.h> |
|
54 |
#include <util/twi.h> |
|
55 |
|
|
56 |
#include <analog.h> |
|
57 |
#include <dio.h> |
|
58 |
#include <time.h> |
|
59 |
#include <lcd.h> |
|
60 |
#include <lights.h> |
|
61 |
#include <motor.h> |
|
62 |
#include <serial.h> |
|
63 |
#include <buzzer.h> |
|
64 |
#include <rangefinder.h> |
|
65 |
#include <bom.h> |
|
66 |
#include <move.h> |
|
67 |
#include <reset.h> |
|
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.h |
|
29 |
* @brief Contains other include files |
|
30 |
* |
|
31 |
* Include this file for all the functionality of libdragonfly. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
36 |
#ifndef _DRAGONFLY_LIB_H_ |
|
37 |
#define _DRAGONFLY_LIB_H_ |
|
38 |
|
|
39 |
/** |
|
40 |
* @addtogroup dragonfly |
|
41 |
* @{ |
|
42 |
**/ |
|
43 |
|
|
44 |
// Configuration definitions |
|
45 |
/** @brief Initialize analog **/ |
|
46 |
#define ANALOG 0x01 |
|
47 |
/** @brief Initialize serial communications **/ |
|
48 |
#define SERIAL 0x02 |
|
49 |
/** @brief Initialize USB communications **/ |
|
50 |
#define USB 0x02 |
|
51 |
/** @brief Initialize communications **/ |
|
52 |
#define COMM 0x02 |
|
53 |
/** @brief Initialize the orb **/ |
|
54 |
#define ORB 0x04 |
|
55 |
/** @brief Initialize the motors **/ |
|
56 |
#define MOTORS 0x08 |
|
57 |
/** @brief Initialize I2C **/ |
|
58 |
#define I2C 0x20 |
|
59 |
/** @brief Initialize the buzzer **/ |
|
60 |
#define BUZZER 0x40 |
|
61 |
/** @brief Initialize the LCD screen **/ |
|
62 |
#define LCD 0x80 |
|
63 |
/** @brief Initialize everything **/ |
|
64 |
#define ALL_ON 0xFF |
|
65 |
|
|
66 |
|
|
67 |
/** @brief Initialize the board **/ |
|
68 |
void dragonfly_init(int config); |
|
69 |
|
|
70 |
/** @} **/ //end addtogroup |
|
71 |
|
|
72 |
#include <inttypes.h> |
|
73 |
#include <stdio.h> |
|
74 |
#include <stdlib.h> |
|
75 |
#include <avr/io.h> |
|
76 |
#include <avr/interrupt.h> |
|
77 |
#include <util/delay.h> |
|
78 |
#include <util/twi.h> |
|
79 |
|
|
80 |
#include <analog.h> |
|
81 |
#include <dio.h> |
|
82 |
#include <time.h> |
|
83 |
#include <lcd.h> |
|
84 |
#include <lights.h> |
|
85 |
#include <motor.h> |
|
86 |
#include <serial.h> |
|
87 |
#include <buzzer.h> |
|
88 |
#include <rangefinder.h> |
|
89 |
#include <bom.h> |
|
90 |
#include <move.h> |
|
91 |
#include <reset.h> |
|
68 | 92 |
#include <math.h> |
69 |
|
|
70 |
#endif |
|
71 |
|
|
93 |
|
|
94 |
#endif |
|
95 |
|
branches/autonomous_recharging/code/projects/libdragonfly/buzzer.c | ||
---|---|---|
1 |
/* |
|
2 |
buzzer.c - Contains the functions necessary for running the buzzer |
|
3 |
|
|
4 |
author: Robotics Club, Colony Project |
|
5 |
|
|
6 |
much taken from FWR's firefly library (author: Tom Lauwers) |
|
7 |
*/ |
|
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 |
**/ |
|
8 | 25 |
|
26 |
|
|
27 |
/** |
|
28 |
* @file buzzer |
|
29 |
* @brief Functions for using the buzzer |
|
30 |
* |
|
31 |
* Contains functions for using the buzzer. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
* |
|
35 |
* much taken from FWR's firefly library (author: Tom Lauwers) |
|
36 |
**/ |
|
37 |
|
|
9 | 38 |
#include <avr/io.h> |
10 | 39 |
#include <buzzer.h> |
11 | 40 |
#include <time.h> |
branches/autonomous_recharging/code/projects/libdragonfly/i2c.h | ||
---|---|---|
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 |
|
|
1 | 27 |
/** @file i2c.h |
2 | 28 |
* @brief Header file for I2C |
3 | 29 |
* |
4 |
* @author CMU Robotics Club, Kevin Woo, Suresh Nidhiry |
|
5 |
*/ |
|
30 |
* Contains functions for I2C. |
|
31 |
* |
|
32 |
* @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club |
|
33 |
**/ |
|
6 | 34 |
|
7 | 35 |
|
8 | 36 |
#ifndef _I2C_H_ |
... | ... | |
10 | 38 |
|
11 | 39 |
#include <stddef.h> |
12 | 40 |
|
13 |
/** @brief Address of slave receive handler function */ |
|
41 |
/** @brief Address of slave receive handler function **/
|
|
14 | 42 |
typedef void (*fun_srecv_t)(char); |
15 | 43 |
|
16 |
/** @brief Address of master receive handler function*/ |
|
44 |
/** @brief Address of master receive handler function**/
|
|
17 | 45 |
typedef int (*fun_mrecv_t)(char); |
18 | 46 |
|
19 |
/** @brief Address of slave send handler function*/ |
|
47 |
/** @brief Address of slave send handler function**/
|
|
20 | 48 |
typedef char (*fun_send_t)(void); |
21 | 49 |
|
22 | 50 |
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send); |
... | ... | |
26 | 54 |
void i2c_packet_rec (char i2c_byte); |
27 | 55 |
void i2c_packet_sniff(char data); |
28 | 56 |
#endif |
57 |
|
branches/autonomous_recharging/code/projects/libdragonfly/serial.h | ||
---|---|---|
1 | 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 |
/** |
|
2 | 28 |
* @file serial.h |
3 | 29 |
* @brief Contains declarations for serial input and output |
4 | 30 |
* |
branches/autonomous_recharging/code/projects/libdragonfly/buzzer.h | ||
---|---|---|
1 | 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 |
/** |
|
2 | 28 |
* @file buzzer.h |
3 | 29 |
* @brief Contains definitions for using the buzzer. |
4 | 30 |
* |
branches/autonomous_recharging/code/projects/libdragonfly/math.c | ||
---|---|---|
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 math.c |
|
29 |
* @brief Math Functions |
|
30 |
* |
|
31 |
* Useful math functions. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
1 | 36 |
#include "math.h" |
2 | 37 |
|
3 | 38 |
/** |
... | ... | |
23 | 58 |
} |
24 | 59 |
|
25 | 60 |
/**@}**/ //end defgroup |
61 |
|
branches/autonomous_recharging/code/projects/libdragonfly/math.h | ||
---|---|---|
1 | 1 |
/** |
2 |
* Copyright (c) 2007 Colony Project |
|
2 | 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 |
* |
|
3 | 29 |
* @file math.h |
4 | 30 |
* @brief Contains math function(s) |
5 | 31 |
* |
... | ... | |
20 | 46 |
/**@}**/ //end group |
21 | 47 |
|
22 | 48 |
#endif |
49 |
|
branches/autonomous_recharging/code/projects/libdragonfly/time.c | ||
---|---|---|
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 time.c |
|
29 |
* @brief Timer code |
|
30 |
* |
|
31 |
* Implementation of functions for timers. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
1 | 36 |
/* |
2 | 37 |
time.c |
3 | 38 |
anything that requires a delay |
branches/autonomous_recharging/code/projects/libdragonfly/analog.c | ||
---|---|---|
1 |
/* |
|
2 |
* analog.c - Contains the function implementations for manipulating the ADC |
|
3 |
* on the firefly+ board |
|
4 |
* |
|
5 |
* author: CMU Robotics Club, Colony Project |
|
6 |
* code mostly taken from fwr analog file (author: Tom Lauwers) |
|
7 |
*/ |
|
8 |
|
|
9 |
#include <util/delay.h> |
|
10 |
#include <avr/interrupt.h> |
|
11 |
#include "analog.h" |
|
12 |
|
|
13 |
// Internal Function Prototypes |
|
14 |
void set_adc_mux(int which); |
|
15 |
|
|
16 |
/** |
|
17 |
* @defgroup analog Analog |
|
18 |
* Functions for manipulation the ADC on the dragonfly board. |
|
19 |
* All definitions may be found in analog.h. |
|
20 |
* |
|
21 |
* @{ |
|
22 |
**/ |
|
23 |
|
|
24 |
|
|
25 |
/** |
|
26 |
* Initializes the ADC. |
|
27 |
* Call analog_init before reading from the analog ports. |
|
28 |
* |
|
29 |
* @see analog8, analog10 |
|
30 |
**/ |
|
31 |
void analog_init(void) |
|
32 |
{ |
|
33 |
// ADC Status Register A |
|
34 |
// Bit 7 - ADEN is set (enables analog) |
|
35 |
// Bit 6 - Start conversion bit is set (must be done once for free-running mode) |
|
36 |
// Bit 5 - Enable Auto Trigger (for free running mode) |
|
37 |
// Bit 4 - ADC interrupt flag, 0 |
|
38 |
// Bit 3 - Enable ADC Interrupt (required to run free-running mode) |
|
39 |
// Bits 2-0 - Set to create a clock divisor of 128, to make ADC clock = 8,000,000/128 |
|
40 |
ADCSRA |= 0xEF; |
|
41 |
|
|
42 |
// ADC Status Register B |
|
43 |
// Bit 7, 5-3 - Must be cleared |
|
44 |
// Bit 2:0 - Set mode, currently cleared for free running operation |
|
45 |
// Bit 6 - Analog comparator mode - cleared |
|
46 |
// ADCSRB = 0x00; |
|
47 |
|
|
48 |
// ADMUX register |
|
49 |
// Bit 7,6 - Set voltage reference to AVcc (0b01) |
|
50 |
// Bit 5 - Set ADLAR bit for left adjust to do simple 8-bit reads |
|
51 |
// Bit 4 - X |
|
52 |
// Bit 3:0 - Sets the current channel, set to ADC7 (the external mux) |
|
53 |
ADMUX = 0x67; |
|
54 |
|
|
55 |
// Set external mux lines to outputs |
|
56 |
DDRG |= 0x1C; |
|
57 |
set_adc_mux(0x07); |
|
58 |
} |
|
59 |
|
|
60 |
|
|
61 |
/** |
|
62 |
* Reads an eight bit number from an analog port. |
|
63 |
* analog_init must be called before using this function. |
|
64 |
* |
|
65 |
* @param which the analog port to read from. One of |
|
66 |
* the constants AN0 - AN7. |
|
67 |
* |
|
68 |
* @return the eight bit input to the specified port |
|
69 |
* |
|
70 |
* @see analog_init, analog10 |
|
71 |
**/ |
|
72 |
unsigned int analog8(int which) |
|
73 |
{ |
|
74 |
if(which < EXT_MUX) |
|
75 |
ADMUX = 0x60 + which; |
|
76 |
else if(which == EXT_MUX) |
|
77 |
return 0; |
|
78 |
else |
|
79 |
{ |
|
80 |
ADMUX = 0x60 + EXT_MUX; |
|
81 |
set_adc_mux(which - 8); |
|
82 |
_delay_ms(1); |
|
83 |
} |
|
84 |
|
|
85 |
_delay_ms(1); // need at least 130 us between conversions |
|
86 |
return ADCH; |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Reads a ten bit number from the specified port. |
|
91 |
* analog_init must be called before using this function. |
|
92 |
* |
|
93 |
* @param which the analog port to read from. Typically |
|
94 |
* a constant, one of AN0 - AN7. |
|
95 |
* |
|
96 |
* @return the ten bit number input to the specified port |
|
97 |
* |
|
98 |
* @see analog_init, analog8 |
|
99 |
**/ |
|
100 |
unsigned int analog10(int which) |
|
101 |
{ |
|
102 |
unsigned int adc_h = 0; |
|
103 |
unsigned int adc_l = 0; |
|
104 |
|
|
105 |
if(which < EXT_MUX) |
|
106 |
ADMUX = 0x60 + which; |
|
107 |
else if(which == EXT_MUX) |
|
108 |
return 0; |
|
109 |
else |
|
110 |
{ |
|
111 |
ADMUX = 0x60 + EXT_MUX; |
|
112 |
set_adc_mux(which - 8); |
|
113 |
_delay_ms(1); |
|
114 |
} |
|
115 |
|
|
116 |
_delay_ms(1); |
|
117 |
adc_l = ADCL; /* highest 2 bits of ADCL -> least 2 bits of analog val */ |
|
118 |
adc_h = ADCH; /* ADCH -> 8 highest bits of analog val */ |
|
119 |
|
|
120 |
return (adc_h << 2) | (adc_l >> 6); |
|
121 |
} |
|
122 |
|
|
123 |
/** |
|
124 |
* Returns the current position of the wheel, as an integer |
|
125 |
* in the range 0 - 255. |
|
126 |
* analog_init must be called before using this function. |
|
127 |
* |
|
128 |
* @return the orientation of the wheel, as an integer in |
|
129 |
* the range 0 - 255. |
|
130 |
* |
|
131 |
* @see analog_init |
|
132 |
**/ |
|
133 |
int wheel(void) |
|
134 |
{ |
|
135 |
return analog8(WHEEL_PORT); |
|
136 |
} |
|
137 |
|
|
138 |
/**@}**/ //end defgroup |
|
139 |
|
|
140 |
SIGNAL (SIG_ADC) |
|
141 |
{ |
|
142 |
// This is just here to catch ADC interrupts because ADC is free running. |
|
143 |
// No code needs to be in here. |
|
144 |
} |
|
145 |
|
|
146 |
void set_adc_mux(int which) |
|
147 |
{ |
|
148 |
// FIX THIS IN NEXT REVISION |
|
149 |
// ADDR2 ADDR1 ADDR0 |
|
150 |
// G2.G4.G3 set mux to port 0-7 via binary selection |
|
151 |
// math would be much cleaner if it was G4.G3.G2 |
|
152 |
|
|
153 |
// mask so only proper bits are possible. |
|
154 |
PORTG = (PORTG & 0xE3) | ((which & 0x03) << 3) | (which & 0x04); |
|
155 |
} |
|
156 |
|
|
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 |
* @file analog.c |
|
28 |
* @brief Analog input and output |
|
29 |
* |
|
30 |
* Contains functions for manipulating the ADC on the Dragonfly board. |
|
31 |
* |
|
32 |
* @author Colony Project, CMU Robotics Club |
|
33 |
* code mostly taken from fwr analog file (author: Tom Lauwers) |
|
34 |
**/ |
|
35 |
|
|
36 |
#include <util/delay.h> |
|
37 |
#include <avr/interrupt.h> |
|
38 |
#include "analog.h" |
|
39 |
#include "serial.h" |
|
40 |
// Internal Function Prototypes |
|
41 |
void set_adc_mux(int which); |
|
42 |
|
|
43 |
/** @brief Struct to hold the value of a particular analog port */ |
|
44 |
typedef struct { |
|
45 |
uint8_t adc8; |
|
46 |
uint16_t adc10; |
|
47 |
} adc_t; |
|
48 |
|
|
49 |
/** |
|
50 |
* @defgroup analog Analog |
|
51 |
* Functions for manipulation the ADC on the dragonfly board. |
|
52 |
* All definitions may be found in analog.h. |
|
53 |
* |
|
54 |
* @{ |
|
55 |
**/ |
|
56 |
|
|
57 |
int adc_loop_running = 0; |
|
58 |
int adc_current_port = AN1; |
|
59 |
adc_t an_val[11]; |
|
60 |
|
|
61 |
/** |
|
62 |
* Initializes the ADC. |
|
63 |
* Call analog_init before reading from the analog ports. |
|
64 |
* |
|
65 |
* @see analog8, analog10 |
|
66 |
**/ |
|
67 |
void analog_init(int start_conversion) |
|
68 |
{ |
|
69 |
for (int i = 0; i < 11; i++) { |
|
70 |
an_val[i].adc10 = 0; |
|
71 |
an_val[i].adc8 = 0; |
|
72 |
} |
|
73 |
|
|
74 |
//cli(); |
|
75 |
// ADMUX register |
|
76 |
// Bit 7,6 - Set voltage reference to AVcc (0b01) |
|
77 |
// Bit 5 - ADLAR set to simplify moving from register |
|
78 |
// Bit 4 - X |
|
79 |
// Bit 3:0 - Sets the current channel |
|
80 |
// Initializes to read from AN1 first (AN0 is reservered for the BOM) |
|
81 |
ADMUX = 0; |
|
82 |
ADMUX |= ADMUX_OPT | _BV(MUX0); |
|
83 |
|
|
84 |
|
|
85 |
// ADC Status Register A |
|
86 |
// Bit 7 - ADEN is set (enables analog) |
|
87 |
// Bit 6 - Start conversion bit is set (must be done once for free-running mode) |
|
88 |
// Bit 5 - Enable Auto Trigger (for free running mode) NOT DOING THIS RIGHT NOW |
|
89 |
// Bit 4 - ADC interrupt flag, 0 |
|
90 |
// Bit 3 - Enable ADC Interrupt (required to run free-running mode) |
|
91 |
// Bits 2-0 - Set to create a clock divisor of 128, to make ADC clock = 8,000,000/64 = 125kHz |
|
92 |
ADCSRA = 0; |
|
93 |
ADCSRA |= _BV(ADEN) | _BV(ADIE) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); |
|
94 |
|
|
95 |
// Set external mux lines to outputs |
|
96 |
DDRG |= 0x1C; |
|
97 |
|
|
98 |
// Set up first port for conversions |
|
99 |
set_adc_mux(0x00); |
|
100 |
adc_current_port = AN1; |
|
101 |
|
|
102 |
//Start the conversion if requested |
|
103 |
if (start_conversion) |
|
104 |
analog_start_loop(); |
|
105 |
else |
|
106 |
analog_stop_loop(); |
|
107 |
//sei(); |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
unsigned int analog8(int which) { |
|
112 |
if (which == BOM_PORT) { |
|
113 |
return 0; |
|
114 |
} else { |
|
115 |
return an_val[which - 1].adc8; |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
unsigned int analog10(int which) { |
|
120 |
if (which == BOM_PORT) { |
|
121 |
return 0; |
|
122 |
} else { |
|
123 |
return an_val[which - 1].adc10; |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
void analog_start_loop(void) { |
|
128 |
//Start the conversion |
|
129 |
ADCSRA |= _BV(ADSC); |
|
130 |
adc_loop_running = 0x1; |
|
131 |
} |
|
132 |
|
|
133 |
//will stop after current conversion finishes |
|
134 |
void analog_stop_loop(void) { |
|
135 |
//Stop the conversion |
|
136 |
adc_loop_running = 0x0; |
|
137 |
} |
|
138 |
/** |
|
139 |
* Reads an eight bit number from an analog port. |
|
140 |
* analog_init must be called before using this function. |
|
141 |
* |
|
142 |
* @param which the analog port to read from. One of |
|
143 |
* the constants AN0 - AN7. |
|
144 |
* |
|
145 |
* @return the eight bit input to the specified port |
|
146 |
* |
|
147 |
* @see analog_init, analog10 |
|
148 |
**/ |
|
149 |
unsigned int analog_get8(int which) |
|
150 |
{ |
|
151 |
// Let any previous conversion finish |
|
152 |
while (ADCSRA & _BV(ADSC)); |
|
153 |
|
|
154 |
if(which < EXT_MUX) { |
|
155 |
ADMUX = ADMUX_OPT + which; |
|
156 |
} else { |
|
157 |
ADMUX = ADMUX_OPT + EXT_MUX; |
|
158 |
set_adc_mux(which - 8); |
|
159 |
} |
|
160 |
|
|
161 |
// Start the conversion |
|
162 |
ADCSRA |= _BV(ADSC); |
|
163 |
|
|
164 |
// Wait for the conversion to finish |
|
165 |
while (ADCSRA & _BV(ADSC)); |
|
166 |
|
|
167 |
return ADCH; //since we left aligned the data, ADCH is the 8 MSB. |
|
168 |
} |
|
169 |
|
|
170 |
/** |
|
171 |
* Reads a ten bit number from the specified port. |
|
172 |
* analog_init must be called before using this function. |
|
173 |
* |
|
174 |
* |
|
175 |
* @param which the analog port to read from. Typically |
|
176 |
* a constant, one of AN0 - AN7. |
|
177 |
* |
|
178 |
* @return the ten bit number input to the specified port |
|
179 |
* |
|
180 |
* @see analog_init, analog8 |
|
181 |
**/ |
|
182 |
unsigned int analog_get10(int which) |
|
183 |
{ |
|
184 |
int adc_h; |
|
185 |
int adc_l; |
|
186 |
|
|
187 |
// Let any previous conversion finish |
|
188 |
while (ADCSRA & _BV(ADSC)); |
|
189 |
|
|
190 |
if(which < EXT_MUX) { |
|
191 |
ADMUX = ADMUX_OPT + which; |
|
192 |
} else { |
|
193 |
ADMUX = ADMUX_OPT + EXT_MUX; |
|
194 |
set_adc_mux(which - 8); |
|
195 |
} |
|
196 |
|
|
197 |
// Start the conversion |
|
198 |
ADCSRA |= _BV(ADSC); |
|
199 |
|
|
200 |
// Wait for the conversion to finish |
|
201 |
while (ADCSRA & _BV(ADSC)); |
|
202 |
|
|
203 |
adc_l = ADCL; |
|
204 |
adc_h = ADCH; |
|
205 |
|
|
206 |
return ((adc_h << 2) | (adc_l >> 6)); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Returns the current position of the wheel, as an integer |
|
211 |
* in the range 0 - 255. |
|
212 |
* analog_init must be called before using this function. |
|
213 |
* |
|
214 |
* @return the orientation of the wheel, as an integer in |
|
215 |
* the range 0 - 255. |
|
216 |
* |
|
217 |
* @see analog_init |
|
218 |
**/ |
|
219 |
int wheel(void) |
|
220 |
{ |
|
221 |
return analog_get8(WHEEL_PORT); |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
226 |
* Sets the value of the external analog mux. Values are read |
|
227 |
* on AN7 physical port. (AN8 - AN15 are "virtual" ports). |
|
228 |
* |
|
229 |
* @param which which analog mux port (0-7) which corresponds |
|
230 |
* to AN8-AN15. |
|
231 |
* |
|
232 |
* @bug FIX THIS IN THE NEXT BOARD REVISION: |
|
233 |
* ADDR2 ADDR1 ADDR0 |
|
234 |
* G2.G4.G3 set mux to port 0-7 via vinary selection |
|
235 |
* math would be much cleaner if it was G4.G3.G2 |
|
236 |
* |
|
237 |
* @see analog_init |
|
238 |
**/ |
|
239 |
void set_adc_mux(int which) |
|
240 |
{ |
|
241 |
// mask so only proper bits are possible. |
|
242 |
PORTG = (PORTG & 0xE3) | ((which & 0x03) << 3) | (which & 0x04); |
|
243 |
} |
|
244 |
|
|
245 |
/**@}**/ //end defgroup |
|
246 |
|
|
247 |
|
|
248 |
ISR(ADC_vect) { |
|
249 |
static volatile int adc_prev_loop_running = 0; |
|
250 |
|
|
251 |
int adc_h = 0; |
|
252 |
int adc_l = 0; |
|
253 |
|
|
254 |
//usb_putc('p'); |
|
255 |
//usb_putc('r'); |
|
256 |
//usb_puti(adc_loop_running); |
|
257 |
//usb_puts("\n\r"); |
|
258 |
|
|
259 |
//Store the value only if this read isn't for the BOM |
|
260 |
if (ADMUX != BOM_PORT) { |
|
261 |
adc_l = ADCL; |
|
262 |
adc_h = ADCH; |
|
263 |
|
|
264 |
an_val[adc_current_port - 1].adc10 = (adc_h << 2) | (adc_l >> 6); |
|
265 |
an_val[adc_current_port - 1].adc8 = adc_h; |
|
266 |
//usb_puti(an_val[adc_current_port - 1].adc10); |
|
267 |
//usb_puts("\n\r"); |
|
268 |
//usb_puti(an_val[adc_current_port - 1].adc8); |
|
269 |
//usb_puti(ADCH); |
|
270 |
//usb_puts("\n\r"); |
|
271 |
} |
|
272 |
|
|
273 |
//Save the result only if we just turned off the loop |
|
274 |
if (!adc_loop_running && !adc_prev_loop_running) |
|
275 |
return; |
|
276 |
|
|
277 |
adc_prev_loop_running = adc_loop_running; |
|
278 |
|
|
279 |
//Skip AN7 because it is not a real port |
|
280 |
if (adc_current_port == AN6) { |
|
281 |
ADMUX = ADMUX_OPT | EXT_MUX; |
|
282 |
set_adc_mux(AN8 - 8); |
|
283 |
adc_current_port = AN8; |
|
284 |
//Wrap around |
|
285 |
} else if (adc_current_port == AN11) { |
|
286 |
adc_current_port = AN1; |
|
287 |
ADMUX = ADMUX_OPT | adc_current_port; |
|
288 |
//Normal increment |
|
289 |
} else { |
|
290 |
adc_current_port++; |
|
291 |
|
|
292 |
if(adc_current_port < EXT_MUX) { |
|
293 |
ADMUX = ADMUX_OPT | adc_current_port; |
|
294 |
} else { |
|
295 |
ADMUX = ADMUX_OPT | EXT_MUX; |
|
296 |
set_adc_mux(adc_current_port - 8); |
|
297 |
} |
|
298 |
} |
|
299 |
|
|
300 |
//Initiate next conversion only if we are running a loop |
|
301 |
if (!adc_loop_running) |
|
302 |
return; |
|
303 |
|
|
304 |
ADCSRA |= _BV(ADSC); |
|
305 |
|
|
306 |
//if (ADCSRA & _BV(ADSC)) |
|
307 |
// usb_putc('s'); |
|
308 |
|
|
309 |
return; |
|
310 |
} |
|
311 |
|
branches/autonomous_recharging/code/projects/libdragonfly/lcd.c | ||
---|---|---|
1 |
/* |
|
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 |
**/ |
|
2 | 25 |
|
3 |
lcd-ar2.c - implementation for lcd functions |
|
4 | 26 |
|
5 |
Author: CMU Robotics Club, Colony Project
|
|
6 |
|
|
7 |
This uses SPI.
|
|
8 |
|
|
9 |
lcd_init MUST be called before anything can be used.
|
|
10 |
|
|
11 |
*/
|
|
12 |
|
|
27 |
/**
|
|
28 |
* @file lcd.c |
|
29 |
* @brief LCD
|
|
30 |
* |
|
31 |
* Implementation of functions for using the LCD.
|
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club
|
|
34 |
**/ |
|
13 | 35 |
#include <avr/io.h> |
14 | 36 |
#include <lcd.h> |
15 | 37 |
#include <time.h> |
16 | 38 |
|
17 |
#define LCD_RS PB4 // Command/Data |
|
18 |
#define LCD_RSTB PE2 // reset line |
|
19 |
#define LCD_CS PB0 |
|
20 |
|
|
21 |
//////lcd defines |
|
39 |
//LCD defines |
|
22 | 40 |
#define RST _BV(4) // pd4 (GPIO) |
23 | 41 |
#define SCE _BV(0) // pb0 (~SS) |
24 | 42 |
#define D_C _BV(5) // pd5 (GPIO?) |
... | ... | |
31 | 49 |
#define LCDRESETPORT PORTD |
32 | 50 |
#define LCDRESETDDR DDRD |
33 | 51 |
|
34 |
// Internal Function Prototypes |
|
35 |
// inialize OLED and SPI |
|
36 |
void OLED_init(void); |
|
37 |
|
|
38 |
// reset Controller |
|
39 |
void Reset_SSD1339(void); |
|
40 |
|
|
41 |
// write command or data |
|
42 |
void write_c(unsigned char out_command); |
|
43 |
void write_d(unsigned char out_data); |
|
44 |
|
|
45 |
// these write data to the OLED on 8 bit data bus, depends on MCU |
|
46 |
void LCD_out(unsigned char cmd); |
|
47 |
|
|
48 |
// these functions set / clear pins for OLED control lines. they accecpt a 0 or 1 |
|
49 |
void DC(char stat); |
|
50 |
void RES(char stat); |
|
51 |
void CS(char stat); |
|
52 |
|
|
53 | 52 |
void lcd_putbyte(unsigned char b); |
54 | 53 |
|
55 |
void crazycircle (void) { |
|
56 |
/* int i; |
|
57 |
// draw 100 random circles |
|
58 |
for(i = 0;i < 100;i++){ |
|
59 |
write_c(0x86); // draw circle command |
|
60 |
write_d(rand() % 130); |
|
61 |
write_d(rand() % 130); |
|
62 |
write_d(rand() % 64); |
|
63 |
write_d(rand()); |
|
64 |
write_d(rand()); |
|
65 |
write_d(rand()); |
|
66 |
write_d(rand()); |
|
67 | 54 |
|
68 |
delay_ms(10); |
|
69 |
} |
|
70 |
*/ |
|
71 |
} |
|
72 |
|
|
73 |
void OLEDtest (void) { |
|
74 |
//int i = 0; |
|
75 |
|
|
76 |
// Initialize |
|
77 |
//Initialize(); |
|
78 |
OLED_init(); |
|
79 |
|
|
80 |
delay_ms(120); |
|
81 |
|
|
82 |
write_c(0x8e); // clear window command |
|
83 |
write_d(0); |
|
84 |
write_d(0); |
|
85 |
write_d(130); |
|
86 |
write_d(130); |
|
87 |
|
|
88 |
delay_ms(100); |
|
89 |
|
|
90 |
write_c(0x92); // fill enable command |
|
91 |
write_d(0x01); |
|
92 |
|
|
93 |
delay_ms(10); |
|
94 |
|
|
95 |
crazycircle(); |
|
96 |
/* |
|
97 |
// write directly to ram, this fills up bottom 1/3 of display with color pattern |
|
98 |
write_c(0x5c); |
|
99 |
for (i = 0; i < 2000; i++){ |
|
100 |
write_c(0x5c); |
|
101 |
write_d(i); |
|
102 |
write_d(i); |
|
103 |
write_d(i); |
|
104 |
} |
|
105 |
*/ |
|
106 |
} |
|
107 |
|
|
108 |
/********************************************************** |
|
109 |
Initialize |
|
110 |
**********************************************************/ |
|
111 |
|
|
112 |
void OLED_init(void) |
|
113 |
{ |
|
114 |
// Setup SPI here |
|
115 |
SPCR = 0x5D; // enable SPI, master, SPI mode 3 |
|
116 |
DDRB |= 0x06; // enable MOSI and SCK as outputs |
|
117 |
|
|
118 |
LCD_out(0); |
|
119 |
DC(0); |
|
120 |
CS(0); |
Also available in: Unified diff