[I2C] Renumber buses starting from 0 instead of 1
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -52,7 +52,7 @@ ESPEasy has a separate setting for Slow I2C devices, and per I2C device this slo
|
||||
- `I2C-bus.org - Clock Stretching <https://www.i2c-bus.org/clock-stretching/>`_
|
||||
- `ESPeasy wiki - Basics: The I2C Bus <https://www.letscontrolit.com/wiki/index.php/Basics:_The_I%C2%B2C_Bus>`_
|
||||
|
||||
This setting is only available for the first I2C Bus, as not many devices (should) need this set, and the devices that do need this should then be connected to I2C Bus 1.
|
||||
This setting is only available for the first I2C Bus, as not many devices (should) need this set, and the devices that do need this should then be connected to I2C Bus 0.
|
||||
|
||||
.. image:: Hardware_I2CBus.png
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 69 KiB After Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -17,7 +17,7 @@ void i2c_scanI2Cbus(bool dbg, int8_t channel, uint8_t i2cBus) {
|
||||
#if FEATURE_I2CMULTIPLEXER
|
||||
|
||||
if (-1 == channel) {
|
||||
serialPrintln(concat(F("Standard I2C bus "), i2cBus + 1));
|
||||
serialPrintln(concat(F("Standard I2C bus "), i2cBus));
|
||||
} else {
|
||||
serialPrintln(concat(F("Multiplexer channel "), channel));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void initI2C() {
|
||||
#if !FEATURE_I2C_MULTIPLE
|
||||
addLog(LOG_LEVEL_INFO, F("INIT : I2C Bus"));
|
||||
#else // if !FEATURE_I2C_MULTIPLE
|
||||
addLog(LOG_LEVEL_INFO, concat(F("INIT : I2C Bus "), i2cBus + 1));
|
||||
addLog(LOG_LEVEL_INFO, concat(F("INIT : I2C Bus "), i2cBus));
|
||||
#endif // if !FEATURE_I2C_MULTIPLE
|
||||
I2CSelectHighClockSpeed(i2cBus); // Set normal clock speed, on I2C Bus 1 (index 0)
|
||||
}
|
||||
|
||||
@@ -440,31 +440,27 @@ void I2CInterfaceSelector(String label,
|
||||
|
||||
if (i2cMaxBusCount > 1) {
|
||||
static uint8_t i2cBusCount = 0;
|
||||
static String i2cBusList[3];
|
||||
static int i2cBusNumbers[3];
|
||||
|
||||
if (i2cBusList[0].isEmpty() || (i2cBusCount != i2cMaxBusCount)) {
|
||||
if (i2cBusCount != i2cMaxBusCount) {
|
||||
i2cBusCount = 0;
|
||||
i2cBusList[i2cBusCount] = '1';
|
||||
i2cBusNumbers[i2cBusCount] = 0;
|
||||
++i2cBusCount;
|
||||
|
||||
if ((getI2CBusCount() > 1) && Settings.isI2CEnabled(1)) {
|
||||
i2cBusList[i2cBusCount] = '2';
|
||||
i2cBusNumbers[i2cBusCount] = 1;
|
||||
++i2cBusCount;
|
||||
}
|
||||
# if FEATURE_I2C_INTERFACE_3
|
||||
|
||||
if ((getI2CBusCount() > 2) && Settings.isI2CEnabled(2)) {
|
||||
i2cBusList[i2cBusCount] = '3';
|
||||
i2cBusNumbers[i2cBusCount] = 2;
|
||||
++i2cBusCount;
|
||||
}
|
||||
# endif // if FEATURE_I2C_INTERFACE_3
|
||||
}
|
||||
FormSelectorOptions selector(i2cBusCount,
|
||||
i2cBusList, i2cBusNumbers);
|
||||
i2cBusNumbers);
|
||||
selector.default_index = 0;
|
||||
bool reloadOnChange = false;
|
||||
|
||||
|
||||
@@ -277,10 +277,10 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose,
|
||||
if (Settings.getI2CSdaPin(i2cBus) == gpio) {
|
||||
#if FEATURE_I2C_MULTIPLE
|
||||
switch (i2cBus) {
|
||||
case 0: return F("I2C SDA (bus 1)");
|
||||
case 1: return F("I2C SDA (bus 2)");
|
||||
case 0: return F("I2C SDA (bus 0)");
|
||||
case 1: return F("I2C SDA (bus 1)");
|
||||
#if FEATURE_I2C_INTERFACE_3
|
||||
case 2: return F("I2C SDA (bus 3)");
|
||||
case 2: return F("I2C SDA (bus 2)");
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
@@ -290,10 +290,10 @@ const __FlashStringHelper* getConflictingUse(int gpio, PinSelectPurpose purpose,
|
||||
if (Settings.getI2CSclPin(i2cBus) == gpio) {
|
||||
#if FEATURE_I2C_MULTIPLE
|
||||
switch (i2cBus) {
|
||||
case 0: return F("I2C SCL (bus 1)");
|
||||
case 1: return F("I2C SCL (bus 2)");
|
||||
case 0: return F("I2C SCL (bus 0)");
|
||||
case 1: return F("I2C SCL (bus 1)");
|
||||
#if FEATURE_I2C_INTERFACE_3
|
||||
case 2: return F("I2C SCL (bus 3)");
|
||||
case 2: return F("I2C SCL (bus 2)");
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -840,7 +840,7 @@ void format_I2C_port_description(taskIndex_t x)
|
||||
html_BR();
|
||||
addHtml(F("I2C Bus"));
|
||||
addHtml(' ');
|
||||
addHtmlInt(i2cBus + 1);
|
||||
addHtmlInt(i2cBus);
|
||||
}
|
||||
#else
|
||||
const uint8_t i2cBus = 0;
|
||||
|
||||
@@ -216,7 +216,7 @@ void handle_hardware() {
|
||||
#if !FEATURE_I2C_MULTIPLE
|
||||
addFormSubHeader(F("I2C Bus"));
|
||||
#else // if !FEATURE_I2C_MULTIPLE
|
||||
addFormSubHeader(strformat(F("I2C Bus %u"), i2cBus + 1));
|
||||
addFormSubHeader(strformat(F("I2C Bus %u"), i2cBus));
|
||||
#endif // if !FEATURE_I2C_MULTIPLE
|
||||
#if FEATURE_PLUGIN_PRIORITY
|
||||
if (isI2CPriorityTaskActive(i2cBus)) {
|
||||
@@ -247,7 +247,7 @@ void handle_hardware() {
|
||||
#if !FEATURE_I2C_MULTIPLE
|
||||
addFormSubHeader(F("I2C Multiplexer"));
|
||||
#else // if !FEATURE_I2C_MULTIPLE
|
||||
addFormSubHeader(strformat(F("I2C Multiplexer %u"), i2cBus + 1));
|
||||
addFormSubHeader(strformat(F("I2C Multiplexer %u"), i2cBus));
|
||||
#endif // if FEATURE_I2C_MULTIPLE
|
||||
// Select the type of multiplexer to use
|
||||
{
|
||||
@@ -492,7 +492,7 @@ bool isI2CPriorityTaskActive(uint8_t i2cBus) {
|
||||
void I2CShowSdaSclReadonly(int8_t i2c_sda, int8_t i2c_scl, uint8_t i2cBus) {
|
||||
int pinnr = -1;
|
||||
bool input, output, warning = false;
|
||||
addFormNote(strformat(F("I2C (%d) GPIO pins can't be changed when an I2C Priority task is configured."), i2cBus + 1));
|
||||
addFormNote(strformat(F("I2C (%d) GPIO pins can't be changed when an I2C Priority task is configured."), i2cBus));
|
||||
addRowLabel(formatGpioName_bidirectional(F("SDA")));
|
||||
getGpioInfo(i2c_sda, pinnr, input, output, warning);
|
||||
addHtml(createGPIO_label(i2c_sda, pinnr, true, true, false));
|
||||
|
||||
@@ -504,7 +504,7 @@ void handle_i2cscanner() {
|
||||
{
|
||||
html_table_class_multirow();
|
||||
#if FEATURE_I2C_MULTIPLE
|
||||
html_table_header(strformat(F("I2C Bus %d"), i2cBus + 1));
|
||||
html_table_header(strformat(F("I2C Bus %d"), i2cBus));
|
||||
html_TR();
|
||||
#endif // if FEATURE_I2C_MULTIPLE
|
||||
#if FEATURE_I2CMULTIPLEXER
|
||||
@@ -556,7 +556,7 @@ void handle_i2cscanner() {
|
||||
nDevices = 0; // Reset for next interface
|
||||
} else {
|
||||
html_TR_TD();
|
||||
addHtml(strformat(F("I2C pins not configured for bus %d"), i2cBus + 1));
|
||||
addHtml(strformat(F("I2C pins not configured for bus %d"), i2cBus));
|
||||
}
|
||||
html_end_table();
|
||||
I2CSelectHighClockSpeed(0); // By default the bus is in standard speed
|
||||
|
||||