Exemplo n.º 1
0
void help(void)
{
	fprintf(stderr, "Syntax: i2cset [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS "
	        "VALUE [MODE] [MASK]\n"
	        "        i2cset -V\n"
	        "  MODE is 'b[yte]' or 'w[ord]' (default b)\n"
	        "  Append 'p' to MODE for PEC checking\n"
	        "  I2CBUS is an integer\n");
	print_i2c_busses(0);
	exit(1);
}
Exemplo n.º 2
0
Arquivo: i2cget.c Projeto: muojie/my_c
static void help(void)
{
	fprintf(stderr, "Syntax: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS "
	        "[DATA-ADDRESS [MODE]]\n"
	        "        i2cget -V\n"
	        "  MODE can be: 'b' (read byte data, default)\n"
	        "               'w' (read word data)\n"
	        "               'c' (write byte/read byte)\n"
		"  If DATA-ADDRESS is omitted, a single read byte command is "
		"issued\n"
	        "  Append 'p' to MODE for PEC checking\n"
	        "  I2CBUS is an integer\n");
	print_i2c_busses(0);
	exit(1);
}
Exemplo n.º 3
0
void help(void)
{
	fprintf(stderr,
	        "Syntax: i2cdetect [-y] [-a] [-q|-r] I2CBUS [FIRST LAST]\n"
	        "        i2cdetect -l\n"
	        "        i2cdetect -V\n"
	        "  I2CBUS is an integer\n"
	        "  With -a, probe all addresses (NOT RECOMMENDED)\n"
	        "  With -q, uses only quick write commands for probing (NOT "
	        "RECOMMENDED)\n"
	        "  With -r, uses only read byte commands for probing (NOT "
	        "RECOMMENDED)\n"
	        "  If provided, FIRST and LAST limit the probing range.\n"
	        "  With -l, lists installed busses only\n");
	print_i2c_busses(0);
}
Exemplo n.º 4
0
static void help(void)
{
	fprintf(stderr, "Syntax: i2cdump [-f] [-y] I2CBUS ADDRESS [MODE] "
	        "[BANK [BANKREG]]\n"
	        "        i2cdump -V\n"
	        "  MODE is one of:\n"
		"    b (byte, default)\n"
		"    w (word)\n"
		"    W (word on even register addresses)\n"
		"    s (SMBus block)\n"
		"    i (I2C block)\n"
	        "    c (consecutive byte)\n"
	        "    Append 'p' to 'b', 'w', 's' or 'c' for PEC checking\n"
	        "  I2CBUS is an integer\n"
	        "  ADDRESS is an integer 0x00 - 0x7f\n"
	        "  BANK and BANKREG are for byte and word accesses (default "
	        "bank 0, reg 0x4e)\n"
	        "  BANK is the command for smbusblock accesses (default 0)\n");
	print_i2c_busses(0);
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
	char *end;
	int i2cbus, file, res;
	char filename[20];
	long funcs;
	int mode = MODE_AUTO;
	int first = 0x03, last = 0x77;
	int flags = 0;
	int yes = 0, version = 0, list = 0;

	/* handle (optional) flags first */
	while (1+flags < argc && argv[1+flags][0] == '-') {
		switch (argv[1+flags][1]) {
		case 'V': version = 1; break;
		case 'y': yes = 1; break;
		case 'l': list = 1; break;
		case 'r': 
			if (mode == MODE_QUICK) {
				fprintf(stderr, "Error: Different modes "
				        "specified!\n");
				exit(1);
			}
			mode = MODE_READ;
			break;
		case 'q':
			if (mode == MODE_READ) {
				fprintf(stderr, "Error: Different modes "
				        "specified!\n");
				exit(1);
			}
			mode = MODE_QUICK;
			break;
		case 'a':
			first = 0x00;
			last = 0x7F;
			break;
		default:
			fprintf(stderr, "Warning: Unsupported flag "
				"\"-%c\"!\n", argv[1+flags][1]);
			help();
			exit(1);
		}
		flags++;
	}

	if (version) {
		fprintf(stderr, "i2cdetect version %s\n", LM_VERSION);
		exit(0);
	}

	if (list) {
		print_i2c_busses(1);
		exit(0);
	}

	if (argc < flags + 2) {
		fprintf(stderr, "Error: No i2c-bus specified!\n");
		help();
		exit(1);
	}
	i2cbus = strtol(argv[flags+1], &end, 0);
	if (*end) {
		fprintf(stderr, "Error: I2CBUS argument not a number!\n");
		help();
		exit(1);
	}
	if ((i2cbus < 0) || (i2cbus > 0xff)) {
		fprintf(stderr, "Error: I2CBUS argument out of range "
		        "(0-255)!\n");
		help();
		exit(1);
	}

	/* read address range if present */
	if (argc == flags + 4) {
		int tmp;

		tmp = strtol(argv[flags+2], &end, 0);
		if (*end) {
			fprintf(stderr, "Error: FIRST argment not a "
			        "number!\n");
			help();
			exit(1);
		}
		if (tmp < first || tmp > last) {
			fprintf(stderr, "Error: FIRST argument out of range "
			        "(0x%02x-0x%02x)!\n", first, last);
			help();
			exit(1);
		}
		first = tmp;

		tmp = strtol(argv[flags+3], &end, 0);
		if (*end) {
			fprintf(stderr, "Error: LAST argment not a "
			        "number!\n");
			help();
			exit(1);
		}
		if (tmp < first || tmp > last) {
			fprintf(stderr, "Error: LAST argument out of range "
			        "(0x%02x-0x%02x)!\n", first, last);
			help();
			exit(1);
		}
		last = tmp;
	} else if (argc != flags + 2) {
		help();
		exit(1);
	}

	file = open_i2c_dev(i2cbus, filename, 0);
	if (file < 0) {
		exit(1);
	}

	if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
		fprintf(stderr, "Error: Could not get the adapter "
		        "functionality matrix: %s\n", strerror(errno));
		close(file);
		exit(1);
	}
	if (mode != MODE_READ && !(funcs & I2C_FUNC_SMBUS_QUICK)) {
		fprintf(stderr, "Error: Can't use SMBus Quick Write command "
		        "on this bus (ISA bus?)\n");
		close(file);
		exit(1);
	}
	if (mode != MODE_QUICK && !(funcs & I2C_FUNC_SMBUS_READ_BYTE)) {
		fprintf(stderr, "Error: Can't use SMBus Read Byte command "
		        "on this bus (ISA bus?)\n");
		close(file);
		exit(1);
	}

	if (!yes) {
		char s[2];

		fprintf(stderr, "WARNING! This program can confuse your I2C "
		        "bus, cause data loss and worse!\n");

		fprintf(stderr, "I will probe file %s%s.\n", filename,
		        mode==MODE_QUICK?" using quick write commands":
		        mode==MODE_READ?" using read byte commands":"");
		fprintf(stderr, "I will probe address range 0x%02x-0x%02x.\n",
		        first, last);

		fprintf(stderr, "Continue? [Y/n] ");
		fflush(stderr);
		fgets(s, 2, stdin);
		if (s[0] != '\n' && s[0] != 'y' && s[0] != 'Y') {
			fprintf(stderr, "Aborting on user request.\n");
			exit(0);
		}
	}

	res = scan_i2c_bus(file, mode, first, last);

	close(file);

	exit(res?1:0);
}