Lines Matching +full:offset +full:- +full:y

1 // SPDX-License-Identifier: GPL-2.0-only
3 * vivid-touch-cap.c - touch support functions.
6 #include "vivid-core.h"
7 #include "vivid-kthread-touch.h"
8 #include "vivid-vid-common.h"
9 #include "vivid-touch-cap.h"
16 struct v4l2_pix_format *f = &dev->tch_format; in touch_cap_queue_setup()
17 unsigned int size = f->sizeimage; in touch_cap_queue_setup()
21 return -EINVAL; in touch_cap_queue_setup()
22 return sizes[0] < size ? -EINVAL : 0; in touch_cap_queue_setup()
32 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_prepare()
33 struct v4l2_pix_format *f = &dev->tch_format; in touch_cap_buf_prepare()
34 unsigned int size = f->sizeimage; in touch_cap_buf_prepare()
36 if (dev->buf_prepare_error) { in touch_cap_buf_prepare()
41 dev->buf_prepare_error = false; in touch_cap_buf_prepare()
42 return -EINVAL; in touch_cap_buf_prepare()
47 return -EINVAL; in touch_cap_buf_prepare()
57 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_queue()
60 vbuf->field = V4L2_FIELD_NONE; in touch_cap_buf_queue()
61 spin_lock(&dev->slock); in touch_cap_buf_queue()
62 list_add_tail(&buf->list, &dev->touch_cap_active); in touch_cap_buf_queue()
63 spin_unlock(&dev->slock); in touch_cap_buf_queue()
71 dev->touch_cap_seq_count = 0; in touch_cap_start_streaming()
72 if (dev->start_streaming_error) { in touch_cap_start_streaming()
73 dev->start_streaming_error = false; in touch_cap_start_streaming()
74 err = -EINVAL; in touch_cap_start_streaming()
82 &dev->touch_cap_active, list) { in touch_cap_start_streaming()
83 list_del(&buf->list); in touch_cap_start_streaming()
84 vb2_buffer_done(&buf->vb.vb2_buf, in touch_cap_start_streaming()
101 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_request_complete()
103 v4l2_ctrl_request_complete(vb->req_obj.req, &dev->ctrl_hdl_touch_cap); in touch_cap_buf_request_complete()
119 if (f->index) in vivid_enum_fmt_tch()
120 return -EINVAL; in vivid_enum_fmt_tch()
122 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in vivid_enum_fmt_tch()
130 if (dev->multiplanar) in vivid_g_fmt_tch()
131 return -ENOTTY; in vivid_g_fmt_tch()
132 f->fmt.pix = dev->tch_format; in vivid_g_fmt_tch()
141 if (!dev->multiplanar) in vivid_g_fmt_tch_mplane()
142 return -ENOTTY; in vivid_g_fmt_tch_mplane()
144 sp_fmt.fmt.pix = dev->tch_format; in vivid_g_fmt_tch_mplane()
154 if (parm->type != (dev->multiplanar ? in vivid_g_parm_tch()
157 return -EINVAL; in vivid_g_parm_tch()
159 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vivid_g_parm_tch()
160 parm->parm.capture.timeperframe = dev->timeperframe_tch_cap; in vivid_g_parm_tch()
161 parm->parm.capture.readbuffers = 1; in vivid_g_parm_tch()
167 if (inp->index) in vivid_enum_input_tch()
168 return -EINVAL; in vivid_enum_input_tch()
170 inp->type = V4L2_INPUT_TYPE_TOUCH; in vivid_enum_input_tch()
171 strscpy(inp->name, "Vivid Touch", sizeof(inp->name)); in vivid_enum_input_tch()
172 inp->capabilities = 0; in vivid_enum_input_tch()
184 struct v4l2_pix_format *f = &dev->tch_format; in vivid_set_touch()
187 return -EINVAL; in vivid_set_touch()
189 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in vivid_set_touch()
190 f->width = VIVID_TCH_WIDTH; in vivid_set_touch()
191 f->height = VIVID_TCH_HEIGHT; in vivid_set_touch()
192 f->field = V4L2_FIELD_NONE; in vivid_set_touch()
193 f->colorspace = V4L2_COLORSPACE_RAW; in vivid_set_touch()
194 f->bytesperline = f->width * sizeof(s16); in vivid_set_touch()
195 f->sizeimage = f->width * f->height * sizeof(s16); in vivid_set_touch()
208 /* Fill 10% of the values within range -3 and 3, zero the others */ in vivid_fill_buff_noise()
215 tch_buf[i] = (rand / 10) % 7 - 3; in vivid_fill_buff_noise()
228 unsigned int x = index % f->width; in vivid_tch_buf_set()
229 unsigned int y = index / f->width; in vivid_tch_buf_set() local
230 unsigned int offset = VIVID_MIN_PRESSURE; in vivid_tch_buf_set() local
232 tch_buf[index] = offset + get_random_pressure(); in vivid_tch_buf_set()
233 offset /= 2; in vivid_tch_buf_set()
235 tch_buf[index - 1] = offset + get_random_pressure(); in vivid_tch_buf_set()
236 if (x < f->width - 1) in vivid_tch_buf_set()
237 tch_buf[index + 1] = offset + get_random_pressure(); in vivid_tch_buf_set()
238 if (y) in vivid_tch_buf_set()
239 tch_buf[index - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
240 if (y < f->height - 1) in vivid_tch_buf_set()
241 tch_buf[index + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
242 offset /= 2; in vivid_tch_buf_set()
243 if (x && y) in vivid_tch_buf_set()
244 tch_buf[index - 1 - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
245 if (x < f->width - 1 && y) in vivid_tch_buf_set()
246 tch_buf[index + 1 - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
247 if (x && y < f->height - 1) in vivid_tch_buf_set()
248 tch_buf[index - 1 + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
249 if (x < f->width - 1 && y < f->height - 1) in vivid_tch_buf_set()
250 tch_buf[index + 1 + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
255 struct v4l2_pix_format *f = &dev->tch_format; in vivid_fillbuff_tch()
256 int size = f->width * f->height; in vivid_fillbuff_tch()
257 int x, y, xstart, ystart, offset_x, offset_y; in vivid_fillbuff_tch() local
260 __s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in vivid_fillbuff_tch()
262 buf->vb.sequence = dev->touch_cap_with_seq_wrap_count; in vivid_fillbuff_tch()
263 test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX; in vivid_fillbuff_tch()
264 test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT; in vivid_fillbuff_tch()
272 dev->tch_pat_random = get_random_u32(); in vivid_fillbuff_tch()
273 rand = dev->tch_pat_random; in vivid_fillbuff_tch()
290 (rand % f->height) * f->width + in vivid_fillbuff_tch()
292 (f->width / TCH_PATTERN_COUNT)); in vivid_fillbuff_tch()
295 x = f->width / 2; in vivid_fillbuff_tch()
296 y = f->height / 2; in vivid_fillbuff_tch()
297 offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) / in vivid_fillbuff_tch()
299 offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) / in vivid_fillbuff_tch()
302 (x - offset_x) + f->width * (y - offset_y)); in vivid_fillbuff_tch()
304 (x + offset_x) + f->width * (y + offset_y)); in vivid_fillbuff_tch()
307 x = f->width / 2; in vivid_fillbuff_tch()
308 y = f->height / 2; in vivid_fillbuff_tch()
310 offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT; in vivid_fillbuff_tch()
312 (x - offset_x) + f->width * (y - offset_y)); in vivid_fillbuff_tch()
314 (x + offset_x) + f->width * (y + offset_y)); in vivid_fillbuff_tch()
317 for (x = 0; x < f->width; x++) in vivid_fillbuff_tch()
318 for (y = f->height / 2; y < f->height; y++) in vivid_fillbuff_tch()
319 tch_buf[x + f->width * y] = VIVID_MIN_PRESSURE + in vivid_fillbuff_tch()
324 for (y = 0; y < 4; y++) { in vivid_fillbuff_tch()
326 ystart = (y * f->height) / 4 + f->height / 8; in vivid_fillbuff_tch()
327 xstart = (x * f->width) / 4 + f->width / 8; in vivid_fillbuff_tch()
329 ystart * f->width + xstart); in vivid_fillbuff_tch()