/*******************************************************************************
* Function Name  : I2C_ReadByte
* Description    : utility function to read several bytes
* Input          : NumberOfBytes, RegAddress, , RxBuffer
* Return         : error status
*******************************************************************************/
int I2C_ReadByte(unsigned char DevAddr,unsigned char RegAddress,unsigned char *RxBuffer,int NumberOfBytes)
{
	int retry;
	int res;
  
	res = i2c_smbus_read_i2c_block_data(sav_client, RegAddress, NumberOfBytes, RxBuffer);
	if (res < 0)
		dev_err(&sav_client->dev, "%s: err %d\n", __func__, res);
#if 0	
	res = I2C_ReadByte(DevAddr,RegAddress,RxBuffer,NumberOfBytes);
	I2C read function has to be updated accordingly to the customer environement
#endif
	return res;
}
예제 #2
0
// Read data via I2C. 
BOOL I2C_ReadBytes(BYTE* Buf, BYTE Len, BYTE I2cDevice)
{
	while(Len--)
	{
		*(Buf++) = I2C_ReadByte(I2cDevice);
		if(Len == 0)
		{
			I2C_SendNoAck(I2cDevice);
		}
		else
		{
			I2C_SendAck(I2cDevice);
		}
	}

	return TRUE;
}
예제 #3
0
파일: ioi2c.c 프로젝트: HapCoderWei/MiniQ
//单字节读取*****************************************
unsigned char Single_Read(unsigned char SlaveAddress,unsigned char REG_Address)
{   unsigned char REG_data;     	
	if(!I2C_Start())return FALSE;
    I2C_SendByte(SlaveAddress); //I2C_SendByte(((REG_Address & 0x0700) >>7) | REG_Address & 0xFFFE);//设置高起始地址+器件地址 
    if(!I2C_WaitAck()){I2C_Stop(); return FALSE;}
    I2C_SendByte((u8) REG_Address);   //设置低起始地址      
    I2C_WaitAck();
    I2C_Start();
    I2C_SendByte(SlaveAddress+1);
    I2C_WaitAck();

	REG_data= I2C_ReadByte();
    I2C_NoAck();
    I2C_Stop();
	return REG_data;

}
예제 #4
0
파일: MPU6050.c 프로젝트: Niugge/2016.01.20
/***********************单字节读取******************/
uint8_t MPU6050_ReadByte(uint8_t SlaveAddress,uint8_t REG_Address)
{   
	unsigned char REG_data;     	
	I2C_Start();//if(!I2C_Start())return 0
    I2C_SendByte(SlaveAddress); //I2C_SendByte(((REG_Address & 0x0700) >>7) | REG_Address & 0xFFFE);//设置高起始地址+器件地址 
    I2C_WaitAck();//if(!I2C_WaitAck()){I2C_Stop();test=1; return 0;}
    I2C_SendByte((uint8_t) REG_Address);   //设置低起始地址      
    I2C_WaitAck();  //if(!I2C_WaitAck()){I2C_Stop(); return 0;}
		
    I2C_Start();//if(!I2C_Start())return 0;
    I2C_SendByte(SlaveAddress+1);
    I2C_WaitAck();//if(!I2C_WaitAck()){I2C_Stop(); return 0;}
    REG_data= I2C_ReadByte();
    I2C_NoAck();
    I2C_Stop();
	return REG_data;
}						      
예제 #5
0
static void WriteInitialRegisterValues(void)
{
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x08, 0x37);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA0, 0xD0);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA1, 0xFC);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA3, 0xC0);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA6, 0x0C);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x2B, 0x01);

	ReadModifyWriteTPI(0x90, BIT_3 | BIT_2, BIT_2);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x91, 0xA5);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x94, 0x75);


	I2C_WriteByte(CBUS_SLAVE_ADDR, 0x31, I2C_ReadByte(CBUS_SLAVE_ADDR, 0x31) | 0x0c);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0xA5, 0xA0);
	TPI_DEBUG_PRINT(("1x Mode\n"));
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x95, 0x31);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x96, 0x20);

	ReadModifyWriteTPI(0x97,  BIT_1, 0);

	ReadModifyWriteTPI(0x95, BIT_6, BIT_6);
	WriteByteTPI(0x92, 0x86);
	WriteByteTPI(0x93, 0xCC);
	if (txPowerState != TX_POWER_STATE_D3) {
		ReadModifyWriteTPI(0x79, BIT_5 | BIT_4, BIT_4);
	}

	DelayMS(25);
	ReadModifyWriteTPI(0x95, BIT_6, 0x00);
	ReadModifyWriteTPI(0x78, BIT_5, 0);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x90, 0x27);

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, 0x08);
	DelayMS(2);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, 0x00);

	InitCBusRegs();

	I2C_WriteByte(TPI_SLAVE_ADDR, 0x05, ASR_VALUE);
	}
예제 #6
0
/******************************************************************************
/ 函数功能:单字节写入
/ 修改日期:none
/ 输入参数:
/   @arg SlaveAddress   从器件地址
/   @arg REG_Address    寄存器地址
/ 输出参数: 读出的字节数据
/ 使用说明:这时一个完整的单字节读取函数
******************************************************************************/
uint8_t Single_Read(uint8_t SlaveAddress,uint8_t REG_Address)
{   
    uint8_t REG_data;       
    I2C_Start();//if(!I2C_Start())return 0
    I2C_SendByte(SlaveAddress); //I2C_SendByte(((REG_Address & 0x0700) >>7) | REG_Address & 0xFFFE);//设置高起始地址+器件地址 
    I2C_WaitAck();//if(!I2C_WaitAck()){I2C_Stop();return 0;}
    I2C_SendByte((uint8_t) REG_Address);   //设置低起始地址      
    I2C_WaitAck();//if(!I2C_WaitAck()){I2C_Stop();return 0;}
    I2C_Start();//if(!I2C_Start())return 0;
    I2C_SendByte(SlaveAddress+1);
	
    I2C_WaitAck();//if(!I2C_Start())return 0;
    REG_data = I2C_ReadByte();
    I2C_NoAck();
    I2C_Stop();
    return REG_data;
}
/*
 *=========================================================
 * 函数功能:读MPU6050单字节
 * 参数
 *       Regs_Addr - 寄存器地址
 * 函数返回值:寄存器值
 *=========================================================   
 */
unsigned char Single_ReadI2C(unsigned char Regs_Addr) 
{
   unsigned char ret;
   
   I2C_Start();
   
   I2C_WriteByte(SlaveAddress); 		//先写Slave地址,并配置成写模式
   I2C_WriteByte(Regs_Addr);    		//写寄存器地址
   
   I2C_Start();
   I2C_WriteByte(SlaveAddress+1);  	//写Slave地址,并配置成读模式
   ret=I2C_ReadByte();							//从传感器中读出数据

   I2C_SlaveAck();
   I2C_Stop();                  		//结束本段IIC进程 
   
   return ret;
} 
/*! \brief Reads data into buffer.
    \param data Pointer to data buffer
    \param bytes  Number of bytes to read
	\param slave_adr  Slave address on I2C bus
	\param slave_reg  Slave memory address from which the reading is started
    \return 1 if successful, otherwise 0
 */
u8 I2C_ReadBytes(u8* data, u8 bytes, u8 slave_adr, u8 slave_reg)
{
  u8 index, success = 0;
  if(!I2C_StartCond())
  {
    return 0;
  }
  if(!I2C_WriteByte((u8)(slave_adr | WRITE)))
  {
    return 0;	
  }
  if(!I2C_WriteByte(slave_reg))
  {
    return 0;	
  }
  write_scl(1);
	DELAY_US(SCL_SDA_DELAY);
	SDA_HIGH;
  if(!I2C_StartCond())
  {
    return 0;
  }
  if(!I2C_WriteByte((u8)(slave_adr | READ)))
  {
    return 0;	
  }
  for(index = 0; index < bytes; index++)
  {
    success = I2C_ReadByte(data, bytes, index);
    if(!success)
	  {
      break; 
    }
  }
  //put stop here
  write_scl(1);
  DELAY_US(SCL_SDA_DELAY);
  SDA_HIGH;
  return success;
}
예제 #9
0
static void i2c_imx_read(struct device *dev, u8_t *rxBuffer, u8_t rxSize)
{
	I2C_Type *base = DEV_BASE(dev);
	struct i2c_imx_data *data = DEV_DATA(dev);
	struct i2c_master_transfer *transfer = &data->transfer;

	transfer->isBusy = true;

	/* Clear I2C interrupt flag to avoid spurious interrupt */
	I2C_ClearStatusFlag(base, i2cStatusInterrupt);

	/* Change to receive state. */
	I2C_SetDirMode(base, i2cDirectionReceive);
	transfer->currentDir = i2cDirectionReceive;

	transfer->rxBuff = rxBuffer;
	transfer->rxSize = rxSize;

	if (transfer->rxSize == 1) {
		/* Send Nack */
		I2C_SetAckBit(base, false);
	} else {
		/* Send Ack */
		I2C_SetAckBit(base, true);
	}

	/* dummy read to clock in 1st byte */
	I2C_ReadByte(base);

	/* Enable I2C interrupt, subsequent data transfer will be handled
	 * in ISR.
	 */
	I2C_SetIntCmd(base, true);

	/* Wait for the transfer to complete */
	k_sem_take(&data->device_sync_sem, K_FOREVER);

}
예제 #10
0
파일: adxl345.c 프로젝트: yzfcer/wind-os
/*
************************************************************
*	函数名称:	ADXL345_Init
*
*	函数功能:	ADXL345初始化配置
*
*	入口参数:	无
*
*	返回参数:	无
*
*	说明:		
************************************************************
*/
void ADXL345_Init(void)
{
	
    unsigned char devid = 0, val = 0;

    DelayUs(300);

    I2C_ReadByte(ADXL345_ADDRESS, 0x00, &devid);			//读ID	且每次读写之前都需要读ID
	DelayUs(300);

	val = 0x2B;
    I2C_WriteByte(ADXL345_ADDRESS, DATA_FORMAT_REG, &val);	//低电平中断输出,13位全分辨率,输出数据右对齐,16g量程
	DelayUs(50);
    
	val = 0x0A;
    I2C_WriteByte(ADXL345_ADDRESS, BW_RATE, &val);			//数据输出速度为100Hz
	DelayUs(50);
    
	val = 0x28;
    I2C_WriteByte(ADXL345_ADDRESS, POWER_CTL, &val);		//链接使能,测量模式
	DelayUs(50);
    
	val = 0;
    I2C_WriteByte(ADXL345_ADDRESS, INT_ENABLE, &val);		//不使用中断
	DelayUs(50);
	
    DelayXms(20);
	
	//软件偏移校准,视上电时为平放状态,x=0,y=0,z=1=====================
	ADXL345_GetValue();
	
	ofz_X = 0 - adxlInfo.incidence_X;
	ofz_Y = 0 - adxlInfo.incidence_Y;
	ofz_Z = 256 - adxlInfo.incidence_Z;

}
예제 #11
0
파일: adxl345.c 프로젝트: yzfcer/wind-os
/*
************************************************************
*	函数名称:	ADXL345_GetValue
*
*	函数功能:	读取ADXL345的三轴加速值
*
*	入口参数:	无
*
*	返回参数:	无
*
*	说明:		结果存放于adxl345结构体中
************************************************************
*/
void ADXL345_GetValue(void)
{

	unsigned char devid = 0;
	
	unsigned char dataTemp[6];
	
	IIC_SpeedCtl(5);													//控制IIC速度

    DelayUs(200);
    I2C_ReadByte(ADXL345_ADDRESS, 0x00, &devid);						//读ID	且每次读写之前都需要读ID
	DelayUs(200);
	
	I2C_ReadBytes(ADXL345_ADDRESS, 0x32, dataTemp, 6);					//读取原始加速值(4mg/LSB)
	
	adxlInfo.incidence_X = (short)(dataTemp[0] + ((unsigned short)dataTemp[1] << 8));
    adxlInfo.incidence_Y = (short)(dataTemp[2] + ((unsigned short)dataTemp[3] << 8));
    adxlInfo.incidence_Z = (short)(dataTemp[4] + ((unsigned short)dataTemp[5] << 8));
	
	adxlInfo.incidence_Xf = (float)(adxlInfo.incidence_X + ofz_X) * 0.0039;		//换算为g
	adxlInfo.incidence_Yf = (float)(adxlInfo.incidence_Y + ofz_Y) * 0.0039;		//每一个LSB代表3.9mg
	adxlInfo.incidence_Zf = (float)(adxlInfo.incidence_Z + ofz_Z) * 0.0039;		//有多少个LSB,就乘以0.0039g就得到了以g为单位的加速值

}
void ExitTest()
{
	unsigned char RxBuffer[10];
	unsigned char IDCode;

	I2C_ReadByte(0xE0,0x18,&IDCode,1); //read RAM
	if(IDCode == 0x13)
	{
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x43,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x1C,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x1D,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x00,RxBuffer,1); 
		msleep(5);
	}
	else
	{
		  //exit test mode
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x43,RxBuffer,1); 
		/*RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x1C,RxBuffer,1); 
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x1D,RxBuffer,1); */
		RxBuffer[0]=0x00;
		I2C_WriteByte(0xE0,0x00,RxBuffer,1); 
		msleep(5);
	}
}
예제 #13
0
static void i2c_imx_isr(void *arg)
{
	struct device *dev = (struct device *)arg;
	I2C_Type *base = DEV_BASE(dev);
	struct i2c_imx_data *data = DEV_DATA(dev);
	struct i2c_master_transfer *transfer = &data->transfer;

	/* Clear interrupt flag. */
	I2C_ClearStatusFlag(base, i2cStatusInterrupt);


	/* Exit the ISR if no transfer is happening for this instance. */
	if (!transfer->isBusy)
		return;

	if (i2cModeMaster == transfer->currentMode) {
		if (i2cDirectionTransmit == transfer->currentDir) {
			/* Normal write operation. */
			transfer->ack =
			!(I2C_GetStatusFlag(base, i2cStatusReceivedAck));

			if (transfer->txSize == 0) {
				/* Close I2C interrupt. */
				I2C_SetIntCmd(base, false);
				/* Release I2C Bus. */
				transfer->isBusy = false;
				k_sem_give(&data->device_sync_sem);
			} else {
				I2C_WriteByte(base, *transfer->txBuff);
				transfer->txBuff++;
				transfer->txSize--;
			}
		} else {
			/* Normal read operation. */
			if (transfer->rxSize == 2) {
				/* Send Nack */
				I2C_SetAckBit(base, false);
			} else {
				/* Send Ack */
				I2C_SetAckBit(base, true);
			}

			if (transfer->rxSize == 1) {
				/* Switch back to Tx direction to avoid
				 * additional I2C bus read.
				 */
				I2C_SetDirMode(base, i2cDirectionTransmit);
				transfer->currentDir = i2cDirectionTransmit;
			}

			*transfer->rxBuff = I2C_ReadByte(base);
			transfer->rxBuff++;
			transfer->rxSize--;

			/* receive finished. */
			if (transfer->rxSize == 0) {
				/* Close I2C interrupt. */
				I2C_SetIntCmd(base, false);
				/* Release I2C Bus. */
				transfer->isBusy = false;
				k_sem_give(&data->device_sync_sem);
			}
		}
	}
}
예제 #14
0
void sii9234_register_init(void)
{
    // Power Up
    I2C_WriteByte(0x7A, 0x3D, 0x3F);			// Power up CVCC 1.2V core
    I2C_WriteByte(0x92, 0x11, 0x01);			// Enable TxPLL Clock
    I2C_WriteByte(0x92, 0x12, 0x15);			// Enable Tx Clock Path & Equalizer
    I2C_WriteByte(0x72, 0x08, 0x35);			// Power Up TMDS Tx Core

    I2C_WriteByte(0x92, 0x00, 0x00);			// SIMG: correcting HW default
    I2C_WriteByte(0x92, 0x13, 0x60);			// SIMG: Set termination value
    I2C_WriteByte(0x92, 0x14, 0xF0);			// SIMG: Change CKDT level
    I2C_WriteByte(0x92, 0x4B, 0x06);			// SIMG: Correcting HW default

    // Analog PLL Control
    I2C_WriteByte(0x92, 0x17, 0x07);			// SIMG: PLL Calrefsel
    I2C_WriteByte(0x92, 0x1A, 0x20);			// VCO Cal
    I2C_WriteByte(0x92, 0x22, 0xE0);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x23, 0xC0);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x24, 0xA0);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x25, 0x80);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x26, 0x60);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x27, 0x40);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x28, 0x20);			// SIMG: Auto EQ
    I2C_WriteByte(0x92, 0x29, 0x00);			// SIMG: Auto EQ

    I2C_WriteByte(0x92, 0x4D, 0x02);			// SIMG: PLL Mode Value (order is important)
    I2C_WriteByte(0x92, 0x4C, 0xA0);			// Manual zone control

    I2C_WriteByte(0x72, 0x80, 0x14);			// Enable Rx PLL Clock Value

    I2C_WriteByte(0x92, 0x31, 0x0B);			// SIMG: Rx PLL BW value from I2C BW ~ 4MHz
    I2C_WriteByte(0x92, 0x45, 0x06);			// SIMG: DPLL Mode
    I2C_WriteByte(0x72, 0xA0, 0xD0);			// SIMG: Term mode
    I2C_WriteByte(0x72, 0xA1, 0xFC);			// Disable internal Mobile HD driver

    I2C_WriteByte(0x72, 0xA3, 0xF9);			// SIMG: Output Swing  default EB
    I2C_WriteByte(0x72, 0xA6, 0x0C);			// SIMG: Swing Offset

    I2C_WriteByte(0x72, 0x2B, 0x01);			// Enable HDCP Compliance workaround

    // CBUS & Discovery
    ReadModifyWriteTPI(0x90, SI_BIT_3 | SI_BIT_2, SI_BIT_3);	// CBUS discovery cycle time for each drive and float = 150us

    I2C_WriteByte(0x72, 0x91, 0xE5);		// Skip RGND detection

    I2C_WriteByte(0x72, 0x94, 0x66);			// 1.8V CBUS VTH & GND threshold

    //set bit 2 and 3, which is Initiator Timeout
    I2C_WriteByte(CBUS_SLAVE_ADDR, 0x31, I2C_ReadByte(CBUS_SLAVE_ADDR, 0x31) | 0x0c);

    // original 3x config
    I2C_WriteByte(0x72, 0xA5, 0x80);			// SIMG: RGND Hysterisis, 3x mode for Beast
    I2C_WriteByte(0x72, 0x95, 0x31);			// RGND & single discovery attempt (RGND blocking)
    I2C_WriteByte(0x72, 0x96, 0x22);			// use 1K and 2K setting

    ReadModifyWriteTPI(0x95, SI_BIT_6, SI_BIT_6);		// Force USB ID switch to open

    WriteByteTPI(0x92, 0x46);				// Force MHD mode
    WriteByteTPI(0x93, 0xDC);				// Disable CBUS pull-up during RGND measurement

    ReadModifyWriteTPI(0x79, SI_BIT_1 | SI_BIT_2, 0);        //daniel test...MHL_INT

    delay_ms(25);
    ReadModifyWriteTPI(0x95, SI_BIT_6, 0x00);		// Release USB ID switch

    I2C_WriteByte(0x72, 0x90, 0x27);			// Enable CBUS discovery

    InitCBusRegs();

    I2C_WriteByte(0x72, 0x05, ASR_VALUE); 		// Enable Auto soft reset on SCDT = 0

    I2C_WriteByte(0x72, 0x0D, 0x1C); 			// HDMI Transcode mode enable
}
예제 #15
0
byte ReadByteCBUS (byte Offset)
{
    return I2C_ReadByte(CBUS_SLAVE_ADDR, Offset);
}
예제 #16
0
byte ReadByteTPI (byte Offset)
{
    return I2C_ReadByte(TPI_SLAVE_ADDR, Offset);
}
예제 #17
0
static ssize_t MHD_check_read(struct device *dev, struct device_attribute *attr, char *buf)
{
	int count;
	int res;
	#if 0

	s3c_gpio_setpull(GPIO_MHL_SEL, S3C_GPIO_PULL_UP);	//MHL_SEL

	gpio_set_value(GPIO_MHL_SEL, 1);
	

	//TVout_LDO_ctrl(true);
	
	if(!MHD_HW_IsOn())
	{
		sii9234_tpi_init();
		res = MHD_Read_deviceID();
		MHD_HW_Off();		
	}
	else
	{
		sii9234_tpi_init();
		res = MHD_Read_deviceID();
	}

	I2C_WriteByte(0x72, 0xA5, 0xE1);
	res = 0;
	res = I2C_ReadByte(0x72, 0xA5);

	printk("A5 res %x",res);

	res = 0;
	res = I2C_ReadByte(0x72, 0x1B);

	printk("Device ID res %x",res);

	res = 0;
	res = I2C_ReadByte(0x72, 0x1C);

	printk("Device Rev ID res %x",res);

	res = 0;
	res = I2C_ReadByte(0x72, 0x1D);

	printk("Device Reserved ID res %x",res);

	printk("\n####HDMI_EN1 %x MHL_RST %x GPIO_MHL_SEL %x\n",gpio_get_value(GPIO_HDMI_EN1),gpio_get_value(GPIO_MHL_RST),gpio_get_value(GPIO_MHL_SEL));

	res = I2C_ReadByte(0x7A, 0x3D);

	res = I2C_ReadByte(0x7A, 0xFF);
		
	s3c_gpio_setpull(GPIO_MHL_SEL, S3C_GPIO_PULL_NONE);	//MHL_SEL

	gpio_set_value(GPIO_MHL_SEL, 0);

#endif
	count = sprintf(buf,"%d\n", res );
	//TVout_LDO_ctrl(false);
	return count;
}
예제 #18
0
void Get_Complementarty_Orientation(int IMU_data[], float Delta_time){
	static float pitch = 0;
	static float roll = 0;
	static float yaw = 0;
	
	//Failure flag
	uint8_t failed = 0;
	
	uint16_t Accel_x_int	= (I2C_ReadByte(0x28, ACCEL_X_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, ACCEL_X_L, PIO_Data, PIO_DDIR, &failed));
	uint16_t Accel_y_int	= (I2C_ReadByte(0x28, ACCEL_Y_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, ACCEL_Y_L, PIO_Data, PIO_DDIR, &failed));
	uint16_t Accel_z_int	= (I2C_ReadByte(0x28, ACCEL_Z_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, ACCEL_Z_L, PIO_Data, PIO_DDIR, &failed));
	
	//printf("Accel_x_u: %d\n", Accel_x_int);
	//printf("Accel_y_u: %d\n", Accel_y_int);
	//printf("Accel_z_u: %d\n", Accel_z_int);
	
	uint16_t Mag_x_int 	= (I2C_ReadByte(0x28, MAG_X_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, MAG_X_L, PIO_Data, PIO_DDIR, &failed));
	uint16_t Mag_y_int 	= (I2C_ReadByte(0x28, MAG_Y_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, MAG_Y_L, PIO_Data, PIO_DDIR, &failed));
	uint16_t Mag_z_int 	= (I2C_ReadByte(0x28, MAG_Z_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, MAG_Z_L, PIO_Data, PIO_DDIR, &failed));
	
	//printf("Mag_x_u: %d\n", Mag_x_int);
	//printf("Mag_y_u: %d\n", Mag_y_int);
	//printf("Mag_z_u: %d\n", Mag_z_int);
	
	uint16_t Gyro_x_int	= (I2C_ReadByte(0x28, GYRO_X_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, GYRO_X_L, PIO_Data, PIO_DDIR, &failed)); 
	uint16_t Gyro_y_int	= (I2C_ReadByte(0x28, GYRO_Y_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, GYRO_Y_L, PIO_Data, PIO_DDIR, &failed)); 
	uint16_t Gyro_z_int	= (I2C_ReadByte(0x28, GYRO_Z_H, PIO_Data, PIO_DDIR, &failed) << 8) | (I2C_ReadByte(0x28, GYRO_Z_L, PIO_Data, PIO_DDIR, &failed));
	
	//printf("Gyro_x_u: %d\n", Gyro_x_int);
	//printf("Gyro_y_u: %d\n", Gyro_y_int);
	//printf("Gyro_z_u: %d\n", Gyro_z_int);
	
	int Accel_x = ((int16_t)Accel_x_int);
	int Accel_y = ((int16_t)Accel_y_int);
	int Accel_z = ((int16_t)Accel_z_int);
	
	//printf("Accel_x: %d\n", Accel_x);
	//printf("Accel_y: %d\n", Accel_y);
	//printf("Accel_z: %d\n", Accel_z);
	
	int Mag_x 	= ((int16_t)Mag_x_int);
	int Mag_y 	= ((int16_t)Mag_y_int);
	int Mag_z 	= ((int16_t)Mag_z_int);
	
	float Gyro_x = ((float)((int16_t)Gyro_x_int)/(float)16) * (PI/(float)180);
	float Gyro_y = ((float)((int16_t)Gyro_y_int)/(float)16) * (PI/(float)180);
	float Gyro_z = ((float)((int16_t)Gyro_z_int)/(float)16) * (PI/(float)180);  

	//printf("Gyro_x: %lf\n", Gyro_x);
	//printf("Gyro_y: %lf\n", Gyro_y);
	//printf("Gyro_z: %lf\n", Gyro_z);
	
	roll =  GYRO_WEIGHT * (roll + Gyro_x * Delta_time) + (1 - GYRO_WEIGHT)*atan2((double)Accel_y,(double)Accel_z);
	
	//printf("Roll: %lf\t", roll);
	
	pitch = GYRO_WEIGHT * (pitch + Gyro_y * Delta_time) + (1 - GYRO_WEIGHT)*atan2(-1*Accel_x, (Accel_y*sin(roll) + Accel_z*cos(roll))); 
	
	//printf("Pitch: %lf\t", pitch);
	
	float Mag_heading = atan2(Mag_z * sin(roll) - Mag_y*cos(roll), (Mag_x*cos(pitch) + Mag_y*sin(pitch)*sin(roll) + Mag_z*sin(pitch)*cos(roll)));
	
	yaw = GYRO_WEIGHT * (yaw + Gyro_z * Delta_time) + (1 - GYRO_WEIGHT)*Mag_heading;
	
	//printf("Yaw: %lf\n", yaw);
	
	IMU_data[0]  = (int)((pitch*(180/PI))*16);
	IMU_data[1]  = (int)((roll*(180/PI))*16);
	IMU_data[2]  = (int)((yaw*(180/PI))*16);
}
예제 #19
0
                {
                        .addr = 0x30, .flags = 0, .len = 1, .buf = &pbuf[2],
                },
                {
                        .addr = 0x50, .flags = 0, .len = 1, .buf = &pbuf[3],
                },
                {       //Block-3
                        .addr = 0x50, .flags = I2C_M_RD, .len = 128, .buf = &edid_buf[384],
                },
        };

#if 0
        DisableTMDS(hdmi);
#else
        uint8_t val;
        val = I2C_ReadByte(TPI_SLAVE_ADDR, 0x1A);
	I2C_WriteByte(TPI_SLAVE_ADDR, 0x1A, val|BIT_4);
#endif

        if (!GetDDC_Access(&SysCtrlReg)) {
                pr_err("%s: DDC bus request failed\n", __func__);
                return false;
        }

        // Block-0
        memset(edid_buf, 0, 512);
	
	for (i=0; i < 512 ; i++) {
        	if (i%16 == 0 ) pr_debug("\n");
	        pr_debug(" %x", edid_buf[i]);
	}
byte ReadByteTPI (byte Offset) 
{
	return I2C_ReadByte(SA_TX_Page0_Primary, Offset);
}
예제 #21
0
void ReadByte_MPU (uint8_t registro, uint8_t *puntero)
{
	I2C_ReadByte(ADDRESS_MPU, registro, puntero);
}
byte SiIRegioCbusRead ( word regAddr, byte channel )
{
    return(I2C_ReadByte(SA_TX_CBUS_Primary + l_cbusPortOffsets[channel], regAddr));
}
/*******************************************************************************
* Function Name  : MainTrim
* Description : STC3115 internal register configuration function
* This function has to be called at stable battery voltage during the application magnufacturing
* This function is checking itself the propper configuration of the device.
*******************************************************************************/
int MainTrim(struct i2c_client *client)
{
	unsigned char IDCode; 
	int ii,error,testnbr;

	if (client)	
		sav_client = client;
	else 
		return STC_CONFIG_CLIENT_FAIL;
	
    //Check the cut v ersion
	I2C_ReadByte(0xE0,0x18,&IDCode,1); //read IDcode
	if(IDCode == 0x13)
	{
		return STC_CONFIG_IDCODE_NOTMATCH;
	}

	ReadRAM(); //Enter test mode
	ReadSector(0, Sector0);  //read sector 0
	ExitTest(); //exit test mode

    if ( (Sector0[1] & 0x01) == 0 )
    {	
      testnbr=0;
      do
      {
        ReadRAM(); //Enter test mode
		ReadSector(0, Sector0);  //read sector 0
		ExitTest(); //exit test mode

        Sector0	[1] = Sector0[1] | 0x01 ;
        PreWriteNVN(0x40);     //Enter test mode 
		WriteSector(6,Sector0);//write sector 0 in 6
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(6, Sector6);  //read sector 6
		ExitTest(); //exit test mode
        
        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector0[ii] != Sector6[ii]) error++;
        }
        testnbr++;
      }
      while(error > 0 && testnbr < 5);
      if (testnbr >= 3)
          return STC_CONFIG_TEST_FAIL;

      testnbr=0;
      do
      {
        PreWriteNVN(0x01);     //Enter test mode 
		WriteSector(0,Sector6);//write sector 0 in 0
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(0, Sector0);  //read sector 0
		ExitTest(); //exit test mode
        
        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector0[ii] != Sector6[ii]) error++;
        }
        testnbr++;
      }
      while(error > 0 && testnbr < 5);
    }



    //Check sector 6 status
#if defined (CONFIG_MACH_HENDRIX) ||		\
	defined (CONFIG_MACH_LT02) ||			\
	defined (CONFIG_MACH_COCOA7)
		Sector3	[	0	]=0x82	;
		Sector3	[	1	]=0x8C	;
		Sector3	[	2	]=0xA0	;
		Sector3	[	3	]=0xB4	;
		Sector3	[	4	]=0xC8	;

		Sector3	[	5	]=0x70	;
		Sector3	[	6	]=0x17	;
		Sector3	[	7	]=0x27	;
		Sector4	[	0	]=0x19	;
		Sector4	[	1	]=0xB2	;
		Sector4	[	2	]=0x19	;
		Sector4	[	3	]=0xFA	;
		Sector4	[	4	]=0x19	;
		Sector4	[	5	]=0x3E	;
		Sector4	[	6	]=0x1A	;
		Sector4	[	7	]=0x6D	;
		Sector5	[	0	]=0x1A	;
		Sector5	[	1	]=0x9D	;
		Sector5	[	2	]=0x1A	;
		Sector5	[	3	]=0xB7	;
		Sector5	[	4	]=0x1A	;
		Sector5	[	5	]=0xD5	;
		Sector5	[	6	]=0x1A	;
		Sector5	[	7	]=0x01	;
		Sector6	[	0	]=0x1B	;
		Sector6	[	1	]=0x6F	;
		Sector6	[	2	]=0x1B	;
		Sector6	[	3	]=0xB1  ;
		Sector6	[	4	]=0x1B	;
		Sector6	[	5	]=0xE7	;
		Sector6	[	6	]=0x1B	;
		Sector6	[	7	]=0x59	;

    ReadRAM(); //Enter test mode
	ReadSector(7, Sector0);  //read sector 7
    ReadSector(7, Sector7);  //read sector 7
	ExitTest(); //exit test mode

		Sector7	[	0	]=0x1C	;
		Sector7	[	1	]=0xF3	;
		Sector7	[	2	]=0x1C	;
		Sector7	[	3	]=0xA8	;
		Sector7	[	4	]=0x1D	;

    error=0;
    for(ii=0;ii<8;ii++)
    {
      if(Sector0[ii] != Sector7[ii]) error++;
    }

    testnbr=0;
    while(error > 0 && testnbr < 5)
    {
        PreWriteNVN(0x80);     //Enter test mode
			  WriteSector(7,Sector7);//write sector 7 in 7
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(7, Sector0);  //read sector 7
		ExitTest(); //exit test mode

        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector7[ii] != Sector0[ii]) error++;
        }
        testnbr++;
    }



    //write sector 3 in 3
    ReadRAM(); //Enter test mode
	ReadSector(3, Sector0);  //read sector 3
	ExitTest(); //exit test mode

    error=0;
    for(ii=0;ii<8;ii++)
    {
      if(Sector0[ii] != Sector3[ii]) error++;
    }

    testnbr=0;
    while(error > 0 && testnbr < 5)
    {
        PreWriteNVN(0x08);     //Enter test mode
		WriteSector(3,Sector3);//write sector 3 in 3
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(3, Sector0);  //read sector 3
		ExitTest(); //exit test mode

        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector3[ii] != Sector0[ii]) error++;
        }
        testnbr++;
    }


    //write sector 4 in 4
    ReadRAM(); //Enter test mode
	  ReadSector(4, Sector0);  //read sector 4
	  ExitTest(); //exit test mode

    error=0;
    for(ii=0;ii<8;ii++)
    {
      if(Sector0[ii] != Sector4[ii]) error++;
    }

    testnbr=0;
    while(error > 0 && testnbr < 5)
    {
        PreWriteNVN(0x10);     //Enter test mode
		WriteSector(4,Sector4);//write sector 4 in 4
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(4, Sector0);  //read sector 4
		ExitTest(); //exit test mode

        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector4[ii] != Sector0[ii]) error++;
        }
        testnbr++;
    }

    //write sector 5 in 5
    ReadRAM(); //Enter test mode
	  ReadSector(5, Sector0);  //read sector 5
	  ExitTest(); //exit test mode

    error=0;
    for(ii=0;ii<8;ii++)
    {
      if(Sector0[ii] != Sector5[ii]) error++;
    }

    testnbr=0;
    while(error > 0 && testnbr < 5)
    {
        PreWriteNVN(0x20);     //Enter test mode
		WriteSector(5,Sector5);//write sector 5 in 5
        ExitTest();

        ReadRAM(); //Enter test mode
		ReadSector(5, Sector0);  //read sector 5
		ExitTest(); //exit test mode

        error=0;
        for(ii=0;ii<8;ii++)
        {
          if(Sector5[ii] != Sector0[ii]) error++;
        }
        testnbr++;
    }

    //write sector 6 in 6
      ReadRAM(); //Enter test mode
	  ReadSector(6, Sector0);  //read sector 6
	  ExitTest(); //exit test mode
#else
    Sector6	[	0	]=0x1B	;
	Sector6	[	1	]=0xCD	;
	Sector6	[	2	]=0x1B	;
	Sector6	[	3	]=0x13	;
	Sector6	[	4	]=0x1C	;
	Sector6	[	5	]=0x57	;
	Sector6	[	6	]=0x1C	;
	Sector6	[	7	]=0x09	;

    ReadRAM(); //Enter test mode
	ReadSector(6, Sector0);  //read sector 0
	ExitTest(); //exit test mode
#endif

    error=0;
    for(ii=0;ii<8;ii++)
    {
      if(Sector0[ii] != Sector6[ii]) error++;
    }

    testnbr=0;
    while(error > 0 && testnbr < 5)
    {
		PreWriteNVN(0x40);     //Enter test mode 
		WriteSector(6,Sector6);//write sector 6 in 6
		ExitTest();

		ReadRAM(); //Enter test mode
	    ReadSector(6, Sector0);  //read sector 0
	    ExitTest(); //exit test mode

		error=0;
		for(ii=0;ii<8;ii++)
		{
			if(Sector0[ii] != Sector6[ii]) error++;
		}
		testnbr++;
    }

	return -1;
}
byte ReadByteCBUS (byte Offset) 
{
	return I2C_ReadByte(SA_TX_CBUS_Primary, Offset);
}
/*******************************************************************************
* Function Name  : MainTrim
* Description : STC3115 internal register configuration function
* This function has to be called at stable battery voltage during the application magnufacturing
* This function is checking itself the propper configuration of the device.
*******************************************************************************/
int MainTrim(struct i2c_client *client)
{
	unsigned char IDCode,RAMBuffer[16];
	int ii,error,testnbr;

	if (client)
		sav_client = client;
	else
		return STC_CONFIG_CLIENT_FAIL;

	//Check the cut v ersion
	I2C_ReadByte(0xE0,0x18,&IDCode,1); //read IDcode
	if(IDCode == 0x13)
	{
		return STC_CONFIG_IDCODE_NOTMATCH;
	}

	I2C_ReadByte(0xE0,0x20,RAMBuffer,16); //read RAM memory content

	ReadRAM(); //Enter test mode
	ReadSector(0, Sector0);  //read sector 0
	ExitTest(); //exit test mode

	if ( (Sector0[1] & 0x01) == 0 )
	{
		testnbr=0;
		do
		{
			ReadRAM(); //Enter test mode
			ReadSector(0, Sector0);  //read sector 0
			ExitTest(); //exit test mode

			Sector0	[1] = Sector0[1] | 0x01 ;
			PreWriteNVN(0x40);     //Enter test mode
			WriteSector(6,Sector0);//write sector 0 in 6
			ExitTest();

			ReadRAM(); //Enter test mode
			ReadSector(6, Sector6);  //read sector 6
			ExitTest(); //exit test mode

			error=0;
			for(ii=0;ii<8;ii++)
			{
				if(Sector0[ii] != Sector6[ii]) error++;
			}
			testnbr++;
		}
		while(error > 0 && testnbr < 5);
		if (testnbr >= 3)
		{
			I2C_WriteByte(0xE0,0x20,RAMBuffer,16);//restore RAM memory content
			return STC_CONFIG_TEST_FAIL;
		}

		testnbr=0;
		do
		{
			PreWriteNVN(0x01);     //Enter test mode
			WriteSector(0,Sector6);//write sector 0 in 0
			ExitTest();

			ReadRAM(); //Enter test mode
			ReadSector(0, Sector0);  //read sector 0
			ExitTest(); //exit test mode

			error=0;
			for(ii=0;ii<8;ii++)
			{
				if(Sector0[ii] != Sector6[ii]) error++;
			}
			testnbr++;
		}
		while(error > 0 && testnbr < 5);
	}

	//Check sector 6 status
	Sector6	[	0	]=0x1B	;
	Sector6	[	1	]=0xCD	;
	Sector6	[	2	]=0x1B	;
	Sector6	[	3	]=0x13  ;
	Sector6	[	4	]=0x1C	;
	Sector6	[	5	]=0x57	;
	Sector6	[	6	]=0x1C	;
	Sector6	[	7	]=0x09	;

	ReadRAM(); //Enter test mode
	ReadSector(6, Sector0);  //read sector 7
	ExitTest(); //exit test mode

	error=0;
	for(ii=0;ii<8;ii++)
	{
		if(Sector0[ii] != Sector6[ii]) error++;
	}

	testnbr=0;
	while(error > 0 && testnbr < 5)
	{
		PreWriteNVN(0x40);     //Enter test mode
		WriteSector(6,Sector6);//write sector 7 in 7
		ExitTest();

		ReadRAM(); //Enter test mode
		ReadSector(6, Sector0);  //read sector 7
		ExitTest(); //exit test mode

		error=0;
		for(ii=0;ii<8;ii++)
		{
			if(Sector0[ii] != Sector6[ii]) error++;
		}
		testnbr++;
	}

	I2C_WriteByte(0xE0,0x20,RAMBuffer,16);//restore RAM memory content

	return -1;
}
예제 #26
0
/*
@brief  关闭写保护.
@param  None.
@retval None.
*/
void FM31256_CloseWP (void)
{
	uint8_t db;
	db = I2C_ReadByte(REG_READ, COMPANION);
	I2C_WriteByte(REG_WRITE,COMPANION,db&0xe7);
}
void PreWriteNVN(unsigned char ErasedSector)
{
	unsigned char RxBuffer[10];
	unsigned char IDCode;

	I2C_ReadByte(0xE0,0x18,&IDCode,1); //read RAM
	if(IDCode == 0x13)
	{
		RxBuffer[0]=0x10;
		I2C_WriteByte(0xE0,0x00,RxBuffer,1);
		RxBuffer[0]=0xBE;
		I2C_WriteByte(0xE0,0x1C,RxBuffer,1);
		RxBuffer[0]=0xEF;
		I2C_WriteByte(0xE0,0x1D,RxBuffer,1);
		RxBuffer[0]=0x09;
		I2C_WriteByte(0xE0,0x43,RxBuffer,1);
		RxBuffer[0]=0xC0;
		I2C_WriteByte(0xE0,0x46,RxBuffer,1);
		msleep(3);
		RxBuffer[0]=ErasedSector;
		I2C_WriteByte(0xE0,0x20,RxBuffer,1); 
		RxBuffer[0]=0x01;
		I2C_WriteByte(0xE0,0x45,RxBuffer,1); 
		RxBuffer[0]=0xCA; // Load SER FTP opcode //3.2s
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(3);

		RxBuffer[0]=0x00;  // clear register 45
		I2C_WriteByte(0xE0,0x45,RxBuffer,1); 
		RxBuffer[0]=0xCF;
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(5);

		RxBuffer[0]=0xCD;  // Write Erase FTP opcode
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(3);

	} 
	else
	{
		RxBuffer[0]=0x10;  // Set GG_RUN = 1
		I2C_WriteByte(0xE0,0x00,RxBuffer,1);
		RxBuffer[0]=0xBE;  // Set TM
		I2C_WriteByte(0xE0,0x1F,RxBuffer,1);
		RxBuffer[0]=0xC0;  // Set FTP_PWR=1, FTP_RST_N=1
		I2C_WriteByte(0xE0,0x46,RxBuffer,1);
		msleep(3);
		RxBuffer[0]=ErasedSector;  // Load FF to erase all sectors of FTP
		I2C_WriteByte(0xE0,0x20,RxBuffer,1); 
		RxBuffer[0]=0x01;  // Load SER opcode //3.2s
		I2C_WriteByte(0xE0,0x45,RxBuffer,1); 
		RxBuffer[0]=0xCA; // Load SER FTP opcode //3.2s
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(3);

		RxBuffer[0]=0x00;  // clear register 45
		I2C_WriteByte(0xE0,0x45,RxBuffer,1); 
		RxBuffer[0]=0xCF;
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(3);

		RxBuffer[0]=0xCD;  // Write Erase FTP opcode
		I2C_WriteByte(0xE0,0x46,RxBuffer,1); 
		msleep(3);

	}
}
예제 #28
0
int main() {

	// Initialize Port Registers 
	//---------------------------------------------------------------

	void *virtual_base;
	int fd;
	void *PIO_Data;
	void *PIO_DDIR;
	
	void *UART_DATA;
	void *UART_CONTROL;


	if( ( fd = open( "/dev/mem", ( O_RDWR | O_SYNC ) ) ) == -1 ) {
		printf( "ERROR: could not open \"/dev/mem\"...\n" );
		return( 1 );
	}

	virtual_base = mmap( NULL, HW_REGS_SPAN, ( PROT_READ | PROT_WRITE ), MAP_SHARED, fd, HW_REGS_BASE );

	if( virtual_base == MAP_FAILED ) {
		printf( "ERROR: mmap() failed...\n" );
		close( fd );
		return( 1 );
	}
	
	PIO_Data = virtual_base + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + PIO_Data_ADDR ) & ( unsigned long)( HW_REGS_MASK ) );
	PIO_DDIR = virtual_base + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + PIO_DDIR_ADDR ) & ( unsigned long)( HW_REGS_MASK ) );
	
	UART_DATA = virtual_base + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + UART_DATA_ADDR ) & ( unsigned long)( HW_REGS_MASK ) );
	UART_CONTROL = virtual_base + ( ( unsigned long  )( ALT_LWFPGASLVS_OFST + UART_CONTROL_ADDR ) & ( unsigned long)( HW_REGS_MASK ) );
	
	/*
	while(1){
		
		uint32_t temp = *(uint32_t *)UART_DATA;
		
		temp &= 0xFFFFFF00;
		
		*(uint32_t *)UART_DATA = (temp | 0x000000AA);
		
		usleep(2000);
	}*/
	
	
	//My code
	//--------------------------------------------------------------
	uint8_t failedWrite;
	
	//Set IMU to IMU mode
	I2C_WriteByte(0x28, 0x3d, 0b00001000, PIO_Data, PIO_DDIR, &failedWrite);
	
	
	
	//Read the entire memory from 0x0 to 0x3b of the imu
	int i; 
	for(i = 0x0; i < 0x3b; i++){
		uint8_t failed = 0;
		
		//Read Data From Device
		int data = I2C_ReadByte(0x28, i, PIO_Data, PIO_DDIR, &failed);
		
		
		if(failed){
			printf("Failed\n");
		}
			
			
		printf("Data(0x%02x): %d\n",i ,data);
		
		//I2C_Start(PIO_Data, PIO_DDIR);
		
		usleep(10000);
	} 
	
	
	// clean up our memory mapping and exit
	//-----------------------------------------------
	
	if( munmap( virtual_base, HW_REGS_SPAN ) != 0 ) {
		printf( "ERROR: munmap() failed...\n" );
		close( fd );
		return( 1 );
	}

	close( fd );

	return( 0 );
}
static void sii9234_register_init(void)
{
    /*Power Up*/
    I2C_WriteByte(0x7A, 0x3D, 0x3F);	/* Power up CVCC 1.2V core */
    I2C_WriteByte(0x92, 0x11, 0x01);	/* Enable TxPLL Clock*/
    I2C_WriteByte(0x92, 0x12, 0x15);	/* Enable Tx Clock Path & Equalizer*/
    I2C_WriteByte(0x72, 0x08, 0x35);	/* Power Up TMDS Tx Core*/

    I2C_WriteByte(0x92, 0x00, 0x00);	/* SIMG: correcting HW default*/
    I2C_WriteByte(0x92, 0x13, 0x60);	/* SIMG: Set termination value*/
    I2C_WriteByte(0x92, 0x14, 0xF0);	/* SIMG: Change CKDT level*/
    I2C_WriteByte(0x92, 0x4B, 0x06);	/* SIMG: Correcting HW default*/

    /*Analog PLL Control*/
    I2C_WriteByte(0x92, 0x17, 0x07);	/* SIMG: PLL Calrefsel*/
    I2C_WriteByte(0x92, 0x1A, 0x20);	/* VCO Cal*/
    I2C_WriteByte(0x92, 0x22, 0xE0);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x23, 0xC0);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x24, 0xA0);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x25, 0x80);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x26, 0x60);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x27, 0x40);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x28, 0x20);	/* SIMG: Auto EQ*/
    I2C_WriteByte(0x92, 0x29, 0x00);	/* SIMG: Auto EQ*/

    /*I2C_WriteByte(0x92, 0x10, 0xF1);*/
    I2C_WriteByte(0x92, 0x4D, 0x02);	/* SIMG: PLL Mode Value (order is important)*/
    /*I2C_WriteByte(0x92, 0x4D, 0x00);*/
    I2C_WriteByte(0x92, 0x4C, 0xA0);	/* Manual zone control*/

    /*I2C_WriteByte(0x72, 0x80, 0x14);*/	/* Enable Rx PLL Clock Value*/
    I2C_WriteByte(0x72, 0x80, 0x34);

    I2C_WriteByte(0x92, 0x31, 0x0B);	/* SIMG: Rx PLL BW value from I2C BW ~ 4MHz*/
    I2C_WriteByte(0x92, 0x45, 0x06);	/* SIMG: DPLL Mode*/
    I2C_WriteByte(0x72, 0xA0, 0xD0);	/* SIMG: Term mode*/
    I2C_WriteByte(0x72, 0xA1, 0xFC);	/* Disable internal Mobile HD driver*/


    I2C_WriteByte(0x72, 0xA3, 0xEB);	/* SIMG: Output Swing  default EB*/
    I2C_WriteByte(0x72, 0xA6, 0x00);	/* SIMG: Swing Offset*/

    I2C_WriteByte(0x72, 0x2B, 0x01);	/* Enable HDCP Compliance workaround*/

    /*CBUS & Discovery*/
    ReadModifyWriteTPI(0x90, SI_BIT_3 | SI_BIT_2, SI_BIT_3);/* CBUS discovery cycle time for each drive and float = 150us*/

    I2C_WriteByte(0x72, 0x91, 0xE5);	/* Skip RGND detection*/

    I2C_WriteByte(0x72, 0x94, 0x66);	/* 1.8V CBUS VTH & GND threshold*/

    /*set bit 2 and 3, which is Initiator Timeout*/
    I2C_WriteByte(CBUS_SLAVE_ADDR, 0x31, I2C_ReadByte(CBUS_SLAVE_ADDR, 0x31) | 0x0c);

    /*original 3x config*/
    I2C_WriteByte(0x72, 0xA5, 0x80);	/* SIMG: RGND Hysterisis, 3x mode for Beast*/
    I2C_WriteByte(0x72, 0x95, 0x31);	/* RGND & single discovery attempt (RGND blocking)*/
    I2C_WriteByte(0x72, 0x96, 0x22);	/* use 1K and 2K setting*/

    ReadModifyWriteTPI(0x95, SI_BIT_6, SI_BIT_6);		/* Force USB ID switch to open*/

    WriteByteTPI(0x92, 0x46);		/* Force MHD mode*/
    WriteByteTPI(0x93, 0xDC);		/* Disable CBUS pull-up during RGND measurement*/

    ReadModifyWriteTPI(0x79, SI_BIT_1 | SI_BIT_2, 0);        /*daniel test...MHL_INT*/

    mdelay(25);
    ReadModifyWriteTPI(0x95, SI_BIT_6, 0x00);	/* Release USB ID switch*/

    I2C_WriteByte(0x72, 0x90, 0x27);	/* Enable CBUS discovery*/

    InitCBusRegs();

    I2C_WriteByte(0x72, 0x05, ASR_VALUE);	/* Enable Auto soft reset on SCDT = 0*/

    I2C_WriteByte(0x72, 0x0D, 0x1C);	/* HDMI Transcode mode enable*/
}
예제 #30
0
  	Wire.begin();

	setBaud(baud);

	I2C_WriteByte(LCR, 0xBF); // access EFR register
	I2C_WriteByte(EFR, 0x10); // enable enhanced registers
	I2C_WriteByte(LCR, 0x03); // 8 data bit, 1 stop bit, no parity

	// can't these be done in the same call?
	I2C_WriteByte(FCR, 0x06); // reset TXFIFO, reset RXFIFO, non FIFO mode
	I2C_WriteByte(FCR, 0x01); // enable FIFO mode

	// Perform read/write test to check if UART is working
	I2C_WriteByte(SPR,'H');
	char data = I2C_ReadByte(SPR);
	// change it to something else for next time we check
	I2C_WriteByte(SPR,'x');

	if(data == 'H') {
		connStatus = 1;
  	}
	return connStatus;
}

void SC16IS::end() {
	connStatus = 0;
}

void SC16IS::enableIrDA(uint8_t enable) {
	// turn on 7th bit ie 64 or 0x40 to enable IrDA SIR. ONLY writable if EFR[4] (0x10) is enabled.