Use TX buffer for slave writes, empty on master read mode + DRDY IRQ
This commit is contained in:
parent
214f990bdb
commit
e5166fb922
2 changed files with 30 additions and 34 deletions
|
|
@ -557,11 +557,8 @@ bool SERCOM::sendDataSlaveWIRE(uint8_t data)
|
|||
//Send data
|
||||
sercom->I2CS.DATA.bit.DATA = data;
|
||||
|
||||
//Wait data transmission successful
|
||||
while(!sercom->I2CS.INTFLAG.bit.DRDY);
|
||||
|
||||
//Problems on line? nack received?
|
||||
if(sercom->I2CS.STATUS.bit.RXNACK)
|
||||
if(!sercom->I2CS.INTFLAG.bit.DRDY || sercom->I2CS.STATUS.bit.RXNACK)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -152,8 +152,6 @@ uint8_t TwoWire::endTransmission()
|
|||
}
|
||||
|
||||
size_t TwoWire::write(uint8_t ucData)
|
||||
{
|
||||
if(sercom->isMasterWIRE())
|
||||
{
|
||||
// No writing, without begun transmission or a full buffer
|
||||
if ( !transmissionBegun || txBuffer.isFull() )
|
||||
|
|
@ -165,16 +163,6 @@ size_t TwoWire::write(uint8_t ucData)
|
|||
|
||||
return 1 ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(sercom->sendDataSlaveWIRE( ucData ))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t TwoWire::write(const uint8_t *data, size_t quantity)
|
||||
{
|
||||
|
|
@ -246,9 +234,9 @@ void TwoWire::onService(void)
|
|||
|
||||
if(sercom->isMasterReadOperationWIRE()) //Is a request ?
|
||||
{
|
||||
// wait for data ready flag,
|
||||
// before calling request callback
|
||||
while(!sercom->isDataReadyWIRE());
|
||||
txBuffer.clear();
|
||||
|
||||
transmissionBegun = true;
|
||||
|
||||
//Calling onRequestCallback, if exists
|
||||
if(onRequestCallback)
|
||||
|
|
@ -257,8 +245,18 @@ void TwoWire::onService(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
else if(sercom->isDataReadyWIRE()) //Received data
|
||||
else if(sercom->isDataReadyWIRE())
|
||||
{
|
||||
if (sercom->isMasterReadOperationWIRE())
|
||||
{
|
||||
uint8_t c = 0xff;
|
||||
|
||||
if( txBuffer.available() ) {
|
||||
c = txBuffer.read_char();
|
||||
}
|
||||
|
||||
transmissionBegun = sercom->sendDataSlaveWIRE(c);
|
||||
} else { //Received data
|
||||
if (rxBuffer.isFull()) {
|
||||
sercom->prepareNackBitWIRE();
|
||||
} else {
|
||||
|
|
@ -272,6 +270,7 @@ void TwoWire::onService(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if WIRE_INTERFACES_COUNT > 0
|
||||
/* In case new variant doesn't define these macros,
|
||||
|
|
|
|||
Loading…
Reference in a new issue