Skip to content

Commit

Permalink
Prepare for virtual I2C (arendst#22427)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger authored and josef109 committed Nov 10, 2024
1 parent 992fec8 commit 32a47e3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file.
### Breaking Changed

### Changed
- AHT1X/AHT2X/AHT3X ready for virtual I2C
- SGP4X ready for virtual I2C

### Fixed
- ESP32S3 UART output mode for Tx
Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota_xsns_sensor/xsns_109_sgp4x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void sgp4x_Init(void)
uint16_t serialNumber[serialNumberSize];
uint16_t error;

sgp4x.begin(Wire);
sgp4x.begin(I2cGetWire());
error = sgp4x.getSerialNumber(serialNumber, serialNumberSize);

if (error) {
Expand Down
33 changes: 19 additions & 14 deletions tasmota/tasmota_xsns_sensor/xsns_63_aht1x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,22 @@ struct {
} aht1x_sensors[AHT1X_MAX_SENSORS];

bool AHT1XWrite(uint8_t aht1x_idx) {
Wire.beginTransmission(aht1x_sensors[aht1x_idx].address);
Wire.write(AHTMeasureCmd, 3);
if (Wire.endTransmission() != 0)
TwoWire &wire = I2cGetWire();
wire.beginTransmission(aht1x_sensors[aht1x_idx].address);
wire.write(AHTMeasureCmd, 3);
if (wire.endTransmission() != 0)
return false;
delay(AHT1X_MEAS_DELAY);
return true;
}

bool AHT1XRead(uint8_t aht1x_idx) {
uint8_t data[6];
Wire.requestFrom(aht1x_sensors[aht1x_idx].address, (uint8_t) 6);
TwoWire &wire = I2cGetWire();
wire.requestFrom(aht1x_sensors[aht1x_idx].address, (uint8_t) 6);

for(uint8_t i = 0; Wire.available() > 0; i++) {
data[i] = Wire.read();
for(uint8_t i = 0; wire.available() > 0; i++) {
data[i] = wire.read();
}
if (data[0] & 0x80)
return false; //device is busy
Expand Down Expand Up @@ -141,23 +143,26 @@ unsigned char AHT1XReadStatus(uint8_t aht1x_address) {
//Wire.beginTransmission(aht1x_address);
//Wire.write(0x71);
//if (Wire.endTransmission() != 0) return false;
Wire.requestFrom(aht1x_address, (uint8_t) 1);
result = Wire.read();
TwoWire &wire = I2cGetWire();
wire.requestFrom(aht1x_address, (uint8_t) 1);
result = wire.read();
return result;
}

void AHT1XReset(uint8_t aht1x_address) {
Wire.beginTransmission(aht1x_address);
Wire.write(AHTResetCmd);
Wire.endTransmission();
TwoWire &wire = I2cGetWire();
wire.beginTransmission(aht1x_address);
wire.write(AHTResetCmd);
wire.endTransmission();
delay(AHT1X_RST_DELAY);
}

/********************************************************************************************/
bool AHT1XInit(uint8_t aht1x_address) {
Wire.beginTransmission(aht1x_address);
Wire.write(AHTSetCalCmd, 3);
if (Wire.endTransmission() != 0)
TwoWire &wire = I2cGetWire();
wire.beginTransmission(aht1x_address);
wire.write(AHTSetCalCmd, 3);
if (wire.endTransmission() != 0)
return false;
delay(AHT1X_CMD_DELAY);
if(AHT1XReadStatus(aht1x_address) & 0x08) // Sensor calibrated?
Expand Down

0 comments on commit 32a47e3

Please sign in to comment.