extern hal_result_t hal_chip_xx_eeprom_read(uint32_t address, uint32_t size, uint8_t* buffer, uint32_t* readbytes)
{   // read and block until done
    hal_result_t res = hal_res_NOK_generic;
    
    hal_chip_xx_eeprom_internal_item_t *intitem = s_hal_chip_xx_eeprom_theinternals.items[0];
    
    if(hal_false == s_hal_chip_xx_eeprom_initted_is())
    {
        return(hal_res_NOK_generic);
    }
    
    // verify bounds and ... clip size to maximum possible if address+size is out of bound
    if(hal_res_NOK_generic == s_hal_chip_xx_eeprom_verify_rw_bounds(address, &size, buffer))
    {
        return(hal_res_NOK_generic);
    }
    
 

    hal_i2c_regaddr_t regaddr;
    regaddr.numofbytes = 2;     // all the managed eeproms use two byte addressing for internal register
    regaddr.bytes.two = (uint16_t) address;
    res = hal_i2c_read(intitem->config.chipcfg.i2cid, intitem->hwaddress, regaddr, buffer, (uint16_t) size);
 
 
    if(NULL != readbytes)
    {
        *readbytes = (hal_res_OK == res) ? (size) : (0);
    }
    
    return(res);
}
Exemple #2
0
result_t i2c_read(i2c_device_t* dev, void* buffer, uint16_t length)
{
    uint16_t busId = dev->busId;
    uint16_t ret;

    if((ret = hal_i2c_set_slave_addr(busId, dev->devAddress)) != RV_OK)
        return ret;

    if((ret = hal_i2c_setup_interface(busId, dev->baudrate)) != RV_OK)
        return ret;

    if((ret = hal_i2c_read(busId, buffer, length)) != RV_OK);
        return ret;

    if((ret = hal_i2c_finalize(busId)) != RV_OK)
        return ret;

    return RV_OK;
}
Exemple #3
0
/*common read */
int i2c_common_read(struct i2c_dev_info_s *dev, void *data, int offset, int size)
{
	int fd = 0, ret;
	char *buf = (char*)data;
	halI2CLock();
	fd = hal_i2c_init(i2c_dev->i2c_controler);
	if(fd < 0)
	{
		ret = ERROR;
		goto out;
	}
	i2c_channel_switch(dev, fd);

	ret = hal_i2c_read(fd, i2c_dev->dev_addr[0], offset, buf, size);
	if(ret < 0)
		goto out;

out:
	if(fd > 0)
		hal_i2c_close(fd);
	halI2CUnLock();
	return ret;
}