Skip to content

Commit e566898

Browse files
committed
Fix mux init from refactor
1 parent a27bd94 commit e566898

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/Wippersnapper_demo.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// All text above must be included in any redistribution.
1010

1111
#include "ws_adapters.h"
12-
ws_adapter_wifi wipper;
13-
//ws_adapter_offline wipper;
12+
//ws_adapter_wifi wipper;
13+
ws_adapter_offline wipper;
1414

1515
#define WS_DEBUG // Enable debug output!
1616

src/components/i2c/controller.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ bool I2cController::Handle_I2cDeviceRemove(pb_istream_t *stream) {
494494
/***********************************************************************/
495495
bool I2cController::InitMux(const char *name, uint32_t address,
496496
bool is_alt_bus) {
497-
WS_DEBUG_PRINTLN("[i2c] Creating new MUX...");
498497
if (is_alt_bus) {
499498
if (!_i2c_bus_alt->HasMux()) {
500499
if (!_i2c_bus_alt->AddMuxToBus(address, name)) {
@@ -582,18 +581,22 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
582581
WS_LED_STATUS_ERROR_RUNTIME, false);
583582
}
584583
WS_DEBUG_PRINTLN("OK!");
584+
return true;
585585
}
586586

587587
// Mux case #2 - We are creating a new driver that USES THE MUX via
588588
// I2cDeviceAddorReplace message
589589
if (device_descriptor.i2c_mux_address != 0x00) {
590-
if (!_i2c_bus_alt->HasMux() || !_i2c_bus_default->HasMux()) {
590+
if (_i2c_bus_alt->HasMux() || _i2c_bus_default->HasMux()) {
591+
WS_DEBUG_PRINT("[i2c] Configuring MUX channel: ");
592+
WS_DEBUG_PRINTLN(device_descriptor.i2c_mux_channel);
593+
ConfigureMuxChannel(device_descriptor.i2c_mux_channel, use_alt_bus);
594+
did_set_mux_ch = true;
595+
} else {
591596
WsV2.haltErrorV2("[i2c] Device requires a MUX but MUX not present "
592597
"within config.json!",
593598
WS_LED_STATUS_ERROR_RUNTIME, false);
594599
}
595-
ConfigureMuxChannel(device_descriptor.i2c_mux_channel, use_alt_bus);
596-
did_set_mux_ch = true;
597600
}
598601

599602
WS_DEBUG_PRINTLN("Creating a new I2C driver");
@@ -620,13 +623,23 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
620623
}
621624

622625
// Attempt to initialize the driver
623-
if (did_set_mux_ch)
626+
if (did_set_mux_ch) {
624627
drv->SetMuxAddress(device_descriptor.i2c_mux_address);
625-
if (use_alt_bus)
628+
WS_DEBUG_PRINTLN("[i2c] Set driver to use MUX");
629+
}
630+
if (use_alt_bus) {
626631
drv->EnableAltI2CBus(_i2c_model->GetI2cDeviceAddOrReplaceMsg()
627632
->i2c_device_description.i2c_bus_scl,
628633
_i2c_model->GetI2cDeviceAddOrReplaceMsg()
629634
->i2c_device_description.i2c_bus_sda);
635+
WS_DEBUG_PRINTLN("[i2c] Set driver to use Alt I2C bus");
636+
}
637+
// Configure the driver
638+
drv->EnableSensorReads(
639+
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_sensor_types,
640+
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_sensor_types_count);
641+
drv->SetSensorPeriod(
642+
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_period);
630643
if (!drv->begin()) {
631644
if (WsV2._sdCardV2->isModeOffline()) {
632645
WsV2.haltErrorV2("[i2c] Driver failed to initialize!\n\tDid you set "
@@ -636,12 +649,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
636649
WS_LED_STATUS_ERROR_RUNTIME, false);
637650
}
638651
}
639-
// Configure the driver
640-
drv->EnableSensorReads(
641-
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_sensor_types,
642-
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_sensor_types_count);
643-
drv->SetSensorPeriod(
644-
_i2c_model->GetI2cDeviceAddOrReplaceMsg()->i2c_device_period);
652+
645653
_i2c_drivers.push_back(drv);
646654
WS_DEBUG_PRINTLN("[i2c] Driver initialized and added to controller: ");
647655
WS_DEBUG_PRINTLN(device_name);

0 commit comments

Comments
 (0)