i2c_bus.h 523 B

123456789101112131415161718192021222324
  1. #pragma once
  2. #include <Arduino.h>
  3. #include <Wire.h>
  4. #include "config.h"
  5. // The PCF85063 RTC and the SHTC3 sensor share one bus. Both drivers call this;
  6. // only the first call does any work.
  7. inline bool i2cBusBegin()
  8. {
  9. static bool started = false;
  10. if (!started) {
  11. started = Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN, I2C_FREQ_HZ);
  12. }
  13. return started;
  14. }
  15. // True if a device acknowledges its address.
  16. inline bool i2cDevicePresent(uint8_t addr)
  17. {
  18. Wire.beginTransmission(addr);
  19. return Wire.endTransmission() == 0;
  20. }