BMI270 HAL API

Module: Board Components / TIDA-010997

BMI270 6-Axis IMU Sensor driver. More…

Structures

Name

struct

Bmi270_Hal_InitParamsType
BMI270 configuration structure.

struct

Bmi270_Hal_AccelDataType
Accelerometer data structure.

struct

Bmi270_Hal_GyroDataType
Gyroscope data structure.

struct

Bmi270_Hal_ImuDataType
Combined IMU data structure.

Types

Name

enum

Bmi270_Hal_PowerModeType { BMI270_HAL_POWER_MODE_SUSPEND = 0U, BMI270_HAL_POWER_MODE_LOW_POWER, BMI270_HAL_POWER_MODE_NORMAL, BMI270_HAL_POWER_MODE_PERFORMANCE, BMI270_HAL_POWER_MODE_MAX}
Power modes for BMI270.

enum

Bmi270_Hal_SensorType { BMI270_HAL_SENSOR_NONE = 0U, BMI270_HAL_SENSOR_ACCEL_ONLY, BMI270_HAL_SENSOR_GYRO_ONLY, BMI270_HAL_SENSOR_BOTH}
Sensor enable configuration.

enum

Bmi270_Hal_AccelRangeType { BMI270_HAL_ACCEL_RANGE_2G = 0U, BMI270_HAL_ACCEL_RANGE_4G, BMI270_HAL_ACCEL_RANGE_8G, BMI270_HAL_ACCEL_RANGE_16G}
Accelerometer measurement range.

enum

Bmi270_Hal_GyroRangeType { BMI270_HAL_GYRO_RANGE_2000DPS = 0U, BMI270_HAL_GYRO_RANGE_1000DPS, BMI270_HAL_GYRO_RANGE_500DPS, BMI270_HAL_GYRO_RANGE_250DPS, BMI270_HAL_GYRO_RANGE_125DPS}
Gyroscope measurement range.

enum

Bmi270_Hal_OdrType { BMI270_HAL_ODR_25HZ = 0x06U, BMI270_HAL_ODR_50HZ = 0x07U, BMI270_HAL_ODR_100HZ = 0x08U, BMI270_HAL_ODR_200HZ = 0x09U, BMI270_HAL_ODR_400HZ = 0x0AU, BMI270_HAL_ODR_800HZ = 0x0BU, BMI270_HAL_ODR_1600HZ = 0x0CU}
Output data rate (ODR) configuration.

enum

Bmi270_Hal_BwpType { BMI270_HAL_BWP_OSR4 = 0x00U, BMI270_HAL_BWP_OSR2 = 0x01U, BMI270_HAL_BWP_NORMAL = 0x02U}
Bandwidth parameter (filter configuration)

enum

Bmi270_Hal_IntTypeType { BMI270_HAL_INT_DATA_RDY = 0U, BMI270_HAL_INT_FIFO_FULL, BMI270_HAL_INT_FIFO_WM, BMI270_HAL_INT_ANY_MOTION, BMI270_HAL_INT_NO_MOTION, BMI270_HAL_INT_TYPE_MAX}
Interrupt types for BMI270.

enum

Bmi270_Hal_IntPinType { BMI270_HAL_INT_PIN_1 = 0U, BMI270_HAL_INT_PIN_2 = 1U, BMI270_HAL_INT_PIN_MAX}
Interrupt pin selection.

enum

Bmi270_Hal_EnabledIntsType { BMI270_HAL_ENABLED_INTS_NONE = 0U, BMI270_HAL_ENABLED_INTS_INT1, BMI270_HAL_ENABLED_INTS_INT2}
Enabled interrupt pins.

Functions

Name

sint32

Bmi270_Hal_Init(const Bmi270_Hal_InitParamsType * configPtr)
Initialize the BMI270 sensor.

sint32

Bmi270_Hal_Reset(void )
Reset the BMI270 sensor.

sint32

Bmi270_Hal_AwaitDataReady(uint32 timeoutMs)
Wait for sensor data-ready.

sint32

Bmi270_Hal_GetAccelData(Bmi270_Hal_AccelDataType * dataPtr)
Read accelerometer data.

sint32

Bmi270_Hal_GetGyroData(Bmi270_Hal_GyroDataType * dataPtr)
Read gyroscope data.

sint32

Bmi270_Hal_GetImuData(Bmi270_Hal_ImuDataType * dataPtr)
Read combined IMU data.

sint32

Bmi270_Hal_SetPowerMode(Bmi270_Hal_PowerModeType mode)
Set power mode.

sint32

Bmi270_Hal_SetSensorEnable(Bmi270_Hal_SensorType sensorEnable)
Set sensor enable configuration.

sint32

Bmi270_Hal_GetChipId(uint8 * chipIdPtr)
Read chip ID.

sint32

Bmi270_Hal_ConfigureInterrupt(Bmi270_Hal_IntTypeType intType, Bmi270_Hal_IntPinType intPin, boolean enable)
Configure BMI270 interrupt pin routing.

void

Bmi270_Hal_SetEnabledInts(Bmi270_Hal_EnabledIntsType mode)
Set enabled interrupt pins.

sint32

Bmi270_Hal_FifoEnable(boolean enable, boolean accelEnable, boolean gyroEnable)
Enable or disable FIFO buffering.

sint32

Bmi270_Hal_FifoRead(uint8 * bufferPtr, uint16 length, uint16 * bytesReadPtr)
Read data from FIFO buffer.

sint32

Bmi270_Hal_FifoFlush(void )
Flush FIFO buffer.

sint32

Bmi270_Hal_WaitForTransferComplete(uint32 timeoutMs)
Wait for SPI transfer to complete (weak override point)

void

Bmi270_Hal_SignalTransferComplete(uint32 errorMask)
Signal SPI transfer completion (weak override point)

void

Bmi270_Hal_DelayMs(uint32 delayMs)
Millisecond delay (weak override point)

void

Bmi270_Hal_CsAssert(void )
Assert SPI chip select (weak override point)

void

Bmi270_Hal_CsDeassert(void )
Deassert SPI chip select (weak override point)

void

Bmi270_Hal_Int1Handler(void )
INT1 interrupt handler (weak override point)

void

Bmi270_Hal_Int2Handler(void )
INT2 interrupt handler (weak override point)

Defines

Name

BMI270_HAL_ERROR_NONE

BMI270_HAL_ERROR_SPI

BMI270_HAL_ERROR_INVALID_CHIP_ID

BMI270_HAL_ERROR_INIT_FAILED

BMI270_HAL_ERROR_TIMEOUT

BMI270_HAL_ERROR_INVALID_DATA

BMI270_HAL_ERROR_SENSOR_DISABLED

BMI270_HAL_ERROR_INVALID_PARAMS

Detailed Description

BMI270 6-Axis IMU Sensor driver.

This module provides drivers for the BMI270 sensor, connected via SPI.

Types Documentation

enum Bmi270_Hal_PowerModeType

Enumerator

Value

Description

BMI270_HAL_POWER_MODE_SUSPEND

0U

All sensors suspended, lowest power

BMI270_HAL_POWER_MODE_LOW_POWER

Low power mode

BMI270_HAL_POWER_MODE_NORMAL

Normal operation mode

BMI270_HAL_POWER_MODE_PERFORMANCE

High performance mode

BMI270_HAL_POWER_MODE_MAX

Power modes for BMI270.

enum Bmi270_Hal_SensorType

Enumerator

Value

Description

BMI270_HAL_SENSOR_NONE

0U

No sensors enabled

BMI270_HAL_SENSOR_ACCEL_ONLY

Accelerometer only

BMI270_HAL_SENSOR_GYRO_ONLY

Gyroscope only

BMI270_HAL_SENSOR_BOTH

Both sensors enabled

Sensor enable configuration.

enum Bmi270_Hal_AccelRangeType

Enumerator

Value

Description

BMI270_HAL_ACCEL_RANGE_2G

0U

±2g range

BMI270_HAL_ACCEL_RANGE_4G

±4g range

BMI270_HAL_ACCEL_RANGE_8G

±8g range

BMI270_HAL_ACCEL_RANGE_16G

±16g range

Accelerometer measurement range.

enum Bmi270_Hal_GyroRangeType

Enumerator

Value

Description

BMI270_HAL_GYRO_RANGE_2000DPS

0U

±2000°/s range

BMI270_HAL_GYRO_RANGE_1000DPS

±1000°/s range

BMI270_HAL_GYRO_RANGE_500DPS

±500°/s range

BMI270_HAL_GYRO_RANGE_250DPS

±250°/s range

BMI270_HAL_GYRO_RANGE_125DPS

±125°/s range

Gyroscope measurement range.

enum Bmi270_Hal_OdrType

Enumerator

Value

Description

BMI270_HAL_ODR_25HZ

0x06U

25 Hz output rate

BMI270_HAL_ODR_50HZ

0x07U

50 Hz output rate

BMI270_HAL_ODR_100HZ

0x08U

100 Hz output rate

BMI270_HAL_ODR_200HZ

0x09U

200 Hz output rate

BMI270_HAL_ODR_400HZ

0x0AU

400 Hz output rate

BMI270_HAL_ODR_800HZ

0x0BU

800 Hz output rate

BMI270_HAL_ODR_1600HZ

0x0CU

1600 Hz output rate

Output data rate (ODR) configuration.

enum Bmi270_Hal_BwpType

Enumerator

Value

Description

BMI270_HAL_BWP_OSR4

0x00U

OSR4 averaging mode

BMI270_HAL_BWP_OSR2

0x01U

OSR2 averaging mode

BMI270_HAL_BWP_NORMAL

0x02U

Normal filter mode

Bandwidth parameter (filter configuration)

enum Bmi270_Hal_IntTypeType

Enumerator

Value

Description

BMI270_HAL_INT_DATA_RDY

0U

Data ready interrupt

BMI270_HAL_INT_FIFO_FULL

FIFO full

BMI270_HAL_INT_FIFO_WM

FIFO watermark

BMI270_HAL_INT_ANY_MOTION

Any motion detected

BMI270_HAL_INT_NO_MOTION

No motion detected

BMI270_HAL_INT_TYPE_MAX

Interrupt types for BMI270.

enum Bmi270_Hal_IntPinType

Enumerator

Value

Description

BMI270_HAL_INT_PIN_1

0U

Interrupt pin 1

BMI270_HAL_INT_PIN_2

1U

Interrupt pin 2

BMI270_HAL_INT_PIN_MAX

Interrupt pin selection.

enum Bmi270_Hal_EnabledIntsType

Enumerator

Value

Description

BMI270_HAL_ENABLED_INTS_NONE

0U

No interrupt pins enabled (use polling)

BMI270_HAL_ENABLED_INTS_INT1

INT1 pin enabled

BMI270_HAL_ENABLED_INTS_INT2

INT2 pin enabled

Enabled interrupt pins.

Functions Documentation

function Bmi270_Hal_Init

sint32 Bmi270_Hal_Init(
    const Bmi270_Hal_InitParamsType * configPtr
)

Initialize the BMI270 sensor.

Parameters:

  • configPtr Pointer to configuration structure

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Performs complete initialization sequence including:

  • SPI mode switching

  • Soft reset

  • Chip ID verification

  • Firmware upload (8KB)

  • Sensor configuration

function Bmi270_Hal_Reset

sint32 Bmi270_Hal_Reset(
    void 
)

Reset the BMI270 sensor.

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Performs soft reset of the device. After reset, the device must be reinitialized using Bmi270_Hal_Init().

function Bmi270_Hal_AwaitDataReady

sint32 Bmi270_Hal_AwaitDataReady(
    uint32 timeoutMs
)

Wait for sensor data-ready.

Parameters:

  • timeoutMs Maximum time to wait in milliseconds

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

In polling mode, polls the STATUS register until the data-ready bits are set, or a timeout occurs. In interrupt mode, waits for interrupt signal from the configured pin. Call after init and before the first data read to ensure valid sensor data is available.

function Bmi270_Hal_GetAccelData

sint32 Bmi270_Hal_GetAccelData(
    Bmi270_Hal_AccelDataType * dataPtr
)

Read accelerometer data.

Parameters:

  • dataPtr Pointer to accelerometer data structure

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Reads 3-axis accelerometer data from the device. Sensor must be enabled (ACCEL_ONLY or BOTH) before reading.

function Bmi270_Hal_GetGyroData

sint32 Bmi270_Hal_GetGyroData(
    Bmi270_Hal_GyroDataType * dataPtr
)

Read gyroscope data.

Parameters:

  • dataPtr Pointer to gyroscope data structure

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Reads 3-axis gyroscope data from the device. Sensor must be enabled (GYRO_ONLY or BOTH) before reading.

function Bmi270_Hal_GetImuData

sint32 Bmi270_Hal_GetImuData(
    Bmi270_Hal_ImuDataType * dataPtr
)

Read combined IMU data.

Parameters:

  • dataPtr Pointer to IMU data structure

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Reads both accelerometer and gyroscope data in a single operation.

function Bmi270_Hal_SetPowerMode

sint32 Bmi270_Hal_SetPowerMode(
    Bmi270_Hal_PowerModeType mode
)

Set power mode.

Parameters:

  • mode Power mode to set

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Changes the device power mode. Must be called after initialization.

function Bmi270_Hal_SetSensorEnable

sint32 Bmi270_Hal_SetSensorEnable(
    Bmi270_Hal_SensorType sensorEnable
)

Set sensor enable configuration.

Parameters:

  • sensorEnable Sensor enable configuration

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Enables or disables accelerometer and/or gyroscope.

function Bmi270_Hal_GetChipId

sint32 Bmi270_Hal_GetChipId(
    uint8 * chipIdPtr
)

Read chip ID.

Parameters:

  • chipIdPtr Pointer to store chip ID

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Reads the device chip ID for verification.

function Bmi270_Hal_ConfigureInterrupt

sint32 Bmi270_Hal_ConfigureInterrupt(
    Bmi270_Hal_IntTypeType intType,
    Bmi270_Hal_IntPinType intPin,
    boolean enable
)

Configure BMI270 interrupt pin routing.

Parameters:

  • intType Type of interrupt to configure

  • intPin Which pin to route to (INT1 or INT2)

  • enable TRUE to enable interrupt, FALSE to disable

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Configures INT1 or INT2 pin to route specific interrupt types By default, all interrupts are disabled and polling mode is used.

function Bmi270_Hal_SetEnabledInts

void Bmi270_Hal_SetEnabledInts(
    Bmi270_Hal_EnabledIntsType mode
)

Set enabled interrupt pins.

Parameters:

  • mode Enabled interrupt pins selection

Note: Currently, only one interrupt pin can be active at a time. Use Bmi270_Hal_ConfigureInterrupt() to route specific interrupt types to the selected pin.

Configure which interrupt pin is active. When INT1 is selected, data ready is routed to INT1. When INT2 is selected, data ready is routed to INT2. When NONE is selected, polling mode is used.

function Bmi270_Hal_FifoEnable

sint32 Bmi270_Hal_FifoEnable(
    boolean enable,
    boolean accelEnable,
    boolean gyroEnable
)

Enable or disable FIFO buffering.

Parameters:

  • enable TRUE to enable FIFO, FALSE to disable

  • accelEnable TRUE to buffer accelerometer data

  • gyroEnable TRUE to buffer gyroscope data

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Configures FIFO buffer to collect sensor data for batch reading. When enabled, sensor data is automatically buffered for later retrieval.

function Bmi270_Hal_FifoRead

sint32 Bmi270_Hal_FifoRead(
    uint8 * bufferPtr,
    uint16 length,
    uint16 * bytesReadPtr
)

Read data from FIFO buffer.

Parameters:

  • bufferPtr Buffer to store FIFO data

  • length Maximum bytes to read, upto maximum of 30

  • bytesReadPtr Actual number of bytes read

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Reads buffered sensor data from the FIFO. The amount of data available depends on FIFO configuration and how many samples have been collected.

function Bmi270_Hal_FifoFlush

sint32 Bmi270_Hal_FifoFlush(
    void 
)

Flush FIFO buffer.

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Clears all data from the FIFO buffer.

function Bmi270_Hal_WaitForTransferComplete

sint32 Bmi270_Hal_WaitForTransferComplete(
    uint32 timeoutMs
)

Wait for SPI transfer to complete (weak override point)

Parameters:

  • timeoutMs Timeout in milliseconds

Return: BMI270_HAL_ERROR_NONE on success, non-zero error code on failure

Weak function that can be overridden for RTOS integration. Default implementation busy-waits with 1ms polling interval.

function Bmi270_Hal_SignalTransferComplete

void Bmi270_Hal_SignalTransferComplete(
    uint32 errorMask
)

Signal SPI transfer completion (weak override point)

Parameters:

  • errorMask Error bit mask (0 = no error)

Weak function that can be overridden for RTOS integration. Called from the SPI transfer complete or error callback.

function Bmi270_Hal_DelayMs

void Bmi270_Hal_DelayMs(
    uint32 delayMs
)

Millisecond delay (weak override point)

Parameters:

  • delayMs Delay duration in milliseconds

Weak function that can be overridden for RTOS integration. Default implementation uses TIDA010997_HAL_CFG_DELAY_MS().

function Bmi270_Hal_CsAssert

void Bmi270_Hal_CsAssert(
    void 
)

Assert SPI chip select (weak override point)

Called before each SPI transfer. Must be overridden in test code or board support to implement GPIO-based CS control. Default implementation is no-op.

function Bmi270_Hal_CsDeassert

void Bmi270_Hal_CsDeassert(
    void 
)

Deassert SPI chip select (weak override point)

Called after each SPI transfer. Must be overridden in test code or board support to implement GPIO-based CS control. Default implementation is no-op.

function Bmi270_Hal_Int1Handler

void Bmi270_Hal_Int1Handler(
    void 
)

INT1 interrupt handler (weak override point)

Called from GPIO interrupt when INT1 pin triggers. Sets the internal interrupt pending flag for INT1. Override to add application-specific handling.

function Bmi270_Hal_Int2Handler

void Bmi270_Hal_Int2Handler(
    void 
)

INT2 interrupt handler (weak override point)

Called from GPIO interrupt when INT2 pin triggers. Sets the internal interrupt pending flag for INT2. Override to add application-specific handling.

Macros Documentation

define BMI270_HAL_ERROR_NONE

#define BMI270_HAL_ERROR_NONE (0)

Operation successful

define BMI270_HAL_ERROR_SPI

#define BMI270_HAL_ERROR_SPI (1)

SPI communication error

define BMI270_HAL_ERROR_INVALID_CHIP_ID

#define BMI270_HAL_ERROR_INVALID_CHIP_ID (2)

Chip ID mismatch

define BMI270_HAL_ERROR_INIT_FAILED

#define BMI270_HAL_ERROR_INIT_FAILED (3)

Initialization failed

define BMI270_HAL_ERROR_TIMEOUT

#define BMI270_HAL_ERROR_TIMEOUT (4)

Operation timeout

define BMI270_HAL_ERROR_INVALID_DATA

#define BMI270_HAL_ERROR_INVALID_DATA (5)

Invalid data received

define BMI270_HAL_ERROR_SENSOR_DISABLED

#define BMI270_HAL_ERROR_SENSOR_DISABLED (6)

Sensor not enabled

define BMI270_HAL_ERROR_INVALID_PARAMS

#define BMI270_HAL_ERROR_INVALID_PARAMS (7)

Invalid parameters passed to function