Skip to content

Commit

Permalink
[SensorBHI260AP] Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jan 28, 2025
1 parent ca7c6b6 commit 6c881fe
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 104,174 deletions.
77 changes: 56 additions & 21 deletions examples/BHI260AP_6DoF/BHI260AP_6DoF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,47 @@
#define BHI260_RST -1
#endif


SensorBHI260AP bhy;

// The firmware runs in RAM and will be lost if the power is off. The firmware will be loaded from RAM each time it is run.
#define BOSCH_APP30_SHUTTLE_BHI260_FW
// #define BOSCH_APP30_SHUTTLE_BHI260_AUX_BMM150FW
// #define BOSCH_APP30_SHUTTLE_BHI260_BME68X
// #define BOSCH_APP30_SHUTTLE_BHI260_BMP390
// #define BOSCH_APP30_SHUTTLE_BHI260_TURBO
// #define BOSCH_BHI260_AUX_BEM280
// #define BOSCH_BHI260_AUX_BMM150_BEM280
// #define BOSCH_BHI260_AUX_BMM150_BEM280_GPIO
// #define BOSCH_BHI260_AUX_BMM150_GPIO
// #define BOSCH_BHI260_GPIO

// Firmware is stored in flash and booted from flash,Depends on BHI260 hardware connected to SPI Flash
// #define BOSCH_APP30_SHUTTLE_BHI260_AUX_BMM150_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_BME68X_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_BMP390_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_TURBO_FLASH
// #define BOSCH_BHI260_AUX_BEM280_FLASH
// #define BOSCH_BHI260_AUX_BMM150_BEM280_FLASH
// #define BOSCH_BHI260_AUX_BMM150_BEM280_GPIO_FLASH
// #define BOSCH_BHI260_AUX_BMM150_GPIO_FLASH
// #define BOSCH_BHI260_GPIO_FLASH

#include <BoschFirmware.h>

// Force update of current firmware, whether it exists or not.
// Only works when external SPI Flash is connected to BHI260.
// After uploading firmware once, you can change this to false to speed up boot time.
bool force_update_spi_firmware = true;

bool isReadyFlag = false;

void dataReadyISR()
{
isReadyFlag = true;
}


void accel_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
void data_ready_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
{
struct bhy2_data_xyz data;
float scaling_factor = get_sensor_default_scaling(sensor_id);
Expand All @@ -106,21 +135,14 @@ void accel_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len,
);
}


void gyro_process_callback(uint8_t sensor_id, uint8_t *data_ptr, uint32_t len, uint64_t *timestamp)
// Firmware update progress callback
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
struct bhy2_data_xyz data;
float scaling_factor = get_sensor_default_scaling(sensor_id);
bhy2_parse_xyz(data_ptr, &data);
Serial.print(bhy.getSensorName(sensor_id));
Serial.print(":");
Serial.printf("x: %f, y: %f, z: %f;\r\n",
data.x * scaling_factor,
data.y * scaling_factor,
data.z * scaling_factor
);
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
}


void setup()
{
Serial.begin(115200);
Expand All @@ -131,9 +153,23 @@ void setup()

Serial.println("Initializing Sensors...");

/*Set the default firmware, only 6 axes, no other functions*/
bhy.setFirmware(bhy2_firmware_image, sizeof(bhy2_firmware_image));
// Set the firmware array address and firmware size
bhy.setFirmware(bosch_firmware_image, bosch_firmware_size, bosch_firmware_type, force_update_spi_firmware);

// Set the firmware update processing progress callback function
// bhy.setUpdateProcessCallback(progress_callback, NULL);

// Set the maximum transfer bytes of I2C/SPI,The default size is I2C 32 bytes, SPI 256 bytes.
// bhy.setMaxiTransferSize(256);

// Set the processing fifo data buffer size,The default size is 512 bytes.
// bhy.setProcessBufferSize(1024);

// Set to load firmware from flash
bhy.setBootFromFlash(bosch_firmware_type);

Serial.println("Initializing Sensors...");

#ifdef USE_I2C_INTERFACE
// Using I2C interface
// BHI260AP_SLAVE_ADDRESS_L = 0x28
Expand Down Expand Up @@ -164,7 +200,7 @@ void setup()
BoschSensorInfo info = bhy.getSensorInfo();
info.printInfo(Serial);

float sample_rate = 100.0; /* Read out hintr_ctrl measured at 100Hz */
float sample_rate = 100.0; /* Read out data measured at 100Hz */
uint32_t report_latency_ms = 0; /* Report immediately */

// Enable acceleration
Expand All @@ -173,10 +209,9 @@ void setup()
bhy.configure(SENSOR_ID_GYRO_PASS, sample_rate, report_latency_ms);

// Set the acceleration sensor result callback function
bhy.onResultEvent(SENSOR_ID_ACC_PASS, accel_process_callback);

bhy.onResultEvent(SENSOR_ID_ACC_PASS, data_ready_callback);
// Set the gyroscope sensor result callback function
bhy.onResultEvent(SENSOR_ID_GYRO_PASS, gyro_process_callback);
bhy.onResultEvent(SENSOR_ID_GYRO_PASS, data_ready_callback);

// Register interrupt function
pinMode(BHI260_IRQ, INPUT);
Expand Down
110 changes: 75 additions & 35 deletions examples/BHI260AP_Expand_GPIO/BHI260AP_Expand_GPIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,6 @@
Commander cmd;
void initialiseCommander();

/*
Example firmware source: https://github.com/boschsensortec/BHY2_SensorAPI/tree/master/firmware
You can also compile custom firmware to write
How to build custom firmware see : https://www.bosch-sensortec.com/media/boschsensortec/downloads/application_notes_1/bst-bhi260ab-an000.pdf
*/

#include "BHI260AP_GPIO.fw.h"
// Custom firmware with GPIO input and output functions
const uint8_t *firmware = bhy2_gpio_firmware_image;
const size_t fw_size = sizeof(bhy2_gpio_firmware_image);

/*
* GPIO Comparison Table
* M1SCX = N.A ! INVALID PIN
* M1SDX = N.A ! INVALID PIN
* M1SDI = N.A ! INVALID PIN
* M2SCX = 14 ! OK
* M2SDX = 15 ! OK
* M2SDI = 16 ! OK
* MCSB1 = 1 ! OK
* MCSB2 = 4 ! OK
* M3SCL = 17 ! OK
* M3SDA = 18 ! OK
* MCSB3 = 5 ! OK
* MCSB4 = 6 ! OK
* JTAG_CLK = 19 ! OK
* JTAG_DIO = 20 ! OK
* RESV1 = 2 ! INVALID PIN
* RESV2 = 3 ! INVALID PIN
* RESV3 = N.A ! INVALID PIN
* */

// #define USE_I2C_INTERFACE true
// #define USE_SPI_INTERFACE true

Expand Down Expand Up @@ -118,26 +86,78 @@ const size_t fw_size = sizeof(bhy2_gpio_firmware_image);

SensorBHI260AP bhy;

// The firmware runs in RAM and will be lost if the power is off. The firmware will be loaded from RAM each time it is run.
// #define BOSCH_APP30_SHUTTLE_BHI260_FW
#define BOSCH_APP30_SHUTTLE_BHI260_AUX_BMM150FW
// #define BOSCH_APP30_SHUTTLE_BHI260_BME68X
// #define BOSCH_APP30_SHUTTLE_BHI260_BMP390
// #define BOSCH_APP30_SHUTTLE_BHI260_TURBO
// #define BOSCH_BHI260_AUX_BEM280
// #define BOSCH_BHI260_AUX_BMM150_BEM280
// #define BOSCH_BHI260_AUX_BMM150_BEM280_GPIO
// #define BOSCH_BHI260_AUX_BMM150_GPIO
// #define BOSCH_BHI260_GPIO

// Firmware is stored in flash and booted from flash,Depends on BHI260 hardware connected to SPI Flash
// #define BOSCH_APP30_SHUTTLE_BHI260_AUX_BMM150_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_BME68X_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_BMP390_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_FLASH
// #define BOSCH_APP30_SHUTTLE_BHI260_TURBO_FLASH
// #define BOSCH_BHI260_AUX_BEM280_FLASH
// #define BOSCH_BHI260_AUX_BMM150_BEM280_FLASH
// #define BOSCH_BHI260_AUX_BMM150_BEM280_GPIO_FLASH
// #define BOSCH_BHI260_AUX_BMM150_GPIO_FLASH
// #define BOSCH_BHI260_GPIO_FLASH

#include <BoschFirmware.h>

// Force update of current firmware, whether it exists or not.
// Only works when external SPI Flash is connected to BHI260.
// After uploading firmware once, you can change this to false to speed up boot time.
bool force_update_spi_firmware = true;

bool isReadyFlag = false;

void dataReadyISR()
{
isReadyFlag = true;
}

// Firmware update progress callback
void progress_callback(void *user_data, uint32_t total, uint32_t transferred)
{
float progress = (float)transferred / total * 100;
Serial.printf("Upload progress: %.2f%%\n", progress);
}

void setup()
{
Serial.begin(115200);
while (!Serial);

// Set the reset pin
bhy.setPins(BHI260_RST);

Serial.println("Initializing Sensors...");

// Set the firmware array address and firmware size
bhy.setFirmware(firmware, fw_size, false);
// Set to load firmware from RAM
bhy.setBootFromFlash(false);
bhy.setFirmware(bosch_firmware_image, bosch_firmware_size, bosch_firmware_type, force_update_spi_firmware);

// Set the firmware update processing progress callback function
// bhy.setUpdateProcessCallback(progress_callback, NULL);

// Set the maximum transfer bytes of I2C/SPI,The default size is I2C 32 bytes, SPI 256 bytes.
// bhy.setMaxiTransferSize(256);

// Set the processing fifo data buffer size,The default size is 512 bytes.
// bhy.setProcessBufferSize(1024);

// Set to load firmware from flash
bhy.setBootFromFlash(bosch_firmware_type);

Serial.println("Initializing Sensors...");

#ifdef USE_I2C_INTERFACE
// Using I2C interface
// BHI260AP_SLAVE_ADDRESS_L = 0x28
Expand Down Expand Up @@ -221,6 +241,26 @@ bool helpHandler(Commander &Cmdr)
return 0;
}

/*
* GPIO Comparison Table
* M1SCX = N.A ! INVALID PIN
* M1SDX = N.A ! INVALID PIN
* M1SDI = N.A ! INVALID PIN
* M2SCX = 14 ! OK
* M2SDX = 15 ! OK
* M2SDI = 16 ! OK
* MCSB1 = 1 ! OK
* MCSB2 = 4 ! OK
* M3SCL = 17 ! OK
* M3SDA = 18 ! OK
* MCSB3 = 5 ! OK
* MCSB4 = 6 ! OK
* JTAG_CLK = 19 ! OK
* JTAG_DIO = 20 ! OK
* RESV1 = 2 ! INVALID PIN
* RESV2 = 3 ! INVALID PIN
* RESV3 = N.A ! INVALID PIN
* */
bool setGpioLevel(Commander &Cmdr)
{
int values[2] = {0, 0};
Expand Down
Loading

0 comments on commit 6c881fe

Please sign in to comment.