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 ### Breaking Changed
### Changed ### Changed
- AHT1X/AHT2X/AHT3X ready for virtual I2C
- SGP4X ready for virtual I2C
### Fixed ### Fixed
- ESP32S3 UART output mode for Tx - ESP32S3 UART output mode for Tx

View File

@ -81,7 +81,7 @@ void sgp4x_Init(void)
uint16_t serialNumber[serialNumberSize]; uint16_t serialNumber[serialNumberSize];
uint16_t error; uint16_t error;
sgp4x.begin(Wire); sgp4x.begin(I2cGetWire());
error = sgp4x.getSerialNumber(serialNumber, serialNumberSize); error = sgp4x.getSerialNumber(serialNumber, serialNumberSize);
if (error) { if (error) {

View File

@ -94,9 +94,10 @@ struct {
} aht1x_sensors[AHT1X_MAX_SENSORS]; } aht1x_sensors[AHT1X_MAX_SENSORS];
bool AHT1XWrite(uint8_t aht1x_idx) { bool AHT1XWrite(uint8_t aht1x_idx) {
Wire.beginTransmission(aht1x_sensors[aht1x_idx].address); TwoWire &wire = I2cGetWire();
Wire.write(AHTMeasureCmd, 3); wire.beginTransmission(aht1x_sensors[aht1x_idx].address);
if (Wire.endTransmission() != 0) wire.write(AHTMeasureCmd, 3);
if (wire.endTransmission() != 0)
return false; return false;
delay(AHT1X_MEAS_DELAY); delay(AHT1X_MEAS_DELAY);
return true; return true;
@ -104,10 +105,11 @@ bool AHT1XWrite(uint8_t aht1x_idx) {
bool AHT1XRead(uint8_t aht1x_idx) { bool AHT1XRead(uint8_t aht1x_idx) {
uint8_t data[6]; 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++) { for(uint8_t i = 0; wire.available() > 0; i++) {
data[i] = Wire.read(); data[i] = wire.read();
} }
if (data[0] & 0x80) if (data[0] & 0x80)
return false; //device is busy return false; //device is busy
@ -141,23 +143,26 @@ unsigned char AHT1XReadStatus(uint8_t aht1x_address) {
//Wire.beginTransmission(aht1x_address); //Wire.beginTransmission(aht1x_address);
//Wire.write(0x71); //Wire.write(0x71);
//if (Wire.endTransmission() != 0) return false; //if (Wire.endTransmission() != 0) return false;
Wire.requestFrom(aht1x_address, (uint8_t) 1); TwoWire &wire = I2cGetWire();
result = Wire.read(); wire.requestFrom(aht1x_address, (uint8_t) 1);
result = wire.read();
return result; return result;
} }
void AHT1XReset(uint8_t aht1x_address) { void AHT1XReset(uint8_t aht1x_address) {
Wire.beginTransmission(aht1x_address); TwoWire &wire = I2cGetWire();
Wire.write(AHTResetCmd); wire.beginTransmission(aht1x_address);
Wire.endTransmission(); wire.write(AHTResetCmd);
wire.endTransmission();
delay(AHT1X_RST_DELAY); delay(AHT1X_RST_DELAY);
} }
/********************************************************************************************/ /********************************************************************************************/
bool AHT1XInit(uint8_t aht1x_address) { bool AHT1XInit(uint8_t aht1x_address) {
Wire.beginTransmission(aht1x_address); TwoWire &wire = I2cGetWire();
Wire.write(AHTSetCalCmd, 3); wire.beginTransmission(aht1x_address);
if (Wire.endTransmission() != 0) wire.write(AHTSetCalCmd, 3);
if (wire.endTransmission() != 0)
return false; return false;
delay(AHT1X_CMD_DELAY); delay(AHT1X_CMD_DELAY);
if(AHT1XReadStatus(aht1x_address) & 0x08) // Sensor calibrated? if(AHT1XReadStatus(aht1x_address) & 0x08) // Sensor calibrated?