?? tw2834.c
字號:
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 1);
tw2834_set_record_pic_pos(2, 2);
tw2834_set_record_pic_pos(3, 3);
}
/*
* Set the record path to normal quad mod.
* @return value: null.
*/
static void set_record_normal_quad(void)
{
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0x7fff, 0x7fff);
/*set live mod for record path */
tw2834_set_op_mode(FUNC_MODE_LIVE);
/*set record mod normal*/
tw2834_set_record_mod(0, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 0);
tw2834_set_record_pic_size(1, 0);
tw2834_set_record_pic_size(2, 0);
tw2834_set_record_pic_size(3, 0);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 1);
tw2834_set_record_pic_pos(2, 2);
tw2834_set_record_pic_pos(3, 3);
}
/*
* Set the record path to normal full mod.
* @param ch: channel number
* @return value: null.
*/
static void set_record_normal_full(unsigned char ch)
{
unsigned char byte_tmp;
if(ch > 3)
{
printk("\tTW2834_ERROR: Channel number input error\n");
return;
}
/*select the input for channel 0*/
byte_tmp = tw2834_read_byte(PAGE1, 0x60);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, ch);
tw2834_write_byte(PAGE1, 0x60, byte_tmp);
/*set live mod for record path */
tw2834_set_op_mode(FUNC_MODE_LIVE);
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0xffff, 0xffff);
/*set record mod normal*/
tw2834_set_record_mod(0, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 3);
tw2834_set_record_pic_size(1, 3);
tw2834_set_record_pic_size(2, 3);
tw2834_set_record_pic_size(3, 3);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 1);
tw2834_set_record_pic_pos(2, 2);
tw2834_set_record_pic_pos(3, 3);
}
/*
* Set the record path to half d1.
* @return value: null.
*/
static void set_record_2half_d1(void)
{
unsigned char byte_tmp;
/*select the input for channel 0 */
byte_tmp = tw2834_read_byte(PAGE1, 0x60);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, 0x00);
tw2834_write_byte(PAGE1, 0x60, byte_tmp);
/*set live mod for record path */
tw2834_set_op_mode(FUNC_MODE_LIVE);
/*select the input for channel 1 */
byte_tmp = tw2834_read_byte(PAGE1, 0x63);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, 0x01);
tw2834_write_byte(PAGE1, 0x63, byte_tmp);
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0xffff, 0xffff);
/*set record mod frame*/
tw2834_set_record_mod(1, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 1);
tw2834_set_record_pic_size(1, 1);
tw2834_set_record_pic_size(2, 1);
tw2834_set_record_pic_size(3, 1);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 2);
tw2834_set_record_pic_pos(2, 1);
tw2834_set_record_pic_pos(3, 3);
}
/*
* Set the record path to normal 1cif mod.
* @param ch: channel number
* @return value: null.
*/
static void set_record_normal_1cif(unsigned char ch)
{
unsigned char byte_tmp;
if(ch > 3)
{
printk("\tTW2834_ERROR: Channel number input error\n");
return;
}
/*select the input for channel 0*/
byte_tmp = tw2834_read_byte(PAGE1, 0x60);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, ch);
tw2834_write_byte(PAGE1, 0x60, byte_tmp);
/*set live mod for record path */
tw2834_set_op_mode(FUNC_MODE_LIVE);
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0x7fff, 0xffff);
/*set record mod normal*/
tw2834_set_record_mod(0, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 2);
tw2834_set_record_pic_size(1, 2);
tw2834_set_record_pic_size(2, 2);
tw2834_set_record_pic_size(3, 2);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 0);
tw2834_set_record_pic_pos(2, 0);
tw2834_set_record_pic_pos(3, 0);
}
/*
* Set the record path to normal 2cif mod.
* @param ch: channel number
* @return value: null.
*/
static void set_record_normal_2cif(void)
{
unsigned char byte_tmp;
/*select the input for channel 0 */
byte_tmp = tw2834_read_byte(PAGE1, 0x60);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, 0x00);
tw2834_write_byte(PAGE1, 0x60, byte_tmp);
/*set live mod for record path */
tw2834_set_op_mode(FUNC_MODE_LIVE);
/*select the input for channel 1 */
byte_tmp = tw2834_read_byte(PAGE1, 0x63);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, 0x01);
tw2834_write_byte(PAGE1, 0x63, byte_tmp);
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0x7fff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0x7fff, 0xffff);
/*set record mod normal*/
tw2834_set_record_mod(0, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 2);
tw2834_set_record_pic_size(1, 2);
tw2834_set_record_pic_size(2, 2);
tw2834_set_record_pic_size(3, 2);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 1);
tw2834_set_record_pic_pos(2, 0);
tw2834_set_record_pic_pos(3, 0);
}
/*
* set record path switch mode
* @param period: switch period(count of field)
* @return value: null.
*/
static void set_record_switch(unsigned long period)
{
unsigned char byte_tmp;
unsigned char byte_tmp1;
if(period > 1023)
{
printk("\tTW2834_ERROR: switch mod period input error\n");
return;
}
/*set scale of each channel */
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 0, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 1, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 2, 0xffff, 0xffff);
tw2834_setvin_scale_ratio(TW2834_PATH_Y, 3, 0xffff, 0xffff);
/*set record mod normal*/
tw2834_set_record_mod(0, 0);
/*set pic_size for each channel*/
tw2834_set_record_pic_size(0, 3);
tw2834_set_record_pic_size(1, 3);
tw2834_set_record_pic_size(2, 3);
tw2834_set_record_pic_size(3, 3);
/*set pic_pos for each channel*/
tw2834_set_record_pic_pos(0, 0);
tw2834_set_record_pic_pos(1, 0);
tw2834_set_record_pic_pos(2, 0);
tw2834_set_record_pic_pos(3, 0);
/*set switch mod for record path */
tw2834_set_op_mode(FUNC_MODE_SWITCH);
/*set mux mod live,set the trig mode,Capture frame*/
byte_tmp = tw2834_read_byte(PAGE1, 0x56);
CLEAR_BIT(byte_tmp, 0xf0);
SET_BIT(byte_tmp, 0xf0);
tw2834_write_byte(PAGE1, 0x56, byte_tmp);
/*set size of the queue to 3*/
tw2834_write_byte(PAGE1, 0x57, 0x03);
/*updata channnel 0 to the queue*/
byte_tmp = tw2834_read_byte(PAGE1, 0x59);
CLEAR_BIT(byte_tmp, 0x0f);
SET_BIT(byte_tmp, 0x00);
tw2834_write_byte(PAGE1, 0x59, byte_tmp);
tw2834_write_byte(PAGE1, 0x5a, 0x00);
tw2834_write_byte(PAGE1, 0x5a, 0x80);
/*updata channnel 1 to the queue*/
byte_tmp = tw2834_read_byte(PAGE1, 0x59);
CLEAR_BIT(byte_tmp, 0x0f);
SET_BIT(byte_tmp, 0x01);
tw2834_write_byte(PAGE1, 0x59, byte_tmp);
tw2834_write_byte(PAGE1, 0x5a, 0x01);
tw2834_write_byte(PAGE1, 0x5a, 0x81);
/*updata channnel 2 to the queue*/
byte_tmp = tw2834_read_byte(PAGE1, 0x59);
CLEAR_BIT(byte_tmp, 0x0f);
SET_BIT(byte_tmp, 0x02);
tw2834_write_byte(PAGE1, 0x59, byte_tmp);
tw2834_write_byte(PAGE1, 0x5a, 0x02);
tw2834_write_byte(PAGE1, 0x5a, 0x82);
/*updata channnel 3 to the queue*/
byte_tmp = tw2834_read_byte(PAGE1, 0x59);
CLEAR_BIT(byte_tmp, 0x0f);
SET_BIT(byte_tmp, 0x03);
tw2834_write_byte(PAGE1, 0x59, byte_tmp);
tw2834_write_byte(PAGE1, 0x5a, 0x03);
tw2834_write_byte(PAGE1, 0x5a, 0x83);
/*set switch period*/
byte_tmp = (unsigned char)period & 0xff;
byte_tmp1 = (unsigned char)(period & 0x0300) >> 2;
tw2834_write_byte(PAGE1, 0x58, byte_tmp);
byte_tmp = tw2834_read_byte(PAGE1, 0x59);
CLEAR_BIT(byte_tmp, 0xc0);
SET_BIT(byte_tmp, byte_tmp1);
tw2834_write_byte(PAGE1, 0x59, byte_tmp);
/*reset queue*/
byte_tmp = tw2834_read_byte(PAGE1, 0x5B);
CLEAR_BIT(byte_tmp, 0x03);
SET_BIT(byte_tmp, 0x03);
tw2834_write_byte(PAGE1, 0x5B, byte_tmp);
}
/****************************record path mod***********************************/
/*
* set tw2834 record path mod to 1 d1
* return value: nothing
*/
static void setd1(int chn)
{
set_record_normal_full(chn);
printk("\tTW2834_OUTPUT_MOD_SET: 1 d1.\n");
return;
}
/*
* set tw2834 record path mod to 1 cif
* return value: nothing
*/
static void set1cif(int chn)
{
set_record_normal_1cif(chn);
printk("\tTW2834_OUTPUT_MOD_SET: 1 cif.\n");
return;
}
/*
* set tw2834 record path mod to 4 d1
* return value: nothing
*/
static void set4d1(void)
{
set_record_switch(1);
printk("\tTW2834_OUTPUT_MOD_SET: 4 d1.\n");
return;
}
/*
* set tw2834 record path mod to 4 cif
* return value: nothing
*/
static void set4cif(void)
{
set_record_frame_quad();
printk("\tTW2834_OUTPUT_MOD_SET: 4 cif.\n");
return;
}
/*
* set tw2834 record path mod to 4 d1
* return value: nothing
*/
static void set_2halfd1(void)
{
set_record_2half_d1();
printk("\tTW2834_OUTPUT_MOD_SET: 2 half d1.\n");
return;
}
/*
* set tw2834 record path mod to 4 qcif
* return value: nothing
*/
static void set4qcif(void)
{
set_record_normal_quad();
printk("\tTW2834_OUTPUT_MOD_SET: 4 qcif.\n");
return;
}
/*
* set tw2834 record path mod to 2 cif
* return value: nothing
*/
static void set2cif(void)
{
set_record_normal_2cif();
printk("\tTW2834_OUTPUT_MOD_SET: 2 cif.\n");
return;
}
/****************************** display path control **************************/
/*
* function: set display path channel region.
* @param ch: channel number
* @region defined by (hl,vt)left top (hr,vb)right bottom.
* @return value: null.
*/
static void set_display_region(unsigned char ch, unsigned long hl, unsigned long hr,
unsigned long vt, unsigned long vb)
{
tw2834_write_byte(PAGE1, REG_PICHL+(ch<<2), hl);
tw2834_write_byte(PAGE1, REG_PICHR+(ch<<2), hr);
tw2834_write_byte(PAGE1, REG_PICVT+(ch<<2), vt);
tw2834_write_byte(PAGE1, REG_PICVB+(ch<<2), vb);
}
/*
* function: set display path d1 mod.
* @return value: null.
*/
static void set_display_d1(int chn)
{
tw2834_setvin_scale_ratio(TW2834_PATH_X, chn, 0xffff, 0xffff);
set_display_region(0, 0, 180, 0, 144);
}
/*
* function: set display path quad mod.
* @return value: null.
*/
static void set_display_quad(void)
{
/*set vin scaling*/
tw2834_setvin_scale_ratio(TW2834_PATH_X, 0, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_X, 1, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_X, 2, 0x7fff, 0x7fff);
tw2834_setvin_scale_ratio(TW2834_PATH_X, 3, 0x7fff, 0x7fff);
set_display_region(0, 0, 90, 0, 72);
set_display_region(1, 90, 180, 0, 72);
set_display_region(2, 0, 90, 72, 144);
set_display_region(3, 90, 180, 72, 144);
}
/****************************** vbi control ***********************************/
/*
* Channel ID config routine.
* @param anolog_chid_lines: the line offset of the digatal ID: <20
* @return value: null.
*/
static void tw2834_ch_id_config(unsigned char anolog_chid_lines)
{
unsigned char anolog_line_offset;
unsigned char anolog_line_width;
unsigned char reg_val;
anolog_line_width = 0;
anolog_line_offset = anolog_chid_lines - anolog_line_width - 1;
reg_val = ((anolog_line_width ) << 5) | (anolog_line_offset & 0x1f);
/*config the mode :anolog channel ID + digital channel ID*/
tw2834_write_byte(PAGE1, 0xC1, 0xa0);
tw2834_write_byte(PAGE1, 0xC2, 0x00);
tw2834_write_byte(PAGE1, 0xC3, 0x00);
/*config the offset and line width of anolog channel ID */
tw2834_write_byte(PAGE1,0xC4,reg_val);
}
/*
* get digital Channel ID vertical offset routine.
* @return value: vertical offset.
*/
unsigned char tw2834_get_chid_offsetv(void)
{
unsigned char anolog_line_offset;
unsigned char anolog_line_width;
unsigned char offsetv;
unsigned char reg_val;
reg_val = tw2834_read_byte(PAGE1, 0xC1);
if ((reg_val & 0xa0) != 0xa0)
{
printk("\tTW2834_ERROR: channel ID mod is not right.\n");
return 0;
}
reg_val = tw2834_read_byte(PAGE1, 0xC4);
anolog_line_width = (reg_val >> 5) + 1;
anolog_line_offset = reg_val & 0x1f;
offsetv = anolog_line_width + anolog_line_offset;
return offsetv;
}
/******************************************************************************/
/*
* initialize the clock
* return value: nothing
*/
static void setmemclock(unsigned char v_mclk)
{
unsigned char r_clkctl;
r_clkctl = tw2834_read_byte(PAGE1,REG_CLK_CTL); /*... REG_CLK_CTL */
tw2834_write_byte(PAGE1,REG_MCLK_CTL,v_mclk); /*... REG_MCLK_CTL*/
tw2834_write_byte(PAGE1,0x7D,00); /*... REG_MCLK_CTL*/
tw2834_write_byte(PAGE1,REG_CLK_CTL,MEM_INIT|r_clkctl); /*... REG_CLK_CTL */
}
/*
* initialize the page0's register
* return value: nothing
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -