ret = spi_sync_transfer(st->spi, t, ARRAY_SIZE(t));
if (ret < 0) return ret;
return be16_to_cpu(st->d16);
}
staticint ad7292_vin_range_multiplier(struct ad7292_state *st, int channel)
{ int samp_mode, range0, range1, factor = 1;
/* * Every AD7292 ADC channel may have its input range adjusted according * to the settings at the ADC sampling mode and VIN range subregisters. * For a given channel, the minimum input range is equal to Vref, and it * may be increased by a multiplier factor of 2 or 4 according to the * following rule: * If channel is being sampled with respect to AGND: * factor = 4 if VIN range0 and VIN range1 equal 0 * factor = 2 if only one of VIN ranges equal 1 * factor = 1 if both VIN range0 and VIN range1 equal 1 * If channel is being sampled with respect to AVDD: * factor = 4 if VIN range0 and VIN range1 equal 0 * Behavior is undefined if any of VIN range doesn't equal 0
*/
if (AD7292_CH_SAMP_MODE(samp_mode, channel)) { /* Sampling with respect to AGND */ if (!AD7292_CH_VIN_RANGE(range0, channel))
factor *= 2;
if (!AD7292_CH_VIN_RANGE(range1, channel))
factor *= 2;
} else { /* Sampling with respect to AVDD */ if (AD7292_CH_VIN_RANGE(range0, channel) ||
AD7292_CH_VIN_RANGE(range1, channel)) return -EPERM;
factor = 4;
}
return factor;
}
staticint ad7292_read_raw(struct iio_dev *indio_dev, conststruct iio_chan_spec *chan, int *val, int *val2, long info)
{ struct ad7292_state *st = iio_priv(indio_dev); unsignedint ch_addr; int ret;
switch (info) { case IIO_CHAN_INFO_RAW:
ch_addr = AD7292_REG_ADC_CH(chan->channel);
ret = ad7292_single_conversion(st, ch_addr); if (ret < 0) return ret;
*val = AD7292_ADC_DATA(ret);
return IIO_VAL_INT; case IIO_CHAN_INFO_SCALE: /* * To convert a raw value to standard units, the IIO defines * this formula: Scaled value = (raw + offset) * scale. * For the scale to be a correct multiplier for (raw + offset), * it must be calculated as the input range divided by the * number of possible distinct input values. Given the ADC data * is 10 bit long, it may assume 2^10 distinct values. * Hence, scale = range / 2^10. The IIO_VAL_FRACTIONAL_LOG2 * return type indicates to the IIO API to divide *val by 2 to * the power of *val2 when returning from read_raw.
*/
ret = ad7292_vin_range_multiplier(st, chan->channel); 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.