#include <linux/ihex.h>
#include "usbvideo.h"
-// #define VICAM_DEBUG
+/* #define VICAM_DEBUG */
#ifdef VICAM_DEBUG
-#define ADBG(lineno,fmt,args...) printk(fmt, jiffies, __func__, lineno, ##args)
-#define DBG(fmt,args...) ADBG((__LINE__),KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt,##args)
+#define ADBG(lineno, fmt, args...) printk(fmt, jiffies, __func__, lineno, ##args)
+#define DBG(fmt, args...) ADBG((__LINE__), KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt, ##args)
#else
-#define DBG(fmn,args...) do {} while(0)
+#define DBG(fmn, args...) do {} while (0)
#endif
#define DRIVER_AUTHOR "Joe Burks, jburks@wavicle.org"
}
struct vicam_camera {
- u16 shutter_speed; // capture shutter speed
- u16 gain; // capture gain
+ u16 shutter_speed; /* capture shutter speed */
+ u16 gain; /* capture gain */
- u8 *raw_image; // raw data captured from the camera
- u8 *framebuf; // processed data in RGB24 format
- u8 *cntrlbuf; // area used to send control msgs
+ u8 *raw_image; /* raw data captured from the camera */
+ u8 *framebuf; /* processed data in RGB24 format */
+ u8 *cntrlbuf; /* area used to send control msgs */
- struct video_device vdev; // v4l video device
- struct usb_device *udev; // usb device
+ struct video_device vdev; /* v4l video device */
+ struct usb_device *udev; /* usb device */
/* guard against simultaneous accesses to the camera */
struct mutex cam_lock;
int needsDummyRead;
};
-static int vicam_probe( struct usb_interface *intf, const struct usb_device_id *id);
+static int vicam_probe(struct usb_interface *intf, const struct usb_device_id *id);
static void vicam_disconnect(struct usb_interface *intf);
static void read_frame(struct vicam_camera *cam, int framenum);
static void vicam_decode_color(const u8 *, u8 *);
{
int status;
- if ((status = send_control_msg(cam, 0x50, state, 0, NULL, 0)) < 0)
+ status = send_control_msg(cam, 0x50, state, 0, NULL, 0));
+ if (status < 0)
return status;
- if (state) {
+ if (state)
send_control_msg(cam, 0x55, 1, 0, NULL, 0);
- }
return 0;
}
{
struct video_picture vp;
DBG("VIDIOCGPICT\n");
- memset(&vp, 0, sizeof (struct video_picture));
+ memset(&vp, 0, sizeof(struct video_picture));
vp.brightness = cam->gain << 8;
vp.depth = 24;
vp.palette = VIDEO_PALETTE_RGB24;
- if (copy_to_user(user_arg, &vp, sizeof (struct video_picture)))
+ if (copy_to_user(user_arg, &vp, sizeof(struct video_picture)))
retval = -EFAULT;
break;
}
if (copy_to_user(user_arg, (void *)&vw, sizeof(vw)))
retval = -EFAULT;
- // I'm not sure what the deal with a capture window is, it is very poorly described
- // in the doc. So I won't support it now.
+ /* I'm not sure what the deal with a capture window is, it is very poorly described
+ * in the doc. So I won't support it now. */
break;
}
DBG("VIDIOCSWIN %d x %d\n", vw.width, vw.height);
- if ( vw.width != 320 || vw.height != 240 )
+ if (vw.width != 320 || vw.height != 240)
retval = -EFAULT;
break;
int i;
DBG("VIDIOCGMBUF\n");
- memset(&vm, 0, sizeof (vm));
+ memset(&vm, 0, sizeof(vm));
vm.size =
VICAM_MAX_FRAME_SIZE * VICAM_FRAMES;
vm.frames = VICAM_FRAMES;
case VIDIOCMCAPTURE:
{
struct video_mmap vm;
- // int video_size;
+ /* int video_size; */
if (copy_from_user((void *)&vm, user_arg, sizeof(vm))) {
retval = -EFAULT;
break;
}
- DBG("VIDIOCMCAPTURE frame=%d, height=%d, width=%d, format=%d.\n",vm.frame,vm.width,vm.height,vm.format);
+ DBG("VIDIOCMCAPTURE frame=%d, height=%d, width=%d, format=%d.\n",
+ vm.frame, vm.width, vm.height, vm.format);
- if ( vm.frame >= VICAM_FRAMES || vm.format != VIDEO_PALETTE_RGB24 )
+ if (vm.frame >= VICAM_FRAMES || vm.format != VIDEO_PALETTE_RGB24)
retval = -EINVAL;
- // in theory right here we'd start the image capturing
- // (fill in a bulk urb and submit it asynchronously)
- //
- // Instead we're going to do a total hack job for now and
- // retrieve the frame in VIDIOCSYNC
+ /* in theory right here we'd start the image capturing
+ * (fill in a bulk urb and submit it asynchronously)
+ *
+ * Instead we're going to do a total hack job for now and
+ * retrieve the frame in VIDIOCSYNC */
break;
}
read_frame(cam, frame);
vicam_decode_color(cam->raw_image,
cam->framebuf +
- frame * VICAM_MAX_FRAME_SIZE );
+ frame * VICAM_MAX_FRAME_SIZE);
break;
}
mutex_unlock(&cam->cam_lock);
- // First upload firmware, then turn the camera on
+ /* First upload firmware, then turn the camera on */
if (!cam->is_initialized) {
initialize_camera(cam);
mutex_unlock(&cam->cam_lock);
- if (!open_count && !udev) {
+ if (!open_count && !udev)
kfree(cam);
- }
return 0;
}
data += VICAM_HEADER_SIZE;
- for( i = 0; i < 240; i++, data += 512 ) {
- const int y = ( i * 242 ) / 240;
+ for (i = 0; i < 240; i++, data += 512) {
+ const int y = (i * 242) / 240;
int j, prevX, nextX;
int Y, Cr, Cb;
- if ( y == 242 - 1 ) {
+ if (y == 242 - 1)
nextY = -512;
- }
prevX = 1;
nextX = 1;
- for ( j = 0; j < 320; j++, rgb += 3 ) {
- const int x = ( j * 512 ) / 320;
+ for (j = 0; j < 320; j++, rgb += 3) {
+ const int x = (j * 512) / 320;
const u8 * const src = &data[x];
- if ( x == 512 - 1 ) {
+ if (x == 512 - 1)
nextX = -1;
- }
- Cr = ( src[prevX] - src[0] ) +
- ( src[nextX] - src[0] );
+ Cr = (src[prevX] - src[0]) +
+ (src[nextX] - src[0]);
Cr /= 2;
- Cb = ( src[prevY] - src[prevX + prevY] ) +
- ( src[prevY] - src[nextX + prevY] ) +
- ( src[nextY] - src[prevX + nextY] ) +
- ( src[nextY] - src[nextX + nextY] );
+ Cb = (src[prevY] - src[prevX + prevY]) +
+ (src[prevY] - src[nextX + prevY]) +
+ (src[nextY] - src[prevX + nextY]) +
+ (src[nextY] - src[nextX + nextY]);
Cb /= 4;
- Y = 1160 * ( src[0] + ( Cr / 2 ) - 16 );
+ Y = 1160 * (src[0] + (Cr / 2) - 16);
- if ( i & 1 ) {
+ if (i & 1) {
int Ct = Cr;
Cr = Cb;
Cb = Ct;
}
- if ( ( x ^ i ) & 1 ) {
+ if ((x ^ i) & 1) {
Cr = -Cr;
Cb = -Cb;
}
- rgb[0] = clamp( ( ( Y + ( 2017 * Cb ) ) +
- 500 ) / 900, 0, 255 );
- rgb[1] = clamp( ( ( Y - ( 392 * Cb ) -
- ( 813 * Cr ) ) +
- 500 ) / 1000, 0, 255 );
- rgb[2] = clamp( ( ( Y + ( 1594 * Cr ) ) +
- 500 ) / 1300, 0, 255 );
+ rgb[0] = clamp(((Y + (2017 * Cb)) +
+ 500) / 900, 0, 255);
+ rgb[1] = clamp(((Y - (392 * Cb) -
+ (813 * Cr)) +
+ 500) / 1000, 0, 255);
+ rgb[2] = clamp(((Y + (1594 * Cr)) +
+ 500) / 1300, 0, 255);
prevX = -1;
}
}
memset(request, 0, 16);
- request[0] = cam->gain; // 0 = 0% gain, FF = 100% gain
+ request[0] = cam->gain; /* 0 = 0% gain, FF = 100% gain */
- request[1] = 0; // 512x242 capture
+ request[1] = 0; /* 512x242 capture */
- request[2] = 0x90; // the function of these two bytes
- request[3] = 0x07; // is not yet understood
+ request[2] = 0x90; /* the function of these two bytes */
+ request[3] = 0x07; /* is not yet understood */
if (cam->shutter_speed > 60) {
- // Short exposure
+ /* Short exposure */
realShutter =
((-15631900 / cam->shutter_speed) + 260533) / 1000;
request[4] = realShutter & 0xFF;
request[6] = 0x03;
request[7] = 0x01;
} else {
- // Long exposure
+ /* Long exposure */
realShutter = 15600 / cam->shutter_speed - 1;
request[4] = 0;
request[5] = 0;
request[7] = realShutter >> 8;
}
- // Per John Markus Bjørndalen, byte at index 8 causes problems if it isn't 0
+ /* Per John Markus Bjørndalen, byte at index 8 causes problems if it isn't 0*/
request[8] = 0;
- // bytes 9-15 do not seem to affect exposure or image quality
+ /* bytes 9-15 do not seem to affect exposure or image quality */
mutex_lock(&cam->cam_lock);
- if (!cam->udev) {
+ if (!cam->udev)
goto done;
- }
n = __send_control_msg(cam, 0x51, 0x80, 0, request, 16);
}
static ssize_t
-vicam_read( struct file *file, char __user *buf, size_t count, loff_t *ppos )
+vicam_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
struct vicam_camera *cam = file->private_data;
count = min_t(size_t, count, VICAM_MAX_FRAME_SIZE - *ppos);
- if (copy_to_user(buf, &cam->framebuf[*ppos], count)) {
+ if (copy_to_user(buf, &cam->framebuf[*ppos], count))
count = -EFAULT;
- } else {
+ else
*ppos += count;
- }
- if (count == VICAM_MAX_FRAME_SIZE) {
+ if (count == VICAM_MAX_FRAME_SIZE)
*ppos = 0;
- }
return count;
}
static int
vicam_mmap(struct file *file, struct vm_area_struct *vma)
{
- // TODO: allocate the raw frame buffer if necessary
+ /* TODO: allocate the raw frame buffer if necessary */
unsigned long page, pos;
unsigned long start = vma->vm_start;
unsigned long size = vma->vm_end-vma->vm_start;
};
static struct video_device vicam_template = {
- .name = "ViCam-based USB Camera",
- .fops = &vicam_fops,
- .release = video_device_release_empty,
+ .name = "ViCam-based USB Camera",
+ .fops = &vicam_fops,
+ .release = video_device_release_empty,
};
/* table of devices that work with this driver */
* this driver might be interested in.
*/
static int
-vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
+vicam_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev(intf);
int bulkEndpoint = 0;
"No bulk in endpoint was found ?! (this is bad)\n");
}
- if ((cam =
- kzalloc(sizeof (struct vicam_camera), GFP_KERNEL)) == NULL) {
+ cam = kzalloc(sizeof(struct vicam_camera), GFP_KERNEL);
+ if (cam == NULL) {
printk(KERN_WARNING
"could not allocate kernel memory for vicam_camera struct\n");
return -ENOMEM;
printk(KERN_INFO "ViCam webcam driver now controlling device %s\n",
video_device_node_name(&cam->vdev));
- usb_set_intfdata (intf, cam);
+ usb_set_intfdata(intf, cam);
return 0;
}
vicam_disconnect(struct usb_interface *intf)
{
int open_count;
- struct vicam_camera *cam = usb_get_intfdata (intf);
- usb_set_intfdata (intf, NULL);
+ struct vicam_camera *cam = usb_get_intfdata(intf);
+ usb_set_intfdata(intf, NULL);
/* we must unregister the device before taking its
* cam_lock. This is because the video open call
mutex_unlock(&cam->cam_lock);
- if (!open_count) {
+ if (!open_count)
kfree(cam);
- }
printk(KERN_DEBUG "ViCam-based WebCam disconnected\n");
}