Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucasrangit/90a9960c23cc8e771d3d2abcf2f9d391 to your computer and use it in GitHub Desktop.
Save lucasrangit/90a9960c23cc8e771d3d2abcf2f9d391 to your computer and use it in GitHub Desktop.
Add shared accelerometer channel enable attribute
From 094ed79b63ecb8a11c9fa69041395f1459a336fa Mon Sep 17 00:00:00 2001
From: Lucas Magasweran <lucas.magasweran@daqri.com>
Date: Thu, 4 Aug 2016 16:24:43 -0700
Subject: [PATCH] iio: dummy: add shared accel enable
Signed-off-by: Lucas Magasweran <lucas.magasweran@daqri.com>
---
drivers/iio/dummy/iio_simple_dummy.c | 37 +++++++++++++++++++++++++++--
drivers/iio/dummy/iio_simple_dummy.h | 6 ++++-
drivers/iio/dummy/iio_simple_dummy_buffer.c | 2 +-
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 43fe4ba..ddeeb3c 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -204,7 +204,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
},
/*
* 'modified' (i.e. axis specified) acceleration channel
- * in_accel_z_raw
+ * in_accel_x_raw
*/
{
.type = IIO_ACCEL,
@@ -220,6 +220,7 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
*/
BIT(IIO_CHAN_INFO_CALIBSCALE) |
BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_ENABLE),
.info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
.scan_index = DUMMY_INDEX_ACCELX,
.scan_type = { /* Description of storage in buffer */
@@ -230,10 +231,38 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
},
},
/*
+ * 'modified' (i.e. axis specified) acceleration channel
+ * in_accel_y_raw
+ */
+ {
+ .type = IIO_ACCEL,
+ .modified = 1,
+ /* Channel 2 is use for modifiers */
+ .channel2 = IIO_MOD_Y,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ /*
+ * Internal bias and gain correction values. Applied
+ * by the hardware or driver prior to userspace
+ * seeing the readings. Typically part of hardware
+ * calibration.
+ */
+ BIT(IIO_CHAN_INFO_CALIBSCALE) |
+ BIT(IIO_CHAN_INFO_CALIBBIAS),
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_ENABLE),
+ .info_mask_shared_by_dir = BIT(IIO_CHAN_INFO_SAMP_FREQ),
+ .scan_index = DUMMY_INDEX_ACCELY,
+ .scan_type = { /* Description of storage in buffer */
+ .sign = 's', /* signed */
+ .realbits = 16, /* 16 bits */
+ .storagebits = 16, /* 16 bits used for storage */
+ .shift = 0, /* zero shift */
+ },
+ },
+ /*
* Convenience macro for timestamps. 4 is the index in
* the buffer.
*/
- IIO_CHAN_SOFT_TIMESTAMP(4),
+ IIO_CHAN_SOFT_TIMESTAMP(DUMMY_INDEX_TIMESTAMP),
/* DAC channel out_voltage0_raw */
{
.type = IIO_VOLTAGE,
@@ -395,6 +424,9 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
*val = st->steps_enabled;
ret = IIO_VAL_INT;
break;
+ case IIO_ACCEL:
+ *val = 1;
+ ret = IIO_VAL_INT;
default:
break;
}
@@ -638,6 +670,7 @@ static int iio_dummy_probe(int index)
if (ret < 0)
goto error_free_device;
+
ret = iio_simple_dummy_configure_buffer(indio_dev);
if (ret < 0)
goto error_unregister_events;
diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
index b9069a1..24ec928 100644
--- a/drivers/iio/dummy/iio_simple_dummy.h
+++ b/drivers/iio/dummy/iio_simple_dummy.h
@@ -101,7 +101,9 @@ iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
* @DUMMY_INDEX_VOLTAGE_0: the single ended voltage channel
* @DUMMY_INDEX_DIFFVOLTAGE_1M2: first differential channel
* @DUMMY_INDEX_DIFFVOLTAGE_3M4: second differential channel
- * @DUMMY_INDEX_ACCELX: acceleration channel
+ * @DUMMY_INDEX_ACCELX: acceleration x-axis channel
+ * @DUMMY_INDEX_ACCELY: acceleration y-axis channel
+ * @DUMMY_INDEX_TIMESTAMP: timestamp (must be last)
*
* Enum provides convenient numbering for the scan index.
*/
@@ -110,6 +112,8 @@ enum iio_simple_dummy_scan_elements {
DUMMY_INDEX_DIFFVOLTAGE_1M2,
DUMMY_INDEX_DIFFVOLTAGE_3M4,
DUMMY_INDEX_ACCELX,
+ DUMMY_INDEX_ACCELY,
+ DUMMY_INDEX_TIMESTAMP,
};
#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
diff --git a/drivers/iio/dummy/iio_simple_dummy_buffer.c b/drivers/iio/dummy/iio_simple_dummy_buffer.c
index cf44a6f..d2bff72 100644
--- a/drivers/iio/dummy/iio_simple_dummy_buffer.c
+++ b/drivers/iio/dummy/iio_simple_dummy_buffer.c
@@ -10,7 +10,6 @@
*
* To test without hardware use the sysfs trigger.
*/
-
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/slab.h>
@@ -31,6 +30,7 @@ static const s16 fakedata[] = {
[DUMMY_INDEX_DIFFVOLTAGE_1M2] = -33,
[DUMMY_INDEX_DIFFVOLTAGE_3M4] = -2,
[DUMMY_INDEX_ACCELX] = 344,
+ [DUMMY_INDEX_ACCELY] = 806,
};
/**
--
2.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment