Bosch Sensortec Community

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

    BMI160 Driver "bmi160_com_fptr_t" not declared

    showns
    New Poster

    BMI160 Driver "bmi160_com_fptr_t" not declared

    I would like to know where in the driver library of BMI160 (version 3.9.1/version 3.9.2) the "bmi160_com_fptr_t" is declared.
    I have errors initializing the BMI160 due to the lines with "bmi160_com_fptr", and I could not find the declaration of "bmi160_com_fptr_t" in any of the files contained in the driver library; bmi160.c/bmi160.h/bmi160_defs.
    h from https://github.com/BoschSensortec/BMI160_driver.
    I have tried initializing with version 3.9.1 and version 3.9.2. I am using the built-in BMI160 sensor on Cypress (Infenion) PSoC 6 BLE Pioneer kit.
    Thank you.

     

     

    /* ========================================
     *
     * Copyright YOUR COMPANY, THE YEAR
     * All Rights Reserved
     * UNPUBLISHED, LICENSED SOFTWARE.
     *
     * CONFIDENTIAL AND PROPRIETARY INFORMATION
     * WHICH IS THE PROPERTY OF your company.
     *
     * ========================================
    */
    #include "project.h"
    // Added
    #include "FreeRTOS.h"
    #include "task.h"
    #include <stdio.h>
    #include "bmi160.h"
    
    #include "bmi160_defs.h"
    
    static struct bmi160_dev bmi160Dev; // Added
    
    static int8_t BMI160BurstWrite(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
    {
        Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
        Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, & I2C_1_context);
        for(int i = 0; i < len; i++) 
        {
            Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, data[i], 0, &I2C_1_context);
        }
        Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);
        
        return 0;  
    }    
    
    // This function supports the BMP?180 library and read I2C Registers
    static int8_t BMI160BurstRead(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len) 
    {
        Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
        Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, & I2C_1_context);
        Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
        for(int i = 0; i < len -1; i++)
        {
            Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_ACK, &data[i], 0, &I2C_1_context);
        }
        Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_NAK, &data[len-1], 0, &I2C_1_context);
        
        Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);
        
        return 0;    
    }
    
    static void bmi160Init(void)
    {
        vTaskDelay(100); // Guess
        
        /* BMI160 */
        bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
        bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
        bmi160Dev.delay_ms = (bmi160_delay_fptr_t)vTaskDelay;
        bmi160Dev.id = BMI160_I2C_ADDR; // I2C device address
       
        
        bmi160_init(&bmi160Dev); // Initialize the device
        
        bmi160Dev.gyro_cfg.odr = BMI160_GYRO_ODR_800HZ;
        bmi160Dev.gyro_cfg.range = BMI160_GYRO_RANGE_125_DPS;
        bmi160Dev.gyro_cfg.bw = BMI160_GYRO_BW_OSR4_MODE;
        
        /* Select the power mode of Gyroscope sensor */
        bmi160Dev.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
        
        bmi160Dev.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
        bmi160Dev.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
        bmi160Dev.accel_cfg.bw = BMI160_ACCEL_BW_OSR4_AVG1;
        bmi160Dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
        
        /* Set the sensor configuration */
        bmi160_set_sens_conf(&bmi160Dev);
        bmi160Dev.delay_ms(50);     
    }
    
    // 32768 = 2g
    #define MAXACCEL (32768/2)
    
    void motionTask(void *arg)
    {
        (void)arg;
        I2C_1_Start();
        bmi160Init();
        struct bmi160_sensor_data acc;
        
        float gx, gy, gz;
        
        while(1) 
        {
            bmi160_get_sensor_data(BMI160_ACCEL_ONLY, &acc, NULL, &bmi160Dev);
            
            gx = (float)acc.x/MAXACCEL;
            gy = (float)acc.y/MAXACCEL;
            gz = (float)acc.z/MAXACCEL;
            
            printf ("x=%1.2f y=%1.2f z=%1.2f\r\n", gx, gy, gz);
            
            vTaskDelay(200);
        }        
        
        
    }    
    
    int main(void)
    {
        __enable_irq(); /* Enable global interrupts. */
        
        UART_1_Start();
        
        xTaskCreate(motionTask, "Motion Task", 400, 0, 1, 0);
        vTaskStartScheduler();
        /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    
        for(;;)
        {
            /* Place your application code here. */
        }
    }
    
    /* [] END OF FILE */

     

     

    Tags (1)
    1 REPLY 1
    BSTRobin
    Community Moderator

    Re: BMI160 Driver "bmi160_com_fptr_t" not declared

    Hi showns,

    You could see the declaration of the write() read() function from this structure.
    struct bmi160_dev
    {
    ...
    /*! Read function pointer */
    bmi160_read_fptr_t read;

    /*! Write function pointer */
    bmi160_write_fptr_t write;
    ...
    }

    So for your code,
    bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
    bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
    should be:
    bmi160Dev.read = (bmi160_read_fptr_t)BMI160BurstRead;
    bmi160Dev.write = (bmi160_write_fptr_t)BMI160BurstWrite;

    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