#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) |
Definition at line 28 of file Wire.h.
| 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 }

| 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 }

| 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 }


| 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().
00074 { 00075 twi_setAddress(address); 00076 twi_attachSlaveTxEvent(onRequestService); 00077 twi_attachSlaveRxEvent(onReceiveService); 00078 begin(); 00079 }

| void TwoWire::begin | ( | int | address | ) |
| void TwoWire::beginTransmission | ( | uint8_t | address | ) |
Definition at line 104 of file Wire.cpp.
References transmitting, txAddress, txBufferIndex, and txBufferLength.
Referenced by beginTransmission(), WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspACC::readRegister(), WaspRTC::readRTC(), WaspRTC::readRTCregister(), 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().
00105 { 00106 // indicate that we are transmitting 00107 transmitting = 1; 00108 // set address of targeted slave 00109 txAddress = address; 00110 // reset tx buffer iterator vars 00111 txBufferIndex = 0; 00112 txBufferLength = 0; 00113 }

| void TwoWire::beginTransmission | ( | int | address | ) |
Definition at line 115 of file Wire.cpp.
References beginTransmission().
00116 { 00117 beginTransmission((uint8_t)address); 00118 }

| void TwoWire::endTransmission | ( | void | ) |
Definition at line 120 of file Wire.cpp.
References transmitting, twi_writeTo(), txAddress, txBuffer, txBufferIndex, and txBufferLength.
Referenced by WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspACC::readRegister(), WaspRTC::readRTC(), WaspRTC::readRTCregister(), 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().
00121 { 00122 // transmit buffer (blocking) 00123 twi_writeTo(txAddress, txBuffer, txBufferLength, 1); 00124 // reset tx buffer iterator vars 00125 txBufferIndex = 0; 00126 txBufferLength = 0; 00127 // indicate that we are done transmitting 00128 transmitting = 0; 00129 }


| 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 }


| 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 }

| 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 }


| 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 }

| void TwoWire::send | ( | int | data | ) |
| void TwoWire::send | ( | char * | data | ) |
| uint8_t TwoWire::available | ( | void | ) |
Definition at line 190 of file Wire.cpp.
References rxBufferIndex, and rxBufferLength.
Referenced by WaspSensorPrototyping::readADC(), WaspSensorAgr::readDendrometer(), WaspSensorAgr::readPT1000(), WaspSensorAgr::readRadiation(), WaspACC::readRegister(), WaspRTC::readRTC(), and WaspRTC::readRTCregister().
00191 { 00192 return rxBufferLength - rxBufferIndex; 00193 }

| 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 }

| 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().


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] |
uint8_t * TwoWire::txBuffer = 0 [static, private] |
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().
1.5.6