SyntekUSBVideoCamera

stk11xx.h

Go to the documentation of this file.
00001 
00034 #ifndef STK11XX_H
00035 #define STK11XX_H
00036 
00037 
00038 #define DRIVER_NAME                 "stk11xx"                   
00039 #define DRIVER_VERSION              "v2.0.0"                    
00040 #define DRIVER_VERSION_NUM          0x020000                    
00041 #define DRIVER_DESC                 "Syntek USB Video Camera"   
00042 #define DRIVER_AUTHOR               "Nicolas VIVIEN"            
00043 #define PREFIX                      DRIVER_NAME ": "            
00045 #define USB_SYNTEK1_VENDOR_ID       0x174f                      
00046 #define USB_SYNTEK2_VENDOR_ID       0x05e1                      
00048 #define USB_STK_A311_PRODUCT_ID     0xa311                      
00049 #define USB_STK_A821_PRODUCT_ID     0xa821                      
00050 #define USB_STK_6A31_PRODUCT_ID     0x6a31                      
00051 #define USB_STK_6A33_PRODUCT_ID     0x6a33                      
00052 #define USB_STK_6A51_PRODUCT_ID     0x6a51                      
00053 #define USB_STK_6A54_PRODUCT_ID     0x6a54                      
00054 #define USB_STK_6D51_PRODUCT_ID     0x6d51                      
00056 #define USB_STK_0501_PRODUCT_ID     0x0501                      
00065 #define VID_HARDWARE_STK11XX        88
00066 
00067 
00068 
00069 
00083 #define MAX_ISO_BUFS                16
00084 #define ISO_FRAMES_PER_DESC         10
00085 #define ISO_MAX_FRAME_SIZE          3 * 1024
00086 #define ISO_BUFFER_SIZE             (ISO_FRAMES_PER_DESC * ISO_MAX_FRAME_SIZE)
00087 
00088 
00096 #define STK11XX_MAX_IMAGES          10
00097 #define STK11XX_FRAME_SIZE          (1280 * 1024 * 4)
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00111 #define DRIVER_SUPPORT              "Syntek USB Camera : STK-1135"
00112 
00133 #ifndef CONFIG_STK11XX_DEBUG
00134 #define CONFIG_STK11XX_DEBUG            0
00135 #endif
00136 
00137 #if CONFIG_STK11XX_DEBUG
00138 
00139 #define STK_INFO(str, args...)          printk(KERN_INFO PREFIX str, ##args)
00140 #define STK_ERROR(str, args...)         printk(KERN_ERR PREFIX str, ##args)
00141 #define STK_WARNING(str, args...)       printk(KERN_WARNING PREFIX str, ##args)
00142 #define STK_DEBUG(str, args...)         printk(KERN_DEBUG PREFIX str, ##args)
00143 
00144 #else
00145 
00146 #define STK_INFO(str, args...)          printk(KERN_INFO PREFIX str, ##args)
00147 #define STK_ERROR(str, args...)         printk(KERN_ERR PREFIX str, ##args)
00148 #define STK_WARNING(str, args...)       printk(KERN_WARNING PREFIX str, ##args)
00149 #define STK_DEBUG(str, args...)         do { } while(0)
00150 
00151 #endif
00152 
00153 
00162 #ifndef CONFIG_STK11XX_DEBUG_STREAM
00163 #define CONFIG_STK11XX_DEBUG_STREAM     0
00164 #endif
00165 
00166 #if CONFIG_STK11XX_DEBUG_STREAM
00167 
00168 #define STK_STREAM(str, args...)        printk(KERN_DEBUG PREFIX str, ##args)
00169 
00170 #else
00171 
00172 #define STK_STREAM(str, args...)        do { } while(0)
00173 
00174 #endif
00175 
00176 
00177 
00181 typedef enum {
00182     SYNTEK_STK_M811 = 1,
00183     SYNTEK_STK_A311 = 2,
00184     SYNTEK_STK_A821 = 3,
00185     SYNTEK_STK_6A31 = 4,
00186     SYNTEK_STK_6A33 = 5,
00187     SYNTEK_STK_6A51 = 6,
00188     SYNTEK_STK_6A54 = 7,
00189     SYNTEK_STK_6D51 = 8
00190 } T_SYNTEK_DEVICE;
00191 
00192 
00196 typedef enum {
00197     STK11XX_VGA,                        
00198     STK11XX_SXGA,                       
00199     STK11XX_UXGA                        
00200 } T_STK11XX_VIDEOMODE;
00201 
00202 
00206 typedef enum {
00207     STK11XX_80x60,
00208     STK11XX_128x96,
00209     STK11XX_160x120,
00210     STK11XX_213x160,
00211     STK11XX_320x240,
00212     STK11XX_640x480,
00213     STK11XX_800x600,
00214     STK11XX_1024x768,
00215     STK11XX_1280x1024,
00216     STK11XX_NBR_SIZES
00217 } T_STK11XX_RESOLUTION;
00218 
00219 
00223 typedef enum {
00224     STK11XX_PALETTE_RGB24,
00225     STK11XX_PALETTE_RGB32,
00226     STK11XX_PALETTE_BGR24,
00227     STK11XX_PALETTE_BGR32,
00228     STK11XX_PALETTE_UYVY,
00229     STK11XX_PALETTE_YUYV
00230 } T_STK11XX_PALETTE;
00231 
00232 
00236 struct stk11xx_iso_buf {
00237     void *data;
00238     int length;
00239     int read;
00240     struct urb *urb;
00241 };
00242 
00243 
00247 struct stk11xx_frame_buf {
00248     int errors;
00249     void *data;
00250     volatile int filled;
00251     struct stk11xx_frame_buf *next;
00252 };
00253 
00254 
00258 struct stk11xx_image_buf {
00259     unsigned long offset;               
00260     int vma_use_count;                  
00261 };
00262 
00263 
00267 struct stk11xx_coord {
00268     int x;                              
00269     int y;                              
00270 };
00271 
00272 
00276 struct stk11xx_video {
00277     int fps;                            
00278     int brightness;                     
00279     int contrast;                       
00280     int whiteness;                      
00281     int colour;                         
00282     int depth;                          
00283     int palette;                        
00284     int hue;                            
00285     int hflip;                          
00286     int vflip;                          
00288     // default values for the device. Above are *current* values
00289     int default_brightness;
00290     int default_contrast;
00291     int default_colour;
00292     int default_whiteness;
00293     int default_hflip;
00294     int default_vflip;
00295 };
00296 
00297 
00301 struct usb_stk11xx {
00302     struct video_device *vdev;          
00303     struct usb_device *udev;            
00304     struct usb_interface *interface;    
00306     int release;                        
00307     int webcam_model;                   
00308     int webcam_type;                    
00310     unsigned char *int_in_buffer;       
00311     size_t int_in_size;                 
00312     __u8 int_in_endpointAddr;           
00314     size_t isoc_in_size;                
00315     __u8 isoc_in_endpointAddr;          
00317     int watchdog;                       
00319     struct stk11xx_video vsettings;     
00321     int error_status;
00322 
00323     int vopen;                          
00324     int visoc_errors;                   
00325     int vframes_error;                  
00326     int vframes_dumped;                 
00329     spinlock_t spinlock;                
00330     struct semaphore mutex;             
00331     wait_queue_head_t wait_frame;       
00332     struct mutex modlock;               
00335     // 1: isoc
00336     char isoc_init_ok;
00337     struct stk11xx_iso_buf isobuf[MAX_ISO_BUFS];
00338 
00339     // 2: frame
00340     int frame_size;
00341     struct stk11xx_frame_buf *framebuf;
00342     struct stk11xx_frame_buf *empty_frames, *empty_frames_tail;
00343     struct stk11xx_frame_buf *full_frames, *full_frames_tail;
00344     struct stk11xx_frame_buf *fill_frame;
00345     struct stk11xx_frame_buf *read_frame;
00346 
00347     // 3: image
00348     int view_size;
00349     int image_size;
00350     void *image_data;
00351     struct stk11xx_image_buf images[STK11XX_MAX_IMAGES];
00352     int image_used[STK11XX_MAX_IMAGES];
00353     unsigned int nbuffers;
00354     unsigned int len_per_image;
00355     int image_read_pos;
00356     int fill_image;
00357     int resolution;
00358     struct stk11xx_coord view;
00359     struct stk11xx_coord image;
00360 };
00361 
00362 
00367 #define STK11XX_PERCENT(x,y) ( ((int)x * (int)y) / 100)
00368 
00369 
00374 #define to_stk11xx_dev(d) container_of(d, struct usb_stk11xx, kref)
00375 
00376 
00377 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
00378 
00379     
00380 int usb_stk11xx_write_registry(struct usb_stk11xx *, __u16, __u16);
00381 int usb_stk11xx_read_registry(struct usb_stk11xx *, __u16, int *);
00382 int usb_stk11xx_set_feature(struct usb_stk11xx *, int);
00383 int usb_stk11xx_set_configuration(struct usb_stk11xx *);
00384 int usb_stk11xx_isoc_init(struct usb_stk11xx *);
00385 void usb_stk11xx_isoc_handler(struct urb *);
00386 void usb_stk11xx_isoc_cleanup(struct usb_stk11xx *);
00387 
00388 int dev_stk11xx_initialize_device(struct usb_stk11xx *);
00389 int dev_stk11xx_start_stream(struct usb_stk11xx *);
00390 int dev_stk11xx_stop_stream(struct usb_stk11xx *);
00391 int dev_stk11xx_check_device(struct usb_stk11xx *, int);
00392 int dev_stk11xx_camera_on(struct usb_stk11xx *);
00393 int dev_stk11xx_camera_off(struct usb_stk11xx *);
00394 int dev_stk11xx_camera_asleep(struct usb_stk11xx *);
00395 int dev_stk11xx_init_camera(struct usb_stk11xx *);
00396 int dev_stk11xx_reconf_camera(struct usb_stk11xx *);
00397 int dev_stk11xx_camera_settings(struct usb_stk11xx *);
00398 int dev_stk11xx_set_camera_quality(struct usb_stk11xx *);
00399 int dev_stk11xx_set_camera_fps(struct usb_stk11xx *);
00400 int dev_stk11xx_watchdog_camera(struct usb_stk11xx *);
00401 
00402 int v4l_stk11xx_select_video_mode(struct usb_stk11xx *, int, int);
00403 int v4l_stk11xx_register_video_device(struct usb_stk11xx *);
00404 int v4l_stk11xx_unregister_video_device(struct usb_stk11xx *);
00405 
00406 int stk11xx_create_sysfs_files(struct video_device *);
00407 void stk11xx_remove_sysfs_files(struct video_device *);
00408 
00409 int stk11xx_allocate_buffers(struct usb_stk11xx *);
00410 int stk11xx_reset_buffers(struct usb_stk11xx *);
00411 int stk11xx_clear_buffers(struct usb_stk11xx *);
00412 int stk11xx_free_buffers(struct usb_stk11xx *);
00413 void stk11xx_next_image(struct usb_stk11xx *);
00414 int stk11xx_next_frame(struct usb_stk11xx *);
00415 int stk11xx_handle_frame(struct usb_stk11xx *);
00416 
00417 int stk11xx_decompress(struct usb_stk11xx *);
00418 
00419 
00420 #endif