mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 12:51:24 +01:00
Allow extended I2C addresses to be specified in non-extended configuration
If an extended I2C address is specified (including mux and/or subbus) then these parameters are ignored, but a warning output to the diagnostic console.
This commit is contained in:
parent
9797a0fd2d
commit
173676287c
@ -350,4 +350,10 @@ void I2CAddress::toHex(const uint8_t value, char *buffer) {
|
||||
*ptr++ = bits > 9 ? bits-10+'a' : bits+'0';
|
||||
bits = value & 0xf;
|
||||
*ptr++ = bits > 9 ? bits-10+'a' : bits+'0';
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(I2C_EXTENDED_ADDRESS)
|
||||
|
||||
/* static */ bool I2CAddress::_addressWarningDone = false;
|
||||
|
||||
#endif
|
22
I2CManager.h
22
I2CManager.h
@ -24,6 +24,7 @@
|
||||
#include <inttypes.h>
|
||||
#include "FSH.h"
|
||||
#include "defines.h"
|
||||
#include "DIAG.h"
|
||||
|
||||
/*
|
||||
* Manager for I2C communications. For portability, it allows use
|
||||
@ -144,9 +145,6 @@
|
||||
//#define I2C_EXTENDED_ADDRESS
|
||||
|
||||
|
||||
// Type to hold I2C address
|
||||
#if defined(I2C_EXTENDED_ADDRESS)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Extended I2C Address type to facilitate extended I2C addresses including
|
||||
// I2C multiplexer support.
|
||||
@ -189,6 +187,9 @@ enum I2CSubBus : uint8_t {
|
||||
SubBus_All = 255, // Enable all sub-buses
|
||||
};
|
||||
|
||||
// Type to hold I2C address
|
||||
#if defined(I2C_EXTENDED_ADDRESS)
|
||||
|
||||
// First MUX address (they range between 0x70-0x77).
|
||||
#define I2C_MUX_BASE_ADDRESS 0x70
|
||||
|
||||
@ -315,6 +316,14 @@ public:
|
||||
I2CAddress(const uint8_t deviceAddress) {
|
||||
_deviceAddress = deviceAddress;
|
||||
}
|
||||
I2CAddress(I2CMux, I2CSubBus, const uint8_t deviceAddress) {
|
||||
addressWarning();
|
||||
_deviceAddress = deviceAddress;
|
||||
}
|
||||
I2CAddress(I2CSubBus, const uint8_t deviceAddress) {
|
||||
addressWarning();
|
||||
_deviceAddress = deviceAddress;
|
||||
}
|
||||
|
||||
// Basic constructor
|
||||
I2CAddress() : I2CAddress(0) {}
|
||||
@ -344,6 +353,13 @@ public:
|
||||
private:
|
||||
// Helper function for converting byte to four-character hex string (e.g. 0x23).
|
||||
void toHex(const uint8_t value, char *buffer);
|
||||
void addressWarning() {
|
||||
if (!_addressWarningDone) {
|
||||
DIAG(F("WARNIING: Extended I2C address used but not supported in this configuration"));
|
||||
_addressWarningDone = true;
|
||||
}
|
||||
}
|
||||
static bool _addressWarningDone;
|
||||
};
|
||||
#endif // I2C_EXTENDED_ADDRESS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user