Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    reason for changing bus communication function pointers

    rey-a
    New Poster

    reason for changing bus communication function pointers

    Hello,

    I'm working with a BMI270 and its GitHub library. I noticed a important change with the release v.2.46.1. (File bmi2_defs.h)

    The old typedef function pointer for the bus interfacing was:

     

    typedef int8_t (*bmi2_read_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);

     

    this instruction has been modified to:

     

    typedef BMI2_INTF_RETURN_TYPE (*bmi2_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);

     

     

    I don't fully understand the interest of such a change... Because now the device address must be passed through the pointer *intf_ptr ... I find it much less clear. There's probably a good reason for this change but I don't understand it.

    If someone can help me...

    Thanks

    3 REPLIES 3
    Minhwan
    Community Moderator

    Re: reason for changing bus communication function pointers

    Hello rey-a, 

    If you are using i2c, you should put dev id in interface as below. 


    i2c_bus = BMI2_I2C_PRIM_ADDR;
    bmi2.intf_ptr = &i2c_bus;
    bmi2.intf = BMI2_I2C_INTF;
    bmi2.read = bmi2xy_hal_i2c_bus_read;
    bmi2.write = bmi2xy_hal_i2c_bus_write;

    /*! This API is used to perform I2C read operation with sensor */
    int8_t bmi2xy_hal_i2c_bus_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    int8_t rslt = 0;
    //uint8_t dev_id = 0x68;
    uint8_t* dev_id = (uint8_t *)intf_ptr;

    rslt = BMI270_read_i2c(*dev_id, reg_addr, reg_data, length);

    return rslt;
    }

    /*! This API is used to perform I2C write operations with sensor */
    int8_t bmi2xy_hal_i2c_bus_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    int8_t rslt = 0;
    // uint8_t dev_id = 0x68;

    uint8_t* dev_id = (uint8_t *)intf_ptr;
    rslt = BMI270_write_i2c(*dev_id, reg_addr, (uint8_t *)reg_data, length);

    return rslt;
    }

     

    If you are using spi and doesn't use several slave, but only bmi270, you don't need to use it. ( It's for chip selection )

    But, anyway you need to put it as below. 


    #define BMI260_CS 10
    spi_bus = BMI260_CS;

    bmi2.intf_ptr = &spi_bus;
    bmi2.intf = BMI2_SPI_INTF;
    bmi2.read = BMI270_read_spi;
    bmi2.write = BMI270_write_spi;

     

    Thanks, 

     

    rey-a
    New Poster

    Re: reason for changing bus communication function pointers

    My question wasn't about the way to use it but on the reason of this changement. So if I understand it correctly, it has been changement to use the same variable (a void pointer) to use it as I2C or SPI parameter depending on the bus used.

    I found the parameter badly adapted to transmit the i2c address, but now it's make sense.

    Thanks for your response.

     


    Minhwan
    Community Moderator

    Re: reason for changing bus communication function pointers

    Hello rey-a, 

     

    Its intention could be flexibility. Using void paramater, it can get any type of value as parameter. 

    Yap, but it could be confusing for old user, and some people. 

    Thanks 🙂

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist