g_APinDescription[PIN_WIRE_SDA].ulPinType, g_APinDescription[PIN_WIRE_SDA].ulPin, g_APinDescription[PIN_WIRE_SDA].ulPinConfiguration); PIO_Configure( g_APinDescription[PIN_WIRE_SCL].pPort, g_APinDescription[PIN_WIRE_SCL].ulPinType, g_APinDescription[PIN_WIRE_SCL].ulPin, g_APinDescription[PIN_WIRE_SCL].ulPinConfiguration); NVIC_DisableIRQ(WIRE_ISR_ID); NVIC_ClearPendingIRQ(WIRE_ISR_ID); NVIC_SetPriority(WIRE_ISR_ID, 0); NVIC_EnableIRQ(WIRE_ISR_ID); } TwoWire Wire = TwoWire(WIRE_INTERFACE, Wire_Init); void WIRE_ISR_HANDLER(void) { Wire.onService(); } #endif #if WIRE_INTERFACES_COUNT > 1 static void Wire1_Init(void) { pmc_enable_periph_clk(WIRE1_INTERFACE_ID); PIO_Configure( g_APinDescription[PIN_WIRE1_SDA].pPort, g_APinDescription[PIN_WIRE1_SDA].ulPinType, g_APinDescription[PIN_WIRE1_SDA].ulPin, g_APinDescription[PIN_WIRE1_SDA].ulPinConfiguration); PIO_Configure(
void TwoWire::onRequestService(void) { // don't bother if user hasn't registered a callback if(!user_onRequest){ return; } // reset tx buffer iterator vars // !!! this will kill any pending pre-master sendTo() activity txBufferIndex = 0; txBufferLength = 0; // alert user program user_onRequest(); } // sets function called on slave write void TwoWire::onReceive( void (*function)(int) ) { user_onReceive = function; } // sets function called on slave read void TwoWire::onRequest( void (*function)(void) ) { user_onRequest = function; } // Preinstantiate Objects ////////////////////////////////////////////////////// TwoWire Wire = TwoWire();
rxBuffer[i] = srvBuffer[i]; rxBufferIndex = 0; rxBufferLength = srvBufferLength; // Alert calling program onReceiveCallback( rxBufferLength); } I2C_ITConfig(twi, I2C_IT_ADDRI, ENABLE); I2C_ITConfig(twi, I2C_IT_RXI | I2C_IT_TXI | I2C_IT_STOPI, DISABLE); I2C_ClearITPendingBit(twi, I2C_IT_STOPF); } } TwoWire Wire = TwoWire(I2C1); TwoWire Wire1 = TwoWire(I2C2); #ifdef __cplusplus extern "C" { #endif void WIRE_ISR_HANDLER(void) { Wire.onService(); } void WIRE1_ISR_HANDLER(void) { Wire1.onService(); } #ifdef __cplusplus } #endif
++rxIndex; } return value; } int TwoWire::peek(void) { int value = -1; if(rxIndex < rxLength) { value = rxBuffer[rxIndex]; } return value; } void TwoWire::flush(void) { rxIndex = 0; rxLength = 0; txIndex = 0; txLength = 0; } void TwoWire::reset(void) { i2cReset( i2c ); i2c = NULL; begin( sda, scl ); } TwoWire Wire = TwoWire(0);
} void TwoWire::onRequest(void(*function)(void)) { onRequestCallback = function; } void TwoWire::onService(void) { } //#if WIRE_INTERFACES_COUNT > 0 static void Wire_Init(void) { } TwoWire Wire = TwoWire(Wire_Init); void WIRE_ISR_HANDLER(void) { Wire.onService(); } //#endif #if WIRE_INTERFACES_COUNT > 1 static void Wire1_Init(void) { if ((adapter_nr = i2c_getadapter(I2C1)) < 0) { return; } if ((i2c_fd = i2c_openadapter(adapter_nr)) < 0) { return; }
PCF85xx::PCF85xx() { this->init(TwoWire(), &this->defaultTimeSaver); }
bool found = false; char * message = (char*)&ERRORTEXT; while(!found && message[0]) { found = t == err; if(!found) { message = message + strlen(message) + 1; t++; } } if(!found) { return NULL; } else { return message; } } /*stickbreaker Dump i2c Interrupt buffer, i2c isr Debugging */ uint32_t TwoWire::setDebugFlags( uint32_t setBits, uint32_t resetBits){ return i2cDebug(i2c,setBits,resetBits); } bool TwoWire::busy(void){ return ((i2cGetStatus(i2c) & 16 )==16); } TwoWire Wire = TwoWire(0); TwoWire Wire1 = TwoWire(1);