コード例 #1
0
ファイル: caraction.cpp プロジェクト: bgtwoigu/Innov_code
int InitGF()
{
#ifndef _8925_8D1
	int file,i;
	file = i2copen(0);
	if( file == 0 )
		return -1;

	Incar_initvolume();

	//把声音设置为工作状态
	i2cset( file, 0x50, 0x00, 0xFF, 'b' );
	//必须进行延时,等待功放稳定,否则配置无效
	usleep( 200000 );

	//必须读0x00 和0x01地址,清除失败状态
	i2cget(file,0x6c,0x00,'b');
	i2cget(file,0x6c,0x01,'b');

	//以下功能检查是否输出短路
	i2cset( file, 0x50, 0x0b, 0x0F, 'b' );
	usleep( 200000 );//等 200 ms

	int nCount = 10;
	int nState = i2cget(file,0x6c,0x07,'b');
	while( (nState != 0x00) && (nCount-- > 0))
	{
		usleep( 35000 );//等 35 ms
		nState = i2cget(file,0x6c,0x07,'b');
		fprintf(stderr, "InitGF nState is %x, nCount is %d\n", nState, nCount);
	}

	int nState1 = i2cget(file,0x6c,0x02,'b');
	int nState2 = i2cget(file,0x6c,0x03,'b');
	if( nState1 != 0x00 || nState2 != 0x00 )
	{
		printf("tas5414_master 0x02 0x03 address is %x %x\n", nState1, nState2);
		return -2;
	}

	//写用户配置参数
	unsigned char* p = tas5414_master;
	for(i = 0;i < (int)(sizeof(tas5414_master)/sizeof(tas5414_master[0]));i+=2)
	{
		i2cset(file,0x6c,*p,*(p+1),'b');
		p += 2;
	}

	i2cclose(file);

	usleep( 3000000 );//必须进行延时,等待功放稳定,否则立即切换界面不能屏蔽电流冲击声
#endif
	return 0;
}
コード例 #2
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_PowerOff()
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	i2cset(i2c,0x6f,0x0c,0x1f,'b');
	i2cset(i2c,0x6c,0x0c,0x1f,'b');

	return i2cset( i2c , MCUADDR , addr_POWER_write , 0x00 , 'b' );
}
コード例 #3
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_AirconditionGet(structAirInfo*test)
{
	int error = 0;
	unsigned char buf[6];
	
	if( !test )
		return -1;
	
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			error = -2;
	}

	if( !error )
	{
		buf[0] = 0x0a;
		int try1 = 2;
		while(try1 --)
		{
			i2cset(i2c,0x50,buf,1);
			i2cget(i2c,0x50,buf,6);
			int i;
			i = buf[0] + buf[1] + buf[2] + buf[3] + buf[4] + buf[5] ;
			i = i & 0x7f;
			if(((buf[5]>>7)==0) && (i==0x7a)) 
				break;
			
		}
		if( try1 <= 0 ) 
			error = -3;
	}
コード例 #4
0
ファイル: caraction.cpp プロジェクト: bgtwoigu/Innov_code
int UnmuteGF()
{
#ifdef _8925_8D1
	//*(volatile unsigned int*)(gpa_vbase + OFFSET_PE) |= (0x1 << GPIO_NUM); 
	//*(volatile unsigned int*)(gpa_vbase + OFFSET_PS) |= (0x1 << GPIO_NUM); 
	*(volatile unsigned int*)(gpe_vbase + OFFSET_FUN2) &= ~(0xf << 4); 
	*(volatile unsigned int*)(gpe_vbase + GPA_EN) |= (0x1 << GPION_MUTE);
	*(volatile unsigned int*)(gpe_vbase + GPA_DAT) |= (0x1 << GPION_MUTE); 
#else
	int file;
	file = i2copen(0);	
	if( file == 0 )
		return -1;

	i2cset(file,0x6c,0x0c,0x00,'b');
	usleep( 35000 );//等 35 ms
	int nState = i2cget(file,0x6c,0x06,'b');
	int nCount = 3;
	while( (nState != 0x0f)  && (nCount-- > 0) )
	{
		usleep( 35000 );//等 35 ms
		nState = i2cget(file,0x6c,0x06,'b');
		fprintf(stderr, "UnmuteGF nState is %x, nCount is %d\n", nState, nCount);
	}

	i2cclose(file);
#endif
	return 0;
}	
コード例 #5
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_ContrastSet(int value)
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	int i;
	i = i2cget(i2c,0x45,0x70,'b');
	i = i | 0x40;
	i2cset(i2c,0x45,0x70,i,'b');
	i2cset(i2c,0x45,0x71,value,'b');
	i2cset(i2c,0x45,0x72,value,'b');
	i2cset(i2c,0x45,0x73,value,'b');
	return 0;
}
コード例 #6
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_brightnessSet(int value)
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	int i;
	i = i2cget(i2c,0x45,0x70,'b');
	i = i | 0x40;
	i2cset(i2c,0x45,0x70,i,'b');
	i2cset(i2c,0x45,0x74,value,'b');
	i2cset(i2c,0x45,0x75,value,'b');
	i2cset(i2c,0x45,0x76,value,'b');
	return 0;
}
コード例 #7
0
ファイル: caraction.cpp プロジェクト: bgtwoigu/Innov_code
int PowerOffGF()
{
#ifndef _8925_8D1
	int file;
	file = i2copen(0);	
	if( file == 0 )
		return -1;

	//由PLAY-MODE进入到MUTE-MODE
	i2cset(file,0x6c,0x0c,0x10,'b');
	int nCount = 10;
	int nState = i2cget(file,0x6c,0x06,'b');
	while( (nState != 0xf0) && (nCount-- > 0) )
	{
		usleep( 35000 );//等 35 ms
		nState = i2cget(file,0x6c,0x06,'b');
		fprintf(stderr, "PowerOffGF MUTE-MODE i2cget 0x6c,0x06 nState is %x, nCount is %d\n", nState, nCount);
	}

	//由MUTE-MODE 进入到LOW-LOW-MODE
	i2cset(file,0x6c,0x0d,0x0f,'b');
	nCount = 10;
	nState = i2cget(file,0x6c,0x05,'b');
	while( (nState != 0xf0) && (nCount-- > 0) )
	{
		usleep( 35000 );//等 35 ms
		nState = i2cget(file,0x6c,0x05,'b');
		fprintf(stderr, "PowerOffGF LOW-LOW-MODE i2cget 0x6c,0x05 nState is %x, nCount is %d\n", nState, nCount);
	}

	//由LOW-LOW-MODE 进入到HIZ-MODE
	i2cset(file,0x6c,0x0c,0x1f,'b');
	nCount = 10;
	nState = i2cget(file,0x6c,0x05,'b');
	while( (nState != 0x0f) && (nCount-- > 0) )
	{
		usleep( 35000 );//等 35 ms
		nState = i2cget(file,0x6c,0x05,'b');
		fprintf(stderr, "PowerOffGF HIZ-MODE i2cget 0x6c,0x05 nState is %x, nCount is %d\n", nState, nCount);
	}

	i2cclose(file);
#endif
	return 0;
}
コード例 #8
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_Reset()
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	return i2cset( i2c , MCUADDR , addr_POWER_write , 0x01 , 'b' );
}
コード例 #9
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_Muteoff()
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	unsigned char aa[1] ;
	aa[0] = 0xf8;
	return	i2cset(i2c,0x44,aa,1);
}
コード例 #10
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
//volume·¶Î§ (  0 - 79 )
int Incar_Setvolume(int value)	
{
	unsigned char aa[2];
	aa[0] = value /10 + 0xd0;
	aa[1] = value % 10 + 0xe0 ;
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	return	i2cset(i2c,0x44,aa,2);
}
コード例 #11
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_backclothSet(int value)
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	if(value > 0x40) value = 0x40;
	if(value < 0 ) value = 0;

	i2cset(i2c,0x45,0xc4,value,'b');
	return 0;
}
コード例 #12
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_initvolume()
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	unsigned char aa[2];
	aa[0] = 0x0c;
	i2cset(i2c,0x44,aa,1);
	aa[0] = 0x80;
	aa[1] = 0x90;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0x40;
	aa[1] = 0x50;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0x00;
	aa[1] = 0x10;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0x20;
	aa[1] = 0x30;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0x60;
	aa[1] = 0x70;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0xa0;
	aa[1] = 0xb0;
	i2cset(i2c,0x44,aa,2);
	aa[0] = 0xd7;
	aa[1] = 0xe9;
	i2cset(i2c,0x44,aa,2);	
	aa[0] = 0xf8;
	i2cset(i2c,0x44,aa,1);
	return 0;
}
コード例 #13
0
ファイル: caraction.cpp プロジェクト: bgtwoigu/Innov_code
int MuteGF()
{
#ifdef _8925_8D1
	//*(volatile unsigned int*)(gpa_vbase + OFFSET_PE) &= ~(0x1 << GPIO_NUM); 
	//*(volatile unsigned int*)(gpa_vbase + OFFSET_PS) &= ~(0x1 << GPIO_NUM); 
	*(volatile unsigned int*)(gpe_vbase + OFFSET_FUN2) &= ~(0xf << 4); 
	*(volatile unsigned int*)(gpe_vbase + GPA_EN) |= (0x1 << GPION_MUTE);
	*(volatile unsigned int*)(gpe_vbase + GPA_DAT) &= ~(0x1 << GPION_MUTE); 
#else
	int file;
	file = i2copen(0);	
	if( file == 0 )
		return -1;

	i2cset(file,0x6c,0x0c,0x1f,'b');

	i2cclose(file);
#endif
	return 0;
}	
コード例 #14
0
ファイル: DevCtrl.cpp プロジェクト: bgtwoigu/Innov_code
int Incar_PowerEnable( int device , int enable )
{
	if( i2c < 0 )
	{
		openi2c();
		if( i2c < 0 )
			return -1;
	}
	if( device >= Incar_Power_Gps && device <= Incar_Power_Dvd )
	{
		
		int value = i2cget( i2c , MCUADDR , addr_POWER_read , 'b' );
		if( enable )
			value |= 1<<(device+1);
		else
			value &= ~(1<<(device+1));
		return i2cset( i2c , MCUADDR , addr_POWER_write , value , 'b' );
	}
	else
		return -1;
}
コード例 #15
0
int main(int argc, char *argv[])
{
	int i2cbus, address, daddress;
	short x_val, y_val, z_val;

	if(argc < 2) {
		fprintf(stderr, "Usage:  %s <i2c-bus> <i2c-address>\n", argv[0]);
		exit(1);
	}

	i2cbus   = atoi(argv[1]);
	address  = atoi(argv[2]);

	//continuously read and print the values for each axis
	while(1){
		//set to continuous measurement mode
		i2cset(i2cbus, address, 2, 0);

		x_val = ((i2cget(i2cbus, address, 3) << 8) + i2cget(i2cbus, address, 4));

		//small wait
		usleep(50000);			

		z_val = ((i2cget(i2cbus, address, 5) << 8) + i2cget(i2cbus, address, 6));

		//small wait
		usleep(50000);	

		y_val = ((i2cget(i2cbus, address, 7) << 8) + i2cget(i2cbus, address, 8));

		fprintf(stderr, "x value = %d, y value = %d, z value = %d\r", x_val, y_val, z_val);
		
		//small wait
		usleep(50000);		

	}	
	
	return 0;

}
コード例 #16
0
ファイル: omapconf.c プロジェクト: KunYi/omapconf
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		main_i2c_write
 * @BRIEF		write given data at given address of given device of
 *			given I2C bus
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_NOT_AVAILABLE
 *			OMAPCONF_ERR_REG_ACCESS
 * @param[in]		argc: shell input argument number
 *			argc must be 6
 * @param[in]		argv: shell input argument(s)
 *			argv[2] = i2cbus: I2C bus number
 *			argv[3] = address: I2C device address
 *			argv[4] = daddress: I2C device register address
 *			argv[5] = data: data to be written
 * @DESCRIPTION		write given data at given address of given device of
 *			given I2C bus
 *//*------------------------------------------------------------------------ */
static int main_i2c_write(int argc, char *argv[])
{
	unsigned int i2cbus, chip_address, data_address;
	unsigned int data;
	int ret;

	if (argv == NULL) {
		printf("%s(): argv == NULL!!!\n", __func__);
		return OMAPCONF_ERR_ARG;
	}
	/* Retrieve arguments */
	if (argc != 6)
		goto main_i2c_write_err;
	ret = sscanf(argv[2], "%u", &i2cbus);
	if (ret != 1)
		goto main_i2c_write_err;
	ret = sscanf(argv[3], "0x%x", &chip_address);
	if (ret != 1)
		goto main_i2c_write_err;
	ret = sscanf(argv[4], "0x%x", &data_address);
	if (ret != 1)
		goto main_i2c_write_err;
	ret = sscanf(argv[5], "0x%x", &data);
	if (ret != 1)
		goto main_i2c_write_err;

	ret = i2cset(i2cbus, chip_address, data_address, data);
	return ret;

main_i2c_write_err:
	printf(
		"Usage: omapconf i2c write 'i2cbus' 0x'chip-address' 0x'data-address' 0x'data'\n");
	printf("  'i2cbus' is decimal value.\n");
	printf(
		"  'chip-address', 'data-address' & 'data' are hexadecimal values.\n");
	printf("  Warning: prefix '0x' is mandatory.\n");
	return OMAPCONF_ERR_ARG;
}
コード例 #17
0
ファイル: twl603x.c プロジェクト: IngenicC/omapconf
/* ------------------------------------------------------------------------*//**
 * @FUNCTION		twl603x_uvoltage_set
 * @BRIEF		set voltage of a given SMPS voltage rail.
 * @RETURNS		0 in case of success
 *			OMAPCONF_ERR_CPU
 *			OMAPCONF_ERR_ARG
 *			OMAPCONF_ERR_NOT_AVAILABLE
 *			OMAPCONF_ERR_REG_ACCESS
 *			OMAPCONF_ERR_INTERNAL
 * @param[in]		vdd_id: voltage domain ID
 * @param[in]		uv: voltage to be set (in micro-volt)
 * @DESCRIPTION		set voltage of a given SMPS voltage rail, in micro-volt.
 *			NB: not supported by TWL6030/TWL6032.
 *//*------------------------------------------------------------------------ */
int twl603x_uvoltage_set(unsigned int vdd_id, unsigned long uv)
{
	int ret;
	unsigned int val;
	unsigned char vsel;
	const twl6035_smps_registers **vdd_smps_regs;
	const twl6035_smps_registers *smps_regs;

	if (!twl603x_is_twl6035())
		return OMAPCONF_ERR_CPU;
	CHECK_ARG_LESS_THAN(vdd_id, 3, OMAPCONF_ERR_ARG);

	/* Retrive SMPS registers addresses */
	vdd_smps_regs = twl6035_smps_vdd54xx[vdd_id];
	if (vdd_smps_regs == NULL)
		return OMAPCONF_ERR_INTERNAL;
	smps_regs = *vdd_smps_regs;
	if (smps_regs == NULL)
		return OMAPCONF_ERR_INTERNAL;

	dprintf("%s(): vdd_id=%u  ADDR: ctrl=0x%02X tstep=0x%02X force=0x%02X "
		"voltage=0x%02X\n", __func__, vdd_id, smps_regs->ctrl,
		smps_regs->tstep, smps_regs->force, smps_regs->voltage);

	/* Check SMPS Status */
	/* FIXME: create dedicated API */
	if (smps_regs->ctrl == -1) {
		dprintf("%s(): SMPSxx_CTRL addr=-1!!!\n", __func__);
		return OMAPCONF_ERR_INTERNAL;
	}
	ret = i2cget(TWL6035_I2C_BUS, TWL6035_ID1_ADDR,
		smps_regs->ctrl, &val);
	if (ret != 0)
		return OMAPCONF_ERR_REG_ACCESS;
	dprintf("%s(): SMPSxx_CTRL=0x%02X\n", __func__, val);
	if (extract_bitfield(val, 4, 2) == 0) {
		dprintf("(%s(): SMPS is OFF\n", __func__);
		return OMAPCONF_ERR_NOT_AVAILABLE;
	}

	/* Make sure SMPSxx_CTRL.ROOF_FLOOR_EN=0 */
	/* FIXME: create dedicated API */
	if (extract_bit(val, 6) == 1) {
		dprintf("%s(): SMPS voltage controlled by resource pins, "
			"clearing ROOF_FLOOR_EN bit.\n", __func__);
		/* Clear ROOF_FLOOR_EN bit (6) */
		val = val & 0xBF;
		ret = i2cset(TWL6035_I2C_BUS, TWL6035_ID1_ADDR,
			smps_regs->ctrl, (unsigned int) val);
		if (ret != 0)
			return OMAPCONF_ERR_REG_ACCESS;
		dprintf("%s(): SMPS voltage now controlled by "
			"SMPS12_FORCE.CMD bit.\n", __func__);
	} else {
		dprintf("%s(): SMPS voltage controlled by "
			"SMPS12_FORCE.CMD bit.\n", __func__);
	}

	/* Convert voltage to VSEL */
	vsel = twl603x_uv_to_vsel(vdd_id, uv);
	dprintf("%s(): uv=%lu vsel=0x%02X\n", __func__, uv, vsel);

	/* Write VSEL to SMPSxx_VOLTAGE */
	ret = i2cset(TWL6035_I2C_BUS, TWL6035_ID1_ADDR,
			smps_regs->voltage, (unsigned int) vsel);
	if (ret != 0)
		return OMAPCONF_ERR_REG_ACCESS;

	/*
	 * Try to switch voltage control to SMPSxx_FORCE register (if exists)
	 * so that voltage will not be overriden by kernel during
	 * DVFS, AVS or power transition.
	 */
	if (smps_regs->force != -1) {
		dprintf("%s(): SMPSxx_FORCE exists, switching control.\n",
			__func__);
		/* Clear bit 7 (CMD) */
		val = vsel & 0x7F;
		ret = i2cset(TWL6035_I2C_BUS, TWL6035_ID1_ADDR,
			smps_regs->force, (unsigned int) val);
	} else {
		dprintf("%s(): SMPSxx_FORCE does not exist.\n", __func__);
		ret = 0;
	}

	return ret;
}