trim controller

This commit is contained in:
brentru 2025-04-10 12:19:05 -04:00
parent d86a445735
commit 8313b66a82
2 changed files with 16 additions and 14 deletions

View file

@ -858,7 +858,7 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
bool I2cController::ScanI2cBus(bool default_bus = true) {
_i2c_bus_default->InitBus(default_bus);
_scan_results = wippersnapper_i2c_I2cBusScanned_init_zero;
if (!default_bus)
if (! default_bus)
return _i2c_bus_alt->ScanBus(&_scan_results);
return _i2c_bus_default->ScanBus(&_scan_results);
}
@ -874,11 +874,10 @@ bool I2cController::ScanI2cBus(bool default_bus = true) {
/***********************************************************************/
bool I2cController::WasDeviceScanned(uint32_t address) {
pb_size_t num_found_devices = _scan_results.i2c_bus_found_devices_count;
WS_DEBUG_PRINT("[i2c] # of Scanned Devices: ");
WS_DEBUG_PRINTLN(num_found_devices);
if (num_found_devices == 0)
return false; // no devices found on bus, or scan was not performed
// Check if the device was found on the bus
for (pb_size_t i; i < num_found_devices; i++) {
if (_scan_results.i2c_bus_found_devices[i].i2c_device_address == address)
return true; // device found on bus!
@ -886,26 +885,30 @@ bool I2cController::WasDeviceScanned(uint32_t address) {
return false; // exhausted all scanned devices, didn't find it
}
/***********************************************************************/
/*!
@brief Returns an i2c address of a device found on the bus.
@param index
The index of the scanned device within scan_results.
@returns The I2C device address of the scanned device.
*/
/***********************************************************************/
uint32_t I2cController::GetScanDeviceAddress(int index) {
if (index < 0 || index >= _scan_results.i2c_bus_found_devices_count)
return 0;
return _scan_results.i2c_bus_found_devices[index].i2c_device_address;
}
/***********************************************************************/
/*!
@brief Gets the number of devices found on the bus.
@returns The number of devices found on the bus.
*/
/***********************************************************************/
size_t I2cController::GetScanDeviceCount() {
return _scan_results.i2c_bus_found_devices_count;
}
void I2cController::PrintScanResults() {
WS_DEBUG_PRINT("[i2c] # of Scanned Devices: ");
WS_DEBUG_PRINTLN(_scan_results.i2c_bus_found_devices_count);
for (pb_size_t i = 0; i < _scan_results.i2c_bus_found_devices_count; i++) {
WS_DEBUG_PRINT("[i2c] Device found at address: ");
WS_DEBUG_PRINTLN(_scan_results.i2c_bus_found_devices[i].i2c_device_address,
HEX);
}
}
/********************************************************************************/
/*!
@brief Enables a MUX channel on the appropriate I2C bus.

View file

@ -105,7 +105,6 @@ public:
void ConfigureMuxChannel(uint32_t mux_channel, bool is_alt_bus);
bool ScanI2cBus(bool default_bus);
bool WasDeviceScanned(uint32_t address);
void PrintScanResults();
uint32_t GetScanDeviceAddress(int index);
size_t GetScanDeviceCount();
bool IsDriverInitialized(wippersnapper_i2c_I2cDeviceDescriptor& device_descriptor);