@@ -63,8 +63,6 @@ void I2cHardware::TogglePowerPin() {
63
63
/* **********************************************************************/
64
64
void I2cHardware::InitBus (bool is_default, const char *sda, const char *scl) {
65
65
uint8_t pin_sda, pin_scl;
66
- WS_DEBUG_PRINT (" is_default: " );
67
- WS_DEBUG_PRINTLN (is_default);
68
66
if (!is_default && (sda == nullptr || scl == nullptr )) {
69
67
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_UNSPECIFIED;
70
68
return ;
@@ -83,7 +81,6 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
83
81
pin_scl = SCL;
84
82
#else
85
83
// RP2040 BSP uses a different naming scheme than Espressif for I2C pins
86
- WS_DEBUG_PRINTLN (" [i2c] Using RP2040 I2C pins..." );
87
84
pin_sda = PIN_WIRE0_SDA;
88
85
pin_scl = PIN_WIRE0_SCL;
89
86
#endif
@@ -130,15 +127,13 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
130
127
_bus->setSDA (pin_sda);
131
128
_bus->setSCL (pin_scl);
132
129
_bus->begin ();
133
- WS_DEBUG_PRINTLN (" [i2c] RP2040 I2C bus initialized!" );
134
130
#elif defined(ARDUINO_ARCH_SAM)
135
131
_bus = new TwoWire (&PERIPH_WIRE, pin_sda, pin_scl);
136
132
_bus->begin ();
137
133
#else
138
134
#error "I2C bus implementation not supported by this platform!"
139
135
#endif
140
136
141
- WS_DEBUG_PRINTLN (" [i2c] I2C bus initialized!" );
142
137
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS;
143
138
}
144
139
@@ -167,15 +162,6 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
167
162
return false ;
168
163
}
169
164
170
- // TODO: WS object needs to be added for this to work?
171
- /* #ifndef ARDUINO_ARCH_ESP32
172
- // Set I2C WDT timeout to catch I2C hangs, SAMD-specific
173
- WS.enableWDT(I2C_WDT_TIMEOUT_MS);
174
- WS.feedWDT();
175
- #endif */
176
- WS_DEBUG_PRINT (" Bus Status: " );
177
- WS_DEBUG_PRINTLN (_bus_status);
178
-
179
165
// Perform a bus scan
180
166
WS_DEBUG_PRINTLN (" [i2c]: Scanning I2C Bus for Devices..." );
181
167
for (uint8_t address = 1 ; address < 127 ; address++) {
@@ -189,17 +175,6 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
189
175
scan_results
190
176
->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
191
177
.i2c_device_address = address;
192
- // NOTE: This is disabled because _sda and _scl are not saved, we should be doing this!
193
- /* strcpy(
194
- scan_results
195
- ->i2c_bus_found_devices[scan_results->i2c_bus_found_devices_count]
196
- .i2c_bus_sda,
197
- _sda);
198
- strcpy(
199
- scan_results
200
- ->i2c_bus_found_devices[scan_results->i2c_bus_found_devices_count]
201
- .i2c_bus_scl,
202
- _scl); */
203
178
scan_results->i2c_bus_found_devices_count ++;
204
179
}
205
180
#if defined(ARDUINO_ARCH_ESP32)
@@ -225,18 +200,11 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
225
200
}
226
201
#endif // ARDUINO_ARCH_ESP32
227
202
else {
228
- // WS_DEBUG_PRINTLN("[i2c] Did not find device: Unknown bus error has
229
- // occured!");
203
+ // Did not find a device, keep scanning
230
204
continue ;
231
205
}
232
206
}
233
207
234
- // TODO: Re-enable this?
235
- /* #ifndef ARDUINO_ARCH_ESP32
236
- // re-enable WipperSnapper SAMD WDT global timeout
237
- WS.enableWDT(WS_WDT_TIMEOUT);
238
- WS.feedWDT();
239
- #endif */
240
208
return true ;
241
209
}
242
210
@@ -274,9 +242,9 @@ bool I2cHardware::AddMuxToBus(uint32_t address_register, const char *name) {
274
242
*/
275
243
/* **********************************************************************/
276
244
void I2cHardware::ClearMuxChannel () {
277
- if (!_has_mux) {
245
+ if (!_has_mux)
278
246
return ;
279
- }
247
+
280
248
_bus->beginTransmission (_mux_address);
281
249
if (_mux_max_channels == 4 )
282
250
_bus->write (0b0000 );
@@ -293,9 +261,9 @@ void I2cHardware::ClearMuxChannel() {
293
261
*/
294
262
/* **********************************************************************/
295
263
void I2cHardware::SelectMuxChannel (uint32_t channel) {
296
- if (channel > _mux_max_channels - 1 ) {
264
+ if (channel > _mux_max_channels - 1 )
297
265
return ;
298
- }
266
+
299
267
_bus->beginTransmission (_mux_address);
300
268
_bus->write (1 << channel);
301
269
_bus->endTransmission ();
0 commit comments