mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-30 11:36:13 +01:00
More bugs to fix
This commit is contained in:
parent
8ecb408da7
commit
75f1a8f43a
|
@ -27,8 +27,8 @@
|
||||||
* #include "IO_EX-IOExpander.h"
|
* #include "IO_EX-IOExpander.h"
|
||||||
*
|
*
|
||||||
* void halSetup() {
|
* void halSetup() {
|
||||||
* // EXIOExpander::create(vpin, num_vpins, i2c_address);
|
* // EXIOExpander::create(vpin, num_vpins, i2c_address, digitalPinCount, analoguePinCount);
|
||||||
* EXIOExpander::create(800, 18, 0x90);
|
* EXIOExpander::create(800, 18, 0x90, 12, 6);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -69,64 +69,56 @@ private:
|
||||||
|
|
||||||
void _begin() {
|
void _begin() {
|
||||||
// Initialise EX-IOExander device
|
// Initialise EX-IOExander device
|
||||||
|
uint8_t _check = I2CManager.checkAddress(_i2cAddress);
|
||||||
|
DIAG(F("I2C status check: %d"), _check);
|
||||||
if (I2CManager.exists(_i2cAddress)) {
|
if (I2CManager.exists(_i2cAddress)) {
|
||||||
|
_activity = EXIOINIT;
|
||||||
#ifdef DIAG_IO
|
#ifdef DIAG_IO
|
||||||
_display();
|
_display();
|
||||||
#endif
|
#endif
|
||||||
_setupDevice();
|
|
||||||
} else {
|
} else {
|
||||||
DIAG(F("EX-IOExpander device not found, I2C:%x"), _i2cAddress);
|
DIAG(F("EX-IOExpander device not found, I2C:x%x"), _i2cAddress);
|
||||||
_deviceState = DEVSTATE_FAILED;
|
_deviceState = DEVSTATE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _setupDevice() {
|
|
||||||
// Send digital and analogue pin counts
|
|
||||||
uint8_t _setupBuffer[3] = {EXIOINIT, _numDigitalPins, _numAnaloguePins};
|
|
||||||
// I2CManager.write(_i2cAddress, 3, EXIOINIT, _numDigitalPins, _numAnaloguePins);
|
|
||||||
I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb);
|
|
||||||
_activity = EXIODPIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _loop(unsigned long currentMicros) override {
|
void _loop(unsigned long currentMicros) override {
|
||||||
if (_i2crb.status == I2C_STATUS_PENDING) return;
|
if (_i2crb.status == I2C_STATUS_PENDING) return;
|
||||||
if (_i2crb.status == I2C_STATUS_OK) {
|
if (_i2crb.status == I2C_STATUS_OK) {
|
||||||
switch(_activity) {
|
switch(_activity) {
|
||||||
|
case EXIOINIT:
|
||||||
|
// Send digital and analogue pin counts
|
||||||
|
_setupBuffer[0] = EXIOINIT;
|
||||||
|
_setupBuffer[1] = _numDigitalPins;
|
||||||
|
_setupBuffer[2] = _numAnaloguePins;
|
||||||
|
I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb);
|
||||||
|
_activity = EXIODPIN;
|
||||||
|
break;
|
||||||
case EXIODPIN:
|
case EXIODPIN:
|
||||||
// Enable digital ports
|
// Enable digital ports
|
||||||
_digitalPinBytes = (_numDigitalPins + 7) / 8 + 1;
|
_digitalPinBytes = (_numDigitalPins + 7) / 8 + 1;
|
||||||
// uint8_t _enableDigitalPins[_digitalPinBytes];
|
|
||||||
// _enableDigitalPins[0] = EXIODPIN;
|
|
||||||
_digitalOutBuffer[0] = EXIODPIN;
|
_digitalOutBuffer[0] = EXIODPIN;
|
||||||
for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) {
|
for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) {
|
||||||
// _enableDigitalPins[byte] = 0;
|
|
||||||
_digitalOutBuffer[byte] = 0;
|
_digitalOutBuffer[byte] = 0;
|
||||||
}
|
}
|
||||||
for (uint8_t pin = 0; pin < _numDigitalPins; pin++) {
|
for (uint8_t pin = 0; pin < _numDigitalPins; pin++) {
|
||||||
int pinByte = pin / 8;
|
int pinByte = pin / 8;
|
||||||
// bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8);
|
|
||||||
bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8);
|
bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8);
|
||||||
}
|
}
|
||||||
// I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb);
|
|
||||||
I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb);
|
I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb);
|
||||||
_activity = EXIOAPIN;
|
_activity = EXIOAPIN;
|
||||||
break;
|
break;
|
||||||
case EXIOAPIN:
|
case EXIOAPIN:
|
||||||
// Enable analogue ports
|
// Enable analogue ports
|
||||||
_analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1;
|
_analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1;
|
||||||
// uint8_t _enableAnaloguePins[_analoguePinBytes];
|
|
||||||
// _enableAnaloguePins[0] = EXIOAPIN;
|
|
||||||
_analogueOutBuffer[0] = EXIOAPIN;
|
_analogueOutBuffer[0] = EXIOAPIN;
|
||||||
for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) {
|
for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) {
|
||||||
// _enableAnaloguePins[byte] = 0;
|
|
||||||
_analogueOutBuffer[byte] = 0;
|
_analogueOutBuffer[byte] = 0;
|
||||||
}
|
}
|
||||||
for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) {
|
for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) {
|
||||||
int pinByte = pin / 8;
|
int pinByte = pin / 8;
|
||||||
// bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8);
|
|
||||||
bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8);
|
bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8);
|
||||||
}
|
}
|
||||||
// I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb);
|
|
||||||
I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb);
|
I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb);
|
||||||
_activity = EXIORDY;
|
_activity = EXIORDY;
|
||||||
break;
|
break;
|
||||||
|
@ -146,6 +138,7 @@ private:
|
||||||
uint8_t _numAnaloguePins;
|
uint8_t _numAnaloguePins;
|
||||||
int _digitalPinBytes;
|
int _digitalPinBytes;
|
||||||
int _analoguePinBytes;
|
int _analoguePinBytes;
|
||||||
|
uint8_t _setupBuffer[3];
|
||||||
uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1];
|
uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1];
|
||||||
uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS];
|
uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS];
|
||||||
uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1];
|
uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user