hw/drivers/sensors/bmx160/src/bmm150_compensate.c
int16_t bmm150_compensate_x(const struct bmm150_trim_regs *trim, uint16_t data_rhall, int16_t mag_data_x)
{
    int16_t retval;
    uint16_t process_comp_x0 = 0;
    int32_t process_comp_x1;
    uint16_t process_comp_x2;
    int32_t process_comp_x3;
    int32_t process_comp_x4;
    int32_t process_comp_x5;
    int32_t process_comp_x6;
    int32_t process_comp_x7;
    int32_t process_comp_x8;
    int32_t process_comp_x9;
    int32_t process_comp_x10;

    if (mag_data_x == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL)
        return  BMM150_OVERFLOW_OUTPUT;

    if (data_rhall != 0)
        process_comp_x0 = data_rhall;
    else if (trim->dig_xyz1 != 0)
        process_comp_x0 = trim->dig_xyz1;
    else
        return  BMM150_OVERFLOW_OUTPUT;

    process_comp_x1 = ((int32_t)trim->dig_xyz1) * 16384;
    process_comp_x2 = ((uint16_t)(process_comp_x1 / process_comp_x0)) - ((uint16_t)0x4000);
    retval = ((int16_t)process_comp_x2);
    process_comp_x3 = (((int32_t)retval) * ((int32_t)retval));
    process_comp_x4 = (((int32_t)trim->dig_xy2) * (process_comp_x3 / 128));
    process_comp_x5 = (int32_t)(((int16_t)trim->dig_xy1) * 128);
    process_comp_x6 = ((int32_t)retval) * process_comp_x5;
    process_comp_x7 = (((process_comp_x4 + process_comp_x6) / 512) + ((int32_t)0x100000));
    process_comp_x8 = ((int32_t)(((int16_t)trim->dig_x2) + ((int16_t)0xA0)));
    process_comp_x9 = ((process_comp_x7 * process_comp_x8) / 4096);
    process_comp_x10 = ((int32_t)mag_data_x) * process_comp_x9;
    retval = ((int16_t)(process_comp_x10 / 8192));
    retval = (retval + (((int16_t)trim->dig_x1) * 8)) / 16;

    return retval;
}
/*!
 * @brief This internal API is used to obtain the compensated
 * magnetometer X axis data(micro-tesla) in int16_t.
 */
@brief This internal API is used to obtain the compensated
magnetometer X axis data(micro-tesla) in int16_t.
@brief This internal API is used to obtain the compensated magnetometer X axis data ( micro - tesla ) in int16_t .
int16_t bmm150_compensate_x(const struct bmm150_trim_regs *trim, uint16_t data_rhall, int16_t mag_data_x)
{
    int16_t retval;
    uint16_t process_comp_x0 = 0;
    int32_t process_comp_x1;
    uint16_t process_comp_x2;
    int32_t process_comp_x3;
    int32_t process_comp_x4;
    int32_t process_comp_x5;
    int32_t process_comp_x6;
    int32_t process_comp_x7;
    int32_t process_comp_x8;
    int32_t process_comp_x9;
    int32_t process_comp_x10;
    if (mag_data_x == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL)
        return  BMM150_OVERFLOW_OUTPUT;
    if (data_rhall != 0)
        process_comp_x0 = data_rhall;
    else if (trim->dig_xyz1 != 0)
        process_comp_x0 = trim->dig_xyz1;
    else
        return  BMM150_OVERFLOW_OUTPUT;
    process_comp_x1 = ((int32_t)trim->dig_xyz1) * 16384;
    process_comp_x2 = ((uint16_t)(process_comp_x1 / process_comp_x0)) - ((uint16_t)0x4000);
    retval = ((int16_t)process_comp_x2);
    process_comp_x3 = (((int32_t)retval) * ((int32_t)retval));
    process_comp_x4 = (((int32_t)trim->dig_xy2) * (process_comp_x3 / 128));
    process_comp_x5 = (int32_t)(((int16_t)trim->dig_xy1) * 128);
    process_comp_x6 = ((int32_t)retval) * process_comp_x5;
    process_comp_x7 = (((process_comp_x4 + process_comp_x6) / 512) + ((int32_t)0x100000));
    process_comp_x8 = ((int32_t)(((int16_t)trim->dig_x2) + ((int16_t)0xA0)));
    process_comp_x9 = ((process_comp_x7 * process_comp_x8) / 4096);
    process_comp_x10 = ((int32_t)mag_data_x) * process_comp_x9;
    retval = ((int16_t)(process_comp_x10 / 8192));
    retval = (retval + (((int16_t)trim->dig_x1) * 8)) / 16;
    return retval;
}
int16_t bmm150_compensate_x ( const struct bmm150_trim_regs * trim , uint16_t data_rhall , int16_t mag_data_x ) { int16_t retval ; uint16_t process_comp_x0 = 0 ; int32_t process_comp_x1 ; uint16_t process_comp_x2 ; int32_t process_comp_x3 ; int32_t process_comp_x4 ; int32_t process_comp_x5 ; int32_t process_comp_x6 ; int32_t process_comp_x7 ; int32_t process_comp_x8 ; int32_t process_comp_x9 ; int32_t process_comp_x10 ; if ( mag_data_x == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL ) return BMM150_OVERFLOW_OUTPUT ; if ( data_rhall != 0 ) process_comp_x0 = data_rhall ; else if ( trim -> dig_xyz1 != 0 ) process_comp_x0 = trim -> dig_xyz1 ; else return BMM150_OVERFLOW_OUTPUT ; process_comp_x1 = ( ( int32_t ) trim -> dig_xyz1 ) * 16384 ; process_comp_x2 = ( ( uint16_t ) ( process_comp_x1 / process_comp_x0 ) ) - ( ( uint16_t ) 0x4000 ) ; retval = ( ( int16_t ) process_comp_x2 ) ; process_comp_x3 = ( ( ( int32_t ) retval ) * ( ( int32_t ) retval ) ) ; process_comp_x4 = ( ( ( int32_t ) trim -> dig_xy2 ) * ( process_comp_x3 / 128 ) ) ; process_comp_x5 = ( int32_t ) ( ( ( int16_t ) trim -> dig_xy1 ) * 128 ) ; process_comp_x6 = ( ( int32_t ) retval ) * process_comp_x5 ; process_comp_x7 = ( ( ( process_comp_x4 + process_comp_x6 ) / 512 ) + ( ( int32_t ) 0x100000 ) ) ; process_comp_x8 = ( ( int32_t ) ( ( ( int16_t ) trim -> dig_x2 ) + ( ( int16_t ) 0xA0 ) ) ) ; process_comp_x9 = ( ( process_comp_x7 * process_comp_x8 ) / 4096 ) ; process_comp_x10 = ( ( int32_t ) mag_data_x ) * process_comp_x9 ; retval = ( ( int16_t ) ( process_comp_x10 / 8192 ) ) ; retval = ( retval + ( ( ( int16_t ) trim -> dig_x1 ) * 8 ) ) / 16 ; return retval ; }
@brief This internal API is used to obtain the compensated
 magnetometer X axis data(micro-tesla) in int16_t.
@brief This internal API is used to obtain the compensated magnetometer X axis data ( micro - tesla ) in int16_t .