SyntekUSBVideoCamera
stk11xx.h
Go to the documentation of this file.
1 
34 #ifndef STK11XX_H
35 #define STK11XX_H
36 
37 #define DRIVER_NAME "stk11xx"
38 #define DRIVER_VERSION "v3.0.0"
39 #define DRIVER_VERSION_NUM 0x030000
40 #define DRIVER_YEAR 2012
41 #define DRIVER_DESC "Syntek USB Video Camera"
42 #define DRIVER_AUTHOR "Nicolas VIVIEN"
43 #define PREFIX DRIVER_NAME ": "
44 #define DRIVER_URL \
45  "http://sourceforge.net/projects/syntekdriver/"
47 #define USB_SYNTEK1_VENDOR_ID 0x174f
48 #define USB_SYNTEK2_VENDOR_ID 0x05e1
50 #define USB_STK_A311_PRODUCT_ID 0xa311
51 #define USB_STK_A821_PRODUCT_ID 0xa821
52 #define USB_STK_AA11_PRODUCT_ID 0xaa11
53 #define USB_STK_6A31_PRODUCT_ID 0x6a31
54 #define USB_STK_6A33_PRODUCT_ID 0x6a33
55 #define USB_STK_6A51_PRODUCT_ID 0x6a51
56 #define USB_STK_6A54_PRODUCT_ID 0x6a54
57 #define USB_STK_6D51_PRODUCT_ID 0x6d51
59 #define USB_STK_0408_PRODUCT_ID 0x0408
60 #define USB_STK_0500_PRODUCT_ID 0x0500
61 #define USB_STK_0501_PRODUCT_ID 0x0501
70 #define VID_HARDWARE_STK11XX 88
71 
72 
73 
74 
88 #define MAX_ISO_BUFS 16
89 #define ISO_FRAMES_PER_DESC 10
90 #define ISO_MAX_FRAME_SIZE 3 * 1024
91 #define ISO_BUFFER_SIZE (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
92 
93 
105 #define STK11XX_MAX_IMAGES 10
106 #define STK11XX_FRAME_SIZE (1280 * 1024 * 4)
107 
108 
109 
110 
111 
112 
113 
120 #define DRIVER_SUPPORT "Syntek USB Camera : STK-1135"
121 
142 #ifndef CONFIG_STK11XX_DEBUG
143 #define CONFIG_STK11XX_DEBUG 0
144 #endif
145 
146 #if CONFIG_STK11XX_DEBUG
147 
148 #define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
149 #define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
150 #define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
151 #define STK_DEBUG(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
152 
153 #else
154 
155 #define STK_INFO(str, args...) printk(KERN_INFO PREFIX str, ##args)
156 #define STK_ERROR(str, args...) printk(KERN_ERR PREFIX str, ##args)
157 #define STK_WARNING(str, args...) printk(KERN_WARNING PREFIX str, ##args)
158 #define STK_DEBUG(str, args...) do { } while(0)
159 
160 #endif
161 
162 
171 #ifndef CONFIG_STK11XX_DEBUG_STREAM
172 #define CONFIG_STK11XX_DEBUG_STREAM 0
173 #endif
174 
175 #if CONFIG_STK11XX_DEBUG_STREAM
176 
177 #define STK_STREAM(str, args...) printk(KERN_DEBUG PREFIX str, ##args)
178 
179 #else
180 
181 #define STK_STREAM(str, args...) do { } while(0)
182 
183 #endif
184 
185 
186 
190 typedef enum {
191  SYNTEK_STK_M811 = 1,
192  SYNTEK_STK_A311 = 2,
193  SYNTEK_STK_A821 = 3,
194  SYNTEK_STK_6A31 = 4,
195  SYNTEK_STK_6A33 = 5,
196  SYNTEK_STK_6A51 = 6,
197  SYNTEK_STK_6A54 = 7,
198  SYNTEK_STK_6D51 = 8,
199  SYNTEK_STK_0500 = 9,
200  SYNTEK_STK_0408 = 10,
201  SYNTEK_STK_AA11 = 11,
203 
204 
208 typedef enum {
214 
215 
219 typedef enum {
220  STK11XX_80x60,
221  STK11XX_128x96,
222  STK11XX_160x120,
223  STK11XX_213x160,
224  STK11XX_320x240,
225  STK11XX_640x480,
226  STK11XX_720x576,
227  STK11XX_800x600,
228  STK11XX_1024x768,
229  STK11XX_1280x1024,
230  STK11XX_NBR_SIZES
232 
233 
237 typedef enum {
238  STK11XX_PALETTE_RGB24,
239  STK11XX_PALETTE_RGB32,
240  STK11XX_PALETTE_BGR24,
241  STK11XX_PALETTE_BGR32,
242  STK11XX_PALETTE_UYVY,
243  STK11XX_PALETTE_YUYV
245 
246 
251  void *data;
252  int length;
253  int read;
254  struct urb *urb;
255 };
256 
257 
262  int errors;
263  void *data;
264  volatile bool odd;
265  volatile int filled;
266  struct stk11xx_frame_buf *next;
267 };
268 
269 
274  unsigned long offset;
276 };
277 
278 
283  int x;
284  int y;
285 };
286 
287 
292  int fps;
294  int contrast;
295  int whiteness;
296  int colour;
297  int depth;
298  int palette;
299  int hue;
300  int hflip;
301  int vflip;
302  int input;
303  int norm;
305  // default values for the device. Above are *current* values
306  int default_brightness;
307  int default_contrast;
308  int default_colour;
309  int default_whiteness;
310  int default_hflip;
311  int default_vflip;
312 };
313 
314 
318 struct usb_stk11xx {
319  struct video_device *vdev;
320  struct usb_device *udev;
321  struct usb_interface *interface;
323  int release;
327  unsigned char *int_in_buffer;
328  size_t int_in_size;
331  size_t isoc_in_size;
334  int watchdog;
338  int error_status;
339 
340  int vopen;
344  int vsync;
345  int v1st_cap;
348  spinlock_t spinlock;
349  struct semaphore mutex;
350  wait_queue_head_t wait_frame;
351  struct mutex modlock;
354  // 1: isoc
355  char isoc_init_ok;
356  struct stk11xx_iso_buf isobuf[MAX_ISO_BUFS];
357 
358  // 2: frame
359  int frame_size;
360  struct stk11xx_frame_buf *framebuf;
361  struct stk11xx_frame_buf *empty_frames, *empty_frames_tail;
362  struct stk11xx_frame_buf *full_frames, *full_frames_tail;
363  struct stk11xx_frame_buf *fill_frame;
364  struct stk11xx_frame_buf *read_frame;
365 
366  // 3: image
367  int view_size;
368  int image_size;
369  void *image_data;
370  struct stk11xx_image_buf images[STK11XX_MAX_IMAGES];
371  int image_used[STK11XX_MAX_IMAGES];
372  unsigned int nbuffers;
373  unsigned int len_per_image;
374  int image_read_pos;
375  int fill_image;
376  int resolution;
377  struct stk11xx_coord view;
378  struct stk11xx_coord image;
379 };
380 
381 
386 #define STK11XX_PERCENT(x,y) ( ((int)x * (int)y) / 100)
387 
388 
393 #define to_stk11xx_dev(d) container_of(d, struct usb_stk11xx, kref)
394 
395 
396 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
397 
398 
399 int usb_stk11xx_write_registry(struct usb_stk11xx *, __u16, __u16);
400 int usb_stk11xx_read_registry(struct usb_stk11xx *, __u16, int *);
401 int usb_stk11xx_set_feature(struct usb_stk11xx *, int);
403 int usb_stk11xx_isoc_init(struct usb_stk11xx *);
404 void usb_stk11xx_isoc_handler(struct urb *);
406 
407 int dev_stk11xx_decompress(struct usb_stk11xx *);
411 int dev_stk11xx_check_device(struct usb_stk11xx *, int);
412 int dev_stk11xx_camera_on(struct usb_stk11xx *);
413 int dev_stk11xx_camera_off(struct usb_stk11xx *);
421 
422 int v4l_stk11xx_select_video_mode(struct usb_stk11xx *, int, int);
425 
426 int stk11xx_create_sysfs_files(struct video_device *);
427 void stk11xx_remove_sysfs_files(struct video_device *);
428 
430 int stk11xx_reset_buffers(struct usb_stk11xx *);
431 int stk11xx_clear_buffers(struct usb_stk11xx *);
432 int stk11xx_free_buffers(struct usb_stk11xx *);
433 void stk11xx_next_image(struct usb_stk11xx *);
434 int stk11xx_next_frame(struct usb_stk11xx *);
435 int stk11xx_handle_frame(struct usb_stk11xx *);
436 
437 int stk11xx_decompress(struct usb_stk11xx *);
438 
439 
440 #endif
int dev_stk11xx_initialize_device(struct usb_stk11xx *)
This function permits to initialize the device.
Definition: stk11xx-dev.c:63
int dev_stk11xx_camera_settings(struct usb_stk11xx *)
This function permits to modify the settings of the camera.
Definition: stk11xx-dev.c:366
struct usb_device * udev
Definition: stk11xx.h:320
int v4l_stk11xx_select_video_mode(struct usb_stk11xx *, int, int)
Select a video mode.
Definition: stk11xx-v4l.c:156
int dev_stk11xx_init_camera(struct usb_stk11xx *)
This function initializes the device for the stream.
Definition: stk11xx-dev.c:123
int visoc_errors
Definition: stk11xx.h:341
int dev_stk11xx_start_stream(struct usb_stk11xx *)
This function sets the device to start the stream.
Definition: stk11xx-dev.c:549
unsigned long offset
Definition: stk11xx.h:274
int dev_stk11xx_watchdog_camera(struct usb_stk11xx *)
A espece of software watchdog.
Definition: stk11xx-dev.c:234
T_STK11XX_PALETTE
Definition: stk11xx.h:237
T_STK11XX_VIDEOMODE
Definition: stk11xx.h:208
int usb_stk11xx_read_registry(struct usb_stk11xx *, __u16, int *)
Read a 16-bits value from a 16-bits register.
Definition: stk11xx-usb.c:590
int whiteness
Definition: stk11xx.h:295
int dev_stk11xx_set_camera_fps(struct usb_stk11xx *)
This function permits to modify the fps of the camera.
Definition: stk11xx-dev.c:489
void stk11xx_next_image(struct usb_stk11xx *)
Prepare the next image.
Definition: stk11xx-buf.c:334
int stk11xx_next_frame(struct usb_stk11xx *)
Prepare the next frame.
Definition: stk11xx-buf.c:352
int vframes_error
Definition: stk11xx.h:342
wait_queue_head_t wait_frame
Definition: stk11xx.h:350
int v1st_cap
Definition: stk11xx.h:345
unsigned char * int_in_buffer
Definition: stk11xx.h:327
int v4l_stk11xx_unregister_video_device(struct usb_stk11xx *)
Unregister the video device.
Definition: stk11xx-v4l.c:1530
void usb_stk11xx_isoc_handler(struct urb *)
ISOC handler.
Definition: stk11xx-usb.c:252
int stk11xx_clear_buffers(struct usb_stk11xx *)
Clear current buffers.
Definition: stk11xx-buf.c:270
#define STK11XX_MAX_IMAGES
Definition: stk11xx.h:105
struct mutex modlock
Definition: stk11xx.h:351
int vsync
Definition: stk11xx.h:344
int dev_stk11xx_camera_on(struct usb_stk11xx *)
This function switchs on the camera.
Definition: stk11xx-dev.c:257
struct stk11xx_video vsettings
Definition: stk11xx.h:336
int dev_stk11xx_decompress(struct usb_stk11xx *)
Decompress/convert a frame from the video stream.
Definition: stk11xx-dev.c:727
int watchdog
Definition: stk11xx.h:334
int stk11xx_create_sysfs_files(struct video_device *)
Create the 'sys' entries.
int webcam_model
Definition: stk11xx.h:324
int vopen
Definition: stk11xx.h:340
int dev_stk11xx_stop_stream(struct usb_stk11xx *)
This function sets the device to stop the stream.
Definition: stk11xx-dev.c:668
__u8 isoc_in_endpointAddr
Definition: stk11xx.h:332
spinlock_t spinlock
Definition: stk11xx.h:348
int dev_stk11xx_reconf_camera(struct usb_stk11xx *)
Reconfigure the camera before the stream.
Definition: stk11xx-dev.c:608
int brightness
Definition: stk11xx.h:293
int usb_stk11xx_set_configuration(struct usb_stk11xx *)
Send the message SET_CONFIGURATION.
Definition: stk11xx-usb.c:524
void usb_stk11xx_isoc_cleanup(struct usb_stk11xx *)
Clean-up all the ISOC buffers.
Definition: stk11xx-usb.c:449
int stk11xx_free_buffers(struct usb_stk11xx *)
Release all buffers.
Definition: stk11xx-buf.c:287
struct video_device * vdev
Definition: stk11xx.h:319
void stk11xx_remove_sysfs_files(struct video_device *)
Remove the 'sys' entries.
size_t int_in_size
Definition: stk11xx.h:328
int release
Definition: stk11xx.h:323
int v4l_stk11xx_register_video_device(struct usb_stk11xx *)
Register the video device.
Definition: stk11xx-v4l.c:1497
int vframes_dumped
Definition: stk11xx.h:343
int usb_stk11xx_isoc_init(struct usb_stk11xx *)
Initilize an isochronous pipe.
Definition: stk11xx-usb.c:133
struct semaphore mutex
Definition: stk11xx.h:349
int dev_stk11xx_check_device(struct usb_stk11xx *, int)
This function permits to check the device in reading the register 0x0201.
Definition: stk11xx-dev.c:186
int dev_stk11xx_set_camera_quality(struct usb_stk11xx *)
This function permits to modify the quality video of the camera.
Definition: stk11xx-dev.c:429
int stk11xx_handle_frame(struct usb_stk11xx *)
Handler frame.
Definition: stk11xx-buf.c:407
const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES]
Definition: stk11xx-v4l.c:59
int stk11xx_decompress(struct usb_stk11xx *)
Decompress a frame.
size_t isoc_in_size
Definition: stk11xx.h:331
int usb_stk11xx_write_registry(struct usb_stk11xx *, __u16, __u16)
Write a 16-bits value to a 16-bits register.
Definition: stk11xx-usb.c:558
int usb_stk11xx_set_feature(struct usb_stk11xx *, int)
Send the message SET_FEATURE and choose the interface.
Definition: stk11xx-usb.c:492
__u8 int_in_endpointAddr
Definition: stk11xx.h:329
int dev_stk11xx_camera_off(struct usb_stk11xx *)
This function switchs off the camera.
Definition: stk11xx-dev.c:280
#define MAX_ISO_BUFS
Definition: stk11xx.h:88
int dev_stk11xx_camera_asleep(struct usb_stk11xx *)
Wake-up the camera.
Definition: stk11xx-dev.c:303
struct usb_interface * interface
Definition: stk11xx.h:321
T_SYNTEK_DEVICE
Definition: stk11xx.h:190
T_STK11XX_RESOLUTION
Definition: stk11xx.h:219
int stk11xx_reset_buffers(struct usb_stk11xx *)
Reset all ISOC buffers.
Definition: stk11xx-buf.c:221
int contrast
Definition: stk11xx.h:294
int stk11xx_allocate_buffers(struct usb_stk11xx *)
Allocate all ISOC buffers.
Definition: stk11xx-buf.c:128
int webcam_type
Definition: stk11xx.h:325