successfully reading temperature from BMX
Some checks failed
Build / build (macos-12) (push) Waiting to run
Build / build (macos-14) (push) Waiting to run
Build / build (windows-2022) (push) Waiting to run
Build / build (ubuntu-22.04) (push) Failing after 17s
Documentation / build (push) Successful in 4s

This commit is contained in:
2024-04-27 23:37:30 -06:00
parent d9acd6b2a8
commit 0aae853cf7
2 changed files with 96 additions and 38 deletions

View File

@ -46,7 +46,7 @@ int main(void)
}
}
printf("Initialized %s\n", dev->name);
LOG_INF("Initialized %s\n", dev->name);
if (cfb_framebuffer_init(dev))
{
@ -106,7 +106,7 @@ int main(void)
LOG_ERR("Device %s not ready\n", bmx->name);
return 0;
}
printf("Initialized %s\n", bmx->name);
LOG_INF("Initialized %s\n", bmx->name);
// hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
// if (!device_is_ready(dev))
@ -156,7 +156,20 @@ int main(void)
LOG_ERR("Could not get pressure (%d)", ret);
return 0;
}
ret = sensor_channel_get(bmp, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
// ret = sensor_channel_get(bmp, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
// if (ret < 0)
// {
// LOG_ERR("Could not get temperature (%d)", ret);
// return 0;
// }
ret = sensor_sample_fetch(bmx);
if (ret < 0)
{
LOG_ERR("Could not fetch sample (%d)", ret);
return 0;
}
ret = sensor_channel_get(bmx, SENSOR_CHAN_DIE_TEMP, &temperature);
if (ret < 0)
{
LOG_ERR("Could not get temperature (%d)", ret);
@ -182,7 +195,7 @@ int main(void)
sprintf(str_t, "T:%03d.%04d", temperature.val1, temperature.val2 / 100);
sprintf(str_h, "H:%05d.%06d", humidity.val1, humidity.val2);
printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
// printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
cfb_framebuffer_clear(dev, false);
if (cfb_print(dev, str_v, 0, 0))

View File

@ -13,9 +13,72 @@
#include <zephyr/logging/log.h>
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;
const uint8_t REG_PMU_BW = 0x10;
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 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;
struct bmx055_data
{
int state;
int16_t accel_x;
int16_t accel_y;
int16_t accel_z;
int16_t gyro_x;
int16_t gyro_y;
int16_t gyro_z;
int8_t temperature;
};
struct bmx055_config
@ -29,40 +92,19 @@ struct bmx055_config
#endif /* CONFIG_INA230_TRIGGER */
};
// int bmx055_reg_read(const struct i2c_dt_spec *bus, uint8_t reg, uint8_t *val)
// {
// uint8_t data[2];
// int ret;
// ret = i2c_burst_read_dt(bus, reg, data, sizeof(data));
// if (ret < 0)
// {
// return ret;
// }
// *val = sys_get_be16(data);
// return ret;
// }
// int bmx055_reg_write(const struct i2c_dt_spec *bus, uint8_t reg, uint8_t val)
// {
// uint8_t tx_buf[2];
// tx_buf[0] = reg;
// tx_buf[1] = val;
// return i2c_write_dt(bus, tx_buf, sizeof(tx_buf));
// }
static int bmx055_sample_fetch(const struct device *dev,
enum sensor_channel chan)
{
// const struct bmx055_config *config = dev->config;
const struct bmx055_config *config = dev->config;
struct bmx055_data *data = dev->data;
int ret;
// data->state = gpio_pin_get_dt(&config->input);
data->state = 0;
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
if (ret < 0)
{
LOG_ERR("Failed to read temperature register!");
return ret;
}
return 0;
}
@ -73,13 +115,17 @@ static int bmx055_channel_get(const struct device *dev,
{
struct bmx055_data *data = dev->data;
if (chan != SENSOR_CHAN_PROX)
switch (chan)
{
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;
default:
return -ENOTSUP;
}
val->val1 = data->state;
return 0;
}
@ -99,7 +145,6 @@ static int bmx055_init(const struct device *dev)
return -ENODEV;
}
const uint8_t REG_BWG_CHIPID = 0x00;
uint8_t chip_id;
ret = i2c_burst_read_dt(&config->bus, REG_BWG_CHIPID, &chip_id, sizeof(chip_id));
if (ret < 0)