Skip to contentSkip to conversation

vivid: Add touch support

PATCH Superseded Vandana BN 2 participants 10 messages Nov 18, 2019 – Nov 26, 2019 1 message not in the archive Media (V4L/DVB)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Vandana BN

author
#1 lore raw

PATCH v7 1/1 vivid: Add touch support

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating, single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and an invalid pattern of simulating 16 different simultaneous touch points.
All of these patterns are based on behavior of rmi_f54 driver.

---
Changes since V6:
simplified touch pattern generation.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 +++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 +++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 286 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  35 +++
 8 files changed, 700 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h
drivers/media/platform/vivid/Makefile +2 -1
index e8a50c506dc9..b12ad0152a3e 100644
@@ -3,7 +3,8 @@ vivid-objs := vivid-core.o vivid-ctrls.o vivid-vid-common.o vivid-vbi-gen.o \
 		vivid-vid-cap.o vivid-vid-out.o vivid-kthread-cap.o vivid-kthread-out.o \
 		vivid-radio-rx.o vivid-radio-tx.o vivid-radio-common.o \
 		vivid-rds-gen.o vivid-sdr-cap.o vivid-vbi-cap.o vivid-vbi-out.o \
-		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o
+		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o \
+		vivid-kthread-touch.o vivid-touch-cap.o
 ifeq ($(CONFIG_VIDEO_VIVID_CEC),y)
   vivid-objs += vivid-cec.o
 endif
drivers/media/platform/vivid/vivid-core.c +152 -12

292 lines not on this page · raw message

drivers/media/platform/vivid/vivid-core.h +20 -0
index 59192b67231c..99e69b8f770f 100644
@@ -133,6 +133,7 @@ struct vivid_dev {
 	struct media_pad		sdr_cap_pad;
 	struct media_pad		meta_cap_pad;
 	struct media_pad		meta_out_pad;
+	struct media_pad		touch_cap_pad;
 #endif
 	struct v4l2_ctrl_handler	ctrl_hdl_user_gen;
 	struct v4l2_ctrl_handler	ctrl_hdl_user_vid;
@@ -159,6 +160,8 @@ struct vivid_dev {
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_cap;
 	struct video_device		meta_out_dev;
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_out;
+	struct video_device		touch_cap_dev;
+	struct v4l2_ctrl_handler	ctrl_hdl_touch_cap;
 
 	spinlock_t			slock;
 	struct mutex			mutex;
@@ -173,6 +176,7 @@ struct vivid_dev {
 	u32				radio_tx_caps;
 	u32				meta_cap_caps;
 	u32				meta_out_caps;
+	u32				touch_cap_caps;
 
 	/* supported features */
 	bool				multiplanar;
@@ -201,6 +205,7 @@ struct vivid_dev {
 	bool				has_meta_cap;
 	bool				has_meta_out;
 	bool				has_tv_tuner;
+	bool				has_touch_cap;
 
 	bool				can_loop_video;
 
@@ -404,6 +409,8 @@ struct vivid_dev {
 	struct list_head		vbi_cap_active;
 	struct vb2_queue		vb_meta_cap_q;
 	struct list_head		meta_cap_active;
+	struct vb2_queue		vb_touch_cap_q;
+	struct list_head		touch_cap_active;
 
 	/* thread for generating video capture stream */
 	struct task_struct		*kthread_vid_cap;
@@ -425,6 +432,19 @@ struct vivid_dev {
 	u32				meta_cap_seq_count;
 	bool				meta_cap_streaming;
 
+	/* Touch capture */
+	struct task_struct		*kthread_touch_cap;
+	unsigned long			jiffies_touch_cap;
+	u64				touch_cap_stream_start;
+	u32				touch_cap_seq_offset;
+	bool				touch_cap_seq_resync;
+	u32				touch_cap_seq_start;
+	u32				touch_cap_seq_count;
+	bool				touch_cap_streaming;
+	struct v4l2_fract		timeperframe_tch_cap;
+	struct v4l2_pix_format		tch_format;
+	int				tch_pat_random;
+
 	/* video output */
 	const struct vivid_fmt		*fmt_out;
 	struct v4l2_fract		timeperframe_vid_out;
drivers/media/platform/vivid/vivid-ctrls.c +11 -0
index 68e8124c7973..334130568dcb 100644
@@ -1508,6 +1508,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	struct v4l2_ctrl_handler *hdl_sdr_cap = &dev->ctrl_hdl_sdr_cap;
 	struct v4l2_ctrl_handler *hdl_meta_cap = &dev->ctrl_hdl_meta_cap;
 	struct v4l2_ctrl_handler *hdl_meta_out = &dev->ctrl_hdl_meta_out;
+	struct v4l2_ctrl_handler *hdl_tch_cap = &dev->ctrl_hdl_touch_cap;
 
 	struct v4l2_ctrl_config vivid_ctrl_dv_timings = {
 		.ops = &vivid_vid_cap_ctrl_ops,
@@ -1551,6 +1552,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	v4l2_ctrl_new_custom(hdl_meta_cap, &vivid_ctrl_class, NULL);
 	v4l2_ctrl_handler_init(hdl_meta_out, 2);
 	v4l2_ctrl_new_custom(hdl_meta_out, &vivid_ctrl_class, NULL);
+	v4l2_ctrl_handler_init(hdl_tch_cap, 2);
+	v4l2_ctrl_new_custom(hdl_tch_cap, &vivid_ctrl_class, NULL);
 
 	/* User Controls */
 	dev->volume = v4l2_ctrl_new_std(hdl_user_aud, NULL,
@@ -1904,6 +1907,13 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 			return hdl_meta_out->error;
 		dev->meta_out_dev.ctrl_handler = hdl_meta_out;
 	}
+	if (dev->has_touch_cap) {
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_user_gen, NULL, false);
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_streaming, NULL, false);
+		if (hdl_tch_cap->error)
+			return hdl_tch_cap->error;
+		dev->touch_cap_dev.ctrl_handler = hdl_tch_cap;
+	}
 	return 0;
 }
 
@@ -1925,4 +1935,5 @@ void vivid_free_controls(struct vivid_dev *dev)
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_fb);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_cap);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_out);
+	v4l2_ctrl_handler_free(&dev->ctrl_hdl_touch_cap);
 }
drivers/media/platform/vivid/vivid-kthread-touch.c new file +181 -0

181 lines not on this page · raw message

drivers/media/platform/vivid/vivid-kthread-touch.h new file +13 -0
new file mode 100644
index 000000000000..ecf79b46209e
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-kthread-cap.h - video/vbi capture thread support functions.
+ *
+ */
+
+#ifndef _VIVID_KTHREAD_CAP_H_
+#define _VIVID_KTHREAD_CAP_H_
+
+int vivid_start_generating_touch_cap(struct vivid_dev *dev);
+void vivid_stop_generating_touch_cap(struct vivid_dev *dev);
+
+#endif
drivers/media/platform/vivid/vivid-touch-cap.c new file +286 -0

286 lines not on this page · raw message

drivers/media/platform/vivid/vivid-touch-cap.h new file +35 -0
new file mode 100644
index 000000000000..6e83ca919f07
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
Signature · 1 line
2.17.1
#2 lore raw

Hi Vandana,

Quoted 2 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating, single tap, double tap, triple

No , after 'simulating'.

Quoted 2 lines

tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and an invalid pattern of

Drop the 'invalid': it is not invalid, just very, very unusual.

Quoted 2 lines

simulating 16 different simultaneous touch points. All of these patterns are based on behavior of rmi_f54 driver.

The patterns aren't from that driver, but the generated values are.

Quoted 19 lines

---
Changes since V6:
simplified touch pattern generation.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 +++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 +++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 286 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  35 +++
 8 files changed, 700 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h

<snip>

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int index = 0, x, y, xstart, ystart;
+	unsigned int test_pattern, test_pat_idx, rand;

drivers/media/platform/vivid/vivid-touch-cap.c line 223

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / 15) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % 15;
+
+	vivid_fill_buff_noise(tch_buf, size);
+
+	if (test_pat_idx >= 10)

The values 10 and 15 should be defines. That makes it easy to change later.

I think it would be better to change 15 to 16 and 10 to 12: 16 helps because in the corner case where the sequence counter will wrap around you will get a smooth transition. And 12 makes each sequence just a little bit longer, which makes it easier to see.

Quoted 12 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +12 -0
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:

drivers/media/platform/vivid/vivid-touch-cap.c line 245

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+		if (test_pat_idx == 3 || test_pat_idx == 6)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(tch_buf,
+				  (rand % f->height) * f->width + test_pat_idx * (f->width / 10));

Line too long (same in similar cases below). It's easiest to break it off after the + like this:

		vivid_tch_buf_set(tch_buf,
				  (rand % f->height) * f->width +
				  test_pat_idx * (f->width / 10));

drivers/media/platform/vivid/vivid-touch-cap.c line 249

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;

You need extra variables for the offset from the center:

		offset_x = ((9 - test_pat_idx) * x) / 10;   (10 should be a define as discussed above)
		offset_y = ((9 - test_pat_idx) * y) / 10;

drivers/media/platform/vivid/vivid-touch-cap.c line 250

Quoted 1 line
drivers/media/platform/vivid/vivid-touch-cap.c new file +1 -0
+		if (x + test_pat_idx < f->width && y + test_pat_idx < f->height) {

Then this if can be dropped here as well.

drivers/media/platform/vivid/vivid-touch-cap.c

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+			vivid_tch_buf_set(tch_buf, (x - test_pat_idx) + f->width * (y - test_pat_idx));
+			vivid_tch_buf_set(tch_buf, (x + test_pat_idx) + f->width * (y + test_pat_idx));
+		}
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		index = min(x, y) - test_pat_idx - 1;> +		if (x + index >= f->width / 2 && y + index >= f->height / 2) {

Same here.

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+			vivid_tch_buf_set(tch_buf, (x - index) + f->width * (y - index));
+			vivid_tch_buf_set(tch_buf, (x + index) + f->width * (y + index));
+		}
+		break;
+	case PALM_PRESS:
+		xstart = f->width - f->width / 4;

Just set this to 0, so the palm covers the bottom quarter.

Quoted 11 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +11 -0
+		ystart = f->height - f->height / 4;
+		if (test_pat_idx != 5)
+			break;
+		for (x = xstart; x < f->width; x++)
+			for (y = ystart; y < f->height; y++)
+				vivid_tch_buf_set(tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:
+		/* 16 pressure points */
+		if (test_pat_idx != 5)
+			break;

drivers/media/platform/vivid/vivid-touch-cap.c line 286

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(tch_buf, ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+}

Regards,

Hans

Quoted 42 lines
drivers/media/platform/vivid/vivid-touch-cap.h new file +35 -0
new file mode 100644
index 000000000000..6e83ca919f07
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
#3 lore raw
Quoted 38 lines · Hans Verkuil

Hi Vandana,

Quoted 2 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating, single tap, double tap, triple

No , after 'simulating'.

Quoted 2 lines

tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and an invalid pattern of

Drop the 'invalid': it is not invalid, just very, very unusual.

Quoted 2 lines

simulating 16 different simultaneous touch points. All of these patterns are based on behavior of rmi_f54 driver.

The patterns aren't from that driver, but the generated values are.

Quoted 5 lines

---
Changes since V6:
simplified touch pattern generation.

Quoted 14 lines
---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 +++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 +++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 286 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  35 +++
 8 files changed, 700 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h
Quoted 2 lines

<snip>

I couldn't resist: here is a vivid_tch_buf_set that fills in the neighboring pixels as well for more realism:

static void vivid_tch_buf_set(__s16 *tch_buf, struct v4l2_pix_format *f, int index)

{
        unsigned int x = index % f->width;
        unsigned int y = index / f->width;
        unsigned int offset = VIVID_MIN_PRESSURE;

        tch_buf[index] = offset + get_random_int() % 40;
        offset /= 2;
        if (x)
                tch_buf[index - 1] = offset + get_random_int() % 40;
        if (x < f->width - 1)
                tch_buf[index + 1] = offset + get_random_int() % 40;
        if (y)
                tch_buf[index - f->width] = offset + get_random_int() % 40;
        if (y < f->height - 1)
                tch_buf[index + f->width] = offset + get_random_int() % 40;
        offset /= 2;
        if (x && y)
                tch_buf[index - 1 - f->width] = offset + get_random_int() % 40;
        if (x < f->width - 1 && y)
                tch_buf[index + 1 - f->width] = offset + get_random_int() % 40;
        if (x && y < f->height - 1)
                tch_buf[index - 1 + f->width] = offset + get_random_int() % 40;
        if (x < f->width - 1 && y < f->height - 1)
                tch_buf[index + 1 + f->width] = offset + get_random_int() % 40;
}

The result now looks very close to the real hardware.

Quoted 78 lines
Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int index = 0, x, y, xstart, ystart;
+	unsigned int test_pattern, test_pat_idx, rand;

drivers/media/platform/vivid/vivid-touch-cap.c line 223

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / 15) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % 15;
+
+	vivid_fill_buff_noise(tch_buf, size);
+
+	if (test_pat_idx >= 10)

The values 10 and 15 should be defines. That makes it easy to change later.

I think it would be better to change 15 to 16 and 10 to 12: 16 helps because in the corner case where the sequence counter will wrap around you will get a smooth transition. And 12 makes each sequence just a little bit longer, which makes it easier to see.

Quoted 12 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +12 -0
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:

drivers/media/platform/vivid/vivid-touch-cap.c line 245

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+		if (test_pat_idx == 3 || test_pat_idx == 6)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(tch_buf,
+				  (rand % f->height) * f->width + test_pat_idx * (f->width / 10));

Line too long (same in similar cases below). It's easiest to break it off after the + like this:

		vivid_tch_buf_set(tch_buf,
				  (rand % f->height) * f->width +
				  test_pat_idx * (f->width / 10));

drivers/media/platform/vivid/vivid-touch-cap.c line 249

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;

You need extra variables for the offset from the center:

		offset_x = ((9 - test_pat_idx) * x) / 10;   (10 should be a define as discussed above)
		offset_y = ((9 - test_pat_idx) * y) / 10;

drivers/media/platform/vivid/vivid-touch-cap.c line 250

Quoted 1 line
drivers/media/platform/vivid/vivid-touch-cap.c new file +1 -0
+		if (x + test_pat_idx < f->width && y + test_pat_idx < f->height) {

Then this if can be dropped here as well.

drivers/media/platform/vivid/vivid-touch-cap.c

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+			vivid_tch_buf_set(tch_buf, (x - test_pat_idx) + f->width * (y - test_pat_idx));
+			vivid_tch_buf_set(tch_buf, (x + test_pat_idx) + f->width * (y + test_pat_idx));
+		}
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		index = min(x, y) - test_pat_idx - 1;> +		if (x + index >= f->width / 2 && y + index >= f->height / 2) {

Same here.

Quoted 5 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 264

Quoted 5 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +5 -0
+			vivid_tch_buf_set(tch_buf, (x - index) + f->width * (y - index));
+			vivid_tch_buf_set(tch_buf, (x + index) + f->width * (y + index));
+		}
+		break;
+	case PALM_PRESS:

For this palm press test and...

Quoted 4 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 1 line
drivers/media/platform/vivid/vivid-touch-cap.c new file +1 -0
+		xstart = f->width - f->width / 4;

Just set this to 0, so the palm covers the bottom quarter.

Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 273

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+		ystart = f->height - f->height / 4;
+		if (test_pat_idx != 5)
+			break;
+		for (x = xstart; x < f->width; x++)
+			for (y = ystart; y < f->height; y++)
+				vivid_tch_buf_set(tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:

... the multiple press test you can drop the 'if (test_pat_idx != 5)' bit:
i.e. this pattern should be there for the full 10 frames.

The point of this pattern is to test something unusual, so it makes sense to show these two patterns for a longer time.

Regards,

Hans

Quoted 61 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 286

Quoted 13 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +13 -0
+		/* 16 pressure points */
+		if (test_pat_idx != 5)
+			break;
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(tch_buf, ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+}

Regards,

Hans

Quoted 42 lines
drivers/media/platform/vivid/vivid-touch-cap.h new file +35 -0
new file mode 100644
index 000000000000..6e83ca919f07
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
#4 lore raw
Quoted 45 lines · Hans Verkuil
Quoted 38 lines · Hans Verkuil

Hi Vandana,

Quoted 2 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating, single tap, double tap, triple

No , after 'simulating'.

Quoted 2 lines

tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and an invalid pattern of

Drop the 'invalid': it is not invalid, just very, very unusual.

Quoted 2 lines

simulating 16 different simultaneous touch points. All of these patterns are based on behavior of rmi_f54 driver.

The patterns aren't from that driver, but the generated values are.

Quoted 5 lines

---
Changes since V6:
simplified touch pattern generation.

Quoted 14 lines
---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 +++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 +++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 286 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  35 +++
 8 files changed, 700 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h
Quoted 2 lines

<snip>

I couldn't resist: here is a vivid_tch_buf_set that fills in the neighboring pixels as well for more realism:

Quoted 7 lines

static void vivid_tch_buf_set(__s16 *tch_buf, struct v4l2_pix_format *f, int index)

{
        unsigned int x = index % f->width;
        unsigned int y = index / f->width;
        unsigned int offset = VIVID_MIN_PRESSURE;

        tch_buf[index] = offset + get_random_int() % 40;

40 should be a define as well.

It makes sense to make a get_random_pressure static inline instead of calling get_random_int() % 40 here.

Quoted 131 lines
        offset /= 2;
        if (x)
                tch_buf[index - 1] = offset + get_random_int() % 40;
        if (x < f->width - 1)
                tch_buf[index + 1] = offset + get_random_int() % 40;
        if (y)
                tch_buf[index - f->width] = offset + get_random_int() % 40;
        if (y < f->height - 1)
                tch_buf[index + f->width] = offset + get_random_int() % 40;
        offset /= 2;
        if (x && y)
                tch_buf[index - 1 - f->width] = offset + get_random_int() % 40;
        if (x < f->width - 1 && y)
                tch_buf[index + 1 - f->width] = offset + get_random_int() % 40;
        if (x && y < f->height - 1)
                tch_buf[index - 1 + f->width] = offset + get_random_int() % 40;
        if (x < f->width - 1 && y < f->height - 1)
                tch_buf[index + 1 + f->width] = offset + get_random_int() % 40;
}

The result now looks very close to the real hardware.

Quoted 78 lines
Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int index = 0, x, y, xstart, ystart;
+	unsigned int test_pattern, test_pat_idx, rand;

drivers/media/platform/vivid/vivid-touch-cap.c line 223

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / 15) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % 15;
+
+	vivid_fill_buff_noise(tch_buf, size);
+
+	if (test_pat_idx >= 10)

The values 10 and 15 should be defines. That makes it easy to change later.

I think it would be better to change 15 to 16 and 10 to 12: 16 helps because in the corner case where the sequence counter will wrap around you will get a smooth transition. And 12 makes each sequence just a little bit longer, which makes it easier to see.

Quoted 12 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +12 -0
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:

drivers/media/platform/vivid/vivid-touch-cap.c line 245

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+		if (test_pat_idx == 3 || test_pat_idx == 6)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)
+			vivid_tch_buf_set(tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(tch_buf,
+				  (rand % f->height) * f->width + test_pat_idx * (f->width / 10));

Line too long (same in similar cases below). It's easiest to break it off after the + like this:

		vivid_tch_buf_set(tch_buf,
				  (rand % f->height) * f->width +
				  test_pat_idx * (f->width / 10));

drivers/media/platform/vivid/vivid-touch-cap.c line 249

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;

You need extra variables for the offset from the center:

		offset_x = ((9 - test_pat_idx) * x) / 10;   (10 should be a define as discussed above)
		offset_y = ((9 - test_pat_idx) * y) / 10;

drivers/media/platform/vivid/vivid-touch-cap.c line 250

Quoted 1 line
drivers/media/platform/vivid/vivid-touch-cap.c new file +1 -0
+		if (x + test_pat_idx < f->width && y + test_pat_idx < f->height) {

Then this if can be dropped here as well.

drivers/media/platform/vivid/vivid-touch-cap.c

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+			vivid_tch_buf_set(tch_buf, (x - test_pat_idx) + f->width * (y - test_pat_idx));
+			vivid_tch_buf_set(tch_buf, (x + test_pat_idx) + f->width * (y + test_pat_idx));
+		}
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		index = min(x, y) - test_pat_idx - 1;> +		if (x + index >= f->width / 2 && y + index >= f->height / 2) {

Same here.

Quoted 5 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 264

Quoted 5 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +5 -0
+			vivid_tch_buf_set(tch_buf, (x - index) + f->width * (y - index));
+			vivid_tch_buf_set(tch_buf, (x + index) + f->width * (y + index));
+		}
+		break;
+	case PALM_PRESS:

For this palm press test and...

Quoted 4 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 1 line
drivers/media/platform/vivid/vivid-touch-cap.c new file +1 -0
+		xstart = f->width - f->width / 4;

Just set this to 0, so the palm covers the bottom quarter.

Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 273

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+		ystart = f->height - f->height / 4;
+		if (test_pat_idx != 5)
+			break;
+		for (x = xstart; x < f->width; x++)
+			for (y = ystart; y < f->height; y++)
+				vivid_tch_buf_set(tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:

... the multiple press test you can drop the 'if (test_pat_idx != 5)' bit:
i.e. this pattern should be there for the full 10 frames.

The point of this pattern is to test something unusual, so it makes sense to show these two patterns for a longer time.

Regards,

Hans

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+		/* 16 pressure points */
+		if (test_pat_idx != 5)
+			break;
+		for (y = 0; y < 4; y++) {
Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 285

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(tch_buf, ystart * f->width + xstart);
+			}
+		}
+		break;
+	}

I realized that there is a final step that needs to be done here: the buffer is supposed to be in little endian format, so if vivid is compiled on a big endian host, then the buffer contents needs to be converted.

So:

#ifdef __BIG_ENDIAN__
		for all pixels:
			tch_buf[i] = (__force s16)__cpu_to_le16((u16)tch_buf[i]);

#endif

Regards,

Hans

Quoted 50 lines
Quoted 49 lines
Quoted 1 line

+}

Regards,

Hans

Quoted 42 lines
drivers/media/platform/vivid/vivid-touch-cap.h new file +35 -0
new file mode 100644
index 000000000000..6e83ca919f07
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
author
#5 lore raw

PATCH v8 1/1 vivid: Add touch support

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 320 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 737 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h
drivers/media/platform/vivid/Makefile +2 -1
index e8a50c506dc9..b12ad0152a3e 100644
@@ -3,7 +3,8 @@ vivid-objs := vivid-core.o vivid-ctrls.o vivid-vid-common.o vivid-vbi-gen.o \
 		vivid-vid-cap.o vivid-vid-out.o vivid-kthread-cap.o vivid-kthread-out.o \
 		vivid-radio-rx.o vivid-radio-tx.o vivid-radio-common.o \
 		vivid-rds-gen.o vivid-sdr-cap.o vivid-vbi-cap.o vivid-vbi-out.o \
-		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o
+		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o \
+		vivid-kthread-touch.o vivid-touch-cap.o
 ifeq ($(CONFIG_VIDEO_VIVID_CEC),y)
   vivid-objs += vivid-cec.o
 endif
drivers/media/platform/vivid/vivid-core.c +152 -12

292 lines not on this page · raw message

drivers/media/platform/vivid/vivid-core.h +20 -0
index 59192b67231c..99e69b8f770f 100644
@@ -133,6 +133,7 @@ struct vivid_dev {
 	struct media_pad		sdr_cap_pad;
 	struct media_pad		meta_cap_pad;
 	struct media_pad		meta_out_pad;
+	struct media_pad		touch_cap_pad;
 #endif
 	struct v4l2_ctrl_handler	ctrl_hdl_user_gen;
 	struct v4l2_ctrl_handler	ctrl_hdl_user_vid;
@@ -159,6 +160,8 @@ struct vivid_dev {
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_cap;
 	struct video_device		meta_out_dev;
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_out;
+	struct video_device		touch_cap_dev;
+	struct v4l2_ctrl_handler	ctrl_hdl_touch_cap;
 
 	spinlock_t			slock;
 	struct mutex			mutex;
@@ -173,6 +176,7 @@ struct vivid_dev {
 	u32				radio_tx_caps;
 	u32				meta_cap_caps;
 	u32				meta_out_caps;
+	u32				touch_cap_caps;
 
 	/* supported features */
 	bool				multiplanar;
@@ -201,6 +205,7 @@ struct vivid_dev {
 	bool				has_meta_cap;
 	bool				has_meta_out;
 	bool				has_tv_tuner;
+	bool				has_touch_cap;
 
 	bool				can_loop_video;
 
@@ -404,6 +409,8 @@ struct vivid_dev {
 	struct list_head		vbi_cap_active;
 	struct vb2_queue		vb_meta_cap_q;
 	struct list_head		meta_cap_active;
+	struct vb2_queue		vb_touch_cap_q;
+	struct list_head		touch_cap_active;
 
 	/* thread for generating video capture stream */
 	struct task_struct		*kthread_vid_cap;
@@ -425,6 +432,19 @@ struct vivid_dev {
 	u32				meta_cap_seq_count;
 	bool				meta_cap_streaming;
 
+	/* Touch capture */
+	struct task_struct		*kthread_touch_cap;
+	unsigned long			jiffies_touch_cap;
+	u64				touch_cap_stream_start;
+	u32				touch_cap_seq_offset;
+	bool				touch_cap_seq_resync;
+	u32				touch_cap_seq_start;
+	u32				touch_cap_seq_count;
+	bool				touch_cap_streaming;
+	struct v4l2_fract		timeperframe_tch_cap;
+	struct v4l2_pix_format		tch_format;
+	int				tch_pat_random;
+
 	/* video output */
 	const struct vivid_fmt		*fmt_out;
 	struct v4l2_fract		timeperframe_vid_out;
drivers/media/platform/vivid/vivid-ctrls.c +11 -0
index 68e8124c7973..334130568dcb 100644
@@ -1508,6 +1508,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	struct v4l2_ctrl_handler *hdl_sdr_cap = &dev->ctrl_hdl_sdr_cap;
 	struct v4l2_ctrl_handler *hdl_meta_cap = &dev->ctrl_hdl_meta_cap;
 	struct v4l2_ctrl_handler *hdl_meta_out = &dev->ctrl_hdl_meta_out;
+	struct v4l2_ctrl_handler *hdl_tch_cap = &dev->ctrl_hdl_touch_cap;
 
 	struct v4l2_ctrl_config vivid_ctrl_dv_timings = {
 		.ops = &vivid_vid_cap_ctrl_ops,
@@ -1551,6 +1552,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	v4l2_ctrl_new_custom(hdl_meta_cap, &vivid_ctrl_class, NULL);
 	v4l2_ctrl_handler_init(hdl_meta_out, 2);
 	v4l2_ctrl_new_custom(hdl_meta_out, &vivid_ctrl_class, NULL);
+	v4l2_ctrl_handler_init(hdl_tch_cap, 2);
+	v4l2_ctrl_new_custom(hdl_tch_cap, &vivid_ctrl_class, NULL);
 
 	/* User Controls */
 	dev->volume = v4l2_ctrl_new_std(hdl_user_aud, NULL,
@@ -1904,6 +1907,13 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 			return hdl_meta_out->error;
 		dev->meta_out_dev.ctrl_handler = hdl_meta_out;
 	}
+	if (dev->has_touch_cap) {
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_user_gen, NULL, false);
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_streaming, NULL, false);
+		if (hdl_tch_cap->error)
+			return hdl_tch_cap->error;
+		dev->touch_cap_dev.ctrl_handler = hdl_tch_cap;
+	}
 	return 0;
 }
 
@@ -1925,4 +1935,5 @@ void vivid_free_controls(struct vivid_dev *dev)
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_fb);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_cap);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_out);
+	v4l2_ctrl_handler_free(&dev->ctrl_hdl_touch_cap);
 }
drivers/media/platform/vivid/vivid-kthread-touch.c new file +181 -0

181 lines not on this page · raw message

drivers/media/platform/vivid/vivid-kthread-touch.h new file +13 -0
new file mode 100644
index 000000000000..ecf79b46209e
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-kthread-cap.h - video/vbi capture thread support functions.
+ *
+ */
+
+#ifndef _VIVID_KTHREAD_CAP_H_
+#define _VIVID_KTHREAD_CAP_H_
+
+int vivid_start_generating_touch_cap(struct vivid_dev *dev);
+void vivid_stop_generating_touch_cap(struct vivid_dev *dev);
+
+#endif
drivers/media/platform/vivid/vivid-touch-cap.c new file +320 -0

320 lines not on this page · raw message

drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
Signature · 1 line
2.17.1
#6 lore raw

Hi Vandana,

This looks really good. I have a few very small comments (I'd have changed it myself, but we're in the code freeze period so there is time for a v9):

Quoted 23 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 320 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 737 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h

<snip>

Quoted 15 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +15 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int x, y, xstart, ystart, offset_x, offset_y;
+	unsigned int test_pattern, test_pat_idx, rand;
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT;
+
+	vivid_fill_buff_noise(tch_buf, size);
+

drivers/media/platform/vivid/vivid-touch-cap.c line 261

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+	if (test_pat_idx >= TCH_PATTERN_COUNT)
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)

Let's change 5 to TCH_PATTERN_COUNT / 2

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6)

And 3 and 6 to:

TCH_PATTERN_COUNT / 3 and 2 * TCH_PATTERN_COUNT / 3

drivers/media/platform/vivid/vivid-touch-cap.c line 269

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)

TCH_PATTERN_COUNT / 4, 2 * TCH_PATTERN_COUNT / 4, 3 * TCH_PATTERN_COUNT / 4

drivers/media/platform/vivid/vivid-touch-cap.c line 275

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(f, tch_buf,
+				  (rand % f->height) * f->width +
+				  test_pat_idx * (f->width / 10));

10 -> TCH_PATTERN_COUNT

Regards,

Hans

Quoted 90 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +45 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) /
+				TCH_PATTERN_COUNT;
+		offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) /
+				TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = (test_pat_idx * x) / TCH_PATTERN_COUNT;
+		offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case PALM_PRESS:
+		for (x = 0; x < f->width; x++)
+			for (y = f->height / 2; y < f->height; y++)
+				vivid_tch_buf_set(f, tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:
+		/* 16 pressure points */
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(f, tch_buf,
+						  ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+#ifdef __BIG_ENDIAN__
+	for (x = 0; x < size; x++)
+		tch_buf[x] = (__force s16)__cpu_to_le16((u16)tch_buf[x]);
+#endif
+}
drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
#7 lore raw
Quoted 108 lines · Hans Verkuil

Hi Vandana,

This looks really good. I have a few very small comments (I'd have changed it myself, but we're in the code freeze period so there is time for a v9):

Quoted 23 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 320 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 737 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h

<snip>

Quoted 15 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +15 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int x, y, xstart, ystart, offset_x, offset_y;
+	unsigned int test_pattern, test_pat_idx, rand;
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT;
+
+	vivid_fill_buff_noise(tch_buf, size);
+

drivers/media/platform/vivid/vivid-touch-cap.c line 261

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+	if (test_pat_idx >= TCH_PATTERN_COUNT)
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)

Let's change 5 to TCH_PATTERN_COUNT / 2

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6)

And 3 and 6 to:

TCH_PATTERN_COUNT / 3 and 2 * TCH_PATTERN_COUNT / 3

drivers/media/platform/vivid/vivid-touch-cap.c line 269

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)

TCH_PATTERN_COUNT / 4, 2 * TCH_PATTERN_COUNT / 4, 3 * TCH_PATTERN_COUNT / 4

drivers/media/platform/vivid/vivid-touch-cap.c line 275

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(f, tch_buf,
+				  (rand % f->height) * f->width +
+				  test_pat_idx * (f->width / 10));

10 -> TCH_PATTERN_COUNT

Regards,

Hans

Quoted 19 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +19 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) /
+				TCH_PATTERN_COUNT;
+		offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) /
+				TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = (test_pat_idx * x) / TCH_PATTERN_COUNT;
+		offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 302

Quoted 8 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +8 -0
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case PALM_PRESS:
+		for (x = 0; x < f->width; x++)
+			for (y = f->height / 2; y < f->height; y++)
+				vivid_tch_buf_set(f, tch_buf, x + f->width * y);

Ah, this is wrong. For this pattern you can't use vivid_tch_buf_set(). Instead each pixel should be set explicitly to VIVID_MIN_PRESSURE + get_random_pressure();

The vivid_tch_buf_set overwrites neighboring pixels, so that doesn't work here.

Regards,

Hans

Quoted 64 lines
Quoted 63 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +18 -0
+		break;
+	case MULTIPLE_PRESS:
+		/* 16 pressure points */
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(f, tch_buf,
+						  ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+#ifdef __BIG_ENDIAN__
+	for (x = 0; x < size; x++)
+		tch_buf[x] = (__force s16)__cpu_to_le16((u16)tch_buf[x]);
+#endif
+}
drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
#8 lore raw
In reply to Hans Verkuil
Quoted 76 lines · Hans Verkuil

Hi Vandana,

This looks really good. I have a few very small comments (I'd have changed it myself, but we're in the code freeze period so there is time for a v9):

Quoted 23 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 320 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 737 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h

<snip>

Quoted 15 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +15 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int x, y, xstart, ystart, offset_x, offset_y;
+	unsigned int test_pattern, test_pat_idx, rand;
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT;
+
+	vivid_fill_buff_noise(tch_buf, size);
+

drivers/media/platform/vivid/vivid-touch-cap.c line 261

Quoted 10 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +10 -0
+	if (test_pat_idx >= TCH_PATTERN_COUNT)
+		return;
+
+	if (test_pat_idx == 0)
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)

Let's change 5 to TCH_PATTERN_COUNT / 2

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6)

And 3 and 6 to:

TCH_PATTERN_COUNT / 3 and 2 * TCH_PATTERN_COUNT / 3

drivers/media/platform/vivid/vivid-touch-cap.c line 269

Quoted 4 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)

TCH_PATTERN_COUNT / 4, 2 * TCH_PATTERN_COUNT / 4, 3 * TCH_PATTERN_COUNT / 4

Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 275

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(f, tch_buf,
+				  (rand % f->height) * f->width +
+				  test_pat_idx * (f->width / 10));

10 -> TCH_PATTERN_COUNT

Actually, this should be (test_pat_idx * f->width) / TCH_PATTERN_COUNT, otherwise you get bad rounding errors.

Regards,

Hans

Quoted 96 lines

Regards,

Hans

Quoted 90 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +45 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) /
+				TCH_PATTERN_COUNT;
+		offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) /
+				TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = (test_pat_idx * x) / TCH_PATTERN_COUNT;
+		offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case PALM_PRESS:
+		for (x = 0; x < f->width; x++)
+			for (y = f->height / 2; y < f->height; y++)
+				vivid_tch_buf_set(f, tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:
+		/* 16 pressure points */
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(f, tch_buf,
+						  ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+#ifdef __BIG_ENDIAN__
+	for (x = 0; x < size; x++)
+		tch_buf[x] = (__force s16)__cpu_to_le16((u16)tch_buf[x]);
+#endif
+}
drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
#9 lore raw
In reply to Hans Verkuil
Quoted 51 lines · Hans Verkuil

Hi Vandana,

This looks really good. I have a few very small comments (I'd have changed it myself, but we're in the code freeze period so there is time for a v9):

Quoted 23 lines · Vandana BN

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 320 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 737 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h

<snip>

Quoted 19 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +19 -0
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf)
+{
+	struct v4l2_pix_format *f = &dev->tch_format;
+	int size = f->width * f->height;
+	int x, y, xstart, ystart, offset_x, offset_y;
+	unsigned int test_pattern, test_pat_idx, rand;
+
+	__s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
+
+	buf->vb.sequence = dev->touch_cap_seq_count;
+	test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX;
+	test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT;
+
+	vivid_fill_buff_noise(tch_buf, size);
+
+	if (test_pat_idx >= TCH_PATTERN_COUNT)
+		return;
+
+	if (test_pat_idx == 0)
Quoted 8 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 261

Quoted 6 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+		dev->tch_pat_random = get_random_int();
+	rand = dev->tch_pat_random;
+
+	switch (test_pattern) {
+	case SINGLE_TAP:
+		if (test_pat_idx == 5)

Let's change 5 to TCH_PATTERN_COUNT / 2

I changed my mind on this. Just check for test_pat_idx == 2

Quoted 9 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 265

Quoted 5 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case DOUBLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6)

And 3 and 6 to:

TCH_PATTERN_COUNT / 3 and 2 * TCH_PATTERN_COUNT / 3

And here change it to == 2 and == 4

Quoted 7 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 269

Quoted 5 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +4 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case TRIPLE_TAP:
+		if (test_pat_idx == 3 || test_pat_idx == 6 || test_pat_idx == 9)

TCH_PATTERN_COUNT / 4, 2 * TCH_PATTERN_COUNT / 4, 3 * TCH_PATTERN_COUNT / 4

And this to == 2, == 4 and == 6.

Testing with my laptop showed that for these double and triple taps there is one empty frame in between the taps. So that is realistic.

Regards,

Hans

Quoted 105 lines

drivers/media/platform/vivid/vivid-touch-cap.c line 275

Quoted 7 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +6 -0
+			vivid_tch_buf_set(f, tch_buf, rand % size);
+		break;
+	case MOVE_LEFT_TO_RIGHT:
+		vivid_tch_buf_set(f, tch_buf,
+				  (rand % f->height) * f->width +
+				  test_pat_idx * (f->width / 10));

10 -> TCH_PATTERN_COUNT

Regards,

Hans

Quoted 90 lines
drivers/media/platform/vivid/vivid-touch-cap.c new file +45 -0
+		break;
+	case ZOOM_IN:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) /
+				TCH_PATTERN_COUNT;
+		offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) /
+				TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case ZOOM_OUT:
+		x = f->width / 2;
+		y = f->height / 2;
+		offset_x = (test_pat_idx * x) / TCH_PATTERN_COUNT;
+		offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT;
+		vivid_tch_buf_set(f, tch_buf,
+				  (x - offset_x) + f->width * (y - offset_y));
+		vivid_tch_buf_set(f, tch_buf,
+				  (x + offset_x) + f->width * (y + offset_y));
+		break;
+	case PALM_PRESS:
+		for (x = 0; x < f->width; x++)
+			for (y = f->height / 2; y < f->height; y++)
+				vivid_tch_buf_set(f, tch_buf, x + f->width * y);
+		break;
+	case MULTIPLE_PRESS:
+		/* 16 pressure points */
+		for (y = 0; y < 4; y++) {
+			for (x = 0; x < 4; x++) {
+				ystart = (y * f->height) / 4 + f->height / 8;
+				xstart = (x * f->width) / 4 + f->width / 8;
+				vivid_tch_buf_set(f, tch_buf,
+						  ystart * f->width + xstart);
+			}
+		}
+		break;
+	}
+#ifdef __BIG_ENDIAN__
+	for (x = 0; x < size; x++)
+		tch_buf[x] = (__force s16)__cpu_to_le16((u16)tch_buf[x]);
+#endif
+}
drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
author
#10 lore raw

PATCH v9 1/1 vivid: Add touch support

Support to emulate touch devices in vivid driver.
It generates touch patterns simulating single tap, double tap, triple tap, move from left to right, zoom in, zoom out, palm press simulating large area being pressed on screen, and simulating 16 different simultaneous touch points.The values generated are based on behavior of the rmi_f54 driver.

---
 drivers/media/platform/vivid/Makefile         |   3 +-
 drivers/media/platform/vivid/vivid-core.c     | 164 ++++++++-
 drivers/media/platform/vivid/vivid-core.h     |  20 ++
 drivers/media/platform/vivid/vivid-ctrls.c    |  11 +
 .../platform/vivid/vivid-kthread-touch.c      | 181 ++++++++++
 .../platform/vivid/vivid-kthread-touch.h      |  13 +
 .../media/platform/vivid/vivid-touch-cap.c    | 322 ++++++++++++++++++
 .../media/platform/vivid/vivid-touch-cap.h    |  38 +++
 8 files changed, 739 insertions(+), 13 deletions(-)
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.c
 create mode 100644 drivers/media/platform/vivid/vivid-kthread-touch.h
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.c
 create mode 100644 drivers/media/platform/vivid/vivid-touch-cap.h
drivers/media/platform/vivid/Makefile +2 -1
index e8a50c506dc9..b12ad0152a3e 100644
@@ -3,7 +3,8 @@ vivid-objs := vivid-core.o vivid-ctrls.o vivid-vid-common.o vivid-vbi-gen.o \
 		vivid-vid-cap.o vivid-vid-out.o vivid-kthread-cap.o vivid-kthread-out.o \
 		vivid-radio-rx.o vivid-radio-tx.o vivid-radio-common.o \
 		vivid-rds-gen.o vivid-sdr-cap.o vivid-vbi-cap.o vivid-vbi-out.o \
-		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o
+		vivid-osd.o vivid-meta-cap.o vivid-meta-out.o \
+		vivid-kthread-touch.o vivid-touch-cap.o
 ifeq ($(CONFIG_VIDEO_VIVID_CEC),y)
   vivid-objs += vivid-cec.o
 endif
drivers/media/platform/vivid/vivid-core.c +152 -12

292 lines not on this page · raw message

drivers/media/platform/vivid/vivid-core.h +20 -0
index 59192b67231c..99e69b8f770f 100644
@@ -133,6 +133,7 @@ struct vivid_dev {
 	struct media_pad		sdr_cap_pad;
 	struct media_pad		meta_cap_pad;
 	struct media_pad		meta_out_pad;
+	struct media_pad		touch_cap_pad;
 #endif
 	struct v4l2_ctrl_handler	ctrl_hdl_user_gen;
 	struct v4l2_ctrl_handler	ctrl_hdl_user_vid;
@@ -159,6 +160,8 @@ struct vivid_dev {
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_cap;
 	struct video_device		meta_out_dev;
 	struct v4l2_ctrl_handler	ctrl_hdl_meta_out;
+	struct video_device		touch_cap_dev;
+	struct v4l2_ctrl_handler	ctrl_hdl_touch_cap;
 
 	spinlock_t			slock;
 	struct mutex			mutex;
@@ -173,6 +176,7 @@ struct vivid_dev {
 	u32				radio_tx_caps;
 	u32				meta_cap_caps;
 	u32				meta_out_caps;
+	u32				touch_cap_caps;
 
 	/* supported features */
 	bool				multiplanar;
@@ -201,6 +205,7 @@ struct vivid_dev {
 	bool				has_meta_cap;
 	bool				has_meta_out;
 	bool				has_tv_tuner;
+	bool				has_touch_cap;
 
 	bool				can_loop_video;
 
@@ -404,6 +409,8 @@ struct vivid_dev {
 	struct list_head		vbi_cap_active;
 	struct vb2_queue		vb_meta_cap_q;
 	struct list_head		meta_cap_active;
+	struct vb2_queue		vb_touch_cap_q;
+	struct list_head		touch_cap_active;
 
 	/* thread for generating video capture stream */
 	struct task_struct		*kthread_vid_cap;
@@ -425,6 +432,19 @@ struct vivid_dev {
 	u32				meta_cap_seq_count;
 	bool				meta_cap_streaming;
 
+	/* Touch capture */
+	struct task_struct		*kthread_touch_cap;
+	unsigned long			jiffies_touch_cap;
+	u64				touch_cap_stream_start;
+	u32				touch_cap_seq_offset;
+	bool				touch_cap_seq_resync;
+	u32				touch_cap_seq_start;
+	u32				touch_cap_seq_count;
+	bool				touch_cap_streaming;
+	struct v4l2_fract		timeperframe_tch_cap;
+	struct v4l2_pix_format		tch_format;
+	int				tch_pat_random;
+
 	/* video output */
 	const struct vivid_fmt		*fmt_out;
 	struct v4l2_fract		timeperframe_vid_out;
drivers/media/platform/vivid/vivid-ctrls.c +11 -0
index 68e8124c7973..334130568dcb 100644
@@ -1508,6 +1508,7 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	struct v4l2_ctrl_handler *hdl_sdr_cap = &dev->ctrl_hdl_sdr_cap;
 	struct v4l2_ctrl_handler *hdl_meta_cap = &dev->ctrl_hdl_meta_cap;
 	struct v4l2_ctrl_handler *hdl_meta_out = &dev->ctrl_hdl_meta_out;
+	struct v4l2_ctrl_handler *hdl_tch_cap = &dev->ctrl_hdl_touch_cap;
 
 	struct v4l2_ctrl_config vivid_ctrl_dv_timings = {
 		.ops = &vivid_vid_cap_ctrl_ops,
@@ -1551,6 +1552,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 	v4l2_ctrl_new_custom(hdl_meta_cap, &vivid_ctrl_class, NULL);
 	v4l2_ctrl_handler_init(hdl_meta_out, 2);
 	v4l2_ctrl_new_custom(hdl_meta_out, &vivid_ctrl_class, NULL);
+	v4l2_ctrl_handler_init(hdl_tch_cap, 2);
+	v4l2_ctrl_new_custom(hdl_tch_cap, &vivid_ctrl_class, NULL);
 
 	/* User Controls */
 	dev->volume = v4l2_ctrl_new_std(hdl_user_aud, NULL,
@@ -1904,6 +1907,13 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap,
 			return hdl_meta_out->error;
 		dev->meta_out_dev.ctrl_handler = hdl_meta_out;
 	}
+	if (dev->has_touch_cap) {
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_user_gen, NULL, false);
+		v4l2_ctrl_add_handler(hdl_tch_cap, hdl_streaming, NULL, false);
+		if (hdl_tch_cap->error)
+			return hdl_tch_cap->error;
+		dev->touch_cap_dev.ctrl_handler = hdl_tch_cap;
+	}
 	return 0;
 }
 
@@ -1925,4 +1935,5 @@ void vivid_free_controls(struct vivid_dev *dev)
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_fb);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_cap);
 	v4l2_ctrl_handler_free(&dev->ctrl_hdl_meta_out);
+	v4l2_ctrl_handler_free(&dev->ctrl_hdl_touch_cap);
 }
drivers/media/platform/vivid/vivid-kthread-touch.c new file +181 -0

181 lines not on this page · raw message

drivers/media/platform/vivid/vivid-kthread-touch.h new file +13 -0
new file mode 100644
index 000000000000..ecf79b46209e
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-kthread-cap.h - video/vbi capture thread support functions.
+ *
+ */
+
+#ifndef _VIVID_KTHREAD_CAP_H_
+#define _VIVID_KTHREAD_CAP_H_
+
+int vivid_start_generating_touch_cap(struct vivid_dev *dev);
+void vivid_stop_generating_touch_cap(struct vivid_dev *dev);
+
+#endif
drivers/media/platform/vivid/vivid-touch-cap.c new file +322 -0

322 lines not on this page · raw message

drivers/media/platform/vivid/vivid-touch-cap.h new file +38 -0
new file mode 100644
index 000000000000..761050b652eb
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * vivid-touch-cap.h - touch support functions.
+ */
+#ifndef _VIVID_TOUCH_CAP_H_
+#define _VIVID_TOUCH_CAP_H_
+
+#define VIVID_TCH_HEIGHT	12
+#define VIVID_TCH_WIDTH		21
+#define VIVID_MIN_PRESSURE	180
+#define VIVID_PRESSURE_LIMIT	40
+#define TCH_SEQ_COUNT		16
+#define TCH_PATTERN_COUNT	12
+
+enum vivid_tch_test {
+	SINGLE_TAP,
+	DOUBLE_TAP,
+	TRIPLE_TAP,
+	MOVE_LEFT_TO_RIGHT,
+	ZOOM_IN,
+	ZOOM_OUT,
+	PALM_PRESS,
+	MULTIPLE_PRESS,
+	TEST_CASE_MAX
+};
+
+extern const struct vb2_ops vivid_touch_cap_qops;
+
+int vivid_enum_fmt_tch(struct file *file, void  *priv, struct v4l2_fmtdesc *f);
+int vivid_g_fmt_tch(struct file *file, void *priv, struct v4l2_format *f);
+int vivid_enum_input_tch(struct file *file, void *priv, struct v4l2_input *inp);
+int vivid_g_input_tch(struct file *file, void *priv, unsigned int *i);
+int vivid_s_input_tch(struct file *file, void *priv, unsigned int i);
+void vivid_fillbuff_tch(struct vivid_dev *dev, struct vivid_buffer *buf);
+int vivid_set_touch(struct vivid_dev *dev, unsigned int i);
+int vivid_g_parm_tch(struct file *file, void *priv,
+		     struct v4l2_streamparm *parm);
+#endif
Signature · 1 line
2.17.1