Revision 1784

View differences:

demos/smart_run_around_fsm/lib/src/libdragonfly/motor.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 motor.h
29
 * @brief Contains definitions for controlling the motors
30
 *
31
 * Contains definitions and functions for controlling
32
 * the motors.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 * Based on Tom Lauwer's Firefly Library
36
 **/
37

  
38
#ifndef _MOTOR_H
39
#define _MOTOR_H
40

  
41
#include <avr/io.h>
42
/**
43
 * @addtogroup motors
44
 * @{
45
 **/
46

  
47
/** @brief make the motors go forwards **/
48
#define FORWARD 1
49
/** @brief make the motors go backwards **/
50
#define BACKWARD 0
51

  
52
/** @brief Initialize the motors **/
53
void motors_init(void);
54
/** @brief Set speed and direction of motor1 
55
 *  @deprecated use the left motor function instead. it's more intuitive and easier to read.**/
56
void motor1_set(int direction, int speed);
57
/** @brief Set speed and direction of motor2 
58
 *  @deprecated use the right motor function instead. it's more intuitive and easier to read.**/
59
void motor2_set(int direction, int speed);
60
/** @brief Set speed and direction of left motor **/
61
void motor_l_set(int direction, int speed);
62
/** @brief Set speed and direction of right motor **/
63
void motor_r_set(int direction, int speed);
64
/** @brief Turn the motors off **/
65
void motors_off(void);
66

  
67
/**@}**/ // end addtogroup
68

  
69
#endif
70

  
demos/smart_run_around_fsm/lib/src/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

  
36
#include "dragonfly_lib.h"
37

  
38
/* init_dragonfly - Initializes functions based on configuration parameters
39
   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
/**
51
 * @defgroup dragonfly Dragonfly
52
 * @brief General Dragonfly Functions
53
 * General functions for the dragonfly. Include
54
 * dragonfly_lib.h to access these functions.
55
 *
56
 * @{
57
 **/
58

  
59
/**
60
 * Initializes the components specified by config.
61
 * 
62
 * @see analog_init, usb_init, xbee_init, buzzer_init,
63
 * bom_init, orb_init, motors_init, lcd_init, encoders_init
64
 **/
65
 
66
void flash_red(void);
67

  
68
void dragonfly_init(int config) 
69
{
70
    sei();
71
    // Set directionality of various IO pins
72
    DDRG &= ~(_BV(PING0)|_BV(PING1));
73
    PORTG |= _BV(PING0)|_BV(PING1);
74
    
75
    if(config & ANALOG)
76
        analog_init(ADC_START);
77
    
78
    if(config & COMM)
79
    {
80
        //Defaults to 115200. Check serial.h for more information.
81
        usb_init();
82
        xbee_init();
83
    }
84
    
85
    if(config & BUZZER)
86
    {
87
        sei();
88
        buzzer_init();
89
    }
90
    
91
    if(config & ORB)
92
    {
93
        sei();
94
        orb_init();
95
    }
96
    
97
    if(config & MOTORS)
98
        motors_init();
99

  
100
    if(config & LCD)
101
        lcd_init();
102
    
103
    if(config & RANGE)
104
        range_init();
105
        
106
    if(config & BOM)
107
    {
108
        unsigned char bom_read = get_bom_type();
109
        if(bom_read == 0xFF)
110
            //warn that bom initialization failed
111
            flash_red();
112
        else
113
            bom_init(bom_read);
114
    }
115

  
116
	if (config & ENCODERS)
117
	{
118
		encoders_init();
119
	}
120

  
121
    // delay a bit for stability
122
    _delay_ms(1);
123
}
124

  
125
//flash lights red three times and restore ports
126
void flash_red(void)
127
{
128
    cli();
129
    char dd = DDRC;
130
    char po = PORTC;
131
    char i;
132
    DDRC = 0x77;
133
    for(i = 0; i<3; i++)
134
    {
135
        PORTC = 0x77;
136
        delay_ms(300);
137
        PORTC = 0x66;
138
        delay_ms(300);
139
    }
140
    
141
    DDRC = dd;
142
    PORTC = po;
143
    sei();
144
}
145
/** @} **/ //end defgroup
146

  
demos/smart_run_around_fsm/lib/src/libdragonfly/i2c.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 i2c.c
29
 * @brief Implemenation of I2C communications protocol
30
 * 
31
 * In the case where you have master sends and then a master request to the same
32
 * address, you will not give up control of the line because the send and
33
 * request addresses are seen as different addresses. In between it will send a
34
 * restart but will not give up the line.
35
 *
36
 * @author CMU Robotics Club, Kevin Woo, Sursh Nidhiry
37
 * @bug Not tested.
38
 */
39

  
40
#include <avr/interrupt.h>
41
#include <util/twi.h>
42

  
43
#include "i2c.h"
44
#include "ring_buffer.h"
45

  
46
/**
47
 * @defgroup i2c I2C 
48
 *
49
 * @brief Provides Inter-Interconnected-Communications (I2C)
50
 * 
51
 * Initiates I2C functions on an ATMega128 which has a fully hardware Two Wire 
52
 * Interface (TWI) module. Any Atmel chip with this hardware should be able to
53
 * use the software.
54
 *
55
 * This code will operate in a multi-master enviornment and can be either a
56
 * slave or a master at any time (as long as they are not one or the other at
57
 * the moment. You can queue up multiple transmission modes in the buffer up to 
58
 * the buffer size. The buffer is implemented as a ring buffer.
59
 *
60
 * It is implemented using callback functions. Whenever you want to send a packet
61
 * you can call the built in send function (as a master) and it will send an array
62
 * of bytes. Master recieve and slave send/receive are all handled by the call back
63
 * functions. It is up to the end user to create functions that will handle the
64
 * receiving of packets. Their functions will be called with every byte recieved
65
 * so you must either buffer the inputs or handle each one separately.
66
 *
67
 * On errors we will simply flush the entire buffer.
68
 * 
69
 * For information on how I2C operates, read the wikipedia article
70
 * http://en.wikipedia.org/wiki/I2c
71
 * for a good explanation of how it works.
72
 * @{
73
 */
74

  
75
/** 
76
 * @brief Set bit rate 12 = 100kbit/s (max speed setting is 10 for an
77
 *  8 MHz clock). It is a divider, so the lower the number the faster the speed.
78
 */
79
#define I2C_BIT_RATE_DIVIDER 0x0C
80

  
81
static int start_flag;
82

  
83
static fun_mrecv_t master_recv_function;
84
static fun_srecv_t slave_recv_function;
85
static fun_send_t slave_send_function;
86

  
87
RING_BUFFER_NEW(i2c_buffer, 128, char, i2c_write_buff, i2c_addr_buff);
88

  
89

  
90
/**
91
 * @brief Initializes the i2c module.
92
 *
93
 * Initializes the I2C module to start listening on the i2c lines. If the callback functions
94
 * are not set to null they will be called when that transmission mode is called. The address
95
 * is your address that you will listen to when you are not the master.
96
 *
97
 * @param addr 			Your address on the I2C bus.
98
 * @param master_recv 	The address of the function to call when you receive a byte when you are a
99
 *                    	master.
100
 * @param slave_recv 	The address of the function to call when you are a slave you receive data
101
 *								from the master
102
 * @param slave_send		The address of the function to call when you are a slave and the master
103
 *								requests data from you.
104
 *
105
 * @return 0 for success, nonzero for failure
106
 **/
107
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send) {
108
    master_recv_function = master_recv;
109
    slave_recv_function = slave_recv;
110
    slave_send_function = slave_send;
111

  
112
    RING_BUFFER_CLEAR(i2c_write_buff);
113
    RING_BUFFER_CLEAR(i2c_addr_buff);
114
  
115
    /* enables twi interrupt, automatic ack sending, and all twi hardware */
116
    TWCR =  (_BV(TWEA) | _BV(TWEN) | _BV(TWIE));
117

  
118
    /* sets the bit rate of data transmission */
119
    TWBR = I2C_BIT_RATE_DIVIDER;
120

  
121
    /* sets the address (it is stored in the 7 most significant bits) and allows
122
     * global messages to be accepted */
123
    TWAR = (addr << 1) | 1;
124
  
125
    return 0;
126
}
127

  
128
/**
129
 * @brief Sends a byte array over I2C as a master
130
 *
131
 * Will perform a send over I2C to the destination from data for the ammount of
132
 * bytes that bytes is.
133
 *
134
 * @param dest		Destination address of the data on the I2C bus.
135
 * @param data 	The pointer to the byte array of data
136
 * @param bytes	The amount of bytes long that the byte array is. This is how
137
 *						many bytes from the array that the function will send.
138
 *
139
 * @return zero for success, nonzero for failure
140
 **/
141
int i2c_send(char dest, char *data, unsigned int bytes) {
142
    int i;
143

  
144
    /* adding data to be sent to ring buffers is not atomic,
145
     * so disable interrupts */
146
    cli();
147
    for(i = 0; i < bytes; i++) {
148
        if(RING_BUFFER_FULL(i2c_write_buff)) {
149
            sei();
150
            return -1;
151
        }
152

  
153
        RING_BUFFER_ADD(i2c_write_buff, data[i]);
154
        RING_BUFFER_ADD(i2c_addr_buff, dest << 1);
155
    }
156
    
157
    /* re-enable the interrupts */
158
    sei();
159
    
160
    /* send the start bit, only if this device is not currently master */
161
    if(!start_flag) {
162
        start_flag = 1;
163
        TWCR |= _BV(TWSTA);
164
        TWCR |= _BV(TWINT);
165
    }
166
  
167
    return 0;
168
}
169
 
170
/**
171
 * @brief Send a master request to the destination
172
 *
173
 * Sends a request of data from the target address and calls
174
 * the callback function to handle data as it comes in. This function will
175
 * not work if the slave has not informationt to send or has nothing implemented
176
 * to send it.
177
 *
178
 * @param dest		The destination that we want to receive information from.
179
 *
180
 * @return 0 for success, nonzero for failure
181
 **/ 
182
int i2c_request(char dest) {
183
    if(RING_BUFFER_FULL(i2c_write_buff))
184
        return -1;
185
  
186
    RING_BUFFER_ADD(i2c_write_buff, 0);
187
    RING_BUFFER_ADD(i2c_addr_buff, (dest << 1) | 1);
188
  
189
    if(!start_flag) {
190
        start_flag = 1;
191
        TWCR |= _BV(TWSTA);
192
        TWCR |= _BV(TWINT);
193
    }
194
  
195
    return 0;
196
}
197

  
198
/** @} **/
199
 
200
/**
201
 * @brief Interrupt to handle I2C interrupts from the I2C hardware.
202
 * 
203
 * Uses the status codes from the I2C register to handle the events
204
 * needed to advance in I2C stages. For instance, you will get a bit for
205
 * receiving a start ack, then a address ack, then a data ack, etc.
206
 * The events are handled in each switch case. The status codes are defined
207
 * by avr-gcc in /util/twi.h but are the same codes as the Atmel documentation.
208
 *
209
 * Bytes are sent by popping off the ring buffer. It also will keep track
210
 * of what modes the send is in.
211
 *
212
 * Errors are handled here as well.
213
 **/ 
214
ISR(TWI_vect) {
215
	static char data_to_send;
216
	static char addr_to_send = -1;
217
	char addr, statusCode;
218
  
219
	//Get status code (only upper 5 bits)
220
	statusCode = (TWSR & 0xF8);
221

  
222
    switch (statusCode) {
223
        //Start sent successfully
224
        case TW_START:
225
        case TW_REP_START:
226
            /* Send address and write
227
             * ring_buffer will not be empty */
228
            RING_BUFFER_REMOVE(i2c_addr_buff, addr_to_send);
229
            RING_BUFFER_REMOVE(i2c_write_buff, data_to_send);
230
            
231
            /* first send the address */
232
            TWDR = addr_to_send; 
233
            
234
            //Turn off start bits
235
            TWCR &= ~_BV(TWSTA);
236
            break;
237

  
238
        //Master Transmit - Address sent succesfully
239
        case TW_MT_SLA_ACK:
240
        //Send byte
241
            TWDR = data_to_send;
242
            PORTG &= ~_BV(PG2);
243
            break;
244
	 
245
        //Master Transmit - Data sent succesfully
246
        case TW_MT_DATA_ACK:    
247
            //If there is still data to send
248
            if(!RING_BUFFER_EMPTY(i2c_write_buff)) {
249
                RING_BUFFER_PEEK(i2c_addr_buff, addr);
250
        
251
                //Still data for this address
252
                if (addr == addr_to_send) {
253
                    RING_BUFFER_REMOVE(i2c_addr_buff, addr);
254
                    RING_BUFFER_REMOVE(i2c_write_buff, TWDR);
255
                    break;
256
                //No more data for this address, data for another address -> resend start
257
                } else {
258
                    TWCR |= _BV(TWSTA);
259
                    break;
260
                }
261
            }
262
            /* there are no bytes to send */
263
            TWCR |= _BV(TWSTO);
264
            start_flag = 0;
265
            break; 
266
            
267
        //Master Transmit - Slave sends a nack, transmit is done
268
        case TW_MT_DATA_NACK:
269
            PORTG |= _BV(PG2);
270
            TWCR |= _BV(TWSTO);
271
            start_flag = 0;
272
            break;
273
    
274
        //Master Receive - Address sent succesfully
275
        case TW_MR_SLA_ACK:
276
            PORTG |= _BV(PG2);
277
            break;
278
            
279
        //Master Receive - Data received succesfully
280
        case TW_MR_DATA_ACK:
281
            if(master_recv_function) {
282
                if(!master_recv_function(TWDR)) {
283
                    TWCR &= ~_BV(TWEA);
284
                }
285
            }
286
            break;
287
            
288
        //Master Receive - Slave sends a nack, transmission is done    
289
        case TW_MR_DATA_NACK:
290
            TWCR |= _BV(TWEA);
291
      
292
            //If there is still data to send
293
            if(!RING_BUFFER_EMPTY(i2c_write_buff)) {
294
                TWCR |= _BV(TWSTA);
295
                break;
296
            }
297
      
298
            /* there are no bytes to send */
299
            TWCR |= _BV(TWSTO);
300
            start_flag = 0;  
301
            break;
302
    
303
        //Slave Transmit - Address received
304
        case TW_ST_SLA_ACK:
305
            break;
306
    
307
        //Slave Transmit - Nack received, no data requsted
308
        case TW_ST_DATA_NACK:
309
            break;
310
        
311
        //Slave Transmit - Data requested, ack received
312
        case TW_ST_DATA_ACK:
313
            if (slave_send_function) {
314
                TWDR = slave_send_function();
315
            }
316
            break;
317
    
318
        //Slave Receive - Address received  
319
        case TW_SR_SLA_ACK:
320
            break;
321
    
322
        //Slave Receive - Data received, ack returned
323
        case TW_SR_DATA_ACK:
324
            if(slave_recv_function) {
325
                slave_recv_function(TWDR);
326
            }
327
            
328
            break;
329
      
330
        //Stop sent  
331
        case TW_SR_STOP:
332
            break;
333
	
334
        //Problem on the bus, reset everything
335
        default:
336
            TWCR |= _BV(TWSTO);
337
            start_flag = 0;
338
            RING_BUFFER_CLEAR(i2c_write_buff);
339
            RING_BUFFER_CLEAR(i2c_addr_buff);  	
340
    }
341
  
342
  /* Toggle TWINT so that it resets and executes the commands */
343
  TWCR |= _BV(TWINT);
344
}
345

  
demos/smart_run_around_fsm/lib/src/libdragonfly/serial.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 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

  
36
#include <avr/io.h>
37
#include "serial.h"
38

  
39
#ifdef USE_STDIO
40

  
41
#include <stdio.h>
42

  
43
/**
44
 * For use with fprintf() and related stdio functions
45
 **/
46
FILE *usb_fd;
47

  
48
/**
49
 * For use with fprintf() and related stdio functions
50
 **/
51
FILE *xbee_fd;
52

  
53
#endif
54

  
55
/**
56
 * Initializes communication over the USB serial port.
57
 * This must be called before any other usb function
58
 * may be used.
59
 **/
60
void usb_init() {
61
  //Set baud rate
62
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
63
  // - 9600 is U2X =1, UBRR = 107.
64
#if (USB_BAUD == 115200)
65
  UBRR0H = 0x00;
66
  UBRR0L = 8;
67
  UCSR0A |= _BV(U2X0);
68
#elif (USB_BAUD == 9600)
69
  UBRR0H = 0x00;
70
  UBRR0L = 103;
71
  UCSR0A |= _BV(U2X0);
72
#else //Baud rate is defined in the header file, we should not get here
73
  return;
74
#endif
75

  
76
  /*Enable receiver and transmitter */
77
  UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
78
	
79
  /* Set frame format: 8data, 1stop bit, asynchronous normal mode */
80
  UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
81
  
82
  // if we have enabled the stdio stuff, then we init it here
83
#ifdef USE_STDIO
84
  /* Open the stdio stream corresponding to this port */
85
  usb_fd = fdevopen(usb_putc, usb_getc);
86
#endif
87
}
88

  
89
/**
90
 * Initializes communication over the XBee.
91
 * This must be called before any other xbee function
92
 * may be used.
93
 **/
94
void xbee_init() {
95
  //Set baud rate
96
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
97
  // - 9600 is U2X =1, UBRR = 107.
98
#if (XBEE_BAUD == 115200)
99
  UBRR1H = 0x00;
100
  UBRR1L = 8;
101
  UCSR1A |= _BV(U2X1);
102
#elif (XBEE_BAUD == 9600)
103
  UBRR1H = 0x00;
104
  UBRR1L = 103;
105
  UCSR1A |= _BV(U2X1);
106
#else //Baud rate is defined in the header file, we should not get here
107
  return;
108
#endif
109

  
110
  //Enable receiver and transmitter
111
  UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
112
	
113
  // Set frame format: 8data, 1stop bit, asynchronous normal mode
114
  UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
115
  
116
  // if we have enabled the stdio stuff, then we init it here
117
#ifdef USE_STDIO
118
  /* Open the stdio stream corresponding to this port */
119
  xbee_fd = fdevopen(xbee_putc, xbee_getc);
120
#endif
121
}
122

  
123
/**
124
 * Sends a character over USB.
125
 *
126
 * @param c the character to send
127
 * @return 0 for success, nonzero for failure
128
 **/
129
int usb_putc(char c) {
130
  // Wait until buffer is clear for sending
131
  loop_until_bit_is_set(UCSR0A, UDRE0);
132
	
133
  // Load buffer with your character
134
  UDR0 = c;
135
  return 0;
136
}
137

  
138
/**
139
 * Sends a character to the XBee.
140
 *
141
 * @param c the character to send
142
 * @return 0 for success, nonzero for failure
143
 **/
144
int xbee_putc(char c) {
145
  // Wait until buffer is clear for sending
146
  loop_until_bit_is_set(UCSR1A, UDRE1);
147
	
148
  // Load buffer with your character
149
  UDR1 = c;
150
  return 0;
151
}
152

  
153
/**
154
 * Sends a sequence of characters over USB.
155
 *
156
 * @param s the string to send
157
 * @return 0 for success, nonzero for failure
158
 **/
159
int usb_puts(char *s) {
160
  char *t = s;
161
  while (*t != 0) {
162
    usb_putc(*t);
163
    t++;
164
  }
165
  return 0;
166
}
167

  
168
/**
169
 * Sends a sequence of characters from program space over USB.
170
 *
171
 * @param s the string to send
172
 **/
173
void usb_puts_P (PGM_P s) {
174
    char buf;
175
	
176
    while (memcpy_P (&buf, s, sizeof (char)), buf!=0) {
177
        usb_putc (buf);
178
        s++;
179
    }
180
}
181

  
182

  
183

  
184
/**
185
 * Returns the first character in the buffer received from USB.
186
 * This function blocks execution until a character has been received.
187
 * xbee_init must be called before this function may be used.
188
 * 
189
 * @return the first character in the usb buffer
190
 *
191
 * @see usb_init, usb_getc_nb
192
 **/
193
int usb_getc(void) {
194
  // Wait for the receive buffer to be filled
195
  loop_until_bit_is_set(UCSR0A, RXC0);
196
	
197
  // Read the receive buffer
198
  return UDR0;
199
}
200

  
201
/**
202
 * Returns the first character in the buffer received from USB.
203
 * This function blocks execution until a character has been
204
 * received. xbee_init must be called before this function
205
 * may be used.
206
 * 
207
 * @return the first character in the xbee buffer
208
 * 
209
 * @see xbee_init, xbee_getc_nb
210
 **/
211
int xbee_getc(void) {
212
  // Wait for the receive buffer to be filled
213
  loop_until_bit_is_set(UCSR1A, RXC1);
214
	
215
  // Read the receive buffer
216
  return UDR1;
217
}
218

  
219
/**
220
 * Non blocking version of usb_getc. If a character is present in the buffer,
221
 * it is returned, otherwise -1 is returned immediately. usb_init must be
222
 * called before this function can be used.
223
 *
224
 * @param c the received character. This will be set if a character has
225
 * been received.
226
 * 
227
 * @return -1 if no character is available, 0 otherwise
228
 * 
229
 * @see usb_init, usb_getc
230
 **/
231
int usb_getc_nb(char *c) {
232
  // check if the receive buffer is filled
233
  if (UCSR0A & _BV(RXC0)) {
234
    // Read the receive buffer
235
    (*c) = UDR0;
236
    return 0;
237
  } else {
238
    // Return empty
239
    return -1;
240
  }
241
}
242

  
243
/**
244
 * Non blocking version of xbee_getc. If a character is present in the buffer,
245
 * it is returned, otherwise -1 is returned immediately. xbee_init
246
 * must be called before this function can be used.
247
 *
248
 * @param c the received character. This will be set if a character has
249
 * been received.
250
 * 
251
 * @return -1 if no character is available, 0 otherwise
252
 *
253
 * @see xbee_init, xbee_getc
254
 **/
255
int xbee_getc_nb(char *c) {
256
  // check if the receive buffer is filled
257
  if (UCSR1A & _BV(RXC1)) {
258
    // Read the receive buffer
259
    (*c) = UDR1;
260
    return 0;
261
  } else {
262
    // Return empty
263
    return -1;
264
  }
265
}
266

  
267

  
268
/*
269
  prints an int to serial
270

  
271
  code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
272
  uses usb_putc
273
*/
274
/**
275
 * Prints an integer, converted to ASCII, to usb. usb_init must be called
276
 * before this function can be used.
277
 *
278
 * @param value the integer to print
279
 * 
280
 * @return 0 if successful, nonzero otherwise
281
 *
282
 * @see usb_init, usb_putc
283
 **/
284
int usb_puti(int value ) {
285
  unsigned char usb_data[6]={'0','0','0','0','0','0' }, position=sizeof(usb_data), radix=10; 
286

  
287
  /* convert int to ascii  */ 
288
  if(value<0) { 
289
    usb_putc('-'); 
290
    value=-value; 
291
  }    
292
  do { 
293
    position--; 
294
    *(usb_data+position)=(value%radix)+'0'; 
295
    value/=radix;  
296
  } while(value); 
297

  
298
    
299
  /* start displaying the number */
300
  for(;position<=(sizeof(usb_data)-1);position++) {
301
            
302
    usb_putc(usb_data[position]);
303
  }
304

  
305
  return 0;
306
}
307

  
308
/**
309
 * Determines a hexadecimal digit in ASCII code.
310
 *
311
 * @param value the value of the digit (0<=value<=15)
312
 * 
313
 * @return the hexadecimal digit in ASCII code, or '?'
314
 * if the input is invalid.
315
 **/
316
uint8_t hex_digit (uint8_t value)
317
{
318
    if (value>15) return '?';
319
    // Postcondition: 0<=x<=15
320

  
321
    return "0123456789ABCDEF"[value];
322
}
323

  
324
/**
325
 * Prints a fixed width hexadecimal representation of an unsigned
326
 * 16 bit integer in ASCII code to USB.
327
 * usb_init must be called before this function can be used.
328
 *
329
 * @param value the value to print
330
 * 
331
 * @see usb_init, usb_puti, usb_puts, usb_puth8, hex_digit
332
 **/
333
void usb_puth16 (uint16_t value)
334
{
335
    usb_putc (hex_digit((value >>12)&0xF));
336
    usb_putc (hex_digit((value >>8 )&0xF));
337
    usb_putc (hex_digit((value >>4 )&0xF));
338
    usb_putc (hex_digit( value      &0xF));
339
}
340

  
341
/**
342
 * Prints a fixed width hexadecimal representation of an unsigned
343
 * 8 bit integer in ASCII code to USB.
344
 * usb_init must be called before this function can be used.
345
 *
346
 * @param value the value to print
347
 * 
348
 * @see usb_init, usb_puti, usb_puts, usb_puth16, hex_digit
349
 **/
350
void usb_puth8(uint8_t value)
351
{
352
    usb_putc (hex_digit ((value)>>4 &0xF));
353
    usb_putc (hex_digit ( value     &0xF));
354
}
355

  
demos/smart_run_around_fsm/lib/src/libdragonfly/dragonfly_lib.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 the rangefinders **/
64
#define RANGE  0x0100
65
/** @brief Initialize the BOM **/
66
#define BOM  0x0200
67
/** @brief Initilize encoders **/
68
#define ENCODERS 0x400
69
/** @brief Initialize everything  **/
70
#define ALL_ON 0x07FF
71

  
72
/** @brief Initialize the board **/
73
void dragonfly_init(int config);
74

  
75
/** @} **/ //end addtogroup
76

  
77
#include <inttypes.h>
78
#include <avr/io.h>
79
#include <avr/interrupt.h>
80
#include <util/delay.h>
81
#include <util/twi.h>
82

  
83
// This file is included from the libdragonfly directory because it seems to be
84
// missing from the AVR libc distribution.
85
#include "atomic.h"
86

  
87
#include "analog.h"
88
#include "dio.h"
89
#include "time.h"
90
#include "lcd.h"
91
#include "lights.h"
92
#include "motor.h"
93
#include "serial.h"
94
#include "buzzer.h"
95
#include "rangefinder.h"
96
#include "bom.h"
97
#include "encoders.h"
98
#include "move.h"
99
#include "reset.h"
100
#include "math.h"
101
#include "eeprom.h"
102

  
103
#include <stddef.h>
104
#include <stdbool.h>
105

  
106
/** @brief shortcut for ATOMIC_BLOCK(ATOMIC_RESTORESTATE) **/
107
#define SYNC ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
108

  
109
/** @brief atomically grab a lock if it is free, return otherwise **/
110
#define REQUIRE_LOCK_OR_RETURN(LOCK) do { SYNC { if (LOCK) return; LOCK=1; } } while (0)
111

  
112
/** @brief atomically release a lock **/
113
#define RELEASE_LOCK(LOCK) do { LOCK=0; } while (0)
114

  
115

  
116

  
117
#endif
118

  
demos/smart_run_around_fsm/lib/src/libdragonfly/buzzer.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 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

  
38
#include <avr/io.h>
39
#include "buzzer.h"
40
#include "time.h"
41

  
42
/**
43
 * @defgroup buzzer Buzzer
44
 * @brief Functions for controlling the buzzer.
45
 * Functions for controlling the buzzer. Include
46
 * buzzer.h to access these functions.
47
 * @{
48
 **/
49

  
50
/**
51
 * Initializes the buzzer. Must be called before any other buzzer
52
 * function may be used.
53
 **/
54
void buzzer_init( void )
55
{
56
	//NOTE: This is mostly handled by buzzer_Set_val for now
57
	// Set pin B7 to output - B7 is buzzer pin
58
	//DDRB |= _BV(DDB7);
59
	//Fast PWM Mode, Clear OCR0 on compare match and set at bottom, clock/64
60
	//TCCR2 = _BV(COM20) | _BV(WGM21)  | _BV(CS22);
61
}
62

  
63
/**
64
 * Sets the value of the buzzer's pitch.
65
 * Higher values are lower frequencies.
66
 *
67
 * @param buzz_value the value to set the buzzer's frequency too,
68
 * in the range 0-255
69
 *
70
 * @see buzzer_init, buzzer_set_freq, buzzer_off
71
 **/
72
void buzzer_set_val(unsigned int buzz_value)
73
{ 
74
	TCCR2 = _BV(COM20) | _BV(WGM21)  | _BV(CS22);
75
	DDRB |= _BV(DDB7);
76
	OCR2 = buzz_value;
77
}
78

  
79
/**
80
 * Sets the buzzer frequency. Usage of constants such as C4
81
 * is highly recommended as input to this function.
82
 * buzzer_init must be called before this function may
83
 * be used.
84
 *
85
 * @param buzz_freq the frequency to set the buzzer to
86
 *
87
 * @see buzzer_init, buzzer_set_val, buzzer_off
88
 **/
89
void buzzer_set_freq(unsigned int buzz_freq)
90
{
91
  int buzz_value;
92
  
93
  buzz_value = 62500/buzz_freq - 1;
94

  
95
  if(buzz_value > 255){
96
    buzz_value = 255;
97
  }else if(buzz_value < 0){
98
    buzz_value = 0;
99
  }
100
  
101
  buzzer_set_val(buzz_value);
102
}
103

  
104
/**
105
 * Plays the specified frequency for the specified
106
 * amount of time. This function blocks execution
107
 * until the time is completed. buzzer_init must be
108
 * called before this function can be used.
109
 *
110
 * @param ms the time in milliseconds to play the frequency
111
 * @param buzz_freq the frequency to play
112
 *
113
 * @see buzzer_init, buzzer_set_freq
114
 **/
115
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq) 
116
{ 
117
  buzzer_set_freq(buzz_freq);
118
  delay_ms(ms);
119
  buzzer_off();
120
}
121

  
122
/**
123
 * Turns off the buzzer by disabling the timer0 clock.
124
 *
125
 * @see buzzer_init
126
 **/
127
void buzzer_off()
128
{
129
  // Disable clock, to halt counter
130
  TCCR2 &= 0xF8;//0b11111000;
131
  
132
  // Set buzzer pin low in case it's high
133
  PORTB &= 0xBF;//0b10111111;
134
}
135

  
136
/** @} **/ // end buzzer group
137

  
demos/smart_run_around_fsm/lib/src/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

  
27
/** @file i2c.h
28
 *  @brief Header file for I2C
29
 *
30
 *  Contains functions for I2C.
31
 *
32
 *  @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club
33
 **/
34

  
35

  
36
#ifndef _I2C_H_
37
#define _I2C_H_
38

  
39
/** @brief Address of slave receive handler function **/
40
typedef void (*fun_srecv_t)(char);
41

  
42
/** @brief Address of master receive handler function**/
43
typedef int (*fun_mrecv_t)(char);
44

  
45
/** @brief Address of slave send handler function**/
46
typedef char (*fun_send_t)(void);
47

  
48
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send);
49
int i2c_send(char dest, char* data, unsigned int bytes);
50
int i2c_request(char dest);
51

  
52
void i2c_packet_rec (char i2c_byte);
53
void i2c_packet_sniff(char data);
54
#endif
55

  
demos/smart_run_around_fsm/lib/src/libdragonfly/serial.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 serial.h
29
 * @brief Contains declarations for serial input and output
30
 *
31
 * Contains definitions for serial input and output.
32
 *
33
 * @author Colony Project, CMU Robotics Club
34
 * Based on Tom Lauwer's Firefly Library
35
 *
36
 **/
37

  
38
/*
39
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40
  author(s): pkv
41
  
42
  Directions:
43
  Call the initialization function for the serial port you wish to use.  Then, use
44
  either the provided functions or the stdio functions (fprintf, etc) to read and
45
  write characters to the serial ports.
46
  
47
  UART Mapping:
48
  usb_*() -> UART0
49
  xbee_*() -> UART1
50
  
51
  Options: (Add the following defines to your code to configure this library)
52
  #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
53
  #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
54
  #define USE_STDIO
55
  
56
  Note: If you enable USE_STDIO, the first init function that is called will 
57
  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
58
  commands, add something like the following to your code:
59
  
60
  #define FOO_BAUD 9600
61
  
62
  **UNLESS YOU KNOW WHAT YOU ARE DOING, PLEASE DO NOT CHANGE THIS FILE**
63
  Many, many other people use this file in their code.  If you change it, you will
64
  probably break all of their nice code.  You should not need to change anything in
65
  here, except to accomodate new hardware.
66
*/
67

  
68
#ifndef _SERIAL_H
69
#define _SERIAL_H
70

  
71
#include <inttypes.h>
72
#include <avr/pgmspace.h>
73

  
74
/**
75
 * @defgroup usb USB Input / Output
76
 * @brief Functions for USB input / output
77
 *
78
 * Low level functions for USB input and output.
79
 *
80
 * @{
81
 **/
82

  
83
// if no baud rate is defined for usb, default is set here
84
#ifndef USB_BAUD
85
/** @brief the USB baud rate **/
86
#define USB_BAUD 115200
87
#endif
88

  
89
/** @brief Initialize the USB **/
90
void usb_init(void);
91
/** @brief Print a character to USB **/
92
int usb_putc(char c);
93
/** @brief Read a character from USB **/
94
int usb_getc(void);
95
/** @brief Read a character from USB without blocking **/
96
int usb_getc_nb(char *c);
97
/** @brief Print a string to USB **/
98
int usb_puts(char *s);
99
/** @brief Print a string from program space to USB **/
100
void usb_puts_P (PGM_P s);
101
/** @brief Print an integer to USB **/
102
int usb_puti(int value);
103
/** @brief Determine a hexadecimal digit **/
104
uint8_t hex_digit (uint8_t value);
105
/** @brief Print a fixed width hexadecimal representation to USB **/
106
void usb_puth16 (uint16_t value);
107
/** @brief Print a fixed width hexadecimal representation to USB **/
108
void usb_puth8(uint8_t value);
109
/** @brief Alias for usb_puth16 **/
110
static inline void usb_puth (uint16_t value) { usb_puth16 (value); };
111

  
112

  
113
/** @} **/ //end addtogroup
114

  
115
/**
116
 * @defgroup xbee XBee Input / Output
117
 * @brief Functions for XBee input / output
118
 *
119
 * Low level functions for XBee input and output.
120
 *
121
 * @{
122
 **/
123

  
124
// if no baud rate is defined for usb, default is set here
125

  
126
// if no baud rate is defined for xbee, default is set here
127
#ifndef XBEE_BAUD
128
/** @brief the XBee baud rate **/
129
#define XBEE_BAUD 9600
130
#endif
131

  
132
/** @brief Initialize the XBee **/
133
void xbee_init(void);
134
/** @brief Print a character to the XBee **/
135
int xbee_putc(char c);
136
/** @brief Read a character from the XBee **/
137
int xbee_getc(void);
138
/** @brief Read a character from the XBee without blocking **/
139
int xbee_getc_nb(char *c);
140

  
141

  
142

  
143
/** @} **/ //end addtogroup
144

  
145
#endif
146

  
demos/smart_run_around_fsm/lib/src/libdragonfly/buzzer.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 buzzer.h
29
 * @brief Contains definitions for using the buzzer.
30
 *
31
 * Contains definitions for using the buzzer built into
32
 * the colony robots.
33
 *
34
 * @author Colony Project, CMU Robotics Club
35
 **/
36

  
37
#ifndef _BUZZER_H_
38
#define _BUZZER_H_
39

  
40
/**
41
 * @addtogroup buzzer
42
 * @{
43
 **/
44

  
45
//Musical note definitions
46
//Source: http://www.answers.com/topic/piano-key-frequencies
47
/** @brief Middle C **/
48
#define	C4	260 //Middle C
49
/** @brief C# **/
50
#define	C4s	277 //C sharp
51
/** @brief D **/
52
#define	D4	294
53
/** @brief D# **/
54
#define	D4s	311
55
/** @brief E **/
56
#define	E4	330
57
/** @brief F **/
58
#define	F4	349
59
/** @brief F# **/
60
#define	F4s	370
61
/** @brief G **/
62
#define	G4	392
63
/** @brief G# **/
64
#define	G4s	415
65
/** @brief A **/
66
#define	A4	440
67
/** @brief A# **/
68
#define	A4s	466
69
/** @brief B **/
70
#define	B4	494
71
/** @brief C **/
72
#define	C5	523
73

  
74
/** @brief Initialize the buzzer. **/
75
void buzzer_init(void);
76
/** @brief Set the value the buzzer plays. **/
77
void buzzer_set_val(unsigned int buzz_value);
78
/** @brief Set the frequency the buzzer plays. **/
79
void buzzer_set_freq(unsigned int buzz_freq);
80
/** @brief Play a frequency for a specified time. **/
81
void buzzer_chirp(unsigned int ms, unsigned int buzz_freq);
82
/** @brief Turn the buzzer off. **/
83
void buzzer_off(void); 
84

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff