@@ -0,0 +1,2994 @@
+/**%0A * Licensed to the Rhiot under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The licenses this file to You under the Apache License, Version 2.0%0A * (the %22License%22); you may not use this file except in compliance with%0A * the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage io.rhiot.component.deviceio.i2c.util;%0A%0Aimport java.io.IOException;%0A%0Aimport jdk.dio.DeviceManager;%0Aimport jdk.dio.DeviceNotFoundException;%0Aimport jdk.dio.i2cbus.I2CDevice;%0Aimport jdk.dio.i2cbus.I2CDeviceConfig;%0A%0Apublic class I2CDetect %7B%0A%0A    enum State %7B%0A        FOUND, NOTFOUND, ERROR, INVALIDRANGE;%0A    %7D%0A%0A    public static final int I2C_DIO_SERIAL_CLOCK = 3400000;%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        int busId = 1;%0A%0A        if (args.length %3E 0) %7B%0A            busId = Integer.parseInt(args%5Bargs.length - 1%5D);%0A        %7D%0A%0A        System.out.print(%22   %22);%0A        for (int i = 0; i %3C= 0xf; i++) %7B%0A            System.out.printf(%22  %25x%22, i);%0A        %7D%0A        System.out.println(%22%22);%0A%0A        for (int j = 0; j %3C 0x80; j = j + 0x10) %7B%0A            System.out.printf(%22%2502x:%22, j);%0A            for (int i = 0; i %3C= 0xf; i++) %7B%0A%0A                switch (foundDevice(busId, i + j)) %7B%0A                case FOUND:%0A                    System.out.printf(%22 %2502x%22, j + i);%0A                    break;%0A                case NOTFOUND:%0A                    System.out.printf(%22 --%22, j + i);%0A                    break;%0A                case ERROR:%0A                    System.out.printf(%22 UU%22, j + i);%0A                    break;%0A                case INVALIDRANGE:%0A                    System.out.printf(%22   %22, j + i);%0A                    break;%0A                %7D%0A%0A            %7D%0A            System.out.println(%22%22);%0A        %7D%0A    %7D%0A%0A    public static State foundDevice(int busId, int deviceAddr) %7B%0A        I2CDevice device = null;%0A        if (deviceAddr %3C 0x03 %7C%7C deviceAddr %3E 0x77) %7B%0A            return State.INVALIDRANGE;%0A        %7D%0A        try %7B%0A            device = DeviceManager.open(new I2CDeviceConfig(busId, deviceAddr, I2CDeviceConfig.ADDR_SIZE_7, -1),%0A                    DeviceManager.EXCLUSIVE);%0A        %7D catch (DeviceNotFoundException e) %7B%0A            return State.NOTFOUND;%0A        %7D catch (IOException e) %7B%0A            return State.ERROR;%0A        %7D%0A%0A        try %7B%0A%0A            // Force read%0A            if (device.isOpen() && device.read() == 0) %7B%0A%0A            %7D%0A            return State.FOUND;%0A        %7D catch (IllegalArgumentException %7C IOException e) %7B%0A            return State.NOTFOUND;%0A        %7D%0A    %7D%0A%7D%0A

add i2cdetect Java impl