add gyro
Some checks failed
Some checks failed
This commit is contained in:
@ -91,7 +91,7 @@ int main(void)
|
||||
uint8_t ppt;
|
||||
uint8_t font_width;
|
||||
uint8_t font_height;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_x, accel_y, accel_z, accel_z_ref, humidity;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_x, accel_y, accel_z, accel_z_ref, gyro_x, gyro_y, gyro_z, humidity;
|
||||
|
||||
char str_v[15] = {0};
|
||||
char str_i[15] = {0};
|
||||
@ -101,6 +101,9 @@ int main(void)
|
||||
char str_ay[16] = {0};
|
||||
char str_az[16] = {0};
|
||||
char str_az_ref[16] = {0};
|
||||
char str_gx[16] = {0};
|
||||
char str_gy[16] = {0};
|
||||
char str_gz[16] = {0};
|
||||
char str_h[16] = {0};
|
||||
|
||||
LOG_INF("Starting Mellifera version %s...", APP_VERSION_STRING);
|
||||
@ -227,10 +230,10 @@ int main(void)
|
||||
{
|
||||
LOG_ERR("Could not get pressure");
|
||||
}
|
||||
// if (sensor_channel_get(baro, SENSOR_CHAN_AMBIENT_TEMP, &temperature) < 0)
|
||||
// {
|
||||
// LOG_ERR("Could not get temperature");
|
||||
// }
|
||||
if (sensor_channel_get(baro, SENSOR_CHAN_AMBIENT_TEMP, &temperature) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get temperature");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(imu) < 0)
|
||||
{
|
||||
@ -252,6 +255,18 @@ int main(void)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration");
|
||||
}
|
||||
if (sensor_channel_get(imu, SENSOR_CHAN_GYRO_X, &gyro_x) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
if (sensor_channel_get(imu, SENSOR_CHAN_GYRO_Y, &gyro_y) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
if (sensor_channel_get(imu, SENSOR_CHAN_GYRO_Z, &gyro_z) < 0)
|
||||
{
|
||||
LOG_ERR("Could not get gyro");
|
||||
}
|
||||
|
||||
if (sensor_sample_fetch(lis) < 0)
|
||||
{
|
||||
@ -279,31 +294,34 @@ int main(void)
|
||||
sprintf(str_i, "I :%7.5f", current.val1 + current.val2 * 1e-6);
|
||||
sprintf(str_p, "P :%7.4f", pressure.val1 + pressure.val2 * 1e-6);
|
||||
sprintf(str_t, "T :%7.4f", temperature.val1 + temperature.val2 * 1e-6);
|
||||
sprintf(str_ax, "X :%+7.3f", accel_x.val1 + accel_x.val2 * 1e-6);
|
||||
sprintf(str_ay, "Y :%+7.3f", accel_y.val1 + accel_y.val2 * 1e-6);
|
||||
sprintf(str_az, "Z :%+7.3f", accel_z.val1 + accel_z.val2 * 1e-6);
|
||||
sprintf(str_ax, "AX:%+7.3f", accel_x.val1 + accel_x.val2 * 1e-6);
|
||||
sprintf(str_ay, "AY:%+7.3f", accel_y.val1 + accel_y.val2 * 1e-6);
|
||||
sprintf(str_az, "AZ:%+7.3f", accel_z.val1 + accel_z.val2 * 1e-6);
|
||||
sprintf(str_gx, "GX:%+7.3f", gyro_x.val1 + gyro_x.val2 * 1e-6);
|
||||
sprintf(str_gy, "GY:%+7.3f", gyro_y.val1 + gyro_y.val2 * 1e-6);
|
||||
sprintf(str_gz, "GZ:%+7.3f", gyro_z.val1 + gyro_z.val2 * 1e-6);
|
||||
sprintf(str_az_ref, "Zr:%+7.3f", accel_z_ref.val1 + accel_z_ref.val2 * 1e-6);
|
||||
sprintf(str_h, "H :%7.3f", humidity.val1 + humidity.val2 * 1e-6);
|
||||
|
||||
// LOG_INF("%s\t%s\t%s\t%s", str_v, str_i, str_p, str_t);
|
||||
|
||||
cfb_framebuffer_clear(display, false);
|
||||
if (cfb_print(display, str_t, 0, 0))
|
||||
if (cfb_print(display, str_gx, 0, 0))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_h, 0, 16))
|
||||
if (cfb_print(display, str_gy, 0, 16))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_gz, 0, 16 * 2))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
if (cfb_print(display, str_ax, 0, 16 * 3))
|
||||
{
|
||||
LOG_ERR("Failed to print a string");
|
||||
}
|
||||
// if (cfb_print(display, str_az, 0, 16 * 2))
|
||||
// {
|
||||
// LOG_ERR("Failed to print a string");
|
||||
// }
|
||||
// if (cfb_print(display, str_az_ref, 0, 16 * 3))
|
||||
// {
|
||||
// LOG_ERR("Failed to print a string");
|
||||
// }
|
||||
|
||||
cfb_framebuffer_finalize(display);
|
||||
#if defined(CONFIG_ARCH_POSIX)
|
||||
|
@ -15,29 +15,29 @@
|
||||
LOG_MODULE_REGISTER(bmx055, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
// Accelerometer registers
|
||||
const uint8_t REG_BWG_CHIPID = 0x00;
|
||||
const uint8_t REG_ACCD_X_LSB = 0x02;
|
||||
const uint8_t REG_ACCD_X_MSB = 0x03;
|
||||
const uint8_t REG_ACCD_Y_LSB = 0x04;
|
||||
const uint8_t REG_ACCD_Y_MSB = 0x05;
|
||||
const uint8_t REG_ACCD_Z_LSB = 0x06;
|
||||
const uint8_t REG_ACCD_Z_MSB = 0x07;
|
||||
const uint8_t REG_ACCD_TEMP = 0x08;
|
||||
const uint8_t REG_INT_STATUS_0 = 0x09;
|
||||
const uint8_t REG_INT_STATUS_1 = 0x0A;
|
||||
const uint8_t REG_INT_STATUS_2 = 0x0B;
|
||||
const uint8_t REG_INT_STATUS_3 = 0x0C;
|
||||
const uint8_t REG_FIFO_STATUS = 0x0E;
|
||||
const uint8_t REG_PMU_RANGE = 0x0F;
|
||||
typedef enum pmu_range_t
|
||||
const uint8_t ACCEL_REG_BWG_CHIPID = 0x00;
|
||||
const uint8_t ACCEL_REG_ACCD_X_LSB = 0x02;
|
||||
const uint8_t ACCEL_REG_ACCD_X_MSB = 0x03;
|
||||
const uint8_t ACCEL_REG_ACCD_Y_LSB = 0x04;
|
||||
const uint8_t ACCEL_REG_ACCD_Y_MSB = 0x05;
|
||||
const uint8_t ACCEL_REG_ACCD_Z_LSB = 0x06;
|
||||
const uint8_t ACCEL_REG_ACCD_Z_MSB = 0x07;
|
||||
const uint8_t ACCEL_REG_ACCD_TEMP = 0x08;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_0 = 0x09;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_1 = 0x0A;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_2 = 0x0B;
|
||||
const uint8_t ACCEL_REG_INT_STATUS_3 = 0x0C;
|
||||
const uint8_t ACCEL_REG_FIFO_STATUS = 0x0E;
|
||||
const uint8_t ACCEL_REG_PMU_RANGE = 0x0F;
|
||||
typedef enum accel_pmu_range_t
|
||||
{
|
||||
PMU_RANGE_2G = 0b0011, ///< DEFAULT
|
||||
PMU_RANGE_4G = 0b0101,
|
||||
PMU_RANGE_8G = 0b1000,
|
||||
PMU_RANGE_16G = 0b1100,
|
||||
} pmu_range_t;
|
||||
const uint8_t REG_PMU_BW = 0x10;
|
||||
typedef enum pmu_bw_t
|
||||
} accel_pmu_range_t;
|
||||
const uint8_t ACCEL_REG_PMU_BW = 0x10;
|
||||
typedef enum accel_pmu_bw_t
|
||||
{
|
||||
PMU_BW_8HZ = 0b01000,
|
||||
PMU_BW_16HZ = 0b01001,
|
||||
@ -47,48 +47,115 @@ typedef enum pmu_bw_t
|
||||
PMU_BW_250HZ = 0b01101,
|
||||
PMU_BW_500HZ = 0b01110,
|
||||
PMU_BW_1000HZ = 0b01111,
|
||||
} pmu_bw_t;
|
||||
const uint8_t REG_PMU_LPW = 0x11;
|
||||
const uint8_t REG_PMU_LOW_POWER = 0x12;
|
||||
const uint8_t REG_ACCD_HBW = 0x13;
|
||||
const uint8_t REG_BGW_SOFTRESET = 0x14;
|
||||
const uint8_t BGW_SOFTRESET = 0xB6; ///< Soft reset occurs when this value is written to REG_BGW_SOFTRESET
|
||||
const uint8_t REG_INT_EN_0 = 0x16;
|
||||
const uint8_t REG_INT_EN_1 = 0x17;
|
||||
const uint8_t REG_INT_EN_2 = 0x18;
|
||||
const uint8_t REG_INT_MAP_0 = 0x19;
|
||||
const uint8_t REG_INT_MAP_1 = 0x1A;
|
||||
const uint8_t REG_INT_MAP_2 = 0x1B;
|
||||
const uint8_t REG_INT_SRC = 0x1E;
|
||||
const uint8_t REG_INT_OUT_CTRL = 0x20;
|
||||
const uint8_t REG_INT_RST_LATCH = 0x21;
|
||||
const uint8_t REG_INT_0 = 0x22;
|
||||
const uint8_t REG_INT_1 = 0x23;
|
||||
const uint8_t REG_INT_2 = 0x24;
|
||||
const uint8_t REG_INT_3 = 0x25;
|
||||
const uint8_t REG_INT_4 = 0x26;
|
||||
const uint8_t REG_INT_5 = 0x27;
|
||||
const uint8_t REG_INT_6 = 0x28;
|
||||
const uint8_t REG_INT_7 = 0x29;
|
||||
const uint8_t REG_INT_8 = 0x2A;
|
||||
const uint8_t REG_INT_9 = 0x2B;
|
||||
const uint8_t REG_INT_A = 0x2C;
|
||||
const uint8_t REG_INT_B = 0x2D;
|
||||
const uint8_t REG_INT_C = 0x2E;
|
||||
const uint8_t REG_INT_D = 0x2F;
|
||||
const uint8_t REG_FIFO_CONFIG_0 = 0x30;
|
||||
const uint8_t REG_PMU_SELF_TEST = 0x32;
|
||||
const uint8_t REG_TRIM_NVM_CTRL = 0x33;
|
||||
const uint8_t REG_BGW_SPI3_WDT = 0x34;
|
||||
const uint8_t REG_OFC_CTRL = 0x36;
|
||||
const uint8_t REG_OFC_SETTING = 0x37;
|
||||
const uint8_t REG_OFC_OFFSET_X = 0x38;
|
||||
const uint8_t REG_OFC_OFFSET_Y = 0x39;
|
||||
const uint8_t REG_OFC_OFFSET_Z = 0x3A;
|
||||
const uint8_t REG_TRIM_GP0 = 0x3B;
|
||||
const uint8_t REG_TRIM_GP1 = 0x3C;
|
||||
const uint8_t REG_FIFO_CONFIG_1 = 0x3E;
|
||||
const uint8_t REG_FIFO_DATA = 0x3F;
|
||||
} accel_pmu_bw_t;
|
||||
const uint8_t ACCEL_REG_PMU_LPW = 0x11;
|
||||
const uint8_t ACCEL_REG_PMU_LOW_POWER = 0x12;
|
||||
const uint8_t ACCEL_REG_ACCD_HBW = 0x13;
|
||||
const uint8_t ACCEL_REG_BGW_SOFTRESET = 0x14;
|
||||
const uint8_t BGW_SOFTRESET = 0xB6; ///< Soft reset occurs when this value is written to ACCEL_REG_BGW_SOFTRESET
|
||||
const uint8_t ACCEL_REG_INT_EN_0 = 0x16;
|
||||
const uint8_t ACCEL_REG_INT_EN_1 = 0x17;
|
||||
const uint8_t ACCEL_REG_INT_EN_2 = 0x18;
|
||||
const uint8_t ACCEL_REG_INT_MAP_0 = 0x19;
|
||||
const uint8_t ACCEL_REG_INT_MAP_1 = 0x1A;
|
||||
const uint8_t ACCEL_REG_INT_MAP_2 = 0x1B;
|
||||
const uint8_t ACCEL_REG_INT_SRC = 0x1E;
|
||||
const uint8_t ACCEL_REG_INT_OUT_CTRL = 0x20;
|
||||
const uint8_t ACCEL_REG_INT_RST_LATCH = 0x21;
|
||||
const uint8_t ACCEL_REG_INT_0 = 0x22;
|
||||
const uint8_t ACCEL_REG_INT_1 = 0x23;
|
||||
const uint8_t ACCEL_REG_INT_2 = 0x24;
|
||||
const uint8_t ACCEL_REG_INT_3 = 0x25;
|
||||
const uint8_t ACCEL_REG_INT_4 = 0x26;
|
||||
const uint8_t ACCEL_REG_INT_5 = 0x27;
|
||||
const uint8_t ACCEL_REG_INT_6 = 0x28;
|
||||
const uint8_t ACCEL_REG_INT_7 = 0x29;
|
||||
const uint8_t ACCEL_REG_INT_8 = 0x2A;
|
||||
const uint8_t ACCEL_REG_INT_9 = 0x2B;
|
||||
const uint8_t ACCEL_REG_INT_A = 0x2C;
|
||||
const uint8_t ACCEL_REG_INT_B = 0x2D;
|
||||
const uint8_t ACCEL_REG_INT_C = 0x2E;
|
||||
const uint8_t ACCEL_REG_INT_D = 0x2F;
|
||||
const uint8_t ACCEL_REG_FIFO_CONFIG_0 = 0x30;
|
||||
const uint8_t ACCEL_REG_PMU_SELF_TEST = 0x32;
|
||||
const uint8_t ACCEL_REG_TRIM_NVM_CTRL = 0x33;
|
||||
const uint8_t ACCEL_REG_BGW_SPI3_WDT = 0x34;
|
||||
const uint8_t ACCEL_REG_OFC_CTRL = 0x36;
|
||||
const uint8_t ACCEL_REG_OFC_SETTING = 0x37;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_X = 0x38;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_Y = 0x39;
|
||||
const uint8_t ACCEL_REG_OFC_OFFSET_Z = 0x3A;
|
||||
const uint8_t ACCEL_REG_TRIM_GP0 = 0x3B;
|
||||
const uint8_t ACCEL_REG_TRIM_GP1 = 0x3C;
|
||||
const uint8_t ACCEL_REG_FIFO_CONFIG_1 = 0x3E;
|
||||
const uint8_t ACCEL_REG_FIFO_DATA = 0x3F;
|
||||
|
||||
const uint8_t GYRO_REG_CHIP_ID = 0x00;
|
||||
const uint8_t GYRO_REG_RATE_X_LSB = 0x02;
|
||||
const uint8_t GYRO_REG_RATE_X_MSB = 0x03;
|
||||
const uint8_t GYRO_REG_RATE_Y_LSB = 0x04;
|
||||
const uint8_t GYRO_REG_RATE_Y_MSB = 0x05;
|
||||
const uint8_t GYRO_REG_RATE_Z_LSB = 0x06;
|
||||
const uint8_t GYRO_REG_RATE_Z_MSB = 0x07;
|
||||
const uint8_t GYRO_REG_INT_STATUS_0 = 0x09;
|
||||
const uint8_t GYRO_REG_INT_STATUS_1 = 0x0A;
|
||||
const uint8_t GYRO_REG_INT_STATUS_2 = 0x0B;
|
||||
const uint8_t GYRO_REG_INT_STATUS_3 = 0x0C;
|
||||
const uint8_t GYRO_REG_FIFO_STATUS = 0x0E;
|
||||
const uint8_t GYRO_REG_RANGE = 0x0F;
|
||||
const uint8_t GYRO_REG_BW = 0x10;
|
||||
const uint8_t GYRO_REG_LPM1 = 0x11;
|
||||
const uint8_t GYRO_REG_LPM2 = 0x12;
|
||||
const uint8_t GYRO_REG_RATE_HBW = 0x13;
|
||||
const uint8_t GYRO_REG_BGW_SOFTRESET = 0x14;
|
||||
const uint8_t GYRO_REG_INT_EN_0 = 0x15;
|
||||
const uint8_t GYRO_REG_INT_EN_1 = 0x16;
|
||||
const uint8_t GYRO_REG_INT_MAP_0 = 0x17;
|
||||
const uint8_t GYRO_REG_INT_MAP_1 = 0x18;
|
||||
const uint8_t GYRO_REG_INT_MAP_2 = 0x19;
|
||||
const uint8_t GYRO_REG_INT_SOURCE_1 = 0x1A;
|
||||
const uint8_t GYRO_REG_INT_SOURCE_2 = 0x1B;
|
||||
// const uint8_t GYRO_REG_ = 0x1C;
|
||||
// const uint8_t GYRO_REG_ = 0x1E;
|
||||
const uint8_t GYRO_REG_INT_RST_LATCH = 0x21;
|
||||
const uint8_t GYRO_REG_HIGH_TH_X = 0x22;
|
||||
const uint8_t GYRO_REG_HIGH_DUR_X = 0x23;
|
||||
const uint8_t GYRO_REG_HIGH_TH_Y = 0x24;
|
||||
const uint8_t GYRO_REG_HIGH_DUR_Y = 0x25;
|
||||
const uint8_t GYRO_REG_HIGH_TH_Z = 0x26;
|
||||
const uint8_t GYRO_REG_HIGH_DUR_Z = 0x27;
|
||||
const uint8_t GYRO_REG_SOC = 0x31;
|
||||
const uint8_t GYRO_REG_A_FOC = 0x32;
|
||||
const uint8_t GYRO_REG_TRIM_NVM_CTRL = 0x33;
|
||||
const uint8_t GYRO_REG_BGW_SPI3_WDT = 0x34;
|
||||
const uint8_t GYRO_REG_OFC1 = 0x36;
|
||||
const uint8_t GYRO_REG_OFC2 = 0x37;
|
||||
const uint8_t GYRO_REG_OFC3 = 0x38;
|
||||
const uint8_t GYRO_REG_OFC4 = 0x39;
|
||||
const uint8_t GYRO_REG_TRIM_GP0 = 0x3A;
|
||||
const uint8_t GYRO_REG_TRIM_GP1 = 0x3B;
|
||||
const uint8_t GYRO_REG_BIST = 0x3C;
|
||||
const uint8_t GYRO_REG_FIFO_CONFIG_0 = 0x3D;
|
||||
const uint8_t GYRO_REG_FIFO_CONFIG_1 = 0x3E;
|
||||
|
||||
const uint8_t MAG_REG_CHIP_ID = 0x40;
|
||||
const uint8_t MAG_REG_DATA_X_LSB = 0x42;
|
||||
const uint8_t MAG_REG_DATA_X_MSB = 0x43;
|
||||
const uint8_t MAG_REG_DATA_Y_LSB = 0x44;
|
||||
const uint8_t MAG_REG_DATA_Y_MSB = 0x45;
|
||||
const uint8_t MAG_REG_DATA_Z_LSB = 0x46;
|
||||
const uint8_t MAG_REG_DATA_Z_MSB = 0x47;
|
||||
const uint8_t MAG_REG_RHALL_LSB = 0x48;
|
||||
const uint8_t MAG_REG_RHALL_MSB = 0x49;
|
||||
const uint8_t MAG_REG_INT_STATUS = 0x4A;
|
||||
const uint8_t MAG_REG_POWER = 0x4B;
|
||||
const uint8_t MAG_REG_MODE = 0x4C;
|
||||
const uint8_t MAG_REG_INT_ENABLE = 0x4D;
|
||||
const uint8_t MAG_REG_INT_SETTINGS = 0x4E;
|
||||
const uint8_t MAG_REG_LOW_THRESH = 0x4F;
|
||||
const uint8_t MAG_REG_HIGH_THRESH = 0x50;
|
||||
const uint8_t MAG_REG_REP_XY = 0x51;
|
||||
const uint8_t MAG_REG_REP_Z = 0x52;
|
||||
|
||||
struct bmx055_data
|
||||
{
|
||||
@ -98,6 +165,9 @@ struct bmx055_data
|
||||
int16_t gyro_x;
|
||||
int16_t gyro_y;
|
||||
int16_t gyro_z;
|
||||
int16_t mag_x;
|
||||
int16_t mag_y;
|
||||
int16_t mag_z;
|
||||
int8_t temperature;
|
||||
};
|
||||
|
||||
@ -120,7 +190,7 @@ static int bmx055_sample_fetch(const struct device *dev,
|
||||
int ret;
|
||||
|
||||
uint8_t accel[6];
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_X_LSB, accel, sizeof(accel));
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_ACCD_X_LSB, accel, sizeof(accel));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read acceleration registers!");
|
||||
@ -130,7 +200,20 @@ static int bmx055_sample_fetch(const struct device *dev,
|
||||
data->accel_y = ((int16_t)sys_get_le16(&accel[2])) >> 4;
|
||||
data->accel_z = ((int16_t)sys_get_le16(&accel[4])) >> 4;
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
|
||||
uint8_t gyro[6];
|
||||
struct i2c_dt_spec gyro_bus = config->bus;
|
||||
gyro_bus.addr = 0x68;
|
||||
ret = i2c_burst_read_dt(&gyro_bus, GYRO_REG_RATE_X_LSB, gyro, sizeof(gyro));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read gyro registers!");
|
||||
return ret;
|
||||
}
|
||||
data->gyro_x = ((int16_t)sys_get_le16(&gyro[0]));
|
||||
data->gyro_y = ((int16_t)sys_get_le16(&gyro[2]));
|
||||
data->gyro_z = ((int16_t)sys_get_le16(&gyro[4]));
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read temperature register!");
|
||||
@ -148,11 +231,13 @@ static int bmx055_channel_get(const struct device *dev,
|
||||
|
||||
switch (chan)
|
||||
{
|
||||
// degrees C
|
||||
case SENSOR_CHAN_DIE_TEMP:
|
||||
// 0.5K/LSB, center temperature is 23C
|
||||
val->val1 = 23 + data->temperature / 2;
|
||||
val->val2 = 0; // TODO: don't throw out LSB
|
||||
break;
|
||||
// m/s^2
|
||||
case SENSOR_CHAN_ACCEL_X:
|
||||
{
|
||||
float accel = data->accel_x * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
@ -180,10 +265,28 @@ static int bmx055_channel_get(const struct device *dev,
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
// radians/second
|
||||
case SENSOR_CHAN_GYRO_X:
|
||||
{
|
||||
float rate = data->gyro_x * 2000.0 / 32767;
|
||||
val->val1 = rate;
|
||||
val->val2 = (rate - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_GYRO_Y:
|
||||
{
|
||||
float rate = data->gyro_y * 2000.0 / 32767;
|
||||
val->val1 = rate;
|
||||
val->val2 = (rate - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_GYRO_Z:
|
||||
return -ENOTSUP;
|
||||
{
|
||||
float rate = data->gyro_z * 2000.0 / 32767;
|
||||
val->val1 = rate;
|
||||
val->val2 = (rate - val->val1) * 1000000;
|
||||
break;
|
||||
}
|
||||
case SENSOR_CHAN_MAGN_X:
|
||||
case SENSOR_CHAN_MAGN_Y:
|
||||
case SENSOR_CHAN_MAGN_Z:
|
||||
@ -212,7 +315,7 @@ static int bmx055_init(const struct device *dev)
|
||||
}
|
||||
|
||||
uint8_t chip_id;
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_BWG_CHIPID, &chip_id, sizeof(chip_id));
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_BWG_CHIPID, &chip_id, sizeof(chip_id));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read chip ID register!");
|
||||
@ -226,12 +329,12 @@ static int bmx055_init(const struct device *dev)
|
||||
|
||||
// // Reset the sensor
|
||||
// uint8_t reset_val = BGW_SOFTRESET;
|
||||
// i2c_burst_write_dt(&config->bus, REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
// i2c_burst_write_dt(&config->bus, ACCEL_REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
|
||||
// // Wait for device to reset
|
||||
|
||||
uint8_t lpw;
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_PMU_LPW, &lpw, sizeof(lpw));
|
||||
ret = i2c_burst_read_dt(&config->bus, ACCEL_REG_PMU_LPW, &lpw, sizeof(lpw));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read LPW register!");
|
||||
@ -241,13 +344,29 @@ static int bmx055_init(const struct device *dev)
|
||||
|
||||
// Write configuration
|
||||
uint8_t accel_range = PMU_RANGE_2G;
|
||||
i2c_burst_write_dt(&config->bus, REG_PMU_RANGE, &accel_range, sizeof(accel_range));
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_PMU_RANGE, &accel_range, sizeof(accel_range));
|
||||
|
||||
uint8_t accel_bw = PMU_BW_8HZ;
|
||||
i2c_burst_write_dt(&config->bus, REG_PMU_BW, &accel_bw, sizeof(accel_bw));
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_PMU_BW, &accel_bw, sizeof(accel_bw));
|
||||
|
||||
uint8_t hbw = (1 << 7); // data_high_bw (read filtered data) and enable lsb/msb shadowing
|
||||
i2c_burst_write_dt(&config->bus, REG_ACCD_HBW, &hbw, sizeof(hbw));
|
||||
i2c_burst_write_dt(&config->bus, ACCEL_REG_ACCD_HBW, &hbw, sizeof(hbw));
|
||||
|
||||
struct i2c_dt_spec gyro_bus = config->bus;
|
||||
gyro_bus.addr = 0x68;
|
||||
|
||||
uint8_t gyro_chip_id;
|
||||
ret = i2c_burst_read_dt(&gyro_bus, GYRO_REG_CHIP_ID, &gyro_chip_id, sizeof(gyro_chip_id));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read gyro chip ID register!");
|
||||
return ret;
|
||||
}
|
||||
const uint8_t GYRO_CHIP_ID = 0x0f;
|
||||
if (gyro_chip_id != GYRO_CHIP_ID)
|
||||
{
|
||||
LOG_ERR("Gyro chip ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, gyro_chip_id, GYRO_CHIP_ID);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user