@@ -58,7 +58,7 @@ static volatile bool twi_do_reset_on_timeout = false; // reset the TWI register
58
58
static void (* twi_onSlaveTransmit )(void );
59
59
static void (* twi_onSlaveReceive )(uint8_t * , int );
60
60
61
- static uint8_t twi_masterBuffer [ TWI_BUFFER_LENGTH ] ;
61
+ static uint8_t * twi_masterBuffer ;
62
62
static volatile uint8_t twi_masterBufferIndex ;
63
63
static volatile uint8_t twi_masterBufferLength ;
64
64
@@ -158,8 +158,6 @@ void twi_setFrequency(uint32_t frequency)
158
158
*/
159
159
uint8_t twi_readFrom (uint8_t address , uint8_t * data , uint8_t length , uint8_t sendStop )
160
160
{
161
- uint8_t i ;
162
-
163
161
// ensure data will fit into buffer
164
162
if (TWI_BUFFER_LENGTH < length ){
165
163
return 0 ;
@@ -179,6 +177,7 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
179
177
twi_error = 0xFF ;
180
178
181
179
// initialize buffer iteration vars
180
+ twi_masterBuffer = data ;
182
181
twi_masterBufferIndex = 0 ;
183
182
twi_masterBufferLength = length - 1 ; // This is not intuitive, read on...
184
183
// On receive, the previously configured ACK/NACK setting is transmitted in
@@ -226,11 +225,6 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
226
225
length = twi_masterBufferIndex ;
227
226
}
228
227
229
- // copy twi buffer to data
230
- for (i = 0 ; i < length ; ++ i ){
231
- data [i ] = twi_masterBuffer [i ];
232
- }
233
-
234
228
return length ;
235
229
}
236
230
@@ -252,8 +246,6 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
252
246
*/
253
247
uint8_t twi_writeTo (uint8_t address , uint8_t * data , uint8_t length , uint8_t wait , uint8_t sendStop )
254
248
{
255
- uint8_t i ;
256
-
257
249
// ensure data will fit into buffer
258
250
if (TWI_BUFFER_LENGTH < length ){
259
251
return 1 ;
@@ -273,14 +265,10 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
273
265
twi_error = 0xFF ;
274
266
275
267
// initialize buffer iteration vars
268
+ twi_masterBuffer = data ;
276
269
twi_masterBufferIndex = 0 ;
277
270
twi_masterBufferLength = length ;
278
271
279
- // copy data to twi buffer
280
- for (i = 0 ; i < length ; ++ i ){
281
- twi_masterBuffer [i ] = data [i ];
282
- }
283
-
284
272
// build sla+w, slave device address + w bit
285
273
twi_slarw = TW_WRITE ;
286
274
twi_slarw |= address << 1 ;
0 commit comments