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.

43 lines
894 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. void i2cScan() {
  8. uint8_t address;
  9. uint8_t response;
  10. uint8_t buffer[1];
  11. int nDevices = 0;
  12. for (address = 1; address < 128; address++) {
  13. brzo_i2c_start_transaction(address, I2C_SCL_FREQUENCY);
  14. brzo_i2c_ACK_polling(1000);
  15. response = brzo_i2c_end_transaction();
  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"));
  24. }
  25. void i2cSetup() {
  26. brzo_i2c_setup(I2C_SDA_PIN, I2C_SCL_PIN, I2C_CLOCK_STRETCH_TIME);
  27. i2cScan();
  28. }
  29. #endif