Project

General

Profile

Revision 1345

Added by Rich Hong almost 11 years ago

Final spline code for master/slave

updated outdated libdragonfly and libwireless

View differences:

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

  

Also available in: Unified diff