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()
26 if (vq->num_buffers + *nbuffers < 2) in touch_cap_queue_setup()
27 *nbuffers = 2 - vq->num_buffers; in touch_cap_queue_setup()
35 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_prepare()
36 struct v4l2_pix_format *f = &dev->tch_format; in touch_cap_buf_prepare()
37 unsigned int size = f->sizeimage; in touch_cap_buf_prepare()
39 if (dev->buf_prepare_error) { in touch_cap_buf_prepare()
44 dev->buf_prepare_error = false; in touch_cap_buf_prepare()
45 return -EINVAL; in touch_cap_buf_prepare()
50 return -EINVAL; in touch_cap_buf_prepare()
60 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_queue()
63 vbuf->field = V4L2_FIELD_NONE; in touch_cap_buf_queue()
64 spin_lock(&dev->slock); in touch_cap_buf_queue()
65 list_add_tail(&buf->list, &dev->touch_cap_active); in touch_cap_buf_queue()
66 spin_unlock(&dev->slock); in touch_cap_buf_queue()
74 dev->touch_cap_seq_count = 0; in touch_cap_start_streaming()
75 if (dev->start_streaming_error) { in touch_cap_start_streaming()
76 dev->start_streaming_error = false; in touch_cap_start_streaming()
77 err = -EINVAL; in touch_cap_start_streaming()
85 &dev->touch_cap_active, list) { in touch_cap_start_streaming()
86 list_del(&buf->list); in touch_cap_start_streaming()
87 vb2_buffer_done(&buf->vb.vb2_buf, in touch_cap_start_streaming()
104 struct vivid_dev *dev = vb2_get_drv_priv(vb->vb2_queue); in touch_cap_buf_request_complete()
106 v4l2_ctrl_request_complete(vb->req_obj.req, &dev->ctrl_hdl_touch_cap); in touch_cap_buf_request_complete()
122 if (f->index) in vivid_enum_fmt_tch()
123 return -EINVAL; in vivid_enum_fmt_tch()
125 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in vivid_enum_fmt_tch()
133 if (dev->multiplanar) in vivid_g_fmt_tch()
134 return -ENOTTY; in vivid_g_fmt_tch()
135 f->fmt.pix = dev->tch_format; in vivid_g_fmt_tch()
144 if (!dev->multiplanar) in vivid_g_fmt_tch_mplane()
145 return -ENOTTY; in vivid_g_fmt_tch_mplane()
147 sp_fmt.fmt.pix = dev->tch_format; in vivid_g_fmt_tch_mplane()
157 if (parm->type != (dev->multiplanar ? in vivid_g_parm_tch()
160 return -EINVAL; in vivid_g_parm_tch()
162 parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; in vivid_g_parm_tch()
163 parm->parm.capture.timeperframe = dev->timeperframe_tch_cap; in vivid_g_parm_tch()
164 parm->parm.capture.readbuffers = 1; in vivid_g_parm_tch()
170 if (inp->index) in vivid_enum_input_tch()
171 return -EINVAL; in vivid_enum_input_tch()
173 inp->type = V4L2_INPUT_TYPE_TOUCH; in vivid_enum_input_tch()
174 strscpy(inp->name, "Vivid Touch", sizeof(inp->name)); in vivid_enum_input_tch()
175 inp->capabilities = 0; in vivid_enum_input_tch()
187 struct v4l2_pix_format *f = &dev->tch_format; in vivid_set_touch()
190 return -EINVAL; in vivid_set_touch()
192 f->pixelformat = V4L2_TCH_FMT_DELTA_TD16; in vivid_set_touch()
193 f->width = VIVID_TCH_WIDTH; in vivid_set_touch()
194 f->height = VIVID_TCH_HEIGHT; in vivid_set_touch()
195 f->field = V4L2_FIELD_NONE; in vivid_set_touch()
196 f->colorspace = V4L2_COLORSPACE_RAW; in vivid_set_touch()
197 f->bytesperline = f->width * sizeof(s16); in vivid_set_touch()
198 f->sizeimage = f->width * f->height * sizeof(s16); in vivid_set_touch()
211 /* Fill 10% of the values within range -3 and 3, zero the others */ in vivid_fill_buff_noise()
218 tch_buf[i] = (rand / 10) % 7 - 3; in vivid_fill_buff_noise()
231 unsigned int x = index % f->width; in vivid_tch_buf_set()
232 unsigned int y = index / f->width; in vivid_tch_buf_set() local
233 unsigned int offset = VIVID_MIN_PRESSURE; in vivid_tch_buf_set() local
235 tch_buf[index] = offset + get_random_pressure(); in vivid_tch_buf_set()
236 offset /= 2; in vivid_tch_buf_set()
238 tch_buf[index - 1] = offset + get_random_pressure(); in vivid_tch_buf_set()
239 if (x < f->width - 1) in vivid_tch_buf_set()
240 tch_buf[index + 1] = offset + get_random_pressure(); in vivid_tch_buf_set()
241 if (y) in vivid_tch_buf_set()
242 tch_buf[index - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
243 if (y < f->height - 1) in vivid_tch_buf_set()
244 tch_buf[index + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
245 offset /= 2; in vivid_tch_buf_set()
246 if (x && y) in vivid_tch_buf_set()
247 tch_buf[index - 1 - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
248 if (x < f->width - 1 && y) in vivid_tch_buf_set()
249 tch_buf[index + 1 - f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
250 if (x && y < f->height - 1) in vivid_tch_buf_set()
251 tch_buf[index - 1 + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
252 if (x < f->width - 1 && y < f->height - 1) in vivid_tch_buf_set()
253 tch_buf[index + 1 + f->width] = offset + get_random_pressure(); in vivid_tch_buf_set()
258 struct v4l2_pix_format *f = &dev->tch_format; in vivid_fillbuff_tch()
259 int size = f->width * f->height; in vivid_fillbuff_tch()
260 int x, y, xstart, ystart, offset_x, offset_y; in vivid_fillbuff_tch() local
263 __s16 *tch_buf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); in vivid_fillbuff_tch()
265 buf->vb.sequence = dev->touch_cap_seq_count; in vivid_fillbuff_tch()
266 test_pattern = (buf->vb.sequence / TCH_SEQ_COUNT) % TEST_CASE_MAX; in vivid_fillbuff_tch()
267 test_pat_idx = buf->vb.sequence % TCH_SEQ_COUNT; in vivid_fillbuff_tch()
275 dev->tch_pat_random = get_random_int(); in vivid_fillbuff_tch()
276 rand = dev->tch_pat_random; in vivid_fillbuff_tch()
293 (rand % f->height) * f->width + in vivid_fillbuff_tch()
295 (f->width / TCH_PATTERN_COUNT)); in vivid_fillbuff_tch()
298 x = f->width / 2; in vivid_fillbuff_tch()
299 y = f->height / 2; in vivid_fillbuff_tch()
300 offset_x = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * x) / in vivid_fillbuff_tch()
302 offset_y = ((TCH_PATTERN_COUNT - 1 - test_pat_idx) * y) / in vivid_fillbuff_tch()
305 (x - offset_x) + f->width * (y - offset_y)); in vivid_fillbuff_tch()
307 (x + offset_x) + f->width * (y + offset_y)); in vivid_fillbuff_tch()
310 x = f->width / 2; in vivid_fillbuff_tch()
311 y = f->height / 2; in vivid_fillbuff_tch()
313 offset_y = (test_pat_idx * y) / TCH_PATTERN_COUNT; in vivid_fillbuff_tch()
315 (x - offset_x) + f->width * (y - offset_y)); in vivid_fillbuff_tch()
317 (x + offset_x) + f->width * (y + offset_y)); in vivid_fillbuff_tch()
320 for (x = 0; x < f->width; x++) in vivid_fillbuff_tch()
321 for (y = f->height / 2; y < f->height; y++) in vivid_fillbuff_tch()
322 tch_buf[x + f->width * y] = VIVID_MIN_PRESSURE + in vivid_fillbuff_tch()
327 for (y = 0; y < 4; y++) { in vivid_fillbuff_tch()
329 ystart = (y * f->height) / 4 + f->height / 8; in vivid_fillbuff_tch()
330 xstart = (x * f->width) / 4 + f->width / 8; in vivid_fillbuff_tch()
332 ystart * f->width + xstart); in vivid_fillbuff_tch()