mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-26 21:46:03 +00:00
The ISM330DHCX is a ultra-low power IMU with a 3D digital accelerometer and 3D digital gyroscope tailored for Industry 4.0 applications, which can be interfaced through either I2C or SPI bus. https://www.st.com/resource/en/datasheet/ism330dhcx.pdf This driver is based on stmemsc i/f v1.02. Signed-off-by: Armando Visconti <armando.visconti@st.com>
54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
/* ST Microelectronics ISM330DHCX 6-axis IMU sensor driver
|
|
*
|
|
* Copyright (c) 2020 STMicroelectronics
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Datasheet:
|
|
* https://www.st.com/resource/en/datasheet/ism330dhcx.pdf
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <drivers/i2c.h>
|
|
#include <logging/log.h>
|
|
|
|
#include "ism330dhcx.h"
|
|
|
|
#ifdef DT_ST_ISM330DHCX_BUS_I2C
|
|
|
|
LOG_MODULE_DECLARE(ISM330DHCX, CONFIG_SENSOR_LOG_LEVEL);
|
|
|
|
static int ism330dhcx_i2c_read(struct device *dev, u8_t reg_addr,
|
|
u8_t *value, u8_t len)
|
|
{
|
|
struct ism330dhcx_data *data = dev->driver_data;
|
|
const struct ism330dhcx_config *cfg = dev->config->config_info;
|
|
|
|
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
static int ism330dhcx_i2c_write(struct device *dev, u8_t reg_addr,
|
|
u8_t *value, u8_t len)
|
|
{
|
|
struct ism330dhcx_data *data = dev->driver_data;
|
|
const struct ism330dhcx_config *cfg = dev->config->config_info;
|
|
|
|
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
int ism330dhcx_i2c_init(struct device *dev)
|
|
{
|
|
struct ism330dhcx_data *data = dev->driver_data;
|
|
|
|
data->ctx_i2c.read_reg = (stmdev_read_ptr) ism330dhcx_i2c_read,
|
|
data->ctx_i2c.write_reg = (stmdev_write_ptr) ism330dhcx_i2c_write,
|
|
|
|
data->ctx = &data->ctx_i2c;
|
|
data->ctx->handle = dev;
|
|
|
|
return 0;
|
|
}
|
|
#endif /* DT_ST_ISM330DHCX_BUS_I2C */
|