1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#define STV680_PACKETSIZE 4096
26
27
28#define STV680_NUMSBUF 1
29
30
31#define STV680_NUMFRAMES 2
32
33
34#define STV680_NUMSCRATCH 2
35
36
37#define STV680_MAX_NULLPACKETS 200
38
39
40#define STV680_MAX_ERRORS 100
41
42#define USB_PENCAM_VENDOR_ID 0x0553
43#define USB_PENCAM_PRODUCT_ID 0x0202
44#define PENCAM_TIMEOUT 1000
45
46#define STV_VIDEO_PALETTE VIDEO_PALETTE_RGB24
47
48static struct usb_device_id device_table[] = {
49 {USB_DEVICE (USB_PENCAM_VENDOR_ID, USB_PENCAM_PRODUCT_ID)},
50 {}
51};
52MODULE_DEVICE_TABLE (usb, device_table);
53
54struct stv680_sbuf {
55 unsigned char *data;
56};
57
58enum {
59 FRAME_UNUSED,
60 FRAME_READY,
61 FRAME_GRABBING,
62 FRAME_DONE,
63 FRAME_ERROR,
64};
65
66enum {
67 BUFFER_UNUSED,
68 BUFFER_READY,
69 BUFFER_BUSY,
70 BUFFER_DONE,
71};
72
73
74struct stv680_scratch {
75 unsigned char *data;
76 volatile int state;
77 int offset;
78 int length;
79};
80
81
82struct stv680_frame {
83 unsigned char *data;
84 volatile int grabstate;
85 unsigned char *curline;
86 int curlinepix;
87 int curpix;
88};
89
90
91struct usb_stv {
92 struct video_device vdev;
93
94 struct usb_device *udev;
95
96 unsigned char bulk_in_endpointAddr;
97 char *camera_name;
98
99 unsigned int VideoMode;
100 int SupportedModes;
101 int CIF;
102 int VGA;
103 int QVGA;
104 int cwidth;
105 int cheight;
106 int maxwidth;
107 int maxheight;
108 int vwidth;
109 int vheight;
110 unsigned long int rawbufsize;
111 unsigned long int maxframesize;
112
113 int origGain;
114 int origMode;
115
116 struct semaphore lock;
117 int user;
118 int removed;
119 int streaming;
120 char *fbuf;
121 struct urb *urb[STV680_NUMSBUF];
122 int curframe;
123 struct stv680_frame frame[STV680_NUMFRAMES];
124 int readcount;
125 int framecount;
126 int error;
127 int dropped;
128 int scratch_next;
129 int scratch_use;
130 int scratch_overflow;
131 struct stv680_scratch scratch[STV680_NUMSCRATCH];
132 struct stv680_sbuf sbuf[STV680_NUMSBUF];
133
134 unsigned int brightness;
135 unsigned int chgbright;
136 unsigned int whiteness;
137 unsigned int colour;
138 unsigned int contrast;
139 unsigned int hue;
140 unsigned int palette;
141 unsigned int depth;
142
143 wait_queue_head_t wq;
144
145 struct proc_dir_entry *proc_entry;
146 int nullpackets;
147};
148
149
150unsigned char red[256] = {
151 0, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
152 18, 18, 18, 18, 18, 18, 18, 25, 30, 35, 38, 42,
153 44, 47, 50, 53, 54, 57, 59, 61, 63, 65, 67, 69,
154 71, 71, 73, 75, 77, 78, 80, 81, 82, 84, 85, 87,
155 88, 89, 90, 91, 93, 94, 95, 97, 98, 98, 99, 101,
156 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
157 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 124,
158 125, 125, 126, 127, 128, 129, 129, 130, 131, 132, 133, 134,
159 134, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143,
160 143, 143, 144, 145, 146, 147, 147, 148, 149, 150, 150, 151,
161 152, 152, 152, 153, 154, 154, 155, 156, 157, 157, 158, 159,
162 159, 160, 161, 161, 161, 162, 163, 163, 164, 165, 165, 166,
163 167, 167, 168, 168, 169, 170, 170, 170, 171, 171, 172, 173,
164 173, 174, 174, 175, 176, 176, 177, 178, 178, 179, 179, 179,
165 180, 180, 181, 181, 182, 183, 183, 184, 184, 185, 185, 186,
166 187, 187, 188, 188, 188, 188, 189, 190, 190, 191, 191, 192,
167 192, 193, 193, 194, 195, 195, 196, 196, 197, 197, 197, 197,
168 198, 198, 199, 199, 200, 201, 201, 202, 202, 203, 203, 204,
169 204, 205, 205, 206, 206, 206, 206, 207, 207, 208, 208, 209,
170 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215,
171 215, 215, 215, 216, 216, 217, 217, 218, 218, 218, 219, 219,
172 220, 220, 221, 221
173};
174
175unsigned char green[256] = {
176 0, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
177 21, 21, 21, 21, 21, 21, 21, 28, 34, 39, 43, 47,
178 50, 53, 56, 59, 61, 64, 66, 68, 71, 73, 75, 77,
179 79, 80, 82, 84, 86, 87, 89, 91, 92, 94, 95, 97,
180 98, 100, 101, 102, 104, 105, 106, 108, 109, 110, 111, 113,
181 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126,
182 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
183 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149,
184 150, 151, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159,
185 160, 160, 161, 162, 163, 164, 164, 165, 166, 167, 167, 168,
186 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177,
187 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185,
188 186, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193,
189 193, 194, 194, 195, 196, 196, 197, 198, 198, 199, 199, 200,
190 201, 201, 202, 202, 203, 204, 204, 205, 205, 206, 206, 207,
191 208, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214,
192 214, 215, 215, 216, 217, 217, 218, 218, 219, 219, 220, 220,
193 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227,
194 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233,
195 233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239,
196 239, 240, 240, 241, 241, 242, 242, 243, 243, 243, 244, 244,
197 245, 245, 246, 246
198};
199
200unsigned char blue[256] = {
201 0, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
202 23, 23, 23, 23, 23, 23, 23, 30, 37, 42, 47, 51,
203 55, 58, 61, 64, 67, 70, 72, 74, 78, 80, 82, 84,
204 86, 88, 90, 92, 94, 95, 97, 100, 101, 103, 104, 106,
205 107, 110, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124,
206 125, 126, 127, 128, 129, 132, 133, 134, 135, 136, 137, 138,
207 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151,
208 152, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163,
209 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174,
210 176, 176, 177, 178, 179, 180, 180, 181, 182, 183, 183, 184,
211 185, 187, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194,
212 194, 195, 196, 196, 198, 199, 200, 200, 201, 202, 202, 203,
213 204, 204, 205, 205, 206, 207, 207, 209, 210, 210, 211, 212,
214 212, 213, 213, 214, 215, 215, 216, 217, 217, 218, 218, 220,
215 221, 221, 222, 222, 223, 224, 224, 225, 225, 226, 226, 227,
216 228, 228, 229, 229, 231, 231, 232, 233, 233, 234, 234, 235,
217 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 242, 242,
218 243, 243, 244, 244, 245, 246, 246, 247, 247, 248, 248, 249,
219 249, 250, 250, 251, 251, 253, 253, 254, 254, 255, 255, 255,
220 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
221 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
222 255, 255, 255, 255
223};
224