Exemplo n.º 1
0
/*---------------------------------------------------
int i2c_gpio_phase_start();
        Generate i2c_gpio_phase_start Condition:
        Stream Format:
                SCL   _____/--------\___
                SDA   =---------\_____
                width (4.7u)4.7u|4.7u|
        Arguments:
                NONE
        Return value:
                int SUCCESS                             0
                int ERR_STATUS  1
----------------------------------------------------*/
static RET_CODE i2c_gpio_phase_start(i2c_gpio_priv_t *p_priv)
{
  /* Make sure is out */
  SET_SDA_OUT(p_priv);
  SET_SCL_OUT(p_priv);

  SET_SDA_HI(p_priv);               /* Set SDA high */
  if(0 == GET_SCL(p_priv))
  {
    I2C_GPIO_DELAY_US(p_priv->clock_period);
  }

  SET_SCL_HI(p_priv);               /* Set SCL high */
  I2C_GPIO_DELAY_US(p_priv->clock_period);
  if(0 == GET_SCL(p_priv))
  {
    return ERR_STATUS;
  }

  if(0 == GET_SDA(p_priv))
  {
    return ERR_STATUS;
  }

  SET_SDA_LO(p_priv);
  I2C_GPIO_DELAY_US(p_priv->clock_period);
  SET_SCL_LO(p_priv);

  return SUCCESS;
}
//------------------------------------------------------------------------------
// Function: SetSCLHigh
// Description:
//------------------------------------------------------------------------------
static uint8_t SetSCLHigh(void)
{
    volatile uint8_t x = 0;    //delay variable
    uint32_t timeout = 0;
	
    // set SCL high, and wait for it to go high in case slave is clock stretching
    SET_SCL();
    x++;
    x++;
    x++;
    x++;

    while (!GET_SCL())
    {
        /* do nothing - just wait */
	//udelay(2);
	timeout++;
	    if( timeout > 100000 )   // about 1s is enough
	{
		printk("\n ************IIC SCL low timeout...\n");
		return IIC_SCL_TIMEOUT;
	}
    }
	
    return IIC_OK;
}
Exemplo n.º 3
0
static uint8_t i2c_soft_receive_bit(void)
{
    // SDA = 1
    // SCL = 1
    // wait SCL low
    // bit = SDA
    // SCL = 0
    
    uint8_t bit;
    
    SDA(1);
    waitSomeTimeInUs(1);
    
    SCL1();
    waitSomeTimeInUs(1);
    while( GET_SCL() == 0);
    
    bit = GET_SDA();
    
    SCL0();
    SDA_OUTPUT();
    waitSomeTimeInUs(1);
    
    return bit;
}