From 2f17fa91b50b3434c341b220b3cb0c5c0d81f8e7 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 7 May 2007 07:50:52 -0300 Subject: Add capability to test VIDIOC_[S|G]_FREQUENCY on driver-test From: Mauro Carvalho Chehab Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/lib/v4l2_driver.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ v4l2-apps/lib/v4l2_driver.h | 3 +++ 2 files changed, 60 insertions(+) (limited to 'v4l2-apps/lib') diff --git a/v4l2-apps/lib/v4l2_driver.c b/v4l2-apps/lib/v4l2_driver.c index 3f7a1188f..94f826968 100644 --- a/v4l2-apps/lib/v4l2_driver.c +++ b/v4l2-apps/lib/v4l2_driver.c @@ -745,3 +745,60 @@ int v4l2_close (struct v4l2_driver *drv) return (close(drv->fd)); } + +/**************************************************************************** + Get/Set frequency + ****************************************************************************/ + +int v4l2_getset_freq (struct v4l2_driver *drv, enum v4l2_direction dir, + double *freq) +{ + struct v4l2_tuner tun; + struct v4l2_frequency frq; + double d = 62500; + unsigned int counter; + + memset(&tun, 0, sizeof(tun)); + + if (-1 == xioctl (drv->fd, VIDIOC_G_TUNER, &tun)) { + perror ("g_tuner"); + printf("Assuming 62.5 kHz step\n"); + } else { + if (tun.capability & V4L2_TUNER_CAP_LOW) + d=62.5; + } + + if (drv->debug) { + if (tun.capability & V4L2_TUNER_CAP_LOW) + printf("62.5 Hz step\n"); + else + printf("62.5 kHz step\n"); + } + + memset(&frq, 0, sizeof(frq)); + + frq.type = V4L2_TUNER_ANALOG_TV; + + if (dir & V4L2_GET) { + if (-1 == xioctl (drv->fd, VIDIOC_G_FREQUENCY, &frq)) { + perror ("s_frequency"); + return errno; + } + *freq = frq.frequency * d; + if (drv->debug) + printf("board is at freq %4.3f MHz (%d)\n", + *freq/1000000, frq.frequency); + } else { + frq.frequency = (uint32_t)(((*freq)+d/2) / d); + + if (-1 == xioctl (drv->fd, VIDIOC_S_FREQUENCY, &frq)) { + perror ("s_frequency"); + return errno; + } + if (drv->debug) + printf("board set to freq %4.3f MHz (%d)\n", + *freq/1000000, frq.frequency); + + } + return 0; +} diff --git a/v4l2-apps/lib/v4l2_driver.h b/v4l2-apps/lib/v4l2_driver.h index ef6a754f4..74d5b8358 100644 --- a/v4l2-apps/lib/v4l2_driver.h +++ b/v4l2-apps/lib/v4l2_driver.h @@ -75,3 +75,6 @@ int v4l2_free_bufs(struct v4l2_driver *drv); int v4l2_start_streaming(struct v4l2_driver *drv); int v4l2_stop_streaming(struct v4l2_driver *drv); int v4l2_rcvbuf(struct v4l2_driver *drv, v4l2_recebe_buffer *v4l2_rec_buf); +int v4l2_getset_freq (struct v4l2_driver *drv, enum v4l2_direction dir, + double *freq); + -- cgit v1.2.3