File tree Expand file tree Collapse file tree 6 files changed +102
-25
lines changed Expand file tree Collapse file tree 6 files changed +102
-25
lines changed Original file line number Diff line number Diff line change @@ -531,19 +531,26 @@ bool I2cController::Handle_I2cBusScan(pb_istream_t *stream) {
531
531
532
532
_i2c_model->ClearI2cBusScanned ();
533
533
wippersnapper_i2c_I2cBusScanned* scan_results = _i2c_model->GetI2cBusScannedMsg ();
534
-
535
- // Check default i2c bus status
536
- if (! IsBusStatusOK ()) {
537
- WS_DEBUG_PRINTLN (" [i2c] Default I2C bus is stuck or not operational, reset the board!" );
538
- return false ;
539
- }
540
- // Linearly scan the default i2c bus
541
- if (!_i2c_bus_default->ScanBus (scan_results)) {
542
- WS_DEBUG_PRINTLN (" [i2c] ERROR: Unable to scan default I2C bus!" );
543
- return false ;
534
+
535
+ if (_i2c_model->GetI2cBusScanMsg ()->scan_default_bus ) {
536
+ if (! IsBusStatusOK ()) {
537
+ WS_DEBUG_PRINTLN (" [i2c] Default I2C bus is stuck or not operational, reset the board!" );
538
+ return false ;
539
+ }
540
+ // Linearly scan the default i2c bus
541
+ if (!_i2c_bus_default->ScanBus (scan_results)) {
542
+ WS_DEBUG_PRINTLN (" [i2c] ERROR: Unable to scan default I2C bus!" );
543
+ return false ;
544
+ }
545
+ // TODO: Encode message
546
+ // TODO: Print out the message (to verify)
547
+ // Future TODO: Publish scan results out to IO
548
+ // Return
549
+ return true ;
544
550
}
545
551
546
552
553
+
547
554
// TODO Linear Scan Alt. I2C Bus
548
555
// TODO: Check if alt i2c bus ha been initialized yet, call init. directly if not
549
556
// TODO If Muxes are present, scan them
Original file line number Diff line number Diff line change @@ -47,10 +47,10 @@ class I2cHardware {
47
47
void TogglePowerPin ();
48
48
wippersnapper_i2c_I2cBusStatus _bus_status; // /< I2C bus status
49
49
TwoWire *_bus = nullptr ; // /< I2C bus
50
- uint8_t _bus_sda; // /< SDA pin
51
- uint8_t _bus_scl; // /< SCL pin
50
+ uint8_t _bus_sda; // /< SDA pin
51
+ uint8_t _bus_scl; // /< SCL pin
52
52
bool _has_mux; // /< Is a MUX present on the bus?
53
53
uint32_t _mux_address_register; // /< I2C address for the MUX
54
- int _mux_max_channels; // /< Maximum possible number of MUX channels
54
+ int _mux_max_channels; // /< Maximum possible number of MUX channels
55
55
};
56
56
#endif // WS_I2C_HARDWARE_H
Original file line number Diff line number Diff line change @@ -164,6 +164,16 @@ bool I2cModel::DecodeI2cBusScan(pb_istream_t *stream) {
164
164
&_msg_i2c_bus_scan);
165
165
}
166
166
167
+ /* *********************************************************************/
168
+ /* !
169
+ @brief Returns a pointer to the I2cBusScan message.
170
+ @returns Pointer to a I2cBusScan message.
171
+ */
172
+ /* *********************************************************************/
173
+ wippersnapper_i2c_I2cBusScan *GetI2cBusScanMsg () {
174
+ return &_msg_i2c_bus_scan;
175
+ }
176
+
167
177
/* *********************************************************************/
168
178
/* !
169
179
@brief Returns a pointer to the I2cBusScanned message.
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ class I2cModel {
45
45
wippersnapper_i2c_I2cDeviceAddOrReplace *GetI2cDeviceAddOrReplaceMsg ();
46
46
wippersnapper_i2c_I2cDeviceAddedOrReplaced *GetMsgI2cDeviceAddedOrReplaced ();
47
47
wippersnapper_i2c_I2cDeviceEvent *GetI2cDeviceEvent ();
48
+ wippersnapper_i2c_I2cBusScan *GetI2cBusScanMsg ();
48
49
wippersnapper_i2c_I2cBusScanned *GetI2cBusScannedMsg ();
49
50
// I2cBusScanned Message API
50
51
void ClearI2cBusScanned ();
Original file line number Diff line number Diff line change 9
9
PB_BIND (wippersnapper_i2c_I2cDeviceDescriptor , wippersnapper_i2c_I2cDeviceDescriptor , AUTO )
10
10
11
11
12
+ PB_BIND (wippersnapper_i2c_I2cMuxDescriptor , wippersnapper_i2c_I2cMuxDescriptor , AUTO )
13
+
14
+
15
+ PB_BIND (wippersnapper_i2c_I2cBusDescriptor , wippersnapper_i2c_I2cBusDescriptor , AUTO )
16
+
17
+
12
18
PB_BIND (wippersnapper_i2c_I2cBusScan , wippersnapper_i2c_I2cBusScan , AUTO )
13
19
14
20
You can’t perform that action at this time.
0 commit comments