Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
930 B

  1. /*
  2. I2C MODULE
  3. Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if I2C_SUPPORT
  6. #include "brzo_i2c.h"
  7. bool i2cCheck(unsigned char address) {
  8. brzo_i2c_start_transaction(address, I2C_SCL_FREQUENCY);
  9. brzo_i2c_ACK_polling(1000);
  10. return brzo_i2c_end_transaction();
  11. }
  12. void i2cScan() {
  13. unsigned char nDevices = 0;
  14. for (unsigned char address = 1; address < 128; address++) {
  15. unsigned char response = i2cCheck(address);
  16. if (response == 0) {
  17. DEBUG_MSG_P(PSTR("[I2C] Device found at address 0x%02X\n"), address);
  18. nDevices++;
  19. } else if (response != 32) {
  20. //DEBUG_MSG_P(PSTR("[I2C] Unknown error at address 0x%02X\n"), address);
  21. }
  22. }
  23. if (nDevices == 0) DEBUG_MSG_P(PSTR("[I2C] No devices found\n"));
  24. }
  25. void i2cSetup() {
  26. brzo_i2c_setup(I2C_SDA_PIN, I2C_SCL_PIN, I2C_CLOCK_STRETCH_TIME);
  27. i2cScan();
  28. }
  29. #endif