@@ -63,8 +63,6 @@ void I2cHardware::TogglePowerPin() {
6363/* **********************************************************************/
6464void I2cHardware::InitBus (bool is_default, const char *sda, const char *scl) {
6565 uint8_t pin_sda, pin_scl;
66- WS_DEBUG_PRINT (" is_default: " );
67- WS_DEBUG_PRINTLN (is_default);
6866 if (!is_default && (sda == nullptr || scl == nullptr )) {
6967 _bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_UNSPECIFIED;
7068 return ;
@@ -83,7 +81,6 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
8381 pin_scl = SCL;
8482#else
8583 // RP2040 BSP uses a different naming scheme than Espressif for I2C pins
86- WS_DEBUG_PRINTLN (" [i2c] Using RP2040 I2C pins..." );
8784 pin_sda = PIN_WIRE0_SDA;
8885 pin_scl = PIN_WIRE0_SCL;
8986#endif
@@ -130,15 +127,13 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
130127 _bus->setSDA (pin_sda);
131128 _bus->setSCL (pin_scl);
132129 _bus->begin ();
133- WS_DEBUG_PRINTLN (" [i2c] RP2040 I2C bus initialized!" );
134130#elif defined(ARDUINO_ARCH_SAM)
135131 _bus = new TwoWire (&PERIPH_WIRE, pin_sda, pin_scl);
136132 _bus->begin ();
137133#else
138134#error "I2C bus implementation not supported by this platform!"
139135#endif
140136
141- WS_DEBUG_PRINTLN (" [i2c] I2C bus initialized!" );
142137 _bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS;
143138}
144139
@@ -167,15 +162,6 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
167162 return false ;
168163 }
169164
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-
179165 // Perform a bus scan
180166 WS_DEBUG_PRINTLN (" [i2c]: Scanning I2C Bus for Devices..." );
181167 for (uint8_t address = 1 ; address < 127 ; address++) {
@@ -189,17 +175,6 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
189175 scan_results
190176 ->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
191177 .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); */
203178 scan_results->i2c_bus_found_devices_count ++;
204179 }
205180#if defined(ARDUINO_ARCH_ESP32)
@@ -225,18 +200,11 @@ bool I2cHardware::ScanBus(wippersnapper_i2c_I2cBusScanned *scan_results) {
225200 }
226201#endif // ARDUINO_ARCH_ESP32
227202 else {
228- // WS_DEBUG_PRINTLN("[i2c] Did not find device: Unknown bus error has
229- // occured!");
203+ // Did not find a device, keep scanning
230204 continue ;
231205 }
232206 }
233207
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 */
240208 return true ;
241209}
242210
@@ -274,9 +242,9 @@ bool I2cHardware::AddMuxToBus(uint32_t address_register, const char *name) {
274242*/
275243/* **********************************************************************/
276244void I2cHardware::ClearMuxChannel () {
277- if (!_has_mux) {
245+ if (!_has_mux)
278246 return ;
279- }
247+
280248 _bus->beginTransmission (_mux_address);
281249 if (_mux_max_channels == 4 )
282250 _bus->write (0b0000 );
@@ -293,9 +261,9 @@ void I2cHardware::ClearMuxChannel() {
293261*/
294262/* **********************************************************************/
295263void I2cHardware::SelectMuxChannel (uint32_t channel) {
296- if (channel > _mux_max_channels - 1 ) {
264+ if (channel > _mux_max_channels - 1 )
297265 return ;
298- }
266+
299267 _bus->beginTransmission (_mux_address);
300268 _bus->write (1 << channel);
301269 _bus->endTransmission ();
0 commit comments