xref: /haiku/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.h (revision c9ad965c81b08802fed0827fd1dd16f45297928a)
1 /*
2  * Copyright 2004-2008, François Revol, <revol@free.fr>.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _SONIX_CAM_DEVICE_H
6 #define _SONIX_CAM_DEVICE_H
7 
8 #include "CamDevice.h"
9 
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 H­sync of sensor
30 							    Note:
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 V­sync 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
46 
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
52 
53 
54 #define SN9C102_RGB_GAIN_MAX	0x7f
55 
56 // This class represents each webcam
57 class SonixCamDevice : public CamDevice
58 {
59 	public:
60 						SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
61 						~SonixCamDevice();
62 	virtual bool		SupportsBulk();
63 	virtual bool		SupportsIsochronous();
64 	virtual status_t	StartTransfer();
65 	virtual status_t	StopTransfer();
66 
67 	// sensor chip handling
68 	virtual status_t	PowerOnSensor(bool on);
69 
70 	// generic register-like access
71 	virtual ssize_t		WriteReg(uint16 address, uint8 *data, size_t count=1);
72 	virtual ssize_t		ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
73 
74 	// I2C-like access
75 	virtual status_t	GetStatusIIC();
76 	virtual status_t	WaitReadyIIC();
77 	virtual ssize_t		WriteIIC(uint8 address, uint8 *data, size_t count=1);
78 	virtual ssize_t		ReadIIC(uint8 address, uint8 *data);
79 
80 	virtual status_t	SetVideoFrame(BRect rect);
81 	virtual status_t	SetScale(float scale);
82 	virtual status_t	SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue);
83 
84 	virtual void		AddParameters(BParameterGroup *group, int32 &index);
85 	virtual status_t	GetParameterValue(int32 id, bigtime_t *last_change, void *value, size_t *size);
86 	virtual status_t	SetParameterValue(int32 id, bigtime_t when, const void *value, size_t size);
87 
88 
89 	// for use by deframer
90 	virtual size_t		MinRawFrameSize();
91 	virtual size_t		MaxRawFrameSize();
92 	virtual bool		ValidateStartOfFrameTag(const uint8 *tag, size_t taglen);
93 	virtual bool		ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen);
94 
95 	virtual status_t	GetFrameBitmap(BBitmap **bm, bigtime_t *stamp=NULL);
96 	virtual status_t	FillFrameBuffer(BBuffer *buffer, bigtime_t *stamp=NULL);
97 
98 
99 	void				DumpRegs();
100 
101 	private:
102 //	status_t			SendCommand(uint8 dir, uint8 request, uint16 value,
103 //									uint16 index, uint16 length, void* data);
104 	uint8				fCachedRegs[SN9C102_REG_COUNT];
105 	int					fChipVersion;
106 
107 	int					fFrameTagState;
108 
109 	uint8				fRGain;
110 	uint8				fGGain;
111 	uint8				fBGain;
112 	float				fContrast;
113 	float				fBrightness;
114 };
115 
116 // the addon itself, that instanciate
117 
118 class SonixCamDeviceAddon : public CamDeviceAddon
119 {
120 	public:
121 						SonixCamDeviceAddon(WebCamMediaAddOn* webcam);
122 	virtual 			~SonixCamDeviceAddon();
123 
124 	virtual const char	*BrandName();
125 	virtual SonixCamDevice	*Instantiate(CamRoster &roster, BUSBDevice *from);
126 
127 };
128 
129 
130 
131 #endif /* _SONIX_CAM_DEVICE_H */
132