minimal communication with BMX055
Some checks failed
Some checks failed
This commit is contained in:
@ -84,7 +84,7 @@ int main(void)
|
||||
|
||||
cfb_set_kerning(dev, 3);
|
||||
|
||||
const struct device *ina, *bmp, *hdc;
|
||||
const struct device *ina, *bmp, *bmx, *hdc;
|
||||
|
||||
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
||||
if (!device_is_ready(ina))
|
||||
@ -100,6 +100,14 @@ int main(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bmx = DEVICE_DT_GET(DT_NODELABEL(bmx055));
|
||||
if (!device_is_ready(bmx))
|
||||
{
|
||||
LOG_ERR("Device %s not ready\n", bmx->name);
|
||||
return 0;
|
||||
}
|
||||
printf("Initialized %s\n", bmx->name);
|
||||
|
||||
// hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
|
||||
// if (!device_is_ready(dev))
|
||||
// {
|
||||
|
@ -168,6 +168,11 @@
|
||||
compatible = "ti,hdc20xx"; // FIXME: add proper support for this part. Hopefully these parts are close enough
|
||||
reg = <0x40>;
|
||||
};
|
||||
|
||||
bmx055: bmx055@18 {
|
||||
compatible = "bosch,bmx055";
|
||||
reg = <0x18>;
|
||||
};
|
||||
};
|
||||
|
||||
&spi1 {
|
||||
|
@ -2,3 +2,4 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
add_subdirectory_ifdef(CONFIG_EXAMPLE_SENSOR example_sensor)
|
||||
add_subdirectory_ifdef(CONFIG_BMX055 bmx055)
|
||||
|
@ -3,4 +3,5 @@
|
||||
|
||||
if SENSOR
|
||||
rsource "example_sensor/Kconfig"
|
||||
rsource "bmx055/Kconfig"
|
||||
endif # SENSOR
|
||||
|
2
drivers/sensor/bmx055/CMakeLists.txt
Normal file
2
drivers/sensor/bmx055/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
zephyr_library()
|
||||
zephyr_library_sources(bmx055.c)
|
17
drivers/sensor/bmx055/Kconfig
Normal file
17
drivers/sensor/bmx055/Kconfig
Normal file
@ -0,0 +1,17 @@
|
||||
config BMX055
|
||||
bool "BMX055"
|
||||
default y
|
||||
depends on DT_HAS_BOSCH_BMX055_ENABLED
|
||||
help
|
||||
Enable driver for BMX055.
|
||||
|
||||
if BMX055
|
||||
|
||||
config BMX055_TRIGGER
|
||||
bool "BMX055 trigger mode"
|
||||
depends on BMX055
|
||||
help
|
||||
Set to enable trigger mode using gpio interrupt, where
|
||||
interrupts are configured to line ALERT PIN.
|
||||
|
||||
endif # BMX055
|
171
drivers/sensor/bmx055/bmx055.c
Normal file
171
drivers/sensor/bmx055/bmx055.c
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT bosch_bmx055
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/drivers/sensor.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(bmx055, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
struct bmx055_data
|
||||
{
|
||||
int state;
|
||||
};
|
||||
|
||||
struct bmx055_config
|
||||
{
|
||||
struct i2c_dt_spec bus;
|
||||
#ifdef CONFIG_INA230_TRIGGER
|
||||
bool trig_enabled;
|
||||
uint16_t mask;
|
||||
const struct gpio_dt_spec alert_gpio;
|
||||
uint16_t alert_limit;
|
||||
#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;
|
||||
struct bmx055_data *data = dev->data;
|
||||
|
||||
// data->state = gpio_pin_get_dt(&config->input);
|
||||
data->state = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bmx055_channel_get(const struct device *dev,
|
||||
enum sensor_channel chan,
|
||||
struct sensor_value *val)
|
||||
{
|
||||
struct bmx055_data *data = dev->data;
|
||||
|
||||
if (chan != SENSOR_CHAN_PROX)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
val->val1 = data->state;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct sensor_driver_api bmx055_api = {
|
||||
.sample_fetch = &bmx055_sample_fetch,
|
||||
.channel_get = &bmx055_channel_get,
|
||||
};
|
||||
|
||||
static int bmx055_init(const struct device *dev)
|
||||
{
|
||||
const struct bmx055_config *const config = dev->config;
|
||||
int ret;
|
||||
|
||||
if (!device_is_ready(config->bus.bus))
|
||||
{
|
||||
LOG_ERR("I2C bus %s is not ready", config->bus.bus->name);
|
||||
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)
|
||||
{
|
||||
LOG_ERR("Failed to read chip ID register!");
|
||||
return ret;
|
||||
}
|
||||
const uint8_t CHIP_ID = 0xfa;
|
||||
if (chip_id != CHIP_ID)
|
||||
{
|
||||
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;
|
||||
// }
|
||||
|
||||
// ret = ina230_calibrate(dev);
|
||||
// if (ret < 0)
|
||||
// {
|
||||
// LOG_ERR("Failed to write calibration register!");
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
// #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;
|
||||
// }
|
||||
|
||||
// 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 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define BMX055_INIT(i) \
|
||||
static struct bmx055_data bmx055_data_##i; \
|
||||
\
|
||||
static const struct bmx055_config bmx055_config_##i = { \
|
||||
.bus = I2C_DT_SPEC_INST_GET(i), \
|
||||
}; \
|
||||
\
|
||||
SENSOR_DEVICE_DT_INST_DEFINE(i, &bmx055_init, NULL, \
|
||||
&bmx055_data_##i, \
|
||||
&bmx055_config_##i, POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &bmx055_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(BMX055_INIT)
|
12
dts/bindings/sensor/bosch,bmx055.yaml
Normal file
12
dts/bindings/sensor/bosch,bmx055.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
description: |
|
||||
TODO: add a description
|
||||
|
||||
compatible: "bosch,bmx055"
|
||||
|
||||
include: [sensor-device.yaml, i2c-device.yaml]
|
||||
|
||||
# properties:
|
||||
# input-gpios:
|
||||
# type: phandle-array
|
||||
# required: true
|
||||
# description: Input GPIO to be sensed.
|
Reference in New Issue
Block a user