acceleration isn't quite working yet
Some checks failed
Some checks failed
This commit is contained in:
@ -118,11 +118,12 @@ int main(void)
|
||||
while (1)
|
||||
{
|
||||
int ret;
|
||||
struct sensor_value voltage, current, pressure, temperature, humidity;
|
||||
struct sensor_value voltage, current, pressure, temperature, accel_x, humidity;
|
||||
char str_v[15] = {0};
|
||||
char str_i[15] = {0};
|
||||
char str_p[16] = {0};
|
||||
char str_t[16] = {0};
|
||||
char str_ax[16] = {0};
|
||||
char str_h[16] = {0};
|
||||
|
||||
ret = sensor_sample_fetch(ina);
|
||||
@ -175,6 +176,12 @@ int main(void)
|
||||
LOG_ERR("Could not get temperature (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = sensor_channel_get(bmx, SENSOR_CHAN_ACCEL_X, &accel_x);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not get acceleration (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ret = sensor_sample_fetch(hdc);
|
||||
// if (ret < 0)
|
||||
@ -193,6 +200,7 @@ int main(void)
|
||||
sprintf(str_i, "I:%01d.%06d", current.val1, current.val2);
|
||||
sprintf(str_p, "P:%03d.%04d", pressure.val1, pressure.val2 / 100);
|
||||
sprintf(str_t, "T:%03d.%04d", temperature.val1, temperature.val2 / 100);
|
||||
sprintf(str_ax, "X:%03d.%04d", accel_x.val1, accel_x.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);
|
||||
@ -208,7 +216,7 @@ int main(void)
|
||||
printf("Failed to print a string\n");
|
||||
continue;
|
||||
}
|
||||
if (cfb_print(dev, str_p, 0, 16 * 2))
|
||||
if (cfb_print(dev, str_ax, 0, 16 * 2))
|
||||
{
|
||||
printf("Failed to print a string\n");
|
||||
continue;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(bmx055, CONFIG_SENSOR_LOG_LEVEL);
|
||||
@ -28,11 +29,30 @@ 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
|
||||
{
|
||||
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
|
||||
{
|
||||
PMU_BW_8HZ = 0b01000,
|
||||
PMU_BW_16HZ = 0b01001,
|
||||
PMU_BW_31HZ = 0b01010,
|
||||
PMU_BW_63HZ = 0b01011,
|
||||
PMU_BW_125HZ = 0b01100,
|
||||
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;
|
||||
@ -99,6 +119,17 @@ static int bmx055_sample_fetch(const struct device *dev,
|
||||
struct bmx055_data *data = dev->data;
|
||||
int ret;
|
||||
|
||||
uint8_t accel[6];
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_X_LSB, accel, sizeof(accel));
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Failed to read acceleration registers!");
|
||||
return ret;
|
||||
}
|
||||
data->accel_x = sys_get_be16(&accel[0]) >> 4;
|
||||
data->accel_y = sys_get_be16(&accel[2]) >> 4;
|
||||
data->accel_z = sys_get_be16(&accel[4]) >> 4;
|
||||
|
||||
ret = i2c_burst_read_dt(&config->bus, REG_ACCD_TEMP, &data->temperature, sizeof(data->temperature));
|
||||
if (ret < 0)
|
||||
{
|
||||
@ -122,6 +153,28 @@ static int bmx055_channel_get(const struct device *dev,
|
||||
val->val1 = 23 + data->temperature / 2;
|
||||
val->val2 = 0; // TODO: don't throw out LSB
|
||||
break;
|
||||
case SENSOR_CHAN_ACCEL_X:
|
||||
// For now assume 2g since that's the default value
|
||||
// 2g 0.98mg/LSB
|
||||
// 4g 1.95mg/LSB
|
||||
// 8g 3.91mg/LSB
|
||||
// 16g 7.81mg/LSB
|
||||
// 1 g = 9.80665 m/s^2
|
||||
float accel = data->accel_x * 0.00098 * 9.80665; // to gees, to m/s^2
|
||||
val->val1 = accel;
|
||||
val->val2 = (accel - val->val1) * 1000000;
|
||||
break;
|
||||
case SENSOR_CHAN_ACCEL_Y:
|
||||
case SENSOR_CHAN_ACCEL_Z:
|
||||
return -ENOTSUP;
|
||||
case SENSOR_CHAN_GYRO_X:
|
||||
case SENSOR_CHAN_GYRO_Y:
|
||||
case SENSOR_CHAN_GYRO_Z:
|
||||
return -ENOTSUP;
|
||||
case SENSOR_CHAN_MAGN_X:
|
||||
case SENSOR_CHAN_MAGN_Y:
|
||||
case SENSOR_CHAN_MAGN_Z:
|
||||
return -ENOTSUP;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@ -158,45 +211,18 @@ static int bmx055_init(const struct device *dev)
|
||||
LOG_ERR("Chip ID read from %s incorrect. Read 0x%02X, expected 0x%02X", dev->name, chip_id, CHIP_ID);
|
||||
}
|
||||
|
||||
// ret = ina23x_reg_write(&config->bus, INA230_REG_CONFIG, config->config);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to write configuration register!");
|
||||
// return ret;
|
||||
// }
|
||||
// Reset the sensor
|
||||
uint8_t reset_val = BGW_SOFTRESET;
|
||||
i2c_burst_write_dt(&config->bus, REG_BGW_SOFTRESET, &reset_val, sizeof(reset_val));
|
||||
|
||||
// ret = ina230_calibrate(dev);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to write calibration register!");
|
||||
// return ret;
|
||||
// }
|
||||
// Wait for device to reset
|
||||
|
||||
// #ifdef CONFIG_INA230_TRIGGER
|
||||
// if (config->trig_enabled)
|
||||
// {
|
||||
// ret = ina230_trigger_mode_init(dev);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to init trigger mode\n");
|
||||
// return ret;
|
||||
// }
|
||||
// Write configuration
|
||||
uint8_t accel_range = PMU_RANGE_2G;
|
||||
i2c_burst_write_dt(&config->bus, REG_PMU_RANGE, &accel_range, sizeof(accel_range));
|
||||
|
||||
// ret = ina23x_reg_write(&config->bus, INA230_REG_ALERT, config->alert_limit);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to write alert register!");
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
// ret = ina23x_reg_write(&config->bus, INA230_REG_MASK, config->mask);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to write mask register!");
|
||||
// return ret;
|
||||
// }
|
||||
// }
|
||||
// #endif /* CONFIG_INA230_TRIGGER */
|
||||
uint8_t accel_bw = PMU_BW_8HZ;
|
||||
i2c_burst_write_dt(&config->bus, REG_PMU_BW, &accel_bw, sizeof(accel_bw));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user