Created
November 13, 2014 15:40
-
-
Save patrickelectric/bfa006d9bc68281d07e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Function twi_transmit | |
* Desc fills slave tx buffer with data | |
* must be called in slave tx event callback | |
* Input data: pointer to byte array | |
* length: number of bytes in array | |
* Output 1 length too long for buffer | |
* 2 not slave transmitter | |
* 0 ok | |
*/ | |
uint8_t twi_transmit(const uint8_t* data, uint8_t length) | |
{ | |
uint8_t i; | |
// ensure data will fit into buffer | |
if(TWI_BUFFER_LENGTH < length){ | |
return 1; | |
} | |
// ensure we are currently a slave transmitter | |
if(TWI_STX != twi_state){ | |
return 2; | |
} | |
// set length and copy data into tx buffer | |
twi_txBufferLength = length; | |
for(i = 0; i < length; ++i){ | |
twi_txBuffer[i] = data[i]; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment