8 #ifndef TWI_NONBLOCK_H_ 9 #define TWI_NONBLOCK_H_ 11 #include <hardware_defines.h> 16 #include <compat/twi.h> 18 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 19 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 23 #define TWI_FREQ 100000L
26 #ifndef TWI_BUFFER_LENGTH 27 #define TWI_BUFFER_LENGTH 32
38 static volatile uint8_t twi_state;
39 static volatile uint8_t twi_oldstate;
41 static uint8_t twi_slarw;
43 static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
44 static volatile uint8_t twi_masterBufferIndex;
45 static uint8_t twi_masterBufferLength;
47 static volatile uint8_t twi_error;
49 #define BUFFER_LENGTH 32
50 static uint8_t rxBuffer[BUFFER_LENGTH];
51 static uint8_t rxBufferIndex = 0;
52 static uint8_t rxBufferLength = 0;
54 static uint8_t txAddress = 0;
55 static uint8_t txBuffer[BUFFER_LENGTH];
56 static uint8_t txBufferIndex = 0;
57 static uint8_t txBufferLength = 0;
59 static uint8_t transmitting;
62 void initialize_twi_nonblock();
64 uint8_t twowire_requestFrom(uint8_t address, uint8_t quantity);
65 void twowire_beginTransmission( uint8_t address );
66 void twowire_send( uint8_t data );
67 uint8_t twowire_endTransmission(
void);
70 uint8_t twi_initiateReadFrom(uint8_t address, uint8_t length);
71 void twi_continueReadFrom();
73 uint8_t twi_readMasterBuffer( uint8_t* data, uint8_t length );
75 uint8_t twi_initiateWriteTo(uint8_t address, uint8_t* data, uint8_t length );
76 void twi_continueWriteTo();
79 void twi_reply(uint8_t ack);
81 void twi_releaseBus(
void);
84 uint8_t twi_readFromBlocking(uint8_t address, uint8_t* data, uint8_t length);
85 uint8_t twi_writeToBlocking(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait);