Revision 1496
Reverted "libdragonfly" folder back to version before Init Checking was implemented and did "make dist" to recompile the library. BOM LEDs now shine
correctly.
i2c.c | ||
---|---|---|
43 | 43 |
#include "i2c.h" |
44 | 44 |
#include "ring_buffer.h" |
45 | 45 |
|
46 |
//NOTE: this is here just to provide colony error codes, it can be safely removed |
|
47 |
// for use in another project |
|
48 |
#include <dragonfly_lib.h> |
|
49 |
|
|
50 | 46 |
/** |
51 | 47 |
* @defgroup i2c I2C |
52 | 48 |
* |
... | ... | |
82 | 78 |
*/ |
83 | 79 |
#define I2C_BIT_RATE_DIVIDER 0x0C |
84 | 80 |
|
85 |
unsigned char i2c_initd=0; |
|
86 |
|
|
87 | 81 |
static int start_flag; |
88 | 82 |
|
89 | 83 |
static fun_mrecv_t master_recv_function; |
... | ... | |
111 | 105 |
* @return 0 for success, nonzero for failure |
112 | 106 |
**/ |
113 | 107 |
int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send) { |
114 |
|
|
115 |
if(i2c_initd) |
|
116 |
return ERROR_INIT_ALREADY_INITD; |
|
117 |
|
|
118 |
|
|
119 | 108 |
master_recv_function = master_recv; |
120 | 109 |
slave_recv_function = slave_recv; |
121 | 110 |
slave_send_function = slave_send; |
... | ... | |
133 | 122 |
* global messages to be accepted */ |
134 | 123 |
TWAR = (addr << 1) | 1; |
135 | 124 |
|
136 |
i2c_initd = 1; |
|
137 | 125 |
return 0; |
138 | 126 |
} |
139 | 127 |
|
... | ... | |
153 | 141 |
int i2c_send(char dest, char *data, unsigned int bytes) { |
154 | 142 |
int i; |
155 | 143 |
|
156 |
if(!i2c_initd) |
|
157 |
return ERROR_LIBRARY_NOT_INITD; |
|
158 |
|
|
159 |
|
|
160 | 144 |
/* adding data to be sent to ring buffers is not atomic, |
161 | 145 |
* so disable interrupts */ |
162 | 146 |
cli(); |
... | ... | |
196 | 180 |
* @return 0 for success, nonzero for failure |
197 | 181 |
**/ |
198 | 182 |
int i2c_request(char dest) { |
199 |
if(!i2c_initd) |
|
200 |
return ERROR_LIBRARY_NOT_INITD; |
|
201 |
|
|
202 | 183 |
if(RING_BUFFER_FULL(i2c_write_buff)) |
203 | 184 |
return -1; |
204 | 185 |
|
Also available in: Unified diff