| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <fcntl.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <unistd.h> |
| 8 |
#include <linux/videodev2.h> |
| 9 |
#include "v4l2_config.h" |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#define ADV7611_SUBDEV "/dev/v4l-subdev0" |
| 15 |
#define ADV7511_SUBDEV "/dev/v4l-subdev1" |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
int main(void) |
| 21 |
{ |
| 22 |
int adv7611_subdev_fd; |
| 23 |
int adv7511_subdev_fd; |
| 24 |
struct v4l2_dv_timings dv_timings; |
| 25 |
struct v4l2_queryctrl ctrls[20]; |
| 26 |
struct v4l2_event_new event; |
| 27 |
int ctrls_no; |
| 28 |
int index; |
| 29 |
int ret; |
| 30 |
|
| 31 |
|
| 32 |
adv7611_subdev_fd = open(ADV7611_SUBDEV, O_RDWR | O_NONBLOCK, 0); |
| 33 |
if (adv7611_subdev_fd == -1) |
| 34 |
return -1; |
| 35 |
|
| 36 |
adv7511_subdev_fd = open(ADV7511_SUBDEV, O_RDWR | O_NONBLOCK, 0); |
| 37 |
if (adv7511_subdev_fd == -1) |
| 38 |
goto err1; |
| 39 |
|
| 40 |
|
| 41 |
ret = v4l2_cfg_query_dv_timings(adv7611_subdev_fd, &dv_timings); |
| 42 |
if (ret) |
| 43 |
goto err2; |
| 44 |
|
| 45 |
|
| 46 |
ret = v4l2_cfg_set_dv_timings(adv7611_subdev_fd, &dv_timings); |
| 47 |
if (ret) |
| 48 |
goto err2; |
| 49 |
ret = v4l2_cfg_set_dv_timings(adv7511_subdev_fd, &dv_timings); |
| 50 |
if (ret) |
| 51 |
goto err2; |
| 52 |
|
| 53 |
|
| 54 |
ret = v4l2_cfg_get_dv_timings(adv7611_subdev_fd, &dv_timings); |
| 55 |
if (ret) |
| 56 |
goto err2; |
| 57 |
ret = v4l2_cfg_get_dv_timings(adv7511_subdev_fd, &dv_timings); |
| 58 |
if (ret) |
| 59 |
goto err2; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
ret = v4l2_cfg_subscribe_event(adv7611_subdev_fd, V4L2_EVENT_SOURCE_CHANGE, 0); |
| 67 |
if (ret) |
| 68 |
goto err2; |
| 69 |
|
| 70 |
printf("Poll for \"SRC_CH_RESOLUTION\" event...\n"); |
| 71 |
while (1) { |
| 72 |
if (!v4l2_cfg_dequeue_event(adv7611_subdev_fd, &event)) { |
| 73 |
|
| 74 |
while (v4l2_cfg_query_dv_timings(adv7611_subdev_fd, &dv_timings) != 0); |
| 75 |
|
| 76 |
|
| 77 |
ret = v4l2_cfg_set_dv_timings(adv7611_subdev_fd, &dv_timings); |
| 78 |
if (ret) { |
| 79 |
goto err2; |
| 80 |
} |
| 81 |
ret = v4l2_cfg_set_dv_timings(adv7511_subdev_fd, &dv_timings); |
| 82 |
if (ret) { |
| 83 |
goto err2; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
ret = v4l2_cfg_query_ctrls(adv7511_subdev_fd, ctrls, &ctrls_no); |
| 94 |
if (ret) |
| 95 |
goto err2; |
| 96 |
printf("Controls found:\n"); |
| 97 |
for (index = 0; index < ctrls_no; index++) { |
| 98 |
printf("\t%s (ID: 0x%x)\n", ctrls[index].name, ctrls[index].id); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
ret = v4l2_cfg_subscribe_event(adv7511_subdev_fd, V4L2_EVENT_CTRL, ctrls[1].id); |
| 103 |
if (ret) |
| 104 |
goto err2; |
| 105 |
|
| 106 |
printf("Poll for \"%s\" event...\n", ctrls[1].name); |
| 107 |
while (1) { |
| 108 |
if (!v4l2_cfg_dequeue_event(adv7511_subdev_fd, &event)) { |
| 109 |
if (event.u.ctrl.changes & V4L2_EVENT_CTRL_CH_VALUE) { |
| 110 |
if (event.u.ctrl.type == V4L2_CTRL_TYPE_INTEGER64) |
| 111 |
printf("value = 0x%llx\n", event.u.ctrl.value64); |
| 112 |
else |
| 113 |
printf("value = 0x%x\n", event.u.ctrl.value); |
| 114 |
} |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
ret = v4l2_cfg_query_ctrls(adv7611_subdev_fd, ctrls, &ctrls_no); |
| 124 |
if (ret) |
| 125 |
goto err2; |
| 126 |
printf("Controls found:\n"); |
| 127 |
for (index = 0; index < ctrls_no; index++) { |
| 128 |
printf("\t%s (ID: 0x%x)\n", ctrls[index].name, ctrls[index].id); |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 133 |
V4L2_CFG_CID_ADV7611_FREE_RUN_MODE, 0); |
| 134 |
if (ret) |
| 135 |
goto err2; |
| 136 |
|
| 137 |
|
| 138 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 139 |
V4L2_CFG_CID_ADV7611_FREE_RUN_MODE, 2); |
| 140 |
if (ret) |
| 141 |
goto err2; |
| 142 |
|
| 143 |
|
| 144 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 145 |
V4L2_CFG_CID_ADV7611_FREE_RUN_MODE, 1); |
| 146 |
if (ret) |
| 147 |
goto err2; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 152 |
V4L2_CFG_CID_ADV7611_FREE_RUN_COLOR_MANUAL, 1); |
| 153 |
if (ret) |
| 154 |
goto err2; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 159 |
V4L2_CFG_CID_ADV7611_FREE_RUN_COLOR, 0xFF0000); |
| 160 |
if (ret) |
| 161 |
goto err2; |
| 162 |
|
| 163 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 164 |
V4L2_CFG_CID_ADV7611_FREE_RUN_COLOR, 0x00FF00); |
| 165 |
if (ret) |
| 166 |
goto err2; |
| 167 |
|
| 168 |
ret = v4l2_cfg_set_control_value(adv7611_subdev_fd, |
| 169 |
V4L2_CFG_CID_ADV7611_FREE_RUN_COLOR, 0x0000FF); |
| 170 |
if (ret) |
| 171 |
goto err2; |
| 172 |
|
| 173 |
close(adv7611_subdev_fd); |
| 174 |
close(adv7511_subdev_fd); |
| 175 |
|
| 176 |
return 0; |
| 177 |
|
| 178 |
err2: |
| 179 |
close(adv7511_subdev_fd); |
| 180 |
err1: |
| 181 |
close(adv7611_subdev_fd); |
| 182 |
return -1; |
| 183 |
} |