int nmi_i2c_read(unsigned char adr, unsigned char *b, unsigned long sz)
{
	int i;

	i2c_begin();
	i2c_write_byte((adr << 1)|0x1);

	for(i = 0; i < sz; i++) {
	    b[i] = i2c_read_byte();	    
		
	    if(i == sz-1) 
			i2c_write_ask(1);	
	    else  	           
			i2c_write_ask(0);
	}
 
	i2c_end();
	return 1;
}
Beispiel #2
0
i2c_ack i2c_read_2byte(int bus_id, char chip_addr, unsigned int sub_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret_rec = 0;
    ret_rec = SOC_I2C_Rec_2B_SubAddr(3, TC358746_I2C_ChipAdd, sub_addr, buf, size);
    //lidbg("\n************i2c_read_2byte  ret_rec=%d *****************\n",ret_rec);
    if(ret_rec > 0)
    {
        return ACK;
    }
    else
    {
        return NACK;
    }
#else
    u8 i;
    mutex_lock(&io_i2c_lock);
    i2c_init();
    // start transmite
    i2c_begin();//msg 0>>
    i2c_write_chip_addr(chip_addr, hkj_WRITE) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK------i2c_write_chip_addr----r--\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    //i2c_stop();
    // restart transmite


    // send message to mm_i2c device to transmite data
    i2c_write(sub_addr >> 8) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK-----subadder1-------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_write(sub_addr) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg(" chip_addr devices is not ACK------subadder0------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_stop();//msg 0<<

    // start transmite
    i2c_begin();//msg 1>>
    i2c_write_chip_addr(chip_addr, hkj_READ) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();

        i2c_free();
        lidbg(" chip_addr devices is not ACK----- i2c_write_chip_addr-------\r\n");
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    // transmite data
    for(i = 0; i < size; i++)
    {
        buf[i] = i2c_read();
        ( i == (size - 1) ) ? i2c_write_ask(NACK) : i2c_write_ask(ACK);
    }

    // stop transmite
    i2c_stop();//msg 1<<

    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}
Beispiel #3
0
i2c_ack i2c_read_byte(int bus_id, char chip_addr, unsigned int sub_addr, char *buf, unsigned int size)
{
#ifdef FLY_VIDEO_BOARD_V3
    int ret = 0;
    //ret=i2c_api_do_recv(3,chip_addr, sub_addr , buf, size);
    ret = SOC_I2C_Rec(3, chip_addr, sub_addr , buf, size);
    //lidbg("\n************ i2c_read_byte =%d*******\n",ret);
    //if(ret==size){
    if(ret > 0)
    {
#ifdef  DEBUG_ACK
        return NACK;
#else
        return ACK;
#endif

    }
    else
    {
        return NACK;
    }
#else
    u8 i;
    mutex_lock(&io_i2c_lock);
    i2c_init();
    // start transmite
    i2c_begin();
    i2c_write_chip_addr(chip_addr, hkj_WRITE) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write_chip_addr(%.2x, %d) ; is not ACK\n", chip_addr, hkj_WRITE);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }

    //i2c_stop();
    // restart transmite
    //i2c_begin();

    // send message to mm_i2c device to transmite data
    i2c_write(sub_addr) ;
    if (i2c_read_ack () == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write (%.2x) is not ACK\n", sub_addr & 0xff);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    i2c_stop();

    // start transmite
    i2c_begin();
    i2c_write_chip_addr(chip_addr, hkj_READ) ;
    if (i2c_read_ack() == NACK)
    {
        i2c_stop();
        i2c_free();
        lidbg("at read funtion :i2c_write_chip_addr(%.2x, %d) ; is not ACK\n", sub_addr, hkj_READ);
        mutex_unlock(&io_i2c_lock);
        return NACK;
    }
    // transmite data
    for(i = 0; i < size; i++)
    {
        buf[i] = i2c_read();
        ( i == (size - 1) ) ? i2c_write_ask(NACK) : i2c_write_ask(ACK);
    }

    // stop transmite
    i2c_stop();
    i2c_free();
    mutex_unlock(&io_i2c_lock);
    return ACK;
#endif
}