linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RFC: Sensor event related attribute naming.
@ 2010-09-21 14:58 Jonathan Cameron
  2010-09-24 10:34 ` Hemanth V
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2010-09-21 14:58 UTC (permalink / raw)
  To: LKML, linux-iio, linux-input, Dmitry Torokhov, Hemanth V,
	Manuel Stahl, Jean Delvare, Greg KH, Alan Cox, Andrew Morton,
	drivers, achew, Donggeun Kim

Hi All,

I afraid this is a fairly dense email to start the discussion.
There is a lot to cover and I wanted to start with a reasonably
thorough description for what I want to get the communities
opinions on.

The types of events this discussion is meant to cover are
those that are produced by 'smart' sensors.  These sensors
have on device implementations of various simple algorithms
to derive conditions such as free fall.

To provide a quick idea of the sort of sensors we are considering:
* Accelerometers
* Gyroscopes
* Generic ADCs
* Magnetometers
* Light sensors
* Proximity sensors

Now lets start to form a list of what events exist (please add
anything else you have seen with an example of a device that does it!)

threshold interrupts -  (a boundary is crossed, either by
	rising value or falling value)
	adis16350 and numerous others (IIO - IMU so most sensor types)
	tsl2563 (iio -light),
	tmd2771x (iio - light)

rate of change interrupts (a boundary in the rate of change
	is crossed either by rising above a particular value
	or falling below it)
	adis16350 (IIO) and lots of other Analog devices parts.

magnitude interrupts -
	same as threshold for unsigned measurements (hence not used
	in that case). If signed then abs(value) is compared with the
	threshold.  Common on accelerometers (often couched as either
	free fall or motion detector though these can be more complex)
	 
free fall detector - (often no parameters for this one)
	in some cases these are simple low magnitude thresholds,
	but AND across all directions.
	on all axes.
	adxl345 (input - accel)
	sca3000 (IIO - accel)
	cma3000 (input shortly - accel) - partly blocked pending this
		discussion.

Motion detector
	in some cases these are simple high magnitude thresholds,
	but OR on all directions
	adxl345 (input - accel)
	sca3000 (IIO - accel)
	cma3000 (input shortly - accel)
	kxsd9 (IIO - accel)

Some more specific types provide:
Click detection
Double click detection
Orientation change detection

A number of discussions have highlighted the advantages of
a consistent naming structure for attributes relating to such
events. To pull out one recent case of a driver being blocked
by the lack of agreement on naming conventions.

[PATCH] input: CMA3000 Accelerometer Driver http://lkml.org/lkml/2010/9/8/21

Currently there are a few related attributes in various drivers:

For example hwmon implements some 'alarms'.
To pull out those for temperature sensors
temp[1-*]_alarm
temp[1-*]_min_alarm
temp[1-*]_max_alarm
temp[1-*]_crit_alarm
temp[1-*]_fault

These clearly cover the important cases for hardware monitoring
but I don't think they generalize well to more general sensor types.

We have had naming conventions in IIO for a while but they have not
yet been terribly satisfactory. Our latest suggestion, which I'm
finally happy is general enough whilst remaining clear to be found
in  http://marc.info/?l=linux-iio&m=128394796116223&w=2

Manuel Stahl pointed out that the following summary covers what was
proposed in a clearer fashion.

<channel>_<limit>_<dir>_<attr>, where
 <channel>: name of the channel, i.e. accel_x0
 <limit>:   thresh, mag, roc
 <dir>:     rising, falling
 <attr>:    en, value, period, mean_period

<channel> tells us which device channel.  Our naming convention is an
  extension of that of hwmon.  So we have types:
  in, accel, gyro, magn, illuminance etc

  All of these can be modified to be more specific, either with a number
  or a label. So we can have accel7, accel_x, accel_x2 etc if appropriate.
  More general interrupts, such as those on any axis can be specified by
  dropping the modifier. So accel_thresh_rising_value will apply to all
  axes.	

  It's not unusual to have a device where the  threshold value is
  shared across all axes, but they an be enabled independently. Thus some
  attributes may be shared whilst others are not.  We also allow attributes
  to interact. So if a threshold is shared across x and y, but not z axes
  we would have accel_x_thresh_value and accel_y_thresh_value both reading
  the same underlying value.  The naming convention just gets too complex
  if we don't allow this. This is particularly true with devices that support
  say 2 alarms that can then be attached to any of a much larger set of
  channels. In these cases the userspace code attempt to write what it wants.
  The driver is responsible for providing the 'best' available set (so first
  in first out if there aren't enough alarms) then user space must read back
  the attributes to find out what it actually set up. We may add some
  'hint' attributes at a later date to save some complexity in userspace
  by say indicating that only 2 alarms are usable at a time.

  Other modifiers will be needed in future to cover things like sum squared
  thresholds.  Some events may have their own label (not matching a channel).
  For example, orientation detector events aren't linked to any single sensor.

<limit> describes the type of event.
  Options in IIO so far:
  * thresh - signed threshold interrupt
  * mag - theshold on abs(value)
  * roc - rate of change
  This list can be extended to include freefall, orientation etc

<dir> describes the direction of the interrupt.
  Options in IIO so far:
  *  - leaving this out means it is on both directions (or not relevant to
	the event type)
  * rising
  * falling

<attr> is used in the above summary to indicate the types of event
   related attributes we actually have. So far we have defined: 

  en - enable / disable the event.
  value - the value associated with the event. In our case whether
	this is a raw (adc counts) or processed (SI units) value
	can be established from other non event attributes. Perhaps
	we should make this explicit in the naming.
  period - a period for which the event is true before the devices
	sends an interrupt to the host.
  mean_period - a moving average is compared to the threshold and	
	this parameters sets the window width.  More complex filters
	exist (such as FIR low pass filters) but we haven't explicitly
 	set an interface for these as yet.  Filtering on these units
	is a complex mess and we simply don't have enough device
	drivers implementing them explicitly to pin down a unified
	interface for these as yet.

  This list is no where near comprehensive. It is just based on what
  we needed to cover the vast majority of our current driver set.

Naturally having come up with the IIO interface spec (with assistance
from members of that community), I'm in favour every one picking that up :)

However, we are still in staging and that gives us some leeway to get this
right. The purpose of this RFC is to get opinions from the wider community,
with the intent that we can not only get a naming convention that meets our
needs, but hopefully one of more general utility. The ideal would be to
come up with a convention that suits everyone with a similar problem.

Thanks for reading this far and sorry again for not being able to
introduce the question more succinctly.

Please add any relevant questions I have forgotten.

All opinions on this topic welcomed!

Jonathan 

p.s. As ever please cc anyone who may want to contribute - this list above
is either people who have been vocal on similar issues in the past, or
submitted drivers recently where these questions are relevant.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sensor event related attribute naming.
  2010-09-21 14:58 RFC: Sensor event related attribute naming Jonathan Cameron
@ 2010-09-24 10:34 ` Hemanth V
  2010-09-24 11:58   ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Hemanth V @ 2010-09-24 10:34 UTC (permalink / raw)
  To: Jonathan Cameron, LKML, linux-iio, linux-input, Dmitry Torokhov,
	Manuel Stahl, Jean Delvare, Greg KH, Alan Cox, Andrew Morton,
	drivers, achew, Donggeun Kim

----- Original Message ----- 
From: "Jonathan Cameron" <jic23@cam.ac.uk>
<snip>
> 
> We have had naming conventions in IIO for a while but they have not
> yet been terribly satisfactory. Our latest suggestion, which I'm
> finally happy is general enough whilst remaining clear to be found
> in  http://marc.info/?l=linux-iio&m=128394796116223&w=2
> 
> Manuel Stahl pointed out that the following summary covers what was
> proposed in a clearer fashion.
> 
> <channel>_<limit>_<dir>_<attr>, where
> <channel>: name of the channel, i.e. accel_x0
> <limit>:   thresh, mag, roc
> <dir>:     rising, falling
> <attr>:    en, value, period, mean_period
> 

Jonathan, I am trying to understand howto apply this to cma3000. I
have few parameters like below. Would you be able to suggest how
the sysfs entries should look like for the below parameters or are these
still to be defined.

grange:  2000, 8000 mg 
sampling frequency  : 40, 100, 400 Hz
Modes : Motion detect, Measurement, Free fall

Thanks
Hemanth

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sensor event related attribute naming.
  2010-09-24 10:34 ` Hemanth V
@ 2010-09-24 11:58   ` Jonathan Cameron
  2010-09-27  9:42     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2010-09-24 11:58 UTC (permalink / raw)
  To: Hemanth V
  Cc: LKML, linux-iio, linux-input, Dmitry Torokhov, Manuel Stahl,
	Jean Delvare, Greg KH, Alan Cox, Andrew Morton, drivers, achew,
	Donggeun Kim

On 09/24/10 11:34, Hemanth V wrote:
> ----- Original Message ----- From: "Jonathan Cameron" <jic23@cam.ac.uk>
> <snip>
>>
>> We have had naming conventions in IIO for a while but they have not
>> yet been terribly satisfactory. Our latest suggestion, which I'm
>> finally happy is general enough whilst remaining clear to be found
>> in  http://marc.info/?l=linux-iio&m=128394796116223&w=2
>>
>> Manuel Stahl pointed out that the following summary covers what was
>> proposed in a clearer fashion.
>>
>> <channel>_<limit>_<dir>_<attr>, where
>> <channel>: name of the channel, i.e. accel_x0
>> <limit>:   thresh, mag, roc
>> <dir>:     rising, falling
>> <attr>:    en, value, period, mean_period
>>
> 
> Jonathan, I am trying to understand howto apply this to cma3000. I
> have few parameters like below. Would you be able to suggest how
> the sysfs entries should look like for the below parameters or are these
> still to be defined.
Hi Hemanth,

> 
> grange:  2000, 8000 mg sampling frequency  : 40, 100, 400 Hz
These weren't covered by this discussion at all. However, I am happy to at
least tell you how these are handled in IIO.  Firstly instead of defining
ranges we define _scale attributes.  This decision has a lot to do with
our approach of using raw data. To process that data, userspace needs to
know how to scale it appropriately. It really doesn't directly care what the
limits are.  If there is a particular use case for these limits directly then
we could propose adding say accel_mag_max. Such a parameter would clearly
interact with the alternate setting mechanism of accel_scale and maintaining
that relationship would be a job for the driver.

Note that if the multiplication is handled in driver (and hence to userspace
looks like the device was doing it) then any sysfs based output is obtained
via accel_x_input and the associated scale would be in accel_calibgain.
accel_calibgain_available would give a space separated list of available gains.

Also note that we always stick to SI units, so accelerations are measured in
m/s^2 rather that g, so there are some factors to be taken into account.
We are against making an exception for accelerometers because that will then
make the units for a given sensor type very unpredictable.

Frequency is controlled via sampling_frequency (in Hz) with a space
separated list of available options in sampling_frequency_available

Things are a little fiddly for some parts as the available range can be
mode dependant - lower frequencies are often used for motion detection.
For example, when motion detection is enabled on the cma3000 the sampling
frequency and the measurement range change (10Hz and 8g) so this should be
reflected in any reads of these attributes.

> Modes : Motion detect, Measurement, Free fall
Based on our sca3000 driver and the cma3000 data sheet.

The device starts up in Measurement mode - this is the mode it is always
in if neither of the others are enabled.  It's up to userspace to switch to
one of the other modes.  If sysfs direct read attributes are supplied and the
current mode does not allow values to be obtained then we simply return -EBUSY.

We then have two event enable attributes.  The names of these are up for
discussion (and part of what this thread was meant to address).  Let us for
now call them:
accel_freefall_en and accel_motiondetect_en

The will have accompanying parameters

accel_motiondetect_period (MDTMR[3:0] -> in seconds, a pain to do, but it's the
			only way we will have a consistent interface, for cases
			like this with few options,
			 accel_motiondetect_period_available could provide a
			 list of options)
accel_motiondetect_value (MDTHR[6:0] -> in either raw units or processed.
			 Whether we need to make this choice explicit in
			 the naming is one of the questions I was hoping this
			 thread might answer) Perhaps
			 accel_motiondetect_value_input for processed values
			 and accel_motiondetect_value_raw for raw sensor units
			 (adc counts).

accel_freefall_period (FFTMR[3:0] -> again in seconds)
accel_freefall_value (FFTMR[3:0])

In our event code structure (not yet posted) we actually allow another option
which leads to a more logical and general description of these two detectors
which I am keen on because we do have parts that allow weird subsets and
devices other than accelerometers that actually perform very similar combined
axis boolean combinations. Basically freefall and motiondetect don't really
generalise to anything other than 3d accelerometers.

For motion detection:

accel_x|y|z_thresh_rising_en (the | characters are part of the name,
			     not indicating options for naming!)

accel_x|y|z_thresh_rising_period, accel_x|y|z_thresh_rising_value

for freefall:

accel_x&y&z_thresh_falling_en
accel_x&y&z_thresh_falling_value
accel_x&y&z_thresh_falling_period

These generalize to other forms of sensor far better than the magic 'freefall'
but do not easily allow for more sophisticated free fall detectors. From an IIO
point of view I would actually like to distinguish how these detectors are
working but fully appreciate that your average user on a mobile phone doesn't
care!

I also know of some parts that do more complex arithmetic to detect free fall
such as applying the detector on the sum squared value. I haven't as yet worked
out how to name that one! Perhaps, accel_sum^2_thresh_falling_en?  One for
another day I think.

Anyhow for your part you would need to make the attributes mutually exclusive
(I think).  Thus we only guarantee that an interrupt will remain enabled as long
as no userspace interactions occur with the attributes.  Hence if one enabled
freefall first then motion detection, userspace gets to find out they are
mutually exclusive by reading back the values when it is done setting up what it
would like.  Providing the 'mode' type option you suggested unfortunately does
not generalize. For the cma3000 for example, how do you indicate that full rate
data (more or less as if you were in measurement mode) is available when in free
fall mode, but not when in motion detection mode? (on the sca3000 to take this
futher, motion detecton mode completely disables any direct reading of the
acceleration values) Also, the mode approach breaks down the moment you have
a device that can do 2 out of n forms of detection at the same time.  This is
very common (see Analog devices adis parts which have 2 general purpose alarms
which can detect various things on one channel each where there may be 10 or
more channels).

For these special cases, I am perfectly willing to accept that simply labelling
them free fall and motion detect is fine. I may map the resulting codes in IIO
to the same as for the above alternate forms, but that doesn't matter for this
discussion.

Thanks,

Jonathan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sensor event related attribute naming.
  2010-09-24 11:58   ` Jonathan Cameron
@ 2010-09-27  9:42     ` Jonathan Cameron
  2010-09-30 10:06       ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2010-09-27  9:42 UTC (permalink / raw)
  To: Hemanth V
  Cc: LKML, linux-iio, linux-input, Dmitry Torokhov, Manuel Stahl,
	Jean Delvare, Greg KH, Alan Cox, Andrew Morton, drivers, achew,
	Donggeun Kim

On 09/24/10 12:58, Jonathan Cameron wrote:
> On 09/24/10 11:34, Hemanth V wrote:
>> ----- Original Message ----- From: "Jonathan Cameron" <jic23@cam.ac.uk>
>> <snip>
>>>
>>> We have had naming conventions in IIO for a while but they have not
>>> yet been terribly satisfactory. Our latest suggestion, which I'm
>>> finally happy is general enough whilst remaining clear to be found
>>> in  http://marc.info/?l=linux-iio&m=128394796116223&w=2
>>>
>>> Manuel Stahl pointed out that the following summary covers what was
>>> proposed in a clearer fashion.
>>>
>>> <channel>_<limit>_<dir>_<attr>, where
>>> <channel>: name of the channel, i.e. accel_x0
>>> <limit>:   thresh, mag, roc
>>> <dir>:     rising, falling
>>> <attr>:    en, value, period, mean_period
>>>
>>
>> Jonathan, I am trying to understand howto apply this to cma3000. I
>> have few parameters like below. Would you be able to suggest how
>> the sysfs entries should look like for the below parameters or are these
>> still to be defined.
> Hi Hemanth,
> 
>>
>> grange:  2000, 8000 mg sampling frequency  : 40, 100, 400 Hz
> These weren't covered by this discussion at all. However, I am happy to at
> least tell you how these are handled in IIO.  Firstly instead of defining
> ranges we define _scale attributes.  This decision has a lot to do with
> our approach of using raw data. To process that data, userspace needs to
> know how to scale it appropriately. It really doesn't directly care what the
> limits are.  If there is a particular use case for these limits directly then
> we could propose adding say accel_mag_max. Such a parameter would clearly
> interact with the alternate setting mechanism of accel_scale and maintaining
> that relationship would be a job for the driver.
> 
> Note that if the multiplication is handled in driver (and hence to userspace
> looks like the device was doing it) then any sysfs based output is obtained
> via accel_x_input and the associated scale would be in accel_calibgain.
> accel_calibgain_available would give a space separated list of available gains.
> 
> Also note that we always stick to SI units, so accelerations are measured in
> m/s^2 rather that g, so there are some factors to be taken into account.
> We are against making an exception for accelerometers because that will then
> make the units for a given sensor type very unpredictable.
> 
> Frequency is controlled via sampling_frequency (in Hz) with a space
> separated list of available options in sampling_frequency_available
> 
> Things are a little fiddly for some parts as the available range can be
> mode dependant - lower frequencies are often used for motion detection.
> For example, when motion detection is enabled on the cma3000 the sampling
> frequency and the measurement range change (10Hz and 8g) so this should be
> reflected in any reads of these attributes.
> 
>> Modes : Motion detect, Measurement, Free fall
> Based on our sca3000 driver and the cma3000 data sheet.
> 
> The device starts up in Measurement mode - this is the mode it is always
> in if neither of the others are enabled.  It's up to userspace to switch to
> one of the other modes.  If sysfs direct read attributes are supplied and the
> current mode does not allow values to be obtained then we simply return -EBUSY.
> 
> We then have two event enable attributes.  The names of these are up for
> discussion (and part of what this thread was meant to address).  Let us for
> now call them:
> accel_freefall_en and accel_motiondetect_en
> 
> The will have accompanying parameters
> 
> accel_motiondetect_period (MDTMR[3:0] -> in seconds, a pain to do, but it's the
> 			only way we will have a consistent interface, for cases
> 			like this with few options,
> 			 accel_motiondetect_period_available could provide a
> 			 list of options)
> accel_motiondetect_value (MDTHR[6:0] -> in either raw units or processed.
> 			 Whether we need to make this choice explicit in
> 			 the naming is one of the questions I was hoping this
> 			 thread might answer) Perhaps
> 			 accel_motiondetect_value_input for processed values
> 			 and accel_motiondetect_value_raw for raw sensor units
> 			 (adc counts).
> 
> accel_freefall_period (FFTMR[3:0] -> again in seconds)
> accel_freefall_value (FFTMR[3:0])
> 
> In our event code structure (not yet posted) we actually allow another option
> which leads to a more logical and general description of these two detectors
> which I am keen on because we do have parts that allow weird subsets and
> devices other than accelerometers that actually perform very similar combined
> axis boolean combinations. Basically freefall and motiondetect don't really
> generalise to anything other than 3d accelerometers.
> 
> For motion detection:
> 
> accel_x|y|z_thresh_rising_en (the | characters are part of the name,
> 			     not indicating options for naming!)
> 
> accel_x|y|z_thresh_rising_period, accel_x|y|z_thresh_rising_value
> 
> for freefall:
> 
> accel_x&y&z_thresh_falling_en
> accel_x&y&z_thresh_falling_value
> accel_x&y&z_thresh_falling_period
> 
> These generalize to other forms of sensor far better than the magic 'freefall'
> but do not easily allow for more sophisticated free fall detectors. From an IIO
> point of view I would actually like to distinguish how these detectors are
> working but fully appreciate that your average user on a mobile phone doesn't
> care!
> 
> I also know of some parts that do more complex arithmetic to detect free fall
> such as applying the detector on the sum squared value. I haven't as yet worked
> out how to name that one! Perhaps, accel_sum^2_thresh_falling_en?  One for
> another day I think.
> 
> Anyhow for your part you would need to make the attributes mutually exclusive
> (I think).  Thus we only guarantee that an interrupt will remain enabled as long
> as no userspace interactions occur with the attributes.  Hence if one enabled
> freefall first then motion detection, userspace gets to find out they are
> mutually exclusive by reading back the values when it is done setting up what it
> would like.  Providing the 'mode' type option you suggested unfortunately does
> not generalize. For the cma3000 for example, how do you indicate that full rate
> data (more or less as if you were in measurement mode) is available when in free
> fall mode, but not when in motion detection mode? (on the sca3000 to take this
> futher, motion detecton mode completely disables any direct reading of the
> acceleration values) Also, the mode approach breaks down the moment you have
> a device that can do 2 out of n forms of detection at the same time.  This is
> very common (see Analog devices adis parts which have 2 general purpose alarms
> which can detect various things on one channel each where there may be 10 or
> more channels).
> 
> For these special cases, I am perfectly willing to accept that simply labelling
> them free fall and motion detect is fine. I may map the resulting codes in IIO
> to the same as for the above alternate forms, but that doesn't matter for this
> discussion.
> 
I have started conducting a review of what devices on the market actually implement.
http://sourceforge.net/apps/mediawiki/iioutils/index.php?title=Events

One additional option to the above has come up and I'm not entirely sure how it would
fit into the above. The ADXL345 implements a activity and inactivity detection with
'AC coupling'.  This basically means it takes a sample of the current value when
the detector is first enabled then subtract this from the current value before
threshold comparisons are performed.  This is obviously an entirely sensible thing
to do, I merely haven't seen it before. If it were possible to read back the
offset that is being applied we could simply add say, accel_x_mag_rising_offset
(and one per axis) but it isn't.  Thus I can only think to suggest another
'event' type.  Perhaps accel_x_offsetmag_rising? Suggestions for better
names would be most welcome.

This device can also effectively provide 2 freefall detectors if we set the 'inactivity'
detector to be DC with a very low period and value.  The 'inactivity' detector is 
a lot more flexible than the free fall detector.   I guess we may have to allow
accel_x&y&z_falling0_en and accel_x&y&z_falling1_en.

Anyhow, I'm sure there will be more devices out there implementing combinations I
haven't thought of yet...



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sensor event related attribute naming.
  2010-09-27  9:42     ` Jonathan Cameron
@ 2010-09-30 10:06       ` Jonathan Cameron
  2010-11-08 14:07         ` Hemanth V
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2010-09-30 10:06 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Hemanth V, LKML, linux-iio, linux-input, Dmitry Torokhov,
	Manuel Stahl, Jean Delvare, Greg KH, Alan Cox, Andrew Morton,
	drivers, achew, Donggeun Kim

On 09/27/10 10:42, Jonathan Cameron wrote:
> On 09/24/10 12:58, Jonathan Cameron wrote:
>> On 09/24/10 11:34, Hemanth V wrote:
>>> ----- Original Message ----- From: "Jonathan Cameron" <jic23@cam.ac.uk>
>>> <snip>
>>>>
>>>> We have had naming conventions in IIO for a while but they have not
>>>> yet been terribly satisfactory. Our latest suggestion, which I'm
>>>> finally happy is general enough whilst remaining clear to be found
>>>> in  http://marc.info/?l=linux-iio&m=128394796116223&w=2
>>>>
>>>> Manuel Stahl pointed out that the following summary covers what was
>>>> proposed in a clearer fashion.
>>>>
>>>> <channel>_<limit>_<dir>_<attr>, where
>>>> <channel>: name of the channel, i.e. accel_x0
>>>> <limit>:   thresh, mag, roc
>>>> <dir>:     rising, falling
>>>> <attr>:    en, value, period, mean_period
>>>>
>>>
>>> Jonathan, I am trying to understand howto apply this to cma3000. I
>>> have few parameters like below. Would you be able to suggest how
>>> the sysfs entries should look like for the below parameters or are these
>>> still to be defined.
>> Hi Hemanth,
>>
>>>
>>> grange:  2000, 8000 mg sampling frequency  : 40, 100, 400 Hz
>> These weren't covered by this discussion at all. However, I am happy to at
>> least tell you how these are handled in IIO.  Firstly instead of defining
>> ranges we define _scale attributes.  This decision has a lot to do with
>> our approach of using raw data. To process that data, userspace needs to
>> know how to scale it appropriately. It really doesn't directly care what the
>> limits are.  If there is a particular use case for these limits directly then
>> we could propose adding say accel_mag_max. Such a parameter would clearly
>> interact with the alternate setting mechanism of accel_scale and maintaining
>> that relationship would be a job for the driver.
>>
>> Note that if the multiplication is handled in driver (and hence to userspace
>> looks like the device was doing it) then any sysfs based output is obtained
>> via accel_x_input and the associated scale would be in accel_calibgain.
>> accel_calibgain_available would give a space separated list of available gains.
>>
>> Also note that we always stick to SI units, so accelerations are measured in
>> m/s^2 rather that g, so there are some factors to be taken into account.
>> We are against making an exception for accelerometers because that will then
>> make the units for a given sensor type very unpredictable.
>>
>> Frequency is controlled via sampling_frequency (in Hz) with a space
>> separated list of available options in sampling_frequency_available
>>
>> Things are a little fiddly for some parts as the available range can be
>> mode dependant - lower frequencies are often used for motion detection.
>> For example, when motion detection is enabled on the cma3000 the sampling
>> frequency and the measurement range change (10Hz and 8g) so this should be
>> reflected in any reads of these attributes.
>>
>>> Modes : Motion detect, Measurement, Free fall
>> Based on our sca3000 driver and the cma3000 data sheet.
>>
>> The device starts up in Measurement mode - this is the mode it is always
>> in if neither of the others are enabled.  It's up to userspace to switch to
>> one of the other modes.  If sysfs direct read attributes are supplied and the
>> current mode does not allow values to be obtained then we simply return -EBUSY.
>>
>> We then have two event enable attributes.  The names of these are up for
>> discussion (and part of what this thread was meant to address).  Let us for
>> now call them:
>> accel_freefall_en and accel_motiondetect_en
>>
>> The will have accompanying parameters
>>
>> accel_motiondetect_period (MDTMR[3:0] -> in seconds, a pain to do, but it's the
>> 			only way we will have a consistent interface, for cases
>> 			like this with few options,
>> 			 accel_motiondetect_period_available could provide a
>> 			 list of options)
>> accel_motiondetect_value (MDTHR[6:0] -> in either raw units or processed.
>> 			 Whether we need to make this choice explicit in
>> 			 the naming is one of the questions I was hoping this
>> 			 thread might answer) Perhaps
>> 			 accel_motiondetect_value_input for processed values
>> 			 and accel_motiondetect_value_raw for raw sensor units
>> 			 (adc counts).
>>
>> accel_freefall_period (FFTMR[3:0] -> again in seconds)
>> accel_freefall_value (FFTMR[3:0])
>>
>> In our event code structure (not yet posted) we actually allow another option
>> which leads to a more logical and general description of these two detectors
>> which I am keen on because we do have parts that allow weird subsets and
>> devices other than accelerometers that actually perform very similar combined
>> axis boolean combinations. Basically freefall and motiondetect don't really
>> generalise to anything other than 3d accelerometers.
>>
>> For motion detection:
>>
>> accel_x|y|z_thresh_rising_en (the | characters are part of the name,
>> 			     not indicating options for naming!)
>>
>> accel_x|y|z_thresh_rising_period, accel_x|y|z_thresh_rising_value
>>
>> for freefall:
>>
>> accel_x&y&z_thresh_falling_en
>> accel_x&y&z_thresh_falling_value
>> accel_x&y&z_thresh_falling_period
>>
>> These generalize to other forms of sensor far better than the magic 'freefall'
>> but do not easily allow for more sophisticated free fall detectors. From an IIO
>> point of view I would actually like to distinguish how these detectors are
>> working but fully appreciate that your average user on a mobile phone doesn't
>> care!
>>
>> I also know of some parts that do more complex arithmetic to detect free fall
>> such as applying the detector on the sum squared value. I haven't as yet worked
>> out how to name that one! Perhaps, accel_sum^2_thresh_falling_en?  One for
>> another day I think.
>>
>> Anyhow for your part you would need to make the attributes mutually exclusive
>> (I think).  Thus we only guarantee that an interrupt will remain enabled as long
>> as no userspace interactions occur with the attributes.  Hence if one enabled
>> freefall first then motion detection, userspace gets to find out they are
>> mutually exclusive by reading back the values when it is done setting up what it
>> would like.  Providing the 'mode' type option you suggested unfortunately does
>> not generalize. For the cma3000 for example, how do you indicate that full rate
>> data (more or less as if you were in measurement mode) is available when in free
>> fall mode, but not when in motion detection mode? (on the sca3000 to take this
>> futher, motion detecton mode completely disables any direct reading of the
>> acceleration values) Also, the mode approach breaks down the moment you have
>> a device that can do 2 out of n forms of detection at the same time.  This is
>> very common (see Analog devices adis parts which have 2 general purpose alarms
>> which can detect various things on one channel each where there may be 10 or
>> more channels).
>>
>> For these special cases, I am perfectly willing to accept that simply labelling
>> them free fall and motion detect is fine. I may map the resulting codes in IIO
>> to the same as for the above alternate forms, but that doesn't matter for this
>> discussion.
>>
> I have started conducting a review of what devices on the market actually implement.
> http://sourceforge.net/apps/mediawiki/iioutils/index.php?title=Events
> 
> One additional option to the above has come up and I'm not entirely sure how it would
> fit into the above. The ADXL345 implements a activity and inactivity detection with
> 'AC coupling'.  This basically means it takes a sample of the current value when
> the detector is first enabled then subtract this from the current value before
> threshold comparisons are performed.  This is obviously an entirely sensible thing
> to do, I merely haven't seen it before. If it were possible to read back the
> offset that is being applied we could simply add say, accel_x_mag_rising_offset
> (and one per axis) but it isn't.  Thus I can only think to suggest another
> 'event' type.  Perhaps accel_x_offsetmag_rising? Suggestions for better
> names would be most welcome.
> 
> This device can also effectively provide 2 freefall detectors if we set the 'inactivity'
> detector to be DC with a very low period and value.  The 'inactivity' detector is 
> a lot more flexible than the free fall detector.   I guess we may have to allow
> accel_x&y&z_falling0_en and accel_x&y&z_falling1_en.
> 
> Anyhow, I'm sure there will be more devices out there implementing combinations I
> haven't thought of yet...
> 
Given the lack of further comment, I went ahead and implemented the above naming
scheme for IIO. As the above discussion with Hemanth shows, there are some corner cases
that will need futher thought in the future.

One question for this round of updates though.  How to distinguish whether
the _value attributes are in raw units (common in iio) or in processed units (typically
SI) such as the are in input. In IIO we can normally distinguish the two cases based
on the naming of the direct access sysfs interfaces to the relevant channels. However,
this doesn't generalize well as for some devices there may be no direct read capability.

Lets take an example

accel_x_thresh_mag_rising_value  is ambiguous, the next most obvious option is:
accel_x_thresh_mag_rising_value_input
accel_x_thresh_mag_rising_value_raw

but that makes them look like the direct access attributes for very odd channels.

accel_x_input_thresh_mag_rising_value
accel_x_raw_thresh_mag_rising_value
would do the job I suppose, but are clunky given the other parameter names
accel_x_thresh_mag_rising_period etc..

We could introduce new keywords (other than input and raw) to distinguish the cases
but that will introduce further inconsistencies...

Other suggestions most welcome, if nothing better is suggested I guess I'll go
with the last option above...

I'm keen to get this cleared up as much as possible for the next merge window
so time is of the essence!

Jonathan


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Sensor event related attribute naming.
  2010-09-30 10:06       ` Jonathan Cameron
@ 2010-11-08 14:07         ` Hemanth V
  0 siblings, 0 replies; 6+ messages in thread
From: Hemanth V @ 2010-11-08 14:07 UTC (permalink / raw)
  To: Jonathan Cameron, Dmitry Torokhov
  Cc: LKML, linux-iio, linux-input, Manuel Stahl, Jean Delvare,
	Greg KH, Alan Cox, Andrew Morton, drivers, achew, Donggeun Kim

----- Original Message ----- 
From: "Jonathan Cameron" <jic23@cam.ac.uk>
To: "Jonathan Cameron" <jic23@cam.ac.uk>
Sent: Thursday, September 30, 2010 3:36 PM
Subject: Re: Sensor event related attribute naming.


> Given the lack of further comment, I went ahead and implemented the above 
> naming
> scheme for IIO. As the above discussion with Hemanth shows, there are some 
> corner cases
> that will need futher thought in the future.
>

Jonathan, haven't seen many comments on this. Do u think the reason
might be that these interfaces are hidden behind a HAL layer like in android 
and
might not be a burning issue for many people.

Thanks
Hemanth



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-08 14:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-21 14:58 RFC: Sensor event related attribute naming Jonathan Cameron
2010-09-24 10:34 ` Hemanth V
2010-09-24 11:58   ` Jonathan Cameron
2010-09-27  9:42     ` Jonathan Cameron
2010-09-30 10:06       ` Jonathan Cameron
2010-11-08 14:07         ` Hemanth V

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).