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
|
//Send data
|
||||||
sercom->I2CS.DATA.bit.DATA = data;
|
sercom->I2CS.DATA.bit.DATA = data;
|
||||||
|
|
||||||
//Wait data transmission successful
|
|
||||||
while(!sercom->I2CS.INTFLAG.bit.DRDY);
|
|
||||||
|
|
||||||
//Problems on line? nack received?
|
//Problems on line? nack received?
|
||||||
if(sercom->I2CS.STATUS.bit.RXNACK)
|
if(!sercom->I2CS.INTFLAG.bit.DRDY || sercom->I2CS.STATUS.bit.RXNACK)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,6 @@ uint8_t TwoWire::endTransmission()
|
||||||
|
|
||||||
size_t TwoWire::write(uint8_t ucData)
|
size_t TwoWire::write(uint8_t ucData)
|
||||||
{
|
{
|
||||||
if(sercom->isMasterWIRE())
|
|
||||||
{
|
|
||||||
// No writing, without begun transmission or a full buffer
|
// No writing, without begun transmission or a full buffer
|
||||||
if ( !transmissionBegun || txBuffer.isFull() )
|
if ( !transmissionBegun || txBuffer.isFull() )
|
||||||
{
|
{
|
||||||
|
|
@ -164,16 +162,6 @@ size_t TwoWire::write(uint8_t ucData)
|
||||||
txBuffer.store_char( ucData ) ;
|
txBuffer.store_char( ucData ) ;
|
||||||
|
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(sercom->sendDataSlaveWIRE( ucData ))
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t TwoWire::write(const uint8_t *data, size_t quantity)
|
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 ?
|
if(sercom->isMasterReadOperationWIRE()) //Is a request ?
|
||||||
{
|
{
|
||||||
// wait for data ready flag,
|
txBuffer.clear();
|
||||||
// before calling request callback
|
|
||||||
while(!sercom->isDataReadyWIRE());
|
transmissionBegun = true;
|
||||||
|
|
||||||
//Calling onRequestCallback, if exists
|
//Calling onRequestCallback, if exists
|
||||||
if(onRequestCallback)
|
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()) {
|
if (rxBuffer.isFull()) {
|
||||||
sercom->prepareNackBitWIRE();
|
sercom->prepareNackBitWIRE();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -271,6 +269,7 @@ void TwoWire::onService(void)
|
||||||
sercom->prepareCommandBitsWire(0x03);
|
sercom->prepareCommandBitsWire(0x03);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WIRE_INTERFACES_COUNT > 0
|
#if WIRE_INTERFACES_COUNT > 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue