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"
12 //#define ENABLE_GAIN 1
15 class TAS5110C1BSensor
: public CamSensor
{
17 TAS5110C1BSensor(CamDevice
*_camera
);
19 virtual status_t
Probe();
20 virtual status_t
Setup();
22 virtual bool Use400kHz() const { return false; };
23 virtual bool UseRealIIC() const { return true /*false*/; };
24 virtual uint8
IICReadAddress() const { return 0x00; };
25 virtual uint8
IICWriteAddress() const { return 0x61; /*0x11;*/ /*0xff;*/ };
27 virtual int MaxWidth() const { return 352; };
28 virtual int MaxHeight() const { return 288; };
30 virtual status_t
AcceptVideoFrame(uint32
&width
, uint32
&height
);
31 virtual status_t
SetVideoFrame(BRect rect
);
32 virtual void AddParameters(BParameterGroup
*group
, int32
&firstID
);
33 virtual status_t
GetParameterValue(int32 id
, bigtime_t
*last_change
, void *value
, size_t *size
);
34 virtual status_t
SetParameterValue(int32 id
, bigtime_t when
, const void *value
, size_t size
);
42 TAS5110C1BSensor::TAS5110C1BSensor(CamDevice
*_camera
)
45 fIsSonix
= (dynamic_cast<SonixCamDevice
*>(_camera
) != NULL
);
49 PRINT((CH
": unknown camera device!" CT
));
52 fGain
= (float)0x40; // default
56 TAS5110C1BSensor::~TAS5110C1BSensor()
62 TAS5110C1BSensor::Probe()
71 TAS5110C1BSensor::Setup()
76 Device()->PowerOnSensor(false);
77 Device()->PowerOnSensor(true);
80 Device()->WriteReg8(SN9C102_CHIP_CTRL
, 0x01); /* power down the sensor */
81 Device()->WriteReg8(SN9C102_CHIP_CTRL
, 0x44); /* power up the sensor, enable tx, sysclk@24MHz */
82 Device()->WriteReg8(SN9C102_CHIP_CTRL
, 0x04); /* power up the sensor, enable tx, sysclk@24MHz */
83 Device()->WriteReg8(SN9C102_R_B_GAIN
, 0x00); /* red, blue gain = 1+0/8 = 1 */
84 Device()->WriteReg8(SN9C102_G_GAIN
, 0x00); /* green gain = 1+0/8 = 1 */
85 Device()->WriteReg8(SN9C102_OFFSET
, 0x0a); /* 10 pix offset */
86 Device()->WriteReg8(SN9C102_CLOCK_SEL
, 0x60); /* enable sensor clk, and invert it */
87 Device()->WriteReg8(SN9C102_CLOCK_SEL
, 0x60); /* enable sensor clk, and invert it */
88 Device()->WriteReg8(SN9C102_SYNC_N_SCALE
, 0x06); /* no compression, normal curve,
89 * no scaling, vsync active low,
90 * v/hsync change at rising edge,
91 * falling edge of sensor pck */
92 Device()->WriteReg8(SN9C102_PIX_CLK
, 0xfb); /* pixclk = 2 * masterclk, sensor is slave mode */
94 // some IIC stuff for the sensor
95 // though it seems more data is sent than told the controller
96 // this is what the XP driver sends to the ICECAM...
97 uint8 tmp_7
[] = { 0xb0, 0x61, 0x1c, 0xf8, 0x10, 0x00, 0x00, 0x16 };
98 Device()->WriteReg(SN9C102_I2C_SETUP
, tmp_7
, 8);
100 Device()->WriteReg8(SN9C102_PIX_CLK
, 0x4b);
102 uint8 tmp_8
[] = { 0xa0, 0x61, 0x1c, 0x0f, 0x10, 0x00, 0x00, 0x16 };
103 Device()->WriteReg(SN9C102_I2C_SETUP
, tmp_8
, 8);
110 //sonix_i2c_write_multi(dev, dev->sensor->i2c_wid, 2, 0xc0, 0x80, 0, 0, 0); /* AEC = 0x203 ??? */
111 //Device()->WriteIIC8(0xc0, 0x80); /* AEC = 0x203 ??? */
112 //Device()->WriteIIC8(0x1c, 0x80); /* AEC = 0x203 ??? */
115 Device()->WriteReg8(SN9C102_H_SIZE
, 69);
116 Device()->WriteReg8(SN9C102_V_SIZE
, 9);
117 SetVideoFrame(BRect(0, 0, 352-1, 288-1));
121 //Device()->SetScale(1);
128 TAS5110C1BSensor::Name()
130 return "TASC tas5110c1b";
135 TAS5110C1BSensor::AcceptVideoFrame(uint32
&width
, uint32
&height
)
137 // default sanity checks
138 status_t err
= CamSensor::AcceptVideoFrame(width
, height
);
151 TAS5110C1BSensor::SetVideoFrame(BRect rect
)
155 Device()->WriteReg8(SN9C102_H_START
, /*rect.left + */69);
156 Device()->WriteReg8(SN9C102_V_START
, /*rect.top + */9);
157 Device()->WriteReg8(SN9C102_PIX_CLK
, 0xfb);
158 Device()->WriteReg8(SN9C102_HO_SIZE
, 0x14);
159 Device()->WriteReg8(SN9C102_VO_SIZE
, 0x0a);
161 /* HACK: TEST IMAGE */
162 //Device()->WriteReg8(SN9C102_CLOCK_SEL, 0x70); /* enable sensor clk, and invert it, test img */
171 TAS5110C1BSensor::AddParameters(BParameterGroup
*group
, int32
&index
)
173 BContinuousParameter
*p
;
174 CamSensor::AddParameters(group
, index
);
178 BParameterGroup
*g
= group
->MakeGroup("global gain");
179 p
= g
->MakeContinuousParameter(index
++,
180 B_MEDIA_RAW_VIDEO
, "global gain",
181 B_GAIN
, "", (float)0x00, (float)0xf6, (float)1);
187 TAS5110C1BSensor::GetParameterValue(int32 id
, bigtime_t
*last_change
, void *value
, size_t *size
)
190 if (id
== fFirstParameterID
) {
191 *size
= sizeof(float);
192 *((float *)value
) = fGain
;
193 *last_change
= fLastParameterChanges
;
201 TAS5110C1BSensor::SetParameterValue(int32 id
, bigtime_t when
, const void *value
, size_t size
)
204 if (id
== fFirstParameterID
) {
205 if (!value
|| (size
!= sizeof(float)))
207 if (*(float *)value
== fGain
)
209 fGain
= *(float *)value
;
210 fLastParameterChanges
= when
;
211 PRINT((CH
": gain: %f" CT
, fGain
));
215 //Device()->WriteIIC8(0x20, (uint8)0xf6 - (uint8)fGain);
216 // but it doesn't seem to work
218 // works, not sure why yet, XXX check datasheet for AEG/AEC
219 uint8 buf
[2] = { 0x20, 0x70 };
220 buf
[1] = (uint8
)0xff - (uint8
)fGain
;
221 Device()->WriteIIC(0x02, buf
, 2);
232 B_WEBCAM_DECLARE_SENSOR(TAS5110C1BSensor
, tas5110c1b
)