Lines Matching +full:average +full:- +full:mode
1 /* ST Microelectronics LIS2MDL 3-axis magnetometer sensor
3 * Copyright (c) 2018-2019 STMicroelectronics
5 * SPDX-License-Identifier: Apache-2.0
21 /* Based on the data sheet, the maximum turn-on time is ("9.4 ms + 1/ODR") when
22 * offset cancellation is on. But in the single mode the ODR is not dependent on
37 const struct lis2mdl_config *cfg = dev->config; in lis2mdl_set_odr()
38 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lis2mdl_set_odr()
41 switch (val->val1) { in lis2mdl_set_odr()
55 return -EINVAL; in lis2mdl_set_odr()
59 return -EIO; in lis2mdl_set_odr()
70 const struct lis2mdl_config *cfg = dev->config; in lis2mdl_set_hard_iron()
71 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lis2mdl_set_hard_iron()
76 offset[i] = val->val1; in lis2mdl_set_hard_iron()
90 struct lis2mdl_data *lis2mdl = dev->data; in lis2mdl_channel_get_mag()
109 cval = lis2mdl->mag[i] * 1500; in lis2mdl_channel_get_mag()
110 pval->val1 = cval / 1000000; in lis2mdl_channel_get_mag()
111 pval->val2 = cval % 1000000; in lis2mdl_channel_get_mag()
120 struct lis2mdl_data *drv_data = dev->data; in lis2mdl_channel_get_temp()
123 val->val1 = 25 + drv_data->temp_sample / 8; in lis2mdl_channel_get_temp()
124 val->val2 = (drv_data->temp_sample % 8) * 1000000 / 8; in lis2mdl_channel_get_temp()
143 return -ENOTSUP; in lis2mdl_channel_get()
162 return -ENOTSUP; in lis2mdl_config()
182 return -ENOTSUP; in lis2mdl_attr_set()
191 struct lis2mdl_data *lis2mdl = dev->data; in get_single_mode_raw_data()
192 const struct lis2mdl_config *cfg = dev->config; in get_single_mode_raw_data()
193 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in get_single_mode_raw_data()
198 LOG_ERR("set single mode failed"); in get_single_mode_raw_data()
202 if (k_sem_take(&lis2mdl->fetch_sem, K_MSEC(SAMPLE_FETCH_TIMEOUT_MS))) { in get_single_mode_raw_data()
205 return -EIO; in get_single_mode_raw_data()
219 struct lis2mdl_data *lis2mdl = dev->data; in lis2mdl_sample_fetch_mag()
220 const struct lis2mdl_config *cfg = dev->config; in lis2mdl_sample_fetch_mag()
221 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lis2mdl_sample_fetch_mag()
225 if (cfg->single_mode) { in lis2mdl_sample_fetch_mag()
231 lis2mdl->mag[0] = raw_mag[0]; in lis2mdl_sample_fetch_mag()
232 lis2mdl->mag[1] = raw_mag[1]; in lis2mdl_sample_fetch_mag()
233 lis2mdl->mag[2] = raw_mag[2]; in lis2mdl_sample_fetch_mag()
235 if (cfg->cancel_offset) { in lis2mdl_sample_fetch_mag()
237 * cancellation is enabled in the single mode. Then the in lis2mdl_sample_fetch_mag()
238 * average of the first measurement done above and this in lis2mdl_sample_fetch_mag()
240 * needed in continuous mode since it has been taken in lis2mdl_sample_fetch_mag()
249 lis2mdl->mag[0] += raw_mag[0]; in lis2mdl_sample_fetch_mag()
250 lis2mdl->mag[1] += raw_mag[1]; in lis2mdl_sample_fetch_mag()
251 lis2mdl->mag[2] += raw_mag[2]; in lis2mdl_sample_fetch_mag()
252 lis2mdl->mag[0] /= 2; in lis2mdl_sample_fetch_mag()
253 lis2mdl->mag[1] /= 2; in lis2mdl_sample_fetch_mag()
254 lis2mdl->mag[2] /= 2; in lis2mdl_sample_fetch_mag()
264 lis2mdl->mag[0] = raw_mag[0]; in lis2mdl_sample_fetch_mag()
265 lis2mdl->mag[1] = raw_mag[1]; in lis2mdl_sample_fetch_mag()
266 lis2mdl->mag[2] = raw_mag[2]; in lis2mdl_sample_fetch_mag()
273 struct lis2mdl_data *lis2mdl = dev->data; in lis2mdl_sample_fetch_temp()
274 const struct lis2mdl_config *cfg = dev->config; in lis2mdl_sample_fetch_temp()
275 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lis2mdl_sample_fetch_temp()
281 return -EIO; in lis2mdl_sample_fetch_temp()
284 lis2mdl->temp_sample = raw_temp; in lis2mdl_sample_fetch_temp()
307 return -ENOTSUP; in lis2mdl_sample_fetch()
324 struct lis2mdl_data *lis2mdl = dev->data; in lis2mdl_init()
325 const struct lis2mdl_config *cfg = dev->config; in lis2mdl_init()
326 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; in lis2mdl_init()
330 lis2mdl->dev = dev; in lis2mdl_init()
332 if (cfg->spi_4wires) { in lis2mdl_init()
335 return -EIO; in lis2mdl_init()
341 return -EIO; in lis2mdl_init()
346 return -EINVAL; in lis2mdl_init()
352 return -EIO; in lis2mdl_init()
357 if (cfg->spi_4wires) { in lis2mdl_init()
360 return -EIO; in lis2mdl_init()
367 return -EIO; in lis2mdl_init()
373 return -EIO; in lis2mdl_init()
376 if (cfg->cancel_offset) { in lis2mdl_init()
378 * and continuous mode. in lis2mdl_init()
382 LOG_ERR("reset sensor mode failed"); in lis2mdl_init()
383 return -EIO; in lis2mdl_init()
390 return -EIO; in lis2mdl_init()
393 if (cfg->cancel_offset && cfg->single_mode) { in lis2mdl_init()
395 * the single-mode when offset cancellation is enabled. in lis2mdl_init()
405 if (cfg->single_mode) { in lis2mdl_init()
420 k_sem_init(&lis2mdl->fetch_sem, 0, 1); in lis2mdl_init()
423 /* Set device in continuous mode */ in lis2mdl_init()
427 LOG_ERR("set continuous mode failed"); in lis2mdl_init()
433 if (cfg->trig_enabled) { in lis2mdl_init()
436 return -EIO; in lis2mdl_init()
448 const struct lis2mdl_config *config = dev->config; in lis2mdl_pm_action()
449 stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx; in lis2mdl_pm_action()
454 if (config->single_mode) { in lis2mdl_pm_action()
474 return -ENOTSUP; in lis2mdl_pm_action()
553 * bus-specific macro at preprocessor time.