I2C device discovery and printout of known device names

Files at this revision

API Documentation at this revision

Comitter:
loopsva
Date:
Thu Jan 10 17:44:10 2019 +0000
Commit message:
General I2C device updates

Changed in this revision

i2cDevices.cpp Show annotated file Show diff for this revision Revisions of this file
i2cDevices.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i2cDevices.cpp	Thu Jan 10 17:44:10 2019 +0000
@@ -0,0 +1,751 @@
+#include "mbed.h"
+#include "i2cDevices.h"
+
+extern RawSerial pc;
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+//Constructor
+
+i2c_discovery::i2c_discovery(PinName sda, PinName scl, const char* name)  : _i2c(sda, scl) {
+        _i2c.frequency(100000);
+}
+
+//--------------------------------------------------------------------------------------------------------------------------------------//
+//Display detected i2c device name
+
+int i2c_discovery::showI2C(i2cDeviceFlags& i2cFlags, char addr) {
+    switch (addr) {
+#ifdef  I2C_0x02
+        case 0x02: 
+            pc.printf("%s\r\n", I2C_0x02);
+            i2cFlags.PCA9955_GGG_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x04
+        case 0x04: 
+            pc.printf("%s\r\n", I2C_0x04);
+            break;
+#endif
+#ifdef  I2C_0x06
+        case 0x06: 
+            pc.printf("%s\r\n", I2C_0x06);
+            break;
+#endif
+#ifdef  I2C_0x08
+        case 0x08: 
+            pc.printf("%s\r\n", I2C_0x08);
+            break;
+#endif
+#ifdef  I2C_0x0A
+        case 0x0A: 
+            pc.printf("%s\r\n", I2C_0x0A);
+            break;
+#endif
+#ifdef  I2C_0x0C
+        case 0x0C: 
+            pc.printf("%s\r\n", I2C_0x0C);
+            break;
+#endif
+#ifdef  I2C_0x0E
+        case 0x0E: 
+            pc.printf("%s\r\n", I2C_0x0E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x10
+        case 0x10: 
+            pc.printf("%s\r\n", I2C_0x10);
+            break;
+#endif
+#ifdef  I2C_0x12
+        case 0x12: 
+            pc.printf("%s\r\n", I2C_0x12);
+            break;
+#endif
+#ifdef  I2C_0x14
+        case 0x14: 
+            pc.printf("%s\r\n", I2C_0x14);
+            break;
+#endif
+#ifdef  I2C_0x16
+        case 0x16: 
+            pc.printf("%s\r\n", I2C_0x16);
+            break;
+#endif
+#ifdef  I2C_0x18
+        case 0x18: 
+            pc.printf("%s\r\n", I2C_0x18);
+            break;
+#endif
+#ifdef  I2C_0x1A
+        case 0x1A: 
+            pc.printf("%s\r\n", I2C_0x1A);
+            break;
+#endif
+#ifdef  I2C_0x1C
+        case 0x1C: 
+            pc.printf("%s\r\n", I2C_0x1C);
+            break;
+#endif
+#ifdef  I2C_0x1E
+        case 0x1E: 
+            pc.printf("%s\r\n", I2C_0x1E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x20
+        case 0x20: 
+            pc.printf("%s\r\n", I2C_0x20);
+            i2cFlags.VEML60xx_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x22
+        case 0x22: 
+            pc.printf("%s\r\n", I2C_0x22);
+            break;
+#endif
+#ifdef  I2C_0x24
+        case 0x24: 
+            pc.printf("%s\r\n", I2C_0x24);
+            break;
+#endif
+#ifdef  I2C_0x26
+        case 0x26: 
+            pc.printf("%s\r\n", I2C_0x26);
+            break;
+#endif
+#ifdef  I2C_0x28
+        case 0x28: 
+            pc.printf("%s\r\n", I2C_0x28);
+            break;
+#endif
+#ifdef  I2C_0x2A
+        case 0x2A: 
+            pc.printf("%s\r\n", I2C_0x2A);
+            break;
+#endif
+#ifdef  I2C_0x2C
+        case 0x2C: 
+            pc.printf("%s\r\n", I2C_0x2C);
+            break;
+#endif
+#ifdef  I2C_0x2E
+        case 0x2E: 
+            pc.printf("%s\r\n", I2C_0x2E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x30
+        case 0x30: 
+            pc.printf("%s\r\n", I2C_0x30);
+            break;
+#endif
+#ifdef  I2C_0x32
+        case 0x32: 
+            pc.printf("%s\r\n", I2C_0x32);
+            break;
+#endif
+#ifdef  I2C_0x34
+        case 0x34: 
+            pc.printf("%s\r\n", I2C_0x34);
+            break;
+#endif
+#ifdef  I2C_0x36
+        case 0x36: 
+            pc.printf("%s\r\n", I2C_0x36);
+            break;
+#endif
+#ifdef  I2C_0x38
+        case 0x38: 
+            pc.printf("%s\r\n", I2C_0x38);
+            i2cFlags.mma8451cs1_ok = true;
+            //fxos8700_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x3A
+        case 0x3A: 
+            pc.printf("%s\r\n", I2C_0x3A);
+            //fxos8700_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x3C
+        case 0x3C: 
+            pc.printf("%s\r\n", I2C_0x3C);
+            //fxos8700_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x3E
+        case 0x3E: 
+            pc.printf("%s\r\n", I2C_0x3E);
+            //fxos8700_ok = true;
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x40
+        case 0x40: 
+            pc.printf("%s\r\n", I2C_0x40);
+            break;
+#endif
+#ifdef  I2C_0x42
+        case 0x42: 
+            pc.printf("%s\r\n", I2C_0x42);
+            break;
+#endif
+#ifdef  I2C_0x44
+        case 0x44: 
+            pc.printf("%s\r\n", I2C_0x44);
+            break;
+#endif
+#ifdef  I2C_0x46
+        case 0x46: 
+            pc.printf("%s\r\n", I2C_0x46);
+            break;
+#endif
+#ifdef  I2C_0x48
+        case 0x48: 
+            pc.printf("%s\r\n", I2C_0x48);
+            break;
+#endif
+#ifdef  I2C_0x4A
+        case 0x4A: 
+            pc.printf("%s\r\n", I2C_0x4A);
+            break;
+#endif
+#ifdef  I2C_0x4C
+        case 0x4C: 
+            pc.printf("%s\r\n", I2C_0x4C);
+            break;
+#endif
+#ifdef  I2C_0x4E
+        case 0x4E: 
+            pc.printf("%s\r\n", I2C_0x4E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x50
+        case 0x50: 
+            pc.printf("%s\r\n", I2C_0x50);
+            break;
+#endif
+#ifdef  I2C_0x52
+        case 0x52: 
+            pc.printf("%s\r\n", I2C_0x52);
+            break;
+#endif
+#ifdef  I2C_0x54
+        case 0x54: 
+            pc.printf("%s\r\n", I2C_0x54);
+            break;
+#endif
+#ifdef  I2C_0x56
+        case 0x56: 
+            pc.printf("%s\r\n", I2C_0x56);
+            break;
+#endif
+#ifdef  I2C_0x58
+        case 0x58: 
+            pc.printf("%s\r\n", I2C_0x58);
+            break;
+#endif
+#ifdef  I2C_0x5A
+        case 0x5A: 
+            pc.printf("%s\r\n", I2C_0x5A);
+            break;
+#endif
+#ifdef  I2C_0x5C
+        case 0x5C: 
+            pc.printf("%s\r\n", I2C_0x5C);
+            break;
+#endif
+#ifdef  I2C_0x5E
+        case 0x5E: 
+            pc.printf("%s\r\n", I2C_0x5E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x60
+        case 0x60: 
+            pc.printf("%s\r\n", I2C_0x60);
+            break;
+#endif
+#ifdef  I2C_0x62
+        case 0x62: 
+            pc.printf("%s\r\n", I2C_0x62);
+            break;
+#endif
+#ifdef  I2C_0x64
+        case 0x64: 
+            pc.printf("%s\r\n", I2C_0x64);
+            break;
+#endif
+#ifdef  I2C_0x66
+        case 0x66: 
+            pc.printf("%s\r\n", I2C_0x66);
+            break;
+#endif
+#ifdef  I2C_0x68
+        case 0x68: 
+            pc.printf("%s\r\n", I2C_0x68);
+            break;
+#endif
+#ifdef  I2C_0x6A
+        case 0x6A: 
+            pc.printf("%s\r\n", I2C_0x6A);
+            break;
+#endif
+#ifdef  I2C_0x6C
+        case 0x6C: 
+            pc.printf("%s\r\n", I2C_0x6C);
+            break;
+#endif
+#ifdef  I2C_0x6E
+        case 0x6E: 
+            pc.printf("%s\r\n", I2C_0x6E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x70
+        case 0x70: 
+            pc.printf("%s\r\n", I2C_0x70);
+            i2cFlags.VEML6070_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x72
+        case 0x72: 
+            pc.printf("%s\r\n", I2C_0x72);
+            break;
+#endif
+#ifdef  I2C_0x74
+        case 0x74: 
+            pc.printf("%s\r\n", I2C_0x74);
+            break;
+#endif
+#ifdef  I2C_0x76
+        case 0x76: 
+            pc.printf("%s\r\n", I2C_0x76);
+            break;
+#endif
+#ifdef  I2C_0x78
+        case 0x78: 
+            pc.printf("%s\r\n", I2C_0x78);
+            break;
+#endif
+#ifdef  I2C_0x7A
+        case 0x7A: 
+            pc.printf("%s\r\n", I2C_0x7A);
+            break;
+#endif
+#ifdef  I2C_0x7C
+        case 0x7C: 
+            pc.printf("%s\r\n", I2C_0x7C);
+            break;
+#endif
+#ifdef  I2C_0x7E
+        case 0x7E: 
+            pc.printf("%s\r\n", I2C_0x7E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x80
+        case 0x80: 
+            pc.printf("%s\r\n", I2C_0x80);
+            i2cFlags.HTU21D_ok = true;
+            i2cFlags.INA219_MAX7300_gg_ok = true;
+            i2cFlags.INA230_MAX7300_gg_ok = true;
+            break;
+#endif
+#ifdef  I2C_0x82
+        case 0x82: 
+            pc.printf("%s\r\n", I2C_0x82);
+            break;
+#endif
+#ifdef  I2C_0x84
+        case 0x84: 
+            pc.printf("%s\r\n", I2C_0x84);
+            break;
+#endif
+#ifdef  I2C_0x86
+        case 0x86: 
+            pc.printf("%s\r\n", I2C_0x86);
+            break;
+#endif
+#ifdef  I2C_0x88
+        case 0x88: 
+            pc.printf("%s\r\n", I2C_0x88);
+            break;
+#endif
+#ifdef  I2C_0x8A
+        case 0x8A: 
+            pc.printf("%s\r\n", I2C_0x8A);
+            break;
+#endif
+#ifdef  I2C_0x8C
+        case 0x8C: 
+            pc.printf("%s\r\n", I2C_0x8C);
+            break;
+#endif
+#ifdef  I2C_0x8E
+        case 0x8E: 
+            pc.printf("%s\r\n", I2C_0x8E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0x90
+        case 0x90: 
+            pc.printf("%s\r\n", I2C_0x90);
+            break;
+#endif
+#ifdef  I2C_0x92
+        case 0x92: 
+            pc.printf("%s\r\n", I2C_0x92);
+            break;
+#endif
+#ifdef  I2C_0x94
+        case 0x94: 
+            pc.printf("%s\r\n", I2C_0x94);
+            break;
+#endif
+#ifdef  I2C_0x96
+        case 0x96: 
+            pc.printf("%s\r\n", I2C_0x96);
+            break;
+#endif
+#ifdef  I2C_0x98
+        case 0x98: 
+            pc.printf("%s\r\n", I2C_0x98);
+            break;
+#endif
+#ifdef  I2C_0x9A
+        case 0x9A: 
+            pc.printf("%s\r\n", I2C_0x9A);
+            break;
+#endif
+#ifdef  I2C_0x9C
+        case 0x9C: 
+            pc.printf("%s\r\n", I2C_0x9C);
+            break;
+#endif
+#ifdef  I2C_0x9E
+        case 0x9E: 
+            pc.printf("%s\r\n", I2C_0x9E);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xA0
+        case 0xA0: 
+            pc.printf("%s\r\n", I2C_0xA0);
+            i2cFlags.eeprom000_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xA2
+        case 0xA2: 
+            pc.printf("%s\r\n", I2C_0xA2);
+            break;
+#endif
+#ifdef  I2C_0xA4
+        case 0xA4: 
+            pc.printf("%s\r\n", I2C_0xA4);
+            break;
+#endif
+#ifdef  I2C_0xA6
+        case 0xA6: 
+            pc.printf("%s\r\n", I2C_0xA6);
+            break;
+#endif
+#ifdef  I2C_0xA8
+        case 0xA8: 
+            pc.printf("%s\r\n", I2C_0xA8);
+            break;
+#endif
+#ifdef  I2C_0xAA
+        case 0xAA: 
+            pc.printf("%s\r\n", I2C_0xAA);
+            i2cFlags.bq27210_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xAC
+        case 0xAC: 
+            pc.printf("%s\r\n", I2C_0xAC);
+            break;
+#endif
+#ifdef  I2C_0xAE
+        case 0xAE: 
+            pc.printf("%s\r\n", I2C_0xAE);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xB0
+        case 0xB0: 
+            pc.printf("%s\r\n", I2C_0xB0);
+            break;
+#endif
+#ifdef  I2C_0xB2
+        case 0xB2: 
+            pc.printf("%s\r\n", I2C_0xB2);
+            break;
+#endif
+#ifdef  I2C_0xB4
+        case 0xB4: 
+            pc.printf("%s\r\n", I2C_0xB4);
+            i2cFlags.ccs811_0_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xB6
+        case 0xB6: 
+            pc.printf("%s\r\n", I2C_0xB6);
+            i2cFlags.ccs811_1_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xB8
+        case 0xB8: 
+            pc.printf("%s\r\n", I2C_0xB8);
+            break;
+#endif
+#ifdef  I2C_0xBA
+        case 0xBA: 
+            pc.printf("%s\r\n", I2C_0xBA);
+            break;
+#endif
+#ifdef  I2C_0xBC
+        case 0xBC: 
+            pc.printf("%s\r\n", I2C_0xBC);
+            break;
+#endif
+#ifdef  I2C_0xBE
+        case 0xBE: 
+            pc.printf("%s\r\n", I2C_0xBE);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xC0
+        case 0xC0: 
+            pc.printf("%s\r\n", I2C_0xC0);
+            i2cFlags.mlx90620_ok = true;
+            //i2cFlags.PCA9955_GGG_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xC2
+        case 0xC2: 
+            pc.printf("%s\r\n", I2C_0xC2);
+            i2cFlags.SCD30_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xC4
+        case 0xC4: 
+            pc.printf("%s\r\n", I2C_0xC4);
+            break;
+#endif
+#ifdef  I2C_0xC6
+        case 0xC6: 
+            pc.printf("%s\r\n", I2C_0xC6);
+            break;
+#endif
+#ifdef  I2C_0xC8
+        case 0xC8: 
+            pc.printf("%s\r\n", I2C_0xC8);
+            break;
+#endif
+#ifdef  I2C_0xCA
+        case 0xCA: 
+            pc.printf("%s\r\n", I2C_0xCA);
+            break;
+#endif
+#ifdef  I2C_0xCC
+        case 0xCC: 
+            pc.printf("%s\r\n", I2C_0xCC);
+            break;
+#endif
+#ifdef  I2C_0xCE
+        case 0xCE: 
+            pc.printf("%s\r\n", I2C_0xCE);
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xD0
+        case 0xD0: 
+            pc.printf("%s\r\n", I2C_0xD0);
+            i2cFlags.rtcDS_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xD2
+        case 0xD2: 
+            pc.printf("%s\r\n", I2C_0xD2);
+            break;
+#endif
+#ifdef  I2C_0xD4
+        case 0xD4: 
+            pc.printf("%s\r\n", I2C_0xD4);
+            break;
+#endif
+#ifdef  I2C_0xD6
+        case 0xD6: 
+            pc.printf("%s\r\n", I2C_0xD6);
+            break;
+#endif
+#ifdef  I2C_0xD8
+        case 0xD8: 
+            pc.printf("%s\r\n", I2C_0xD8);
+            break;
+#endif
+#ifdef  I2C_0xDA
+        case 0xDA: 
+            pc.printf("%s\r\n", I2C_0xDA);
+            break;
+#endif
+#ifdef  I2C_0xDC
+        case 0xDC: 
+            pc.printf("%s\r\n", I2C_0xDC);
+            break;
+#endif
+#ifdef  I2C_0xDE
+        case 0xDE: 
+            pc.printf("%s\r\n", I2C_0xDE);
+            i2cFlags.mcp7941x_ok = true;
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xE0
+        case 0xE0: 
+            pc.printf("%s\r\n", I2C_0xE0);
+            break;
+#endif
+#ifdef  I2C_0xE2
+        case 0xE2: 
+            pc.printf("%s\r\n", I2C_0xE2);
+            break;
+#endif
+#ifdef  I2C_0xE4
+        case 0xE4: 
+            pc.printf("%s\r\n", I2C_0xE4);
+            break;
+#endif
+#ifdef  I2C_0xE6
+        case 0xE6: 
+            pc.printf("%s\r\n", I2C_0xE6);
+            break;
+#endif
+#ifdef  I2C_0xE8
+        case 0xE8: 
+            pc.printf("%s\r\n", I2C_0xE8);
+            break;
+#endif
+#ifdef  I2C_0xEA
+        case 0xEA: 
+            pc.printf("%s\r\n", I2C_0xEA);
+            break;
+#endif
+#ifdef  I2C_0xEC
+        case 0xEC: 
+            pc.printf("%s\r\n", I2C_0xEC);
+            i2cFlags.bme280_cs0_ok = true;
+            break;
+#endif
+#ifdef  I2C_0xEE
+        case 0xEE: 
+            pc.printf("%s\r\n", I2C_0xEE);
+            i2cFlags.ms5611_ok = true;
+            i2cFlags.bme280_cs1_ok = true;
+            break;
+#endif
+//----------------------------------------
+#ifdef  I2C_0xF0
+        case 0xF0: 
+            pc.printf("%s\r\n", I2C_0xF0);
+            break;
+#endif
+#ifdef  I2C_0xF2
+        case 0xF2: 
+            pc.printf("%s\r\n", I2C_0xF2);
+            break;
+#endif
+#ifdef  I2C_0xF4
+        case 0xF4: 
+            pc.printf("%s\r\n", I2C_0xF4);
+            break;
+#endif
+#ifdef  I2C_0xF6
+        case 0xF6: 
+            pc.printf("%s\r\n", I2C_0xF6);
+            break;
+#endif
+#ifdef  I2C_0xF8
+        case 0xF8: 
+            pc.printf("%s\r\n", I2C_0xF8);
+            break;
+#endif
+#ifdef  I2C_0xFA
+        case 0xFA: 
+            pc.printf("%s\r\n", I2C_0xFA);
+            break;
+#endif
+#ifdef  I2C_0xFC
+        case 0xFC: 
+            pc.printf("%s\r\n", I2C_0xFC);
+            break;
+#endif
+#ifdef  I2C_0xFE
+        case 0xFE: 
+            pc.printf("%s\r\n", I2C_0xFE);
+            break;
+#endif
+//----------------------------------------   
+        default:
+            pc.printf("%sunknown%s\r\n", DOMAGENTA, DONONE);
+            break;
+    }
+    return(0);    
+}
+
+//------------------------------------------------------------------------------
+// Clear I2C device flags
+
+void i2c_discovery::clearFlags(i2cDeviceFlags& i2cFlags) {
+    i2cFlags.rtcDS_ok = false;
+    i2cFlags.ms5611_ok = false;
+    i2cFlags.bme280_cs0_ok = false;
+    i2cFlags.bme280_cs1_ok = false;
+    i2cFlags.mma8451cs1_ok = false;
+    i2cFlags.HTU21D_ok = false;
+    i2cFlags.PCA9955_GGG_ok = false;
+    i2cFlags.VEML60xx_ok = false;
+    i2cFlags.VEML6070_ok = false;
+    i2cFlags.eeprom000_ok = false;
+    i2cFlags.INA219_MAX7300_gg_ok = false;
+    i2cFlags.INA230_MAX7300_gg_ok = false;
+    i2cFlags.bq27210_ok = false;
+    i2cFlags.SCD30_ok = false;
+    i2cFlags.ccs811_0_ok = false;
+    i2cFlags.ccs811_1_ok = false;
+    i2cFlags.mcp7941x_ok = false;
+}
+    
+//------------------------------------------------------------------------------
+// Detect I2C device chain.  If i2c chain > 1, return illegal number 255.  Else, 
+// return the total number of i2c devices detected
+
+int i2c_discovery::dispI2C(i2cDeviceFlags& i2cFlags) {
+    //i2c_discovery::clearFlags(i2cFlags);
+    int count = 0;
+    for (int address = 2; address < 256; address +=2) {
+        char xBuf[2] = { 0, 0 };
+        int x2c = _i2c.write(address, xBuf, 1, false);
+        if(x2c == 0) {
+            pc.printf(" - i2c device found at address 0x%02X  %s", address, DOBLUE);
+            showI2C(i2cFlags, address);
+            pc.printf("%s", DONONE);
+            count++;
+        }
+    }
+    return(count);
+}
+
+//------------------------------------------------------------------------------
+// Detect I2C device chain
+
+int i2c_discovery::find_i2c(i2cDeviceFlags& i2cFlags) {
+    pc.printf("Searching for devices on i2c bus...\n");
+    int count = dispI2C(i2cFlags);
+    pc.printf("   - %s%2d%s device(s) found on i2c bus\n", DOBLUE, count, DONONE);
+    return(count);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/i2cDevices.h	Thu Jan 10 17:44:10 2019 +0000
@@ -0,0 +1,207 @@
+#ifndef I2CDEVICES_H
+#define I2CDEVICES_H
+
+#include "DevI2C.h"
+
+//if the use of low-level I2C routines is required, uncomment out the next two lines 
+//#define I2CLOWLEVEL     1   
+//#warning "using low level I2C routines"
+
+/** Software routines that show the I2C devices connected to the I2C bus. The
+ *  routine also sets flags that indicate certain I2C devices have been 
+ *  detected.  Those flags are within a "typedef" structure.
+ *
+ * NOTE: Requires the external definition of the user console: "RawSerial pc;"
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "i2cDevices.h"
+ *
+ * RawSerial pc(USBTX, USBRX);
+ * DigitalOut led1(LED1);
+ *
+ * #define SDA         PTE0     //i2c bus for KL25Z
+ * #define SCL         PTE1
+ *
+ * I2C i2c1(SDA, SCL);
+ * i2c_discovery i2c_d(SDA, SCL, "i2c_d");
+ * i2c_discovery::i2cDeviceFlags i2c_flags = {};
+ *
+ * int main() {
+ *     pc.baud(230400);
+ *     i2c1.frequency(400000);
+ *     pc.print("\r\n\r\nbegin....\r\n");
+ *     i2c_d.find_i2c(i2c_flags);
+ *     if(i2c_flags.PCA9955_0 == true) {
+ *         pc.printf("Device detected!\r\n");
+ *     } else {
+ *         pc.printf("Device not found!!!\r\n");
+ *     }
+ *     while(1) {
+ *         led1 = !led1;
+ *         wait(1.0);
+ *     }
+ * }
+ *
+ * @endcode
+ */
+
+//used to define terminal text output color
+#define COLOR_TERM
+#ifdef COLOR_TERM
+    #define DOBLUE      "\033[0;34;2m"
+    #define DOMAGENTA   "\033[0;35;2m"
+    #define DONONE      "\033[0m"
+#else
+    #define DOBLUE      ""
+    #define DOMAGENTA   ""
+    #define DONONE      ""
+#endif
+
+//list of i2c device possibilities
+#define I2C_0x02    "PCA9955-GGG"
+#define I2C_0x06    "SHT1x"
+#define I2C_0x0C    "AK8975"
+
+#define I2C_0x1C    "MAG3110"
+
+#define I2C_0x20    "VEML6040, VEML6075"
+
+#define I2C_0x38    "MMA8451-0, FXOS8700CQ-2"
+#define I2C_0x3A    "MMA8451-1, FXOS8700CQ-1"
+#define I2C_0x3C    "FXOS8700CQ-0, LIS3MDL"
+#define I2C_0x3E    "FXOS8700CQ-3"
+
+#define I2C_0x42    "MCP23017-b"
+#define I2C_0x44    "MCP23017-c"
+#define I2C_0x46    "MCP23017-d"
+
+#define I2C_0x50    "MAX5387-ggg"
+#define I2C_0x52    "MAX5387-ggv, VL53L0X"
+#define I2C_0x54    "MAX5387-gvg"
+#define I2C_0x56    "MAX5387-gvv"
+#define I2C_0x58    "MAX5387-vgg"
+#define I2C_0x5A    "MAX5387-vgv"
+#define I2C_0x5C    "MAX5387-vvg"
+#define I2C_0x5E    "MAX5387-vvv"
+
+#define I2C_0x70    "VEML6070-ld/c"
+#define I2C_0x72    "VEML6070-hd"
+
+#define I2C_0x80    "Si7005, Si7021, HTU21D, HDC1080, INA2xx/MAX7300-gg"
+#define I2C_0x82    "INA2xx/MAX7300-gv"
+#define I2C_0x84    "INA2xx/MAX7300-gd"
+#define I2C_0x86    "INA2xx/MAX7300-gc"
+#define I2C_0x88    "INA2xx/MAX7300-vg"
+#define I2C_0x8A    "INA2xx/MAX7300-vv"
+#define I2C_0x8C    "INA2xx/MAX7300-vd"
+#define I2C_0x8E    "INA2xx/MAX7300-vc"
+
+#define I2C_0x90    "AD7416-a, LM75, INA2xx/MAX7300-dg"
+#define I2C_0x92    "MAX9768, INA2xx/MAX7300-dv"
+#define I2C_0x94    "INA2xx/MAX7300-dd"
+#define I2C_0x96    "INA2xx/MAX7300-dc"
+#define I2C_0x98    "INA2xx/MAX7300-cg"
+#define I2C_0x9A    "INA2xx/MAX7300-cv"
+#define I2C_0x9C    "INA2xx/MAX7300-cd"
+#define I2C_0x9E    "INA2xx/MAX7300-cc"
+
+#define I2C_0xA0    "24FC512-000, 24AA02-b0"
+#define I2C_0xA2    "24AA02-b1"
+#define I2C_0xA4    "24AA02-b2"
+#define I2C_0xA6    "24AA02-b3"
+#define I2C_0xA8    "24AA02-b4"
+#define I2C_0xAA    "MMA8491, 24AA02-b5, BQ27xx0, BQ34Z100-G1"
+#define I2C_0xAC    "24AA02-b6, M24SR64-Y"
+#define I2C_0xAE    "24AA02-b7"
+
+#define I2C_0xB4    "CCS811-0"
+#define I2C_0xB6    "CCS811-1"
+#define I2C_0xBA    "LPS22HB"
+#define I2C_0xBE    "HTS221"
+
+#define I2C_0xC0    "MPL3115A2, MLX90620-ram, PCA9955-0"
+#define I2C_0xC2    "SCD30"
+
+#define I2C_0xD0    "M41T11, DS1307, DS3232M, MCU9150-0"
+#define I2C_0xD2    "MCU9150-1"
+#define I2C_0xD4    "LSM6DSL"
+#define I2C_0xDE    "MCP7941x-rtc"
+
+#define I2C_0xE0    "PCA9955-AllCall"
+#define I2C_0xEC    "MS5611-cs1, BME280-cs0, PCA9955-SubCall"
+#define I2C_0xEE    "MS5611-cs0, BME280-cs1, BMP-05"
+
+/** Create an i2c controller class
+ *
+ * @param i2c class class
+ *
+ */
+class i2c_discovery
+{
+    public:
+    /** Structure which is used to exchange indicate certain
+     *  devices of interest is detected or not by this routine.
+     */    
+    typedef struct {
+        bool rtcDS_ok;          /*!< i2c address 0xd0 */
+        bool ms5611_ok;         /*!< i2c address 0xee */
+        bool bme280_cs0_ok;     /*!< i2c address 0xec */
+        bool bme280_cs1_ok;     /*!< i2c address 0xee */
+        bool mma8451cs1_ok;     /*!< i2c address 0x3a */
+        bool HTU21D_ok;         /*!< i2c address 0x80 */
+        bool INA219_MAX7300_gg_ok; /*!< i2c address 0x80 */
+        bool INA230_MAX7300_gg_ok; /*!< i2c address 0x80 */
+        bool PCA9955_GGG_ok;    /*!< i2c address 0xc0 */
+        bool VEML60xx_ok;       /*!< i2c address 0x20 */
+        bool VEML6070_ok;       /*!< i2c address 0x70 */
+        bool eeprom000_ok;      /*!< i2c address 0xa0 */
+        bool mlx90620_ok;       /*!< i2c address 0xc0 */
+        bool SCD30_ok;          /*!< i2c address 0xc2 */
+        bool bq27210_ok;        /*!< i2c address 0xaa */
+        bool ccs811_0_ok;       /*!< i2c address 0xb4 */
+        bool ccs811_1_ok;       /*!< i2c address 0xb6 */
+        bool mcp7941x_ok;       /*!< i2c address 0xde */
+    } i2cDeviceFlags;
+
+    /**
+     * Constructor, uses default I2C clock speed
+     * - Fixed at I2C address 0x80
+     * - I2C speed set to 400KHz
+     *
+     * @param sda - mbed I2C interface pin
+     * @param scl - mbed I2C interface pin
+     * @param name - name of i2c_discovery
+     */
+    i2c_discovery(PinName sda, PinName scl, const char* name);
+    
+    /**
+     * Clear I2C device Flags
+     * 
+     * @param i2cDeviceFlags pointer
+     *
+     * @return --none--
+    */    
+    void clearFlags(i2cDeviceFlags& i2cFlags);
+    
+    /**
+     * Go and search for I2C devices
+     * 
+     * @param i2cDeviceFlags pointer
+     *
+     * @return count - number of i2c devices detected
+    */     
+    int find_i2c(i2cDeviceFlags& i2cFlags);
+    
+    private:
+
+    int showI2C(i2cDeviceFlags& i2cFlags, char addr);
+    int dispI2C(i2cDeviceFlags& i2cFlags);
+    
+    protected:
+    
+    DevI2C _i2c;
+
+};
+
+#endif