Skip to content

Commit 2466a85

Browse files
committed
Snake in mux scan func and handler, not operational yet
1 parent c5c2091 commit 2466a85

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/components/i2c/controller.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,11 @@ bool I2cController::Handle_I2cBusScan(pb_istream_t *stream) {
587587
// TODO: Print out what was scanned? or do this at the end
588588
}
589589

590-
// TODO If Muxes are present, scan them
590+
// Case 3: Do we have a MUX on the default bus?
591+
if (_i2c_model->GetI2cBusScanMsg()->i2c_mux_descriptors_count > 0) {
592+
// Iterate through the MUX descriptors, scanning each MUX
593+
}
594+
591595
// TODO Scan I2C Port 1 for Muxes
592596
// TODO Scan I2C Port 2 for Muxes
593597

src/components/i2c/hardware.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
151151
#endif */
152152

153153
// Get the SDA and SCL pins from the bus
154+
// TODO: Abstract this?
154155
char i2c_bus_scl[15] = {0}, i2c_bus_sda[15] = {0};
155156
snprintf(i2c_bus_scl, sizeof(i2c_bus_scl), "D%u", _bus_scl);
156157
snprintf(i2c_bus_sda, sizeof(i2c_bus_sda), "D%u", _bus_sda);
@@ -165,6 +166,7 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
165166

166167
if (endTransmissionRC == 0) {
167168
WS_DEBUG_PRINTLN("[i2c] Found Device!");
169+
// TODO: Abstract this? Allow for mux flags to be set here, too
168170
scan_results
169171
->i2c_bus_found_devices[scan_results->i2c_bus_found_devices_count]
170172
.i2c_device_address = address;
@@ -292,4 +294,21 @@ void I2cHardware::SelectMuxChannel(uint32_t channel) {
292294
@returns True if a MUX is present on the bus, False otherwise.
293295
*/
294296
/***********************************************************************/
295-
bool I2cHardware::HasMux() { return _has_mux; }
297+
bool I2cHardware::HasMux() { return _has_mux; }
298+
299+
bool I2cHardware::ScanMux(wippersnapper_i2c_I2cBusScanned* scan_results) {
300+
if (!HasMux()) {
301+
WS_DEBUG_PRINTLN("[i2c] ERROR: No MUX present on the bus!");
302+
return false;
303+
}
304+
305+
for (uint8_t ch = 0; ch < _mux_max_channels; ch++) {
306+
SelectMuxChannel(ch);
307+
WS_DEBUG_PRINT("[i2c] Scanning MUX Channel: ");
308+
WS_DEBUG_PRINTLN(ch);
309+
if (!ScanBus(scan_results)) {
310+
WS_DEBUG_PRINTLN("[i2c] ERROR: Failed to scan MUX channel!");
311+
return false;
312+
}
313+
}
314+
}

src/components/i2c/hardware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class I2cHardware {
4343
void SelectMuxChannel(uint32_t channel);
4444
bool HasMux();
4545
void ClearMuxChannel();
46+
bool ScanMux(wippersnapper_i2c_I2cBusScanned* scan_results);
4647
private:
4748
void TogglePowerPin();
4849
wippersnapper_i2c_I2cBusStatus _bus_status; ///< I2C bus status

0 commit comments

Comments
 (0)