![background image](http://html1.mh-extra.com/html/ibase-technology/ib113/ib113_user-manual_3233460044.webp)
Copyright © 2013 IBASE Technology Inc. All Rights Reserved.
43
IBASE Technology Inc.
}
} else {
size = I2C_SMBUS_BYTE;
daddress = -1;
}
if (argc > flags + 4) {
switch (argv[flags+4][0]) {
case 'b': size = I2C_SMBUS_BYTE_DATA; break;
case 'w': size = I2C_SMBUS_WORD_DATA; break;
case 'c': size = I2C_SMBUS_BYTE; break;
default:
fprintf(stderr, "Error: Invalid mode!\n");
help();
}
pec = argv[flags+4][1] == 'p';
}
file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0);
if (file < 0
|| check_funcs(file, size, daddress, pec)
|| set_slave_addr(file, address, force))
exit(1);
if (!yes && !confirm(filename, address, size, daddress, pec))
exit(0);
if (pec && ioctl(file, I2C_PEC, 1) < 0) {
fprintf(stderr, "Error: Could not set PEC: %s\n",
strerror(errno));
close(file);
exit(1);
}
switch (size) {
case I2C_SMBUS_BYTE:
if (daddress >= 0) {
res = i2c_smbus_write_byte(file, daddress);
if (res < 0)
fprintf(stderr, "Warning - write failed\n");
}
res = i2c_smbus_read_byte(file);
break;
case I2C_SMBUS_WORD_DATA:
res = i2c_smbus_read_word_data(file, daddress);
break;
default: /* I2C_SMBUS_BYTE_DATA */
res = i2c_smbus_read_byte_data(file, daddress);
}
close(file);
if (res < 0) {
fprintf(stderr, "Error: Read failed\n");
exit(2);
}
printf("0x%0*x\n", size == I2C_SMBUS_WORD_DATA ? 4 : 2, res);
exit(0);
}
i2cset.c
/*
i2cset.c - A user-space program to write an I2C register.
Copyright (C) 2001-2003 Frodo Looijaard <[email protected]>, and
Mark D. Studebaker <[email protected]>
Copyright (C) 2004-2012 Jean Delvare <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by