Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing repeat channels #1

Open
wants to merge 4 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 76 additions & 34 deletions drivers/iio/dummy/iio_simple_dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,23 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
.shift = 0, /* zero shift */
},
},
/*
* Convenience macro for timestamps. 4 is the index in
* the buffer.
*/
IIO_CHAN_SOFT_TIMESTAMP(4),
/* Rotation channel with 4 repeated elements */
{
.type = IIO_ROT,
.modified = 1,
.channel2 = IIO_MOD_QUATERNION,
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
.scan_index = DUMMY_INDEX_ROT,
.scan_type = {
.sign = 's',
.realbits = sizeof(uint16_t) * 8,
.storagebits = sizeof(uint16_t) * 8,
.endianness = IIO_LE,
.repeat = 4,
},
},
/* Convenience macro for timestamps */
IIO_CHAN_SOFT_TIMESTAMP(DUMMY_INDEX_TIMESTAMP),
/* DAC channel out_voltage0_raw */
{
.type = IIO_VOLTAGE,
Expand Down Expand Up @@ -271,19 +283,20 @@ static const struct iio_chan_spec iio_dummy_channels[] = {
};

/**
* iio_dummy_read_raw() - data read function.
* iio_dummy_read_raw_multi() - data read function
* @indio_dev: the struct iio_dev associated with this device instance
* @chan: the channel whose data is to be read
* @val: first element of returned value (typically INT)
* @val2: second element of returned value (typically MICRO)
* @max_len: maximum number of elements
* @vals: the elements making up the returned value
* (typically vals[0] INT vals[1] MICRO)
* @val_len: length of valid elements in vals
* @mask: what we actually want to read as per the info_mask_*
* in iio_chan_spec.
*/
static int iio_dummy_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val,
int *val2,
long mask)
static int iio_dummy_read_raw_multi(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int max_len, int *vals, int *val_len,
long mask)
{
struct iio_dummy_state *st = iio_priv(indio_dev);
int ret = -EINVAL;
Expand All @@ -295,41 +308,58 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
case IIO_VOLTAGE:
if (chan->output) {
/* Set integer part to cached value */
*val = st->dac_val;
vals[0] = st->dac_val;
*val_len = 1;
ret = IIO_VAL_INT;
} else if (chan->differential) {
if (chan->channel == 1)
*val = st->differential_adc_val[0];
vals[0] = st->differential_adc_val[0];
else
*val = st->differential_adc_val[1];
vals[0] = st->differential_adc_val[1];
*val_len = 1;
ret = IIO_VAL_INT;
} else {
*val = st->single_ended_adc_val;
vals[0] = st->single_ended_adc_val;
*val_len = 1;
ret = IIO_VAL_INT;
}
break;
case IIO_ACCEL:
*val = st->accel_val;
vals[0] = st->accel_val;
*val_len = 1;
ret = IIO_VAL_INT;
break;
case IIO_ROT:
if (max_len >= 4) {
vals[0] = st->rotation_val[0];
vals[1] = st->rotation_val[1];
vals[2] = st->rotation_val[2];
vals[3] = st->rotation_val[3];
*val_len = 4;
ret = IIO_VAL_INT_MULTIPLE;
}
break;
default:
break;
}
break;
case IIO_CHAN_INFO_PROCESSED:
switch (chan->type) {
case IIO_STEPS:
*val = st->steps;
vals[0] = st->steps;
*val_len = 1;
ret = IIO_VAL_INT;
break;
case IIO_ACTIVITY:
switch (chan->channel2) {
case IIO_MOD_RUNNING:
*val = st->activity_running;
vals[0] = st->activity_running;
*val_len = 1;
ret = IIO_VAL_INT;
break;
case IIO_MOD_WALKING:
*val = st->activity_walking;
vals[0] = st->activity_walking;
*val_len = 1;
ret = IIO_VAL_INT;
break;
default:
Expand All @@ -342,7 +372,8 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_OFFSET:
/* only single ended adc -> 7 */
*val = 7;
vals[0] = 7;
*val_len = 1;
ret = IIO_VAL_INT;
break;
case IIO_CHAN_INFO_SCALE:
Expand All @@ -351,14 +382,16 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
switch (chan->differential) {
case 0:
/* only single ended adc -> 0.001333 */
*val = 0;
*val2 = 1333;
vals[0] = 0;
vals[1] = 1333;
*val_len = 1;
ret = IIO_VAL_INT_PLUS_MICRO;
break;
case 1:
/* all differential adc -> 0.000001344 */
*val = 0;
*val2 = 1344;
vals[0] = 0;
vals[1] = 1344;
*val_len = 1;
ret = IIO_VAL_INT_PLUS_NANO;
}
break;
Expand All @@ -368,23 +401,27 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_CALIBBIAS:
/* only the acceleration axis - read from cache */
*val = st->accel_calibbias;
vals[0] = st->accel_calibbias;
*val_len = 1;
ret = IIO_VAL_INT;
break;
case IIO_CHAN_INFO_CALIBSCALE:
*val = st->accel_calibscale->val;
*val2 = st->accel_calibscale->val2;
vals[0] = st->accel_calibscale->val;
vals[1] = st->accel_calibscale->val2;
*val_len = 1;
ret = IIO_VAL_INT_PLUS_MICRO;
break;
case IIO_CHAN_INFO_SAMP_FREQ:
*val = 3;
*val2 = 33;
vals[0] = 3;
vals[1] = 33;
*val_len = 1;
ret = IIO_VAL_INT_PLUS_NANO;
break;
case IIO_CHAN_INFO_ENABLE:
switch (chan->type) {
case IIO_STEPS:
*val = st->steps_enabled;
vals[0] = st->steps_enabled;
*val_len = 1;
ret = IIO_VAL_INT;
break;
default:
Expand All @@ -394,7 +431,8 @@ static int iio_dummy_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_CALIBHEIGHT:
switch (chan->type) {
case IIO_STEPS:
*val = st->height;
vals[0] = st->height;
*val_len = 1;
ret = IIO_VAL_INT;
break;
default:
Expand Down Expand Up @@ -520,7 +558,7 @@ static int iio_dummy_write_raw(struct iio_dev *indio_dev,
*/
static const struct iio_info iio_dummy_info = {
.driver_module = THIS_MODULE,
.read_raw = &iio_dummy_read_raw,
.read_raw_multi = &iio_dummy_read_raw_multi,
.write_raw = &iio_dummy_write_raw,
#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
.read_event_config = &iio_simple_dummy_read_event_config,
Expand Down Expand Up @@ -551,6 +589,10 @@ static int iio_dummy_init_device(struct iio_dev *indio_dev)
st->steps = 47;
st->activity_running = 98;
st->activity_walking = 4;
st->rotation_val[0] = 52;
st->rotation_val[1] = 126;
st->rotation_val[2] = 51;
st->rotation_val[3] = 75;

return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions drivers/iio/dummy/iio_simple_dummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct iio_dummy_state {
int steps_enabled;
int steps;
int height;
int rotation_val[4];
#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
int event_irq;
int event_val;
Expand Down Expand Up @@ -102,6 +103,8 @@ iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
* @DUMMY_INDEX_DIFFVOLTAGE_1M2: first differential channel
* @DUMMY_INDEX_DIFFVOLTAGE_3M4: second differential channel
* @DUMMY_INDEX_ACCELX: acceleration channel
* @DUMMY_INDEX_ROT: rotation x, y, z, w channels
* @DUMMY_INDEX_TIMESTAMP: timestamp (must be last)
*
* Enum provides convenient numbering for the scan index.
*/
Expand All @@ -110,6 +113,8 @@ enum iio_simple_dummy_scan_elements {
DUMMY_INDEX_DIFFVOLTAGE_1M2,
DUMMY_INDEX_DIFFVOLTAGE_3M4,
DUMMY_INDEX_ACCELX,
DUMMY_INDEX_ROT,
DUMMY_INDEX_TIMESTAMP,
};

#ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
Expand Down
13 changes: 11 additions & 2 deletions drivers/iio/dummy/iio_simple_dummy_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static const s16 fakedata[] = {
[DUMMY_INDEX_DIFFVOLTAGE_1M2] = -33,
[DUMMY_INDEX_DIFFVOLTAGE_3M4] = -2,
[DUMMY_INDEX_ACCELX] = 344,
[DUMMY_INDEX_ROT] = 30,
};

/**
Expand Down Expand Up @@ -80,8 +81,16 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
j = find_next_bit(indio_dev->active_scan_mask,
indio_dev->masklength, j);
/* random access read from the 'device' */
data[i] = fakedata[j];
len += 2;
if (j == DUMMY_INDEX_ROT) {
data[i++] = fakedata[j];
data[i++] = fakedata[j] + 1;
data[i++] = fakedata[j] + 2;
data[i++] = fakedata[j] + 3;
len += 8;
} else {
data[i] = fakedata[j];
len += 2;
}
}
}

Expand Down
59 changes: 34 additions & 25 deletions tools/iio/iio_generic_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
channels[i].location = bytes - bytes % channels[i].bytes
+ channels[i].bytes;

bytes = channels[i].location + channels[i].bytes;
bytes = channels[i].location + channels[i].bytes
* (channels[i].repeat ? channels[i].repeat : 1);
i++;
}

Expand Down Expand Up @@ -175,30 +176,38 @@ void process_scan(char *data,
struct iio_channel_info *channels,
int num_channels)
{
int k;

for (k = 0; k < num_channels; k++)
switch (channels[k].bytes) {
/* only a few cases implemented so far */
case 1:
print1byte(*(uint8_t *)(data + channels[k].location),
&channels[k]);
break;
case 2:
print2byte(*(uint16_t *)(data + channels[k].location),
&channels[k]);
break;
case 4:
print4byte(*(uint32_t *)(data + channels[k].location),
&channels[k]);
break;
case 8:
print8byte(*(uint64_t *)(data + channels[k].location),
&channels[k]);
break;
default:
break;
}
int k, repeat_nr;

for (k = 0; k < num_channels; k++) {
repeat_nr = 0;
do {
switch (channels[k].bytes) {
/* only a few cases implemented so far */
case 1:
print1byte(*(uint8_t *)(data + channels[k].location
+ repeat_nr*channels[k].bytes),
&channels[k]);
break;
case 2:
print2byte(*(uint16_t *)(data + channels[k].location
+ repeat_nr*channels[k].bytes),
&channels[k]);
break;
case 4:
print4byte(*(uint32_t *)(data + channels[k].location
+ repeat_nr*channels[k].bytes),
&channels[k]);
break;
case 8:
print8byte(*(uint64_t *)(data + channels[k].location
+ repeat_nr*channels[k].bytes),
&channels[k]);
break;
default:
break;
}
} while (++repeat_nr < (channels[k].repeat ? channels[k].repeat : 1));
}
printf("\n");
}

Expand Down
Loading