mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 21:01:25 +01:00
Merge pull request #288 from DCC-EX:debug-ex-io-expander-on-mega
Debug-ex-io-expander-on-mega
This commit is contained in:
commit
de4954ca3e
@ -66,19 +66,18 @@ private:
|
|||||||
_i2cAddress = i2cAddress;
|
_i2cAddress = i2cAddress;
|
||||||
_numDigitalPins = numDigitalPins;
|
_numDigitalPins = numDigitalPins;
|
||||||
_numAnaloguePins = numAnaloguePins;
|
_numAnaloguePins = numAnaloguePins;
|
||||||
int _dPinArrayLen = (_numDigitalPins + 7) / 8;
|
|
||||||
addDevice(this);
|
addDevice(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _begin() {
|
void _begin() {
|
||||||
// Initialise EX-IOExander device
|
// Initialise EX-IOExander device
|
||||||
uint8_t _check = I2CManager.checkAddress(_i2cAddress);
|
I2CManager.begin();
|
||||||
if (I2CManager.exists(_i2cAddress)) {
|
if (I2CManager.exists(_i2cAddress)) {
|
||||||
_digitalOutBuffer[0] = EXIOINIT;
|
_digitalOutBuffer[0] = EXIOINIT;
|
||||||
_digitalOutBuffer[1] = _numDigitalPins;
|
_digitalOutBuffer[1] = _numDigitalPins;
|
||||||
_digitalOutBuffer[2] = _numAnaloguePins;
|
_digitalOutBuffer[2] = _numAnaloguePins;
|
||||||
// Send config, if EXIORDY returned, we're good, otherwise go offline
|
// Send config, if EXIORDY returned, we're good, otherwise go offline
|
||||||
I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb);
|
I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3);
|
||||||
if (_digitalInBuffer[0] != EXIORDY) {
|
if (_digitalInBuffer[0] != EXIORDY) {
|
||||||
DIAG(F("ERROR configuring EX-IOExpander device, I2C:x%x"), _i2cAddress);
|
DIAG(F("ERROR configuring EX-IOExpander device, I2C:x%x"), _i2cAddress);
|
||||||
_deviceState = DEVSTATE_FAILED;
|
_deviceState = DEVSTATE_FAILED;
|
||||||
@ -87,7 +86,7 @@ private:
|
|||||||
// Attempt to get version, if we don't get it, we don't care, don't go offline
|
// Attempt to get version, if we don't get it, we don't care, don't go offline
|
||||||
// Using digital in buffer in reverse to save RAM
|
// Using digital in buffer in reverse to save RAM
|
||||||
_digitalInBuffer[0] = EXIOVER;
|
_digitalInBuffer[0] = EXIOVER;
|
||||||
I2CManager.read(_i2cAddress, _versionBuffer, 3, _digitalInBuffer, 1, &_i2crb);
|
I2CManager.read(_i2cAddress, _versionBuffer, 3, _digitalInBuffer, 1);
|
||||||
_majorVer = _versionBuffer[0];
|
_majorVer = _versionBuffer[0];
|
||||||
_minorVer = _versionBuffer[1];
|
_minorVer = _versionBuffer[1];
|
||||||
_patchVer = _versionBuffer[2];
|
_patchVer = _versionBuffer[2];
|
||||||
@ -105,11 +104,10 @@ private:
|
|||||||
if (paramCount != 1) return false;
|
if (paramCount != 1) return false;
|
||||||
bool pullup = params[0];
|
bool pullup = params[0];
|
||||||
int pin = vpin - _firstVpin;
|
int pin = vpin - _firstVpin;
|
||||||
uint8_t mask = 1 << ((pin-_firstVpin) % 8);
|
|
||||||
_digitalOutBuffer[0] = EXIODPUP;
|
_digitalOutBuffer[0] = EXIODPUP;
|
||||||
_digitalOutBuffer[1] = pin;
|
_digitalOutBuffer[1] = pin;
|
||||||
_digitalOutBuffer[2] = pullup;
|
_digitalOutBuffer[2] = pullup;
|
||||||
I2CManager.write(_i2cAddress, _digitalOutBuffer, 3, &_i2crb);
|
I2CManager.write(_i2cAddress, _digitalOutBuffer, 3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +115,7 @@ private:
|
|||||||
int pin = vpin - _firstVpin;
|
int pin = vpin - _firstVpin;
|
||||||
_analogueOutBuffer[0] = EXIORDAN;
|
_analogueOutBuffer[0] = EXIORDAN;
|
||||||
_analogueOutBuffer[1] = pin;
|
_analogueOutBuffer[1] = pin;
|
||||||
I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2, &_i2crb);
|
I2CManager.read(_i2cAddress, _analogueInBuffer, 2, _analogueOutBuffer, 2);
|
||||||
return (_analogueInBuffer[1] << 8) + _analogueInBuffer[0];
|
return (_analogueInBuffer[1] << 8) + _analogueInBuffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +124,7 @@ private:
|
|||||||
_digitalOutBuffer[0] = EXIORDD;
|
_digitalOutBuffer[0] = EXIORDD;
|
||||||
_digitalOutBuffer[1] = pin;
|
_digitalOutBuffer[1] = pin;
|
||||||
_digitalOutBuffer[2] = 0x00; // Don't need to use this for reading
|
_digitalOutBuffer[2] = 0x00; // Don't need to use this for reading
|
||||||
I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3, &_i2crb);
|
I2CManager.read(_i2cAddress, _digitalInBuffer, 1, _digitalOutBuffer, 3);
|
||||||
return _digitalInBuffer[0];
|
return _digitalInBuffer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +133,7 @@ private:
|
|||||||
_digitalOutBuffer[0] = EXIOWRD;
|
_digitalOutBuffer[0] = EXIOWRD;
|
||||||
_digitalOutBuffer[1] = pin;
|
_digitalOutBuffer[1] = pin;
|
||||||
_digitalOutBuffer[2] = value;
|
_digitalOutBuffer[2] = value;
|
||||||
I2CManager.write(_i2cAddress, _digitalOutBuffer, 3, &_i2crb);
|
I2CManager.write(_i2cAddress, _digitalOutBuffer, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _display() override {
|
void _display() override {
|
||||||
@ -167,7 +165,6 @@ private:
|
|||||||
uint8_t _majorVer = 0;
|
uint8_t _majorVer = 0;
|
||||||
uint8_t _minorVer = 0;
|
uint8_t _minorVer = 0;
|
||||||
uint8_t _patchVer = 0;
|
uint8_t _patchVer = 0;
|
||||||
I2CRB _i2crb;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
EXIOINIT = 0xE0, // Flag to initialise setup procedure
|
EXIOINIT = 0xE0, // Flag to initialise setup procedure
|
||||||
|
Loading…
Reference in New Issue
Block a user