t613.c
来自「trident tm5600的linux驱动」· C语言 代码 · 共 1,192 行 · 第 1/3 页
C
1,192 行
/* * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *Notes: * t613 + tas5130A * * Focus to light do not balance well as in win. * Quality in win is not good, but its kinda better. * * Fix some "extraneous bytes", most of apps will show the image anyway * * Gamma table, is there, but its really doing something? * * 7~8 Fps, its ok, max on win its 10. * Costantino Leandro */#define MODULE_NAME "t613"#include "gspca.h"#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");MODULE_DESCRIPTION("GSPCA/T613 (JPEG Compliance) USB Camera Driver");MODULE_LICENSE("GPL");struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ unsigned char brightness; unsigned char contrast; unsigned char colors; unsigned char autogain; unsigned char gamma; unsigned char sharpness; unsigned char freq; unsigned char whitebalance; unsigned char mirror; unsigned char effect; __u8 sensor;#define SENSOR_TAS5130A 0#define SENSOR_OM6802 1};/* V4L2 controls supported by the driver */static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val);static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val);static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val);static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val);static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val);static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val);static int sd_querymenu(struct gspca_dev *gspca_dev, struct v4l2_querymenu *menu);static struct ctrl sd_ctrls[] = {#define SD_BRIGHTNESS 0 { { .id = V4L2_CID_BRIGHTNESS, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Brightness", .minimum = 0, .maximum = 14, .step = 1, .default_value = 8, }, .set = sd_setbrightness, .get = sd_getbrightness, },#define SD_CONTRAST 1 { { .id = V4L2_CID_CONTRAST, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Contrast", .minimum = 0, .maximum = 0x0d, .step = 1, .default_value = 0x07, }, .set = sd_setcontrast, .get = sd_getcontrast, },#define SD_COLOR 2 { { .id = V4L2_CID_SATURATION, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Color", .minimum = 0, .maximum = 0x0f, .step = 1, .default_value = 0x05, }, .set = sd_setcolors, .get = sd_getcolors, },#define GAMMA_MAX 16#define GAMMA_DEF 10 { { .id = V4L2_CID_GAMMA, /* (gamma on win) */ .type = V4L2_CTRL_TYPE_INTEGER, .name = "Gamma", .minimum = 0, .maximum = GAMMA_MAX - 1, .step = 1, .default_value = GAMMA_DEF, }, .set = sd_setgamma, .get = sd_getgamma, },#define SD_AUTOGAIN 4 { { .id = V4L2_CID_GAIN, /* here, i activate only the lowlight, * some apps dont bring up the * backligth_compensation control) */ .type = V4L2_CTRL_TYPE_INTEGER, .name = "Low Light", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0x01, }, .set = sd_setlowlight, .get = sd_getlowlight, },#define SD_MIRROR 5 { { .id = V4L2_CID_HFLIP, .type = V4L2_CTRL_TYPE_BOOLEAN, .name = "Mirror Image", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0, }, .set = sd_setflip, .get = sd_getflip },#define SD_LIGHTFREQ 6 { { .id = V4L2_CID_POWER_LINE_FREQUENCY, .type = V4L2_CTRL_TYPE_MENU, .name = "Light Frequency Filter", .minimum = 1, /* 1 -> 0x50, 2->0x60 */ .maximum = 2, .step = 1, .default_value = 1, }, .set = sd_setfreq, .get = sd_getfreq},#define SD_WHITE_BALANCE 7 { { .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, .type = V4L2_CTRL_TYPE_INTEGER, .name = "White Balance", .minimum = 0, .maximum = 1, .step = 1, .default_value = 0, }, .set = sd_setwhitebalance, .get = sd_getwhitebalance },#define SD_SHARPNESS 8 /* (aka definition on win) */ { { .id = V4L2_CID_SHARPNESS, .type = V4L2_CTRL_TYPE_INTEGER, .name = "Sharpness", .minimum = 0, .maximum = 15, .step = 1, .default_value = 0x06, }, .set = sd_setsharpness, .get = sd_getsharpness, },#define SD_EFFECTS 9 { { .id = V4L2_CID_EFFECTS, .type = V4L2_CTRL_TYPE_MENU, .name = "Webcam Effects", .minimum = 0, .maximum = 4, .step = 1, .default_value = 0, }, .set = sd_seteffect, .get = sd_geteffect },};static char *effects_control[] = { "Normal", "Emboss", /* disabled */ "Monochrome", "Sepia", "Sketch", "Sun Effect", /* disabled */ "Negative",};static struct v4l2_pix_format vga_mode_t16[] = { {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 160, .sizeimage = 160 * 120 * 4 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 4}, {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 176, .sizeimage = 176 * 144 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 3}, {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 320, .sizeimage = 320 * 240 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 2}, {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 352, .sizeimage = 352 * 288 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 1}, {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 640, .sizeimage = 640 * 480 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 0},};/* sensor specific data */struct additional_sensor_data { const __u8 data1[20]; const __u8 data2[18]; const __u8 data3[18]; const __u8 data4[4]; const __u8 data5[6]; const __u8 stream[4];};const static struct additional_sensor_data sensor_data[] = { { /* TAS5130A */ .data1 = {0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb, 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27, 0xd8, 0xc8, 0xd9, 0xfc}, .data2 = {0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8, 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8, 0xe8, 0xe0}, .data3 = {0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8, 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8, 0xcf, 0xe0}, .data4 = /* Freq (50/60Hz). Splitted for test purpose */ {0x66, 0x00, 0xa8, 0xe8}, .data5 = {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20}, .stream = {0x0b, 0x04, 0x0a, 0x40}, }, { /* OM6802 */ .data1 = {0xd0, 0xc2, 0xd1, 0x28, 0xd2, 0x0f, 0xd3, 0x22, 0xd4, 0xcd, 0xd5, 0x27, 0xd6, 0x2c, 0xd7, 0x06, 0xd8, 0xb3, 0xd9, 0xfc}, .data2 = {0xe0, 0x80, 0xe1, 0xff, 0xe2, 0xff, 0xe3, 0x80, 0xe4, 0xff, 0xe5, 0xff, 0xe6, 0x80, 0xe7, 0xff, 0xe8, 0xff}, .data3 = {0xc7, 0x80, 0xc8, 0xff, 0xc9, 0xff, 0xca, 0x80, 0xcb, 0xff, 0xcc, 0xff, 0xcd, 0x80, 0xce, 0xff, 0xcf, 0xff}, .data4 = /*Freq (50/60Hz). Splitted for test purpose */ {0x66, 0xca, 0xa8, 0xf0 }, .data5 = /* this could be removed later */ {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23}, .stream = {0x0b, 0x04, 0x0a, 0x78}, }};#define MAX_EFFECTS 7/* easily done by soft, this table could be removed, * i keep it here just in case */static const __u8 effects_table[MAX_EFFECTS][6] = { {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x00}, /* Normal */ {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x04}, /* Repujar */ {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x20}, /* Monochrome */ {0xa8, 0xe8, 0xc6, 0xd2, 0xc0, 0x80}, /* Sepia */ {0xa8, 0xc8, 0xc6, 0x52, 0xc0, 0x02}, /* Croquis */ {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x10}, /* Sun Effect */ {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */};static const __u8 gamma_table[GAMMA_MAX][34] = { {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85, /* 0 */ 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9, 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb, 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x33, 0x92, 0x5a, 0x93, 0x75, /* 1 */ 0x94, 0x85, 0x95, 0x93, 0x96, 0xa1, 0x97, 0xad, 0x98, 0xb7, 0x99, 0xc2, 0x9a, 0xcb, 0x9b, 0xd4, 0x9c, 0xde, 0x9D, 0xe7, 0x9e, 0xf0, 0x9f, 0xf7, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x2f, 0x92, 0x51, 0x93, 0x6b, /* 2 */ 0x94, 0x7c, 0x95, 0x8a, 0x96, 0x99, 0x97, 0xa6, 0x98, 0xb1, 0x99, 0xbc, 0x9a, 0xc6, 0x9b, 0xd0, 0x9c, 0xdb, 0x9d, 0xe4, 0x9e, 0xed, 0x9f, 0xf6, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60, /* 3 */ 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9e, 0x98, 0xaa, 0x99, 0xb5, 0x9a, 0xbf, 0x9b, 0xcb, 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x23, 0x92, 0x3f, 0x93, 0x55, /* 4 */ 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95, 0x98, 0xa2, 0x99, 0xad, 0x9a, 0xb9, 0x9b, 0xc6, 0x9c, 0xd2, 0x9d, 0xde, 0x9e, 0xe9, 0x9f, 0xf4, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x1b, 0x92, 0x33, 0x93, 0x48, /* 5 */ 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87, 0x98, 0x96, 0x99, 0xa3, 0x9a, 0xb1, 0x9b, 0xbe, 0x9c, 0xcc, 0x9d, 0xda, 0x9e, 0xe7, 0x9f, 0xf3, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20, /* 6 */ 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67, 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa, 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26, /* 7 */ 0x94, 0x38, 0x95, 0x4a, 0x96, 0x60, 0x97, 0x70, 0x98, 0x80, 0x99, 0x90, 0x9a, 0xa0, 0x9b, 0xb0, 0x9c, 0xc0, 0x9D, 0xd0, 0x9e, 0xe0, 0x9f, 0xf0, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35, /* 8 */ 0x94, 0x47, 0x95, 0x5a, 0x96, 0x69, 0x97, 0x79, 0x98, 0x88, 0x99, 0x97, 0x9a, 0xa7, 0x9b, 0xb6, 0x9c, 0xc4, 0x9d, 0xd3, 0x9e, 0xe0, 0x9f, 0xf0, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40, /* 9 */ 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84, 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x18, 0x92, 0x2b, 0x93, 0x44, /* 10 */ 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8e, 0x98, 0x9c, 0x99, 0xaa, 0x9a, 0xb7, 0x9b, 0xc4, 0x9c, 0xd0, 0x9d, 0xd8, 0x9e, 0xe2, 0x9f, 0xf0, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x1a, 0x92, 0x34, 0x93, 0x52, /* 11 */ 0x94, 0x66, 0x95, 0x7e, 0x96, 0x8D, 0x97, 0x9B, 0x98, 0xa8, 0x99, 0xb4, 0x9a, 0xc0, 0x9b, 0xcb, 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x3f, 0x92, 0x5a, 0x93, 0x6e, /* 12 */ 0x94, 0x7f, 0x95, 0x8e, 0x96, 0x9c, 0x97, 0xa8, 0x98, 0xb4, 0x99, 0xbf, 0x9a, 0xc9, 0x9b, 0xd3, 0x9c, 0xdc, 0x9d, 0xe5, 0x9e, 0xee, 0x9f, 0xf6, 0xa0, 0xff}, {0x90, 0x00, 0x91, 0x54, 0x92, 0x6f, 0x93, 0x83, /* 13 */ 0x94, 0x93, 0x95, 0xa0, 0x96, 0xad, 0x97, 0xb7, 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdc,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?