I think there are loads of examples for calculating the angle from accelerometer (gravity) values. Perhaps something like this will explain? http://www.hobbytronics.co.uk/accelerometer-info
I haven't tried this code myself though.
To get the accelerometer values you can do something like this:
u8 int_data[6] = {0, 0, 0, 0, 0, 0};
s16 acc_x, acc_y, acc_z;
bmi160_get_regs(0x12, &int_data, 6, dev);
acc_x = ((int_data[1] << 8 | int_data[0]));
acc_y = ((int_data[3] << 8 | int_data[2]));
acc_z = ((int_data[5] << 8 | int_data[4]));
Read the 6 registers (0x12 - 0x17) and combine them into 16 bit signed integers to get the accelerometer values to use for your calculations.