mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-09-06 19:11:56 +00:00
Usually, we want to operate only on "available" device nodes ("available" means "status is okay and a matching binding is found"), but that's not true in all cases. Sometimes we want to operate on special nodes without matching bindings, such as those describing memory. To handle the distinction, change various additional devicetree APIs making it clear that they operate only on available device nodes, adjusting gen_defines and devicetree.h implementation details accordingly: - emit macros for all existing nodes in gen_defines.py, regardless of status or matching binding - rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY - rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY - rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY - rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY - rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS - resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS - remove DT_COMPAT_ON_BUS as a public API - use the new default_prop_types edtlib parameter Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
/* ST Microelectronics LIS2MDL 3-axis magnetometer sensor
|
|
*
|
|
* Copyright (c) 2019 STMicroelectronics
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Datasheet:
|
|
* https://www.st.com/resource/en/datasheet/lis2mdl.pdf
|
|
*/
|
|
|
|
#define DT_DRV_COMPAT st_lis2mdl
|
|
|
|
#include <string.h>
|
|
#include <drivers/i2c.h>
|
|
#include <logging/log.h>
|
|
|
|
#include "lis2mdl.h"
|
|
|
|
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
|
|
|
#define LOG_LEVEL CONFIG_SENSOR_LOG_LEVEL
|
|
LOG_MODULE_DECLARE(LIS2MDL);
|
|
|
|
static int lis2mdl_i2c_read(struct device *dev, u8_t reg_addr,
|
|
u8_t *value, u16_t len)
|
|
{
|
|
struct lis2mdl_data *data = dev->driver_data;
|
|
const struct lis2mdl_config *cfg = dev->config_info;
|
|
|
|
return i2c_burst_read(data->bus, cfg->i2c_slv_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
static int lis2mdl_i2c_write(struct device *dev, u8_t reg_addr,
|
|
u8_t *value, u16_t len)
|
|
{
|
|
struct lis2mdl_data *data = dev->driver_data;
|
|
const struct lis2mdl_config *cfg = dev->config_info;
|
|
|
|
return i2c_burst_write(data->bus, cfg->i2c_slv_addr,
|
|
reg_addr, value, len);
|
|
}
|
|
|
|
int lis2mdl_i2c_init(struct device *dev)
|
|
{
|
|
struct lis2mdl_data *data = dev->driver_data;
|
|
|
|
data->ctx_i2c.read_reg = (stmdev_read_ptr) lis2mdl_i2c_read;
|
|
data->ctx_i2c.write_reg = (stmdev_write_ptr) lis2mdl_i2c_write;
|
|
|
|
data->ctx = &data->ctx_i2c;
|
|
data->ctx->handle = dev;
|
|
|
|
return 0;
|
|
}
|
|
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
|