Project

General

Profile

Revision 891

Moved comments to headers. That was painful.

View differences:

i2c.h
32 32
 *  @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club
33 33
 **/
34 34

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

  
36 64
#ifndef _I2C_H_
37 65
#define _I2C_H_
......
47 75
/** @brief Address of slave send handler function**/
48 76
typedef char (*fun_send_t)(void);
49 77

  
78
/**
79
 * @brief Initializes the i2c module.
80
 *
81
 * Initializes the I2C module to start listening on the i2c lines. If the callback functions
82
 * are not set to null they will be called when that transmission mode is called. The address
83
 * is your address that you will listen to when you are not the master.
84
 *
85
 * @param addr 			Your address on the I2C bus.
86
 * @param master_recv 	The address of the function to call when you receive a byte when you are a
87
 *                    	master.
88
 * @param slave_recv 	The address of the function to call when you are a slave you receive data
89
 *								from the master
90
 * @param slave_send		The address of the function to call when you are a slave and the master
91
 *								requests data from you.
92
 *
93
 * @return 0 for success, nonzero for failure
94
 **/
50 95
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send);
96

  
97
/**
98
 * @brief Sends a byte array over I2C as a master
99
 *
100
 * Will perform a send over I2C to the destination from data for the ammount of
101
 * bytes that bytes is.
102
 *
103
 * @param dest		Destination address of the data on the I2C bus.
104
 * @param data 	The pointer to the byte array of data
105
 * @param bytes	The amount of bytes long that the byte array is. This is how
106
 *						many bytes from the array that the function will send.
107
 *
108
 * @return zero for success, nonzero for failure
109
 **/
51 110
int i2c_send(char dest, char* data, size_t bytes);
111

  
112
/**
113
 * @brief Send a master request to the destination
114
 *
115
 * Sends a request of data from the target address and calls
116
 * the callback function to handle data as it comes in. This function will
117
 * not work if the slave has not informationt to send or has nothing implemented
118
 * to send it.
119
 *
120
 * @param dest		The destination that we want to receive information from.
121
 *
122
 * @return 0 for success, nonzero for failure
123
 **/ 
52 124
int i2c_request(char dest);
53 125

  
54
void i2c_packet_rec (char i2c_byte);
55
void i2c_packet_sniff(char data);
56 126
#endif
57 127

  

Also available in: Unified diff