i2c_status_type fuel_gpio_fuel_gpio_i2c_write_addr(u8 val) { i2c_state_type state = I2C_FAIL_S; i2c_status_type status = I2C_FAILURE; i2c_gpio_type *bus = &i2c_io_info; if (bus->state == I2C_TX_S) { /* Bus already STARTed */ I2C_REP_START_COND(); } else if (bus->state == I2C_IDLE_S) { /* bus not STARTed */ I2C_START_COND(); } if (fuel_gpio_i2c_write_byte_io(val) == I2C_ACK) { /* Write addr byte */ /* State change depend on READ/WRITE */ state = ((val & I2C_IO_MASK) == I2C_IO_MASK_R)? I2C_RX_S: I2C_TX_S; status = I2C_SUCCESS; } else { status = I2C_SUCCESS; } bus->state = state; return (status); }
/* * Signal a start to the I2C Bus. * * A start is signaled when data goes to low in a high clock cycle. * * Ends with Clock Low. * * Status: not tested */ void SkI2cStart( SK_IOC IoC) /* I/O Context */ { /* Init data and Clock to output lines */ /* Set Data high */ I2C_DATA_OUT(IoC); I2C_DATA_HIGH(IoC); /* Set Clock high */ I2C_CLK_HIGH(IoC); SkDgWaitTime(IoC, NS2BCLK(T_START_SETUP)); /* Set Data Low */ I2C_DATA_LOW(IoC); SkDgWaitTime(IoC, NS2BCLK(T_START_HOLD)); /* Clock low without Data to Input */ I2C_START_COND(IoC); SkDgWaitTime(IoC, NS2BCLK(T_CLK_LOW)); } /* SkI2cStart */