title: Setup I2C reading and writing in c language
body: <p>First I'm noob in this stuff, but learning and really want to get this working. I bought a raspberrypi and a bno055 bosch accelerometer. It comes with a bno055.c, bno055.h and a bno055_support.c file. After getting into programming and c and  studying/trying out it seems somehow I need to define how to do I2C read and write.  It needs to be setup so you can define the amount of bytes read/written. Below you can find the two functions as predefined :</p>
  
  <pre><code>/*  \Brief: The API 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 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  {
      s32 BNO055_iERROR = BNO055_INIT_VALUE;
      u8 array[I2C_BUFFER_LEN];
      u8 stringpos = BNO055_INIT_VALUE;
  
      array[BNO055_INIT_VALUE] = reg_addr;
      for (stringpos = BNO055_INIT_VALUE; stringpos &lt; cnt; stringpos++)
          array[stringpos + BNO055_I2C_BUS_WRITE_ARRAY_INDEX] =
              *(reg_data + stringpos);
      }
      /*
      * Please take the below APIs as your reference for
      * write the data using I2C communication
      * "BNO055_iERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)"
      * add your I2C write APIs here
      * BNO055_iERROR is an return value of I2C read API
      * Please select your valid return value
      * In the driver BNO055_SUCCESS defined as 0
      * 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:
      */
      return (s8)BNO055_iERROR;
  }
  
   /* \Brief: The API is used as I2C bus read
   *  \Return : Status of the I2C read
   *  \param dev_addr : The device address of the sensor
   *  \param reg_addr : Address of the first register,
   *  will data is going to be read
   *  \param reg_data : This data read from the sensor,
   *   which is hold in an array
   *  \param cnt : The no of byte of data to be read
   */
  s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
  {
      s32 BNO055_iERROR = BNO055_INIT_VALUE;
      u8 array[I2C_BUFFER_LEN] = {BNO055_INIT_VALUE};
      u8 stringpos = BNO055_INIT_VALUE;
  
      array[BNO055_INIT_VALUE] = reg_addr;
  
      /* Please take the below API as your reference
       * for read the data using I2C communication
       * add your I2C read API here.
       * "BNO055_iERROR = I2C_WRITE_READ_STRING(DEV_ADDR,
       * ARRAY, ARRAY, 1, CNT)"
       * BNO055_iERROR is an return value of SPI write API
       * Please select your valid return value
       * In the driver BNO055_SUCCESS defined as 0
       * and FAILURE defined as -1
       */
      for (stringpos = BNO055_INIT_VALUE; stringpos &lt; cnt; stringpos++)
          *(reg_data + stringpos) = array[stringpos];
      return (s8)BNO055_iERROR;
  }
  </code></pre>
  
  <p>My question is there somebody out, that can coach me through this challenge?
  I'm learning about, <a href="https://www.kernel.org/doc/Documentation/i2c/dev-interface" rel="nofollow noreferrer">https://www.kernel.org/doc/Documentation/i2c/dev-interface</a>, but stuck here for the moment. Thx in advance for reading / replying. </p>