Changeset 5911
- Timestamp:
- 01/29/11 18:15:01 (2 years ago)
- Location:
- i2c-tools/trunk
- Files:
-
- 3 modified
-
CHANGES (modified) (1 diff)
-
tools/i2cset.8 (modified) (2 diffs)
-
tools/i2cset.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c-tools/trunk/CHANGES
r5894 r5911 4 4 SVN 5 5 i2c-dev.h: Make value arrays const for block write functions 6 i2cset: Add support for SMBus and I2C block writes 6 7 7 8 3.0.3 (2010-12-12) -
i2c-tools/trunk/tools/i2cset.8
r5771 r5911 13 13 .I data-address 14 14 .RI [ value ] 15 .RI ... 15 16 .RI [ mode ] 16 17 .br … … 63 64 .PP 64 65 The \fIvalue\fR parameter, if specified, is the value to write to that 65 location on the chip. If this parameter is omit ed, then a short write is66 location on the chip. If this parameter is omitted, then a short write is 66 67 issued. For most chips, it simply sets an internal pointer to the target 67 68 location, but doesn't actually write to that location. For a few chips 68 69 though, in particular simple ones with a single register, this short write 69 is an actual write. 70 is an actual write. If the mode parameter is \fBs\fP or \fBi\fP, multiple 71 values can be specified. 70 72 .PP 71 The \fImode\fR parameter, if specified, is one of the letters \fBb\fP or 72 \fBw\fP, corresponding to a write size of a single byte or a 16-bit word, 73 respectively. A \fBp\fP can also be appended to the \fImode\fR parameter to 74 enable PEC. If the \fImode\fR parameter is omitted, i2cset defaults to byte 73 The \fImode\fR parameter, if specified, is one of the letters \fBb\fP, 74 \fBw\fP, \fBs\fP, or \fBi\fP, corresponding to a write size of a single byte, 75 a 16-bit word, a SMBus block write, or an I2C block write, respectively. 76 For SMBus and I2C block writes, the write size is determined by the number 77 of \fIvalue\fR parameters. 78 Except for I2C block writes, a \fBp\fP can also be appended to the \fImode\fR 79 parameter to enable PEC. 80 If the \fImode\fR parameter is omitted, i2cset defaults to byte 75 81 mode without PEC. The \fIvalue\fR provided must be within range for the 76 specified data type (0x00-0xFF for bytes, 0x0000-0xFFFF for words). 82 specified data type (0x00-0xFF for byte and block writes, 0x0000-0xFFFF 83 for words). 77 84 Another possible mode is \fBc\fP, which doesn't write any value (so-called 78 85 short write). You usually don't have to specify this mode, as it is the -
i2c-tools/trunk/tools/i2cset.c
r5885 r5911 36 36 { 37 37 fprintf(stderr, 38 "Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] [MODE]\n"38 "Usage: i2cset [-f] [-y] [-m MASK] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE] ... [MODE]\n" 39 39 " I2CBUS is an integer or an I2C bus name\n" 40 40 " ADDRESS is an integer (0x03 - 0x77)\n" … … 43 43 " b (byte data, default)\n" 44 44 " w (word data)\n" 45 " i (I2C block data)\n" 46 " s (SMBus block data)\n" 45 47 " Append p for SMBus PEC\n"); 46 48 exit(1); … … 79 81 } 80 82 break; 83 84 case I2C_SMBUS_BLOCK_DATA: 85 if (!(funcs & I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)) { 86 fprintf(stderr, MISSING_FUNC_FMT, "SMBus block write"); 87 return -1; 88 } 89 break; 90 case I2C_SMBUS_I2C_BLOCK_DATA: 91 if (!(funcs & I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { 92 fprintf(stderr, MISSING_FUNC_FMT, "I2C block write"); 93 return -1; 94 } 95 break; 81 96 } 82 97 … … 91 106 92 107 static int confirm(const char *filename, int address, int size, int daddress, 93 int value, int vmask, int pec) 108 int value, int vmask, const unsigned char *block, int len, 109 int pec) 94 110 { 95 111 int dont = 0; … … 110 126 if (size == I2C_SMBUS_BYTE) 111 127 fprintf(stderr, "no data.\n"); 112 else 128 else if (size == I2C_SMBUS_BLOCK_DATA || 129 size == I2C_SMBUS_I2C_BLOCK_DATA) { 130 int i; 131 132 fprintf(stderr, "data"); 133 for (i = 0; i < len; i++) 134 fprintf(stderr, " 0x%02x", block[i]); 135 fprintf(stderr, ", mode %s.\n", size == I2C_SMBUS_BLOCK_DATA 136 ? "smbus block" : "i2c block"); 137 } else 113 138 fprintf(stderr, "data 0x%02x%s, mode %s.\n", value, 114 139 vmask ? " (masked)" : "", … … 137 162 int flags = 0; 138 163 int force = 0, yes = 0, version = 0, readback = 0; 164 unsigned char block[I2C_SMBUS_BLOCK_MAX]; 165 int len; 139 166 140 167 /* handle (optional) flags first */ … … 181 208 } 182 209 210 /* check for block data */ 211 len = 0; 212 if (argc > flags + 5) { 213 switch (argv[argc-1][0]) { 214 case 's': size = I2C_SMBUS_BLOCK_DATA; break; 215 case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; 216 default: 217 size = 0; 218 break; 219 } 220 if (size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) { 221 pec = argv[argc-1][1] == 'p'; 222 if (pec && size == I2C_SMBUS_I2C_BLOCK_DATA) { 223 fprintf(stderr, "Error: PEC not supported for I2C block writes!\n"); 224 help(); 225 } 226 for (len = 0; len < (int)sizeof(block) && len + flags + 5 < argc; len++) { 227 value = strtol(argv[flags + len + 4], &end, 0); 228 if (*end || value < 0 || value > 0xff) { 229 fprintf(stderr, "Error: Block data value invalid!\n"); 230 help(); 231 } 232 block[len] = value; 233 } 234 goto dofile; 235 } 236 } 237 183 238 if (argc > flags + 4) { 184 239 if (!strcmp(argv[flags+4], "c") … … 237 292 } 238 293 294 dofile: 239 295 file = open_i2c_dev(i2cbus, filename, sizeof(filename), 0); 240 296 if (file < 0 … … 244 300 245 301 if (!yes && !confirm(filename, address, size, daddress, 246 value, vmask, pec))302 value, vmask, block, len, pec)) 247 303 exit(0); 248 304 … … 300 356 res = i2c_smbus_write_word_data(file, daddress, value); 301 357 break; 358 case I2C_SMBUS_BLOCK_DATA: 359 res = i2c_smbus_write_block_data(file, daddress, len, block); 360 break; 361 case I2C_SMBUS_I2C_BLOCK_DATA: 362 res = i2c_smbus_write_i2c_block_data(file, daddress, len, block); 363 break; 302 364 default: /* I2C_SMBUS_BYTE_DATA */ 303 365 res = i2c_smbus_write_byte_data(file, daddress, value); 366 break; 304 367 } 305 368 if (res < 0) {
