/* Set digital low pass filter. The following LPF settings are supported: 188, 98, 42, 20, 10, 5.  */
int mpu_set_lpf(unsigned short lpf)
/* Set digital low pass filter. The following LPF settings are supported: 188, 98, 42, 20, 10, 5.  */
int mpu_set_lpf(unsigned short lpf)
{
    unsigned char data;
    if (!(st.chip_cfg.sensors))
        return -1;
    if (lpf >= 188)
        data = INV_FILTER_188HZ;
    else if (lpf >= 98)
        data = INV_FILTER_98HZ;
    else if (lpf >= 42)
        data = INV_FILTER_42HZ;
    else if (lpf >= 20)
        data = INV_FILTER_20HZ;
    else if (lpf >= 10)
        data = INV_FILTER_10HZ;
    else
        data = INV_FILTER_5HZ;
    if (st.chip_cfg.lpf == data)
        return 0;
    if (i2c_write(st.hw->addr, st.reg->lpf, 1, &data))
        return -1;
    st.chip_cfg.lpf = data;
    return 0;
}