AnsweredAssumed Answered

IIO trigger driver for adxl345

Question asked by Alberto on Sep 1, 2017
Latest reply on Sep 5, 2017 by Alberto

Hi,

 

i am developing an IIO driver to control adxl345. I can execute a sysfs trigger succesfully and read the 3 axis samples reading /dev/iio:device1 from an IIO device buffer, but i am not able to read the samples using the iio_generic_buffer application.

 

This is my trigger_handler function:

 

static irqreturn_t adxl345_trigger_handler(int irq, void *p)

{

struct iio_poll_func *pf = p;

struct iio_dev *indio_dev = pf->indio_dev;

struct adxl345_data *data = iio_priv(indio_dev);

 

/* we have to align timestamp to 8 bytes */

s16 buf[8]; // 3 axis x s16 + 1 x s16 pad + 4 x s16 tstamp

int i, ret, j = 0, base = DATAX0;

__le16 sample;

 

for_each_set_bit(i, indio_dev->active_scan_mask,

indio_dev->masklength) {

ret = regmap_bulk_read(data->regmap, base + i * sizeof(__le16),

&sample, sizeof(__le16));

pr_info("the value of i is %d\n", i);

if (ret < 0)

goto done;

buf[j++] = sample;

}

  

/* each buffer entry line is 6 bytes + 2 bytes pad + 8 bytes timestamp */

iio_push_to_buffers_with_timestamp(indio_dev, buf,

iio_get_time_ns(indio_dev));

  

done:

iio_trigger_notify_done(indio_dev->trig);

  

return IRQ_HANDLED;

}

 

These are the steps followed to execute the sysfs trigger and read from the buffer

 

/* echo 1 > iio_sysfs_trigger/add_trigger

* cat trigger1/name > iio:device1/trigger/current_trigger

* echo 100 > buffer/length

* echo 1 > scan_elements/in_accel_x_en

* echo 1 > scan_elements/in_accel_y_en

* echo 1 > scan_elements/in_accel_z_en

* echo 1 > scan_elements/in_timestamp_en

* echo 1 > buffer/enable

* echo 1 > trigger1/trigger_now // do 2 succesive triggers

* echo 1 > trigger1/trigger_now

* hexdump -v -e '16/1 "%02x " "\n"' < /dev/iio\:device1 // con timestamp

* echo 0 > buffer/enable // stop the buffer to remove the module

*/

This is the output i get: 3 axes reading + timestamp for each sysfs trigger (i do 2 conversions)

root@sama5d2-xplained:/sys/bus/iio/devices# hexdump -v -e '16/1 "%02x " "\n"' <

/dev/iio\:device1                                                              

19 00 f2 00 cb ff 87 c9 12 47 a2 9e e9 d5 c9 14                                

18 00 f3 00 ca ff 87 c9 c0 a2 b5 ab ea d5 c9 14

 

But when i use the iio_generic_buffer application i do not get any output.

root@sama5d2-xplained:~# ./iio_generic_buffer --device-num 1 --trigger-num 1 -c 2                                                                          

iio device number being used is 1                                              

iio trigger number being used is 1                                            

/sys/bus/iio/devices/iio:device1 sysfstrig1                                    

 

Any idea about why the appplication is not working?

 

Thanks in advance

Alberto

Outcomes