Prepare for virtual I2C (#22427)

This commit is contained in:
s-hadinger 2024-11-04 22:31:50 +01:00 committed by GitHub
parent 57d8bea761
commit 94c45689a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 15 deletions

View File

@ -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

View File

@ -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) {

View File

@ -94,9 +94,10 @@ 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;
@ -104,10 +105,11 @@ bool AHT1XWrite(uint8_t aht1x_idx) {
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
@ -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?