56 #include "rnr/rnrconfig.h" 85 .usage_args =
"--address <addr>",
87 .synopsis =
"Check if an I2C device exists on an I2C Bus.",
90 "The %P command queries the specified I2C Bus for a device " 91 "with the specified address.",
94 "Exit status is 0 if device with address is found, 1 otherwise. " 95 "Exit status is >= 2 if error(s) are encountered." 105 .long_opt =
"address",
107 .has_arg = required_argument,
109 .fn_cvt = OptsCvtArgInt,
110 .fn_fmt = OptsFmtInt,
111 .arg_name =
"<addr>",
112 .opt_desc =
"I2C device address. REQUIRED" 117 .long_opt =
"device",
119 .has_arg = required_argument,
122 .fn_cvt = OptsCvtArgStr,
123 .fn_fmt = OptsFmtStr,
124 .arg_name =
"<device>",
125 .opt_desc =
"I2C device." 131 .short_opt = OPTS_NO_SHORT,
132 .has_arg = required_argument,
134 .fn_cvt = OptsCvtArgInt,
135 .fn_fmt = OptsFmtInt,
137 .opt_desc =
"Opened I2C device file descriptor." 142 .long_opt =
"verbose",
144 .has_arg = no_argument,
147 .fn_fmt = OptsFmtBool,
148 .opt_desc =
"Set print verbosity." 173 printf(
"%s checking 0x%02x...\n",
Argv0, (byte_t)addr);
180 printf(
"device %s\n", (rc?
"found":
"not found"));
200 Argv0 = basename(argv[0]);
212 fprintf(stderr,
"%s: Address option required\n",
Argv0);
217 fprintf(stderr,
"%s: Address out of range: 0x%x\n",
Argv0,
OptI2CAddr);
225 pI2C->
addr = (ushort_t)(-1);
243 LOGSYSERROR(
"%s: Failed to open.",
OptDevName);
257 int main(
int argc,
char *argv[])
266 return rc > 0? 0: (rc == 0? 1: 2);
i2c_addr_t addr
address of the currently selected attached I2C device
int fd
opened file descriptor of the I2C bus device
ushort_t i2c_addr_t
I2C Device Address Type.
static int OptDevFd
opened i2c bus device fd option
static int execCheck(i2c_t *pI2C, int addr)
Execute I2C slave device check.
#define I2C_ADDR_DEV_HIGH
last available device address
static OptsInfo_T I2CCheckOptsInfo[]
Command Line Options Information.
static int OptI2CAddr
slave device address option
I2C character device interface.
static const PkgInfo_T PkgInfo
int main(int argc, char *argv[])
i2ccheck main()
static char * OptDevName
i2c bus device option
static char * Argv0
command name
Package version information.
int i2c_open(i2c_t *i2c, const char *device)
Open the host I2C Bus device.
static void MainInit(int argc, char *argv[], i2c_t *pI2C)
Command initialization.
#define I2C_ADDR_DEV_LOW
first available device address
static int OptVerbose
verbose option
int i2c_exists(i2c_t *i2c, i2c_addr_t addr)
Test the existance of a device at the given address on the given I2C Bus.
Low-level I2C communication level.
static OptsPgmInfo_T I2CCheckPgmInfo
Program Information.