2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
5 #ifndef _SONIX_CAM_DEVICE_H
6 #define _SONIX_CAM_DEVICE_H
10 #define SN9C102_REG_COUNT 0x20
11 /* SN9c102 registers */
12 #define SN9C102_ASIC_ID 0x00
13 #define SN9C102_CHIP_CTRL 0x01
14 #define SN9C102_GPIO 0x02
15 #define SN9C103_G_GAIN 0x04 /* chip version dependant! */
16 #define SN9C102_R_GAIN 0x05
17 #define SN9C102_B_GAIN 0x06
18 #define SN9C102_I2C_SETUP 0x08
19 #define SN9C102_I2C_SLAVE_ID 0x09
20 #define SN9C102_I2C_DATA0 0x0a
21 #define SN9C102_I2C_DATA1 0x0b
22 #define SN9C102_I2C_DATA2 0x0c
23 #define SN9C102_I2C_DATA3 0x0d
24 #define SN9C102_I2C_DATA4 0x0e
25 #define SN9C102_CONTROL_STAT 0x0f /*I2C ??*/
26 #define SN9C102_R_B_GAIN 0x10 /* datasheet says so but it's WRONG */
27 #define SN9C102_G_GAIN 0x11 /* Green channel gain control. -> Gain = (1+G_GAIN/8)
28 Note: It is sync with VSYNC */
29 #define SN9C102_H_START 0x12 /* Start active pixel number after Hsync of sensor
31 The 1st line sequence of image data is BGBGBG
32 The 2nd line sequence of image data is GRGRGR */
33 #define SN9C102_V_START 0x13 /* Start active line number after Vsync of sensor */
34 #define SN9C102_OFFSET 0x14 /* Offset adjustment for sensor image data. */
35 #define SN9C102_H_SIZE 0x15 /* Horizontal pixel number for sensor. */
36 #define SN9C102_V_SIZE 0x16 /* Vertical pixel number for sensor. */
37 #define SN9C102_CLOCK_SEL 0x17
38 #define SN9C102_SYNC_N_SCALE 0x18
39 #define SN9C102_PIX_CLK 0x19
40 #define SN9C102_HO_SIZE 0x1a /* /32 */
41 #define SN9C102_VO_SIZE 0x1b /* /32 */
42 #define SN9C102_AE_STRX 0x1c
43 #define SN9C102_AE_STRY 0x1d
44 #define SN9C102_AE_ENDX 0x1e
45 #define SN9C102_AE_ENDY 0x1f
47 // extra regs ? maybe 103 or later only ? used by gspcav1
48 #define SN9C10x_CONTRAST 0x84
49 #define SN9C10x_BRIGHTNESS 0x96
50 #undef SN9C102_REG_COUNT
51 #define SN9C102_REG_COUNT 0x100
54 #define SN9C102_RGB_GAIN_MAX 0x7f
56 // This class represents each webcam
57 class SonixCamDevice
: public CamDevice
{
59 SonixCamDevice(CamDeviceAddon
&_addon
, BUSBDevice
* _device
);
61 virtual bool SupportsBulk();
62 virtual bool SupportsIsochronous();
63 virtual status_t
StartTransfer();
64 virtual status_t
StopTransfer();
66 // sensor chip handling
67 virtual status_t
PowerOnSensor(bool on
);
69 // generic register-like access
70 virtual ssize_t
WriteReg(uint16 address
, uint8
*data
, size_t count
=1);
71 virtual ssize_t
ReadReg(uint16 address
, uint8
*data
, size_t count
=1, bool cached
=false);
74 virtual status_t
GetStatusIIC();
75 virtual status_t
WaitReadyIIC();
76 virtual ssize_t
WriteIIC(uint8 address
, uint8
*data
, size_t count
=1);
77 virtual ssize_t
ReadIIC(uint8 address
, uint8
*data
);
79 virtual status_t
SetVideoFrame(BRect rect
);
80 virtual status_t
SetScale(float scale
);
81 virtual status_t
SetVideoParams(float brightness
, float contrast
, float hue
, float red
, float green
, float blue
);
83 virtual void AddParameters(BParameterGroup
*group
, int32
&index
);
84 virtual status_t
GetParameterValue(int32 id
, bigtime_t
*last_change
, void *value
, size_t *size
);
85 virtual status_t
SetParameterValue(int32 id
, bigtime_t when
, const void *value
, size_t size
);
88 // for use by deframer
89 virtual size_t MinRawFrameSize();
90 virtual size_t MaxRawFrameSize();
91 virtual bool ValidateStartOfFrameTag(const uint8
*tag
, size_t taglen
);
92 virtual bool ValidateEndOfFrameTag(const uint8
*tag
, size_t taglen
, size_t datalen
);
94 virtual status_t
GetFrameBitmap(BBitmap
**bm
, bigtime_t
*stamp
=NULL
);
95 virtual status_t
FillFrameBuffer(BBuffer
*buffer
, bigtime_t
*stamp
=NULL
);
101 // status_t SendCommand(uint8 dir, uint8 request, uint16 value,
102 // uint16 index, uint16 length, void* data);
103 uint8 fCachedRegs
[SN9C102_REG_COUNT
];
115 // the addon itself, that instanciate
117 class SonixCamDeviceAddon
: public CamDeviceAddon
{
119 SonixCamDeviceAddon(WebCamMediaAddOn
* webcam
);
120 virtual ~SonixCamDeviceAddon();
122 virtual const char *BrandName();
123 virtual SonixCamDevice
*Instantiate(CamRoster
&roster
, BUSBDevice
*from
);
129 #endif /* _SONIX_CAM_DEVICE_H */