Skip to content

Commit 59bb1e5

Browse files
committed
Use fix for Wire1, too
1 parent e602c71 commit 59bb1e5

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/components/i2c/controller.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,19 @@ bool I2cController::ScanI2cBus(bool default_bus = true) {
881881
}
882882
}
883883

884+
/***********************************************************************/
885+
/*!
886+
@brief Returns the I2C bus object.
887+
@param is_alt_bus
888+
True if the alternative I2C bus is being used, False
889+
otherwise.
890+
@returns A pointer to the I2C bus object.
891+
*/
892+
/***********************************************************************/
884893
TwoWire *I2cController::GetI2cBus(bool is_alt_bus) {
894+
if (is_alt_bus) {
895+
return _i2c_bus_alt->GetBus();
896+
}
885897
return _i2c_bus_default->GetBus();
886898
}
887899

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ void ws_sdcard::ConfigureSDCard() {
121121
/**************************************************************************/
122122
bool ws_sdcard::InitDS1307() {
123123
_rtc_ds1307 = new RTC_DS1307();
124-
if (!_rtc_ds1307->begin()) {
125-
if (!_rtc_ds1307->begin(&Wire1)) {
126-
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC");
124+
if (!_rtc_ds1307->begin(WsV2._i2c_controller->GetI2cBus())) {
125+
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC on WIRE");
126+
if (!_rtc_ds1307->begin(WsV2._i2c_controller->GetI2cBus(true))) {
127+
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS1307 RTC on WIRE1");
127128
delete _rtc_ds1307;
128129
return false;
129130
}
@@ -144,9 +145,10 @@ bool ws_sdcard::InitDS1307() {
144145
bool ws_sdcard::InitDS3231() {
145146
WS_DEBUG_PRINTLN("Begin DS3231 init");
146147
_rtc_ds3231 = new RTC_DS3231();
147-
if (!_rtc_ds3231->begin(&Wire)) {
148-
if (!_rtc_ds3231->begin(&Wire1)) {
149-
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC");
148+
if (!_rtc_ds3231->begin(WsV2._i2c_controller->GetI2cBus())) {
149+
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC on WIRE");
150+
if (!_rtc_ds3231->begin(WsV2._i2c_controller->GetI2cBus(true))) {
151+
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize DS3231 RTC on WIRE1");
150152
delete _rtc_ds3231;
151153
return false;
152154
}
@@ -165,17 +167,10 @@ bool ws_sdcard::InitDS3231() {
165167
*/
166168
/**************************************************************************/
167169
bool ws_sdcard::InitPCF8523() {
168-
WsV2._i2c_controller->ScanI2cBus(true);
169-
WS_DEBUG_PRINT("[sd] Scanned I2C Devices: ")
170-
WS_DEBUG_PRINTLN(WsV2._i2c_controller->GetScanDeviceCount());
171-
WS_DEBUG_PRINT("Was Device Found? ");
172-
WS_DEBUG_PRINTLN(WsV2._i2c_controller->WasDeviceScanned(0x68));
173-
174-
175170
_rtc_pcf8523 = new RTC_PCF8523();
176171
if (!_rtc_pcf8523->begin(WsV2._i2c_controller->GetI2cBus())) {
177172
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE");
178-
if (!_rtc_pcf8523->begin(&Wire1)) {
173+
if (!_rtc_pcf8523->begin(WsV2._i2c_controller->GetI2cBus(true))) {
179174
WS_DEBUG_PRINTLN("[SD] Error: Failed to initialize PCF8523 RTC on WIRE1");
180175
delete _rtc_pcf8523;
181176
return false;

0 commit comments

Comments
 (0)