Esempio n. 1
0
 /*	\Brief: The function is used as I2C bus write
 *	\Return : Status of the I2C write
 *	\param dev_addr : The device address of the sensor
 *	\param reg_addr : Address of the first register, will data is going to be written
 *	\param reg_data : It is a value hold in the array,
 *		will be used for write the value into the register
 *	\param cnt : The no of byte of data to be write
 */
s8 BMG160_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
        mico_i2c_message_t bmg160_i2c_msg = {NULL, NULL, 0, 0, 0, false};
	s32 iError = BMG160_INIT_VALUE;
	u8 array[I2C_BUFFER_LEN];
	u8 stringpos = BMG160_INIT_VALUE;
	array[BMG160_INIT_VALUE] = reg_addr;
	for (stringpos = BMG160_INIT_VALUE; stringpos < cnt; stringpos++) {
		array[stringpos + BMG160_GEN_READ_WRITE_DATA_LENGTH] = *(reg_data + stringpos);
	}
	/*
	* Please take the below function as your reference for
	* write the data using I2C communication
	* "IERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)"
	* add your I2C write function here
	* iError is an return value of I2C read function
	* Please select your valid return value
	* In the driver SUCCESS defined as BMG160_INIT_VALUE
    * and FAILURE defined as -1
	* Note :
	* This is a full duplex operation,
	* The first read data is discarded, for that extra write operation
	* have to be initiated. For that cnt+1 operation done in the I2C write string function
	* For more information please refer data sheet SPI communication:
	*/
        iError = MicoI2cBuildTxMessage(&bmg160_i2c_msg, array, cnt + 1, 3);
        iError = MicoI2cTransfer(&bmg160_i2c_device, &bmg160_i2c_msg, 1);
        if(0 != iError){
          iError = -1;
        }
	return (s8)iError;
}
Esempio n. 2
0
void RGB_LED_write_frame_with_i2c(uint8_t *data, uint32_t cnt)
{
   mico_i2c_message_t _i2c_msg = {NULL, NULL, 0, 0, 0, false};
   
   MicoI2cBuildTxMessage(&_i2c_msg, data, cnt, 10);
   MicoI2cTransfer(&p9813_i2c_device, &_i2c_msg, 1);
}
Esempio n. 3
0
/*	\Brief: The function is used as I2C bus write
*	\Return : Status of the I2C write
*	\param dev_addr : The device address of the sensor
*	\param reg_addr : Address of the first register, will data is going to be written
*	\param reg_data : It is a value hold in the array,
*		will be used for write the value into the register
*	\param cnt : The no of byte of data to be write
*/
PRESSURE_StatusTypeDef LPS25HB_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToWrite)
{
  mico_i2c_message_t lps25hb_i2c_msg = {NULL, NULL, 0, 0, 0, false};
  int iError = 0;
  uint8_t array[8];
  uint8_t stringpos;
  array[0] = RegisterAddr;
  for (stringpos = 0; stringpos < NumByteToWrite; stringpos++) {
    array[stringpos + 1] = *(pBuffer + stringpos);
  }
  
  iError = MicoI2cBuildTxMessage(&lps25hb_i2c_msg, array, NumByteToWrite + 1, 3);
  iError = MicoI2cTransfer(&lps25hb_i2c_device, &lps25hb_i2c_msg, 1);
  if(0 != iError){
    iError = PRESSURE_ERROR;
  }
  
  return (PRESSURE_StatusTypeDef)iError;
}
Esempio n. 4
0
/*	\Brief: The function is used as I2C bus write
*	\Return : Status of the I2C write
*	\param dev_addr : The device address of the sensor
*	\param reg_addr : Address of the first register, will data is going to be written
*	\param reg_data : It is a value hold in the array,
*		will be used for write the value into the register
*	\param cnt : The no of byte of data to be write
*/
OSStatus UVIS25_IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
{
  mico_i2c_message_t uvis25_i2c_msg = {NULL, NULL, 0, 0, 0, false};
  OSStatus iError = kNoErr;
  uint8_t array[8];
  uint8_t stringpos;
  array[0] = RegisterAddr;
  for (stringpos = 0; stringpos < NumByteToWrite; stringpos++) {
    array[stringpos + 1] = *(pBuffer + stringpos);
  }
  
  iError = MicoI2cBuildTxMessage(&uvis25_i2c_msg, array, NumByteToWrite + 1, 3);
  iError = MicoI2cTransfer(&uvis25_i2c_device, &uvis25_i2c_msg, 1);
  if(kNoErr != iError){
    iError = kWriteErr;
  }
  
  return kNoErr;
}
OSStatus APDS9930_I2C_bus_write(uint8_t reg_addr, uint8_t *reg_data, uint8_t cnt)
{
  OSStatus err = kNoErr;
  mico_i2c_message_t apds_i2c_msg = {NULL, NULL, 0, 0, 0, false};

  uint8_t array[APDS_BUFFER_LEN];
  uint8_t stringpos;
  array[0] = reg_addr;
  for (stringpos = 0; stringpos < cnt; stringpos++) {
          array[stringpos + 1] = *(reg_data + stringpos);
  }

  err = MicoI2cBuildTxMessage(&apds_i2c_msg, array, cnt + 1, 3);
  require_noerr( err, exit );
  err = MicoI2cTransfer(&apds_i2c_device, &apds_i2c_msg, 1);
  require_noerr( err, exit );
  
exit:  
  return err;
}