Lines Matching +full:divider +full:- +full:int +full:- +full:2

4  * SPDX-License-Identifier: Apache-2.0
22 uint16_t divider) in hmc5883l_convert() argument
24 /* val = raw_val / divider */ in hmc5883l_convert()
25 val->val1 = raw_val / divider; in hmc5883l_convert()
26 val->val2 = (((int64_t)raw_val % divider) * 1000000L) / divider; in hmc5883l_convert()
29 static int hmc5883l_channel_get(const struct device *dev, in hmc5883l_channel_get()
33 struct hmc5883l_data *drv_data = dev->data; in hmc5883l_channel_get()
36 hmc5883l_convert(val, drv_data->x_sample, in hmc5883l_channel_get()
37 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
39 hmc5883l_convert(val, drv_data->y_sample, in hmc5883l_channel_get()
40 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
42 hmc5883l_convert(val, drv_data->z_sample, in hmc5883l_channel_get()
43 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
45 hmc5883l_convert(val, drv_data->x_sample, in hmc5883l_channel_get()
46 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
47 hmc5883l_convert(val + 1, drv_data->y_sample, in hmc5883l_channel_get()
48 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
49 hmc5883l_convert(val + 2, drv_data->z_sample, in hmc5883l_channel_get()
50 hmc5883l_gain[drv_data->gain_idx]); in hmc5883l_channel_get()
52 return -ENOTSUP; in hmc5883l_channel_get()
58 static int hmc5883l_sample_fetch(const struct device *dev, in hmc5883l_sample_fetch()
61 struct hmc5883l_data *drv_data = dev->data; in hmc5883l_sample_fetch()
62 const struct hmc5883l_config *config = dev->config; in hmc5883l_sample_fetch()
68 if (i2c_burst_read_dt(&config->i2c, HMC5883L_REG_DATA_START, in hmc5883l_sample_fetch()
71 return -EIO; in hmc5883l_sample_fetch()
74 drv_data->x_sample = sys_be16_to_cpu(buf[0]); in hmc5883l_sample_fetch()
75 drv_data->z_sample = sys_be16_to_cpu(buf[1]); in hmc5883l_sample_fetch()
76 drv_data->y_sample = sys_be16_to_cpu(buf[2]); in hmc5883l_sample_fetch()
89 int hmc5883l_init(const struct device *dev) in hmc5883l_init()
91 struct hmc5883l_data *drv_data = dev->data; in hmc5883l_init()
92 const struct hmc5883l_config *config = dev->config; in hmc5883l_init()
95 if (!device_is_ready(config->i2c.bus)) { in hmc5883l_init()
97 return -ENODEV; in hmc5883l_init()
101 if (i2c_burst_read_dt(&config->i2c, HMC5883L_REG_CHIP_ID, id, 3) < 0) { in hmc5883l_init()
103 return -EIO; in hmc5883l_init()
107 id[2] != HMC5883L_CHIP_ID_C) { in hmc5883l_init()
109 return -EINVAL; in hmc5883l_init()
120 LOG_ERR("Invalid full-scale range value."); in hmc5883l_init()
121 return -EINVAL; in hmc5883l_init()
124 drv_data->gain_idx = idx; in hmc5883l_init()
135 return -EINVAL; in hmc5883l_init()
140 chip_cfg[1] = drv_data->gain_idx << HMC5883L_GAIN_SHIFT; in hmc5883l_init()
141 chip_cfg[2] = HMC5883L_MODE_CONTINUOUS; in hmc5883l_init()
143 if (i2c_burst_write_dt(&config->i2c, HMC5883L_REG_CONFIG_A, in hmc5883l_init()
146 return -EIO; in hmc5883l_init()
150 if (config->int_gpio.port) { in hmc5883l_init()
153 return -EIO; in hmc5883l_init()