xref: /haiku/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.h (revision 9d6d3fcf5fe8308cd020cecf89dede440346f8c4)
1 #ifndef _SONIX_CAM_DEVICE_H
2 #define _SONIX_CAM_DEVICE_H
3 
4 #include "CamDevice.h"
5 
6 #define SN9C102_REG_COUNT	0x20
7 /* SN9c102 registers */
8 #define SN9C102_ASIC_ID		0x00
9 #define SN9C102_CHIP_CTRL	0x01
10 #define SN9C102_GPIO			0x02
11 #define SN9C102_I2C_SETUP	0x08
12 #define SN9C102_I2C_SLAVE_ID	0x09
13 #define SN9C102_I2C_DATA0	0x0a
14 #define SN9C102_I2C_DATA1	0x0b
15 #define SN9C102_I2C_DATA2	0x0c
16 #define SN9C102_I2C_DATA3	0x0d
17 #define SN9C102_I2C_DATA4	0x0e
18 #define SN9C102_CONTROL_STAT	0x0f /*I2C ??*/
19 #define SN9C102_R_B_GAIN		0x10
20 #define SN9C102_G_GAIN		0x11 /* Green channel gain control. -> Gain = (1+G_GAIN/8)
21 							    Note: It is sync with VSYNC */
22 #define SN9C102_H_START		0x12 /* Start active pixel number after H­sync of sensor
23 							    Note:
24 							    The 1st line sequence of image data is BGBGBG
25 							    The 2nd line sequence of image data is GRGRGR */
26 #define SN9C102_V_START		0x13 /* Start active line number after V­sync of sensor */
27 #define SN9C102_OFFSET		0x14 /* Offset adjustment for sensor image data. */
28 #define SN9C102_H_SIZE		0x15 /* Horizontal pixel number for sensor. */
29 #define SN9C102_V_SIZE		0x16 /* Vertical pixel number for sensor. */
30 #define SN9C102_CLOCK_SEL	0x17
31 #define SN9C102_SYNC_N_SCALE	0x18
32 #define SN9C102_PIX_CLK		0x19
33 #define SN9C102_HO_SIZE		0x1a /* /32 */
34 #define SN9C102_VO_SIZE		0x1b /* /32 */
35 #define SN9C102_AE_STRX		0x1c
36 #define SN9C102_AE_STRY		0x1d
37 #define SN9C102_AE_ENDX		0x1e
38 #define SN9C102_AE_ENDY		0x1f
39 
40 // This class represents each webcam
41 class SonixCamDevice : public CamDevice
42 {
43 	public:
44 						SonixCamDevice(CamDeviceAddon &_addon, BUSBDevice* _device);
45 						~SonixCamDevice();
46 	virtual bool		SupportsBulk();
47 	virtual bool		SupportsIsochronous();
48 	virtual status_t	StartTransfer();
49 	virtual status_t	StopTransfer();
50 
51 	// generic register-like access
52 	virtual ssize_t		WriteReg(uint16 address, uint8 *data, size_t count=1);
53 	virtual ssize_t		ReadReg(uint16 address, uint8 *data, size_t count=1, bool cached=false);
54 
55 	// I2C-like access
56 	virtual status_t	GetStatusIIC();
57 	virtual status_t	WaitReadyIIC();
58 	virtual ssize_t		WriteIIC(uint8 address, uint8 *data, size_t count=1);
59 	virtual ssize_t		ReadIIC(uint8 address, uint8 *data);
60 
61 	virtual status_t	SetVideoFrame(BRect rect);
62 	virtual status_t	SetScale(float scale);
63 	virtual status_t	SetVideoParams(float brightness, float contrast, float hue, float red, float green, float blue);
64 
65 	// for use by deframer
66 	virtual size_t		MinRawFrameSize();
67 	virtual size_t		MaxRawFrameSize();
68 	virtual bool		ValidateStartOfFrameTag(const uint8 *tag, size_t taglen);
69 	virtual bool		ValidateEndOfFrameTag(const uint8 *tag, size_t taglen, size_t datalen);
70 
71 	virtual status_t	GetFrameBitmap(BBitmap **bm);
72 	virtual status_t	FillFrameBuffer(BBuffer *buffer);
73 
74 
75 	void				DumpRegs();
76 
77 	private:
78 	status_t			SendCommand(uint8 dir, uint8 request, uint16 value,
79 									uint16 index, uint16 length, void* data);
80 	uint8				fCachedRegs[SN9C102_REG_COUNT];
81 	int					fChipVersion;
82 
83 	int					fFrameTagState;
84 };
85 
86 // the addon itself, that instanciate
87 
88 class SonixCamDeviceAddon : public CamDeviceAddon
89 {
90 	public:
91 						SonixCamDeviceAddon(WebCamMediaAddOn* webcam);
92 	virtual 			~SonixCamDeviceAddon();
93 
94 	virtual const char	*BrandName();
95 	virtual SonixCamDevice	*Instantiate(CamRoster &roster, BUSBDevice *from);
96 
97 };
98 
99 
100 
101 #endif /* _SONIX_CAM_DEVICE_H */
102