Changeset 5237
- Timestamp:
- 05/05/08 14:38:22 (4 years ago)
- Location:
- i2c-tools/trunk
- Files:
-
- 3 modified
-
CHANGES (modified) (1 diff)
-
tools/i2cset.8 (modified) (2 diffs)
-
tools/i2cset.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c-tools/trunk/CHANGES
r5209 r5237 15 15 Restrict the chip address to 0x03-0x77 16 16 Split the code into several functions for clarity 17 Add support for short writes (SMBus send byte) 17 18 18 19 3.0.1 (2008-04-04) -
i2c-tools/trunk/tools/i2cset.8
r5236 r5237 10 10 .I chip-address 11 11 .I data-address 12 .I value 13 .RI [ "mode " [ mask ]] 12 .RI [ "value " [ "mode " [ mask ]]] 14 13 .br 15 14 .B i2cset … … 39 38 scripts. 40 39 .PP 41 There are fourrequired options to i2cset. \fIi2cbus\fR indicates the number40 There are three required options to i2cset. \fIi2cbus\fR indicates the number 42 41 or name of the I2C bus to be scanned. This number should correspond to one of 43 42 the busses listed by \fIi2cdetect -l\fR. \fIchip-address\fR specifies the 44 43 address of the chip on that bus, and is an integer between 0x03 and 0x77. 45 44 \fIdata-address\fR specifies the address on that chip to write to, and is an 46 integer between 0x00 and 0xFF. \fIvalue\fR is the value to write to that 47 location on the chip. 45 integer between 0x00 and 0xFF. 46 .PP 47 The \fIvalue\fR parameter, if specified, is the value to write to that 48 location on the chip. If this parameter is omited, then a short write is 49 issued. For most chips, it simply sets an internal pointer to the target 50 location, but doesn't actually write to that location. For a few chips 51 though, in particular simple ones with a single register, this short write 52 is an actual write. 48 53 .PP 49 54 The \fImode\fR parameter, if specified, is one of the letters \fBb\fP or -
i2c-tools/trunk/tools/i2cset.c
r5236 r5237 36 36 { 37 37 fprintf(stderr, 38 "Usage: i2cset [-f] [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS VALUE [MODE [MASK]]\n"38 "Usage: i2cset [-f] [-y] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE [MODE [MASK]]]\n" 39 39 " I2CBUS is an integer or an I2C bus name\n" 40 40 " ADDRESS is an integer (0x03 - 0x77)\n" … … 58 58 59 59 switch (size) { 60 case I2C_SMBUS_BYTE: 61 if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) { 62 fprintf(stderr, "Error: Adapter for i2c bus %d does " 63 "not have byte send capability\n", i2cbus); 64 return -1; 65 } 66 break; 67 60 68 case I2C_SMBUS_BYTE_DATA: 61 69 if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { … … 101 109 102 110 fprintf(stderr, "I will write to device file %s, chip address " 103 "0x%02x, data address\n0x%02x, data 0x%02x%s, mode " 104 "%s.\n", filename, address, daddress, value, 105 vmask ? " (masked)" : "", 106 size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 111 "0x%02x, data address\n0x%02x, ", filename, address, daddress); 112 if (size == I2C_SMBUS_BYTE) 113 fprintf(stderr, "no data.\n"); 114 else 115 fprintf(stderr, "data 0x%02x%s, mode %s.\n", value, 116 vmask ? " (masked)" : "", 117 size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); 107 118 if (pec) 108 119 fprintf(stderr, "PEC checking enabled.\n"); … … 148 159 } 149 160 150 if (argc < flags + 5)161 if (argc < flags + 4) 151 162 help(); 152 163 … … 165 176 } 166 177 167 value = strtol(argv[flags+4], &end, 0); 168 if (*end) { 169 fprintf(stderr, "Error: Data value invalid!\n"); 170 help(); 178 if (argc > flags + 4) { 179 size = I2C_SMBUS_BYTE_DATA; 180 value = strtol(argv[flags+4], &end, 0); 181 if (*end || value < 0) { 182 fprintf(stderr, "Error: Data value invalid!\n"); 183 help(); 184 } 185 } else { 186 size = I2C_SMBUS_BYTE; 187 value = -1; 171 188 } 172 189 … … 180 197 } 181 198 pec = argv[flags+5][1] == 'p'; 182 } else {183 size = I2C_SMBUS_BYTE_DATA;184 199 } 185 200 … … 192 207 } 193 208 194 if (value < 0 195 || (size == I2C_SMBUS_BYTE_DATA && value > 0xff) 209 if ((size == I2C_SMBUS_BYTE_DATA && value > 0xff) 196 210 || (size == I2C_SMBUS_WORD_DATA && value > 0xffff)) { 197 211 fprintf(stderr, "Error: Data value out of range!\n"); … … 250 264 } 251 265 252 if (size == I2C_SMBUS_WORD_DATA) { 266 switch (size) { 267 case I2C_SMBUS_BYTE: 268 res = i2c_smbus_write_byte(file, daddress); 269 break; 270 case I2C_SMBUS_WORD_DATA: 253 271 res = i2c_smbus_write_word_data(file, daddress, value); 254 } else { 272 break; 273 default: /* I2C_SMBUS_BYTE_DATA */ 255 274 res = i2c_smbus_write_byte_data(file, daddress, value); 256 275 } … … 270 289 } 271 290 272 if (size == I2C_SMBUS_WORD_DATA) { 291 switch (size) { 292 case I2C_SMBUS_BYTE: 293 /* No readback */ 294 break; 295 case I2C_SMBUS_WORD_DATA: 273 296 res = i2c_smbus_read_word_data(file, daddress); 274 } else { 297 break; 298 default: /* I2C_SMBUS_BYTE_DATA */ 275 299 res = i2c_smbus_read_byte_data(file, daddress); 276 300 } 277 301 close(file); 302 303 if (size == I2C_SMBUS_BYTE) /* We're done */ 304 exit(0); 278 305 279 306 if (res < 0) {
