Skip to content

Commit a780749

Browse files
committed
Match Protobuf 52c4252a7336cda1274b61cdd5292f580ef4dd3d
1 parent 6d32292 commit a780749

File tree

6 files changed

+102
-25
lines changed

6 files changed

+102
-25
lines changed

src/components/i2c/controller.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,26 @@ bool I2cController::Handle_I2cBusScan(pb_istream_t *stream) {
531531

532532
_i2c_model->ClearI2cBusScanned();
533533
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;
544550
}
545551

546552

553+
547554
// TODO Linear Scan Alt. I2C Bus
548555
// TODO: Check if alt i2c bus ha been initialized yet, call init. directly if not
549556
// TODO If Muxes are present, scan them

src/components/i2c/hardware.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class I2cHardware {
4747
void TogglePowerPin();
4848
wippersnapper_i2c_I2cBusStatus _bus_status; ///< I2C bus status
4949
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
5252
bool _has_mux; ///< Is a MUX present on the bus?
5353
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
5555
};
5656
#endif // WS_I2C_HARDWARE_H

src/components/i2c/model.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ bool I2cModel::DecodeI2cBusScan(pb_istream_t *stream) {
164164
&_msg_i2c_bus_scan);
165165
}
166166

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+
167177
/**********************************************************************/
168178
/*!
169179
@brief Returns a pointer to the I2cBusScanned message.

src/components/i2c/model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class I2cModel {
4545
wippersnapper_i2c_I2cDeviceAddOrReplace *GetI2cDeviceAddOrReplaceMsg();
4646
wippersnapper_i2c_I2cDeviceAddedOrReplaced *GetMsgI2cDeviceAddedOrReplaced();
4747
wippersnapper_i2c_I2cDeviceEvent *GetI2cDeviceEvent();
48+
wippersnapper_i2c_I2cBusScan *GetI2cBusScanMsg();
4849
wippersnapper_i2c_I2cBusScanned *GetI2cBusScannedMsg();
4950
// I2cBusScanned Message API
5051
void ClearI2cBusScanned();

src/protos/i2c.pb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
PB_BIND(wippersnapper_i2c_I2cDeviceDescriptor, wippersnapper_i2c_I2cDeviceDescriptor, AUTO)
1010

1111

12+
PB_BIND(wippersnapper_i2c_I2cMuxDescriptor, wippersnapper_i2c_I2cMuxDescriptor, AUTO)
13+
14+
15+
PB_BIND(wippersnapper_i2c_I2cBusDescriptor, wippersnapper_i2c_I2cBusDescriptor, AUTO)
16+
17+
1218
PB_BIND(wippersnapper_i2c_I2cBusScan, wippersnapper_i2c_I2cBusScan, AUTO)
1319

1420

0 commit comments

Comments
 (0)