libmaple/i2c.c
int32 i2c_master_xfer(i2c_dev *dev,
                      i2c_msg *msgs,
                      uint16 num,
                      uint32 timeout) {
    int32 rc;

    ASSERT(dev->state == I2C_STATE_IDLE);

    dev->msg = msgs;
    dev->msgs_left = num;
    dev->timestamp = systick_uptime();
    dev->state = I2C_STATE_BUSY;

    i2c_enable_irq(dev, I2C_IRQ_EVENT);
    i2c_start_condition(dev);

    rc = wait_for_state_change(dev, I2C_STATE_XFER_DONE, timeout);
    if (rc < 0) {
        goto out;
    }

    dev->state = I2C_STATE_IDLE;
out:
    return rc;
}
/**
 * @brief Process an i2c transaction.
 *
 * Transactions are composed of one or more i2c_msg's, and may be read
 * or write tranfers.  Multiple i2c_msg's will generate a repeated
 * start in between messages.
 *
 * @param dev I2C device
 * @param msgs Messages to send/receive
 * @param num Number of messages to send/receive
 * @param timeout Bus idle timeout in milliseconds before aborting the
 *                transfer.  0 denotes no timeout.
 * @return 0 on success,
 *         I2C_ERROR_PROTOCOL if there was a protocol error,
 *         I2C_ERROR_TIMEOUT if the transfer timed out.
 */
@brief Process an i2c transaction.
Transactions are composed of one or more i2c_msg's, and may be read
or write tranfers.  Multiple i2c_msg's will generate a repeated
start in between messages.

@param dev I2C device
@param msgs Messages to send/receive
@param num Number of messages to send/receive
@param timeout Bus idle timeout in milliseconds before aborting the
transfer.  0 denotes no timeout.
@return 0 on success,
I2C_ERROR_PROTOCOL if there was a protocol error,
I2C_ERROR_TIMEOUT if the transfer timed out.
@brief Process an i2c transaction . Transactions are composed of one or more i2c_msg ' s and may be read or write tranfers . Multiple i2c_msg ' s will generate a repeated start in between messages . @param dev I2C device @param msgs Messages to send / receive @param num Number of messages to send / receive @param timeout Bus idle timeout in milliseconds before aborting the transfer . 0 denotes no timeout . @return 0 on success I2C_ERROR_PROTOCOL if there was a protocol error I2C_ERROR_TIMEOUT if the transfer timed out .
int32 i2c_master_xfer(i2c_dev *dev,
                      i2c_msg *msgs,
                      uint16 num,
                      uint32 timeout) {
    int32 rc;
    ASSERT(dev->state == I2C_STATE_IDLE);
    dev->msg = msgs;
    dev->msgs_left = num;
    dev->timestamp = systick_uptime();
    dev->state = I2C_STATE_BUSY;
    i2c_enable_irq(dev, I2C_IRQ_EVENT);
    i2c_start_condition(dev);
    rc = wait_for_state_change(dev, I2C_STATE_XFER_DONE, timeout);
    if (rc < 0) {
        goto out;
    }
    dev->state = I2C_STATE_IDLE;
out:
    return rc;
}
int32 i2c_master_xfer ( i2c_dev * dev , i2c_msg * msgs , uint16 num , uint32 timeout ) { int32 rc ; ASSERT ( dev -> state == I2C_STATE_IDLE ) ; dev -> msg = msgs ; dev -> msgs_left = num ; dev -> timestamp = systick_uptime ( ) ; dev -> state = I2C_STATE_BUSY ; i2c_enable_irq ( dev , I2C_IRQ_EVENT ) ; i2c_start_condition ( dev ) ; rc = wait_for_state_change ( dev , I2C_STATE_XFER_DONE , timeout ) ; if ( rc < 0 ) { goto out ; } dev -> state = I2C_STATE_IDLE ; out : return rc ; }
@brief Process an i2c transaction.
@brief Process an i2c transaction .