TwoWire Class Reference

#include <Wire.h>


Public Member Functions

 TwoWire ()
void begin ()
void begin (uint8_t)
void begin (int)
void beginTransmission (uint8_t)
void beginTransmission (int)
void endTransmission (void)
void requestFrom (uint8_t, uint8_t)
void requestFrom (int, int)
void send (uint8_t)
void send (uint8_t *, uint8_t)
void send (int)
void send (char *)
uint8_t available (void)
uint8_t receive (void)
void onReceive (void(*)(int))
void onRequest (void(*)(void))
void close ()

Static Private Member Functions

static void onRequestService (void)
static void onReceiveService (uint8_t *, int)

Static Private Attributes

static uint8_t * rxBuffer = 0
static uint8_t rxBufferIndex = 0
static uint8_t rxBufferLength = 0
static uint8_t txAddress = 0
static uint8_t * txBuffer = 0
static uint8_t txBufferIndex = 0
static uint8_t txBufferLength = 0
static uint8_t transmitting = 0
static void(* user_onRequest )(void)
static void(* user_onReceive )(int)


Detailed Description

Definition at line 28 of file Wire.h.


Constructor & Destructor Documentation

TwoWire::TwoWire (  ) 

Definition at line 52 of file Wire.cpp.

00053 {
00054 }


Member Function Documentation

void TwoWire::onRequestService ( void   )  [static, private]

Definition at line 239 of file Wire.cpp.

References txBufferIndex, txBufferLength, and user_onRequest.

Referenced by begin().

00240 {
00241   // don't bother if user hasn't registered a callback
00242   if(!user_onRequest){
00243     return;
00244   }
00245   // reset tx buffer iterator vars
00246   // !!! this will kill any pending pre-master sendTo() activity
00247   txBufferIndex = 0;
00248   txBufferLength = 0;
00249   // alert user program
00250   user_onRequest();
00251 }

Here is the caller graph for this function:

void TwoWire::onReceiveService ( uint8_t *  inBytes,
int  numBytes 
) [static, private]

Definition at line 214 of file Wire.cpp.

References rxBuffer, rxBufferIndex, rxBufferLength, and user_onReceive.

Referenced by begin().

00215 {
00216   // don't bother if user hasn't registered a callback
00217   if(!user_onReceive){
00218     return;
00219   }
00220   // don't bother if rx buffer is in use by a master requestFrom() op
00221   // i know this drops data, but it allows for slight stupidity
00222   // meaning, they may not have read all the master requestFrom() data yet
00223   if(rxBufferIndex < rxBufferLength){
00224     return;
00225   }
00226   // copy twi rx buffer into local read buffer
00227   // this enables new reads to happen in parallel
00228   for(uint8_t i = 0; i < numBytes; ++i){
00229     rxBuffer[i] = inBytes[i];    
00230   }
00231   // set rx iterator vars
00232   rxBufferIndex = 0;
00233   rxBufferLength = numBytes;
00234   // alert user program
00235   user_onReceive(numBytes);
00236 }

Here is the caller graph for this function:

void TwoWire::begin ( void   ) 

Definition at line 58 of file Wire.cpp.

References BUFFER_LENGTH, rxBuffer, rxBufferIndex, rxBufferLength, twi_init(), txBuffer, txBufferIndex, and txBufferLength.

Referenced by begin(), WaspRTC::begin(), WaspACC::begin(), WaspSensorPrototyping::readADC(), WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspSensorAgr::readRadiation(), WaspSensorGas::setAmplifier(), WaspSensorPrototyping::setAmplifierGain(), WaspSensorAgr::setDigipot(), WaspSensorEvent::setDigipot0(), WaspSensorEvent::setDigipot1(), WaspSensorPrototyping::setLoadResistor(), WaspPWR::setLowBatteryThreshold(), and WaspSensorGas::setResistor().

00059 {
00060   // init buffer for reads
00061   rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
00062   rxBufferIndex = 0;
00063   rxBufferLength = 0;
00064 
00065   // init buffer for writes
00066   txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
00067   txBufferIndex = 0;
00068   txBufferLength = 0;
00069 
00070   twi_init();
00071 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TwoWire::begin ( uint8_t  address  ) 

Definition at line 73 of file Wire.cpp.

References begin(), onReceiveService(), onRequestService(), twi_attachSlaveRxEvent(), twi_attachSlaveTxEvent(), and twi_setAddress().

Here is the call graph for this function:

void TwoWire::begin ( int  address  ) 

Definition at line 81 of file Wire.cpp.

References begin().

00082 {
00083   begin((uint8_t)address);
00084 }

Here is the call graph for this function:

void TwoWire::beginTransmission ( uint8_t  address  ) 

void TwoWire::beginTransmission ( int  address  ) 

Definition at line 115 of file Wire.cpp.

References beginTransmission().

00116 {
00117   beginTransmission((uint8_t)address);
00118 }

Here is the call graph for this function:

void TwoWire::endTransmission ( void   ) 

void TwoWire::requestFrom ( uint8_t  address,
uint8_t  quantity 
)

Definition at line 86 of file Wire.cpp.

References BUFFER_LENGTH, rxBuffer, rxBufferIndex, rxBufferLength, and twi_readFrom().

Referenced by WaspSensorPrototyping::readADC(), WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspSensorAgr::readRadiation(), WaspACC::readRegister(), WaspRTC::readRTC(), WaspRTC::readRTCregister(), and requestFrom().

00087 {
00088   // clamp to buffer length
00089   if(quantity > BUFFER_LENGTH){
00090     quantity = BUFFER_LENGTH;
00091   }
00092   // perform blocking read into buffer
00093   twi_readFrom(address, rxBuffer, quantity);
00094   // set rx buffer iterator vars
00095   rxBufferIndex = 0;
00096   rxBufferLength = quantity;
00097 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TwoWire::requestFrom ( int  address,
int  quantity 
)

Definition at line 99 of file Wire.cpp.

References requestFrom().

00100 {
00101   requestFrom((uint8_t)address, (uint8_t)quantity);
00102 }

Here is the call graph for this function:

void TwoWire::send ( uint8_t  data  ) 

Definition at line 134 of file Wire.cpp.

References BUFFER_LENGTH, transmitting, twi_transmit(), txBuffer, txBufferIndex, and txBufferLength.

Referenced by WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspACC::readRegister(), WaspRTC::readRTC(), WaspRTC::readRTCregister(), send(), WaspSensorGas::setAmplifier(), WaspSensorPrototyping::setAmplifierGain(), WaspSensorAgr::setDigipot(), WaspSensorEvent::setDigipot0(), WaspSensorEvent::setDigipot1(), WaspSensorPrototyping::setLoadResistor(), WaspPWR::setLowBatteryThreshold(), WaspSensorGas::setResistor(), WaspACC::writeRegister(), WaspRTC::writeRTC(), WaspRTC::writeRTCalarm1(), WaspRTC::writeRTCalarm2(), and WaspRTC::writeRTCregister().

00135 {
00136   if(transmitting){
00137   // in master transmitter mode
00138     // don't bother if buffer is full
00139     if(txBufferLength >= BUFFER_LENGTH){
00140       return;
00141     }
00142     // put byte in tx buffer
00143     txBuffer[txBufferIndex] = data;
00144     ++txBufferIndex;
00145     // update amount in buffer   
00146     txBufferLength = txBufferIndex;
00147   }else{
00148   // in slave send mode
00149     // reply to master
00150     twi_transmit(&data, 1);
00151   }
00152 }

Here is the call graph for this function:

Here is the caller graph for this function:

void TwoWire::send ( uint8_t *  data,
uint8_t  quantity 
)

Definition at line 157 of file Wire.cpp.

References send(), transmitting, and twi_transmit().

00158 {
00159   if(transmitting){
00160   // in master transmitter mode
00161     for(uint8_t i = 0; i < quantity; ++i){
00162       send(data[i]);
00163     }
00164   }else{
00165   // in slave send mode
00166     // reply to master
00167     twi_transmit(data, quantity);
00168   }
00169 }

Here is the call graph for this function:

void TwoWire::send ( int  data  ) 

Definition at line 182 of file Wire.cpp.

References send().

00183 {
00184   send((uint8_t)data);
00185 }

Here is the call graph for this function:

void TwoWire::send ( char *  data  ) 

Definition at line 174 of file Wire.cpp.

References send().

00175 {
00176   send((uint8_t*)data, strlen(data));
00177 }

Here is the call graph for this function:

uint8_t TwoWire::available ( void   ) 

uint8_t TwoWire::receive ( void   ) 

Definition at line 198 of file Wire.cpp.

References rxBuffer, rxBufferIndex, and rxBufferLength.

Referenced by WaspSensorPrototyping::readADC(), WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspSensorAgr::readRadiation(), WaspACC::readRegister(), WaspRTC::readRTC(), and WaspRTC::readRTCregister().

00199 {
00200   // default to returning null char
00201   // for people using with char strings
00202   uint8_t value = '\0';
00203   
00204   // get each successive byte on each call
00205   if(rxBufferIndex < rxBufferLength){
00206     value = rxBuffer[rxBufferIndex];
00207     ++rxBufferIndex;
00208   }
00209 
00210   return value;
00211 }

Here is the caller graph for this function:

void TwoWire::onReceive ( void(*)(int)  function  ) 

Definition at line 254 of file Wire.cpp.

References user_onReceive.

00255 {
00256   user_onReceive = function;
00257 }

void TwoWire::onRequest ( void(*)(void)  function  ) 

Definition at line 260 of file Wire.cpp.

References user_onRequest.

00261 {
00262   user_onRequest = function;
00263 }

void TwoWire::close ( void   ) 

Definition at line 265 of file Wire.cpp.

References rxBuffer, twi_close(), and txBuffer.

Referenced by WaspPWR::closeI2C().

00266 {
00267         free(rxBuffer);
00268         free(txBuffer);
00269         twi_close();
00270 }

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

uint8_t * TwoWire::rxBuffer = 0 [static, private]

Definition at line 31 of file Wire.h.

Referenced by begin(), close(), onReceiveService(), receive(), and requestFrom().

uint8_t TwoWire::rxBufferIndex = 0 [static, private]

Definition at line 32 of file Wire.h.

Referenced by available(), begin(), onReceiveService(), receive(), and requestFrom().

uint8_t TwoWire::rxBufferLength = 0 [static, private]

Definition at line 33 of file Wire.h.

Referenced by available(), begin(), onReceiveService(), receive(), and requestFrom().

uint8_t TwoWire::txAddress = 0 [static, private]

Definition at line 35 of file Wire.h.

Referenced by beginTransmission(), and endTransmission().

uint8_t * TwoWire::txBuffer = 0 [static, private]

Definition at line 36 of file Wire.h.

Referenced by begin(), close(), endTransmission(), and send().

uint8_t TwoWire::txBufferIndex = 0 [static, private]

Definition at line 37 of file Wire.h.

Referenced by begin(), beginTransmission(), endTransmission(), onRequestService(), and send().

uint8_t TwoWire::txBufferLength = 0 [static, private]

Definition at line 38 of file Wire.h.

Referenced by begin(), beginTransmission(), endTransmission(), onRequestService(), and send().

uint8_t TwoWire::transmitting = 0 [static, private]

Definition at line 40 of file Wire.h.

Referenced by beginTransmission(), endTransmission(), and send().

void(* TwoWire::user_onRequest)(void) ( void   )  [static, private]

Referenced by onRequest(), and onRequestService().

void(* TwoWire::user_onReceive)(int) ( int   )  [static, private]

Referenced by onReceive(), and onReceiveService().


The documentation for this class was generated from the following files:

Generated on Tue Jul 20 09:31:01 2010 for WaspmoteAPI by  doxygen 1.5.6