2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
6 #include "QuickCamDevice.h"
11 const usb_webcam_support_descriptor kSupportedDevices
[] = {
12 {{ 0, 0, 0, 0x046d, 0x0840 }, "Logitech", "QuickCam Express", NULL
},
13 {{ 0, 0, 0, 0x046d, 0x0850 }, "Logitech", "QuickCam Express LEGO", NULL
},
14 {{ 0, 0, 0, 0, 0}, NULL
, NULL
, NULL
}
19 QuickCamDevice::QuickCamDevice(CamDeviceAddon
&_addon
, BUSBDevice
* _device
)
20 :CamDevice(_addon
, _device
)
24 // linux seems to infer this sets I2C controller to 8 or 16 bit mode...
25 // sensors will set to the mode they want when probing
29 // reset I2C mode to 8 bit as linux driver does
31 // not much we can do anyway
38 QuickCamDevice::~QuickCamDevice()
45 QuickCamDevice::SupportsBulk()
52 QuickCamDevice::SupportsIsochronous()
59 QuickCamDevice::StartTransfer()
63 SetVideoFrame(BRect(0, 0, Sensor()->MaxWidth()-1, Sensor()->MaxHeight()-1));
65 //SetVideoFrame(BRect(0, 0, 320-1, 240-1));
69 err
= ReadReg(SN9C102_CHIP_CTRL
, &r
, 1, true);
73 err
= WriteReg8(SN9C102_CHIP_CTRL
, r
);
77 return CamDevice::StartTransfer();
82 QuickCamDevice::StopTransfer()
87 err
= CamDevice::StopTransfer();
91 err
= ReadReg(SN9C102_CHIP_CTRL
, &r
, 1, true);
95 err
= WriteReg8(SN9C102_CHIP_CTRL
, r
);
104 QuickCamDevice::WriteReg(uint16 address
, uint8
*data
, size_t count
)
106 PRINT((CH
"(%u, @%p, %u)" CT
, address
, data
, count
));
107 return SendCommand(USB_REQTYPE_DEVICE_OUT
, 0x04, address
, 0, count
, data
);
112 QuickCamDevice::ReadReg(uint16 address
, uint8
*data
, size_t count
, bool cached
)
114 PRINT((CH
"(%u, @%p, %u, %d)" CT
, address
, data
, count
, cached
));
115 memset(data
, 0xaa, count
); // linux drivers do that without explaining why !?
116 return SendCommand(USB_REQTYPE_DEVICE_IN
, 0x04, address
, 0, count
, data
);
121 QuickCamDevice::GetStatusIIC()
123 status_t err
= B_ERROR
;
126 //dprintf(ID "i2c_status: error 0x%08lx, status = %02x\n", err, status);
129 return (status
&0x08)?EIO
:0;
134 QuickCamDevice::WaitReadyIIC()
142 QuickCamDevice::WriteIIC(uint8 address
, uint8
*data
, size_t count
)
148 memset(buffer
, 0, sizeof(buffer
));
149 buffer
[0x20] = Sensor() ? Sensor()->IICWriteAddress() : 0;
150 buffer
[0x21] = count
- 1;
152 for (i
= 0; i
< count
; i
++) {
153 buffer
[i
] = address
+ i
;
154 buffer
[i
+16] = data
[i
];
156 return SendCommand(USB_REQTYPE_DEVICE_OUT
, 0x04, STV_I2C_WRITE
, 0, 0x23, buffer
);
161 QuickCamDevice::ReadIIC(uint8 address
, uint8
*data
)
163 return ReadIIC(address
, data
);
168 QuickCamDevice::ReadIIC8(uint8 address
, uint8
*data
)
172 memset(buffer
, 0, sizeof(buffer
));
173 buffer
[0x20] = Sensor() ? Sensor()->IICReadAddress() : 0;
174 buffer
[0x21] = 1 - 1;
177 err
= SendCommand(USB_REQTYPE_DEVICE_OUT
, 0x04, STV_I2C_WRITE
, 0, 0x23, buffer
);
178 PRINT((CH
": SendCommand: %s" CT
, strerror(err
)));
183 err
= SendCommand(USB_REQTYPE_DEVICE_IN
, 0x04, STV_I2C_READ
, 0, 0x1, buffer
);
184 PRINT((CH
": SendCommand: %s" CT
, strerror(err
)));
189 PRINT((CH
": 0x%02x" CT
, *data
));
195 QuickCamDevice::ReadIIC16(uint8 address
, uint16
*data
)
199 memset(buffer
, 0, sizeof(buffer
));
200 buffer
[0x20] = Sensor() ? Sensor()->IICReadAddress() : 0;
201 buffer
[0x21] = 1 - 1;
204 err
= SendCommand(USB_REQTYPE_DEVICE_OUT
, 0x04, STV_I2C_WRITE
, 0, 0x23, buffer
);
210 err
= SendCommand(USB_REQTYPE_DEVICE_IN
, 0x04, STV_I2C_READ
, 0, 0x2, buffer
);
211 PRINT((CH
": SendCommand: %s" CT
, strerror(err
)));
215 if (fChipIsBigEndian
)
216 *data
= B_HOST_TO_BENDIAN_INT16(*(uint16
*)(&buffer
[0]));
218 *data
= B_HOST_TO_LENDIAN_INT16(*(uint16
*)(&buffer
[0]));
219 PRINT((CH
": 0x%04x" CT
, *data
));
225 QuickCamDevice::SetIICBitsMode(size_t bits
)
229 WriteReg8(STV_REG23
, 0);
232 WriteReg8(STV_REG23
, 1);
242 QuickCamDevice::SendCommand(uint8 dir
, uint8 request
, uint16 value
,
243 uint16 index
, uint16 length
, void* data
)
248 if (length
> GetDevice()->MaxEndpoint0PacketSize())
250 ret
= GetDevice()->ControlTransfer(
251 USB_REQTYPE_VENDOR
| dir
,
252 request
, value
, index
, length
, data
);
257 QuickCamDeviceAddon::QuickCamDeviceAddon(WebCamMediaAddOn
* webcam
)
258 : CamDeviceAddon(webcam
)
260 SetSupportedDevices(kSupportedDevices
);
264 QuickCamDeviceAddon::~QuickCamDeviceAddon()
270 QuickCamDeviceAddon::BrandName()
277 QuickCamDeviceAddon::Instantiate(CamRoster
&roster
, BUSBDevice
*from
)
279 return new QuickCamDevice(*this, from
);
284 B_WEBCAM_MKINTFUNC(quickcam
)
285 (WebCamMediaAddOn
* webcam
, CamDeviceAddon
**addon
)
287 *addon
= new QuickCamDeviceAddon(webcam
);