// Basic config #include "globals.h" #include "i2cscan.h" // Local logging tag static const char TAG[] = __FILE__; #define SSD1306_PRIMARY_ADDRESS (0x3D) #define SSD1306_SECONDARY_ADDRESS (0x3C) #define BME_PRIMARY_ADDRESS (0x77) #define BME_SECONDARY_ADDRESS (0x76) #define AXP192_PRIMARY_ADDRESS (0x34) #define MCP_24AA02E64_PRIMARY_ADDRESS (0x50) #define QUECTEL_GPS_PRIMARY_ADDRESS (0x10) int i2c_scan(void) { int i2c_ret, addr; int devices = 0; ESP_LOGI(TAG, "Starting I2C bus scan..."); for (addr = 8; addr <= 119; addr++) { // scan i2c bus with no more to 100KHz #ifdef HAS_DISPLAY Wire.begin(MY_OLED_SDA, MY_OLED_SCL, 100000); #else Wire.begin(SDA, SCL, 100000); #endif Wire.beginTransmission(addr); Wire.write(addr); i2c_ret = Wire.endTransmission(); if (i2c_ret == 0) { devices++; switch (addr) { case SSD1306_PRIMARY_ADDRESS: case SSD1306_SECONDARY_ADDRESS: ESP_LOGI(TAG, "0x%X: SSD1306 Display controller", addr); break; case BME_PRIMARY_ADDRESS: case BME_SECONDARY_ADDRESS: ESP_LOGI(TAG, "0x%X: Bosch BME MEMS", addr); break; case AXP192_PRIMARY_ADDRESS: ESP_LOGI(TAG, "0x%X: AXP192 power management", addr); #ifdef HAS_PMU AXP192_init(); #endif break; case QUECTEL_GPS_PRIMARY_ADDRESS: ESP_LOGI(TAG, "0x%X: Quectel GPS", addr); break; case MCP_24AA02E64_PRIMARY_ADDRESS: ESP_LOGI(TAG, "0x%X: 24AA02E64 serial EEPROM", addr); break; default: ESP_LOGI(TAG, "0x%X: Unknown device", addr); break; } } // switch } // for loop ESP_LOGI(TAG, "I2C scan done, %u devices found.", devices); return devices; } #ifdef HAS_PMU void AXP192_init(void) { AXP20X_Class axp; if (axp.begin(Wire, AXP192_PRIMARY_ADDRESS)) ESP_LOGI(TAG, "AXP192 PMU initialization failed"); else { axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON); axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON); axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); axp.setDCDC1Voltage(3300); axp.setChgLEDMode(AXP20X_LED_BLINK_1HZ); // axp.setChgLEDMode(AXP20X_LED_OFF); axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); #ifdef PMU_INT pinMode(PMU_INT, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(PMU_INT), [] { ESP_LOGI(TAG, "Power source changed"); /* put your code here */ }, FALLING); axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); axp.clearIRQ(); #endif // PMU_INT ESP_LOGI(TAG, "AXP192 PMU initialized."); } } #endif // HAS_PMU