/* * LSB is the ADC single digital step * 1 LSB = (vref_mv / 2 ^ 16) * * LSB is used to calculate analog voltage value * from the number of ADC steps count * * Ain = (count * LSB)
*/ #define MAX11100_LSB_DIV (1 << 16)
/* * DMA (thus cache coherency maintenance) may require the * transfer buffers to live in their own cache lines.
*/
u8 buffer[3] __aligned(IIO_DMA_MINALIGN);
};
staticint max11100_read_single(struct iio_dev *indio_dev, int *val)
{ int ret; struct max11100_state *state = iio_priv(indio_dev);
ret = spi_read(state->spi, state->buffer, sizeof(state->buffer)); if (ret) {
dev_err(&indio_dev->dev, "SPI transfer failed\n"); return ret;
}
/* the first 8 bits sent out from ADC must be 0s */ if (state->buffer[0]) {
dev_err(&indio_dev->dev, "Invalid value: buffer[0] != 0\n"); return -EINVAL;
}
*val = get_unaligned_be16(&state->buffer[1]);
return 0;
}
staticint max11100_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long info)
{ int ret, vref_uv; struct max11100_state *state = iio_priv(indio_dev);
switch (info) { case IIO_CHAN_INFO_RAW:
ret = max11100_read_single(indio_dev, val); if (ret) return ret;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
vref_uv = regulator_get_voltage(state->vref_reg); if (vref_uv < 0) /* dummy regulator "get_voltage" returns -EINVAL */ return -EINVAL;
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.