iio_trigger_alloc
iio_trigger_free
In many situations it is useful for a driver to be able to capture data based on some external event (trigger) as opposed to periodically polling for data. An IIO trigger can be provided by a device driver that also has an IIO device based on hardware generated events (e.g. data ready or threshold exceeded) or provided by a separate driver from an independent interrupt source (e.g. GPIO line connected to some external system, timer interrupt or user space writing a specific file in sysfs). A trigger may initiate data capture for a number of sensors and also it may be completely unrelated to the sensor itself.
/sys/bus/iio/devices/triggerY
,
this file is created once an IIO trigger is registered with
the IIO core and corresponds to trigger with index Y. Because
triggers can be very different depending on type there are few
standard attributes that we can describe here:
/sys/bus/iio/devices/iio:deviceX/trigger/
, this
directory is created once the device supports a triggered
buffer. We can associate a trigger with our device by writing
the trigger's name in the current_trigger
file.
Let's see a simple example of how to setup a trigger to be used by a driver.
struct iio_trigger_ops trigger_ops = { .set_trigger_state = sample_trigger_state, .validate_device = sample_validate_device, } struct iio_trigger *trig; /* first, allocate memory for our trigger */ trig = iio_trigger_alloc(dev, "trig-%s-%d", name, idx); /* setup trigger operations field */ trig->ops = &trigger_ops; /* now register the trigger with the IIO core */ iio_trigger_register(trig);
Notice that a trigger has a set of operations attached:
set_trigger_state
, switch the trigger on/off
on demand.
validate_device
, function to validate the
device when the current trigger gets changed.