root / demos / hunter_prey / lib / src / libdragonfly / serial.h @ 1828
History | View | Annotate | Download (4.37 KB)
1 | 1828 | emullini | /**
|
---|---|---|---|
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
|