; ; I2C Detective ; see http://www.ulisp.com/show?3F7R ; (defvar *devices* '(("6-Axis IMU" ("LSM6DSOX" #x6A #x6B) ("LSM6DS33" #x6A #x6B) ("ICM330DHC" #x6A #x6B)) ("9-Axis IMU" ("MPU-9250" #x68 #x69) ("LSM9DS0" (#x1D #x1E #x6A #x6B) nil) ("BNO055" #x28 #x29)) ("Accelerometer" ("BMA180" #x77 #x77) ("LIS3DH" #x18 #x19 (whoami #x0F #x33)) ("MMA845x" #x1C #x1D) ("MMA7455L" #x1C #x1D) ("ADXL345" (#x1D #x53) nil) ("MSA301" #x26 #x26)) ("Accelerometer/Gyroscope" ("MPU-60X0" #x68 #x69) ("ICM-20649" #x68 #x69)) ("Accelerometer/Magnetometer" ("LSM303AGR" #x19 #x1E lsm303agr) ("LSM303D" #x1D #x1E) ("FXOS8700" #x1C #x1F)) ("Amplifier" ("TPA2016" #x58 #x58)) ("Analogue to Digital Converter" ("ADS1115" #x48 #x4B)) ("Capacitive Touch Sensor" ("MPR121" #x5A #x5D) ("CAP1188" #x28 #x2D) ("FT6x06" #x38 #x38)) ("Clock Generator" ("Si5351A" #x60 #x61)) ("CO2 Sensor" ("SCD-30" #x61 #x61)) ("Colour Sensor" ("TCS34725" #x29 #x29) ("ISL29125" #x44 #x44)) ("Current/Voltage Sensor" ("INA219" #x40 #x4F)) ("Current/Power Sensor" ("INA260" #x40 #x4F)) ("Digital to Analogue Converter" ("MCP4725A3" #x66 #x67) ("MCP4725A2" #x64 #x65) ("MCP4725A1" #x62 #x63) ("MCP4728" #x60 #x60)) ("Digital Potentiometer" ("DS1841" #x28 #x2B) ("DS3502" #x28 #x2B)) ("Fan Controller" ("EMC2101" #x4C #x4C)) ("Ferroelectric RAM" ("MB85RC" #x50 #x57)) ("FM Transmitter" ("Si4713" (#x11 #x63) nil)) ("Gas Sensor" ("SGP30" #x58 #x58) ("SGP40" #x59 #x59)) ("GPIO Expander" ("MCP23008" #x20 #x27) ("MCP23017" #x20 #x27)) ("Gyroscope" ("L3GD20H" #x6A #x6B) ("ITG3200" #x68 #x69) ("FXAS21001" #x20 #x21)) ("Humidity/Temperature Sensor" ("DHT12" #x5C #x5C) ("AM2320" #x5C #x5C) ("AM2315" #x5C #x5C) ("SHT31" #x44 #x45) ("Si7021" #x40 #x40) ("HTU21D-F" #x40 #x40) ("HDC1008" #x40 #x43)) ("IR Temperature Sensor" ("MLX9061x" #x5A #x5A) ("TMP006" #x40 #x47) ("TMP007" #x40 #x47)) ("IR Thermal Camera" ("MLX90640" #x33 #x33) ("AMG8831" #x68 #x69) ("AMG8833" #x68 #x69)) ("IC/Colour/Proximity Sensor" ("APDS-9660" #x39 #x39)) ("LED Charlieplex Driver" ("IS31FL3731" #x74 #x77)) ("LED Matrix Driver" ("HT16K33" #x70 #x77)) ("Light Sensor" ("Si1145" #x60 #x60) ("VEML7700" #x10 #x10) ("TSL2591" #x28 #x29) ("TSL2561" (#x29 #x39 #x49) nil) ("BH1750" (#x23 #x5C) nil)) ("Magnetometer" ("TLV493D" #x5E #x5E) ("MAG3110" #x0E #x0E) ("LIS3MDL" (#x1C #x1E) nil) ("HMC5883" #x1E #x1E) ("LIS2MDL" #x1E #x1E)) ("Motor Driver" ("DRV2605" #x5A #x5A)) ("Multiplexer" ("TCA9548" #x70 #x77)) ("NFC/RFID Reader" ("PN532" #x48 #x48)) ("Nunchuck Controller" ("Nintendo" #x52 #x52)) ("OLED Display" ("SSD1305" #x3C #x3D) ("SH1106" #x3C #x3D) ("SSD1306" #x3C #x3D)) ("Pressure Sensor" ("MS5607" #x76 #x77) ("MS5611" #x76 #x77) ("MPL115A2" #x60 #x60) ("MPL3115A2" #x60 #x60) ("LPS35HW" #x5C #x5D) ("LPS33HW" #x5C #x5D) ("LPS25" #x5C #x5D)) ("Proximity Sensor" ("VCNL40x0" #x13 #x13)) ("Proximity/Light Sensor" ("VCNL4040" #x60 #x60)) ("Pulse & Oximetry Sensor" ("MAX3010x" #x57 #x57)) ("PWM Driver" ("PCA9685" (#x40 #x7F) nil)) ("Radio Receiver" ("TEA5767" #x60 #x60)) ("Real-Time Clock" ("DS1307" #x68 #x68) ("DS3231" #x68 #x68) ("PCF8523" #x68 #x68)) ("Resistive Touch Controller" ("STMPE610" (#x41 #x44) nil) ("STMPE811" (#x41 #x44) nil)) ("Temperature Sensor" ("TMP117" #x48 #x49) ("TMP102" #x48 #x4B) ("MCP9808" #x18 #x1F (whoami #x07 #x04))) ("Temperature/Pressure Sensor" ("BMP085" #x77 #x77) ("BMP280" #x76 #x77 (whoami #xD0 #x58)) ("BMP180" #x77 #x77 (whoami #xD0 #x55))) ("Temperature/Pressure/Humidity Sensor" ("BME280" #x76 #x77 (whoami #xD0 #x60))) ("Temperature/Pressure/Humidity/Gas Sensor" ("BME680" #x76 #x77 (whoami #xD0 #x61))) ("Time of Flight Sensor" ("VL53L0x" #x29 #x29) ("VL6180X" #x29 #x29)) ("UV Light Sensor" ("LTR390" #x53 #x53) ("VEML6075" #x10 #x10) ("VEML6070" #x38 #x39)) ("VOC Sensor" ("CCS811" #x5A #x5B)) ("Water Sensor" ("Chirp!" #x20 #x20)))) (defun lookup (p) (let (result) (dolist (category *devices*) (let ((name (first category)) (options (cdr category))) (when (dolist (device options nil) (let* ((id (first device)) (from (second device)) (to (third device)) (test (nth 3 device)) (ok (if (listp from) (member p from) (<= from p to)))) (cond ((not ok) nil) ((and test (funcall (eval test) p)) (setq result (list p name id)) (return t)) (test nil) (t (push id result) (push name result) (push p result))))) (return)))) (when result (format t "~{#x~x: ~a - ~a~%~}" result)))) (defun whoami (reg value) (lambda (p) (with-i2c (str p) (when str (write-byte reg str) (restart-i2c str 1) (= (read-byte str) value))))) (defun lsm303agr (p) (and (funcall (whoami #x0F #x33) #x19) (funcall (whoami #x4F #x40) #x1E))) (defun scan () (dotimes (p 127) (with-i2c (str p) (when str (lookup p)))))