![]() |
SparkFun BMI330 Arduino Library
v1.0.0-2-gdbddb99
Arduino Library for the SparkFun Qwiic BMI330 6-DoF IMU (Bosch BMI330)
|
Platform-independent driver for the Bosch BMI330 6-DoF IMU. More...
#include <sfDevBMI330.h>
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... | |
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.
|
inline |
Default constructor.
The device is not touched until begin().
|
inlinevirtual |
| float sfDevBMI330::accelRawToG | ( | int16_t | raw | ) |
Convert a raw accelerometer count to g using the cached range.
| raw | Raw 16-bit signed count. |
|
static |
Sensitivity of a given accelerometer range, in LSB per g.
| range | Full-scale range. |
| 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.
| theBus | Bus to communicate over. Pass nullptr to keep a bus set earlier. |
| sfTkError_t sfDevBMI330::enableAccel | ( | bool | enable = true | ) |
Turn the accelerometer on in high-performance mode, or off.
| enable | true for high-performance mode, false to disable the sensor. |
| 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.
| features | Bitwise OR of sfe_bmi330_feature_t values. |
| enable | true to set those bits, false to clear them. |
| 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.
| sfTkError_t sfDevBMI330::enableGyro | ( | bool | enable = true | ) |
Turn the gyroscope on in high-performance mode, or off.
| enable | true for high-performance mode, false to disable the sensor. |
| sfTkError_t sfDevBMI330::flushFifo | ( | void | ) |
Discard everything in the FIFO.
|
static |
Words per FIFO frame for a given set of sources.
| sources | Bitwise OR of sfe_bmi330_fifo_source_t values. |
| 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.
| mode | Receives the power mode. |
| odr | Receives the output data rate. |
| range | Receives the full-scale range. |
| bandwidth | Receives the filter setting. |
| averaging | Receives the averaging setting. |
| sfTkError_t sfDevBMI330::getAccelData | ( | sfe_bmi330_data_t & | data | ) |
Read just the accelerometer, converted to g.
| data | Receives the acceleration. |
| sfTkError_t sfDevBMI330::getAccelDataRaw | ( | sfe_bmi330_raw_data_t & | data | ) |
Read just the accelerometer, in raw counts.
| data | Receives the raw acceleration. |
| sfTkError_t sfDevBMI330::getAccelOffset | ( | int16_t & | x, |
| int16_t & | y, | ||
| int16_t & | z | ||
| ) |
Read the accelerometer user offsets.
| x | Receives the X axis offset. |
| y | Receives the Y axis offset. |
| z | Receives the Z axis offset. |
|
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.
| sfTkError_t sfDevBMI330::getAnyMotionConfig | ( | sfe_bmi330_motion_config_t & | config | ) |
Read the any-motion detector configuration.
| config | Receives the settings. |
| sfTkError_t sfDevBMI330::getAxisRemap | ( | sfe_bmi330_axis_remap_t & | remap | ) |
Read the current axis remapping.
| remap | Receives the permutation and sign flips. |
| sfTkError_t sfDevBMI330::getChipID | ( | uint8_t & | chipId, |
| uint8_t & | revId | ||
| ) |
Read the chip and revision IDs from CHIP_ID (0x00).
| chipId | Receives the chip ID - 0x48 for a BMI330, 0x43 for a BMI323. |
| revId | Receives the silicon revision from the upper nibble. |
| sfTkError_t sfDevBMI330::getDataReady | ( | bool & | accelReady, |
| bool & | gyroReady, | ||
| bool & | tempReady | ||
| ) |
Read the STATUS register (0x02) data-ready flags.
| accelReady | Receives the accelerometer data-ready flag. |
| gyroReady | Receives the gyroscope data-ready flag. |
| tempReady | Receives the temperature data-ready flag. |
| sfTkError_t sfDevBMI330::getEnabledFeatures | ( | uint16_t & | features | ) |
Read which features are currently enabled.
| features | Receives the FEATURE_IO0 word. |
| sfTkError_t sfDevBMI330::getErrorStatus | ( | sfe_bmi330_error_status_t & | status | ) |
Read and decode ERR_REG (0x01).
| status | Receives the decoded error flags. |
| 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.
| status | Receives the register word. |
| bool sfDevBMI330::getFeatureEngineStatus | ( | void | ) |
Check whether the feature engine is running.
| sfTkError_t sfDevBMI330::getFifoConfig | ( | uint16_t & | sources, |
| bool & | stopOnFull | ||
| ) |
Read back the configured FIFO sources and full behavior.
| sources | Receives the enabled source bits. |
| stopOnFull | Receives the stop-on-full setting. |
| sfTkError_t sfDevBMI330::getFifoFillLevel | ( | uint16_t & | words | ) |
Read how many words the FIFO currently holds.
| words | Receives the fill level in words. The buffer holds 1024 words (2 kB). |
| sfTkError_t sfDevBMI330::getFifoWatermark | ( | uint16_t & | words | ) |
Read the FIFO watermark, in words.
| words | Receives the watermark level. |
| sfTkError_t sfDevBMI330::getFlatConfig | ( | sfe_bmi330_flat_config_t & | config | ) |
Read the flat detector configuration.
| config | Receives the settings. |
| 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).
| mode | Receives the power mode. |
| odr | Receives the output data rate. |
| range | Receives the full-scale range. |
| bandwidth | Receives the filter setting. |
| averaging | Receives the averaging setting. |
| sfTkError_t sfDevBMI330::getGyroData | ( | sfe_bmi330_data_t & | data | ) |
Read just the gyroscope, converted to degrees per second.
| data | Receives the angular rate. |
| sfTkError_t sfDevBMI330::getGyroDataRaw | ( | sfe_bmi330_raw_data_t & | data | ) |
Read just the gyroscope, in raw counts.
| data | Receives the raw angular rate. |
| sfTkError_t sfDevBMI330::getGyroOffset | ( | int16_t & | x, |
| int16_t & | y, | ||
| int16_t & | z | ||
| ) |
Read the gyroscope user offsets.
| x | Receives the X axis offset. |
| y | Receives the Y axis offset. |
| z | Receives the Z axis offset. |
|
inline |
Get the cached gyroscope full-scale range.
| sfTkError_t sfDevBMI330::getInterruptStatus | ( | sfe_bmi330_int_pin_t | pin, |
| uint16_t & | status | ||
| ) |
Read and clear a pin's interrupt status word.
| pin | Which pin's status to read. |
| status | Receives the status word. |
|
protected |
Shared implementation for the any-motion and no-motion configuration readers.
| baseAddr | BMI330_FEAT_ADDR_ANY_MOTION or BMI330_FEAT_ADDR_NO_MOTION. |
| config | Receives the settings. |
| sfTkError_t sfDevBMI330::getNoMotionConfig | ( | sfe_bmi330_motion_config_t & | config | ) |
Read the no-motion detector configuration.
| config | Receives the settings. |
| sfTkError_t sfDevBMI330::getOrientation | ( | sfe_bmi330_orientation_t & | orientation, |
| bool & | faceDown | ||
| ) |
Read the current orientation classification.
| orientation | Receives the portrait / landscape classification. |
| faceDown | Receives the face-down flag. Meaningful only with face up / down enabled. |
| sfTkError_t sfDevBMI330::getOrientationConfig | ( | sfe_bmi330_orientation_config_t & | config | ) |
Read the orientation detector configuration.
| config | Receives the settings. |
| sfTkError_t sfDevBMI330::getSaturationFlags | ( | sfe_bmi330_saturation_t & | flags | ) |
Read and decode the per-axis saturation flags in SAT_FLAGS (0x0C).
| flags | Receives the decoded flags. |
| 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.
| data | Receives the reading. |
| 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).
| sensorTime | Receives the timestamp. |
| sfTkError_t sfDevBMI330::getSigMotionConfig | ( | sfe_bmi330_sig_motion_config_t & | config | ) |
Read the significant motion detector configuration.
| config | Receives the settings. |
| 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.
| steps | Receives the step count. |
| sfTkError_t sfDevBMI330::getStepCounterWatermark | ( | uint16_t & | watermark | ) |
Read the step counter watermark.
| watermark | Receives the watermark, in units of 20 steps. |
| sfTkError_t sfDevBMI330::getTapConfig | ( | sfe_bmi330_tap_config_t & | config | ) |
Read the tap detector configuration.
| config | Receives the settings. |
| 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).
| event | Receives the gesture flags. |
| sfTkError_t sfDevBMI330::getTemperature | ( | float & | celsius | ) |
Read the die temperature in degrees Celsius.
| celsius | Receives the temperature. |
| sfTkError_t sfDevBMI330::getTiltConfig | ( | sfe_bmi330_tilt_config_t & | config | ) |
Read the tilt detector configuration.
| config | Receives the settings. |
| float sfDevBMI330::gyroRawToDps | ( | int16_t | raw | ) |
Convert a raw gyroscope count to degrees per second using the cached range.
| raw | Raw 16-bit signed count. |
|
static |
Sensitivity of a given gyroscope range, in LSB per degree per second.
| range | Full-scale range. |
| bool sfDevBMI330::isConnected | ( | void | ) |
Check that a BMI330 is responding.
| 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.
| source | The source to route. |
| pin | Destination pin, or BMI330_INT_NONE to disconnect. |
| 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.
| selection | What to correct. |
| applyCorrection | true to have the device apply the result to its output immediately. |
| result | Receives the outcome. |
result for the verdict. | 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.
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.| selection | Which sensors to test. |
| result | Receives the outcome. |
result for the verdict.
|
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.
|
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.
| raw | Raw 16-bit signed count. |
| sfTkError_t sfDevBMI330::readFeatureWords | ( | uint8_t | baseAddr, |
| uint16_t * | words, | ||
| uint8_t | count | ||
| ) |
Read consecutive words from feature engine extended memory.
| baseAddr | Feature base address - see sfe_bmi330_feature_addr_t. |
| words | Destination buffer. |
| count | Number of words to read. Maximum kMaxBurstWords. |
| 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.
| frames | Destination array. |
| maxFrames | Capacity of frames. |
| numFrames | Receives the number of frames actually decoded. |
| sources | The same source bits that were passed to setFifoConfig(). The FIFO is headerless, so the parser cannot work this out on its own. |
| 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.
| words | Destination buffer, at least count words. |
| count | Number of words to read. |
|
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.
| words | Destination buffer. |
| count | Number of words. Maximum kMaxBurstWords. |
| sfTkError_t sfDevBMI330::readRegister | ( | uint8_t | reg, |
| uint16_t & | value | ||
| ) |
Read one 16-bit register, dummy bytes handled.
| reg | Register address. |
| value | Receives the register contents. |
| sfTkError_t sfDevBMI330::readRegisters | ( | uint8_t | reg, |
| uint16_t * | values, | ||
| uint8_t | count | ||
| ) |
Read consecutive 16-bit registers in one transaction, dummy bytes handled.
| reg | First register address. |
| values | Destination buffer. |
| count | Number of words. Maximum kMaxBurstWords. |
| 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.
| sfTkError_t sfDevBMI330::sendCommand | ( | uint16_t | command | ) |
Send a command through the CMD register (0x7E).
| command | Command word. |
| sfTkError_t sfDevBMI330::setAccelAveraging | ( | sfe_bmi330_averaging_t | averaging | ) |
Set the accelerometer hardware averaging.
| averaging | Samples to average. |
| sfTkError_t sfDevBMI330::setAccelBandwidth | ( | sfe_bmi330_bandwidth_t | bandwidth | ) |
Set the accelerometer filter bandwidth.
| bandwidth | Cutoff as a fraction of ODR. |
| 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.
| mode | Power mode. |
| odr | Output data rate. |
| range | Full-scale range. |
| bandwidth | Filter cutoff as a fraction of ODR. |
| averaging | Hardware averaging. |
| sfTkError_t sfDevBMI330::setAccelMode | ( | sfe_bmi330_accel_mode_t | mode | ) |
Set the accelerometer power mode, leaving the rest of ACC_CONF alone.
| mode | Power mode. |
| sfTkError_t sfDevBMI330::setAccelODR | ( | sfe_bmi330_odr_t | odr | ) |
Set the accelerometer output data rate.
| odr | Output data rate. |
| 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.
| x | X axis offset, 14-bit signed. |
| y | Y axis offset, 14-bit signed. |
| z | Z axis offset, 14-bit signed. |
| sfTkError_t sfDevBMI330::setAccelRange | ( | sfe_bmi330_accel_range_t | range | ) |
Set the accelerometer full-scale range.
| range | Full-scale range. |
| sfTkError_t sfDevBMI330::setAnyMotionConfig | ( | const sfe_bmi330_motion_config_t & | config | ) |
Write the any-motion detector configuration.
| config | Detector settings. |
| 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.
| remap | Axis permutation and sign flips. |
| 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.
| theBus | Bus to use for communication. |
| sfTkError_t sfDevBMI330::setFifoConfig | ( | uint16_t | sources, |
| bool | stopOnFull = false |
||
| ) |
Choose what the FIFO records, and what it does when full.
| sources | Bitwise OR of sfe_bmi330_fifo_source_t values. Zero disables the FIFO. |
| stopOnFull | true to stop writing when full (keep the oldest data), false to overwrite the oldest data and keep the newest. |
| 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.
| words | Watermark level in words. Range 0 to 1023. |
| sfTkError_t sfDevBMI330::setFlatConfig | ( | const sfe_bmi330_flat_config_t & | config | ) |
Write the flat detector configuration.
| config | Detector settings. |
| sfTkError_t sfDevBMI330::setGyroAveraging | ( | sfe_bmi330_averaging_t | averaging | ) |
Set the gyroscope hardware averaging.
| averaging | Samples to average. |
| sfTkError_t sfDevBMI330::setGyroBandwidth | ( | sfe_bmi330_bandwidth_t | bandwidth | ) |
Set the gyroscope filter bandwidth.
| bandwidth | Cutoff as a fraction of ODR. |
| 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.
| mode | Power mode. |
| odr | Output data rate. |
| range | Full-scale range. |
| bandwidth | Filter cutoff as a fraction of ODR. |
| averaging | Hardware averaging. |
| sfTkError_t sfDevBMI330::setGyroMode | ( | sfe_bmi330_gyro_mode_t | mode | ) |
Set the gyroscope power mode, leaving the rest of GYR_CONF alone.
| mode | Power mode. |
| sfTkError_t sfDevBMI330::setGyroODR | ( | sfe_bmi330_odr_t | odr | ) |
Set the gyroscope output data rate.
| odr | Output data rate. |
| 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.
| x | X axis offset, 10-bit signed. |
| y | Y axis offset, 10-bit signed. |
| z | Z axis offset, 10-bit signed. |
| sfTkError_t sfDevBMI330::setGyroRange | ( | sfe_bmi330_gyro_range_t | range | ) |
Set the gyroscope full-scale range.
| range | Full-scale range. |
| 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.
| latched | true to latch until the status register is read. |
| 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.
| pin | Which pin to configure. BMI330_INT_NONE is ignored. |
| config | Drive strength, polarity and enable. |
|
protected |
Shared implementation for the any-motion and no-motion configuration writers.
| baseAddr | BMI330_FEAT_ADDR_ANY_MOTION or BMI330_FEAT_ADDR_NO_MOTION. |
| config | Detector settings. |
| sfTkError_t sfDevBMI330::setNoMotionConfig | ( | const sfe_bmi330_motion_config_t & | config | ) |
Write the no-motion detector configuration.
| config | Detector settings. |
| sfTkError_t sfDevBMI330::setOrientationConfig | ( | const sfe_bmi330_orientation_config_t & | config | ) |
Write the orientation detector configuration.
| config | Detector settings. |
| sfTkError_t sfDevBMI330::setSigMotionConfig | ( | const sfe_bmi330_sig_motion_config_t & | config | ) |
Write the significant motion detector configuration.
| config | Detector settings. |
| 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.
| watermark | Watermark in units of 20 steps. Range 0 to 1023. |
| sfTkError_t sfDevBMI330::setTapConfig | ( | const sfe_bmi330_tap_config_t & | config | ) |
Write the tap detector configuration.
| config | Detector settings. |
| sfTkError_t sfDevBMI330::setTiltConfig | ( | const sfe_bmi330_tilt_config_t & | config | ) |
Write the tilt detector configuration.
| config | Detector settings. |
|
staticprotected |
Sign-extend a right-aligned two's complement field to a full int16_t.
| value | Field value, right-aligned, upper bits zero. |
| bits | Width of the field in bits. |
| 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.
|
protected |
Read-modify-write a bit field of a feature engine word.
| baseAddr | Feature base address. |
| wordIndex | Word offset within the feature block. |
| mask | Field mask. |
| value | Field value, already shifted into position. |
|
protected |
Read-modify-write a bit field of a 16-bit register.
| reg | Register address. |
| mask | Field mask. |
| value | Field value, already shifted into position. |
|
protected |
Poll FEATURE_IO1 until the self-test / self-calibration completion bit is set.
| featureIO1 | Receives the final FEATURE_IO1 word. |
| stepDelayMs | Delay between polls, in milliseconds. |
| sfTkError_t sfDevBMI330::writeFeatureWords | ( | uint8_t | baseAddr, |
| const uint16_t * | words, | ||
| uint8_t | count | ||
| ) |
Write consecutive words to feature engine extended memory.
| baseAddr | Feature base address - see sfe_bmi330_feature_addr_t. |
| words | Source buffer. |
| count | Number of words to write. Maximum kMaxBurstWords. |
| sfTkError_t sfDevBMI330::writeRegister | ( | uint8_t | reg, |
| uint16_t | value | ||
| ) |
Write one 16-bit register.
| reg | Register address. |
| value | Value to write. |
| sfTkError_t sfDevBMI330::writeRegisters | ( | uint8_t | reg, |
| const uint16_t * | values, | ||
| uint8_t | count | ||
| ) |
Write consecutive 16-bit registers in one transaction.
| reg | First register address. |
| values | Source buffer. |
| count | Number of words. Maximum kMaxBurstWords. |
|
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.
|
protected |
Cached accelerometer range, used by accelRawToG().
|
protected |
Dummy bytes the device prepends to every read: 2 on I2C, 1 on SPI.
|
protected |
Cached gyroscope range, used by gyroRawToDps().
|
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.
|
protected |
The bus this driver communicates over.
|
staticprotected |
Accelerometer offset, 13-bit (rev 0).
|
staticprotected |
Accelerometer offset, 14-bit (rev 1+).
|
staticprotected |
Axis map applied.
|
staticprotected |
Axis-map acknowledgement polls before giving up.
|
staticprotected |
Milliseconds between axis-map acknowledgement polls.
|
staticprotected |
Commit an axis remap.
|
staticprotected |
Abort a self-calibration.
|
staticprotected |
Start a gyroscope self-calibration.
|
staticprotected |
Start a self-test.
|
staticprotected |
Soft reset.
|
staticprotected |
Averaging, bits 10:8.
|
staticprotected |
Averaging field position.
|
staticprotected |
Bandwidth, bit 7.
|
staticprotected |
Bandwidth field position.
|
staticprotected |
Power mode, bits 14:12.
|
staticprotected |
Power mode field position.
|
staticprotected |
Output data rate, bits 3:0.
|
staticprotected |
Full-scale range, bits 6:4.
|
staticprotected |
Range field position.
|
staticprotected |
Dummy bytes prepended to a read on I2C.
|
staticprotected |
Dummy bytes prepended to a read on SPI.
|
staticprotected |
Unsupported accelerometer configuration.
|
staticprotected |
Fatal error.
|
staticprotected |
Feature engine overload.
|
staticprotected |
Feature engine watchdog.
|
staticprotected |
Unsupported gyroscope configuration.
|
staticprotected |
Double tap detected.
|
staticprotected |
Face down flag.
|
staticprotected |
Portrait / landscape classification.
|
staticprotected |
Single tap detected.
|
staticprotected |
Triple tap detected.
|
staticprotected |
Address field of FEATURE_DATA_ADDR.
|
staticprotected |
Engine enable / active flag.
|
staticprotected |
Feature engine start-up polls before giving up.
|
staticprotected |
Milliseconds between feature engine start-up polls.
|
staticprotected |
Error nibble in FEATURE_IO1.
|
staticprotected |
Commit bit for FEATURE_IO0 changes.
|
staticprotected |
Error nibble value meaning "no error".
|
staticprotected |
Start-up value written to FEATURE_IO2.
|
staticprotected |
Sentinel word written into a FIFO accelerometer slot when the sensor was idle.
|
staticprotected |
Fill level field.
|
staticprotected |
Flush command bit in FIFO_CTRL.
|
staticprotected |
Sentinel word written into a FIFO gyroscope slot when the sensor was idle.
|
staticprotected |
Words in the FIFO buffer (2048 bytes).
|
staticprotected |
Source enable field.
|
staticprotected |
Stop writing when full.
|
staticprotected |
Sentinel word written into a FIFO temperature slot when the sensor was idle.
|
staticprotected |
Watermark field.
|
staticprotected |
Flat blocking.
|
staticprotected |
Blocking field position.
|
staticprotected |
Flat hold time.
|
staticprotected |
Hold time field position.
|
staticprotected |
Flat hysteresis.
|
staticprotected |
Hysteresis field position.
|
staticprotected |
Flat slope threshold.
|
staticprotected |
Flat theta.
|
staticprotected |
Gyroscope offset, 10-bit signed.
|
staticprotected |
INT1 polarity, 1 = active high.
|
staticprotected |
INT1 open-drain.
|
staticprotected |
INT1 output enable.
|
staticprotected |
INT2 polarity, 1 = active high.
|
staticprotected |
INT2 open-drain.
|
staticprotected |
INT2 output enable.
|
staticprotected |
Latched interrupt mode.
|
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.
|
staticprotected |
Any/no-motion reference update.
|
staticprotected |
Any/no-motion duration.
|
staticprotected |
Any/no-motion hysteresis.
|
staticprotected |
Any/no-motion slope threshold.
|
staticprotected |
Any/no-motion wait time.
|
staticprotected |
Wait time field position.
|
staticprotected |
Orientation blocking.
|
staticprotected |
Blocking field position.
|
staticprotected |
Orientation hold time.
|
staticprotected |
Hold time field position.
|
staticprotected |
Orientation hysteresis.
|
staticprotected |
Hysteresis field position.
|
staticprotected |
Orientation mode.
|
staticprotected |
Orientation mode field position.
|
staticprotected |
Orientation slope threshold.
|
staticprotected |
Orientation theta.
|
staticprotected |
Theta field position.
|
staticprotected |
Orientation face up / down enable.
|
staticprotected |
Accelerometer configuration.
|
staticprotected |
Accelerometer X. Start of the data block.
|
staticprotected |
Accelerometer X user offset.
|
staticprotected |
Alternate accelerometer configuration.
|
staticprotected |
Alternate gyroscope configuration.
|
staticprotected |
Chip and revision ID.
|
staticprotected |
Command register.
|
staticprotected |
Error flags.
|
staticprotected |
Feature engine enable.
|
staticprotected |
Feature memory address window.
|
staticprotected |
Feature memory data port. Auto-increments.
|
staticprotected |
Orientation and tap event outputs.
|
staticprotected |
Feature enable bits.
|
staticprotected |
Feature engine status and errors.
|
staticprotected |
Step count low word / start-up config.
|
staticprotected |
Step count high word / start-up config.
|
staticprotected |
Commit register for FEATURE_IO0 changes.
|
staticprotected |
FIFO source enables and stop-on-full.
|
staticprotected |
FIFO flush.
|
staticprotected |
FIFO read port. Does not auto-increment.
|
staticprotected |
FIFO fill level, in words.
|
staticprotected |
FIFO watermark, in words.
|
staticprotected |
Gyroscope configuration.
|
staticprotected |
Gyroscope X.
|
staticprotected |
Gyroscope X user offset.
|
staticprotected |
Interrupt latch mode.
|
staticprotected |
Interrupt routing, feature sources.
|
staticprotected |
Interrupt routing, data and FIFO sources.
|
staticprotected |
INT1 status. Clear-on-read.
|
staticprotected |
INT2 status. Clear-on-read.
|
staticprotected |
Interrupt pin electrical configuration.
|
staticprotected |
Per-axis saturation flags.
|
staticprotected |
Sensor time, low word.
|
staticprotected |
Data ready and POR flags. Clear-on-read.
|
staticprotected |
Temperature.
|
staticprotected |
Axis permutation.
|
staticprotected |
Invert X.
|
staticprotected |
Invert Y.
|
staticprotected |
Invert Z.
|
staticprotected |
Accelerometer X saturated.
|
staticprotected |
Accelerometer Y saturated.
|
staticprotected |
Accelerometer Z saturated.
|
staticprotected |
Gyroscope X saturated.
|
staticprotected |
Gyroscope Y saturated.
|
staticprotected |
Gyroscope Z saturated.
|
staticprotected |
Gyroscope self-calibration result.
|
staticprotected |
Self-test / self-calibration complete.
|
staticprotected |
Milliseconds between self-calibration completion polls.
|
staticprotected |
Completion polls before a self-test or self-calibration is declared timed out.
|
staticprotected |
Milliseconds between self-test completion polls.
|
staticprotected |
Significant motion maximum crossing rate.
|
staticprotected |
Maximum crossing rate field position.
|
staticprotected |
Significant motion minimum crossing rate.
|
staticprotected |
Minimum crossing rate field position.
|
staticprotected |
Significant motion maximum peak-to-peak.
|
staticprotected |
Significant motion minimum peak-to-peak.
|
staticprotected |
Milliseconds to wait after a soft reset before touching the device.
|
staticprotected |
Accelerometer data ready.
|
staticprotected |
Gyroscope data ready.
|
staticprotected |
Temperature data ready.
|
staticprotected |
Step counter reset bit.
|
staticprotected |
Step counter watermark.
|
staticprotected |
Self-test result.
|
staticprotected |
Tap axis selection.
|
staticprotected |
Tap maximum duration between peaks.
|
staticprotected |
Tap maximum gesture duration.
|
staticprotected |
Gesture duration field position.
|
staticprotected |
Tap maximum peaks.
|
staticprotected |
Maximum peaks field position.
|
staticprotected |
Tap minimum quiet duration.
|
staticprotected |
Minimum quiet field position.
|
staticprotected |
Tap mode.
|
staticprotected |
Mode field position.
|
staticprotected |
Tap peak threshold.
|
staticprotected |
Tap quiet time after gesture.
|
staticprotected |
Quiet after gesture field position.
|
staticprotected |
Tap shock settling duration.
|
staticprotected |
Shock settling field position.
|
staticprotected |
Tap wait-for-timeout.
|
staticprotected |
Tilt minimum angle.
|
staticprotected |
Minimum angle field position.
|
staticprotected |
Tilt reference segment size.