13 #ifndef TWI_NONBLOCK_H_
14 #define TWI_NONBLOCK_H_
16 #include <hardware_defines.h>
21 #include <compat/twi.h>
23 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
24 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
28 #define TWI_FREQ 100000L
31 #ifndef TWI_BUFFER_LENGTH
32 #define TWI_BUFFER_LENGTH 32
43 static volatile uint8_t twi_state;
44 static volatile uint8_t twi_oldstate;
46 static uint8_t twi_slarw;
48 static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH];
49 static volatile uint8_t twi_masterBufferIndex;
50 static uint8_t twi_masterBufferLength;
52 static volatile uint8_t twi_error;
54 #define BUFFER_LENGTH 32
55 static uint8_t rxBuffer[BUFFER_LENGTH];
56 static uint8_t rxBufferIndex = 0;
57 static uint8_t rxBufferLength = 0;
59 static uint8_t txAddress = 0;
60 static uint8_t txBuffer[BUFFER_LENGTH];
61 static uint8_t txBufferIndex = 0;
62 static uint8_t txBufferLength = 0;
64 static uint8_t transmitting;
67 void initialize_twi_nonblock();
69 uint8_t twowire_requestFrom(uint8_t address, uint8_t quantity);
70 void twowire_beginTransmission( uint8_t address );
71 void twowire_send( uint8_t data );
72 uint8_t twowire_endTransmission(
void);
75 uint8_t twi_initiateReadFrom(uint8_t address, uint8_t length);
76 void twi_continueReadFrom();
78 uint8_t twi_readMasterBuffer( uint8_t* data, uint8_t length );
80 uint8_t twi_initiateWriteTo(uint8_t address, uint8_t* data, uint8_t length );
81 void twi_continueWriteTo();
84 void twi_reply(uint8_t ack);
86 void twi_releaseBus(
void);
89 uint8_t twi_readFromBlocking(uint8_t address, uint8_t* data, uint8_t length);
90 uint8_t twi_writeToBlocking(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait);
94 #if !defined _MOZZI_TWI_HEADER_ONLY
95 #include "internal/twi_nonblock.hpp"