mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-24 13:21:23 +01:00
Update I2C address, fix bug setting analogue pins
This commit is contained in:
parent
3862f7250d
commit
8ecb408da7
@ -82,31 +82,58 @@ private:
|
|||||||
|
|
||||||
void _setupDevice() {
|
void _setupDevice() {
|
||||||
// Send digital and analogue pin counts
|
// Send digital and analogue pin counts
|
||||||
I2CManager.write(_i2cAddress, 3, REG_EXIOINIT, _numDigitalPins, _numAnaloguePins);
|
uint8_t _setupBuffer[3] = {EXIOINIT, _numDigitalPins, _numAnaloguePins};
|
||||||
// Enable digital ports
|
// I2CManager.write(_i2cAddress, 3, EXIOINIT, _numDigitalPins, _numAnaloguePins);
|
||||||
_digitalPinBytes = (_numDigitalPins + 7) / 8 + 1;
|
I2CManager.write(_i2cAddress, _setupBuffer, 3, &_i2crb);
|
||||||
uint8_t _enableDigitalPins[_digitalPinBytes];
|
_activity = EXIODPIN;
|
||||||
_enableDigitalPins[0] = REG_EXIODPIN;
|
}
|
||||||
for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) {
|
|
||||||
_enableDigitalPins[byte] = 0;
|
void _loop(unsigned long currentMicros) override {
|
||||||
|
if (_i2crb.status == I2C_STATUS_PENDING) return;
|
||||||
|
if (_i2crb.status == I2C_STATUS_OK) {
|
||||||
|
switch(_activity) {
|
||||||
|
case EXIODPIN:
|
||||||
|
// Enable digital ports
|
||||||
|
_digitalPinBytes = (_numDigitalPins + 7) / 8 + 1;
|
||||||
|
// uint8_t _enableDigitalPins[_digitalPinBytes];
|
||||||
|
// _enableDigitalPins[0] = EXIODPIN;
|
||||||
|
_digitalOutBuffer[0] = EXIODPIN;
|
||||||
|
for (uint8_t byte = 1; byte < _digitalPinBytes; byte++) {
|
||||||
|
// _enableDigitalPins[byte] = 0;
|
||||||
|
_digitalOutBuffer[byte] = 0;
|
||||||
|
}
|
||||||
|
for (uint8_t pin = 0; pin < _numDigitalPins; pin++) {
|
||||||
|
int pinByte = pin / 8;
|
||||||
|
// bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8);
|
||||||
|
bitSet(_digitalOutBuffer[pinByte + 1], pin - pinByte * 8);
|
||||||
|
}
|
||||||
|
// I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb);
|
||||||
|
I2CManager.write(_i2cAddress, _digitalOutBuffer, _digitalPinBytes, &_i2crb);
|
||||||
|
_activity = EXIOAPIN;
|
||||||
|
break;
|
||||||
|
case EXIOAPIN:
|
||||||
|
// Enable analogue ports
|
||||||
|
_analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1;
|
||||||
|
// uint8_t _enableAnaloguePins[_analoguePinBytes];
|
||||||
|
// _enableAnaloguePins[0] = EXIOAPIN;
|
||||||
|
_analogueOutBuffer[0] = EXIOAPIN;
|
||||||
|
for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) {
|
||||||
|
// _enableAnaloguePins[byte] = 0;
|
||||||
|
_analogueOutBuffer[byte] = 0;
|
||||||
|
}
|
||||||
|
for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) {
|
||||||
|
int pinByte = pin / 8;
|
||||||
|
// bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8);
|
||||||
|
bitSet(_analogueOutBuffer[pinByte + 1], pin - pinByte * 8);
|
||||||
|
}
|
||||||
|
// I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb);
|
||||||
|
I2CManager.write(_i2cAddress, _analogueOutBuffer, _analoguePinBytes, &_i2crb);
|
||||||
|
_activity = EXIORDY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (uint8_t pin = 0; pin < _numDigitalPins; pin++) {
|
|
||||||
int pinByte = pin / 8;
|
|
||||||
bitSet(_enableDigitalPins[pinByte + 1], pin - pinByte * 8);
|
|
||||||
}
|
|
||||||
I2CManager.write(_i2cAddress, _enableDigitalPins, _digitalPinBytes, &_i2crb);
|
|
||||||
// Enable analogue ports
|
|
||||||
_analoguePinBytes = (_numAnaloguePins + 7) / 8 + 1;
|
|
||||||
uint8_t _enableAnaloguePins[_analoguePinBytes];
|
|
||||||
_enableAnaloguePins[0] = REG_EXIOAPIN;
|
|
||||||
for (uint8_t byte = 1; byte < _analoguePinBytes; byte++) {
|
|
||||||
_enableAnaloguePins[byte] = 0;
|
|
||||||
}
|
|
||||||
for (uint8_t pin = 0; pin < _numAnaloguePins; pin++) {
|
|
||||||
int pinByte = pin / 8;
|
|
||||||
bitSet(_enableAnaloguePins[pinByte + 1], pin - pinByte * 8);
|
|
||||||
}
|
|
||||||
I2CManager.write(_i2cAddress, _enableAnaloguePins, _analoguePinBytes, &_i2crb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _display() override {
|
void _display() override {
|
||||||
@ -119,15 +146,20 @@ private:
|
|||||||
uint8_t _numAnaloguePins;
|
uint8_t _numAnaloguePins;
|
||||||
int _digitalPinBytes;
|
int _digitalPinBytes;
|
||||||
int _analoguePinBytes;
|
int _analoguePinBytes;
|
||||||
|
uint8_t _digitalOutBuffer[EXIO_NANO_DIGITAL_PINS + 1];
|
||||||
|
uint8_t _digitalInBufer[EXIO_NANO_DIGITAL_PINS];
|
||||||
|
uint8_t _analogueOutBuffer[EXIO_NANO_ANALOGUE_PINS + 1];
|
||||||
|
uint8_t _analogueInBuffer[EXIO_NANO_ANALOGUE_PINS];
|
||||||
|
uint8_t _activity;
|
||||||
I2CRB _i2crb;
|
I2CRB _i2crb;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
REG_EXIOINIT = 0xE0, // Flag to initialise setup procedure
|
EXIOINIT = 0xE0, // Flag to initialise setup procedure
|
||||||
REG_EXIODPIN = 0xE1, // Flag we're sending digital pin assignments
|
EXIODPIN = 0xE1, // Flag we're sending digital pin assignments
|
||||||
REG_EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments
|
EXIOAPIN = 0xE2, // Flag we're sending analogue pin assignments
|
||||||
REG_EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup
|
EXIORDY = 0xE3, // Flag we have completed setup procedure, also for EX-IO to ACK setup
|
||||||
REG_EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration
|
EXIODDIR = 0xE4, // Flag we're sending digital pin direction configuration
|
||||||
REG_EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration
|
EXIODPUP = 0xE5, // Flag we're sending digital pin pullup configuration
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user