#!/bin/sh # This script is used to test i2c interface for bsc9131rdb I2C_DETECT=`which i2cdetect` if [ "x$I2C_DETECT" != "x" ]; then echo "PASS: i2cdetect found" else echo "FAIL: i2cdetect not found" exit 1 fi I2C_SET=`which i2cset` if [ "x$I2C_SET" != "x" ]; then echo "PASS: i2cset found" else echo "FAIL: i2cset not found" exit 1 fi I2C_GET=`which i2cget` if [ "x$I2C_GET" != "x" ]; then echo "PASS: i2cget found" else echo "FAIL: i2cget not found" exit 1 fi if I2C_ADAPTERS=`$I2C_DETECT -l |wc -l`; then echo "PASS: $I2C_ADAPTERS i2c adapters found" else echo "FAIL: no i2c adapters found" exit 1 fi adapters=0 while [ $adapters -lt $I2C_ADAPTERS ] do $I2C_DETECT -y $adapters if [ $? -ne 0 ]; then echo "FAIL: detect i2c adapter $adapters fail" else echo "PASS: detect i2c adapter $adapters success" fi adapters=`expr $adapters + 1` sleep 1 done # Area of bus:i2c-0 addr:0x52 is free to read and write $I2C_SET -y 0 0x52 0 0x55 if [ $? -eq 0 ]; then echo "PASS: i2c_set -y 0 0x52 0 0x55 success" else echo "FAIL: i2c_set -y 0 0x52 0 0x55 fail" fi num=`$I2C_GET -y 0 0x52 0 | grep -c '0x55'` if [ $num -eq 1 ]; then echo "PASS: i2c_get -y 0 0x52 0 success" else echo "FAIL: i2c_get -y 0 0x52 0 fail" fi $I2C_SET -y 0 0x52 0 0xaa if [ $? -eq 0 ]; then echo "PASS: i2c_set -y 0 0x52 0 0xaa success" else echo "FAIL: i2c_set -y 0 0x52 0 0xaa fail" fi num=`$I2C_GET -y 0 0x52 0 | grep -c '0xaa'` if [ $num -eq 1 ]; then echo "PASS: i2c_get -y 0 0x52 0 success" else echo "FAIL: i2c_get -y 0 0x52 0 fail" fi