/* Current unit measurement in uA for a 1 milli-ohm sense resistor */ #define DS2781_CURRENT_UNITS 1563 /* Charge unit measurement in uAh for a 1 milli-ohm sense resistor */ #define DS2781_CHARGE_UNITS 6250 /* Number of bytes in user EEPROM space */ #define DS2781_USER_EEPROM_SIZE (DS2781_EEPROM_BLOCK0_END - \
DS2781_EEPROM_BLOCK0_START + 1) /* Number of bytes in parameter EEPROM space */ #define DS2781_PARAM_EEPROM_SIZE (DS2781_EEPROM_BLOCK1_END - \
DS2781_EEPROM_BLOCK1_START + 1)
/* Get RSGAIN value from 0 to 1.999 in steps of 0.001 */ staticint ds2781_get_rsgain_register(struct ds2781_device_info *dev_info,
u16 *rsgain)
{ return ds2781_read16(dev_info, rsgain, DS2781_RSGAIN_MSB);
}
/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */ staticint ds2781_set_rsgain_register(struct ds2781_device_info *dev_info,
u16 rsgain)
{ int ret;
u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
ret = ds2781_write(dev_info, raw,
DS2781_RSGAIN_MSB, sizeof(raw)); if (ret < 0) return ret;
staticint ds2781_get_voltage(struct ds2781_device_info *dev_info, int *voltage_uV)
{ int ret; char val[2]; int voltage_raw;
ret = w1_ds2781_read(dev_info, val, DS2781_VOLT_MSB, 2 * sizeof(u8)); if (ret < 0) return ret; /* * The voltage value is located in 10 bits across the voltage MSB * and LSB registers in two's complement form * Sign bit of the voltage value is in bit 7 of the voltage MSB register * Bits 9 - 3 of the voltage value are in bits 6 - 0 of the * voltage MSB register * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the * voltage LSB register
*/
voltage_raw = (val[0] << 3) |
(val[1] >> 5);
/* DS2781 reports voltage in units of 9.76mV, but the battery class
* reports in units of uV, so convert by multiplying by 9760. */
*voltage_uV = voltage_raw * 9760;
return 0;
}
staticint ds2781_get_temperature(struct ds2781_device_info *dev_info, int *temp)
{ int ret; char val[2]; int temp_raw;
ret = w1_ds2781_read(dev_info, val, DS2781_TEMP_MSB, 2 * sizeof(u8)); if (ret < 0) return ret; /* * The temperature value is located in 10 bits across the temperature * MSB and LSB registers in two's complement form * Sign bit of the temperature value is in bit 7 of the temperature * MSB register * Bits 9 - 3 of the temperature value are in bits 6 - 0 of the * temperature MSB register * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the * temperature LSB register
*/
temp_raw = ((val[0]) << 3) |
(val[1] >> 5);
*temp = temp_raw + (temp_raw / 4);
return 0;
}
staticint ds2781_get_current(struct ds2781_device_info *dev_info, enum current_types type, int *current_uA)
{ int ret, sense_res;
s16 current_raw;
u8 sense_res_raw, reg_msb;
/* * The units of measurement for current are dependent on the value of * the sense resistor.
*/
ret = ds2781_read8(dev_info, &sense_res_raw, DS2781_RSNSP); if (ret < 0) return ret;
if (sense_res_raw == 0) {
dev_err(dev_info->dev, "sense resistor value is 0\n"); return -EINVAL;
}
sense_res = 1000 / sense_res_raw;
/* * The current value is located in 16 bits across the current MSB * and LSB registers in two's complement form * Sign bit of the current value is in bit 7 of the current MSB register * Bits 14 - 8 of the current value are in bits 6 - 0 of the current * MSB register * Bits 7 - 0 of the current value are in bits 7 - 0 of the current * LSB register
*/
ret = ds2781_read16(dev_info, ¤t_raw, reg_msb); if (ret < 0) return ret;
staticint ds2781_get_accumulated_current(struct ds2781_device_info *dev_info, int *accumulated_current)
{ int ret, sense_res;
s16 current_raw;
u8 sense_res_raw;
/* * The units of measurement for accumulated current are dependent on * the value of the sense resistor.
*/
ret = ds2781_read8(dev_info, &sense_res_raw, DS2781_RSNSP); if (ret < 0) return ret;
if (sense_res_raw == 0) {
dev_err(dev_info->dev, "sense resistor value is 0\n"); return -EINVAL;
}
sense_res = 1000 / sense_res_raw;
/* * The ACR value is located in 16 bits across the ACR MSB and * LSB registers * Bits 15 - 8 of the ACR value are in bits 7 - 0 of the ACR * MSB register * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR * LSB register
*/
ret = ds2781_read16(dev_info, ¤t_raw, DS2781_ACR_MSB); if (ret < 0) return ret;
staticint ds2781_get_charge_now(struct ds2781_device_info *dev_info, int *charge_now)
{ int ret;
u16 charge_raw;
/* * The RAAC value is located in 16 bits across the RAAC MSB and * LSB registers * Bits 15 - 8 of the RAAC value are in bits 7 - 0 of the RAAC * MSB register * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC * LSB register
*/
ret = ds2781_read16(dev_info, &charge_raw, DS2781_RAAC_MSB); if (ret < 0) return ret;
ret = kstrtou16(buf, 0, &new_setting); if (ret < 0) return ret;
/* Gain can only be from 0 to 1.999 in steps of .001 */ if (new_setting > 1999) {
dev_err(dev_info->dev, "Invalid rsgain setting (0 - 1999)\n"); return -EINVAL;
}
ret = ds2781_set_rsgain_register(dev_info, new_setting); if (ret < 0) return ret;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.