Re: [RFC/PATCH] iio: light: add support for TI's opt3001 ligth sensor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Thu, Aug 07, 2014 at 11:08:24AM +0100, Jonathan Cameron wrote:
> >>> +				OPT3001_CONFIGURATION); +		return ret; +	} + +	/* wait for conversion and give it an extra 5ms */ +
> >>> usleep_range(opt->int_time + 5000, opt->int_time + 10000); + +	ret = opt3001_read(opt, OPT3001_CONFIGURATION); 
> >>> +	if (ret < 0) { +		dev_err(opt->dev, "failed to read register %02x\n", +				OPT3001_CONFIGURATION); +		return
> >>> ret; +	} + +	reg = ret; +	if (!(reg & OPT3001_CONFIGURATION_CRF)) +		return -EPIPE; + +	ret = opt3001_read(opt,
> >>> OPT3001_RESULT); +	if (ret < 0) { +		dev_err(opt->dev, "failed to read register %02x\n", +				OPT3001_RESULT); 
> >>> +		return ret; +	} + +	exponent = OPT3001_REG_EXPONENT(ret); +	mantissa = OPT3001_REG_MANTISSA(ret); + +
> >>> opt3001_to_iio_ret(opt, exponent, mantissa, val, val2); + +	return IIO_VAL_INT_PLUS_MICRO; +} + +static int
> >>> opt3001_get_scale(struct opt3001 *opt, int *val, int *val2) +{ +	int ret; +	u8 exponent; +
> >> 
> >> I guess OPT3001_RESULT is only valid AFTER performing opt3001_get_lux()
> > 
> > right. I'm only interested in the exponent part. It'll latch the exponent from last conversion, 0 being default.
> Given you unwind the scale anyway in your read raw, I'd not bother
> having a scale interface at all (assuming I'm right in thinking your
> read raw is returning the value in lux?)  Also as you are in lux, it
> should be the processed form not the raw one to indicate the scale
> does not need to be applied to the value to convert to lux.

alright, I'll switch to processed and remove scale.

> For a light sensor, the conversion here is actually fairly straight
> forward. Almost all of them have to use the processed interface
> as they are horribly non linear.

:)

> > 
> >>> + +	if (opt->mode == OPT3001_CONFIGURATION_M_CONTINUOUS) +		return -EBUSY; + +	if (chan->type != IIO_LIGHT) +
> >>> return -EINVAL; + +	mutex_lock(&opt->lock); + +	switch (mask) {
> >> 
> >> is there no way to control the scale?
> > 
> > yeah, but the HW does auto-scaling which works pretty well. Why would you want to control the scale manually ?
> On a slow device like this you probably wouldn't but for quicker devices
> the overhead of converting into a standard form in kernel might be
> excessive.

hehe, even when you _do_ set the scale, you still have the top 4 bits as
exponent, the difference is that you know what they are before the
conversion is done :-)

-- 
balbi

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux