@@ -151,6 +151,7 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
151
151
#endif */
152
152
153
153
// Get the SDA and SCL pins from the bus
154
+ // TODO: Abstract this?
154
155
char i2c_bus_scl[15 ] = {0 }, i2c_bus_sda[15 ] = {0 };
155
156
snprintf (i2c_bus_scl, sizeof (i2c_bus_scl), " D%u" , _bus_scl);
156
157
snprintf (i2c_bus_sda, sizeof (i2c_bus_sda), " D%u" , _bus_sda);
@@ -165,6 +166,7 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
165
166
166
167
if (endTransmissionRC == 0 ) {
167
168
WS_DEBUG_PRINTLN (" [i2c] Found Device!" );
169
+ // TODO: Abstract this? Allow for mux flags to be set here, too
168
170
scan_results
169
171
->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
170
172
.i2c_device_address = address;
@@ -292,4 +294,21 @@ void I2cHardware::SelectMuxChannel(uint32_t channel) {
292
294
@returns True if a MUX is present on the bus, False otherwise.
293
295
*/
294
296
/* **********************************************************************/
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
+ }
0 commit comments