mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-28 14:25:21 +00:00
Now that device_api attribute is unmodified at runtime, as well as all the other attributes, it is possible to switch all device driver instance to be constant. A coccinelle rule is used for this: @r_const_dev_1 disable optional_qualifier @ @@ -struct device * +const struct device * @r_const_dev_2 disable optional_qualifier @ @@ -struct device * const +const struct device * Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
/* ST Microelectronics IIS2DLPC 3-axis accelerometer driver
|
|
*
|
|
* Copyright (c) 2020 STMicroelectronics
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Datasheet:
|
|
* https://www.st.com/resource/en/datasheet/iis2dlpc.pdf
|
|
*/
|
|
|
|
#define DT_DRV_COMPAT st_iis2dlpc
|
|
|
|
#include <string.h>
|
|
#include <drivers/i2c.h>
|
|
#include <logging/log.h>
|
|
|
|
#include "iis2dlpc.h"
|
|
|
|
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
|
|
|
static uint16_t iis2dlpc_i2c_slave_addr = DT_INST_REG_ADDR(0);
|
|
|
|
LOG_MODULE_DECLARE(IIS2DLPC, CONFIG_SENSOR_LOG_LEVEL);
|
|
|
|
static int iis2dlpc_i2c_read(struct iis2dlpc_data *data, uint8_t reg_addr,
|
|
uint8_t *value, uint16_t len)
|
|
{
|
|
return i2c_burst_read(data->bus, iis2dlpc_i2c_slave_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
static int iis2dlpc_i2c_write(struct iis2dlpc_data *data, uint8_t reg_addr,
|
|
uint8_t *value, uint16_t len)
|
|
{
|
|
return i2c_burst_write(data->bus, iis2dlpc_i2c_slave_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
stmdev_ctx_t iis2dlpc_i2c_ctx = {
|
|
.read_reg = (stmdev_read_ptr) iis2dlpc_i2c_read,
|
|
.write_reg = (stmdev_write_ptr) iis2dlpc_i2c_write,
|
|
};
|
|
|
|
int iis2dlpc_i2c_init(const struct device *dev)
|
|
{
|
|
struct iis2dlpc_data *data = dev->data;
|
|
|
|
data->ctx = &iis2dlpc_i2c_ctx;
|
|
data->ctx->handle = data;
|
|
|
|
return 0;
|
|
}
|
|
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
|