SparkFun BMI330 Arduino Library  v1.0.0-2-gdbddb99
Arduino Library for the SparkFun Qwiic BMI330 6-DoF IMU (Bosch BMI330)
Loading...
Searching...
No Matches
sfDevBMI330 Class Reference

Platform-independent driver for the Bosch BMI330 6-DoF IMU. More...

#include <sfDevBMI330.h>

Inheritance diagram for sfDevBMI330:
SfeBMI330ArdI2C SfeBMI330ArdSPI

Public Member Functions

 sfDevBMI330 ()
 Default constructor. More...
 
virtual ~sfDevBMI330 ()
 
sfTkError_t begin (sfTkIBus *theBus=nullptr)
 Adopt a bus, verify the device, and bring the feature engine up. More...
 
void setCommunicationBus (sfTkIBus *theBus)
 Set the communication bus without initializing the device. More...
 
bool isConnected (void)
 Check that a BMI330 is responding. More...
 
sfTkError_t getChipID (uint8_t &chipId, uint8_t &revId)
 Read the chip and revision IDs from CHIP_ID (0x00). More...
 
sfTkError_t softReset (void)
 Soft reset the device and restart the feature engine. More...
 
sfTkError_t enableFeatureEngine (void)
 Start the feature engine without a full reset. More...
 
bool getFeatureEngineStatus (void)
 Check whether the feature engine is running. More...
 
sfTkError_t getFeatureEngineError (uint16_t &status)
 Read the raw FEATURE_IO1 (0x11) word. More...
 
sfTkError_t setAccelConfig (sfe_bmi330_accel_mode_t mode, sfe_bmi330_odr_t odr, sfe_bmi330_accel_range_t range, sfe_bmi330_bandwidth_t bandwidth=BMI330_BW_ODR_HALF, sfe_bmi330_averaging_t averaging=BMI330_AVG_1)
 Write the whole accelerometer configuration in one register write. More...
 
sfTkError_t getAccelConfig (sfe_bmi330_accel_mode_t &mode, sfe_bmi330_odr_t &odr, sfe_bmi330_accel_range_t &range, sfe_bmi330_bandwidth_t &bandwidth, sfe_bmi330_averaging_t &averaging)
 Read the accelerometer configuration back from ACC_CONF (0x20). More...
 
sfTkError_t enableAccel (bool enable=true)
 Turn the accelerometer on in high-performance mode, or off. More...
 
sfTkError_t setAccelMode (sfe_bmi330_accel_mode_t mode)
 Set the accelerometer power mode, leaving the rest of ACC_CONF alone. More...
 
sfTkError_t setAccelODR (sfe_bmi330_odr_t odr)
 Set the accelerometer output data rate. More...
 
sfTkError_t setAccelRange (sfe_bmi330_accel_range_t range)
 Set the accelerometer full-scale range. More...
 
sfTkError_t setAccelBandwidth (sfe_bmi330_bandwidth_t bandwidth)
 Set the accelerometer filter bandwidth. More...
 
sfTkError_t setAccelAveraging (sfe_bmi330_averaging_t averaging)
 Set the accelerometer hardware averaging. More...
 
sfe_bmi330_accel_range_t getAccelRange (void)
 Get the cached accelerometer full-scale range. More...
 
sfTkError_t setGyroConfig (sfe_bmi330_gyro_mode_t mode, sfe_bmi330_odr_t odr, sfe_bmi330_gyro_range_t range, sfe_bmi330_bandwidth_t bandwidth=BMI330_BW_ODR_HALF, sfe_bmi330_averaging_t averaging=BMI330_AVG_1)
 Write the whole gyroscope configuration in one register write. More...
 
sfTkError_t getGyroConfig (sfe_bmi330_gyro_mode_t &mode, sfe_bmi330_odr_t &odr, sfe_bmi330_gyro_range_t &range, sfe_bmi330_bandwidth_t &bandwidth, sfe_bmi330_averaging_t &averaging)
 Read the gyroscope configuration back from GYR_CONF (0x21). More...
 
sfTkError_t enableGyro (bool enable=true)
 Turn the gyroscope on in high-performance mode, or off. More...
 
sfTkError_t setGyroMode (sfe_bmi330_gyro_mode_t mode)
 Set the gyroscope power mode, leaving the rest of GYR_CONF alone. More...
 
sfTkError_t setGyroODR (sfe_bmi330_odr_t odr)
 Set the gyroscope output data rate. More...
 
sfTkError_t setGyroRange (sfe_bmi330_gyro_range_t range)
 Set the gyroscope full-scale range. More...
 
sfTkError_t setGyroBandwidth (sfe_bmi330_bandwidth_t bandwidth)
 Set the gyroscope filter bandwidth. More...
 
sfTkError_t setGyroAveraging (sfe_bmi330_averaging_t averaging)
 Set the gyroscope hardware averaging. More...
 
sfe_bmi330_gyro_range_t getGyroRange (void)
 Get the cached gyroscope full-scale range. More...
 
sfTkError_t getSensorData (sfe_bmi330_sensor_data_t &data)
 Read accelerometer, gyroscope, temperature and timestamp in one transaction. More...
 
sfTkError_t getAccelData (sfe_bmi330_data_t &data)
 Read just the accelerometer, converted to g. More...
 
sfTkError_t getAccelDataRaw (sfe_bmi330_raw_data_t &data)
 Read just the accelerometer, in raw counts. More...
 
sfTkError_t getGyroData (sfe_bmi330_data_t &data)
 Read just the gyroscope, converted to degrees per second. More...
 
sfTkError_t getGyroDataRaw (sfe_bmi330_raw_data_t &data)
 Read just the gyroscope, in raw counts. More...
 
sfTkError_t getTemperature (float &celsius)
 Read the die temperature in degrees Celsius. More...
 
sfTkError_t getSensorTime (uint32_t &sensorTime)
 Read the 32-bit sensor timestamp, in ticks of 39.0625 us. More...
 
sfTkError_t getDataReady (bool &accelReady, bool &gyroReady, bool &tempReady)
 Read the STATUS register (0x02) data-ready flags. More...
 
sfTkError_t getErrorStatus (sfe_bmi330_error_status_t &status)
 Read and decode ERR_REG (0x01). More...
 
sfTkError_t getSaturationFlags (sfe_bmi330_saturation_t &flags)
 Read and decode the per-axis saturation flags in SAT_FLAGS (0x0C). More...
 
float accelRawToG (int16_t raw)
 Convert a raw accelerometer count to g using the cached range. More...
 
float gyroRawToDps (int16_t raw)
 Convert a raw gyroscope count to degrees per second using the cached range. More...
 
sfTkError_t setInterruptPinConfig (sfe_bmi330_int_pin_t pin, const sfe_bmi330_int_pin_config_t &config)
 Configure the electrical behavior of one interrupt pin. More...
 
sfTkError_t setInterruptLatch (bool latched)
 Choose between latched and pulsed interrupts. More...
 
sfTkError_t mapInterrupt (sfe_bmi330_int_source_t source, sfe_bmi330_int_pin_t pin)
 Route one interrupt source to a pin, or disconnect it. More...
 
sfTkError_t getInterruptStatus (sfe_bmi330_int_pin_t pin, uint16_t &status)
 Read and clear a pin's interrupt status word. More...
 
sfTkError_t setFifoConfig (uint16_t sources, bool stopOnFull=false)
 Choose what the FIFO records, and what it does when full. More...
 
sfTkError_t getFifoConfig (uint16_t &sources, bool &stopOnFull)
 Read back the configured FIFO sources and full behavior. More...
 
sfTkError_t setFifoWatermark (uint16_t words)
 Set the FIFO watermark, in 16-bit words. More...
 
sfTkError_t getFifoWatermark (uint16_t &words)
 Read the FIFO watermark, in words. More...
 
sfTkError_t getFifoFillLevel (uint16_t &words)
 Read how many words the FIFO currently holds. More...
 
sfTkError_t flushFifo (void)
 Discard everything in the FIFO. More...
 
sfTkError_t readFifoRaw (uint16_t *words, uint16_t count)
 Read raw words out of FIFO_DATA (0x16) without interpreting them. More...
 
sfTkError_t readFifoData (sfe_bmi330_fifo_frame_t *frames, uint8_t maxFrames, uint8_t &numFrames, uint16_t sources)
 Read and decode complete frames from the FIFO. More...
 
sfTkError_t enableFeature (uint16_t features, bool enable=true)
 Enable or disable feature-engine features. More...
 
sfTkError_t getEnabledFeatures (uint16_t &features)
 Read which features are currently enabled. More...
 
sfTkError_t readFeatureWords (uint8_t baseAddr, uint16_t *words, uint8_t count)
 Read consecutive words from feature engine extended memory. More...
 
sfTkError_t writeFeatureWords (uint8_t baseAddr, const uint16_t *words, uint8_t count)
 Write consecutive words to feature engine extended memory. More...
 
sfTkError_t setAnyMotionConfig (const sfe_bmi330_motion_config_t &config)
 Write the any-motion detector configuration. More...
 
sfTkError_t getAnyMotionConfig (sfe_bmi330_motion_config_t &config)
 Read the any-motion detector configuration. More...
 
sfTkError_t setNoMotionConfig (const sfe_bmi330_motion_config_t &config)
 Write the no-motion detector configuration. More...
 
sfTkError_t getNoMotionConfig (sfe_bmi330_motion_config_t &config)
 Read the no-motion detector configuration. More...
 
sfTkError_t setSigMotionConfig (const sfe_bmi330_sig_motion_config_t &config)
 Write the significant motion detector configuration. More...
 
sfTkError_t getSigMotionConfig (sfe_bmi330_sig_motion_config_t &config)
 Read the significant motion detector configuration. More...
 
sfTkError_t setTiltConfig (const sfe_bmi330_tilt_config_t &config)
 Write the tilt detector configuration. More...
 
sfTkError_t getTiltConfig (sfe_bmi330_tilt_config_t &config)
 Read the tilt detector configuration. More...
 
sfTkError_t setOrientationConfig (const sfe_bmi330_orientation_config_t &config)
 Write the orientation detector configuration. More...
 
sfTkError_t getOrientationConfig (sfe_bmi330_orientation_config_t &config)
 Read the orientation detector configuration. More...
 
sfTkError_t getOrientation (sfe_bmi330_orientation_t &orientation, bool &faceDown)
 Read the current orientation classification. More...
 
sfTkError_t setFlatConfig (const sfe_bmi330_flat_config_t &config)
 Write the flat detector configuration. More...
 
sfTkError_t getFlatConfig (sfe_bmi330_flat_config_t &config)
 Read the flat detector configuration. More...
 
sfTkError_t setTapConfig (const sfe_bmi330_tap_config_t &config)
 Write the tap detector configuration. More...
 
sfTkError_t getTapConfig (sfe_bmi330_tap_config_t &config)
 Read the tap detector configuration. More...
 
sfTkError_t getTapEvent (sfe_bmi330_tap_event_t &event)
 Read which tap gesture was last detected. More...
 
sfTkError_t getStepCount (uint32_t &steps)
 Read the step count. More...
 
sfTkError_t resetStepCount (void)
 Reset the step count to zero. More...
 
sfTkError_t setStepCounterWatermark (uint16_t watermark)
 Set how many steps trigger the step counter interrupt. More...
 
sfTkError_t getStepCounterWatermark (uint16_t &watermark)
 Read the step counter watermark. More...
 
sfTkError_t setAxisRemap (const sfe_bmi330_axis_remap_t &remap)
 Apply an axis remapping inside the device. More...
 
sfTkError_t getAxisRemap (sfe_bmi330_axis_remap_t &remap)
 Read the current axis remapping. More...
 
sfTkError_t performSelfTest (sfe_bmi330_self_test_t selection, sfe_bmi330_self_test_result_t &result)
 Run the built-in self-test. More...
 
sfTkError_t performGyroSelfCalibration (sfe_bmi330_self_calib_t selection, bool applyCorrection, sfe_bmi330_self_calib_result_t &result)
 Run the gyroscope self-calibration. More...
 
sfTkError_t setAccelOffset (int16_t x, int16_t y, int16_t z)
 Write the accelerometer user offsets. More...
 
sfTkError_t getAccelOffset (int16_t &x, int16_t &y, int16_t &z)
 Read the accelerometer user offsets. More...
 
sfTkError_t setGyroOffset (int16_t x, int16_t y, int16_t z)
 Write the gyroscope user offsets. More...
 
sfTkError_t getGyroOffset (int16_t &x, int16_t &y, int16_t &z)
 Read the gyroscope user offsets. More...
 
sfTkError_t readRegister (uint8_t reg, uint16_t &value)
 Read one 16-bit register, dummy bytes handled. More...
 
sfTkError_t writeRegister (uint8_t reg, uint16_t value)
 Write one 16-bit register. More...
 
sfTkError_t readRegisters (uint8_t reg, uint16_t *values, uint8_t count)
 Read consecutive 16-bit registers in one transaction, dummy bytes handled. More...
 
sfTkError_t writeRegisters (uint8_t reg, const uint16_t *values, uint8_t count)
 Write consecutive 16-bit registers in one transaction. More...
 
sfTkError_t sendCommand (uint16_t command)
 Send a command through the CMD register (0x7E). More...
 

Static Public Member Functions

static float rawToCelsius (int16_t raw)
 Convert a raw temperature count to degrees Celsius. More...
 
static float accelSensitivity (sfe_bmi330_accel_range_t range)
 Sensitivity of a given accelerometer range, in LSB per g. More...
 
static float gyroSensitivity (sfe_bmi330_gyro_range_t range)
 Sensitivity of a given gyroscope range, in LSB per degree per second. More...
 
static uint8_t frameLengthWords (uint16_t sources)
 Words per FIFO frame for a given set of sources. More...
 

Protected Member Functions

sfTkError_t updateRegister (uint8_t reg, uint16_t mask, uint16_t value)
 Read-modify-write a bit field of a 16-bit register. More...
 
sfTkError_t updateFeatureWord (uint8_t baseAddr, uint8_t wordIndex, uint16_t mask, uint16_t value)
 Read-modify-write a bit field of a feature engine word. More...
 
sfTkError_t setMotionConfig (uint8_t baseAddr, const sfe_bmi330_motion_config_t &config)
 Shared implementation for the any-motion and no-motion configuration writers. More...
 
sfTkError_t getMotionConfig (uint8_t baseAddr, sfe_bmi330_motion_config_t &config)
 Shared implementation for the any-motion and no-motion configuration readers. More...
 
sfTkError_t primeGyroFilterCoefficients (void)
 Seed the gyroscope filter coefficients required by BMI330 self-test and self-calibration. More...
 
sfTkError_t waitForSelfTestComplete (uint16_t &featureIO1, uint16_t stepDelayMs)
 Poll FEATURE_IO1 until the self-test / self-calibration completion bit is set. More...
 
sfTkError_t readFifoWords (uint16_t *words, uint8_t count)
 Read up to kMaxBurstWords words from the FIFO in one transaction. More...
 

Static Protected Member Functions

static int16_t signExtend (uint16_t value, uint8_t bits)
 Sign-extend a right-aligned two's complement field to a full int16_t. More...
 

Protected Attributes

sfTkIBus * _theBus
 The bus this driver communicates over. More...
 
uint8_t _dummyBytes
 Dummy bytes the device prepends to every read: 2 on I2C, 1 on SPI. More...
 
sfe_bmi330_accel_range_t _accelRange
 Cached accelerometer range, used by accelRawToG(). More...
 
sfe_bmi330_gyro_range_t _gyroRange
 Cached gyroscope range, used by gyroRawToDps(). More...
 
uint16_t _accelOffsetMask
 Mask for the accelerometer user offset field, set from the silicon revision. More...
 
uint16_t _pendingInt1
 INT1 status bits that setAxisRemap() had to read (and so clear) before its commit. More...
 

Static Protected Attributes

static const uint8_t kRegChipId = 0x00
 Chip and revision ID. More...
 
static const uint8_t kRegErrReg = 0x01
 Error flags. More...
 
static const uint8_t kRegStatus = 0x02
 Data ready and POR flags. Clear-on-read. More...
 
static const uint8_t kRegAccelDataX = 0x03
 Accelerometer X. Start of the data block. More...
 
static const uint8_t kRegGyroDataX = 0x06
 Gyroscope X. More...
 
static const uint8_t kRegTempData = 0x09
 Temperature. More...
 
static const uint8_t kRegSensorTime0 = 0x0A
 Sensor time, low word. More...
 
static const uint8_t kRegSatFlags = 0x0C
 Per-axis saturation flags. More...
 
static const uint8_t kRegIntStatusInt1 = 0x0D
 INT1 status. Clear-on-read. More...
 
static const uint8_t kRegIntStatusInt2 = 0x0E
 INT2 status. Clear-on-read. More...
 
static const uint8_t kRegFeatureIO0 = 0x10
 Feature enable bits. More...
 
static const uint8_t kRegFeatureIO1 = 0x11
 Feature engine status and errors. More...
 
static const uint8_t kRegFeatureIO2 = 0x12
 Step count low word / start-up config. More...
 
static const uint8_t kRegFeatureIO3 = 0x13
 Step count high word / start-up config. More...
 
static const uint8_t kRegFeatureIOStatus = 0x14
 Commit register for FEATURE_IO0 changes. More...
 
static const uint8_t kRegFifoFillLevel = 0x15
 FIFO fill level, in words. More...
 
static const uint8_t kRegFifoData = 0x16
 FIFO read port. Does not auto-increment. More...
 
static const uint8_t kRegAccelConf = 0x20
 Accelerometer configuration. More...
 
static const uint8_t kRegGyroConf = 0x21
 Gyroscope configuration. More...
 
static const uint8_t kRegAltAccelConf = 0x28
 Alternate accelerometer configuration. More...
 
static const uint8_t kRegAltGyroConf = 0x29
 Alternate gyroscope configuration. More...
 
static const uint8_t kRegFifoWatermark = 0x35
 FIFO watermark, in words. More...
 
static const uint8_t kRegFifoConf = 0x36
 FIFO source enables and stop-on-full. More...
 
static const uint8_t kRegFifoCtrl = 0x37
 FIFO flush. More...
 
static const uint8_t kRegIoIntCtrl = 0x38
 Interrupt pin electrical configuration. More...
 
static const uint8_t kRegIntConf = 0x39
 Interrupt latch mode. More...
 
static const uint8_t kRegIntMap1 = 0x3A
 Interrupt routing, feature sources. More...
 
static const uint8_t kRegIntMap2 = 0x3B
 Interrupt routing, data and FIFO sources. More...
 
static const uint8_t kRegFeatureCtrl = 0x40
 Feature engine enable. More...
 
static const uint8_t kRegFeatureDataAddr = 0x41
 Feature memory address window. More...
 
static const uint8_t kRegFeatureDataTx = 0x42
 Feature memory data port. Auto-increments. More...
 
static const uint8_t kRegFeatureEventExt = 0x47
 Orientation and tap event outputs. More...
 
static const uint8_t kRegAccelDpOffX = 0x60
 Accelerometer X user offset. More...
 
static const uint8_t kRegGyroDpOffX = 0x66
 Gyroscope X user offset. More...
 
static const uint8_t kRegCmd = 0x7E
 Command register. More...
 
static const uint16_t kCmdSelfTestTrigger = 0x0100
 Start a self-test. More...
 
static const uint16_t kCmdSelfCalibTrigger = 0x0101
 Start a gyroscope self-calibration. More...
 
static const uint16_t kCmdSelfCalibAbort = 0x0200
 Abort a self-calibration. More...
 
static const uint16_t kCmdAxisMapUpdate = 0x0300
 Commit an axis remap. More...
 
static const uint16_t kCmdSoftReset = 0xDEAF
 Soft reset. More...
 
static const uint16_t kConfOdrMask = 0x000F
 Output data rate, bits 3:0. More...
 
static const uint16_t kConfRangeMask = 0x0070
 Full-scale range, bits 6:4. More...
 
static const uint8_t kConfRangeShift = 4
 Range field position. More...
 
static const uint16_t kConfBwMask = 0x0080
 Bandwidth, bit 7. More...
 
static const uint8_t kConfBwShift = 7
 Bandwidth field position. More...
 
static const uint16_t kConfAvgMask = 0x0700
 Averaging, bits 10:8. More...
 
static const uint8_t kConfAvgShift = 8
 Averaging field position. More...
 
static const uint16_t kConfModeMask = 0x7000
 Power mode, bits 14:12. More...
 
static const uint8_t kConfModeShift = 12
 Power mode field position. More...
 
static const uint16_t kStatusTempDrdy = 0x0020
 Temperature data ready. More...
 
static const uint16_t kStatusGyroDrdy = 0x0040
 Gyroscope data ready. More...
 
static const uint16_t kStatusAccelDrdy = 0x0080
 Accelerometer data ready. More...
 
static const uint16_t kErrFatal = 0x0001
 Fatal error. More...
 
static const uint16_t kErrFeatEngOverload = 0x0004
 Feature engine overload. More...
 
static const uint16_t kErrFeatEngWatchdog = 0x0010
 Feature engine watchdog. More...
 
static const uint16_t kErrAccelConf = 0x0020
 Unsupported accelerometer configuration. More...
 
static const uint16_t kErrGyroConf = 0x0040
 Unsupported gyroscope configuration. More...
 
static const uint16_t kSatAccelX = 0x0001
 Accelerometer X saturated. More...
 
static const uint16_t kSatAccelY = 0x0002
 Accelerometer Y saturated. More...
 
static const uint16_t kSatAccelZ = 0x0004
 Accelerometer Z saturated. More...
 
static const uint16_t kSatGyroX = 0x0008
 Gyroscope X saturated. More...
 
static const uint16_t kSatGyroY = 0x0010
 Gyroscope Y saturated. More...
 
static const uint16_t kSatGyroZ = 0x0020
 Gyroscope Z saturated. More...
 
static const uint16_t kInt1LevelMask = 0x0001
 INT1 polarity, 1 = active high. More...
 
static const uint16_t kInt1OpenDrainMask = 0x0002
 INT1 open-drain. More...
 
static const uint16_t kInt1OutputEnMask = 0x0004
 INT1 output enable. More...
 
static const uint16_t kInt2LevelMask = 0x0100
 INT2 polarity, 1 = active high. More...
 
static const uint16_t kInt2OpenDrainMask = 0x0200
 INT2 open-drain. More...
 
static const uint16_t kInt2OutputEnMask = 0x0400
 INT2 output enable. More...
 
static const uint16_t kIntLatchMask = 0x0001
 Latched interrupt mode. More...
 
static const uint16_t kFifoStopOnFullMask = 0x0001
 Stop writing when full. More...
 
static const uint16_t kFifoSourceMask = 0x0F00
 Source enable field. More...
 
static const uint16_t kFifoFlushMask = 0x0001
 Flush command bit in FIFO_CTRL. More...
 
static const uint16_t kFifoWatermarkMask = 0x03FF
 Watermark field. More...
 
static const uint16_t kFifoFillLevelMask = 0x07FF
 Fill level field. More...
 
static const uint16_t kFifoAccelInvalid = 0x7F01
 Sentinel word written into a FIFO accelerometer slot when the sensor was idle. More...
 
static const uint16_t kFifoGyroInvalid = 0x7F02
 Sentinel word written into a FIFO gyroscope slot when the sensor was idle. More...
 
static const uint16_t kFifoTempInvalid = 0x8000
 Sentinel word written into a FIFO temperature slot when the sensor was idle. More...
 
static const uint16_t kFeatureEngineEnable = 0x0001
 Engine enable / active flag. More...
 
static const uint16_t kFeatureIOStatusCommit = 0x0001
 Commit bit for FEATURE_IO0 changes. More...
 
static const uint16_t kFeatureStartupConfig = 0x012C
 Start-up value written to FEATURE_IO2. More...
 
static const uint16_t kFeatureErrorMask = 0x000F
 Error nibble in FEATURE_IO1. More...
 
static const uint16_t kFeatureNoError = 0x0005
 Error nibble value meaning "no error". More...
 
static const uint16_t kScStComplete = 0x0010
 Self-test / self-calibration complete. More...
 
static const uint16_t kScResult = 0x0020
 Gyroscope self-calibration result. More...
 
static const uint16_t kStResult = 0x0040
 Self-test result. More...
 
static const uint16_t kAxisMapComplete = 0x0400
 Axis map applied. More...
 
static const uint16_t kFeatureAddrMask = 0x07FF
 Address field of FEATURE_DATA_ADDR. More...
 
static const uint16_t kEventOrientationMask = 0x0003
 Portrait / landscape classification. More...
 
static const uint16_t kEventFaceDownMask = 0x0004
 Face down flag. More...
 
static const uint16_t kEventSingleTap = 0x0008
 Single tap detected. More...
 
static const uint16_t kEventDoubleTap = 0x0010
 Double tap detected. More...
 
static const uint16_t kEventTripleTap = 0x0020
 Triple tap detected. More...
 
static const uint16_t kMotionSlopeThresholdMask = 0x0FFF
 Any/no-motion slope threshold. More...
 
static const uint16_t kMotionAccelRefUpMask = 0x1000
 Any/no-motion reference update. More...
 
static const uint16_t kMotionHysteresisMask = 0x03FF
 Any/no-motion hysteresis. More...
 
static const uint16_t kMotionDurationMask = 0x1FFF
 Any/no-motion duration. More...
 
static const uint16_t kMotionWaitTimeMask = 0xE000
 Any/no-motion wait time. More...
 
static const uint8_t kMotionWaitTimeShift = 13
 Wait time field position. More...
 
static const uint16_t kSigP2pMinMask = 0x03FF
 Significant motion minimum peak-to-peak. More...
 
static const uint16_t kSigMcrMinMask = 0xFC00
 Significant motion minimum crossing rate. More...
 
static const uint8_t kSigMcrMinShift = 10
 Minimum crossing rate field position. More...
 
static const uint16_t kSigP2pMaxMask = 0x03FF
 Significant motion maximum peak-to-peak. More...
 
static const uint16_t kSigMcrMaxMask = 0xFC00
 Significant motion maximum crossing rate. More...
 
static const uint8_t kSigMcrMaxShift = 10
 Maximum crossing rate field position. More...
 
static const uint16_t kTiltSegmentSizeMask = 0x00FF
 Tilt reference segment size. More...
 
static const uint16_t kTiltMinAngleMask = 0xFF00
 Tilt minimum angle. More...
 
static const uint8_t kTiltMinAngleShift = 8
 Minimum angle field position. More...
 
static const uint16_t kOrientUdEnMask = 0x0001
 Orientation face up / down enable. More...
 
static const uint16_t kOrientModeMask = 0x0006
 Orientation mode. More...
 
static const uint8_t kOrientModeShift = 1
 Orientation mode field position. More...
 
static const uint16_t kOrientBlockingMask = 0x0018
 Orientation blocking. More...
 
static const uint8_t kOrientBlockingShift = 3
 Blocking field position. More...
 
static const uint16_t kOrientThetaMask = 0x07E0
 Orientation theta. More...
 
static const uint8_t kOrientThetaShift = 5
 Theta field position. More...
 
static const uint16_t kOrientHoldTimeMask = 0xF800
 Orientation hold time. More...
 
static const uint8_t kOrientHoldTimeShift = 11
 Hold time field position. More...
 
static const uint16_t kOrientSlopeThresMask = 0x00FF
 Orientation slope threshold. More...
 
static const uint16_t kOrientHystMask = 0xFF00
 Orientation hysteresis. More...
 
static const uint8_t kOrientHystShift = 8
 Hysteresis field position. More...
 
static const uint16_t kFlatThetaMask = 0x003F
 Flat theta. More...
 
static const uint16_t kFlatBlockingMask = 0x00C0
 Flat blocking. More...
 
static const uint8_t kFlatBlockingShift = 6
 Blocking field position. More...
 
static const uint16_t kFlatHoldTimeMask = 0xFF00
 Flat hold time. More...
 
static const uint8_t kFlatHoldTimeShift = 8
 Hold time field position. More...
 
static const uint16_t kFlatSlopeThresMask = 0x00FF
 Flat slope threshold. More...
 
static const uint16_t kFlatHystMask = 0xFF00
 Flat hysteresis. More...
 
static const uint8_t kFlatHystShift = 8
 Hysteresis field position. More...
 
static const uint16_t kTapAxisMask = 0x0003
 Tap axis selection. More...
 
static const uint16_t kTapWaitTimeoutMask = 0x0004
 Tap wait-for-timeout. More...
 
static const uint16_t kTapMaxPeaksMask = 0x0038
 Tap maximum peaks. More...
 
static const uint8_t kTapMaxPeaksShift = 3
 Maximum peaks field position. More...
 
static const uint16_t kTapModeMask = 0x00C0
 Tap mode. More...
 
static const uint8_t kTapModeShift = 6
 Mode field position. More...
 
static const uint16_t kTapPeakThresMask = 0x03FF
 Tap peak threshold. More...
 
static const uint16_t kTapMaxGestDurMask = 0xFC00
 Tap maximum gesture duration. More...
 
static const uint8_t kTapMaxGestDurShift = 10
 Gesture duration field position. More...
 
static const uint16_t kTapMaxDurBwPeaksMask = 0x000F
 Tap maximum duration between peaks. More...
 
static const uint16_t kTapShockSettDurMask = 0x00F0
 Tap shock settling duration. More...
 
static const uint8_t kTapShockSettDurShift = 4
 Shock settling field position. More...
 
static const uint16_t kTapMinQuietDurMask = 0x0F00
 Tap minimum quiet duration. More...
 
static const uint8_t kTapMinQuietDurShift = 8
 Minimum quiet field position. More...
 
static const uint16_t kTapQuietAfterGestMask = 0xF000
 Tap quiet time after gesture. More...
 
static const uint8_t kTapQuietAfterGestShift = 12
 Quiet after gesture field position. More...
 
static const uint16_t kStepWatermarkMask = 0x03FF
 Step counter watermark. More...
 
static const uint16_t kStepResetCounterMask = 0x0400
 Step counter reset bit. More...
 
static const uint16_t kRemapAxisMask = 0x0007
 Axis permutation. More...
 
static const uint16_t kRemapXSignMask = 0x0008
 Invert X. More...
 
static const uint16_t kRemapYSignMask = 0x0010
 Invert Y. More...
 
static const uint16_t kRemapZSignMask = 0x0020
 Invert Z. More...
 
static const uint16_t kAccelOffsetMask14 = 0x3FFF
 Accelerometer offset, 14-bit (rev 1+). More...
 
static const uint16_t kAccelOffsetMask13 = 0x1FFF
 Accelerometer offset, 13-bit (rev 0). More...
 
static const uint16_t kGyroOffsetMask = 0x03FF
 Gyroscope offset, 10-bit signed. More...
 
static const uint8_t kDummyBytesI2C = 2
 Dummy bytes prepended to a read on I2C. More...
 
static const uint8_t kDummyBytesSPI = 1
 Dummy bytes prepended to a read on SPI. More...
 
static const uint8_t kMaxBurstWords = 15
 Largest word count a single readRegisters() / writeRegisters() call handles. More...
 
static const uint8_t kSoftResetDelayMs = 2
 Milliseconds to wait after a soft reset before touching the device. More...
 
static const uint8_t kFeatureEngineStepMs = 10
 Milliseconds between feature engine start-up polls. More...
 
static const uint8_t kFeatureEngineRetries = 20
 Feature engine start-up polls before giving up. More...
 
static const uint8_t kSelfTestStepMs = 35
 Milliseconds between self-test completion polls. More...
 
static const uint8_t kSelfCalibStepMs = 43
 Milliseconds between self-calibration completion polls. More...
 
static const uint8_t kSelfTestRetries = 10
 Completion polls before a self-test or self-calibration is declared timed out. More...
 
static const uint8_t kAxisMapRetries = 10
 Axis-map acknowledgement polls before giving up. More...
 
static const uint8_t kAxisMapStepMs = 10
 Milliseconds between axis-map acknowledgement polls. More...
 
static const uint16_t kFifoSizeWords = 1024
 Words in the FIFO buffer (2048 bytes). More...
 

Detailed Description

Platform-independent driver for the Bosch BMI330 6-DoF IMU.

Holds every register address, bit field and conversion the part needs, and talks to the device through an sfTkIBus supplied by begin(). It knows nothing about Arduino, Wire or SPI - the Arduino wrappers in SparkFun_BMI330.h provide those. A sketch normally uses SfeBMI330ArdI2C or SfeBMI330ArdSPI, both of which inherit everything documented here.

Methods that touch the bus return sfTkError_t (::ksfTkErrOk on success); methods that only read cached or computed state return the value directly.

See also
SfeBMI330ArdI2C
SfeBMI330ArdSPI

Constructor & Destructor Documentation

◆ sfDevBMI330()

sfDevBMI330::sfDevBMI330 ( )
inline

Default constructor.

The device is not touched until begin().

◆ ~sfDevBMI330()

virtual sfDevBMI330::~sfDevBMI330 ( )
inlinevirtual

Member Function Documentation

◆ accelRawToG()

float sfDevBMI330::accelRawToG ( int16_t  raw)

Convert a raw accelerometer count to g using the cached range.

Parameters
rawRaw 16-bit signed count.
Returns
Acceleration in g.

◆ accelSensitivity()

float sfDevBMI330::accelSensitivity ( sfe_bmi330_accel_range_t  range)
static

Sensitivity of a given accelerometer range, in LSB per g.

Parameters
rangeFull-scale range.
Returns
LSB per g: 16384, 8192, 4096 or 2048.

◆ begin()

sfTkError_t sfDevBMI330::begin ( sfTkIBus *  theBus = nullptr)

Adopt a bus, verify the device, and bring the feature engine up.

Determines the read dummy-byte count from the bus type, checks CHIP_ID, picks the accelerometer offset field width from the silicon revision, soft resets - which also starts the feature engine - and then reads ACC_CONF and GYR_CONF back so the cached ranges used by accelRawToG() and gyroRawToDps() describe the device rather than an assumed default. Both sensors are left DISABLED, matching the power-on state; call enableAccel() and enableGyro(), or setAccelConfig() / setGyroConfig(), before expecting data.

Parameters
theBusBus to communicate over. Pass nullptr to keep a bus set earlier.
Returns
::ksfTkErrOk on success, ::ksfTkErrBusNotInit with no bus, or ::ksfTkErrBusNoResponse if the chip ID does not match.

◆ enableAccel()

sfTkError_t sfDevBMI330::enableAccel ( bool  enable = true)

Turn the accelerometer on in high-performance mode, or off.

Parameters
enabletrue for high-performance mode, false to disable the sensor.
Returns
::ksfTkErrOk on success.

◆ enableFeature()

sfTkError_t sfDevBMI330::enableFeature ( uint16_t  features,
bool  enable = true 
)

Enable or disable feature-engine features.

Read-modify-write of FEATURE_IO0 (0x10) followed by the commit write to FEATURE_IO_STATUS (0x14) that tells the engine to pick the change up. Without the commit the bits sit in the register and nothing happens.

Parameters
featuresBitwise OR of sfe_bmi330_feature_t values.
enabletrue to set those bits, false to clear them.
Returns
::ksfTkErrOk on success.

◆ enableFeatureEngine()

sfTkError_t sfDevBMI330::enableFeatureEngine ( void  )

Start the feature engine without a full reset.

softReset() already does this, so it is rarely needed directly. Useful after the engine has reported an overload or watchdog error in ERR_REG.

Returns
::ksfTkErrOk if the engine reports active within the start-up window.

◆ enableGyro()

sfTkError_t sfDevBMI330::enableGyro ( bool  enable = true)

Turn the gyroscope on in high-performance mode, or off.

Parameters
enabletrue for high-performance mode, false to disable the sensor.
Returns
::ksfTkErrOk on success.

◆ flushFifo()

sfTkError_t sfDevBMI330::flushFifo ( void  )

Discard everything in the FIFO.

Returns
::ksfTkErrOk on success.

◆ frameLengthWords()

uint8_t sfDevBMI330::frameLengthWords ( uint16_t  sources)
static

Words per FIFO frame for a given set of sources.

Parameters
sourcesBitwise OR of sfe_bmi330_fifo_source_t values.
Returns
Frame length in 16-bit words, or 0 if no source is enabled.

◆ getAccelConfig()

sfTkError_t sfDevBMI330::getAccelConfig ( sfe_bmi330_accel_mode_t &  mode,
sfe_bmi330_odr_t &  odr,
sfe_bmi330_accel_range_t &  range,
sfe_bmi330_bandwidth_t &  bandwidth,
sfe_bmi330_averaging_t &  averaging 
)

Read the accelerometer configuration back from ACC_CONF (0x20).

Also refreshes the cached range, so a sketch that configured the part in a previous power cycle gets correct conversions after calling this.

Parameters
modeReceives the power mode.
odrReceives the output data rate.
rangeReceives the full-scale range.
bandwidthReceives the filter setting.
averagingReceives the averaging setting.
Returns
::ksfTkErrOk on success.

◆ getAccelData()

sfTkError_t sfDevBMI330::getAccelData ( sfe_bmi330_data_t &  data)

Read just the accelerometer, converted to g.

Parameters
dataReceives the acceleration.
Returns
::ksfTkErrOk on success.

◆ getAccelDataRaw()

sfTkError_t sfDevBMI330::getAccelDataRaw ( sfe_bmi330_raw_data_t &  data)

Read just the accelerometer, in raw counts.

Parameters
dataReceives the raw acceleration.
Returns
::ksfTkErrOk on success.

◆ getAccelOffset()

sfTkError_t sfDevBMI330::getAccelOffset ( int16_t &  x,
int16_t &  y,
int16_t &  z 
)

Read the accelerometer user offsets.

Parameters
xReceives the X axis offset.
yReceives the Y axis offset.
zReceives the Z axis offset.
Returns
::ksfTkErrOk on success.

◆ getAccelRange()

sfe_bmi330_accel_range_t sfDevBMI330::getAccelRange ( void  )
inline

Get the cached accelerometer full-scale range.

This is what the conversion math uses. It tracks setAccelConfig(), setAccelRange() and getAccelConfig(); it does not read the device.

Returns
The cached range.

◆ getAnyMotionConfig()

sfTkError_t sfDevBMI330::getAnyMotionConfig ( sfe_bmi330_motion_config_t &  config)

Read the any-motion detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getAxisRemap()

sfTkError_t sfDevBMI330::getAxisRemap ( sfe_bmi330_axis_remap_t &  remap)

Read the current axis remapping.

Parameters
remapReceives the permutation and sign flips.
Returns
::ksfTkErrOk on success.

◆ getChipID()

sfTkError_t sfDevBMI330::getChipID ( uint8_t &  chipId,
uint8_t &  revId 
)

Read the chip and revision IDs from CHIP_ID (0x00).

Parameters
chipIdReceives the chip ID - 0x48 for a BMI330, 0x43 for a BMI323.
revIdReceives the silicon revision from the upper nibble.
Returns
::ksfTkErrOk on success.

◆ getDataReady()

sfTkError_t sfDevBMI330::getDataReady ( bool &  accelReady,
bool &  gyroReady,
bool &  tempReady 
)

Read the STATUS register (0x02) data-ready flags.

Note
The register is CLEAR-ON-READ: this call consumes the flags. Read once and use all three results.
Parameters
accelReadyReceives the accelerometer data-ready flag.
gyroReadyReceives the gyroscope data-ready flag.
tempReadyReceives the temperature data-ready flag.
Returns
::ksfTkErrOk on success.

◆ getEnabledFeatures()

sfTkError_t sfDevBMI330::getEnabledFeatures ( uint16_t &  features)

Read which features are currently enabled.

Parameters
featuresReceives the FEATURE_IO0 word.
Returns
::ksfTkErrOk on success.

◆ getErrorStatus()

sfTkError_t sfDevBMI330::getErrorStatus ( sfe_bmi330_error_status_t &  status)

Read and decode ERR_REG (0x01).

Parameters
statusReceives the decoded error flags.
Returns
::ksfTkErrOk on success.

◆ getFeatureEngineError()

sfTkError_t sfDevBMI330::getFeatureEngineError ( uint16_t &  status)

Read the raw FEATURE_IO1 (0x11) word.

The low nibble is an error code: 0x05 means no error, 0x03 a configuration CRC failure, 0x06 an axis-map error, 0x0C a self-test or self-calibration precondition failure. Higher bits carry the self-test and self-calibration completion and result flags.

Parameters
statusReceives the register word.
Returns
::ksfTkErrOk on success.

◆ getFeatureEngineStatus()

bool sfDevBMI330::getFeatureEngineStatus ( void  )

Check whether the feature engine is running.

Returns
true if FEATURE_IO1 reports the engine active.

◆ getFifoConfig()

sfTkError_t sfDevBMI330::getFifoConfig ( uint16_t &  sources,
bool &  stopOnFull 
)

Read back the configured FIFO sources and full behavior.

Parameters
sourcesReceives the enabled source bits.
stopOnFullReceives the stop-on-full setting.
Returns
::ksfTkErrOk on success.

◆ getFifoFillLevel()

sfTkError_t sfDevBMI330::getFifoFillLevel ( uint16_t &  words)

Read how many words the FIFO currently holds.

Parameters
wordsReceives the fill level in words. The buffer holds 1024 words (2 kB).
Returns
::ksfTkErrOk on success.

◆ getFifoWatermark()

sfTkError_t sfDevBMI330::getFifoWatermark ( uint16_t &  words)

Read the FIFO watermark, in words.

Parameters
wordsReceives the watermark level.
Returns
::ksfTkErrOk on success.

◆ getFlatConfig()

sfTkError_t sfDevBMI330::getFlatConfig ( sfe_bmi330_flat_config_t &  config)

Read the flat detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getGyroConfig()

sfTkError_t sfDevBMI330::getGyroConfig ( sfe_bmi330_gyro_mode_t &  mode,
sfe_bmi330_odr_t &  odr,
sfe_bmi330_gyro_range_t &  range,
sfe_bmi330_bandwidth_t &  bandwidth,
sfe_bmi330_averaging_t &  averaging 
)

Read the gyroscope configuration back from GYR_CONF (0x21).

Parameters
modeReceives the power mode.
odrReceives the output data rate.
rangeReceives the full-scale range.
bandwidthReceives the filter setting.
averagingReceives the averaging setting.
Returns
::ksfTkErrOk on success.

◆ getGyroData()

sfTkError_t sfDevBMI330::getGyroData ( sfe_bmi330_data_t &  data)

Read just the gyroscope, converted to degrees per second.

Parameters
dataReceives the angular rate.
Returns
::ksfTkErrOk on success.

◆ getGyroDataRaw()

sfTkError_t sfDevBMI330::getGyroDataRaw ( sfe_bmi330_raw_data_t &  data)

Read just the gyroscope, in raw counts.

Parameters
dataReceives the raw angular rate.
Returns
::ksfTkErrOk on success.

◆ getGyroOffset()

sfTkError_t sfDevBMI330::getGyroOffset ( int16_t &  x,
int16_t &  y,
int16_t &  z 
)

Read the gyroscope user offsets.

Parameters
xReceives the X axis offset.
yReceives the Y axis offset.
zReceives the Z axis offset.
Returns
::ksfTkErrOk on success.

◆ getGyroRange()

sfe_bmi330_gyro_range_t sfDevBMI330::getGyroRange ( void  )
inline

Get the cached gyroscope full-scale range.

Returns
The cached range.

◆ getInterruptStatus()

sfTkError_t sfDevBMI330::getInterruptStatus ( sfe_bmi330_int_pin_t  pin,
uint16_t &  status 
)

Read and clear a pin's interrupt status word.

Note
CLEAR-ON-READ. Every pending flag for that pin is consumed by this call, so test the returned word against the sfe_bmi330_int_status_t masks rather than calling again per bit.
Parameters
pinWhich pin's status to read.
statusReceives the status word.
Returns
::ksfTkErrOk on success, ::ksfTkErrInvalidParam for BMI330_INT_NONE.

◆ getMotionConfig()

sfTkError_t sfDevBMI330::getMotionConfig ( uint8_t  baseAddr,
sfe_bmi330_motion_config_t &  config 
)
protected

Shared implementation for the any-motion and no-motion configuration readers.

Parameters
baseAddrBMI330_FEAT_ADDR_ANY_MOTION or BMI330_FEAT_ADDR_NO_MOTION.
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getNoMotionConfig()

sfTkError_t sfDevBMI330::getNoMotionConfig ( sfe_bmi330_motion_config_t &  config)

Read the no-motion detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getOrientation()

sfTkError_t sfDevBMI330::getOrientation ( sfe_bmi330_orientation_t &  orientation,
bool &  faceDown 
)

Read the current orientation classification.

Parameters
orientationReceives the portrait / landscape classification.
faceDownReceives the face-down flag. Meaningful only with face up / down enabled.
Returns
::ksfTkErrOk on success.

◆ getOrientationConfig()

sfTkError_t sfDevBMI330::getOrientationConfig ( sfe_bmi330_orientation_config_t &  config)

Read the orientation detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getSaturationFlags()

sfTkError_t sfDevBMI330::getSaturationFlags ( sfe_bmi330_saturation_t &  flags)

Read and decode the per-axis saturation flags in SAT_FLAGS (0x0C).

Parameters
flagsReceives the decoded flags.
Returns
::ksfTkErrOk on success.

◆ getSensorData()

sfTkError_t sfDevBMI330::getSensorData ( sfe_bmi330_sensor_data_t &  data)

Read accelerometer, gyroscope, temperature and timestamp in one transaction.

One 9-word burst from ACC_DATA_X (0x03) to SENSOR_TIME_1 (0x0B), so every field describes the same instant. Both raw and converted forms are filled in - the conversion is a multiply per axis and costs nothing next to the bus traffic.

Parameters
dataReceives the reading.
Returns
::ksfTkErrOk on success.

◆ getSensorTime()

sfTkError_t sfDevBMI330::getSensorTime ( uint32_t &  sensorTime)

Read the 32-bit sensor timestamp, in ticks of 39.0625 us.

The counter runs from the device's own oscillator, so it timestamps samples far more precisely than millis() can - the host's read latency is not in the number. It wraps about about every 46.6 hours (2^32 ticks).

Parameters
sensorTimeReceives the timestamp.
Returns
::ksfTkErrOk on success.

◆ getSigMotionConfig()

sfTkError_t sfDevBMI330::getSigMotionConfig ( sfe_bmi330_sig_motion_config_t &  config)

Read the significant motion detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getStepCount()

sfTkError_t sfDevBMI330::getStepCount ( uint32_t &  steps)

Read the step count.

The counter is a 32-bit value split across FEATURE_IO2 (0x12) and FEATURE_IO3 (0x13), read here as one two-word burst so the halves cannot disagree.

Parameters
stepsReceives the step count.
Returns
::ksfTkErrOk on success.

◆ getStepCounterWatermark()

sfTkError_t sfDevBMI330::getStepCounterWatermark ( uint16_t &  watermark)

Read the step counter watermark.

Parameters
watermarkReceives the watermark, in units of 20 steps.
Returns
::ksfTkErrOk on success.

◆ getTapConfig()

sfTkError_t sfDevBMI330::getTapConfig ( sfe_bmi330_tap_config_t &  config)

Read the tap detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ getTapEvent()

sfTkError_t sfDevBMI330::getTapEvent ( sfe_bmi330_tap_event_t &  event)

Read which tap gesture was last detected.

Call after a BMI330_INT_STATUS_TAP interrupt. The single, double and triple flags live in FEATURE_EVENT_EXT (0x47).

Parameters
eventReceives the gesture flags.
Returns
::ksfTkErrOk on success.

◆ getTemperature()

sfTkError_t sfDevBMI330::getTemperature ( float &  celsius)

Read the die temperature in degrees Celsius.

Note
This is the temperature of the silicon, which runs warm - it tracks ambient but is not an ambient sensor. Its value is in compensating the gyroscope, not in reporting the weather.
Parameters
celsiusReceives the temperature.
Returns
::ksfTkErrOk on success.

◆ getTiltConfig()

sfTkError_t sfDevBMI330::getTiltConfig ( sfe_bmi330_tilt_config_t &  config)

Read the tilt detector configuration.

Parameters
configReceives the settings.
Returns
::ksfTkErrOk on success.

◆ gyroRawToDps()

float sfDevBMI330::gyroRawToDps ( int16_t  raw)

Convert a raw gyroscope count to degrees per second using the cached range.

Parameters
rawRaw 16-bit signed count.
Returns
Angular rate in degrees per second.

◆ gyroSensitivity()

float sfDevBMI330::gyroSensitivity ( sfe_bmi330_gyro_range_t  range)
static

Sensitivity of a given gyroscope range, in LSB per degree per second.

Parameters
rangeFull-scale range.
Returns
LSB per dps.

◆ isConnected()

bool sfDevBMI330::isConnected ( void  )

Check that a BMI330 is responding.

Returns
true if CHIP_ID reads SFE_BMI330_CHIP_ID.

◆ mapInterrupt()

sfTkError_t sfDevBMI330::mapInterrupt ( sfe_bmi330_int_source_t  source,
sfe_bmi330_int_pin_t  pin 
)

Route one interrupt source to a pin, or disconnect it.

Parameters
sourceThe source to route.
pinDestination pin, or BMI330_INT_NONE to disconnect.
Returns
::ksfTkErrOk on success, ::ksfTkErrInvalidParam for an unknown source.

◆ performGyroSelfCalibration()

sfTkError_t sfDevBMI330::performGyroSelfCalibration ( sfe_bmi330_self_calib_t  selection,
bool  applyCorrection,
sfe_bmi330_self_calib_result_t &  result 
)

Run the gyroscope self-calibration.

Measures and corrects the gyroscope's offset, its sensitivity, or both, storing the result in the device's user registers.

Note
PRECONDITIONS MATTER. The device must be MOTIONLESS for the whole run, and the accelerometer must be in high-performance mode at 100 Hz and +/-8 g - which this method sets up and then restores. Expect up to 430 ms. A calibration run on a moving device reports success and leaves a worse offset than it started with.
Parameters
selectionWhat to correct.
applyCorrectiontrue to have the device apply the result to its output immediately.
resultReceives the outcome.
Returns
::ksfTkErrOk if the routine ran. Check result for the verdict.

◆ performSelfTest()

sfTkError_t sfDevBMI330::performSelfTest ( sfe_bmi330_self_test_t  selection,
sfe_bmi330_self_test_result_t &  result 
)

Run the built-in self-test.

Drives a known stimulus into the selected sensors and checks the response against factory limits. On the BMI330 this also involves seeding the gyroscope filter coefficients in feature memory, which the driver handles - the values differ from the BMI323's, and a test run without them reports failures on a healthy part.

Note
DISRUPTIVE AND SLOW. The routine forces the accelerometer to high-performance mode at 100 Hz, takes up to 350 ms, and leaves both sensors reconfigured. Run it at start-up or on demand, restore the configuration afterwards, and keep the device STILL while it runs.
Per-axis flags are filled in only for the sensors named by selection. The bits belonging to a sensor that was not tested are not meaningful for that run, so they are left false rather than reported as failures.
Parameters
selectionWhich sensors to test.
resultReceives the outcome.
Returns
::ksfTkErrOk if the routine ran. Check result for the verdict.

◆ primeGyroFilterCoefficients()

sfTkError_t sfDevBMI330::primeGyroFilterCoefficients ( void  )
protected

Seed the gyroscope filter coefficients required by BMI330 self-test and self-calibration.

The BMI330 ships with coefficients that differ from the BMI323's, and the routines only produce meaningful results against the BMI330 set. This writes them if what is already there does not match.

Returns
::ksfTkErrOk on success.

◆ rawToCelsius()

float sfDevBMI330::rawToCelsius ( int16_t  raw)
static

Convert a raw temperature count to degrees Celsius.

The BMI330 reports 256 LSB per kelvin with zero at 23 degrees C, so the conversion is raw / 256 + 23.

Note
This divisor is NOT the same on the BMI323, which uses 512. A driver ported from the BMI323 without changing this reads roughly half the true excursion from 23 degrees.
Parameters
rawRaw 16-bit signed count.
Returns
Temperature in degrees Celsius.

◆ readFeatureWords()

sfTkError_t sfDevBMI330::readFeatureWords ( uint8_t  baseAddr,
uint16_t *  words,
uint8_t  count 
)

Read consecutive words from feature engine extended memory.

Parameters
baseAddrFeature base address - see sfe_bmi330_feature_addr_t.
wordsDestination buffer.
countNumber of words to read. Maximum kMaxBurstWords.
Returns
::ksfTkErrOk on success.

◆ readFifoData()

sfTkError_t sfDevBMI330::readFifoData ( sfe_bmi330_fifo_frame_t *  frames,
uint8_t  maxFrames,
uint8_t &  numFrames,
uint16_t  sources 
)

Read and decode complete frames from the FIFO.

Reads only whole frames - if the FIFO holds a partial one, it is left in place for the next call rather than being torn in half. Frames whose source was idle at capture carry an invalid pattern, which is reported as a cleared has... flag.

Parameters
framesDestination array.
maxFramesCapacity of frames.
numFramesReceives the number of frames actually decoded.
sourcesThe same source bits that were passed to setFifoConfig(). The FIFO is headerless, so the parser cannot work this out on its own.
Returns
::ksfTkErrOk on success, including when zero frames were available.

◆ readFifoRaw()

sfTkError_t sfDevBMI330::readFifoRaw ( uint16_t *  words,
uint16_t  count 
)

Read raw words out of FIFO_DATA (0x16) without interpreting them.

The FIFO_DATA register does not auto-increment - the whole burst streams from one address. Useful for logging the FIFO verbatim and decoding later, off the device.

Note
Reads longer than kMaxBurstWords are split into several transactions, always on word boundaries. Because the device retransmits a frame that was only partially read out, ask for a whole number of frames, or an exact multiple of kMaxBurstWords - readFifoData() already does the former.
Parameters
wordsDestination buffer, at least count words.
countNumber of words to read.
Returns
::ksfTkErrOk on success.

◆ readFifoWords()

sfTkError_t sfDevBMI330::readFifoWords ( uint16_t *  words,
uint8_t  count 
)
protected

Read up to kMaxBurstWords words from the FIFO in one transaction.

Splitting a FIFO read at a frame boundary is safe; splitting it inside a frame is not, because the device retransmits a partially-read frame. Callers are responsible for choosing a frame-aligned count.

Parameters
wordsDestination buffer.
countNumber of words. Maximum kMaxBurstWords.
Returns
::ksfTkErrOk on success.

◆ readRegister()

sfTkError_t sfDevBMI330::readRegister ( uint8_t  reg,
uint16_t &  value 
)

Read one 16-bit register, dummy bytes handled.

Parameters
regRegister address.
valueReceives the register contents.
Returns
::ksfTkErrOk on success.

◆ readRegisters()

sfTkError_t sfDevBMI330::readRegisters ( uint8_t  reg,
uint16_t *  values,
uint8_t  count 
)

Read consecutive 16-bit registers in one transaction, dummy bytes handled.

Parameters
regFirst register address.
valuesDestination buffer.
countNumber of words. Maximum kMaxBurstWords.
Returns
::ksfTkErrOk on success.

◆ resetStepCount()

sfTkError_t sfDevBMI330::resetStepCount ( void  )

Reset the step count to zero.

Sets and then clears the reset bit in the step counter's first configuration word, leaving the rest of that 12-word block untouched.

Returns
::ksfTkErrOk on success.

◆ sendCommand()

sfTkError_t sfDevBMI330::sendCommand ( uint16_t  command)

Send a command through the CMD register (0x7E).

Parameters
commandCommand word.
Returns
::ksfTkErrOk on success.

◆ setAccelAveraging()

sfTkError_t sfDevBMI330::setAccelAveraging ( sfe_bmi330_averaging_t  averaging)

Set the accelerometer hardware averaging.

Parameters
averagingSamples to average.
Returns
::ksfTkErrOk on success.

◆ setAccelBandwidth()

sfTkError_t sfDevBMI330::setAccelBandwidth ( sfe_bmi330_bandwidth_t  bandwidth)

Set the accelerometer filter bandwidth.

Parameters
bandwidthCutoff as a fraction of ODR.
Returns
::ksfTkErrOk on success.

◆ setAccelConfig()

sfTkError_t sfDevBMI330::setAccelConfig ( sfe_bmi330_accel_mode_t  mode,
sfe_bmi330_odr_t  odr,
sfe_bmi330_accel_range_t  range,
sfe_bmi330_bandwidth_t  bandwidth = BMI330_BW_ODR_HALF,
sfe_bmi330_averaging_t  averaging = BMI330_AVG_1 
)

Write the whole accelerometer configuration in one register write.

ACC_CONF (0x20) is a single word holding mode, ODR, range, bandwidth and averaging, so setting them together is one transaction rather than five read-modify-writes. The range is cached here for the raw-to-g conversion.

Parameters
modePower mode.
odrOutput data rate.
rangeFull-scale range.
bandwidthFilter cutoff as a fraction of ODR.
averagingHardware averaging.
Returns
::ksfTkErrOk on success.

◆ setAccelMode()

sfTkError_t sfDevBMI330::setAccelMode ( sfe_bmi330_accel_mode_t  mode)

Set the accelerometer power mode, leaving the rest of ACC_CONF alone.

Parameters
modePower mode.
Returns
::ksfTkErrOk on success.

◆ setAccelODR()

sfTkError_t sfDevBMI330::setAccelODR ( sfe_bmi330_odr_t  odr)

Set the accelerometer output data rate.

Parameters
odrOutput data rate.
Returns
::ksfTkErrOk on success.

◆ setAccelOffset()

sfTkError_t sfDevBMI330::setAccelOffset ( int16_t  x,
int16_t  y,
int16_t  z 
)

Write the accelerometer user offsets.

Offsets are signed values applied in the data path before the output registers, at a fixed 0.0039 g per LSB REGARDLESS of the selected range - changing the range does not rescale them.

Note
The field is 14 bits on revision 1 and later silicon and 13 bits on earlier parts. begin() reads the revision and picks; values are masked to whichever width this device has.
Parameters
xX axis offset, 14-bit signed.
yY axis offset, 14-bit signed.
zZ axis offset, 14-bit signed.
Returns
::ksfTkErrOk on success.

◆ setAccelRange()

sfTkError_t sfDevBMI330::setAccelRange ( sfe_bmi330_accel_range_t  range)

Set the accelerometer full-scale range.

Parameters
rangeFull-scale range.
Returns
::ksfTkErrOk on success.

◆ setAnyMotionConfig()

sfTkError_t sfDevBMI330::setAnyMotionConfig ( const sfe_bmi330_motion_config_t &  config)

Write the any-motion detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setAxisRemap()

sfTkError_t sfDevBMI330::setAxisRemap ( const sfe_bmi330_axis_remap_t &  remap)

Apply an axis remapping inside the device.

Writes the map into feature memory, then commits it. The commit is the fiddly part: the device will only accept an axis-map update while the ACCELEROMETER IS SUSPENDED, so this method saves the current accelerometer power mode, disables the sensor, issues the axis-map-update command, waits for the feature engine to acknowledge it, clears the INT1 status the update leaves behind, and restores the saved mode. INT1 events that were already pending are kept and returned by the next getInterruptStatus(BMI330_INT1). Sampling is interrupted for a few tens of milliseconds; the caller's configuration is not otherwise disturbed.

Note
If the accelerometer is already disabled when this is called, the command is issued and the method returns without polling - which is what Bosch's own driver does, because the acknowledgement is only produced on the suspend-and-restore path.
Parameters
remapAxis permutation and sign flips.
Returns
::ksfTkErrOk on success.

◆ setCommunicationBus()

void sfDevBMI330::setCommunicationBus ( sfTkIBus *  theBus)

Set the communication bus without initializing the device.

Also re-derives the dummy-byte count, since it follows the bus type.

Parameters
theBusBus to use for communication.

◆ setFifoConfig()

sfTkError_t sfDevBMI330::setFifoConfig ( uint16_t  sources,
bool  stopOnFull = false 
)

Choose what the FIFO records, and what it does when full.

Parameters
sourcesBitwise OR of sfe_bmi330_fifo_source_t values. Zero disables the FIFO.
stopOnFulltrue to stop writing when full (keep the oldest data), false to overwrite the oldest data and keep the newest.
Returns
::ksfTkErrOk on success.

◆ setFifoWatermark()

sfTkError_t sfDevBMI330::setFifoWatermark ( uint16_t  words)

Set the FIFO watermark, in 16-bit words.

The watermark interrupt fires when the fill level reaches this many WORDS - not bytes and not frames. A frame is 3 words of accelerometer plus 3 of gyroscope plus 1 each of temperature and time, counting only enabled sources, so a watermark of 80 words is 10 frames of accelerometer-plus-gyroscope. frameLengthWords() does the arithmetic.

Parameters
wordsWatermark level in words. Range 0 to 1023.
Returns
::ksfTkErrOk on success.

◆ setFlatConfig()

sfTkError_t sfDevBMI330::setFlatConfig ( const sfe_bmi330_flat_config_t &  config)

Write the flat detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setGyroAveraging()

sfTkError_t sfDevBMI330::setGyroAveraging ( sfe_bmi330_averaging_t  averaging)

Set the gyroscope hardware averaging.

Parameters
averagingSamples to average.
Returns
::ksfTkErrOk on success.

◆ setGyroBandwidth()

sfTkError_t sfDevBMI330::setGyroBandwidth ( sfe_bmi330_bandwidth_t  bandwidth)

Set the gyroscope filter bandwidth.

Parameters
bandwidthCutoff as a fraction of ODR.
Returns
::ksfTkErrOk on success.

◆ setGyroConfig()

sfTkError_t sfDevBMI330::setGyroConfig ( sfe_bmi330_gyro_mode_t  mode,
sfe_bmi330_odr_t  odr,
sfe_bmi330_gyro_range_t  range,
sfe_bmi330_bandwidth_t  bandwidth = BMI330_BW_ODR_HALF,
sfe_bmi330_averaging_t  averaging = BMI330_AVG_1 
)

Write the whole gyroscope configuration in one register write.

Parameters
modePower mode.
odrOutput data rate.
rangeFull-scale range.
bandwidthFilter cutoff as a fraction of ODR.
averagingHardware averaging.
Returns
::ksfTkErrOk on success.

◆ setGyroMode()

sfTkError_t sfDevBMI330::setGyroMode ( sfe_bmi330_gyro_mode_t  mode)

Set the gyroscope power mode, leaving the rest of GYR_CONF alone.

Parameters
modePower mode.
Returns
::ksfTkErrOk on success.

◆ setGyroODR()

sfTkError_t sfDevBMI330::setGyroODR ( sfe_bmi330_odr_t  odr)

Set the gyroscope output data rate.

Parameters
odrOutput data rate.
Returns
::ksfTkErrOk on success.

◆ setGyroOffset()

sfTkError_t sfDevBMI330::setGyroOffset ( int16_t  x,
int16_t  y,
int16_t  z 
)

Write the gyroscope user offsets.

Offsets are 10-bit signed values at a fixed 0.061 dps per LSB, applied before the output registers and independent of the selected range.

Parameters
xX axis offset, 10-bit signed.
yY axis offset, 10-bit signed.
zZ axis offset, 10-bit signed.
Returns
::ksfTkErrOk on success.

◆ setGyroRange()

sfTkError_t sfDevBMI330::setGyroRange ( sfe_bmi330_gyro_range_t  range)

Set the gyroscope full-scale range.

Parameters
rangeFull-scale range.
Returns
::ksfTkErrOk on success.

◆ setInterruptLatch()

sfTkError_t sfDevBMI330::setInterruptLatch ( bool  latched)

Choose between latched and pulsed interrupts.

Pulsed (the default) asserts the pin briefly per event. Latched holds it asserted until the status register is read, which is what an edge-triggered host ISR that might miss a short pulse wants - at the cost of requiring the status read to happen.

Note
The setting is global: it applies to both pins and every source.
Parameters
latchedtrue to latch until the status register is read.
Returns
::ksfTkErrOk on success.

◆ setInterruptPinConfig()

sfTkError_t sfDevBMI330::setInterruptPinConfig ( sfe_bmi330_int_pin_t  pin,
const sfe_bmi330_int_pin_config_t &  config 
)

Configure the electrical behavior of one interrupt pin.

Both pins share IO_INT_CTRL (0x38), so this is a read-modify-write and the other pin's settings are preserved.

Parameters
pinWhich pin to configure. BMI330_INT_NONE is ignored.
configDrive strength, polarity and enable.
Returns
::ksfTkErrOk on success.

◆ setMotionConfig()

sfTkError_t sfDevBMI330::setMotionConfig ( uint8_t  baseAddr,
const sfe_bmi330_motion_config_t &  config 
)
protected

Shared implementation for the any-motion and no-motion configuration writers.

Parameters
baseAddrBMI330_FEAT_ADDR_ANY_MOTION or BMI330_FEAT_ADDR_NO_MOTION.
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setNoMotionConfig()

sfTkError_t sfDevBMI330::setNoMotionConfig ( const sfe_bmi330_motion_config_t &  config)

Write the no-motion detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setOrientationConfig()

sfTkError_t sfDevBMI330::setOrientationConfig ( const sfe_bmi330_orientation_config_t &  config)

Write the orientation detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setSigMotionConfig()

sfTkError_t sfDevBMI330::setSigMotionConfig ( const sfe_bmi330_sig_motion_config_t &  config)

Write the significant motion detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setStepCounterWatermark()

sfTkError_t sfDevBMI330::setStepCounterWatermark ( uint16_t  watermark)

Set how many steps trigger the step counter interrupt.

The count is in units of 20 steps: a watermark of 1 interrupts every 20 steps. Zero disables the watermark interrupt while leaving the counter running, which is what a sketch that polls getStepCount() wants.

Parameters
watermarkWatermark in units of 20 steps. Range 0 to 1023.
Returns
::ksfTkErrOk on success.

◆ setTapConfig()

sfTkError_t sfDevBMI330::setTapConfig ( const sfe_bmi330_tap_config_t &  config)

Write the tap detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ setTiltConfig()

sfTkError_t sfDevBMI330::setTiltConfig ( const sfe_bmi330_tilt_config_t &  config)

Write the tilt detector configuration.

Parameters
configDetector settings.
Returns
::ksfTkErrOk on success.

◆ signExtend()

int16_t sfDevBMI330::signExtend ( uint16_t  value,
uint8_t  bits 
)
staticprotected

Sign-extend a right-aligned two's complement field to a full int16_t.

Parameters
valueField value, right-aligned, upper bits zero.
bitsWidth of the field in bits.
Returns
The sign-extended value.

◆ softReset()

sfTkError_t sfDevBMI330::softReset ( void  )

Soft reset the device and restart the feature engine.

Writes the soft-reset command, waits out the 1.5 ms reset time, performs the dummy read that re-selects SPI when on SPI, then runs the feature engine start-up sequence and polls for it to report active. All registers return to their power-on defaults, which means both sensors end up disabled and any configuration is lost.

Note
The cached full-scale ranges used by accelRawToG() and gyroRawToDps() are resynchronized from the device afterwards, so conversions stay correct across a reset.
Returns
::ksfTkErrOk on success, ::ksfTkErrFail if the feature engine does not start.

◆ updateFeatureWord()

sfTkError_t sfDevBMI330::updateFeatureWord ( uint8_t  baseAddr,
uint8_t  wordIndex,
uint16_t  mask,
uint16_t  value 
)
protected

Read-modify-write a bit field of a feature engine word.

Parameters
baseAddrFeature base address.
wordIndexWord offset within the feature block.
maskField mask.
valueField value, already shifted into position.
Returns
::ksfTkErrOk on success.

◆ updateRegister()

sfTkError_t sfDevBMI330::updateRegister ( uint8_t  reg,
uint16_t  mask,
uint16_t  value 
)
protected

Read-modify-write a bit field of a 16-bit register.

Parameters
regRegister address.
maskField mask.
valueField value, already shifted into position.
Returns
::ksfTkErrOk on success.

◆ waitForSelfTestComplete()

sfTkError_t sfDevBMI330::waitForSelfTestComplete ( uint16_t &  featureIO1,
uint16_t  stepDelayMs 
)
protected

Poll FEATURE_IO1 until the self-test / self-calibration completion bit is set.

Parameters
featureIO1Receives the final FEATURE_IO1 word.
stepDelayMsDelay between polls, in milliseconds.
Returns
::ksfTkErrOk if the bit set within the polling window, ::ksfTkErrBusTimeout otherwise.

◆ writeFeatureWords()

sfTkError_t sfDevBMI330::writeFeatureWords ( uint8_t  baseAddr,
const uint16_t *  words,
uint8_t  count 
)

Write consecutive words to feature engine extended memory.

Parameters
baseAddrFeature base address - see sfe_bmi330_feature_addr_t.
wordsSource buffer.
countNumber of words to write. Maximum kMaxBurstWords.
Returns
::ksfTkErrOk on success.

◆ writeRegister()

sfTkError_t sfDevBMI330::writeRegister ( uint8_t  reg,
uint16_t  value 
)

Write one 16-bit register.

Parameters
regRegister address.
valueValue to write.
Returns
::ksfTkErrOk on success.

◆ writeRegisters()

sfTkError_t sfDevBMI330::writeRegisters ( uint8_t  reg,
const uint16_t *  values,
uint8_t  count 
)

Write consecutive 16-bit registers in one transaction.

Parameters
regFirst register address.
valuesSource buffer.
countNumber of words. Maximum kMaxBurstWords.
Returns
::ksfTkErrOk on success.

Member Data Documentation

◆ _accelOffsetMask

uint16_t sfDevBMI330::_accelOffsetMask
protected

Mask for the accelerometer user offset field, set from the silicon revision.

Revision 1 and later carry a 14-bit offset field; earlier silicon carries 13 bits. begin() reads the revision and picks. Using the wrong width writes a bit outside the field and sign-extends reads from the wrong place.

◆ _accelRange

sfe_bmi330_accel_range_t sfDevBMI330::_accelRange
protected

Cached accelerometer range, used by accelRawToG().

◆ _dummyBytes

uint8_t sfDevBMI330::_dummyBytes
protected

Dummy bytes the device prepends to every read: 2 on I2C, 1 on SPI.

◆ _gyroRange

sfe_bmi330_gyro_range_t sfDevBMI330::_gyroRange
protected

Cached gyroscope range, used by gyroRawToDps().

◆ _pendingInt1

uint16_t sfDevBMI330::_pendingInt1
protected

INT1 status bits that setAxisRemap() had to read (and so clear) before its commit.

INT_STATUS_INT1 is clear-on-read. setAxisRemap() captures whatever is pending before it suspends the accelerometer, and the next getInterruptStatus(BMI330_INT1) merges these bits back in, so a remap never swallows a caller's event.

◆ _theBus

sfTkIBus* sfDevBMI330::_theBus
protected

The bus this driver communicates over.

◆ kAccelOffsetMask13

const uint16_t sfDevBMI330::kAccelOffsetMask13 = 0x1FFF
staticprotected

Accelerometer offset, 13-bit (rev 0).

◆ kAccelOffsetMask14

const uint16_t sfDevBMI330::kAccelOffsetMask14 = 0x3FFF
staticprotected

Accelerometer offset, 14-bit (rev 1+).

◆ kAxisMapComplete

const uint16_t sfDevBMI330::kAxisMapComplete = 0x0400
staticprotected

Axis map applied.

◆ kAxisMapRetries

const uint8_t sfDevBMI330::kAxisMapRetries = 10
staticprotected

Axis-map acknowledgement polls before giving up.

◆ kAxisMapStepMs

const uint8_t sfDevBMI330::kAxisMapStepMs = 10
staticprotected

Milliseconds between axis-map acknowledgement polls.

◆ kCmdAxisMapUpdate

const uint16_t sfDevBMI330::kCmdAxisMapUpdate = 0x0300
staticprotected

Commit an axis remap.

◆ kCmdSelfCalibAbort

const uint16_t sfDevBMI330::kCmdSelfCalibAbort = 0x0200
staticprotected

Abort a self-calibration.

◆ kCmdSelfCalibTrigger

const uint16_t sfDevBMI330::kCmdSelfCalibTrigger = 0x0101
staticprotected

Start a gyroscope self-calibration.

◆ kCmdSelfTestTrigger

const uint16_t sfDevBMI330::kCmdSelfTestTrigger = 0x0100
staticprotected

Start a self-test.

◆ kCmdSoftReset

const uint16_t sfDevBMI330::kCmdSoftReset = 0xDEAF
staticprotected

Soft reset.

◆ kConfAvgMask

const uint16_t sfDevBMI330::kConfAvgMask = 0x0700
staticprotected

Averaging, bits 10:8.

◆ kConfAvgShift

const uint8_t sfDevBMI330::kConfAvgShift = 8
staticprotected

Averaging field position.

◆ kConfBwMask

const uint16_t sfDevBMI330::kConfBwMask = 0x0080
staticprotected

Bandwidth, bit 7.

◆ kConfBwShift

const uint8_t sfDevBMI330::kConfBwShift = 7
staticprotected

Bandwidth field position.

◆ kConfModeMask

const uint16_t sfDevBMI330::kConfModeMask = 0x7000
staticprotected

Power mode, bits 14:12.

◆ kConfModeShift

const uint8_t sfDevBMI330::kConfModeShift = 12
staticprotected

Power mode field position.

◆ kConfOdrMask

const uint16_t sfDevBMI330::kConfOdrMask = 0x000F
staticprotected

Output data rate, bits 3:0.

◆ kConfRangeMask

const uint16_t sfDevBMI330::kConfRangeMask = 0x0070
staticprotected

Full-scale range, bits 6:4.

◆ kConfRangeShift

const uint8_t sfDevBMI330::kConfRangeShift = 4
staticprotected

Range field position.

◆ kDummyBytesI2C

const uint8_t sfDevBMI330::kDummyBytesI2C = 2
staticprotected

Dummy bytes prepended to a read on I2C.

◆ kDummyBytesSPI

const uint8_t sfDevBMI330::kDummyBytesSPI = 1
staticprotected

Dummy bytes prepended to a read on SPI.

◆ kErrAccelConf

const uint16_t sfDevBMI330::kErrAccelConf = 0x0020
staticprotected

Unsupported accelerometer configuration.

◆ kErrFatal

const uint16_t sfDevBMI330::kErrFatal = 0x0001
staticprotected

Fatal error.

◆ kErrFeatEngOverload

const uint16_t sfDevBMI330::kErrFeatEngOverload = 0x0004
staticprotected

Feature engine overload.

◆ kErrFeatEngWatchdog

const uint16_t sfDevBMI330::kErrFeatEngWatchdog = 0x0010
staticprotected

Feature engine watchdog.

◆ kErrGyroConf

const uint16_t sfDevBMI330::kErrGyroConf = 0x0040
staticprotected

Unsupported gyroscope configuration.

◆ kEventDoubleTap

const uint16_t sfDevBMI330::kEventDoubleTap = 0x0010
staticprotected

Double tap detected.

◆ kEventFaceDownMask

const uint16_t sfDevBMI330::kEventFaceDownMask = 0x0004
staticprotected

Face down flag.

◆ kEventOrientationMask

const uint16_t sfDevBMI330::kEventOrientationMask = 0x0003
staticprotected

Portrait / landscape classification.

◆ kEventSingleTap

const uint16_t sfDevBMI330::kEventSingleTap = 0x0008
staticprotected

Single tap detected.

◆ kEventTripleTap

const uint16_t sfDevBMI330::kEventTripleTap = 0x0020
staticprotected

Triple tap detected.

◆ kFeatureAddrMask

const uint16_t sfDevBMI330::kFeatureAddrMask = 0x07FF
staticprotected

Address field of FEATURE_DATA_ADDR.

◆ kFeatureEngineEnable

const uint16_t sfDevBMI330::kFeatureEngineEnable = 0x0001
staticprotected

Engine enable / active flag.

◆ kFeatureEngineRetries

const uint8_t sfDevBMI330::kFeatureEngineRetries = 20
staticprotected

Feature engine start-up polls before giving up.

◆ kFeatureEngineStepMs

const uint8_t sfDevBMI330::kFeatureEngineStepMs = 10
staticprotected

Milliseconds between feature engine start-up polls.

◆ kFeatureErrorMask

const uint16_t sfDevBMI330::kFeatureErrorMask = 0x000F
staticprotected

Error nibble in FEATURE_IO1.

◆ kFeatureIOStatusCommit

const uint16_t sfDevBMI330::kFeatureIOStatusCommit = 0x0001
staticprotected

Commit bit for FEATURE_IO0 changes.

◆ kFeatureNoError

const uint16_t sfDevBMI330::kFeatureNoError = 0x0005
staticprotected

Error nibble value meaning "no error".

◆ kFeatureStartupConfig

const uint16_t sfDevBMI330::kFeatureStartupConfig = 0x012C
staticprotected

Start-up value written to FEATURE_IO2.

◆ kFifoAccelInvalid

const uint16_t sfDevBMI330::kFifoAccelInvalid = 0x7F01
staticprotected

Sentinel word written into a FIFO accelerometer slot when the sensor was idle.

◆ kFifoFillLevelMask

const uint16_t sfDevBMI330::kFifoFillLevelMask = 0x07FF
staticprotected

Fill level field.

◆ kFifoFlushMask

const uint16_t sfDevBMI330::kFifoFlushMask = 0x0001
staticprotected

Flush command bit in FIFO_CTRL.

◆ kFifoGyroInvalid

const uint16_t sfDevBMI330::kFifoGyroInvalid = 0x7F02
staticprotected

Sentinel word written into a FIFO gyroscope slot when the sensor was idle.

◆ kFifoSizeWords

const uint16_t sfDevBMI330::kFifoSizeWords = 1024
staticprotected

Words in the FIFO buffer (2048 bytes).

◆ kFifoSourceMask

const uint16_t sfDevBMI330::kFifoSourceMask = 0x0F00
staticprotected

Source enable field.

◆ kFifoStopOnFullMask

const uint16_t sfDevBMI330::kFifoStopOnFullMask = 0x0001
staticprotected

Stop writing when full.

◆ kFifoTempInvalid

const uint16_t sfDevBMI330::kFifoTempInvalid = 0x8000
staticprotected

Sentinel word written into a FIFO temperature slot when the sensor was idle.

◆ kFifoWatermarkMask

const uint16_t sfDevBMI330::kFifoWatermarkMask = 0x03FF
staticprotected

Watermark field.

◆ kFlatBlockingMask

const uint16_t sfDevBMI330::kFlatBlockingMask = 0x00C0
staticprotected

Flat blocking.

◆ kFlatBlockingShift

const uint8_t sfDevBMI330::kFlatBlockingShift = 6
staticprotected

Blocking field position.

◆ kFlatHoldTimeMask

const uint16_t sfDevBMI330::kFlatHoldTimeMask = 0xFF00
staticprotected

Flat hold time.

◆ kFlatHoldTimeShift

const uint8_t sfDevBMI330::kFlatHoldTimeShift = 8
staticprotected

Hold time field position.

◆ kFlatHystMask

const uint16_t sfDevBMI330::kFlatHystMask = 0xFF00
staticprotected

Flat hysteresis.

◆ kFlatHystShift

const uint8_t sfDevBMI330::kFlatHystShift = 8
staticprotected

Hysteresis field position.

◆ kFlatSlopeThresMask

const uint16_t sfDevBMI330::kFlatSlopeThresMask = 0x00FF
staticprotected

Flat slope threshold.

◆ kFlatThetaMask

const uint16_t sfDevBMI330::kFlatThetaMask = 0x003F
staticprotected

Flat theta.

◆ kGyroOffsetMask

const uint16_t sfDevBMI330::kGyroOffsetMask = 0x03FF
staticprotected

Gyroscope offset, 10-bit signed.

◆ kInt1LevelMask

const uint16_t sfDevBMI330::kInt1LevelMask = 0x0001
staticprotected

INT1 polarity, 1 = active high.

◆ kInt1OpenDrainMask

const uint16_t sfDevBMI330::kInt1OpenDrainMask = 0x0002
staticprotected

INT1 open-drain.

◆ kInt1OutputEnMask

const uint16_t sfDevBMI330::kInt1OutputEnMask = 0x0004
staticprotected

INT1 output enable.

◆ kInt2LevelMask

const uint16_t sfDevBMI330::kInt2LevelMask = 0x0100
staticprotected

INT2 polarity, 1 = active high.

◆ kInt2OpenDrainMask

const uint16_t sfDevBMI330::kInt2OpenDrainMask = 0x0200
staticprotected

INT2 open-drain.

◆ kInt2OutputEnMask

const uint16_t sfDevBMI330::kInt2OutputEnMask = 0x0400
staticprotected

INT2 output enable.

◆ kIntLatchMask

const uint16_t sfDevBMI330::kIntLatchMask = 0x0001
staticprotected

Latched interrupt mode.

◆ kMaxBurstWords

const uint8_t sfDevBMI330::kMaxBurstWords = 15
staticprotected

Largest word count a single readRegisters() / writeRegisters() call handles.

Fifteen, not sixteen, and the reason is the transport. A read asks the bus for count * 2 + dummy bytes; the Toolkit's Arduino I2C layer splits anything longer than its 32-byte chunk size into separate transactions, and the BMI330 re-inserts its dummy bytes at the start of every read phase. A split burst would therefore return two dummy bytes in the middle of the payload, shifting everything after them by one word - and, because the byte COUNT still comes out right, reporting success. Fifteen words plus two dummy bytes is exactly 32, which also fits the 32-byte Wire buffer on AVR.

Note
This cap is load-bearing, not slack. readFifoData() packs as many whole frames into a burst as will fit, so an accelerometer-only FIFO reads the full fifteen words at a time. Raising this constant without also raising the bus object's chunk size reintroduces the silent corruption described above.

◆ kMotionAccelRefUpMask

const uint16_t sfDevBMI330::kMotionAccelRefUpMask = 0x1000
staticprotected

Any/no-motion reference update.

◆ kMotionDurationMask

const uint16_t sfDevBMI330::kMotionDurationMask = 0x1FFF
staticprotected

Any/no-motion duration.

◆ kMotionHysteresisMask

const uint16_t sfDevBMI330::kMotionHysteresisMask = 0x03FF
staticprotected

Any/no-motion hysteresis.

◆ kMotionSlopeThresholdMask

const uint16_t sfDevBMI330::kMotionSlopeThresholdMask = 0x0FFF
staticprotected

Any/no-motion slope threshold.

◆ kMotionWaitTimeMask

const uint16_t sfDevBMI330::kMotionWaitTimeMask = 0xE000
staticprotected

Any/no-motion wait time.

◆ kMotionWaitTimeShift

const uint8_t sfDevBMI330::kMotionWaitTimeShift = 13
staticprotected

Wait time field position.

◆ kOrientBlockingMask

const uint16_t sfDevBMI330::kOrientBlockingMask = 0x0018
staticprotected

Orientation blocking.

◆ kOrientBlockingShift

const uint8_t sfDevBMI330::kOrientBlockingShift = 3
staticprotected

Blocking field position.

◆ kOrientHoldTimeMask

const uint16_t sfDevBMI330::kOrientHoldTimeMask = 0xF800
staticprotected

Orientation hold time.

◆ kOrientHoldTimeShift

const uint8_t sfDevBMI330::kOrientHoldTimeShift = 11
staticprotected

Hold time field position.

◆ kOrientHystMask

const uint16_t sfDevBMI330::kOrientHystMask = 0xFF00
staticprotected

Orientation hysteresis.

◆ kOrientHystShift

const uint8_t sfDevBMI330::kOrientHystShift = 8
staticprotected

Hysteresis field position.

◆ kOrientModeMask

const uint16_t sfDevBMI330::kOrientModeMask = 0x0006
staticprotected

Orientation mode.

◆ kOrientModeShift

const uint8_t sfDevBMI330::kOrientModeShift = 1
staticprotected

Orientation mode field position.

◆ kOrientSlopeThresMask

const uint16_t sfDevBMI330::kOrientSlopeThresMask = 0x00FF
staticprotected

Orientation slope threshold.

◆ kOrientThetaMask

const uint16_t sfDevBMI330::kOrientThetaMask = 0x07E0
staticprotected

Orientation theta.

◆ kOrientThetaShift

const uint8_t sfDevBMI330::kOrientThetaShift = 5
staticprotected

Theta field position.

◆ kOrientUdEnMask

const uint16_t sfDevBMI330::kOrientUdEnMask = 0x0001
staticprotected

Orientation face up / down enable.

◆ kRegAccelConf

const uint8_t sfDevBMI330::kRegAccelConf = 0x20
staticprotected

Accelerometer configuration.

◆ kRegAccelDataX

const uint8_t sfDevBMI330::kRegAccelDataX = 0x03
staticprotected

Accelerometer X. Start of the data block.

◆ kRegAccelDpOffX

const uint8_t sfDevBMI330::kRegAccelDpOffX = 0x60
staticprotected

Accelerometer X user offset.

◆ kRegAltAccelConf

const uint8_t sfDevBMI330::kRegAltAccelConf = 0x28
staticprotected

Alternate accelerometer configuration.

◆ kRegAltGyroConf

const uint8_t sfDevBMI330::kRegAltGyroConf = 0x29
staticprotected

Alternate gyroscope configuration.

◆ kRegChipId

const uint8_t sfDevBMI330::kRegChipId = 0x00
staticprotected

Chip and revision ID.

◆ kRegCmd

const uint8_t sfDevBMI330::kRegCmd = 0x7E
staticprotected

Command register.

◆ kRegErrReg

const uint8_t sfDevBMI330::kRegErrReg = 0x01
staticprotected

Error flags.

◆ kRegFeatureCtrl

const uint8_t sfDevBMI330::kRegFeatureCtrl = 0x40
staticprotected

Feature engine enable.

◆ kRegFeatureDataAddr

const uint8_t sfDevBMI330::kRegFeatureDataAddr = 0x41
staticprotected

Feature memory address window.

◆ kRegFeatureDataTx

const uint8_t sfDevBMI330::kRegFeatureDataTx = 0x42
staticprotected

Feature memory data port. Auto-increments.

◆ kRegFeatureEventExt

const uint8_t sfDevBMI330::kRegFeatureEventExt = 0x47
staticprotected

Orientation and tap event outputs.

◆ kRegFeatureIO0

const uint8_t sfDevBMI330::kRegFeatureIO0 = 0x10
staticprotected

Feature enable bits.

◆ kRegFeatureIO1

const uint8_t sfDevBMI330::kRegFeatureIO1 = 0x11
staticprotected

Feature engine status and errors.

◆ kRegFeatureIO2

const uint8_t sfDevBMI330::kRegFeatureIO2 = 0x12
staticprotected

Step count low word / start-up config.

◆ kRegFeatureIO3

const uint8_t sfDevBMI330::kRegFeatureIO3 = 0x13
staticprotected

Step count high word / start-up config.

◆ kRegFeatureIOStatus

const uint8_t sfDevBMI330::kRegFeatureIOStatus = 0x14
staticprotected

Commit register for FEATURE_IO0 changes.

◆ kRegFifoConf

const uint8_t sfDevBMI330::kRegFifoConf = 0x36
staticprotected

FIFO source enables and stop-on-full.

◆ kRegFifoCtrl

const uint8_t sfDevBMI330::kRegFifoCtrl = 0x37
staticprotected

FIFO flush.

◆ kRegFifoData

const uint8_t sfDevBMI330::kRegFifoData = 0x16
staticprotected

FIFO read port. Does not auto-increment.

◆ kRegFifoFillLevel

const uint8_t sfDevBMI330::kRegFifoFillLevel = 0x15
staticprotected

FIFO fill level, in words.

◆ kRegFifoWatermark

const uint8_t sfDevBMI330::kRegFifoWatermark = 0x35
staticprotected

FIFO watermark, in words.

◆ kRegGyroConf

const uint8_t sfDevBMI330::kRegGyroConf = 0x21
staticprotected

Gyroscope configuration.

◆ kRegGyroDataX

const uint8_t sfDevBMI330::kRegGyroDataX = 0x06
staticprotected

Gyroscope X.

◆ kRegGyroDpOffX

const uint8_t sfDevBMI330::kRegGyroDpOffX = 0x66
staticprotected

Gyroscope X user offset.

◆ kRegIntConf

const uint8_t sfDevBMI330::kRegIntConf = 0x39
staticprotected

Interrupt latch mode.

◆ kRegIntMap1

const uint8_t sfDevBMI330::kRegIntMap1 = 0x3A
staticprotected

Interrupt routing, feature sources.

◆ kRegIntMap2

const uint8_t sfDevBMI330::kRegIntMap2 = 0x3B
staticprotected

Interrupt routing, data and FIFO sources.

◆ kRegIntStatusInt1

const uint8_t sfDevBMI330::kRegIntStatusInt1 = 0x0D
staticprotected

INT1 status. Clear-on-read.

◆ kRegIntStatusInt2

const uint8_t sfDevBMI330::kRegIntStatusInt2 = 0x0E
staticprotected

INT2 status. Clear-on-read.

◆ kRegIoIntCtrl

const uint8_t sfDevBMI330::kRegIoIntCtrl = 0x38
staticprotected

Interrupt pin electrical configuration.

◆ kRegSatFlags

const uint8_t sfDevBMI330::kRegSatFlags = 0x0C
staticprotected

Per-axis saturation flags.

◆ kRegSensorTime0

const uint8_t sfDevBMI330::kRegSensorTime0 = 0x0A
staticprotected

Sensor time, low word.

◆ kRegStatus

const uint8_t sfDevBMI330::kRegStatus = 0x02
staticprotected

Data ready and POR flags. Clear-on-read.

◆ kRegTempData

const uint8_t sfDevBMI330::kRegTempData = 0x09
staticprotected

Temperature.

◆ kRemapAxisMask

const uint16_t sfDevBMI330::kRemapAxisMask = 0x0007
staticprotected

Axis permutation.

◆ kRemapXSignMask

const uint16_t sfDevBMI330::kRemapXSignMask = 0x0008
staticprotected

Invert X.

◆ kRemapYSignMask

const uint16_t sfDevBMI330::kRemapYSignMask = 0x0010
staticprotected

Invert Y.

◆ kRemapZSignMask

const uint16_t sfDevBMI330::kRemapZSignMask = 0x0020
staticprotected

Invert Z.

◆ kSatAccelX

const uint16_t sfDevBMI330::kSatAccelX = 0x0001
staticprotected

Accelerometer X saturated.

◆ kSatAccelY

const uint16_t sfDevBMI330::kSatAccelY = 0x0002
staticprotected

Accelerometer Y saturated.

◆ kSatAccelZ

const uint16_t sfDevBMI330::kSatAccelZ = 0x0004
staticprotected

Accelerometer Z saturated.

◆ kSatGyroX

const uint16_t sfDevBMI330::kSatGyroX = 0x0008
staticprotected

Gyroscope X saturated.

◆ kSatGyroY

const uint16_t sfDevBMI330::kSatGyroY = 0x0010
staticprotected

Gyroscope Y saturated.

◆ kSatGyroZ

const uint16_t sfDevBMI330::kSatGyroZ = 0x0020
staticprotected

Gyroscope Z saturated.

◆ kScResult

const uint16_t sfDevBMI330::kScResult = 0x0020
staticprotected

Gyroscope self-calibration result.

◆ kScStComplete

const uint16_t sfDevBMI330::kScStComplete = 0x0010
staticprotected

Self-test / self-calibration complete.

◆ kSelfCalibStepMs

const uint8_t sfDevBMI330::kSelfCalibStepMs = 43
staticprotected

Milliseconds between self-calibration completion polls.

◆ kSelfTestRetries

const uint8_t sfDevBMI330::kSelfTestRetries = 10
staticprotected

Completion polls before a self-test or self-calibration is declared timed out.

◆ kSelfTestStepMs

const uint8_t sfDevBMI330::kSelfTestStepMs = 35
staticprotected

Milliseconds between self-test completion polls.

◆ kSigMcrMaxMask

const uint16_t sfDevBMI330::kSigMcrMaxMask = 0xFC00
staticprotected

Significant motion maximum crossing rate.

◆ kSigMcrMaxShift

const uint8_t sfDevBMI330::kSigMcrMaxShift = 10
staticprotected

Maximum crossing rate field position.

◆ kSigMcrMinMask

const uint16_t sfDevBMI330::kSigMcrMinMask = 0xFC00
staticprotected

Significant motion minimum crossing rate.

◆ kSigMcrMinShift

const uint8_t sfDevBMI330::kSigMcrMinShift = 10
staticprotected

Minimum crossing rate field position.

◆ kSigP2pMaxMask

const uint16_t sfDevBMI330::kSigP2pMaxMask = 0x03FF
staticprotected

Significant motion maximum peak-to-peak.

◆ kSigP2pMinMask

const uint16_t sfDevBMI330::kSigP2pMinMask = 0x03FF
staticprotected

Significant motion minimum peak-to-peak.

◆ kSoftResetDelayMs

const uint8_t sfDevBMI330::kSoftResetDelayMs = 2
staticprotected

Milliseconds to wait after a soft reset before touching the device.

◆ kStatusAccelDrdy

const uint16_t sfDevBMI330::kStatusAccelDrdy = 0x0080
staticprotected

Accelerometer data ready.

◆ kStatusGyroDrdy

const uint16_t sfDevBMI330::kStatusGyroDrdy = 0x0040
staticprotected

Gyroscope data ready.

◆ kStatusTempDrdy

const uint16_t sfDevBMI330::kStatusTempDrdy = 0x0020
staticprotected

Temperature data ready.

◆ kStepResetCounterMask

const uint16_t sfDevBMI330::kStepResetCounterMask = 0x0400
staticprotected

Step counter reset bit.

◆ kStepWatermarkMask

const uint16_t sfDevBMI330::kStepWatermarkMask = 0x03FF
staticprotected

Step counter watermark.

◆ kStResult

const uint16_t sfDevBMI330::kStResult = 0x0040
staticprotected

Self-test result.

◆ kTapAxisMask

const uint16_t sfDevBMI330::kTapAxisMask = 0x0003
staticprotected

Tap axis selection.

◆ kTapMaxDurBwPeaksMask

const uint16_t sfDevBMI330::kTapMaxDurBwPeaksMask = 0x000F
staticprotected

Tap maximum duration between peaks.

◆ kTapMaxGestDurMask

const uint16_t sfDevBMI330::kTapMaxGestDurMask = 0xFC00
staticprotected

Tap maximum gesture duration.

◆ kTapMaxGestDurShift

const uint8_t sfDevBMI330::kTapMaxGestDurShift = 10
staticprotected

Gesture duration field position.

◆ kTapMaxPeaksMask

const uint16_t sfDevBMI330::kTapMaxPeaksMask = 0x0038
staticprotected

Tap maximum peaks.

◆ kTapMaxPeaksShift

const uint8_t sfDevBMI330::kTapMaxPeaksShift = 3
staticprotected

Maximum peaks field position.

◆ kTapMinQuietDurMask

const uint16_t sfDevBMI330::kTapMinQuietDurMask = 0x0F00
staticprotected

Tap minimum quiet duration.

◆ kTapMinQuietDurShift

const uint8_t sfDevBMI330::kTapMinQuietDurShift = 8
staticprotected

Minimum quiet field position.

◆ kTapModeMask

const uint16_t sfDevBMI330::kTapModeMask = 0x00C0
staticprotected

Tap mode.

◆ kTapModeShift

const uint8_t sfDevBMI330::kTapModeShift = 6
staticprotected

Mode field position.

◆ kTapPeakThresMask

const uint16_t sfDevBMI330::kTapPeakThresMask = 0x03FF
staticprotected

Tap peak threshold.

◆ kTapQuietAfterGestMask

const uint16_t sfDevBMI330::kTapQuietAfterGestMask = 0xF000
staticprotected

Tap quiet time after gesture.

◆ kTapQuietAfterGestShift

const uint8_t sfDevBMI330::kTapQuietAfterGestShift = 12
staticprotected

Quiet after gesture field position.

◆ kTapShockSettDurMask

const uint16_t sfDevBMI330::kTapShockSettDurMask = 0x00F0
staticprotected

Tap shock settling duration.

◆ kTapShockSettDurShift

const uint8_t sfDevBMI330::kTapShockSettDurShift = 4
staticprotected

Shock settling field position.

◆ kTapWaitTimeoutMask

const uint16_t sfDevBMI330::kTapWaitTimeoutMask = 0x0004
staticprotected

Tap wait-for-timeout.

◆ kTiltMinAngleMask

const uint16_t sfDevBMI330::kTiltMinAngleMask = 0xFF00
staticprotected

Tilt minimum angle.

◆ kTiltMinAngleShift

const uint8_t sfDevBMI330::kTiltMinAngleShift = 8
staticprotected

Minimum angle field position.

◆ kTiltSegmentSizeMask

const uint16_t sfDevBMI330::kTiltSegmentSizeMask = 0x00FF
staticprotected

Tilt reference segment size.


The documentation for this class was generated from the following files: