Skip to content

Commit

Permalink
bmi323: format
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Nov 4, 2023
1 parent d31221c commit 14563d0
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 161 deletions.
82 changes: 40 additions & 42 deletions src/driver/spi_bmi323.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,70 @@
#include "driver/time.h"
#include "util/util.h"


#ifdef USE_GYRO

#define SPI_SPEED_SLOW MHZ_TO_HZ(4)
#define SPI_SPEED_FAST MHZ_TO_HZ(10)

extern spi_bus_device_t gyro_bus;

static int8_t gyro_cas=0;// not ready
static int8_t gyro_cas = 0; // not ready

static void bmi323_reset_to_spi(){
// put the device in spi mode by toggeling CS
static void bmi323_reset_to_spi() {
// put the device in spi mode by toggeling CS
gpio_pin_reset(gyro_bus.nss);
time_delay_ms(1);
gpio_pin_set(gyro_bus.nss);
time_delay_ms(10);
}

uint8_t bmi323_detect(){
bmi323_reset_to_spi();

const uint8_t whoami=bmi3_read8(BMI323_REG_CHIP_ID);
switch (whoami)
{
case BMI323_WHO_AMI:
/* code */
return GYRO_TYPE_BMI323;

default:
return GYRO_TYPE_INVALID;
}
}
uint8_t bmi323_detect() {
bmi323_reset_to_spi();

const uint8_t whoami = bmi3_read8(BMI323_REG_CHIP_ID);
switch (whoami) {
case BMI323_WHO_AMI:
return GYRO_TYPE_BMI323;

static void bmi323_init(){
bmi323_reset_to_spi();
bmi3_write16(BMI323_REG_CMD,BMI323_CMD_SOFT_RESET,100);
bmi323_reset_to_spi();
default:
return GYRO_TYPE_INVALID;
}
}

static void bmi323_init() {
bmi323_reset_to_spi();
bmi3_write16(BMI323_REG_CMD, BMI323_CMD_SOFT_RESET, 100);
bmi323_reset_to_spi();
}

static void bmi323_init_config(){
//init acc conf
uint16_t regdata=0;
regdata= BMI3_ACC_BW_ODR_QUARTER<<7|BMI323_ACC_RANGE_16G<<4|BMI323_ACC_ODR_6400HZ;
regdata|=BMI3_ACC_MODE_HIGH_PERF<<12| BMI323_ACC_AVG1<<8;
bmi3_write16(BMI323_REG_ACC_CONF,regdata,1);
regdata=0;
//init gyro conf
regdata=BMI323_GYR_BW_ODR_QUARTER<<7|BMI323_GYR_RANGE_2000DPS<<4|BMI323_GYR_ODR_6400HZ;
regdata|=BMI323_GYR_MODE_HIGH_PERF<<12|BMI323_GYR_AVG1<<8;
bmi3_write16(BMI323_REG_GYRO_CONF,regdata,1);
//init data ready interupt to pin int1/ push_pull /active_high NO_LATCH(default)
//BMI323_REG_IO_INT_CTRL push_pull/active_high
bmi3_write8(BMI323_REG_IO_INT_CTRL,BMI3_INT_OUTPUT_ENABLE<<2|BMI3_INT_PUSH_PULL<<1|BMI3_INT_ACTIVE_HIGH,1);
//BMI323_REG_INT_MAP2 accready /gyro_ready
regdata=0;
regdata= 0x01<<10 | 0x01<<8;
bmi3_write16(BMI323_REG_INT_MAP2,regdata,15);
static void bmi323_init_config() {
// init acc conf
uint16_t regdata = 0;
regdata = BMI3_ACC_BW_ODR_QUARTER << 7 | BMI323_ACC_RANGE_16G << 4 | BMI323_ACC_ODR_6400HZ;
regdata |= BMI3_ACC_MODE_HIGH_PERF << 12 | BMI323_ACC_AVG1 << 8;
bmi3_write16(BMI323_REG_ACC_CONF, regdata, 1);

// init gyro conf
regdata = 0;
regdata = BMI323_GYR_BW_ODR_QUARTER << 7 | BMI323_GYR_RANGE_2000DPS << 4 | BMI323_GYR_ODR_6400HZ;
regdata |= BMI323_GYR_MODE_HIGH_PERF << 12 | BMI323_GYR_AVG1 << 8;
bmi3_write16(BMI323_REG_GYRO_CONF, regdata, 1);

// init data ready interupt to pin int1/ push_pull /active_high NO_LATCH(default)
// BMI323_REG_IO_INT_CTRL push_pull/active_high
bmi3_write8(BMI323_REG_IO_INT_CTRL, BMI3_INT_OUTPUT_ENABLE << 2 | BMI3_INT_PUSH_PULL << 1 | BMI3_INT_ACTIVE_HIGH, 1);

// BMI323_REG_INT_MAP2 accready /gyro_ready
regdata = 0;
regdata = 0x01 << 10 | 0x01 << 8;
bmi3_write16(BMI323_REG_INT_MAP2, regdata, 15);
}

void bmi323_configure() {
bmi323_init();
// skip CRT for now
bmi323_init_config();
// bmi323_enable_cas();
// bmi323_enable_cas();
}

uint8_t bmi3_read8(uint8_t reg) {
Expand Down Expand Up @@ -185,5 +184,4 @@ void bmi323_read_gyro_data(gyro_data_t *data) {
data->temp = 0;
}


#endif
Loading

0 comments on commit 14563d0

Please sign in to comment.