@@ -139,71 +139,84 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
139
139
_bus_status = wippersnapper_i2c_I2cBusStatus_I2C_BUS_STATUS_SUCCESS;
140
140
}
141
141
142
- bool I2cHardware::ScanBus (wippersnapper_i2c_I2cBusScanned* scan_results) {
142
+ bool I2cHardware::ScanBus (wippersnapper_i2c_I2cBusScanned * scan_results) {
143
143
if (!scan_results)
144
- return false ;
144
+ return false ;
145
145
146
- // TODO: WS object needs to be added for this to work?
147
- /* #ifndef ARDUINO_ARCH_ESP32
148
- // Set I2C WDT timeout to catch I2C hangs, SAMD-specific
149
- WS.enableWDT(I2C_WDT_TIMEOUT_MS);
150
- WS.feedWDT();
151
- #endif */
146
+ // TODO: WS object needs to be added for this to work?
147
+ /* #ifndef ARDUINO_ARCH_ESP32
148
+ // Set I2C WDT timeout to catch I2C hangs, SAMD-specific
149
+ WS.enableWDT(I2C_WDT_TIMEOUT_MS);
150
+ WS.feedWDT();
151
+ #endif */
152
152
153
- // Get the SDA and SCL pins from the bus
154
- char i2c_bus_scl[15 ] = {0 }, i2c_bus_sda[15 ] = {0 };
155
- snprintf (i2c_bus_scl, sizeof (i2c_bus_scl), " D%u" , _bus_scl);
156
- snprintf (i2c_bus_sda, sizeof (i2c_bus_sda), " D%u" , _bus_sda);
153
+ // Get the SDA and SCL pins from the bus
154
+ char i2c_bus_scl[15 ] = {0 }, i2c_bus_sda[15 ] = {0 };
155
+ snprintf (i2c_bus_scl, sizeof (i2c_bus_scl), " D%u" , _bus_scl);
156
+ snprintf (i2c_bus_sda, sizeof (i2c_bus_sda), " D%u" , _bus_sda);
157
157
158
- // Perform a bus scan
159
- WS_DEBUG_PRINTLN (" [i2c]: Scanning I2C Bus for Devices..." );
160
- for (uint8_t address = 1 ; address < 127 ; ++address) {
161
- WS_DEBUG_PRINT (" [i2c] Scanning Address: 0x" );
162
- WS_DEBUG_PRINTLN (address, HEX);
163
- _bus->beginTransmission (address);
164
- uint8_t endTransmissionRC = _bus->endTransmission ();
158
+ // Perform a bus scan
159
+ WS_DEBUG_PRINTLN (" [i2c]: Scanning I2C Bus for Devices..." );
160
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
161
+ WS_DEBUG_PRINT (" [i2c] Scanning Address: 0x" );
162
+ WS_DEBUG_PRINTLN (address, HEX);
163
+ _bus->beginTransmission (address);
164
+ uint8_t endTransmissionRC = _bus->endTransmission ();
165
165
166
- if (endTransmissionRC == 0 ) {
167
- WS_DEBUG_PRINTLN (" [i2c] Found Device!" );
168
- scan_results->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ].i2c_device_address = address;
169
- scan_results->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ].i2c_mux_address = 0xFFFF ; // Tell user that device is not on a mux
170
- strcpy (scan_results->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ].i2c_bus_sda , i2c_bus_sda);
171
- strcpy (scan_results->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ].i2c_bus_scl , i2c_bus_scl);
172
- scan_results->i2c_bus_found_devices_count ++;
173
- }
174
- #if defined(ARDUINO_ARCH_ESP32)
175
- // Check endTransmission()'s return code (Arduino-ESP32 ONLY)
176
- else if (endTransmissionRC == 3 ) {
177
- WS_DEBUG_PRINTLN (" [i2c] Did not find device: NACK on transmit of data!" );
178
- continue ;
179
- } else if (endTransmissionRC == 2 ) {
180
- WS_DEBUG_PRINTLN (
181
- " [i2c] Did not find device: NACK on transmit of address!" );
182
- continue ;
183
- } else if (endTransmissionRC == 1 ) {
184
- WS_DEBUG_PRINTLN (
185
- " [i2c] Did not find device: data too long to fit in xmit buffer!" );
186
- continue ;
187
- } else if (endTransmissionRC == 4 ) {
188
- WS_DEBUG_PRINTLN (
189
- " [i2c] Did not find device: Unspecified bus error occured!" );
190
- continue ;
191
- } else if (endTransmissionRC == 5 ) {
192
- WS_DEBUG_PRINTLN (" [i2c] Did not find device: Bus timed out!" );
193
- continue ;
194
- #endif // ARDUINO_ARCH_ESP32
195
- } else {
196
- WS_DEBUG_PRINTLN (
197
- " [i2c] Did not find device: Unknown bus error has occured!" );
198
- continue ;
199
- }
166
+ if (endTransmissionRC == 0 ) {
167
+ WS_DEBUG_PRINTLN (" [i2c] Found Device!" );
168
+ scan_results
169
+ ->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
170
+ .i2c_device_address = address;
171
+ scan_results
172
+ ->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
173
+ .i2c_mux_address = 0xFFFF ; // Tell user that device is not on a mux
174
+ strcpy (
175
+ scan_results
176
+ ->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
177
+ .i2c_bus_sda ,
178
+ i2c_bus_sda);
179
+ strcpy (
180
+ scan_results
181
+ ->i2c_bus_found_devices [scan_results->i2c_bus_found_devices_count ]
182
+ .i2c_bus_scl ,
183
+ i2c_bus_scl);
184
+ scan_results->i2c_bus_found_devices_count ++;
185
+ }
186
+ #if defined(ARDUINO_ARCH_ESP32)
187
+ // Check endTransmission()'s return code (Arduino-ESP32 ONLY)
188
+ else if (endTransmissionRC == 3 ) {
189
+ WS_DEBUG_PRINTLN (" [i2c] Did not find device: NACK on transmit of data!" );
190
+ continue ;
191
+ } else if (endTransmissionRC == 2 ) {
192
+ WS_DEBUG_PRINTLN (
193
+ " [i2c] Did not find device: NACK on transmit of address!" );
194
+ continue ;
195
+ } else if (endTransmissionRC == 1 ) {
196
+ WS_DEBUG_PRINTLN (
197
+ " [i2c] Did not find device: data too long to fit in xmit buffer!" );
198
+ continue ;
199
+ } else if (endTransmissionRC == 4 ) {
200
+ WS_DEBUG_PRINTLN (
201
+ " [i2c] Did not find device: Unspecified bus error occured!" );
202
+ continue ;
203
+ } else if (endTransmissionRC == 5 ) {
204
+ WS_DEBUG_PRINTLN (" [i2c] Did not find device: Bus timed out!" );
205
+ continue ;
206
+ #endif // ARDUINO_ARCH_ESP32
207
+ } else {
208
+ WS_DEBUG_PRINTLN (
209
+ " [i2c] Did not find device: Unknown bus error has occured!" );
210
+ continue ;
200
211
}
201
-
202
- /* #ifndef ARDUINO_ARCH_ESP32
203
- // re-enable WipperSnapper SAMD WDT global timeout
204
- WS.enableWDT(WS_WDT_TIMEOUT);
205
- WS.feedWDT();
206
- #endif */
212
+ }
213
+
214
+ /* #ifndef ARDUINO_ARCH_ESP32
215
+ // re-enable WipperSnapper SAMD WDT global timeout
216
+ WS.enableWDT(WS_WDT_TIMEOUT);
217
+ WS.feedWDT();
218
+ #endif */
219
+ return true ; // TODO: Change this!
207
220
}
208
221
209
222
/* **********************************************************************/
0 commit comments