コード例 #1
0
ファイル: i2c_alc5628.c プロジェクト: cmotc/openwrt-realtek
unsigned int serial_out_i2c(unsigned int addr, int offset, int value)
{
	//printk( "serial_out_i2c(%X):%X,%X\n", addr, offset, value );
	unsigned short int data_hibyte;
	unsigned short int data_lowbyte;

	data_hibyte =(unsigned char) (value>>8);
	data_lowbyte =(unsigned char) (value & 0xff);

	if( addr != ALC5628_I2C_ADDR )
		return 0;
	//printk("(%d)", __LINE__);
	// start 
	i2c_start_condition( &alc5628_i2c_dev );
	
	// addr + write
	i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | ALC5628_I2C_WRITE );
	
	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	//printk("(%d)", __LINE__);
	// write register address 
	i2c_serial_write_byte( &alc5628_i2c_dev, offset );
	
	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	//printk("(%d)", __LINE__);
	// write data hibyte
	i2c_serial_write_byte( &alc5628_i2c_dev, data_hibyte );

	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	//printk("(%d)", __LINE__);
	// write data lowbyte
	i2c_serial_write_byte( &alc5628_i2c_dev, data_lowbyte );

	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	//printk("(%d)", __LINE__);
	// stop
	i2c_stop_condition( &alc5628_i2c_dev );
	
	return 0;
}
コード例 #2
0
ファイル: i2c_alc5628.c プロジェクト: cmotc/openwrt-realtek
unsigned int serial_in_i2c(unsigned int addr, int offset)
{
	unsigned short int data_hibyte=0;
	unsigned short int data_lowbyte=0;
	unsigned short int data;
	
	//printk( "serial_in_i2c(%X):%X\n", addr, offset );
	
	if( addr != ALC5628_I2C_ADDR )
		return 0;
	
	// start 
	i2c_start_condition( &alc5628_i2c_dev );
	
	// addr + write
	i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | 
											   ALC5628_I2C_WRITE );
	
	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	
	// write register address 
	i2c_serial_write_byte( &alc5628_i2c_dev, offset );
	
	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
	
	// start 
	i2c_start_condition( &alc5628_i2c_dev );

	// addr + read
	i2c_serial_write_byte( &alc5628_i2c_dev, ALC5628_I2C_ADDR | 
											   ALC5628_I2C_READ );
	
	// read ACK 
	if( i2c_ACK( &alc5628_i2c_dev ) != 0 )
		return 0;
		
	// read data_hibyte
	i2c_serial_read( &alc5628_i2c_dev, &data_hibyte );

	//write ACK
	i2c_ACK_w(&alc5628_i2c_dev, 0);

	// read data_lowbyte
	i2c_serial_read( &alc5628_i2c_dev, &data_lowbyte );

	data = (data_hibyte<<8) | data_lowbyte;

	// write negative-ACK
	i2c_ACK_w( &alc5628_i2c_dev, 1 );
	
	// stop
	i2c_stop_condition( &alc5628_i2c_dev );
	
	//printk( "in[%X]\n", data );
	
	return data;
}
コード例 #3
0
ファイル: i2c.c プロジェクト: ClarkChen633/rtl819x-toolchain
void i2c_serial_write(i2c_dev_t* pI2C_Dev, unsigned char *data)
{
	i2c_serial_write_byte( pI2C_Dev, *data );
}