我正在编写代码以使用“/linux/i2c.h”中的标准接口访问i2c驱动程序(从内核空间)
当我试图调用如下所示的方法时,出现了一个错误:(参数太少)。附件是“i2c.c”中定义的方法的实现代码
我的代码:

static inline unsigned char i2cReadByte()
{
    unsigned char retVal = 0x00;
    struct i2c_msg value;
    //TODO Fill in msg
    i2c_transfer((struct i2c_msg*)&value); // Error: too few arguments to function 'i2c_transfer'
    return retVal;
}

i2c.c中定义的i2c U传输码:
int i2c_transfer(struct i2c_msg *msg)
{
    int ret;

    if (!msg)
        goto transfer_error_msg_empty;

    switch(msg->direction) {

    case I2C_WRITE:

        /* check if bus is not busy */
        if (!i2c_isr_set_cleared(0,ISR_IBB))
            goto transfer_error_bus_busy;

        /* start transmission */
        ICR &= ~ICR_START;
        ICR &= ~ICR_STOP;
        IDBR = msg->data;
        if (msg->condition == I2C_COND_START)     ICR |=  ICR_START;
        if (msg->condition == I2C_COND_STOP)      ICR |=  ICR_STOP;
        if (msg->acknack   == I2C_ACKNAK_SENDNAK) ICR |=  ICR_ACKNAK;
        if (msg->acknack   == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK;
        ICR &= ~ICR_ALDIE;
        ICR |= ICR_TB;

        /* transmit register empty? */
        if (!i2c_isr_set_cleared(ISR_ITE,0))
            goto transfer_error_transmit_timeout;

        /* clear 'transmit empty' state */
        ISR |= ISR_ITE;

        /* wait for ACK from slave */
        if (msg->acknack == I2C_ACKNAK_WAITACK)
            if (!i2c_isr_set_cleared(0,ISR_ACKNAK))
                goto transfer_error_ack_missing;
        break;

    case I2C_READ:

        /* check if bus is not busy */
        if (!i2c_isr_set_cleared(0,ISR_IBB))
            goto transfer_error_bus_busy;

        /* start receive */
        ICR &= ~ICR_START;
        ICR &= ~ICR_STOP;
        if (msg->condition == I2C_COND_START)     ICR |= ICR_START;
        if (msg->condition == I2C_COND_STOP)      ICR |= ICR_STOP;
        if (msg->acknack   == I2C_ACKNAK_SENDNAK) ICR |=  ICR_ACKNAK;
        if (msg->acknack   == I2C_ACKNAK_SENDACK) ICR &= ~ICR_ACKNAK;
        ICR &= ~ICR_ALDIE;
        ICR |= ICR_TB;

        /* receive register full? */
        if (!i2c_isr_set_cleared(ISR_IRF,0))
            goto transfer_error_receive_timeout;

        msg->data = IDBR;

        /* clear 'receive empty' state */
        ISR |= ISR_IRF;

        break;

    default:

        goto transfer_error_illegal_param;

    }

    return 0;

transfer_error_msg_empty:
        PRINTD(("i2c_transfer: error: 'msg' is empty\n"));
        ret = -1; goto i2c_transfer_finish;

transfer_error_transmit_timeout:
        PRINTD(("i2c_transfer: error: transmit timeout\n"));
        ret = -2; goto i2c_transfer_finish;

transfer_error_ack_missing:
        PRINTD(("i2c_transfer: error: ACK missing\n"));
        ret = -3; goto i2c_transfer_finish;

transfer_error_receive_timeout:
        PRINTD(("i2c_transfer: error: receive timeout\n"));
        ret = -4; goto i2c_transfer_finish;

transfer_error_illegal_param:
        PRINTD(("i2c_transfer: error: illegal parameters\n"));
        ret = -5; goto i2c_transfer_finish;

transfer_error_bus_busy:
        PRINTD(("i2c_transfer: error: bus is busy\n"));
        ret = -6; goto i2c_transfer_finish;

i2c_transfer_finish:
        PRINTD(("i2c_transfer: ISR: 0x%04x\n",ISR));
        i2c_reset();
        return ret;

}

最佳答案

您与linux/i2c.h中的一个内核函数有名称冲突:

/* Transfer num messages.
 */
extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
            int num);

关于c - 出现错误:我明确拥有正确数字的参数太少,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5663472/

10-13 08:15