1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-24 00:26:13 +01:00

Initial success

This commit is contained in:
peteGSX 2024-01-18 18:29:36 +10:00
parent 5959a8655c
commit 76734f7380
2 changed files with 16 additions and 16 deletions

View File

@ -147,35 +147,35 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t
const uint8_t writeBuffer[], uint8_t writeSize, I2CRB *rb) const uint8_t writeBuffer[], uint8_t writeSize, I2CRB *rb)
{ {
// DIAG(F("Read addr=%x rdBuf=%x, rdLen=%d, wrBuf=%x, wrLen=%d"), address, readBuffer, readSize, writeBuffer, writeSize); // DIAG(F("Read addr=%x rdBuf=%x, rdLen=%d, wrBuf=%x, wrLen=%d"), address, readBuffer, readSize, writeBuffer, writeSize);
DIAG(F("I2CManagerClass::read() hit")); // DIAG(F("I2CManagerClass::read() hit"));
uint8_t status, muxStatus; uint8_t status, muxStatus;
uint8_t nBytes = 0; uint8_t nBytes = 0;
uint8_t retryCount = 0; uint8_t retryCount = 0;
// If request fails, retry up to the defined limit, unless the NORETRY flag is set // If request fails, retry up to the defined limit, unless the NORETRY flag is set
// in the request block. // in the request block.
do { do {
DIAG(F("do hit")); // DIAG(F("do hit"));
status = muxStatus = I2C_STATUS_OK; status = muxStatus = I2C_STATUS_OK;
DIAG(F("status=%d"),status); // DIAG(F("status=%d"),status);
#ifdef I2C_EXTENDED_ADDRESS #ifdef I2C_EXTENDED_ADDRESS
DIAG(F("Extended address hit")); // DIAG(F("Extended address hit"));
if (address.muxNumber() != I2CMux_None) { if (address.muxNumber() != I2CMux_None) {
muxStatus = muxSelect(address); muxStatus = muxSelect(address);
} }
#endif #endif
// Only start new transaction if address is non-zero. // Only start new transaction if address is non-zero.
if (muxStatus == I2C_STATUS_OK && address != 0) { if (muxStatus == I2C_STATUS_OK && address != 0) {
DIAG(F("muxStatus=%d"),muxStatus); // DIAG(F("muxStatus=%d"),muxStatus);
if (writeSize > 0) { if (writeSize > 0) {
DIAG(F("wrBuf=%x, wrSize=%d"),writeBuffer,writeSize); // DIAG(F("wrBuf=%x, wrSize=%d"),writeBuffer,writeSize);
Wire.beginTransmission(address); Wire.beginTransmission(address);
Wire.write(writeBuffer, writeSize); Wire.write(writeBuffer, writeSize);
status = Wire.endTransmission(false); // Don't free bus yet status = Wire.endTransmission(false); // Don't free bus yet
DIAG(F("status=%d"),status); // DIAG(F("status=%d"),status);
} }
if (status == I2C_STATUS_OK) { if (status == I2C_STATUS_OK) {
#ifdef WIRE_HAS_TIMEOUT #ifdef WIRE_HAS_TIMEOUT
DIAG(F("WIRE_HAS_TIMEOUT")); // DIAG(F("WIRE_HAS_TIMEOUT"));
Wire.clearWireTimeoutFlag(); Wire.clearWireTimeoutFlag();
Wire.requestFrom(address, (size_t)readSize); Wire.requestFrom(address, (size_t)readSize);
if (!Wire.getWireTimeoutFlag()) { if (!Wire.getWireTimeoutFlag()) {
@ -186,16 +186,16 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t
status = I2C_STATUS_TIMEOUT; status = I2C_STATUS_TIMEOUT;
} }
#else #else
DIAG(F("NO timeout")); // DIAG(F("NO timeout"));
Wire.requestFrom(address, (size_t)readSize); Wire.requestFrom(address, (size_t)readSize);
DIAG(F("address=%x, nBytes=%d, readSize=%d"),address,nBytes,readSize); // DIAG(F("address=%x, nBytes=%d, readSize=%d"),address,nBytes,readSize);
DIAG(F("Wire.available()=%d"),Wire.available()); // DIAG(F("Wire.available()=%d"),Wire.available());
// while (Wire.available() && nBytes < readSize) // while (Wire.available() && nBytes < readSize)
while (nBytes < readSize) while (nBytes < readSize)
if (Wire.available()) { if (Wire.available()) {
// uint8_t temp=nBytes; // uint8_t temp=nBytes;
char readByte=Wire.read(); char readByte=Wire.read();
DIAG(F("nBytes=%d, readByte=%d"),nBytes,readByte); // DIAG(F("nBytes=%d, readByte=%d"),nBytes,readByte);
// readBuffer[nBytes++] = Wire.read(); // readBuffer[nBytes++] = Wire.read();
readBuffer[nBytes++]=readByte; readBuffer[nBytes++]=readByte;
// DIAG(F("nBytes=%d, readBuffer[nBytes]=%d"), temp, readBuffer[temp]); // DIAG(F("nBytes=%d, readBuffer[nBytes]=%d"), temp, readBuffer[temp]);
@ -204,7 +204,7 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t
} }
// DIAG(F("nBytes=%d,readBuffer[nBytes]=%d"),nBytes-1,readBuffer[nBytes-1]); // DIAG(F("nBytes=%d,readBuffer[nBytes]=%d"),nBytes-1,readBuffer[nBytes-1]);
if (nBytes < readSize) status = I2C_STATUS_TRUNCATED; if (nBytes < readSize) status = I2C_STATUS_TRUNCATED;
DIAG(F("status=%d"),status); // DIAG(F("status=%d"),status);
#endif #endif
} }
} }
@ -234,7 +234,7 @@ uint8_t I2CManagerClass::read(I2CAddress address, uint8_t readBuffer[], uint8_t
* the non-blocking version. * the non-blocking version.
***************************************************************************/ ***************************************************************************/
void I2CManagerClass::queueRequest(I2CRB *req) { void I2CManagerClass::queueRequest(I2CRB *req) {
DIAG(F("I2CManagerClass::queueRequest() hit")); // DIAG(F("I2CManagerClass::queueRequest() hit"));
if (req==NULL) { if (req==NULL) {
DIAG(F("NOOOOOOOOOOO")); DIAG(F("NOOOOOOOOOOO"));
return; return;

View File

@ -252,7 +252,7 @@ private:
// Issue new read request for digital states. As the request is non-blocking, the buffer has to // Issue new read request for digital states. As the request is non-blocking, the buffer has to
// be allocated from heap (object state). // be allocated from heap (object state).
_readCommandBuffer[0] = EXIORDD; _readCommandBuffer[0] = EXIORDD;
DIAG(F("EXIORDD address=%x, states=%d, bytes=%d"),_I2CAddress,_digitalInputStates,(_numDigitalPins+7)/8); // DIAG(F("EXIORDD address=%x, states=%d, bytes=%d"),_I2CAddress,_digitalInputStates,(_numDigitalPins+7)/8);
I2CManager.read(_I2CAddress, _digitalInputStates, (_numDigitalPins+7)/8, _readCommandBuffer, 1, &_i2crb); I2CManager.read(_I2CAddress, _digitalInputStates, (_numDigitalPins+7)/8, _readCommandBuffer, 1, &_i2crb);
// non-blocking read // non-blocking read
_lastDigitalRead = currentMicros; _lastDigitalRead = currentMicros;
@ -260,7 +260,7 @@ private:
} else if (currentMicros - _lastAnalogueRead > _analogueRefresh && _numAnaloguePins>0) { // Delay for analogue read refresh } else if (currentMicros - _lastAnalogueRead > _analogueRefresh && _numAnaloguePins>0) { // Delay for analogue read refresh
// Issue new read for analogue input states // Issue new read for analogue input states
_readCommandBuffer[0] = EXIORDAN; _readCommandBuffer[0] = EXIORDAN;
DIAG(F("EXIORDAN address=%x, aBuffer=%d, bytes=%d"),_I2CAddress,_analogueInputBuffer,_numAnaloguePins*2); // DIAG(F("EXIORDAN address=%x, aBuffer=%d, bytes=%d"),_I2CAddress,_analogueInputBuffer,_numAnaloguePins*2);
I2CManager.read(_I2CAddress, _analogueInputBuffer, I2CManager.read(_I2CAddress, _analogueInputBuffer,
_numAnaloguePins * 2, _readCommandBuffer, 1, &_i2crb); _numAnaloguePins * 2, _readCommandBuffer, 1, &_i2crb);
_lastAnalogueRead = currentMicros; _lastAnalogueRead = currentMicros;