2 * Copyright 2004-2008, François Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
6 #include <ParameterWeb.h>
10 #include "addons/sonix/SonixCamDevice.h"
17 class TAS5130D1BSensor
: public CamSensor
{
19 TAS5130D1BSensor(CamDevice
*_camera
);
21 virtual status_t
Probe();
22 virtual status_t
Setup();
24 virtual bool Use400kHz() const { return false; };
25 virtual bool UseRealIIC() const { return false; };
26 virtual uint8
IICReadAddress() const { return 0x00; };
27 virtual uint8
IICWriteAddress() const { return 0x11; /*0xff;*/ };
29 virtual int MaxWidth() const { return 640; };
30 virtual int MaxHeight() const { return 480; };
32 virtual status_t
AcceptVideoFrame(uint32
&width
, uint32
&height
);
33 virtual status_t
SetVideoFrame(BRect rect
);
34 virtual void AddParameters(BParameterGroup
*group
, int32
&firstID
);
35 virtual status_t
GetParameterValue(int32 id
, bigtime_t
*last_change
, void *value
, size_t *size
);
36 virtual status_t
SetParameterValue(int32 id
, bigtime_t when
, const void *value
, size_t size
);
44 TAS5130D1BSensor::TAS5130D1BSensor(CamDevice
*_camera
)
47 fIsSonix
= (dynamic_cast<SonixCamDevice
*>(_camera
) != NULL
);
51 PRINT((CH
": unknown camera device!" CT
));
54 fGain
= (float)0x40; // default
58 TAS5130D1BSensor::~TAS5130D1BSensor()
64 TAS5130D1BSensor::Probe()
73 TAS5130D1BSensor::Setup()
79 Device()->PowerOnSensor(false);
80 Device()->PowerOnSensor(true);
83 // linux driver seems to do this, but doesn't say why
84 Device()->WriteReg8(SN9C102_CHIP_CTRL
, 0x01); /* power down the sensor */
85 Device()->WriteReg8(SN9C102_CLOCK_SEL
, 0x20); /* enable sensor clk */
86 Device()->WriteReg8(SN9C102_CHIP_CTRL
, 0x04); /* power up the sensor, enable tx, sysclk@12MHz */
87 Device()->WriteReg8(SN9C102_R_B_GAIN
, 0x01); /* red gain = 1+0/8 = 1, red gain = 1+1/8 !!? */
88 Device()->WriteReg8(SN9C102_G_GAIN
, 0x00); /* green gain = 1+0/8 = 1 */
89 Device()->WriteReg8(SN9C102_OFFSET
, 0x0a); /* 0 pix offset */
90 Device()->WriteReg8(SN9C102_CLOCK_SEL
, 0x60); /* enable sensor clk, and invert it */
91 Device()->WriteReg8(SN9C102_SYNC_N_SCALE
, 0x06); /* no compression, normal curve,
92 * no scaling, vsync active low,
93 * v/hsync change at rising edge,
94 * raising edge of sensor pck */
95 Device()->WriteReg8(SN9C102_PIX_CLK
, 0xf3); /* pixclk = masterclk, sensor is slave mode */
100 //sonix_i2c_write_multi(dev, dev->sensor->i2c_wid, 2, 0xc0, 0x80, 0, 0, 0); /* AEC = 0x203 ??? */
102 Device()->WriteIIC8(0xc0, 0x80); /* AEC = 0x203 ??? */
106 Device()->WriteIIC8(0x20, 0xf6 - 0xd0); /* GAIN */
107 Device()->WriteIIC8(0x40, 0x47 - 0x40); /* Exposure */
109 Device()->WriteReg8(SN9C102_H_SIZE
, 104);
110 Device()->WriteReg8(SN9C102_V_SIZE
, 12);
111 SetVideoFrame(BRect(0, 0, 320-1, 240-1));
116 Device()->WriteIIC8(0xc0, 0x80); /* AEC = 0x203 ??? */
117 Device()->WriteReg8(SN9C102_H_SIZE
, 69);
118 Device()->WriteReg8(SN9C102_V_SIZE
, 9);
119 SetVideoFrame(BRect(0, 0, 352-1, 288-1));
124 //Device()->SetScale(1);
131 TAS5130D1BSensor::Name()
133 return "TASC tas5130d1b";
138 TAS5130D1BSensor::AcceptVideoFrame(uint32
&width
, uint32
&height
)
140 // default sanity checks
141 status_t err
= CamSensor::AcceptVideoFrame(width
, height
);
154 TAS5130D1BSensor::SetVideoFrame(BRect rect
)
158 Device()->WriteReg8(SN9C102_H_START
, /*rect.left + */104);
159 Device()->WriteReg8(SN9C102_V_START
, /*rect.top + */12);
160 Device()->WriteReg8(SN9C102_PIX_CLK
, 0xfb);
161 Device()->WriteReg8(SN9C102_HO_SIZE
, 0x14);
162 Device()->WriteReg8(SN9C102_VO_SIZE
, 0x0a);
164 Device()->WriteReg8(SN9C102_H_START
, /*rect.left + */104);
165 Device()->WriteReg8(SN9C102_V_START
, /*rect.top + */12);
166 Device()->WriteReg8(SN9C102_PIX_CLK
, 0xf3);
167 Device()->WriteReg8(SN9C102_HO_SIZE
, 0x1f);
168 Device()->WriteReg8(SN9C102_VO_SIZE
, 0x1a);
171 /* HACK: TEST IMAGE */
172 //Device()->WriteReg8(SN9C102_CLOCK_SEL, 0x70); /* enable sensor clk, and invert it, test img */
181 TAS5130D1BSensor::AddParameters(BParameterGroup
*group
, int32
&index
)
183 BContinuousParameter
*p
;
184 CamSensor::AddParameters(group
, index
);
188 BParameterGroup
*g
= group
->MakeGroup("global gain");
189 p
= g
->MakeContinuousParameter(index
++,
190 B_MEDIA_RAW_VIDEO
, "global gain",
191 B_GAIN
, "", (float)0x00, (float)0xf6, (float)1);
197 TAS5130D1BSensor::GetParameterValue(int32 id
, bigtime_t
*last_change
, void *value
, size_t *size
)
200 if (id
== fFirstParameterID
) {
201 *size
= sizeof(float);
202 *((float *)value
) = fGain
;
203 *last_change
= fLastParameterChanges
;
211 TAS5130D1BSensor::SetParameterValue(int32 id
, bigtime_t when
, const void *value
, size_t size
)
214 if (id
== fFirstParameterID
) {
215 if (!value
|| (size
!= sizeof(float)))
217 if (*(float *)value
== fGain
)
219 fGain
= *(float *)value
;
220 fLastParameterChanges
= when
;
221 PRINT((CH
": gain: %f" CT
, fGain
));
225 //Device()->WriteIIC8(0x20, (uint8)0xf6 - (uint8)fGain);
226 // but it doesn't seem to work
228 // works, not sure why yet, XXX check datasheet for AEG/AEC
229 uint8 buf
[2] = { 0x20, 0x70 };
230 buf
[1] = (uint8
)0xff - (uint8
)fGain
;
231 Device()->WriteIIC(0x02, buf
, 2);
241 B_WEBCAM_DECLARE_SENSOR(TAS5130D1BSensor
, tas5130d1b
)