56 #include "rnr/rnrconfig.h" 82 .synopsis =
"I2C Bus Scan",
85 "The %P command scans the specified I2C Bus for all attached devices. " 86 "The I2C addresses of all found devices are written to stdout in ASCII hex " 90 "Exit status is 0 if devices are found, 1 otherwise. Exit tatus is >= 2 if " 91 "error(s) are encountered." 101 .long_opt =
"device",
103 .has_arg = required_argument,
106 .fn_cvt = OptsCvtArgStr,
107 .fn_fmt = OptsFmtStr,
108 .arg_name =
"<device>",
109 .opt_desc =
"I2C device." 115 .short_opt = OPTS_NO_SHORT,
116 .has_arg = required_argument,
118 .fn_cvt = OptsCvtArgInt,
119 .fn_fmt = OptsFmtInt,
121 .opt_desc =
"Opened I2C device file descriptor." 126 .long_opt =
"verbose",
128 .has_arg = no_argument,
131 .fn_fmt = OptsFmtBool,
132 .opt_desc =
"Set print verbosity." 149 printf(
"0x%02x ", addr);
166 printf(
"%s scanning...\n",
Argv0);
167 printf(
" scanned devices: ");
178 printf(
" number found: %d\n", n);
194 Argv0 = basename(argv[0]);
207 pI2C->
addr = (ushort_t)(-1);
225 LOGSYSERROR(
"%s: Failed to open.",
OptDevName);
239 int main(
int argc,
char *argv[])
i2c_addr_t addr
address of the currently selected attached I2C device
static OptsPgmInfo_T I2CScanPgmInfo
Program Information.
int fd
opened file descriptor of the I2C bus device
static char * OptDevName
i2c bus device option
ushort_t i2c_addr_t
I2C Device Address Type.
static int execScan(i2c_t *pI2C)
Execute I2C slave device scan.
int i2c_scan(i2c_t *i2c, int(*callback)(i2c_t *i2c, i2c_addr_t addr, void *context), void *context)
Scans the given I2C Bus to find all connected devices.
static int scanCallback(i2c_t *pI2C, i2c_addr_t addr, void *context)
Found scanned device callback.
I2C character device interface.
static const PkgInfo_T PkgInfo
static int OptVerbose
verbose option
Package version information.
int main(int argc, char *argv[])
i2cscan main()
static int OptDevFd
opened i2c bus device fd option
static void MainInit(int argc, char *argv[], i2c_t *pI2C)
Command initialization.
int i2c_open(i2c_t *i2c, const char *device)
Open the host I2C Bus device.
static char * Argv0
command name
static OptsInfo_T I2CScanOptsInfo[]
Command Line Options Information.
Low-level I2C communication level.