hw/drivers/sensors/bmx160/src/bmm150_compensate.c
int16_t bmm150_compensate_y(const struct bmm150_trim_regs *trim, uint16_t data_rhall, int16_t mag_data_y)
{
    int16_t retval;
    uint16_t process_comp_y0 = 0;
    int32_t process_comp_y1;
    uint16_t process_comp_y2;
    int32_t process_comp_y3;
    int32_t process_comp_y4;
    int32_t process_comp_y5;
    int32_t process_comp_y6;
    int32_t process_comp_y7;
    int32_t process_comp_y8;
    int32_t process_comp_y9;

    /* Overflow condition check */
    if (mag_data_y == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL)
        return  BMM150_OVERFLOW_OUTPUT;

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

    process_comp_y1 = (((int32_t)trim->dig_xyz1) * 16384) / process_comp_y0;
    process_comp_y2 = ((uint16_t)process_comp_y1) - ((uint16_t)0x4000);
    retval = ((int16_t)process_comp_y2);
    process_comp_y3 = ((int32_t) retval) * ((int32_t)retval);
    process_comp_y4 = ((int32_t)trim->dig_xy2) * (process_comp_y3 / 128);
    process_comp_y5 = ((int32_t)(((int16_t)trim->dig_xy1) * 128));
    process_comp_y6 = ((process_comp_y4 + (((int32_t)retval) * process_comp_y5)) / 512);
    process_comp_y7 = ((int32_t)(((int16_t)trim->dig_y2) + ((int16_t)0xA0)));
    process_comp_y8 = (((process_comp_y6 + ((int32_t)0x100000)) * process_comp_y7) / 4096);
    process_comp_y9 = (((int32_t)mag_data_y) * process_comp_y8);
    retval = (int16_t)(process_comp_y9 / 8192);
    retval = (retval + (((int16_t)trim->dig_y1) * 8)) / 16;

    return retval;
}
/*!
 * @brief This internal API is used to obtain the compensated
 * magnetometer Y axis data(micro-tesla) in int16_t.
 */
@brief This internal API is used to obtain the compensated
magnetometer Y axis data(micro-tesla) in int16_t.
@brief This internal API is used to obtain the compensated magnetometer Y axis data ( micro - tesla ) in int16_t .
int16_t bmm150_compensate_y(const struct bmm150_trim_regs *trim, uint16_t data_rhall, int16_t mag_data_y)
{
    int16_t retval;
    uint16_t process_comp_y0 = 0;
    int32_t process_comp_y1;
    uint16_t process_comp_y2;
    int32_t process_comp_y3;
    int32_t process_comp_y4;
    int32_t process_comp_y5;
    int32_t process_comp_y6;
    int32_t process_comp_y7;
    int32_t process_comp_y8;
    int32_t process_comp_y9;
    if (mag_data_y == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL)
        return  BMM150_OVERFLOW_OUTPUT;
    if (data_rhall != 0)
        process_comp_y0 = data_rhall;
    else if (trim->dig_xyz1 != 0)
        process_comp_y0 = trim->dig_xyz1;
    else
        return  BMM150_OVERFLOW_OUTPUT;
    process_comp_y1 = (((int32_t)trim->dig_xyz1) * 16384) / process_comp_y0;
    process_comp_y2 = ((uint16_t)process_comp_y1) - ((uint16_t)0x4000);
    retval = ((int16_t)process_comp_y2);
    process_comp_y3 = ((int32_t) retval) * ((int32_t)retval);
    process_comp_y4 = ((int32_t)trim->dig_xy2) * (process_comp_y3 / 128);
    process_comp_y5 = ((int32_t)(((int16_t)trim->dig_xy1) * 128));
    process_comp_y6 = ((process_comp_y4 + (((int32_t)retval) * process_comp_y5)) / 512);
    process_comp_y7 = ((int32_t)(((int16_t)trim->dig_y2) + ((int16_t)0xA0)));
    process_comp_y8 = (((process_comp_y6 + ((int32_t)0x100000)) * process_comp_y7) / 4096);
    process_comp_y9 = (((int32_t)mag_data_y) * process_comp_y8);
    retval = (int16_t)(process_comp_y9 / 8192);
    retval = (retval + (((int16_t)trim->dig_y1) * 8)) / 16;
    return retval;
}
int16_t bmm150_compensate_y ( const struct bmm150_trim_regs * trim , uint16_t data_rhall , int16_t mag_data_y ) { int16_t retval ; uint16_t process_comp_y0 = 0 ; int32_t process_comp_y1 ; uint16_t process_comp_y2 ; int32_t process_comp_y3 ; int32_t process_comp_y4 ; int32_t process_comp_y5 ; int32_t process_comp_y6 ; int32_t process_comp_y7 ; int32_t process_comp_y8 ; int32_t process_comp_y9 ; if ( mag_data_y == BMM150_XYAXES_FLIP_OVERFLOW_ADCVAL ) return BMM150_OVERFLOW_OUTPUT ; if ( data_rhall != 0 ) process_comp_y0 = data_rhall ; else if ( trim -> dig_xyz1 != 0 ) process_comp_y0 = trim -> dig_xyz1 ; else return BMM150_OVERFLOW_OUTPUT ; process_comp_y1 = ( ( ( int32_t ) trim -> dig_xyz1 ) * 16384 ) / process_comp_y0 ; process_comp_y2 = ( ( uint16_t ) process_comp_y1 ) - ( ( uint16_t ) 0x4000 ) ; retval = ( ( int16_t ) process_comp_y2 ) ; process_comp_y3 = ( ( int32_t ) retval ) * ( ( int32_t ) retval ) ; process_comp_y4 = ( ( int32_t ) trim -> dig_xy2 ) * ( process_comp_y3 / 128 ) ; process_comp_y5 = ( ( int32_t ) ( ( ( int16_t ) trim -> dig_xy1 ) * 128 ) ) ; process_comp_y6 = ( ( process_comp_y4 + ( ( ( int32_t ) retval ) * process_comp_y5 ) ) / 512 ) ; process_comp_y7 = ( ( int32_t ) ( ( ( int16_t ) trim -> dig_y2 ) + ( ( int16_t ) 0xA0 ) ) ) ; process_comp_y8 = ( ( ( process_comp_y6 + ( ( int32_t ) 0x100000 ) ) * process_comp_y7 ) / 4096 ) ; process_comp_y9 = ( ( ( int32_t ) mag_data_y ) * process_comp_y8 ) ; retval = ( int16_t ) ( process_comp_y9 / 8192 ) ; retval = ( retval + ( ( ( int16_t ) trim -> dig_y1 ) * 8 ) ) / 16 ; return retval ; }
@brief This internal API is used to obtain the compensated
 magnetometer Y axis data(micro-tesla) in int16_t.
@brief This internal API is used to obtain the compensated magnetometer Y axis data ( micro - tesla ) in int16_t .
/* Overflow condition check */