Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/SparkFun_BMI270_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BMI270::BMI270()
/// @brief Checks whether sensor is connected, initializes sensor, then sets
/// default config parameters
/// @return Error code (0 is success, negative is failure, positive is warning)
int8_t BMI270::begin()
int8_t BMI270::begin(bool skip_reset)
{
// Variable to track errors returned by API calls
int8_t err = BMI2_OK;
Expand All @@ -22,7 +22,7 @@ int8_t BMI270::begin()
sensor.read_write_len = 32;

// Initialize the sensor
err = bmi270_init(&sensor);
err = bmi270_init(&sensor, skip_reset ? 1 : 0);
if(err != BMI2_OK) return err;

// Enable the accelerometer and gyroscope
Expand Down Expand Up @@ -50,7 +50,7 @@ int8_t BMI270::begin()
/// @param address I2C address of sensor
/// @param wirePort I2C port to use for communication, defaults to Wire
/// @return Error code (0 is success, negative is failure, positive is warning)
int8_t BMI270::beginI2C(uint8_t address, TwoWire& wirePort)
int8_t BMI270::beginI2C(uint8_t address, TwoWire& wirePort, bool skip_reset)
{
// Check whether address is valid option
if(address != BMI2_I2C_PRIM_ADDR && address != BMI2_I2C_SEC_ADDR)
Expand All @@ -68,15 +68,15 @@ int8_t BMI270::beginI2C(uint8_t address, TwoWire& wirePort)
interfaceData.interface = BMI2_I2C_INTF;

// Initialize sensor
return begin();
return begin(skip_reset);
}

/// @brief Begin communication with the sensor over SPI, initialize it, and set
/// default config parameters
/// @param csPin Chip select pin of sensor
/// @param clockFrequency SPI clock frequency
/// @return Error code (0 is success, negative is failure, positive is warning)
int8_t BMI270::beginSPI(uint8_t csPin, uint32_t clockFrequency)
int8_t BMI270::beginSPI(uint8_t csPin, uint32_t clockFrequency, bool skip_reset)
{
// Set up chip select pin
interfaceData.spiCSPin = csPin;
Expand All @@ -93,7 +93,7 @@ int8_t BMI270::beginSPI(uint8_t csPin, uint32_t clockFrequency)
sensor.dummy_byte = 1;

// Initialize sensor
return begin();
return begin(skip_reset);
}

/// @brief Performs a soft reset of the sensor
Expand Down Expand Up @@ -385,7 +385,7 @@ int8_t BMI270::enableAdvancedPowerSave(bool enable)
{
return bmi2_set_adv_power_save(BMI2_DISABLE, &sensor);
}

}

/// @brief Disables advanced power save mode
Expand Down Expand Up @@ -664,7 +664,7 @@ int8_t BMI270::setFIFOConfig(BMI270_FIFOConfig config)
// Set flag bits
err = setFIFOFlags(config.flags, BMI2_ENABLE);
if(err != BMI2_OK) return err;

// Clear unused flag bits
err = setFIFOFlags(~config.flags, BMI2_DISABLE);
if(err != BMI2_OK) return err;
Expand Down Expand Up @@ -727,7 +727,7 @@ int8_t BMI270::setFIFOFlags(uint16_t flags, bool enable)
{
fifoConfigFlags &= ~flags;
}

// Compute number of bytes per FIFO frame
bytesPerFIFOData = 0;
bytesPerFIFOData += ((fifoConfigFlags & BMI2_FIFO_ACC_EN) != 0) * 6;
Expand Down Expand Up @@ -827,13 +827,13 @@ int8_t BMI270::extractFIFOData(BMI270_SensorData* data, bmi2_fifo_frame* fifoDat
// Sensor is disabled in FIFO, just return
return BMI2_OK;
}

// Variable to track errors returned by API calls
int8_t err = BMI2_OK;

// Create buffer to hold raw data
bmi2_sens_axes_data* rawData = (bmi2_sens_axes_data*) malloc((*numFrames) * sizeof(bmi2_sens_axes_data));

// Extract raw data from the FIFO data
if(sensorSelect == BMI2_ACCEL)
{
Expand All @@ -848,7 +848,7 @@ int8_t BMI270::extractFIFOData(BMI270_SensorData* data, bmi2_fifo_frame* fifoDat
free(rawData);
return err;
}

// Convert raw data
for(int i = 0; i < (*numFrames); i++)
{
Expand All @@ -861,7 +861,7 @@ int8_t BMI270::extractFIFOData(BMI270_SensorData* data, bmi2_fifo_frame* fifoDat
convertRawGyroData(&(rawData[i]), &(data[i]));
}
}

free(rawData);
return err;
}
Expand Down Expand Up @@ -944,7 +944,7 @@ int8_t BMI270::getStepCount(uint32_t* count)
featureData.type = BMI2_STEP_COUNTER;
err = getFeatureData(&featureData);
if(err) return err;

*count = featureData.sens_data.step_counter_output;
return BMI2_OK;
}
Expand Down Expand Up @@ -1002,7 +1002,7 @@ int8_t BMI270::getStepActivity(uint8_t* activity)
featureData.type = BMI2_STEP_ACTIVITY;
err = getFeatureData(&featureData);
if(err) return err;

*activity = featureData.sens_data.activity_output;
return BMI2_OK;
}
Expand All @@ -1026,7 +1026,7 @@ int8_t BMI270::getWristGesture(uint8_t* gesture)
featureData.type = BMI2_WRIST_GESTURE;
err = getFeatureData(&featureData);
if(err) return err;

*gesture = featureData.sens_data.wrist_gesture_output;
return BMI2_OK;
}
Expand Down Expand Up @@ -1284,7 +1284,7 @@ BMI2_INTF_RETURN_TYPE BMI270::writeRegistersI2C(uint8_t regAddress, const uint8_

// Write the address
interfaceData->i2cPort->write(regAddress);

// Write all the data
for(uint32_t i = 0; i < numBytes; i++)
{
Expand All @@ -1311,10 +1311,10 @@ BMI2_INTF_RETURN_TYPE BMI270::writeRegistersSPI(uint8_t regAddress, const uint8_
// Begin transmission
SPI.beginTransaction(SPISettings(interfaceData->spiClockFrequency, MSBFIRST, SPI_MODE0));
digitalWrite(interfaceData->spiCSPin, LOW);

// Write the address
SPI.transfer(regAddress);

// Write all the data
for(uint32_t i = 0; i < numBytes; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions src/SparkFun_BMI270_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class BMI270
BMI270();

// Sensor initialization, must specify communication interface
int8_t beginI2C(uint8_t address = BMI2_I2C_PRIM_ADDR, TwoWire& wirePort = Wire);
int8_t beginSPI(uint8_t csPin, uint32_t clockFrequency = 100000);
int8_t beginI2C(uint8_t address = BMI2_I2C_PRIM_ADDR, TwoWire& wirePort = Wire, bool skip_reset = false);
int8_t beginSPI(uint8_t csPin, uint32_t clockFrequency = 100000, bool skip_reset = false);

// Sensor control
int8_t reset();
Expand Down Expand Up @@ -231,7 +231,7 @@ class BMI270

private:
// Sensor initialization, after communication interface has been selected
int8_t begin();
int8_t begin(bool skip_reset = false);

// Convert from raw data (bmi2_sens_data) to g's (BMI270_SensorData)
void convertRawAccelData(bmi2_sens_axes_data* rawData, BMI270_SensorData* data);
Expand Down
7 changes: 7 additions & 0 deletions src/bmi270_api/bmi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1880,6 +1880,11 @@ static int8_t validate_foc_accel_axis(int16_t avg_foc_data, struct bmi2_dev *dev
* chip-id of the sensor.
*/
int8_t bmi2_sec_init(struct bmi2_dev *dev)
{
return bmi2_sec_init_with_opt(dev, 0);
}

int8_t bmi2_sec_init_with_opt(struct bmi2_dev *dev, uint8_t skip_reset)
{
/* Variable to define error */
int8_t rslt;
Expand Down Expand Up @@ -1928,6 +1933,8 @@ int8_t bmi2_sec_init(struct bmi2_dev *dev)
*/
dev->remap = axes_remap;

if (skip_reset) return BMI2_OK;

/* Perform soft-reset to bring all register values to their
* default values
*/
Expand Down
2 changes: 2 additions & 0 deletions src/bmi270_api/bmi2.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ extern "C" {
*/
int8_t bmi2_sec_init(struct bmi2_dev *dev);

int8_t bmi2_sec_init_with_opt(struct bmi2_dev *dev, uint8_t skip_reset);

/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_set_spi_en bmi2_set_spi_en
Expand Down
4 changes: 2 additions & 2 deletions src/bmi270_api/bmi270.c
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ static int8_t disable_sensor_features(uint64_t sensor_sel, struct bmi2_dev *dev)
* 4) Updates the feature offset parameters in the device structure.
* 5) Updates the maximum number of pages, in the device structure.
*/
int8_t bmi270_init(struct bmi2_dev *dev)
int8_t bmi270_init(struct bmi2_dev *dev, uint8_t skip_reset)
{
/* Variable to define error */
int8_t rslt;
Expand Down Expand Up @@ -1389,7 +1389,7 @@ int8_t bmi270_init(struct bmi2_dev *dev)
}

/* Initialize BMI2 sensor */
rslt = bmi2_sec_init(dev);
rslt = bmi2_sec_init_with_opt(dev, skip_reset);
if (rslt == BMI2_OK)
{
/* Assign the offsets of the feature input
Expand Down
2 changes: 1 addition & 1 deletion src/bmi270_api/bmi270.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extern "C" {
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi270_init(struct bmi2_dev *dev);
int8_t bmi270_init(struct bmi2_dev *dev, uint8_t skip_reset);

/**
* \ingroup bmi270
Expand Down