Basic set of APIs for interacting with the BMI160 motion sensor.
This provides basic initialization and access to to the basic accelerometer & gyroscope data. It also provides access to the base BMI160 driver for full control. For more information about the motion sensor, see: https://github.com/BoschSensortec/BMI160_driver
The following snippet initializes an I2C instance and the BMI160, then reads from the BMI160.
The following snippet demonstrates how to configure a BMI160 interrupt.
Data Structures | |
struct | mtb_bmi160_t |
Structure holding the IMU instance specific information. More... | |
struct | mtb_bmi160_data_t |
Structure holding the accelerometer and gyroscope data read from the device. More... | |
Enumerations | |
enum | mtb_bmi160_address_t { MTB_BMI160_DEFAULT_ADDRESS = BMI160_I2C_ADDR , MTB_BMI160_SECONDARY_ADDRESS = BMI160_AUX_BMM150_I2C_ADDR } |
Enumeration used for selecting I2C address. | |
Functions | |
cy_rslt_t | mtb_bmi160_init_i2c (mtb_bmi160_t *obj, cyhal_i2c_t *inst, mtb_bmi160_address_t address) |
Initialize the IMU for I2C communication. More... | |
cy_rslt_t | mtb_bmi160_init_spi (mtb_bmi160_t *obj, cyhal_spi_t *inst, cyhal_gpio_t spi_ss) |
Initialize the sensor for SPI communication. More... | |
cy_rslt_t | mtb_bmi160_config_default (mtb_bmi160_t *obj) |
Configure the motion sensor to a default mode with both accelerometer & gyroscope enabled with a nominal output data rate. More... | |
cy_rslt_t | mtb_bmi160_read (mtb_bmi160_t *obj, mtb_bmi160_data_t *sensor_data) |
Reads the current accelerometer & gyroscope data from the motion sensor. More... | |
struct bmi160_dev * | mtb_bmi160_get (mtb_bmi160_t *obj) |
Gets access to the base motion sensor data. More... | |
cy_rslt_t | mtb_bmi160_selftest (mtb_bmi160_t *obj) |
Performs both accelerometer and gyro self tests. More... | |
cy_rslt_t | mtb_bmi160_config_int (mtb_bmi160_t *obj, struct bmi160_int_settg *intsettings, cyhal_gpio_t pin, uint8_t intr_priority, cyhal_gpio_event_t event, cyhal_gpio_event_callback_t callback, void *callback_arg) |
Configure a GPIO pin as an interrupt for the BMI160. More... | |
void | mtb_bmi160_free (mtb_bmi160_t *obj) |
Frees up any resources allocated by the motion_sensor as part of mtb_bmi160_init_i2c(). More... | |
struct mtb_bmi160_t |
struct mtb_bmi160_data_t |
cy_rslt_t mtb_bmi160_init_i2c | ( | mtb_bmi160_t * | obj, |
cyhal_i2c_t * | inst, | ||
mtb_bmi160_address_t | address | ||
) |
Initialize the IMU for I2C communication.
Then applies the default configuration settings for both the accelerometer & gyroscope. Known maximum I2C frequency of 1MHz; refer to manufacturer's datasheet for confirmation. See: mtb_bmi160_config_default()
[in] | obj | Pointer to a BMI160 object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | inst | I2C instance to use for communicating with the BMI160 sensor. |
[in] | address | BMI160 I2C address, set by hardware implementation. |
cy_rslt_t mtb_bmi160_init_spi | ( | mtb_bmi160_t * | obj, |
cyhal_spi_t * | inst, | ||
cyhal_gpio_t | spi_ss | ||
) |
Initialize the sensor for SPI communication.
Then applies the default configuration settings for the accelerometer & gyroscope. NOTE: The SPI slave select pin (spi_ss
) is expected to be controlled by this driver, not the SPI block itself. This allows the driver to issue multiple read/write requests back to back. See: mtb_bmi160_config_default()
[in] | obj | Pointer to a BMI160 object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in] | inst | SPI instance to use for communicating with the BMI160 sensor. |
[in] | spi_ss | SPI slave select pin to use for communicating with the BMI160 sensor. |
cy_rslt_t mtb_bmi160_config_default | ( | mtb_bmi160_t * | obj | ) |
Configure the motion sensor to a default mode with both accelerometer & gyroscope enabled with a nominal output data rate.
The default values used are from the example in the BMI160 driver repository, see https://github.com/BoschSensortec/BMI160_driver
[in] | obj | Pointer to a BMI160 object. |
cy_rslt_t mtb_bmi160_read | ( | mtb_bmi160_t * | obj, |
mtb_bmi160_data_t * | sensor_data | ||
) |
Reads the current accelerometer & gyroscope data from the motion sensor.
[in] | obj | Pointer to a BMI160 object. |
[out] | sensor_data | The accelerometer & gyroscope data read from the motion sensor |
struct bmi160_dev * mtb_bmi160_get | ( | mtb_bmi160_t * | obj | ) |
Gets access to the base motion sensor data.
This allows for direct manipulation of the sensor for any desired behavior. See https://github.com/BoschSensortec/BMI160_driver for more details on the sensor.
[in] | obj | Pointer to a BMI160 object. |
cy_rslt_t mtb_bmi160_selftest | ( | mtb_bmi160_t * | obj | ) |
Performs both accelerometer and gyro self tests.
Note these tests cause a soft reset of the device and device should be reconfigured after a test. See https://github.com/BoschSensortec/BMI160_driver for more details.
[in] | obj | Pointer to a BMI160 object. |
cy_rslt_t mtb_bmi160_config_int | ( | mtb_bmi160_t * | obj, |
struct bmi160_int_settg * | intsettings, | ||
cyhal_gpio_t | pin, | ||
uint8_t | intr_priority, | ||
cyhal_gpio_event_t | event, | ||
cyhal_gpio_event_callback_t | callback, | ||
void * | callback_arg | ||
) |
Configure a GPIO pin as an interrupt for the BMI160.
This configures the pin as an interrupt, and calls the BMI160 interrupt configuration API with the application supplied settings structure. See https://github.com/BoschSensortec/BMI160_driver for more details.
[in] | obj | Pointer to a BMI160 object. |
[in] | intsettings | Pointer to a BMI160 interrupt settings structure. |
[in] | pin | Which pin to configure as interrupt |
[in] | intr_priority | The priority for NVIC interrupt events |
[in] | event | The type of interrupt event |
[in] | callback | The function to call when the specified event happens. Pass NULL to unregister the handler. |
[in] | callback_arg | Generic argument that will be provided to the callback when called, can be NULL |
void mtb_bmi160_free | ( | mtb_bmi160_t * | obj | ) |
Frees up any resources allocated by the motion_sensor as part of mtb_bmi160_init_i2c().
[in] | obj | Pointer to a BMI160 object. |