/* Adjust channel real bits based on report descriptor */ staticvoid dev_rot_adjust_channel_bit_mask(struct iio_chan_spec *chan, int size)
{
chan->scan_type.sign = 's'; /* Real storage bits will change based on the report desc. */
chan->scan_type.realbits = size * 8; /* Maximum size of a sample to capture is u32 */
chan->scan_type.storagebits = sizeof(u32) * 8;
chan->scan_type.repeat = 4;
}
/* Channel read_raw handler */ staticint dev_rot_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int size, int *vals, int *val_len, long mask)
{ struct dev_rot_state *rot_state = iio_priv(indio_dev); int ret_type; int i;
vals[0] = 0;
vals[1] = 0;
switch (mask) { case IIO_CHAN_INFO_RAW: if (size >= 4) { for (i = 0; i < 4; ++i)
vals[i] = rot_state->scan.sampled_vals[i];
ret_type = IIO_VAL_INT_MULTIPLE;
*val_len = 4;
} else
ret_type = -EINVAL; break; case IIO_CHAN_INFO_SCALE:
vals[0] = rot_state->scale_pre_decml;
vals[1] = rot_state->scale_post_decml; return rot_state->scale_precision;
case IIO_CHAN_INFO_OFFSET:
*vals = rot_state->value_offset; return IIO_VAL_INT;
/* Callback handler to send event after all samples are received and captured */ staticint dev_rot_proc_event(struct hid_sensor_hub_device *hsdev, unsigned usage_id, void *priv)
{ struct iio_dev *indio_dev = platform_get_drvdata(priv); struct dev_rot_state *rot_state = iio_priv(indio_dev);
dev_dbg(&indio_dev->dev, "dev_rot_proc_event\n"); if (atomic_read(&rot_state->common_attributes.data_ready)) { if (!rot_state->timestamp)
rot_state->timestamp = iio_get_time_ns(indio_dev);
/* Parse report which is specific to an usage id*/ staticint dev_rot_parse_report(struct platform_device *pdev, struct hid_sensor_hub_device *hsdev, struct iio_chan_spec *channels, unsigned usage_id, struct dev_rot_state *st)
{ int ret;
ret = sensor_hub_input_get_attribute_info(hsdev,
HID_INPUT_REPORT,
usage_id,
HID_USAGE_SENSOR_ORIENT_QUATERNION,
&st->quaternion); if (ret) return ret;
/* Function to initialize the processing for usage id */ staticint hid_dev_rot_probe(struct platform_device *pdev)
{ struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); int ret; char *name; struct iio_dev *indio_dev; struct dev_rot_state *rot_state;
switch (hsdev->usage) { case HID_USAGE_SENSOR_DEVICE_ORIENTATION:
name = "dev_rotation"; break; case HID_USAGE_SENSOR_RELATIVE_ORIENTATION:
name = "relative_orientation"; break; case HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION:
name = "geomagnetic_orientation"; break; default: return -EINVAL;
}
ret = hid_sensor_parse_common_attributes(hsdev,
hsdev->usage,
&rot_state->common_attributes,
rotation_sensitivity_addresses,
ARRAY_SIZE(rotation_sensitivity_addresses)); if (ret) {
dev_err(&pdev->dev, "failed to setup common attributes\n"); return ret;
}
indio_dev->channels = devm_kmemdup(&pdev->dev, dev_rot_channels, sizeof(dev_rot_channels),
GFP_KERNEL); if (!indio_dev->channels) {
dev_err(&pdev->dev, "failed to duplicate channels\n"); return -ENOMEM;
}
ret = dev_rot_parse_report(pdev, hsdev,
(struct iio_chan_spec *)indio_dev->channels,
hsdev->usage, rot_state); if (ret) {
dev_err(&pdev->dev, "failed to setup attributes\n"); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.