Skip to content

Commit c2662e3

Browse files
sandeepmistryfacchinm
authored andcommitted
Remove use of slave_bytesToWrite and slave_writeData in Wire.cpp
1 parent 0a174fe commit c2662e3

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

libraries/Wire/src/Wire.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void TwoWire::begin(uint8_t address)
7575

7676
TWI_SlaveInit(address);
7777

78-
TWI_attachSlaveTxEvent(onRequestService); // default callback must exist
78+
TWI_attachSlaveTxEvent(onRequestService, txBuffer); // default callback must exist
7979
TWI_attachSlaveRxEvent(onReceiveService, rxBuffer, BUFFER_LENGTH); // default callback must exist
8080

8181
}
@@ -291,11 +291,11 @@ void TwoWire::onReceiveService(int numBytes)
291291
}
292292

293293
// behind the scenes function that is called when data is requested
294-
void TwoWire::onRequestService(void)
294+
uint8_t TwoWire::onRequestService(void)
295295
{
296296
// don't bother if user hasn't registered a callback
297297
if(!user_onRequest){
298-
return;
298+
return 0;
299299
}
300300

301301
// reset slave write buffer iterator var
@@ -305,8 +305,7 @@ void TwoWire::onRequestService(void)
305305
// alert user program
306306
user_onRequest();
307307

308-
slave_bytesToWrite = txBufferLength;
309-
slave_writeData = txBuffer;
308+
return txBufferLength;
310309
}
311310

312311
// sets function called on slave write

libraries/Wire/src/Wire.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class TwoWire : public HardwareI2C
4444
static uint8_t transmitting;
4545
static void (*user_onRequest)(void);
4646
static void (*user_onReceive)(int);
47-
static void onRequestService(void);
47+
static uint8_t onRequestService(void);
4848
static void onReceiveService(int);
4949
public:
5050
TwoWire();

libraries/Wire/src/utility/twi.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void TWI_SlaveAddressMatchHandler(){
577577
if(TWI0.SSTATUS & TWI_DIR_bm){
578578
slave_bytesWritten = 0;
579579
/* Call user function */
580-
TWI_onSlaveTransmit();
580+
slave_bytesToWrite = TWI_onSlaveTransmit();
581581
twi_mode = TWI_MODE_SLAVE_TRANSMIT;
582582
}
583583
/* If Master Write/Slave Read */
@@ -709,8 +709,9 @@ void TWI_attachSlaveRxEvent( void (*function)(int), uint8_t *read_data, uint8_t
709709
* Input function: callback function to use
710710
* Output none
711711
*/
712-
void TWI_attachSlaveTxEvent( void (*function)(void) ){
712+
void TWI_attachSlaveTxEvent( uint8_t (*function)(void), uint8_t* write_data ){
713713
TWI_onSlaveTransmit = function;
714+
slave_writeData = write_data;
714715
}
715716

716717

libraries/Wire/src/utility/twi.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ register8_t master_trans_status; /*!< Status of transactio
8282
register8_t master_result; /*!< Result of transaction */
8383

8484
/* Slave variables */
85-
static void (*TWI_onSlaveTransmit)(void) __attribute__((unused));
85+
static uint8_t (*TWI_onSlaveTransmit)(void) __attribute__((unused));
8686
static void (*TWI_onSlaveReceive)(int) __attribute__((unused));
8787
register8_t* slave_writeData;
8888
register8_t* slave_readData;
@@ -135,7 +135,7 @@ void TWI_SlaveDataHandler(void);
135135
void TWI_SlaveWriteHandler(void);
136136
void TWI_SlaveReadHandler(void);
137137
void TWI_attachSlaveRxEvent( void (*function)(int), uint8_t *read_data, uint8_t bytes_to_read );
138-
void TWI_attachSlaveTxEvent( void (*function)(void) );
138+
void TWI_attachSlaveTxEvent( uint8_t (*function)(void), uint8_t *write_data );
139139
void TWI_SlaveTransactionFinished(uint8_t result);
140140
/*! TWI master interrupt service routine.
141141
*

0 commit comments

Comments
 (0)