text
stringlengths
9
39.2M
dir
stringlengths
25
226
lang
stringclasses
163 values
created_date
timestamp[s]
updated_date
timestamp[s]
repo_name
stringclasses
751 values
repo_full_name
stringclasses
752 values
star
int64
1.01k
183k
len_tokens
int64
1
18.5M
```c /* * */ /* * Bus-specific functionality for BMM150s accessed via I2C. */ #include "bmm150.h" #if BMM150_BUS_I2C static int bmm150_bus_check_i2c(const union bmm150_bus *bus) { return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV; } static int bmm150_reg_read_i2c(const union bmm150_bus *bus, uint8_t start, uint8_t *buf, int size) { return i2c_burst_read_dt(&bus->i2c, start, buf, size); } static int bmm150_reg_write_i2c(const union bmm150_bus *bus, uint8_t reg, uint8_t val) { return i2c_reg_write_byte_dt(&bus->i2c, reg, val); } const struct bmm150_bus_io bmm150_bus_io_i2c = { .check = bmm150_bus_check_i2c, .read = bmm150_reg_read_i2c, .write = bmm150_reg_write_i2c, }; #endif /* BMM150_BUS_I2C */ ```
/content/code_sandbox/drivers/sensor/bosch/bmm150/bmm150_i2c.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
252
```c /* Bosch BMM150 pressure sensor * * * * Datasheet: * path_to_url */ #include <zephyr/kernel.h> #include <zephyr/pm/device.h> #include <zephyr/logging/log.h> #include "bmm150.h" LOG_MODULE_DECLARE(BMM150, CONFIG_SENSOR_LOG_LEVEL); static void bmm150_handle_interrupts(const void *arg) { const struct device *dev = (const struct device *)arg; struct bmm150_data *data = dev->data; if (data->drdy_handler) { data->drdy_handler(dev, data->drdy_trigger); } } #ifdef CONFIG_BMM150_TRIGGER_OWN_THREAD static K_THREAD_STACK_DEFINE(bmm150_thread_stack, CONFIG_BMM150_THREAD_STACK_SIZE); static struct k_thread bmm150_thread; static void bmm150_thread_main(void *arg1, void *unused1, void *unused2) { ARG_UNUSED(unused1); ARG_UNUSED(unused2); const struct device *dev = (const struct device *)arg1; struct bmm150_data *data = dev->data; while (1) { k_sem_take(&data->sem, K_FOREVER); bmm150_handle_interrupts(dev); } } #endif #ifdef CONFIG_BMM150_TRIGGER_GLOBAL_THREAD static void bmm150_work_handler(struct k_work *work) { struct bmm150_data *data = CONTAINER_OF(work, struct bmm150_data, work); bmm150_handle_interrupts(data->dev); } #endif static void bmm150_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { struct bmm150_data *data = CONTAINER_OF(cb, struct bmm150_data, gpio_cb); ARG_UNUSED(port); ARG_UNUSED(pin); #if defined(CONFIG_BMM150_TRIGGER_OWN_THREAD) k_sem_give(&data->sem); #elif defined(CONFIG_BMM150_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #elif defined(CONFIG_BMM150_TRIGGER_DIRECT) bmm150_handle_interrupts(data->dev); #endif } int bmm150_trigger_set( const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { uint16_t values[BMM150_AXIS_XYZR_MAX]; struct bmm150_data *data = dev->data; const struct bmm150_config *cfg = dev->config; #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif if (trig->type != SENSOR_TRIG_DATA_READY) { return -ENOTSUP; } data->drdy_trigger = trig; data->drdy_handler = handler; if (bmm150_reg_update_byte(dev, BMM150_REG_INT_DRDY, BMM150_MASK_DRDY_EN, (handler != NULL) << BMM150_SHIFT_DRDY_EN) < 0) { LOG_ERR("Failed to enable DRDY interrupt"); return -EIO; } /* Clean data registers */ if (cfg->bus_io->read(&cfg->bus, BMM150_REG_X_L, (uint8_t *)values, sizeof(values)) < 0) { LOG_ERR("failed to read sample"); return -EIO; } return 0; } int bmm150_trigger_mode_init(const struct device *dev) { struct bmm150_data *data = dev->data; const struct bmm150_config *cfg = dev->config; int ret; if (!device_is_ready(cfg->drdy_int.port)) { LOG_ERR("INT device is not ready"); return -ENODEV; } #if defined(CONFIG_BMM150_TRIGGER_OWN_THREAD) k_sem_init(&data->sem, 0, 1); k_thread_create( &bmm150_thread, bmm150_thread_stack, CONFIG_BMM150_THREAD_STACK_SIZE, bmm150_thread_main, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BMM150_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMM150_TRIGGER_GLOBAL_THREAD) k_work_init(&data->work, bmm150_work_handler); #endif #if defined(CONFIG_BMM150_TRIGGER_GLOBAL_THREAD) || \ defined(CONFIG_BMM150_TRIGGER_DIRECT) data->dev = dev; #endif ret = gpio_pin_configure_dt(&cfg->drdy_int, GPIO_INPUT); if (ret < 0) { return ret; } gpio_init_callback(&data->gpio_cb, bmm150_gpio_callback, BIT(cfg->drdy_int.pin)); ret = gpio_add_callback(cfg->drdy_int.port, &data->gpio_cb); if (ret < 0) { return ret; } ret = gpio_pin_interrupt_configure_dt(&cfg->drdy_int, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { return ret; } return 0; } ```
/content/code_sandbox/drivers/sensor/bosch/bmm150/bmm150_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,077
```unknown # BMM150 Geomagnetic sensor configuration options menuconfig BMM150 bool "BMM150 I2C Geomagnetic Chip" default y depends on DT_HAS_BOSCH_BMM150_ENABLED select I2C help Enable driver for BMM150 I2C-based Geomagnetic sensor. if BMM150 choice prompt "Default preset" default BMM150_PRESET_REGULAR help Specify the default preset (x/y oversampling, z oversampling, sampling frequency). config BMM150_PRESET_LOW_POWER bool "Low power (3, 3, 10)" config BMM150_PRESET_REGULAR bool "Regular (9, 15, 10)" config BMM150_PRESET_ENHANCED_REGULAR bool "Enhanced regular (15, 27, 10)" config BMM150_PRESET_HIGH_ACCURACY bool "High accuracy (47, 83, 20)" endchoice choice BMM150_TRIGGER_MODE prompt "Trigger mode" default BMM150_TRIGGER_NONE help Specify the type of triggering to be used by the driver. config BMM150_TRIGGER_NONE bool "No trigger" config BMM150_TRIGGER_GLOBAL_THREAD bool "Use global thread" select BMM150_TRIGGER config BMM150_TRIGGER_OWN_THREAD bool "Use own thread" select BMM150_TRIGGER config BMM150_TRIGGER_DIRECT bool "Use IRQ handler" select BMM150_TRIGGER endchoice config BMM150_TRIGGER bool config BMM150_SAMPLING_RATE_RUNTIME bool "Dynamic sampling rate" help Enable alteration of sampling rate attribute at runtime. config BMM150_SAMPLING_REP_XY bool "Dynamic XY oversampling" help Enable alteration of XY oversampling at runtime. config BMM150_SAMPLING_REP_Z bool "Dynamic Z oversampling" help Enable alteration of Z oversampling at runtime. config BMM150_THREAD_PRIORITY int "Own thread priority" depends on BMM150_TRIGGER_OWN_THREAD default 10 help Priority of the thread used by the driver to handle interrupts. config BMM150_THREAD_STACK_SIZE int "Own thread stack size" depends on BMM150_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. endif # BMM150 ```
/content/code_sandbox/drivers/sensor/bosch/bmm150/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
509
```c /* bmm150.c - Driver for Bosch BMM150 Geomagnetic Sensor */ /* * */ #include <zephyr/logging/log.h> #include "bmm150.h" LOG_MODULE_REGISTER(BMM150, CONFIG_SENSOR_LOG_LEVEL); static const struct { int freq; uint8_t reg_val; } bmm150_samp_freq_table[] = { { 2, 0x01 }, { 6, 0x02 }, { 8, 0x03 }, { 10, 0x00 }, { 15, 0x04 }, { 20, 0x05 }, { 25, 0x06 }, { 30, 0x07 } }; static const struct bmm150_preset { uint8_t rep_xy; uint8_t rep_z; uint8_t odr; } bmm150_presets_table[] = { [BMM150_LOW_POWER_PRESET] = { 3, 3, 10 }, [BMM150_REGULAR_PRESET] = { 9, 15, 10 }, [BMM150_ENHANCED_REGULAR_PRESET] = { 15, 27, 10 }, [BMM150_HIGH_ACCURACY_PRESET] = { 47, 83, 20 } }; static inline int bmm150_bus_check(const struct device *dev) { const struct bmm150_config *cfg = dev->config; return cfg->bus_io->check(&cfg->bus); } static inline int bmm150_reg_read(const struct device *dev, uint8_t start, uint8_t *buf, int size) { const struct bmm150_config *cfg = dev->config; return cfg->bus_io->read(&cfg->bus, start, buf, size); } static inline int bmm150_reg_write(const struct device *dev, uint8_t reg, uint8_t val) { const struct bmm150_config *cfg = dev->config; return cfg->bus_io->write(&cfg->bus, reg, val); } int bmm150_reg_update_byte(const struct device *dev, uint8_t reg, uint8_t mask, uint8_t value) { int ret = 0; uint8_t old_value, new_value; ret = bmm150_reg_read(dev, reg, &old_value, 1); if (ret < 0) { goto failed; } new_value = (old_value & ~mask) | (value & mask); if (new_value == old_value) { return 0; } return bmm150_reg_write(dev, reg, new_value); failed: return ret; } /* Power control = 'bit' */ static int bmm150_power_control(const struct device *dev, uint8_t bit) { return bmm150_reg_update_byte(dev, BMM150_REG_POWER, BMM150_MASK_POWER_CTL, bit); } /* OpMode = 'mode' */ static int bmm150_opmode(const struct device *dev, uint8_t mode) { return bmm150_reg_update_byte(dev, BMM150_REG_OPMODE_ODR, BMM150_MASK_OPMODE, mode << BMM150_SHIFT_OPMODE); } static int bmm150_set_odr(const struct device *dev, uint8_t val) { uint8_t i; for (i = 0U; i < ARRAY_SIZE(bmm150_samp_freq_table); ++i) { if (val <= bmm150_samp_freq_table[i].freq) { return bmm150_reg_update_byte(dev, BMM150_REG_OPMODE_ODR, BMM150_MASK_ODR, (bmm150_samp_freq_table[i].reg_val << BMM150_SHIFT_ODR)); } } return -ENOTSUP; } #if defined(BMM150_SET_ATTR_REP) static int bmm150_read_rep_xy(const struct device *dev) { struct bmm150_data *data = dev->driver->data; const struct bmm150_config *config = dev->config; uint8_t reg_val; if (bmm150_reg_read(dev, BMM150_REG_REP_XY, &reg_val, 1) < 0) { return -EIO; } data->rep_xy = BMM150_REGVAL_TO_REPXY((uint8_t)(reg_val)); return 0; } static int bmm150_read_rep_z(const struct device *dev) { struct bmm150_data *data = dev->data; const struct bmm150_config *config = dev->config; uint8_t reg_val; if (bmm150_reg_read(dev, BMM150_REG_REP_Z, &reg_val, 1) < 0) { return -EIO; } data->rep_z = BMM150_REGVAL_TO_REPZ((int)(reg_val)); return 0; } static int bmm150_compute_max_odr(const struct device *dev, int rep_xy, int rep_z, int *max_odr) { struct bmm150_data *data = dev->data; if (rep_xy == 0) { if (data->rep_xy <= 0) { if (bmm150_read_rep_xy(dev) < 0) { return -EIO; } } rep_xy = data->rep_xy; } if (rep_z == 0) { if (data->rep_z <= 0) { if (bmm150_read_rep_z(dev) < 0) { return -EIO; } } rep_z = data->rep_z; } /* Equation reference Datasheet 4.2.4 */ *max_odr = 1000000 / (145 * rep_xy + 500 * rep_z + 980); return 0; } #endif #if defined(BMM150_SET_ATTR_REP) static int bmm150_read_odr(const struct device *dev) { struct bmm150_data *data = dev->data; const struct bmm150_config *config = dev->config; uint8_t i, odr_val, reg_val; if (bmm150_reg_read(dev, BMM150_REG_OPMODE_ODR, &reg_val, 1) < 0) { return -EIO; } odr_val = (reg_val & BMM150_MASK_ODR) >> BMM150_SHIFT_ODR; for (i = 0U; i < ARRAY_SIZE(bmm150_samp_freq_table); ++i) { if (bmm150_samp_freq_table[i].reg_val == odr_val) { data->odr = bmm150_samp_freq_table[i].freq; return 0; } } return -ENOTSUP; } #endif #if defined(CONFIG_BMM150_SAMPLING_REP_XY) static int bmm150_write_rep_xy(const struct device *dev, int val) { struct bmm150_data *data = dev->data; const struct bmm150_config *config = dev->config; if (bmm150_reg_update_byte(dev, BMM150_REG_REP_XY, BMM150_REG_REP_DATAMASK, BMM150_REPXY_TO_REGVAL(val)) < 0) { return -EIO; } data->rep_xy = val; return 0; } #endif #if defined(CONFIG_BMM150_SAMPLING_REP_Z) static int bmm150_write_rep_z(const struct device *dev, int val) { struct bmm150_data *data = dev->data; const struct bmm150_config *config = dev->config; if (bmm150_reg_update_byte(dev, BMM150_REG_REP_Z, BMM150_REG_REP_DATAMASK, BMM150_REPZ_TO_REGVAL(val)) < 0) { return -EIO; } data->rep_z = val; return 0; } #endif /* Reference Datasheet 4.3.2 */ static int32_t bmm150_compensate_xy(struct bmm150_trim_regs *tregs, int16_t xy, uint16_t rhall, bool is_x) { int8_t txy1, txy2; int16_t val; uint16_t prevalue; int32_t temp1, temp2, temp3; if (xy == BMM150_XY_OVERFLOW_VAL) { return INT32_MIN; } if (!rhall) { rhall = tregs->xyz1; } if (is_x) { txy1 = tregs->x1; txy2 = tregs->x2; } else { txy1 = tregs->y1; txy2 = tregs->y2; } prevalue = (uint16_t)((((int32_t)tregs->xyz1) << 14) / rhall); val = (int16_t)((prevalue) - ((uint16_t)0x4000)); temp1 = (((int32_t)tregs->xy2) * ((((int32_t)val) * ((int32_t)val)) >> 7)); temp2 = ((int32_t)val) * ((int32_t)(((int16_t)tregs->xy1) << 7)); temp3 = (((((temp1 + temp2) >> 9) + ((int32_t)0x100000)) * ((int32_t)(((int16_t)txy2) + ((int16_t)0xA0)))) >> 12); val = ((int16_t)((((int32_t)xy) * temp3) >> 13)) + (((int16_t)txy1) << 3); return (int32_t)val; } static int32_t bmm150_compensate_z(struct bmm150_trim_regs *tregs, int16_t z, uint16_t rhall) { int32_t val, temp1, temp2; int16_t temp3; if (z == BMM150_Z_OVERFLOW_VAL) { return INT32_MIN; } temp1 = (((int32_t)(z - tregs->z4)) << 15); temp2 = ((((int32_t)tregs->z3) * ((int32_t)(((int16_t)rhall) - ((int16_t)tregs->xyz1)))) >> 2); temp3 = ((int16_t)(((((int32_t)tregs->z1) * ((((int16_t)rhall) << 1))) + (1 << 15)) >> 16)); val = ((temp1 - temp2) / (tregs->z2 + temp3)); return val; } static int bmm150_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmm150_data *drv_data = dev->data; uint16_t values[BMM150_AXIS_XYZR_MAX]; int16_t raw_x, raw_y, raw_z; uint16_t rhall; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_MAGN_XYZ); if (bmm150_reg_read(dev, BMM150_REG_X_L, (uint8_t *)values, sizeof(values)) < 0) { LOG_ERR("failed to read sample"); return -EIO; } raw_x = (int16_t)sys_le16_to_cpu(values[BMM150_AXIS_X]) >> BMM150_SHIFT_XY_L; raw_y = (int16_t)sys_le16_to_cpu(values[BMM150_AXIS_Y]) >> BMM150_SHIFT_XY_L; raw_z = (int16_t)sys_le16_to_cpu(values[BMM150_AXIS_Z]) >> BMM150_SHIFT_Z_L; rhall = sys_le16_to_cpu(values[BMM150_RHALL]) >> BMM150_SHIFT_RHALL_L; drv_data->sample_x = bmm150_compensate_xy(&drv_data->tregs, raw_x, rhall, true); drv_data->sample_y = bmm150_compensate_xy(&drv_data->tregs, raw_y, rhall, false); drv_data->sample_z = bmm150_compensate_z(&drv_data->tregs, raw_z, rhall); return 0; } /* * Datasheet specify raw units are 16 LSB/uT and this function converts it to * Gauss */ static void bmm150_convert(struct sensor_value *val, int raw_val) { /* val = raw_val / 1600 */ val->val1 = raw_val / 1600; val->val2 = ((int32_t)raw_val * (1000000 / 1600)) % 1000000; } static int bmm150_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmm150_data *drv_data = dev->data; switch (chan) { case SENSOR_CHAN_MAGN_X: bmm150_convert(val, drv_data->sample_x); break; case SENSOR_CHAN_MAGN_Y: bmm150_convert(val, drv_data->sample_y); break; case SENSOR_CHAN_MAGN_Z: bmm150_convert(val, drv_data->sample_z); break; case SENSOR_CHAN_MAGN_XYZ: bmm150_convert(val, drv_data->sample_x); bmm150_convert(val + 1, drv_data->sample_y); bmm150_convert(val + 2, drv_data->sample_z); break; default: return -ENOTSUP; } return 0; } #if defined(BMM150_SET_ATTR_REP) static inline int bmm150_attr_set_rep(const struct device *dev, enum sensor_channel chan, const struct sensor_value *val) { struct bmm150_data *data = dev->data; int max_odr; switch (chan) { #if defined(CONFIG_BMM150_SAMPLING_REP_XY) case SENSOR_CHAN_MAGN_X: case SENSOR_CHAN_MAGN_Y: if (val->val1 < 1 || val->val1 > 511) { return -EINVAL; } if (bmm150_compute_max_odr(dev, val->val1, 0, &max_odr) < 0) { return -EIO; } if (data->odr <= 0) { if (bmm150_read_odr(dev) < 0) { return -EIO; } } if (data->odr > max_odr) { return -EINVAL; } if (bmm150_write_rep_xy(dev, val->val1) < 0) { return -EIO; } break; #endif #if defined(CONFIG_BMM150_SAMPLING_REP_Z) case SENSOR_CHAN_MAGN_Z: if (val->val1 < 1 || val->val1 > 256) { return -EINVAL; } if (bmm150_compute_max_odr(dev, 0, val->val1, &max_odr) < 0) { return -EIO; } if (data->odr <= 0) { if (bmm150_read_odr(dev) < 0) { return -EIO; } } if (data->odr > max_odr) { return -EINVAL; } if (bmm150_write_rep_z(dev, val->val1) < 0) { return -EIO; } break; #endif default: return -EINVAL; } return 0; } #endif #if defined(BMM150_SET_ATTR_REP) static int bmm150_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { struct bmm150_magn_data *data = dev->data; switch (attr) { #if defined(CONFIG_BMM150_SAMPLING_RATE_RUNTIME) case SENSOR_ATTR_SAMPLING_FREQUENCY: if (data->max_odr <= 0) { if (bmm150_compute_max_odr(dev, 0, 0, &data->max_odr) < 0) { return -EIO; } } if (data->max_odr < val->val1) { LOG_ERR("not supported with current oversampling"); return -ENOTSUP; } if (bmm150_set_odr(dev, (uint8_t)(val->val1)) < 0) { return -EIO; } break; #endif #if defined(BMM150_SET_ATTR_REP) case SENSOR_ATTR_OVERSAMPLING: bmm150_attr_set_rep(dev, chan, val); break; #endif default: return -EINVAL; } return 0; } #endif static const struct sensor_driver_api bmm150_api_funcs = { #if defined(BMM150_SET_ATTR_REP) .attr_set = bmm150_attr_set, #endif .sample_fetch = bmm150_sample_fetch, .channel_get = bmm150_channel_get, #ifdef CONFIG_BMM150_TRIGGER .trigger_set = bmm150_trigger_set, #endif }; static int bmm150_full_por(const struct device *dev) { int ret; /* Ensure we are not in suspend mode so soft reset is not ignored */ ret = bmm150_power_control(dev, 1); if (ret != 0) { LOG_ERR("failed to ensure not in suspend mode: %d", ret); return ret; } k_sleep(BMM150_START_UP_TIME); /* Soft reset always brings the device into sleep mode */ ret = bmm150_reg_update_byte(dev, BMM150_REG_POWER, BMM150_MASK_SOFT_RESET, BMM150_SOFT_RESET); if (ret != 0) { LOG_ERR("failed soft reset: %d", ret); return ret; } /* * To perform full POR (after soft reset), bring the device into suspend * mode then back into sleep mode, see datasheet section 5.6 */ ret = bmm150_power_control(dev, 0); if (ret != 0) { LOG_ERR("failed to enter suspend mode: %d", ret); return ret; } k_sleep(BMM150_POR_TIME); /* Full POR - back into sleep mode */ ret = bmm150_power_control(dev, 1); if (ret != 0) { LOG_ERR("failed to go back into sleep mode: %d", ret); return ret; } k_sleep(BMM150_START_UP_TIME); return 0; } static int bmm150_init_chip(const struct device *dev) { struct bmm150_data *data = dev->data; struct bmm150_preset preset; uint8_t chip_id; if (bmm150_full_por(dev) != 0) { goto err_poweroff; } /* Read chip ID (can only be read in sleep mode)*/ if (bmm150_reg_read(dev, BMM150_REG_CHIP_ID, &chip_id, 1) < 0) { LOG_ERR("failed reading chip id"); goto err_poweroff; } if (chip_id != BMM150_CHIP_ID_VAL) { LOG_ERR("invalid chip id 0x%x", chip_id); goto err_poweroff; } /* Setting preset mode */ preset = bmm150_presets_table[BMM150_DEFAULT_PRESET]; if (bmm150_set_odr(dev, preset.odr) < 0) { LOG_ERR("failed to set ODR to %d", preset.odr); goto err_poweroff; } if (bmm150_reg_write(dev, BMM150_REG_REP_XY, BMM150_REPXY_TO_REGVAL(preset.rep_xy)) < 0) { LOG_ERR("failed to set REP XY to %d", preset.rep_xy); goto err_poweroff; } if (bmm150_reg_write(dev, BMM150_REG_REP_Z, BMM150_REPZ_TO_REGVAL(preset.rep_z)) < 0) { LOG_ERR("failed to set REP Z to %d", preset.rep_z); goto err_poweroff; } /* Set chip normal mode */ if (bmm150_opmode(dev, BMM150_MODE_NORMAL) < 0) { LOG_ERR("failed to enter normal mode"); } /* Reads the trim registers of the sensor */ if (bmm150_reg_read(dev, BMM150_REG_TRIM_START, (uint8_t *)&data->tregs, sizeof(data->tregs)) < 0) { LOG_ERR("failed to read trim regs"); goto err_poweroff; } data->rep_xy = 0; data->rep_z = 0; data->odr = 0; data->max_odr = 0; data->sample_x = 0; data->sample_y = 0; data->sample_z = 0; data->tregs.xyz1 = sys_le16_to_cpu(data->tregs.xyz1); data->tregs.z1 = sys_le16_to_cpu(data->tregs.z1); data->tregs.z2 = sys_le16_to_cpu(data->tregs.z2); data->tregs.z3 = sys_le16_to_cpu(data->tregs.z3); data->tregs.z4 = sys_le16_to_cpu(data->tregs.z4); return 0; err_poweroff: (void)bmm150_power_control(dev, 0); /* Suspend */ return -EIO; } #ifdef CONFIG_PM_DEVICE static int pm_action(const struct device *dev, enum pm_device_action action) { int ret; switch (action) { case PM_DEVICE_ACTION_RESUME: /* Need to enter sleep mode before setting OpMode to normal */ ret = bmm150_power_control(dev, 1); if (ret != 0) { LOG_ERR("failed to enter sleep mode: %d", ret); } k_sleep(BMM150_START_UP_TIME); ret |= bmm150_opmode(dev, BMM150_MODE_NORMAL); if (ret != 0) { LOG_ERR("failed to enter normal mode: %d", ret); } break; case PM_DEVICE_ACTION_SUSPEND: ret = bmm150_power_control(dev, 0); /* Suspend */ if (ret != 0) { LOG_ERR("failed to enter suspend mode: %d", ret); } break; default: return -ENOTSUP; } return ret; } #endif static int bmm150_init(const struct device *dev) { int err = 0; err = bmm150_bus_check(dev); if (err < 0) { LOG_DBG("bus check failed: %d", err); return err; } if (bmm150_init_chip(dev) < 0) { LOG_ERR("failed to initialize chip"); return -EIO; } #ifdef CONFIG_BMM150_TRIGGER if (bmm150_trigger_mode_init(dev) < 0) { LOG_ERR("Cannot set up trigger mode."); return -EINVAL; } #endif return 0; } /* Initializes a struct bmm150_config for an instance on a SPI bus. */ #define BMM150_CONFIG_SPI(inst) \ .bus.spi = SPI_DT_SPEC_INST_GET(inst, BMM150_SPI_OPERATION, 0), \ .bus_io = &bmm150_bus_io_spi, /* Initializes a struct bmm150_config for an instance on an I2C bus. */ #define BMM150_CONFIG_I2C(inst) \ .bus.i2c = I2C_DT_SPEC_INST_GET(inst), \ .bus_io = &bmm150_bus_io_i2c, #define BMM150_BUS_CFG(inst) \ COND_CODE_1(DT_INST_ON_BUS(inst, i2c), \ (BMM150_CONFIG_I2C(inst)), \ (BMM150_CONFIG_SPI(inst))) #if defined(CONFIG_BMM150_TRIGGER) #define BMM150_INT_CFG(inst) \ .drdy_int = GPIO_DT_SPEC_INST_GET(inst, drdy_gpios), #else #define BMM150_INT_CFG(inst) #endif /* * Main instantiation macro, which selects the correct bus-specific * instantiation macros for the instance. */ #define BMM150_DEFINE(inst) \ static struct bmm150_data bmm150_data_##inst; \ static const struct bmm150_config bmm150_config_##inst = { \ BMM150_BUS_CFG(inst) \ BMM150_INT_CFG(inst) \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, \ bmm150_init, \ PM_DEVICE_DT_INST_GET(inst), \ &bmm150_data_##inst, \ &bmm150_config_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &bmm150_api_funcs); /* Create the struct device for every status "okay" node in the devicetree. */ DT_INST_FOREACH_STATUS_OKAY(BMM150_DEFINE) ```
/content/code_sandbox/drivers/sensor/bosch/bmm150/bmm150.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,465
```c /* Bosch BMI08X inertial measurement unit driver * * */ #include <zephyr/drivers/sensor.h> #include <zephyr/pm/device.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/byteorder.h> #define DT_DRV_COMPAT bosch_bmi08x_gyro #include "bmi08x.h" LOG_MODULE_REGISTER(BMI08X_GYRO, CONFIG_SENSOR_LOG_LEVEL); #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) static int bmi08x_gyro_transceive_i2c(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_gyro_config *bmi08x = dev->config; if (!write) { return i2c_write_read_dt(&bmi08x->bus.i2c, &reg, 1, data, length); } if (length > CONFIG_BMI08X_I2C_WRITE_BURST_SIZE) { return -EINVAL; } uint8_t buf[1 + CONFIG_BMI08X_I2C_WRITE_BURST_SIZE]; buf[0] = reg; memcpy(&buf[1], data, length); return i2c_write_dt(&bmi08x->bus.i2c, buf, 1 + length); } static int bmi08x_bus_check_i2c(const union bmi08x_bus *bus) { return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV; } static const struct bmi08x_gyro_bus_io bmi08x_i2c_api = { .check = bmi08x_bus_check_i2c, .transceive = bmi08x_gyro_transceive_i2c, }; #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) static int bmi08x_gyro_transceive_spi(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_gyro_config *bmi08x = dev->config; const struct spi_buf tx_buf[2] = {{.buf = &reg, .len = 1}, {.buf = data, .len = length}}; const struct spi_buf_set tx = {.buffers = tx_buf, .count = write ? 2 : 1}; if (!write) { uint16_t dummy; const struct spi_buf rx_buf[2] = {{.buf = &dummy, .len = 1}, {.buf = data, .len = length}}; const struct spi_buf_set rx = {.buffers = rx_buf, .count = 2}; return spi_transceive_dt(&bmi08x->bus.spi, &tx, &rx); } return spi_write_dt(&bmi08x->bus.spi, &tx); } static int bmi08x_bus_check_spi(const union bmi08x_bus *bus) { return spi_is_ready_dt(&bus->spi) ? 0 : -ENODEV; } static const struct bmi08x_gyro_bus_io bmi08x_spi_api = { .check = bmi08x_bus_check_spi, .transceive = bmi08x_gyro_transceive_spi, }; #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ static inline int bmi08x_bus_check(const struct device *dev) { const struct bmi08x_gyro_config *config = dev->config; return config->api->check(&config->bus); } static int bmi08x_gyro_transceive(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_gyro_config *cfg = dev->config; return cfg->api->transceive(dev, reg, write, data, length); } int bmi08x_gyro_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len) { return bmi08x_gyro_transceive(dev, reg_addr | BIT(7), false, data, len); } int bmi08x_gyro_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte) { return bmi08x_gyro_transceive(dev, reg_addr | BIT(7), false, byte, 1); } int bmi08x_gyro_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte) { return bmi08x_gyro_transceive(dev, reg_addr & 0x7F, true, &byte, 1); } int bmi08x_gyro_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word) { uint8_t tx_word[2] = {(uint8_t)(word & 0xff), (uint8_t)(word >> 8)}; return bmi08x_gyro_transceive(dev, reg_addr & 0x7F, true, tx_word, 2); } int bmi08x_gyro_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val) { uint8_t old_val; int ret; ret = bmi08x_gyro_byte_read(dev, reg_addr, &old_val); if (ret < 0) { return ret; } return bmi08x_gyro_byte_write(dev, reg_addr, (old_val & ~mask) | ((val << pos) & mask)); } static const struct bmi08x_range bmi08x_gyr_range_map[] = { {125, BMI08X_GYR_RANGE_125DPS}, {250, BMI08X_GYR_RANGE_250DPS}, {500, BMI08X_GYR_RANGE_500DPS}, {1000, BMI08X_GYR_RANGE_1000DPS}, {2000, BMI08X_GYR_RANGE_2000DPS}, }; #define BMI08X_GYR_RANGE_MAP_SIZE ARRAY_SIZE(bmi08x_gyr_range_map) int32_t bmi08x_gyr_reg_val_to_range(uint8_t reg_val) { return bmi08x_reg_val_to_range(reg_val, bmi08x_gyr_range_map, BMI08X_GYR_RANGE_MAP_SIZE); } static int bmi08x_gyr_odr_set(const struct device *dev, uint16_t freq_int, uint16_t freq_milli) { int odr = bmi08x_freq_to_odr_val(freq_int, freq_milli); if (odr < 0) { return odr; } if (odr < BMI08X_GYRO_BW_532_ODR_2000_HZ || odr > BMI08X_GYRO_BW_32_ODR_100_HZ) { return -ENOTSUP; } return bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_BANDWIDTH, (uint8_t)odr); } static int bmi08x_gyr_range_set(const struct device *dev, uint16_t range) { struct bmi08x_gyro_data *bmi08x = dev->data; int32_t reg_val = bmi08x_range_to_reg_val(range, bmi08x_gyr_range_map, BMI08X_GYR_RANGE_MAP_SIZE); int ret; if (reg_val < 0) { return reg_val; } ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_RANGE, reg_val); if (ret < 0) { return ret; } bmi08x->scale = BMI08X_GYR_SCALE(range); return ret; } static int bmi08x_gyr_config(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { switch (attr) { case SENSOR_ATTR_FULL_SCALE: return bmi08x_gyr_range_set(dev, sensor_rad_to_degrees(val)); case SENSOR_ATTR_SAMPLING_FREQUENCY: return bmi08x_gyr_odr_set(dev, val->val1, val->val2 / 1000); default: LOG_DBG("Gyro attribute not supported."); return -ENOTSUP; } } static int bmi08x_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif switch (chan) { case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: return bmi08x_gyr_config(dev, chan, attr, val); default: LOG_DBG("attr_set() not supported on this channel."); return -ENOTSUP; } } static int bmi08x_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmi08x_gyro_data *bmi08x = dev->data; size_t i; int ret; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_GYRO_XYZ) { LOG_DBG("Unsupported sensor channel"); return -ENOTSUP; } ret = bmi08x_gyro_read(dev, BMI08X_REG_GYRO_X_LSB, (uint8_t *)bmi08x->gyr_sample, sizeof(bmi08x->gyr_sample)); if (ret < 0) { return ret; } /* convert samples to cpu endianness */ for (i = 0; i < ARRAY_SIZE(bmi08x->gyr_sample); i++) { bmi08x->gyr_sample[i] = sys_le16_to_cpu(bmi08x->gyr_sample[i]); } return ret; } static void bmi08x_to_fixed_point(int16_t raw_val, uint16_t scale, struct sensor_value *val) { int32_t converted_val; /* * maximum converted value we can get is: max(raw_val) * max(scale) * max(raw_val) = +/- 2^15 * max(scale) = 4785 * max(converted_val) = 156794880 which is less than 2^31 */ converted_val = raw_val * scale; val->val1 = converted_val / 1000000; val->val2 = converted_val % 1000000; } static void bmi08x_channel_convert(enum sensor_channel chan, uint16_t scale, uint16_t *raw_xyz, struct sensor_value *val) { int i; uint8_t ofs_start, ofs_stop; switch (chan) { case SENSOR_CHAN_GYRO_X: ofs_start = ofs_stop = 0U; break; case SENSOR_CHAN_GYRO_Y: ofs_start = ofs_stop = 1U; break; case SENSOR_CHAN_GYRO_Z: ofs_start = ofs_stop = 2U; break; default: ofs_start = 0U; ofs_stop = 2U; break; } for (i = ofs_start; i <= ofs_stop; i++, val++) { bmi08x_to_fixed_point(raw_xyz[i], scale, val); } } static inline void bmi08x_gyr_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmi08x_gyro_data *bmi08x = dev->data; bmi08x_channel_convert(chan, bmi08x->scale, bmi08x->gyr_sample, val); } static int bmi08x_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif switch ((int16_t)chan) { case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: bmi08x_gyr_channel_get(dev, chan, val); return 0; default: LOG_DBG("Channel not supported."); return -ENOTSUP; } } #ifdef CONFIG_PM_DEVICE static int bmi08x_gyro_pm_action(const struct device *dev, enum pm_device_action action) { uint8_t reg_val; int ret; switch (action) { case PM_DEVICE_ACTION_RESUME: reg_val = BMI08X_GYRO_PM_NORMAL; break; case PM_DEVICE_ACTION_SUSPEND: reg_val = BMI08X_GYRO_PM_SUSPEND; break; default: return -ENOTSUP; } ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_LPM1, reg_val); if (ret < 0) { LOG_ERR("Failed to set power mode"); return ret; } k_msleep(BMI08X_GYRO_POWER_MODE_CONFIG_DELAY); return ret; } #endif /* CONFIG_PM_DEVICE */ static const struct sensor_driver_api bmi08x_api = { .attr_set = bmi08x_attr_set, #ifdef CONFIG_BMI08X_GYRO_TRIGGER .trigger_set = bmi08x_trigger_set_gyr, #endif .sample_fetch = bmi08x_sample_fetch, .channel_get = bmi08x_channel_get, }; int bmi08x_gyro_init(const struct device *dev) { const struct bmi08x_gyro_config *config = dev->config; uint8_t val = 0U; int ret; ret = bmi08x_bus_check(dev); if (ret < 0) { LOG_ERR("Bus not ready for '%s'", dev->name); return ret; } /* reboot the chip */ ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_SOFTRESET, BMI08X_SOFT_RESET_CMD); if (ret < 0) { LOG_ERR("Cannot reboot chip."); return ret; } k_msleep(BMI08X_GYRO_SOFTRESET_DELAY); ret = bmi08x_gyro_byte_read(dev, BMI08X_REG_GYRO_CHIP_ID, &val); if (ret < 0) { LOG_ERR("Failed to read chip id."); return ret; } if (val != BMI08X_GYRO_CHIP_ID) { LOG_ERR("Unsupported chip detected (0x%02x)!", val); return -ENODEV; } /* set gyro default range */ ret = bmi08x_gyr_range_set(dev, config->gyro_fs); if (ret < 0) { LOG_ERR("Cannot set default range for gyroscope."); return ret; } /* set gyro default bandwidth */ ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_BANDWIDTH, config->gyro_hz); if (ret < 0) { LOG_ERR("Failed to set gyro's default ODR."); return ret; } #ifdef CONFIG_BMI08X_GYRO_TRIGGER ret = bmi08x_gyr_trigger_mode_init(dev); if (ret < 0) { LOG_ERR("Cannot set up trigger mode."); return ret; } #endif /* with BMI08X_DATA_SYNC set, it is expected that the INT3 or INT4 is wired to either INT1 * or INT2 */ #if defined(CONFIG_BMI08X_GYRO_TRIGGER) || BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC /* set gyro ints */ /* set ints */ ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_INT_CTRL, 0x80); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_INT3_INT4_IO_CONF, config->int3_4_conf_io); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } ret = bmi08x_gyro_byte_write(dev, BMI08X_REG_GYRO_INT3_INT4_IO_MAP, config->int3_4_map); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } #endif return ret; } #define BMI08X_CONFIG_SPI(inst) \ .bus.spi = SPI_DT_SPEC_INST_GET( \ inst, SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8), 2), #define BMI08X_CONFIG_I2C(inst) .bus.i2c = I2C_DT_SPEC_INST_GET(inst), #define BMI08X_GYRO_TRIG(inst) \ .int3_4_map = DT_INST_PROP(inst, int3_4_map_io), \ .int3_4_conf_io = DT_INST_PROP(inst, int3_4_conf_io), #if BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC /* the bmi08x-gyro should not have trigger mode with data-sync enabled */ BUILD_ASSERT(CONFIG_BMI08X_GYRO_TRIGGER_NONE, "Only none trigger type allowed for bmi08x-gyro with data-sync enabled"); /* with data-sync, one of the int pins should be wired directory to the accel's int pins, their * config should be defined */ #define BMI08X_GYRO_TRIGGER_PINS(inst) BMI08X_GYRO_TRIG(inst) #else #define BMI08X_GYRO_TRIGGER_PINS(inst) \ IF_ENABLED(CONFIG_BMI08X_GYRO_TRIGGER, (BMI08X_GYRO_TRIG(inst))) #endif #define BMI08X_CREATE_INST(inst) \ \ static struct bmi08x_gyro_data bmi08x_drv_##inst; \ \ static const struct bmi08x_gyro_config bmi08x_config_##inst = { \ COND_CODE_1(DT_INST_ON_BUS(inst, spi), (BMI08X_CONFIG_SPI(inst)), \ (BMI08X_CONFIG_I2C(inst))) \ .api = COND_CODE_1(DT_INST_ON_BUS(inst, spi), (&bmi08x_spi_api), \ (&bmi08x_i2c_api)), \ IF_ENABLED(CONFIG_BMI08X_GYRO_TRIGGER, \ (.int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios),)) \ .gyro_hz = DT_INST_ENUM_IDX(inst, gyro_hz), \ BMI08X_GYRO_TRIGGER_PINS(inst).gyro_fs = DT_INST_PROP(inst, gyro_fs), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, bmi08x_gyro_pm_action); \ SENSOR_DEVICE_DT_INST_DEFINE(inst, bmi08x_gyro_init, PM_DEVICE_DT_INST_GET(inst), \ &bmi08x_drv_##inst, &bmi08x_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &bmi08x_api); /* Create the struct device for every status "okay" node in the devicetree. */ DT_INST_FOREACH_STATUS_OKAY(BMI08X_CREATE_INST) ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x_gyro.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,113
```c /* Bosch BMI08X inertial measurement unit driver * * */ #include <zephyr/drivers/sensor.h> #include <zephyr/pm/device.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/byteorder.h> #define DT_DRV_COMPAT bosch_bmi08x_accel #include "bmi08x.h" #include "bmi08x_config_file.h" LOG_MODULE_REGISTER(BMI08X_ACCEL, CONFIG_SENSOR_LOG_LEVEL); #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) static int bmi08x_accel_transceive_i2c(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_accel_config *bmi08x = dev->config; if (!write) { return i2c_write_read_dt(&bmi08x->bus.i2c, &reg, 1, data, length); } if (length > CONFIG_BMI08X_I2C_WRITE_BURST_SIZE) { return -EINVAL; } uint8_t buf[1 + CONFIG_BMI08X_I2C_WRITE_BURST_SIZE]; buf[0] = reg; memcpy(&buf[1], data, length); return i2c_write_dt(&bmi08x->bus.i2c, buf, 1 + length); } #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC static int bmi08x_stream_transfer_write_i2c(const struct device *dev, uint16_t index, const uint8_t *stream_data, uint16_t stream_length) { uint8_t asic_msb = (uint8_t)((index / 2) >> 4); uint8_t asic_lsb = ((index / 2) & 0x0F); int ret; ret = bmi08x_accel_byte_write(dev, BMI08X_ACCEL_RESERVED_5B_REG, asic_lsb); if (ret != 0) { LOG_ERR("Cannot write index"); return ret; } ret = bmi08x_accel_byte_write(dev, BMI08X_ACCEL_RESERVED_5C_REG, asic_msb); if (ret != 0) { LOG_ERR("Cannot write index"); return ret; } ret = bmi08x_accel_write(dev, BMI08X_ACCEL_FEATURE_CFG_REG, (uint8_t *)stream_data, stream_length); if (ret != 0) { LOG_ERR("Cannot write configuration for accelerometer."); return ret; } return ret; } static int bmi08x_write_config_file_i2c(const struct device *dev) { const uint8_t *data = bmi08x_config_file; uint16_t length = sizeof(bmi08x_config_file); uint16_t index = 0; int ret = 0; while (length != 0) { uint16_t len1 = length; if (len1 > CONFIG_BMI08X_I2C_WRITE_BURST_SIZE) { len1 = CONFIG_BMI08X_I2C_WRITE_BURST_SIZE; } ret = bmi08x_stream_transfer_write_i2c(dev, index, data, len1); if (ret != 0) { return ret; } index += len1; data += len1; length -= len1; } return ret; } #endif static int bmi08x_bus_check_i2c(const union bmi08x_bus *bus) { return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV; } static const struct bmi08x_accel_bus_io bmi08x_i2c_api = {.check = bmi08x_bus_check_i2c, .transceive = bmi08x_accel_transceive_i2c, #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC .write_config_file = bmi08x_write_config_file_i2c #endif }; #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */ #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) static int bmi08x_accel_transceive_spi(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_accel_config *bmi08x = dev->config; const struct spi_buf tx_buf[2] = {{.buf = &reg, .len = 1}, {.buf = data, .len = length}}; const struct spi_buf_set tx = {.buffers = tx_buf, .count = write ? 2 : 1}; if (!write) { uint16_t dummy; const struct spi_buf rx_buf[2] = {{.buf = &dummy, .len = 2}, {.buf = data, .len = length}}; const struct spi_buf_set rx = {.buffers = rx_buf, .count = 2}; return spi_transceive_dt(&bmi08x->bus.spi, &tx, &rx); } return spi_write_dt(&bmi08x->bus.spi, &tx); } #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC static int bmi08x_write_config_file_spi(const struct device *dev) { int ret; ret = bmi08x_accel_byte_write(dev, BMI08X_ACCEL_RESERVED_5B_REG, 0); if (ret < 0) { LOG_ERR("Cannot write index"); return ret; } ret = bmi08x_accel_byte_write(dev, BMI08X_ACCEL_RESERVED_5C_REG, 0); if (ret < 0) { LOG_ERR("Cannot write index"); return ret; } /* write config file */ ret = bmi08x_accel_write(dev, BMI08X_ACCEL_FEATURE_CFG_REG, (uint8_t *)bmi08x_config_file, sizeof(bmi08x_config_file)); if (ret < 0) { LOG_ERR("Cannot write configuration for accelerometer."); return ret; } return ret; } #endif static int bmi08x_bus_check_spi(const union bmi08x_bus *bus) { return spi_is_ready_dt(&bus->spi) ? 0 : -ENODEV; } static int bmi08x_bus_init_spi(const struct device *dev) { uint8_t val; int ret; /* do a dummy read from 0x7F to activate SPI */ ret = bmi08x_accel_byte_read(dev, 0x7F, &val); if (ret < 0) { LOG_ERR("Cannot read from 0x7F.."); return ret; } k_usleep(100); return ret; } static const struct bmi08x_accel_bus_io bmi08x_spi_api = {.check = bmi08x_bus_check_spi, .bus_init = bmi08x_bus_init_spi, .transceive = bmi08x_accel_transceive_spi, #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC .write_config_file = bmi08x_write_config_file_spi #endif }; #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */ static inline int bmi08x_bus_check(const struct device *dev) { const struct bmi08x_accel_config *config = dev->config; return config->api->check(&config->bus); } static inline int bmi08x_bus_init(const struct device *dev) { const struct bmi08x_accel_config *config = dev->config; /* optional, only needed to initialize SPI according to datasheet */ if (config->api->bus_init) { return config->api->bus_init(dev); } return 0; } static int bmi08x_accel_transceive(const struct device *dev, uint8_t reg, bool write, void *data, size_t length) { const struct bmi08x_accel_config *config = dev->config; return config->api->transceive(dev, reg, write, data, length); } int bmi08x_accel_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len) { return bmi08x_accel_transceive(dev, reg_addr | BIT(7), false, data, len); } int bmi08x_accel_write(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint16_t len) { return bmi08x_accel_transceive(dev, reg_addr, true, data, len); } int bmi08x_accel_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte) { return bmi08x_accel_transceive(dev, reg_addr | BIT(7), false, byte, 1); } static int bmi08x_accel_word_read(const struct device *dev, uint8_t reg_addr, uint16_t *word) { int ret; ret = bmi08x_accel_transceive(dev, reg_addr | BIT(7), false, word, 2); if (ret != 0) { return ret; } *word = sys_le16_to_cpu(*word); return ret; } int bmi08x_accel_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte) { return bmi08x_accel_transceive(dev, reg_addr & 0x7F, true, &byte, 1); } int bmi08x_accel_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word) { uint8_t tx_word[2] = {(uint8_t)(word & 0xff), (uint8_t)(word >> 8)}; return bmi08x_accel_transceive(dev, reg_addr & 0x7F, true, tx_word, 2); } int bmi08x_accel_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val) { uint8_t old_val; int ret; ret = bmi08x_accel_byte_read(dev, reg_addr, &old_val); if (ret < 0) { return ret; } return bmi08x_accel_byte_write(dev, reg_addr, (old_val & ~mask) | ((val << pos) & mask)); } static int bmi08x_acc_odr_set(const struct device *dev, uint16_t freq_int, uint16_t freq_milli) { int odr = bmi08x_freq_to_odr_val(freq_int, freq_milli); if (odr < BMI08X_ACCEL_ODR_12_5_HZ) { return odr; } return bmi08x_accel_reg_field_update(dev, BMI08X_REG_ACCEL_CONF, 0, BMI08X_ACCEL_ODR_MASK, (uint8_t)odr); } static const struct bmi08x_range bmi085_acc_range_map[] = { {2, BMI085_ACCEL_RANGE_2G}, {4, BMI085_ACCEL_RANGE_4G}, {8, BMI085_ACCEL_RANGE_8G}, {16, BMI085_ACCEL_RANGE_16G}, }; #define BMI085_ACC_RANGE_MAP_SIZE ARRAY_SIZE(bmi085_acc_range_map) static const struct bmi08x_range bmi088_acc_range_map[] = { {3, BMI088_ACCEL_RANGE_3G}, {6, BMI088_ACCEL_RANGE_6G}, {12, BMI088_ACCEL_RANGE_12G}, {24, BMI088_ACCEL_RANGE_24G}, }; #define BMI088_ACC_RANGE_MAP_SIZE ARRAY_SIZE(bmi088_acc_range_map) static int bmi08x_acc_range_set(const struct device *dev, int32_t range) { struct bmi08x_accel_data *data = dev->data; int32_t reg_val = -1; int ret; if (data->accel_chip_id == BMI085_ACCEL_CHIP_ID) { reg_val = bmi08x_range_to_reg_val(range, bmi085_acc_range_map, BMI085_ACC_RANGE_MAP_SIZE); } else if (data->accel_chip_id == BMI088_ACCEL_CHIP_ID) { reg_val = bmi08x_range_to_reg_val(range, bmi088_acc_range_map, BMI088_ACC_RANGE_MAP_SIZE); } else { return -ENODEV; } if (reg_val < 0) { return reg_val; } ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_RANGE, reg_val & 0xff); if (ret < 0) { return ret; } data->scale = BMI08X_ACC_SCALE(range); return ret; } static int bmi08x_acc_config(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { switch (attr) { case SENSOR_ATTR_FULL_SCALE: return bmi08x_acc_range_set(dev, sensor_ms2_to_g(val)); case SENSOR_ATTR_SAMPLING_FREQUENCY: return bmi08x_acc_odr_set(dev, val->val1, val->val2 / 1000); default: LOG_DBG("Accel attribute not supported."); return -ENOTSUP; } } static int bmi08x_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif switch (chan) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: return bmi08x_acc_config(dev, chan, attr, val); default: LOG_DBG("attr_set() not supported on this channel."); return -ENOTSUP; } } static int bmi08x_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmi08x_accel_data *data = dev->data; size_t i; int ret; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_ACCEL_XYZ) { LOG_DBG("Unsupported sensor channel"); return -ENOTSUP; } #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif pm_device_busy_set(dev); ret = bmi08x_accel_read(dev, BMI08X_REG_ACCEL_X_LSB, (uint8_t *)data->acc_sample, sizeof(data->acc_sample)); if (ret < 0) { pm_device_busy_clear(dev); return ret; } /* convert samples to cpu endianness */ for (i = 0; i < ARRAY_SIZE(data->acc_sample); i++) { data->acc_sample[i] = sys_le16_to_cpu(data->acc_sample[i]); } pm_device_busy_clear(dev); return ret; } static void bmi08x_to_fixed_point(int16_t raw_val, uint16_t scale, struct sensor_value *val) { int32_t converted_val; /* * maximum converted value we can get is: max(raw_val) * max(scale) * max(raw_val) = +/- 2^15 * max(scale) = 4785 * max(converted_val) = 156794880 which is less than 2^31 */ converted_val = raw_val * scale; val->val1 = converted_val / 1000000; val->val2 = converted_val % 1000000; } static void bmi08x_channel_convert(enum sensor_channel chan, uint16_t scale, uint16_t *raw_xyz, struct sensor_value *val) { int i; uint8_t ofs_start, ofs_stop; switch (chan) { case SENSOR_CHAN_ACCEL_X: ofs_start = ofs_stop = 0U; break; case SENSOR_CHAN_ACCEL_Y: ofs_start = ofs_stop = 1U; break; case SENSOR_CHAN_ACCEL_Z: ofs_start = ofs_stop = 2U; break; default: ofs_start = 0U; ofs_stop = 2U; break; } for (i = ofs_start; i <= ofs_stop; i++, val++) { bmi08x_to_fixed_point(raw_xyz[i], scale, val); } } static inline void bmi08x_acc_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmi08x_accel_data *data = dev->data; bmi08x_channel_convert(chan, data->scale, data->acc_sample, val); } static int bmi08x_temp_channel_get(const struct device *dev, struct sensor_value *val) { uint16_t temp_raw = 0U; int32_t temp_micro = 0; int ret; ret = bmi08x_accel_word_read(dev, BMI08X_REG_TEMP_MSB, &temp_raw); if (ret < 0) { return ret; } /* the scale is 1/2^5/LSB = 31250 micro degrees */ temp_micro = BMI08X_TEMP_OFFSET * 1000000ULL + temp_raw * 31250ULL; val->val1 = temp_micro / 1000000ULL; val->val2 = temp_micro % 1000000ULL; return ret; } static int bmi08x_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif switch ((int16_t)chan) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: bmi08x_acc_channel_get(dev, chan, val); return 0; case SENSOR_CHAN_DIE_TEMP: return bmi08x_temp_channel_get(dev, val); default: LOG_DBG("Channel not supported."); return -ENOTSUP; } return 0; } #ifdef CONFIG_PM_DEVICE static int bmi08x_accel_pm_action(const struct device *dev, enum pm_device_action action) { uint8_t conf_reg_val; uint8_t ctrl_reg_val; int ret; switch (action) { case PM_DEVICE_ACTION_RESUME: conf_reg_val = BMI08X_ACCEL_PM_ACTIVE; ctrl_reg_val = BMI08X_ACCEL_POWER_ENABLE; break; case PM_DEVICE_ACTION_SUSPEND: conf_reg_val = BMI08X_ACCEL_PM_SUSPEND; ctrl_reg_val = BMI08X_ACCEL_POWER_DISABLE; break; default: return -ENOTSUP; } ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CONF, conf_reg_val); if (ret < 0) { LOG_ERR("Failed to set conf power mode"); return ret; } k_msleep(BMI08X_POWER_CONFIG_DELAY); ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CTRL, ctrl_reg_val); if (ret < 0) { LOG_ERR("Failed to set ctrl power mode"); return ret; } k_msleep(BMI08X_POWER_CONFIG_DELAY); return ret; } #endif /* CONFIG_PM_DEVICE */ static const struct sensor_driver_api bmi08x_api = { .attr_set = bmi08x_attr_set, #ifdef CONFIG_BMI08X_ACCEL_TRIGGER .trigger_set = bmi08x_trigger_set_acc, #endif .sample_fetch = bmi08x_sample_fetch, .channel_get = bmi08x_channel_get, }; #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC static int bmi08x_apply_sync_binary_config(const struct device *dev) { const struct bmi08x_accel_config *config = dev->config; int ret; ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CONF, BMI08X_ACCEL_PM_ACTIVE); if (ret < 0) { LOG_ERR("Cannot deactivate advanced power save mode."); return ret; } /* required when switching power modes */ k_msleep(BMI08X_POWER_CONFIG_DELAY); /* deactivate accel, otherwise post processing can not be enabled safely */ ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CTRL, BMI08X_ACCEL_POWER_DISABLE); if (ret < 0) { LOG_ERR("Cannot deactivate accel."); return ret; } /* required when switching power modes */ k_msleep(BMI08X_POWER_CONFIG_DELAY); /* disable config loading */ ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INIT_CTRL, BMI08X_ACCEL_INIT_CTRL_DISABLE); if (ret < 0) { LOG_ERR("Cannot disable config loading."); return ret; } if (config->api->write_config_file(dev) != 0) { LOG_ERR("Cannot write configuration for accelerometer."); return -EIO; } k_msleep(5U); ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INIT_CTRL, BMI08X_ACCEL_INIT_CTRL_ENABLE); if (ret < 0) { LOG_ERR("Cannot write configuration for accelerometer."); return ret; } k_msleep(BMI08X_ASIC_INIT_TIME_MS); /* check config initialization status */ uint8_t val; ret = bmi08x_accel_byte_read(dev, BMI08X_REG_ACCEL_INTERNAL_STAT, &val); if (ret < 0) { LOG_ERR("Cannot write configuration for accelerometer."); return ret; } if (val != 1) { LOG_ERR("Configuration stream error."); return -EIO; } /* write feature configuration */ uint8_t fdata[8]; ret = bmi08x_accel_read(dev, BMI08X_ACCEL_FEATURE_CFG_REG, fdata, 6); if (ret < 0) { LOG_ERR("Cannot read configuration for accelerometer."); return ret; } fdata[4] = config->data_sync; fdata[5] = 0x00; ret = bmi08x_accel_write(dev, BMI08X_ACCEL_FEATURE_CFG_REG, fdata, 6); if (ret < 0) { LOG_ERR("Cannot write configuration for accelerometer."); return ret; } k_msleep(100U); ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CTRL, BMI08X_ACCEL_POWER_ENABLE); if (ret < 0) { LOG_ERR("Cannot activate accel."); return ret; } /* required when switching power modes */ k_msleep(BMI08X_POWER_CONFIG_DELAY); return ret; } #endif int bmi08x_accel_init(const struct device *dev) { const struct bmi08x_accel_config *config = dev->config; struct bmi08x_accel_data *data = dev->data; uint8_t val = 0U; int ret; ret = bmi08x_bus_check(dev); if (ret < 0) { LOG_ERR("Bus not ready for '%s'", dev->name); return ret; } /* reboot the chip */ ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_SOFTRESET, BMI08X_SOFT_RESET_CMD); if (ret < 0) { LOG_ERR("Cannot reboot chip."); return ret; } k_msleep(BMI08X_ACCEL_SOFTRESET_DELAY_MS); ret = bmi08x_bus_init(dev); if (ret < 0) { LOG_ERR("Can't initialize bus for %s", dev->name); return ret; } ret = bmi08x_accel_byte_read(dev, BMI08X_REG_ACCEL_CHIP_ID, &val); if (ret < 0) { LOG_ERR("Failed to read chip id."); return ret; } if ((val != BMI085_ACCEL_CHIP_ID) && (val != BMI088_ACCEL_CHIP_ID)) { LOG_ERR("Unsupported chip detected (0x%02x)!", val); return -ENODEV; } data->accel_chip_id = val; /* enable power */ ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CONF, BMI08X_ACCEL_PM_ACTIVE); if (ret < 0) { LOG_ERR("Failed to set conf power mode"); return ret; } k_msleep(BMI08X_POWER_CONFIG_DELAY); ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_PWR_CTRL, BMI08X_ACCEL_POWER_ENABLE); if (ret < 0) { LOG_ERR("Failed to set ctrl power mode"); return ret; } k_msleep(BMI08X_POWER_CONFIG_DELAY); #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC if (config->data_sync != 0) { ret = bmi08x_apply_sync_binary_config(dev); if (ret < 0) { return ret; } } #endif /* set accelerometer default range, divide by two because the dts contains both bmi085 and * bmi088 valid values even values in the enum are for the bmi085 and odd values are for the * bmi088 */ ret = bmi08x_acc_range_set(dev, config->accel_fs); if (ret < 0) { LOG_ERR("Cannot set default range for accelerometer."); return ret; } /* set accelerometer default odr */ /* add 5 to offset from the dts enum */ ret = bmi08x_accel_reg_field_update(dev, BMI08X_REG_ACCEL_CONF, 0, BMI08X_ACCEL_ODR_MASK, config->accel_hz); if (ret < 0) { LOG_ERR("Failed to set accel's default ODR."); return ret; } #ifdef CONFIG_BMI08X_ACCEL_TRIGGER ret = bmi08x_acc_trigger_mode_init(dev); if (ret < 0) { LOG_ERR("Cannot set up trigger mode."); return ret; } #endif return ret; } #define BMI08X_CONFIG_SPI(inst) \ .bus.spi = SPI_DT_SPEC_INST_GET( \ inst, SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8), 2), #define BMI08X_CONFIG_I2C(inst) .bus.i2c = I2C_DT_SPEC_INST_GET(inst), #define BMI08X_ACCEL_TRIG(inst) \ .int1_map = DT_INST_PROP(inst, int1_map_io), .int2_map = DT_INST_PROP(inst, int2_map_io), \ .int1_conf_io = DT_INST_PROP(inst, int1_conf_io), \ .int2_conf_io = DT_INST_PROP(inst, int2_conf_io), /* verify the bmi08x-accel is paired with a bmi08x-gyro */ #define BMI08X_VERIFY_DATA_SYNC(inst) \ BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_INST_PHANDLE(inst, data_sync), bosch_bmi08x_gyro) != 0, \ "bmi08x-accel data sync not paired with a bmi08x-gyro") /* * verify data sync odr, the only valid odr combinitions with the gyro are * (gyro-hz == "400_47" and accel-hz == "400") or (gyro-hz == "1000_116" and accel-hz == "800") * or ((gyro-hz == "2000_230" or gyro-hz == "2000_532") and accel-hz == "1600") */ #define BMI08X_GYRO_ODR(inst) DT_ENUM_IDX(DT_INST_PHANDLE(inst, data_sync), gyro_hz) #define BMI08X_ACCEL_ODR(inst) DT_INST_ENUM_IDX(inst, accel_hz) /* As the dts uses strings to define the definition, ints must be used for comparision */ #define BMI08X_VERIFY_DATA_SYNC_ODR(inst) \ BUILD_ASSERT((BMI08X_GYRO_ODR(inst) == 3 && BMI08X_ACCEL_ODR(inst) == 5) || \ (BMI08X_GYRO_ODR(inst) == 2 && BMI08X_ACCEL_ODR(inst) == 6) || \ ((BMI08X_GYRO_ODR(inst) == 1 || BMI08X_GYRO_ODR(inst) == 0) && \ BMI08X_ACCEL_ODR(inst) == 7), \ "Invalid gyro and accel odr for data-sync") /* Assert if the gyro does not have data-sync enabled */ #define BMI08X_VERIFY_GYRO_DATA_SYNC_EN(inst) \ BUILD_ASSERT(DT_PROP(DT_INST_PHANDLE(inst, data_sync), data_sync), \ "paired bmi08x-gyro does not have data-sync enabled") /* infer the data-sync value from the gyro and accel odr 2000=1, 1000=2, 400=3, otherwise it is 0 if * it is not enabled. the build_assert should prevent any invalid values when it is enabled */ #define BMI08X_DATA_SYNC_REG_VAL(inst) \ (BMI08X_GYRO_ODR(inst) == 3 && BMI08X_ACCEL_ODR(inst) == 5) ? 3 \ : (BMI08X_GYRO_ODR(inst) == 2 && BMI08X_ACCEL_ODR(inst) == 6) ? 2 \ : ((BMI08X_GYRO_ODR(inst) == 1 || BMI08X_GYRO_ODR(inst) == 0) && \ BMI08X_ACCEL_ODR(inst) == 7) \ ? 1 \ : 0 /* define the .data_sync in the driver config */ #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC /* if another bmi08x as the data sync enabled, and one doesn't, it will get the value of 0 and won't * have the config file sent over */ #define BMI08X_DATA_SYNC_REG(inst) \ .data_sync = COND_CODE_1(BMI08X_ACCEL_DATA_SYNC_EN(inst), \ (BMI08X_DATA_SYNC_REG_VAL(inst)), (0)), #define BMI08X_ACCEL_TRIGGER_PINS(inst) BMI08X_ACCEL_TRIG(inst) #else #define BMI08X_DATA_SYNC_REG(inst) #define BMI08X_ACCEL_TRIGGER_PINS(inst) \ IF_ENABLED(CONFIG_BMI08X_ACCEL_TRIGGER, (BMI08X_ACCEL_TRIG(inst))) #endif #define BMI08X_CREATE_INST(inst) \ \ IF_ENABLED(BMI08X_ACCEL_DATA_SYNC_EN(inst), (BMI08X_VERIFY_DATA_SYNC(inst);)) \ IF_ENABLED(BMI08X_ACCEL_DATA_SYNC_EN(inst), (BMI08X_VERIFY_DATA_SYNC_ODR(inst);)) \ IF_ENABLED(BMI08X_ACCEL_DATA_SYNC_EN(inst), (BMI08X_VERIFY_GYRO_DATA_SYNC_EN(inst);)) \ \ static struct bmi08x_accel_data bmi08x_drv_##inst; \ \ static const struct bmi08x_accel_config bmi08x_config_##inst = { \ COND_CODE_1(DT_INST_ON_BUS(inst, spi), (BMI08X_CONFIG_SPI(inst)), \ (BMI08X_CONFIG_I2C(inst))) \ .api = COND_CODE_1(DT_INST_ON_BUS(inst, spi), (&bmi08x_spi_api), \ (&bmi08x_i2c_api)), \ IF_ENABLED(CONFIG_BMI08X_ACCEL_TRIGGER, \ (.int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios),)) \ BMI08X_ACCEL_TRIGGER_PINS(inst) \ .accel_hz = DT_INST_ENUM_IDX(inst, accel_hz) + 5, \ .accel_fs = DT_INST_PROP(inst, accel_fs), BMI08X_DATA_SYNC_REG(inst)}; \ \ PM_DEVICE_DT_INST_DEFINE(inst, bmi08x_accel_pm_action); \ SENSOR_DEVICE_DT_INST_DEFINE(inst, bmi08x_accel_init, PM_DEVICE_DT_INST_GET(inst), \ &bmi08x_drv_##inst, &bmi08x_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &bmi08x_api); /* Create the struct device for every status "okay" node in the devicetree. */ DT_INST_FOREACH_STATUS_OKAY(BMI08X_CREATE_INST) ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x_accel.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
6,958
```c /* Bosch BMI08X inertial measurement unit driver * * */ #include <zephyr/kernel.h> #include "bmi08x.h" /* * Output data rate map with allowed frequencies: * freq = freq_int + freq_milli / 1000 * * Since we don't need a finer frequency resolution than milliHz, use uint16_t * to save some flash. */ static const struct { uint16_t freq_int; uint16_t freq_milli; /* User should convert to uHz before setting the * SENSOR_ATTR_SAMPLING_FREQUENCY attribute. */ } bmi08x_odr_map[] = { {0, 0}, {0, 780}, {1, 562}, {3, 120}, {6, 250}, {12, 500}, {25, 0}, {50, 0}, {100, 0}, {200, 0}, {400, 0}, {800, 0}, {1600, 0}, {3200, 0}, }; int bmi08x_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli) { size_t i; /* An ODR of 0 Hz is not allowed */ if (freq_int == 0U && freq_milli == 0U) { return -EINVAL; } for (i = 0; i < ARRAY_SIZE(bmi08x_odr_map); i++) { if (freq_int < bmi08x_odr_map[i].freq_int || (freq_int == bmi08x_odr_map[i].freq_int && freq_milli <= bmi08x_odr_map[i].freq_milli)) { return i; } } return -EINVAL; } int32_t bmi08x_range_to_reg_val(uint16_t range, const struct bmi08x_range *range_map, uint16_t range_map_size) { int i; for (i = 0; i < range_map_size; i++) { if (range <= range_map[i].range) { return range_map[i].reg_val; } } return -EINVAL; } int32_t bmi08x_reg_val_to_range(uint8_t reg_val, const struct bmi08x_range *range_map, uint16_t range_map_size) { int i; for (i = 0; i < range_map_size; i++) { if (reg_val == range_map[i].reg_val) { return range_map[i].range; } } return -EINVAL; } ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
543
```c /* Bosch BMI08X inertial measurement unit driver, trigger implementation * * */ #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/pm/device.h> #include <zephyr/kernel.h> #define DT_DRV_COMPAT bosch_bmi08x_gyro #include "bmi08x.h" #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(BMI08X_GYRO, CONFIG_SENSOR_LOG_LEVEL); static void bmi08x_handle_drdy_gyr(const struct device *dev) { struct bmi08x_gyro_data *data = dev->data; #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return; } #endif if (data->handler_drdy_gyr) { data->handler_drdy_gyr(dev, data->drdy_trig_gyr); } } static void bmi08x_handle_interrupts_gyr(void *arg) { const struct device *dev = (const struct device *)arg; bmi08x_handle_drdy_gyr(dev); } #ifdef CONFIG_BMI08X_GYRO_TRIGGER_OWN_THREAD static void bmi08x_gyr_thread_main(void *arg1, void *unused1, void *unused2) { k_thread_name_set(NULL, "bmi08x_gyr_trig"); ARG_UNUSED(unused1); ARG_UNUSED(unused2); const struct device *dev = (const struct device *)arg1; struct bmi08x_gyro_data *data = dev->data; while (1) { k_sem_take(&data->sem, K_FOREVER); bmi08x_handle_interrupts_gyr((void *)dev); } } #endif #ifdef CONFIG_BMI08X_GYRO_TRIGGER_GLOBAL_THREAD static void bmi08x_gyr_work_handler(struct k_work *work) { struct bmi08x_gyro_data *data = CONTAINER_OF(work, struct bmi08x_gyro_data, work); bmi08x_handle_interrupts_gyr((void *)data->dev); } #endif static void bmi08x_gyr_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { struct bmi08x_gyro_data *data = CONTAINER_OF(cb, struct bmi08x_gyro_data, gpio_cb); ARG_UNUSED(port); ARG_UNUSED(pin); #if defined(CONFIG_BMI08X_GYRO_TRIGGER_OWN_THREAD) k_sem_give(&data->sem); #elif defined(CONFIG_BMI08X_GYRO_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #endif } int bmi08x_trigger_set_gyr(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi08x_gyro_data *data = dev->data; if ((trig->chan == SENSOR_CHAN_GYRO_XYZ) && (trig->type == SENSOR_TRIG_DATA_READY)) { data->handler_drdy_gyr = handler; data->drdy_trig_gyr = trig; return 0; } return -ENOTSUP; } int bmi08x_gyr_trigger_mode_init(const struct device *dev) { struct bmi08x_gyro_data *data = dev->data; const struct bmi08x_gyro_config *cfg = dev->config; int ret; if (!gpio_is_ready_dt(&cfg->int_gpio)) { LOG_ERR("GPIO device not ready"); return -ENODEV; } #if defined(CONFIG_BMI08X_GYRO_TRIGGER_OWN_THREAD) k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&data->thread, data->thread_stack, CONFIG_BMI08X_GYRO_THREAD_STACK_SIZE, bmi08x_gyr_thread_main, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BMI08X_GYRO_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMI08X_GYRO_TRIGGER_GLOBAL_THREAD) data->work.handler = bmi08x_gyr_work_handler; data->dev = dev; #endif gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INPUT); gpio_init_callback(&data->gpio_cb, bmi08x_gyr_gpio_callback, BIT(cfg->int_gpio.pin)); ret = gpio_add_callback(cfg->int_gpio.port, &data->gpio_cb); if (ret < 0) { LOG_ERR("Failed to set gpio callback."); return ret; } gpio_pin_interrupt_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); return ret; } ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x_gyro_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
982
```c /* Bosch BMI08X inertial measurement unit driver, trigger implementation * * */ #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/pm/device.h> #include <zephyr/kernel.h> #define DT_DRV_COMPAT bosch_bmi08x_accel #include "bmi08x.h" #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(BMI08X_ACCEL, CONFIG_SENSOR_LOG_LEVEL); static void bmi08x_handle_drdy_acc(const struct device *dev) { struct bmi08x_accel_data *data = dev->data; #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return; } #endif if (data->handler_drdy_acc) { data->handler_drdy_acc(dev, data->drdy_trig_acc); } } static void bmi08x_handle_interrupts_acc(void *arg) { const struct device *dev = (const struct device *)arg; bmi08x_handle_drdy_acc(dev); } #ifdef CONFIG_BMI08X_ACCEL_TRIGGER_OWN_THREAD static void bmi08x_acc_thread_main(void *arg1, void *unused1, void *unused2) { k_thread_name_set(NULL, "bmi08x_acc_trig"); ARG_UNUSED(unused1); ARG_UNUSED(unused2); const struct device *dev = (const struct device *)arg1; struct bmi08x_accel_data *data = dev->data; while (1) { k_sem_take(&data->sem, K_FOREVER); bmi08x_handle_interrupts_acc((void *)dev); } } #endif #ifdef CONFIG_BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD static void bmi08x_acc_work_handler(struct k_work *work) { struct bmi08x_accel_data *data = CONTAINER_OF(work, struct bmi08x_accel_data, work); bmi08x_handle_interrupts_acc((void *)data->dev); } #endif static void bmi08x_acc_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { struct bmi08x_accel_data *data = CONTAINER_OF(cb, struct bmi08x_accel_data, gpio_cb); ARG_UNUSED(port); ARG_UNUSED(pin); #if defined(CONFIG_BMI08X_ACCEL_TRIGGER_OWN_THREAD) k_sem_give(&data->sem); #elif defined(CONFIG_BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #endif } int bmi08x_trigger_set_acc(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi08x_accel_data *data = dev->data; if ((trig->chan == SENSOR_CHAN_ACCEL_XYZ) && (trig->type == SENSOR_TRIG_DATA_READY)) { data->handler_drdy_acc = handler; data->drdy_trig_acc = trig; return 0; } return -ENOTSUP; } int bmi08x_acc_trigger_mode_init(const struct device *dev) { struct bmi08x_accel_data *data = dev->data; const struct bmi08x_accel_config *cfg = dev->config; int ret = 0; if (!gpio_is_ready_dt(&cfg->int_gpio)) { LOG_ERR("GPIO device not ready"); return -ENODEV; } #if defined(CONFIG_BMI08X_ACCEL_TRIGGER_OWN_THREAD) k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&data->thread, data->thread_stack, CONFIG_BMI08X_ACCEL_THREAD_STACK_SIZE, bmi08x_acc_thread_main, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BMI08X_ACCEL_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD) data->work.handler = bmi08x_acc_work_handler; data->dev = dev; #endif #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC if (config->data_sync != 0) { /* set accel ints */ ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INT1_MAP, cfg->int1_map); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INT2_MAP, cfg->int2_map); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } } else #endif { uint8_t map_data = ((cfg->int2_map << BMI08X_ACCEL_INT2_DRDY_POS) | (cfg->int1_map << BMI08X_ACCEL_INT1_DRDY_POS)); ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INT1_INT2_MAP_DATA, map_data); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } } ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INT1_IO_CONF, cfg->int1_conf_io); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } ret = bmi08x_accel_byte_write(dev, BMI08X_REG_ACCEL_INT2_IO_CONF, cfg->int2_conf_io); if (ret < 0) { LOG_ERR("Failed to map interrupts."); return ret; } gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INPUT); gpio_init_callback(&data->gpio_cb, bmi08x_acc_gpio_callback, BIT(cfg->int_gpio.pin)); ret = gpio_add_callback(cfg->int_gpio.port, &data->gpio_cb); if (ret < 0) { LOG_ERR("Failed to set gpio callback."); return ret; } gpio_pin_interrupt_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); return ret; } ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x_accel_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,299
```objective-c /* Bosch BMI08X inertial measurement unit header * * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI08X_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI08X_H_ #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/spi.h> #include <zephyr/sys/util.h> /* Accel Chip Id register */ #define BMI08X_REG_ACCEL_CHIP_ID 0x00 /* Accel Error condition register */ #define BMI08X_REG_ACCEL_ERR 0x02 /* Accel Status flag register */ #define BMI08X_REG_ACCEL_STATUS 0x03 /* Accel X LSB data register */ #define BMI08X_REG_ACCEL_X_LSB 0x12 /* Accel X MSB data register */ #define BMI08X_REG_ACCEL_X_MSB 0x13 /* Accel Y LSB data register */ #define BMI08X_REG_ACCEL_Y_LSB 0x14 /* Accel Y MSB data register */ #define BMI08X_REG_ACCEL_Y_MSB 0x15 /* Accel Z LSB data register */ #define BMI08X_REG_ACCEL_Z_LSB 0x16 /* Accel Z MSB data register */ #define BMI08X_REG_ACCEL_Z_MSB 0x17 /* Sensor time byte 0 register */ #define BMI08X_REG_ACCEL_SENSORTIME_0 0x18 /* Sensor time byte 1 register */ #define BMI08X_REG_ACCEL_SENSORTIME_1 0x19 /* Sensor time byte 2 register */ #define BMI08X_REG_ACCEL_SENSORTIME_2 0x1A /* Accel Interrupt status0 register */ #define BMI08X_REG_ACCEL_INT_STAT_0 0x1C /* Accel Interrupt status1 register */ #define BMI08X_REG_ACCEL_INT_STAT_1 0x1D /* Accel general purpose register 0*/ #define BMI08X_REG_ACCEL_GP_0 0x1E /* Sensor temperature MSB data register */ #define BMI08X_REG_TEMP_MSB 0x22 /* Sensor temperature LSB data register */ #define BMI08X_REG_TEMP_LSB 0x23 /* Accel general purpose register 4*/ #define BMI08X_REG_ACCEL_GP_4 0x27 /* Accel Internal status register */ #define BMI08X_REG_ACCEL_INTERNAL_STAT 0x2A /* Accel configuration register */ #define BMI08X_REG_ACCEL_CONF 0x40 /* Accel range setting register */ #define BMI08X_REG_ACCEL_RANGE 0x41 /* Accel Interrupt pin 1 configuration register */ #define BMI08X_REG_ACCEL_INT1_IO_CONF 0x53 /* Accel Interrupt pin 2 configuration register */ #define BMI08X_REG_ACCEL_INT2_IO_CONF 0x54 /* Accel Interrupt latch configuration register */ #define BMI08X_REG_ACCEL_INT_LATCH_CONF 0x55 /* Accel Interrupt pin1 mapping register */ #define BMI08X_REG_ACCEL_INT1_MAP 0x56 /* Accel Interrupt pin2 mapping register */ #define BMI08X_REG_ACCEL_INT2_MAP 0x57 /* Accel Interrupt map register */ #define BMI08X_REG_ACCEL_INT1_INT2_MAP_DATA 0x58 /* Accel Init control register */ #define BMI08X_REG_ACCEL_INIT_CTRL 0x59 /* Accel Self test register */ #define BMI08X_REG_ACCEL_SELF_TEST 0x6D /* Accel Power mode configuration register */ #define BMI08X_REG_ACCEL_PWR_CONF 0x7C /* Accel Power control (switch on or off register */ #define BMI08X_REG_ACCEL_PWR_CTRL 0x7D /* Accel Soft reset register */ #define BMI08X_REG_ACCEL_SOFTRESET 0x7E /* BMI085 Accel unique chip identifier */ #define BMI085_ACCEL_CHIP_ID 0x1F /* BMI088 Accel unique chip identifier */ #define BMI088_ACCEL_CHIP_ID 0x1E /* Feature Config related Registers */ #define BMI08X_ACCEL_RESERVED_5B_REG 0x5B #define BMI08X_ACCEL_RESERVED_5C_REG 0x5C #define BMI08X_ACCEL_FEATURE_CFG_REG 0x5E /* Interrupt masks */ #define BMI08X_ACCEL_DATA_READY_INT 0x80 /* Accel Bandwidth */ #define BMI08X_ACCEL_BW_OSR4 0x00 #define BMI08X_ACCEL_BW_OSR2 0x01 #define BMI08X_ACCEL_BW_NORMAL 0x02 /* BMI085 Accel Range */ #define BMI085_ACCEL_RANGE_2G 0x00 #define BMI085_ACCEL_RANGE_4G 0x01 #define BMI085_ACCEL_RANGE_8G 0x02 #define BMI085_ACCEL_RANGE_16G 0x03 /**\name BMI088 Accel Range */ #define BMI088_ACCEL_RANGE_3G 0x00 #define BMI088_ACCEL_RANGE_6G 0x01 #define BMI088_ACCEL_RANGE_12G 0x02 #define BMI088_ACCEL_RANGE_24G 0x03 /* Accel Output data rate */ #define BMI08X_ACCEL_ODR_12_5_HZ 0x05 #define BMI08X_ACCEL_ODR_25_HZ 0x06 #define BMI08X_ACCEL_ODR_50_HZ 0x07 #define BMI08X_ACCEL_ODR_100_HZ 0x08 #define BMI08X_ACCEL_ODR_200_HZ 0x09 #define BMI08X_ACCEL_ODR_400_HZ 0x0A #define BMI08X_ACCEL_ODR_800_HZ 0x0B #define BMI08X_ACCEL_ODR_1600_HZ 0x0C /* Accel Init Ctrl */ #define BMI08X_ACCEL_INIT_CTRL_DISABLE 0x00 #define BMI08X_ACCEL_INIT_CTRL_ENABLE 0x01 /* Accel Self test */ #define BMI08X_ACCEL_SWITCH_OFF_SELF_TEST 0x00 #define BMI08X_ACCEL_POSITIVE_SELF_TEST 0x0D #define BMI08X_ACCEL_NEGATIVE_SELF_TEST 0x09 /* Accel Power mode */ #define BMI08X_ACCEL_PM_ACTIVE 0x00 #define BMI08X_ACCEL_PM_SUSPEND 0x03 /* Accel Power control settings */ #define BMI08X_ACCEL_POWER_DISABLE 0x00 #define BMI08X_ACCEL_POWER_ENABLE 0x04 /* Accel internal interrupt pin mapping */ #define BMI08X_ACCEL_INTA_DISABLE 0x00 #define BMI08X_ACCEL_INTA_ENABLE 0x01 #define BMI08X_ACCEL_INTB_DISABLE 0x00 #define BMI08X_ACCEL_INTB_ENABLE 0x02 #define BMI08X_ACCEL_INTC_DISABLE 0x00 #define BMI08X_ACCEL_INTC_ENABLE 0x04 /* Accel Soft reset delay */ #define BMI08X_ACCEL_SOFTRESET_DELAY_MS 1 /* Mask definitions for ACCEL_ERR_REG register */ #define BMI08X_FATAL_ERR_MASK 0x01 #define BMI08X_ERR_CODE_MASK 0x1C /* Position definitions for ACCEL_ERR_REG register */ #define BMI08X_CMD_ERR_POS 1 #define BMI08X_ERR_CODE_POS 2 /* Mask definition for ACCEL_STATUS_REG register */ #define BMI08X_ACCEL_STATUS_MASK 0x80 /* Position definitions for ACCEL_STATUS_REG */ #define BMI08X_ACCEL_STATUS_POS 7 /* Mask definitions for odr, bandwidth and range */ #define BMI08X_ACCEL_ODR_MASK 0x0F #define BMI08X_ACCEL_BW_MASK 0x70 #define BMI08X_ACCEL_RANGE_MASK 0x03 /* Position definitions for odr, bandwidth and range */ #define BMI08X_ACCEL_BW_POS 4 /* Mask definitions for INT1_IO_CONF register */ #define BMI08X_ACCEL_INT_EDGE_MASK 0x01 #define BMI08X_ACCEL_INT_LVL_MASK 0x02 #define BMI08X_ACCEL_INT_OD_MASK 0x04 #define BMI08X_ACCEL_INT_IO_MASK 0x08 #define BMI08X_ACCEL_INT_IN_MASK 0x10 /* Position definitions for INT1_IO_CONF register */ #define BMI08X_ACCEL_INT_EDGE_POS 0 #define BMI08X_ACCEL_INT_LVL_POS 1 #define BMI08X_ACCEL_INT_OD_POS 2 #define BMI08X_ACCEL_INT_IO_POS 3 #define BMI08X_ACCEL_INT_IN_POS 4 /* Mask definitions for INT1/INT2 mapping register */ #define BMI08X_ACCEL_MAP_INTA_MASK 0x01 /* Mask definitions for INT1/INT2 mapping register */ #define BMI08X_ACCEL_MAP_INTA_POS 0x00 /* Mask definitions for INT1_INT2_MAP_DATA register */ #define BMI08X_ACCEL_INT1_DRDY_MASK 0x04 #define BMI08X_ACCEL_INT2_DRDY_MASK 0x40 /* Position definitions for INT1_INT2_MAP_DATA register */ #define BMI08X_ACCEL_INT1_DRDY_POS 2 #define BMI08X_ACCEL_INT2_DRDY_POS 6 /* Asic Initialization value */ #define BMI08X_ASIC_INITIALIZED 0x01 #define BMI08X_TEMP_OFFSET 32 /*************************** BMI08 Gyroscope Macros *****************************/ /** Register map */ /* Gyro registers */ /* Gyro Chip Id register */ #define BMI08X_REG_GYRO_CHIP_ID 0x00 /* Gyro X LSB data register */ #define BMI08X_REG_GYRO_X_LSB 0x02 /* Gyro X MSB data register */ #define BMI08X_REG_GYRO_X_MSB 0x03 /* Gyro Y LSB data register */ #define BMI08X_REG_GYRO_Y_LSB 0x04 /* Gyro Y MSB data register */ #define BMI08X_REG_GYRO_Y_MSB 0x05 /* Gyro Z LSB data register */ #define BMI08X_REG_GYRO_Z_LSB 0x06 /* Gyro Z MSB data register */ #define BMI08X_REG_GYRO_Z_MSB 0x07 /* Gyro Interrupt status register */ #define BMI08X_REG_GYRO_INT_STAT_1 0x0A /* Gyro Range register */ #define BMI08X_REG_GYRO_RANGE 0x0F /* Gyro Bandwidth register */ #define BMI08X_REG_GYRO_BANDWIDTH 0x10 /* Gyro Power register */ #define BMI08X_REG_GYRO_LPM1 0x11 /* Gyro Soft reset register */ #define BMI08X_REG_GYRO_SOFTRESET 0x14 /* Gyro Interrupt control register */ #define BMI08X_REG_GYRO_INT_CTRL 0x15 /* Gyro Interrupt Pin configuration register */ #define BMI08X_REG_GYRO_INT3_INT4_IO_CONF 0x16 /* Gyro Interrupt Map register */ #define BMI08X_REG_GYRO_INT3_INT4_IO_MAP 0x18 /* Gyro Self test register */ #define BMI08X_REG_GYRO_SELF_TEST 0x3C /* Gyro unique chip identifier */ #define BMI08X_GYRO_CHIP_ID 0x0F /* Gyro Range */ #define BMI08X_GYRO_RANGE_2000_DPS 0x00 #define BMI08X_GYRO_RANGE_1000_DPS 0x01 #define BMI08X_GYRO_RANGE_500_DPS 0x02 #define BMI08X_GYRO_RANGE_250_DPS 0x03 #define BMI08X_GYRO_RANGE_125_DPS 0x04 /* Gyro Output data rate and bandwidth */ #define BMI08X_GYRO_BW_532_ODR_2000_HZ 0x00 #define BMI08X_GYRO_BW_230_ODR_2000_HZ 0x01 #define BMI08X_GYRO_BW_116_ODR_1000_HZ 0x02 #define BMI08X_GYRO_BW_47_ODR_400_HZ 0x03 #define BMI08X_GYRO_BW_23_ODR_200_HZ 0x04 #define BMI08X_GYRO_BW_12_ODR_100_HZ 0x05 #define BMI08X_GYRO_BW_64_ODR_200_HZ 0x06 #define BMI08X_GYRO_BW_32_ODR_100_HZ 0x07 #define BMI08X_GYRO_ODR_RESET_VAL 0x80 /* Gyro Power mode */ #define BMI08X_GYRO_PM_NORMAL 0x00 #define BMI08X_GYRO_PM_DEEP_SUSPEND 0x20 #define BMI08X_GYRO_PM_SUSPEND 0x80 /* Gyro data ready interrupt enable value */ #define BMI08X_GYRO_DRDY_INT_DISABLE_VAL 0x00 #define BMI08X_GYRO_DRDY_INT_ENABLE_VAL 0x80 /* Gyro data ready map values */ #define BMI08X_GYRO_MAP_DRDY_TO_INT3 0x01 #define BMI08X_GYRO_MAP_DRDY_TO_INT4 0x80 #define BMI08X_GYRO_MAP_DRDY_TO_BOTH_INT3_INT4 0x81 /* Gyro Soft reset delay */ #define BMI08X_GYRO_SOFTRESET_DELAY 30 /* Gyro power mode config delay */ #define BMI08X_GYRO_POWER_MODE_CONFIG_DELAY 30 /** Mask definitions for range, bandwidth and power */ #define BMI08X_GYRO_RANGE_MASK 0x07 #define BMI08X_GYRO_BW_MASK 0x0F #define BMI08X_GYRO_POWER_MASK 0xA0 /** Position definitions for range, bandwidth and power */ #define BMI08X_GYRO_POWER_POS 5 /* Mask definitions for BMI08X_GYRO_INT_CTRL_REG register */ #define BMI08X_GYRO_DATA_EN_MASK 0x80 /* Position definitions for BMI08X_GYRO_INT_CTRL_REG register */ #define BMI08X_GYRO_DATA_EN_POS 7 /* Mask definitions for BMI08X_GYRO_INT3_INT4_IO_CONF_REG register */ #define BMI08X_GYRO_INT3_LVL_MASK 0x01 #define BMI08X_GYRO_INT3_OD_MASK 0x02 #define BMI08X_GYRO_INT4_LVL_MASK 0x04 #define BMI08X_GYRO_INT4_OD_MASK 0x08 /* Position definitions for BMI08X_GYRO_INT3_INT4_IO_CONF_REG register */ #define BMI08X_GYRO_INT3_OD_POS 1 #define BMI08X_GYRO_INT4_LVL_POS 2 #define BMI08X_GYRO_INT4_OD_POS 3 /* Mask definitions for BMI08X_GYRO_INT_EN_REG register */ #define BMI08X_GYRO_INT_EN_MASK 0x80 /* Position definitions for BMI08X_GYRO_INT_EN_REG register */ #define BMI08X_GYRO_INT_EN_POS 7 /* Mask definitions for BMI088_GYRO_INT_MAP_REG register */ #define BMI08X_GYRO_INT3_MAP_MASK 0x01 #define BMI08X_GYRO_INT4_MAP_MASK 0x80 /* Position definitions for BMI088_GYRO_INT_MAP_REG register */ #define BMI08X_GYRO_INT3_MAP_POS 0 #define BMI08X_GYRO_INT4_MAP_POS 7 /* Mask definitions for BMI088_GYRO_INT_MAP_REG register */ #define BMI088_GYRO_INT3_MAP_MASK 0x01 #define BMI088_GYRO_INT4_MAP_MASK 0x80 /* Position definitions for BMI088_GYRO_INT_MAP_REG register */ #define BMI088_GYRO_INT3_MAP_POS 0 #define BMI088_GYRO_INT4_MAP_POS 7 /* Mask definitions for GYRO_SELF_TEST register */ #define BMI08X_GYRO_SELF_TEST_EN_MASK 0x01 #define BMI08X_GYRO_SELF_TEST_RDY_MASK 0x02 #define BMI08X_GYRO_SELF_TEST_RESULT_MASK 0x04 #define BMI08X_GYRO_SELF_TEST_FUNCTION_MASK 0x08 /* Position definitions for GYRO_SELF_TEST register */ #define BMI08X_GYRO_SELF_TEST_RDY_POS 1 #define BMI08X_GYRO_SELF_TEST_RESULT_POS 2 #define BMI08X_GYRO_SELF_TEST_FUNCTION_POS 3 /*************************** Common Macros for both Accel and Gyro *****************************/ /** Soft reset Value */ #define BMI08X_SOFT_RESET_CMD 0xB6 /* Constant values macros */ #define BMI08X_SENSOR_DATA_SYNC_TIME_MS 1 #define BMI08X_DELAY_BETWEEN_WRITES_MS 1 #define BMI08X_SELF_TEST_DELAY_MS 3 #define BMI08X_POWER_CONFIG_DELAY 5 #define BMI08X_SENSOR_SETTLE_TIME_MS 30 #define BMI08X_SELF_TEST_DATA_READ_MS 50 #define BMI08X_ASIC_INIT_TIME_MS 150 /* allowed ODR values */ enum bmi08x_odr { BMI08X_ODR_25_2, BMI08X_ODR_25, BMI08X_ODR_50, BMI08X_ODR_100, BMI08X_ODR_200, BMI08X_ODR_400, BMI08X_ODR_800, BMI08X_ODR_1600, }; /* Range values for accelerometer */ #define BMI08X_ACC_RANGE_2G_3G 0x0 #define BMI08X_ACC_RANGE_4G_6G 0x1 #define BMI08X_ACC_RANGE_8G_12G 0x2 #define BMI08X_ACC_RANGE_16G_24G 0x3 /* Range values for gyro */ #define BMI08X_GYR_RANGE_2000DPS 0 #define BMI08X_GYR_RANGE_1000DPS 1 #define BMI08X_GYR_RANGE_500DPS 2 #define BMI08X_GYR_RANGE_250DPS 3 #define BMI08X_GYR_RANGE_125DPS 4 #define BMI08X_ACC_SCALE(range_g) ((2 * range_g * SENSOR_G) / 65536LL) #define BMI08X_GYR_SCALE(range_dps) ((2 * range_dps * SENSOR_PI) / 180LL / 65536LL) /* report of data sync is selected */ #define BMI08X_ACCEL_DATA_SYNC_EN(inst) DT_NODE_HAS_STATUS(DT_INST_PHANDLE(inst, data_sync), okay) /* Macro used for compile time optimization to compile in/out code used for data-sync * if at least 1 bmi08x has data-sync enabled */ #define ACCEL_HELPER(inst) BMI08X_ACCEL_DATA_SYNC_EN(inst) || #define BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC DT_INST_FOREACH_STATUS_OKAY(ACCEL_HELPER) 0 #define GYRO_HELPER(inst) DT_INST_PROP(inst, data_sync) || #define BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC DT_INST_FOREACH_STATUS_OKAY(GYRO_HELPER) 0 struct bmi08x_range { uint16_t range; uint8_t reg_val; }; union bmi08x_bus { #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) struct spi_dt_spec spi; #endif #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) struct i2c_dt_spec i2c; #endif }; struct bmi08x_accel_bus_io { int (*check)(const union bmi08x_bus *bus); int (*bus_init)(const struct device *dev); int (*transceive)(const struct device *dev, uint8_t reg, bool write, void *data, size_t length); #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC int (*write_config_file)(const struct device *dev); #endif }; struct bmi08x_gyro_bus_io { int (*check)(const union bmi08x_bus *bus); int (*transceive)(const struct device *dev, uint8_t reg, bool write, void *data, size_t length); }; struct bmi08x_accel_config { union bmi08x_bus bus; const struct bmi08x_accel_bus_io *api; #if defined(CONFIG_BMI08X_ACCEL_TRIGGER) struct gpio_dt_spec int_gpio; #endif #if defined(CONFIG_BMI08X_ACCEL_TRIGGER) || BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC uint8_t int1_map; uint8_t int2_map; uint8_t int1_conf_io; uint8_t int2_conf_io; #endif uint8_t accel_hz; uint8_t accel_fs; #if BMI08X_ACCEL_ANY_INST_HAS_DATA_SYNC uint8_t data_sync; #endif }; struct bmi08x_gyro_config { union bmi08x_bus bus; const struct bmi08x_gyro_bus_io *api; #if defined(CONFIG_BMI08X_GYRO_TRIGGER) struct gpio_dt_spec int_gpio; #endif #if defined(CONFIG_BMI08X_GYRO_TRIGGER) || BMI08X_GYRO_ANY_INST_HAS_DATA_SYNC uint8_t int3_4_map; uint8_t int3_4_conf_io; #endif uint8_t gyro_hz; uint16_t gyro_fs; }; struct bmi08x_accel_data { #if defined(CONFIG_BMI08X_ACCEL_TRIGGER) struct gpio_callback gpio_cb; #endif uint16_t acc_sample[3]; uint16_t scale; /* micro m/s^2/lsb */ #if defined(CONFIG_BMI08X_ACCEL_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMI08X_ACCEL_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem sem; #elif defined(CONFIG_BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD) struct k_work work; const struct device *dev; #endif #ifdef CONFIG_BMI08X_ACCEL_TRIGGER sensor_trigger_handler_t handler_drdy_acc; const struct sensor_trigger *drdy_trig_acc; #endif /* CONFIG_BMI08X_ACCEL_TRIGGER */ uint8_t accel_chip_id; }; struct bmi08x_gyro_data { #if defined(CONFIG_BMI08X_GYRO_TRIGGER) struct gpio_callback gpio_cb; #endif uint16_t gyr_sample[3]; uint16_t scale; /* micro radians/s/lsb */ #if defined(CONFIG_BMI08X_GYRO_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMI08X_GYRO_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem sem; #elif defined(CONFIG_BMI08X_GYRO_TRIGGER_GLOBAL_THREAD) struct k_work work; const struct device *dev; #endif #ifdef CONFIG_BMI08X_GYRO_TRIGGER sensor_trigger_handler_t handler_drdy_gyr; const struct sensor_trigger *drdy_trig_gyr; #endif /* CONFIG_BMI08X_GYRO_TRIGGER */ }; /* common functions for accel and gyro */ int bmi08x_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli); int32_t bmi08x_range_to_reg_val(uint16_t range, const struct bmi08x_range *range_map, uint16_t range_map_size); int32_t bmi08x_reg_val_to_range(uint8_t reg_val, const struct bmi08x_range *range_map, uint16_t range_map_size); int bmi08x_accel_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len); int bmi08x_accel_write(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint16_t len); int bmi08x_accel_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte); int bmi08x_accel_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte); int bmi08x_accel_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word); int bmi08x_accel_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val); static inline int bmi08x_accel_reg_update(const struct device *dev, uint8_t reg_addr, uint8_t mask, uint8_t val) { return bmi08x_accel_reg_field_update(dev, reg_addr, 0, mask, val); } int bmi08x_gyro_read(const struct device *dev, uint8_t reg_addr, uint8_t *data, uint8_t len); int bmi08x_gyro_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte); int bmi08x_gyro_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte); int bmi08x_gyro_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word); int bmi08x_gyro_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val); static inline int bmi08x_gyro_reg_update(const struct device *dev, uint8_t reg_addr, uint8_t mask, uint8_t val) { return bmi08x_gyro_reg_field_update(dev, reg_addr, 0, mask, val); } int bmi08x_acc_trigger_mode_init(const struct device *dev); int bmi08x_trigger_set_acc(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bmi08x_acc_slope_config(const struct device *dev, enum sensor_attribute attr, const struct sensor_value *val); int32_t bmi08x_acc_reg_val_to_range(uint8_t reg_val); int bmi08x_gyr_trigger_mode_init(const struct device *dev); int bmi08x_trigger_set_gyr(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bmi08x_gyr_slope_config(const struct device *dev, enum sensor_attribute attr, const struct sensor_value *val); int32_t bmi08x_gyr_reg_val_to_range(uint8_t reg_val); #endif /* ZEPHYR_DRIVERS_SENSOR_BMI08X_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,623
```unknown # Bosch BMI08X inertial measurement configuration options menuconfig BMI08X bool "Bosch BMI08X inertial measurement unit" default y depends on DT_HAS_BOSCH_BMI08X_ACCEL_ENABLED || DT_HAS_BOSCH_BMI08X_GYRO_ENABLED select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_ACCEL),i2c) \ || $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_GYRO),i2c) select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_ACCEL),spi) \ || $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI08X_GYRO),spi) help Enable Bosch BMI08X inertial measurement unit that provides acceleration and angular rate measurements. if BMI08X choice BMI08X_ACCEL_TRIGGER_MODE prompt "Accelerometer trigger mode" default BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config BMI08X_ACCEL_TRIGGER_NONE bool "No trigger" config BMI08X_ACCEL_TRIGGER_GLOBAL_THREAD bool "Use global thread" select BMI08X_ACCEL_TRIGGER config BMI08X_ACCEL_TRIGGER_OWN_THREAD bool "Use own thread" select BMI08X_ACCEL_TRIGGER endchoice config BMI08X_ACCEL_TRIGGER bool config BMI08X_ACCEL_THREAD_PRIORITY int "Accelerometer own thread priority" depends on BMI08X_ACCEL_TRIGGER_OWN_THREAD default 10 help The priority of the thread used for handling interrupts. config BMI08X_ACCEL_THREAD_STACK_SIZE int "Accelerometer own thread stack size" depends on BMI08X_ACCEL_TRIGGER_OWN_THREAD default 1536 help The thread stack size. choice BMI08X_GYRO_TRIGGER_MODE prompt "Gyroscope trigger mode" default BMI08X_GYRO_TRIGGER_NONE default BMI08X_GYRO_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config BMI08X_GYRO_TRIGGER_NONE bool "No trigger" config BMI08X_GYRO_TRIGGER_GLOBAL_THREAD bool "Use global thread" select BMI08X_GYRO_TRIGGER config BMI08X_GYRO_TRIGGER_OWN_THREAD bool "Use own thread" select BMI08X_GYRO_TRIGGER endchoice config BMI08X_GYRO_TRIGGER bool config BMI08X_GYRO_THREAD_PRIORITY int "Own thread priority" depends on BMI08X_GYRO_TRIGGER_OWN_THREAD default 10 help The priority of the thread used for handling interrupts. config BMI08X_GYRO_THREAD_STACK_SIZE int "Own thread stack size" depends on BMI08X_GYRO_TRIGGER_OWN_THREAD default 1536 help The thread stack size. config BMI08X_I2C_WRITE_BURST_SIZE int "Maximum length of single i2c write" default 16 endif # BMI08X ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
654
```c /* * */ /* * Bus-specific functionality for BMI270s accessed via SPI. */ #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include "bmi270.h" LOG_MODULE_DECLARE(bmi270, CONFIG_SENSOR_LOG_LEVEL); static int bmi270_bus_check_spi(const union bmi270_bus *bus) { return spi_is_ready_dt(&bus->spi) ? 0 : -ENODEV; } static int bmi270_reg_read_spi(const union bmi270_bus *bus, uint8_t start, uint8_t *data, uint16_t len) { int ret; uint8_t addr; uint8_t tmp[2]; const struct spi_buf tx_buf = { .buf = &addr, .len = 1 }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; struct spi_buf rx_buf[2]; const struct spi_buf_set rx = { .buffers = rx_buf, .count = ARRAY_SIZE(rx_buf) }; /* First byte we read should be discarded. */ rx_buf[0].buf = &tmp; rx_buf[0].len = 2; rx_buf[1].len = len; rx_buf[1].buf = data; addr = start | 0x80; ret = spi_transceive_dt(&bus->spi, &tx, &rx); if (ret < 0) { LOG_DBG("spi_transceive failed %i", ret); return ret; } k_usleep(BMI270_SPI_ACC_DELAY_US); return 0; } static int bmi270_reg_write_spi(const union bmi270_bus *bus, uint8_t start, const uint8_t *data, uint16_t len) { int ret; uint8_t addr; const struct spi_buf tx_buf[2] = { {.buf = &addr, .len = sizeof(addr)}, {.buf = (uint8_t *)data, .len = len} }; const struct spi_buf_set tx = { .buffers = tx_buf, .count = ARRAY_SIZE(tx_buf) }; addr = start & BMI270_REG_MASK; ret = spi_write_dt(&bus->spi, &tx); if (ret < 0) { LOG_ERR("spi_write_dt failed %i", ret); return ret; } k_usleep(BMI270_SPI_ACC_DELAY_US); return 0; } static int bmi270_bus_init_spi(const union bmi270_bus *bus) { uint8_t tmp; /* Single read of SPI initializes the chip to SPI mode */ return bmi270_reg_read_spi(bus, BMI270_REG_CHIP_ID, &tmp, 1); } const struct bmi270_bus_io bmi270_bus_io_spi = { .check = bmi270_bus_check_spi, .read = bmi270_reg_read_spi, .write = bmi270_reg_write_spi, .init = bmi270_bus_init_spi, }; ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270_spi.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
631
```objective-c /* Bosch BMI08X inertial measurement unit header * * */ #ifndef BMI08X_BMI08X_CONFIG_FILE_H_ #define BMI08X_BMI08X_CONFIG_FILE_H_ /* Source : path_to_url#L69 */ const uint8_t bmi08x_config_file[] = { 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x48, 0xb4, 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x6d, 0xb4, 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0xd4, 0xb3, 0x80, 0x2e, 0xb0, 0xb3, 0x80, 0x2e, 0x12, 0xb4, 0x50, 0x39, 0x21, 0x2e, 0xb0, 0xf0, 0x10, 0x30, 0x21, 0x2e, 0x16, 0xf0, 0x80, 0x2e, 0xfe, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x45, 0x79, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0xfb, 0x7f, 0x98, 0x2e, 0x03, 0xb1, 0x12, 0x24, 0x67, 0x00, 0x90, 0x42, 0x81, 0x42, 0xba, 0x82, 0xd1, 0x7f, 0xe2, 0x7f, 0x98, 0x2e, 0x3c, 0xb0, 0xd1, 0x6f, 0x00, 0x2e, 0x41, 0x40, 0x40, 0xb2, 0x4c, 0x2f, 0xe1, 0x6f, 0x44, 0x86, 0x03, 0x2e, 0x67, 0x00, 0xc2, 0x40, 0xf7, 0x86, 0x4a, 0x04, 0xc1, 0x42, 0x00, 0x2e, 0xc2, 0x40, 0x80, 0xac, 0x01, 0x2f, 0x23, 0x2e, 0x63, 0x00, 0xd1, 0x40, 0xd2, 0x40, 0x0a, 0x0f, 0x01, 0x2f, 0x40, 0xac, 0x02, 0x2f, 0x01, 0x30, 0x23, 0x2e, 0x63, 0x00, 0xfe, 0x82, 0xc2, 0x40, 0x43, 0x40, 0xd3, 0x04, 0x46, 0x84, 0xc3, 0x7f, 0x85, 0x86, 0xc5, 0x82, 0x45, 0x80, 0x44, 0x40, 0xc1, 0x6f, 0xc3, 0x40, 0xe0, 0x7f, 0xd1, 0x7f, 0x00, 0x2e, 0x82, 0x40, 0x98, 0x2e, 0x00, 0xb0, 0xe1, 0x6f, 0x72, 0x84, 0x40, 0x42, 0x85, 0x86, 0xc5, 0x82, 0x45, 0x80, 0x44, 0x40, 0xc3, 0x40, 0xd1, 0x6f, 0xe0, 0x7f, 0x00, 0x2e, 0x82, 0x40, 0x98, 0x2e, 0x00, 0xb0, 0xe1, 0x6f, 0x72, 0x84, 0x40, 0x42, 0x85, 0x86, 0xc5, 0x82, 0x45, 0x80, 0x44, 0x40, 0xc3, 0x40, 0xd1, 0x6f, 0xe0, 0x7f, 0x00, 0x2e, 0x82, 0x40, 0x98, 0x2e, 0x00, 0xb0, 0xe1, 0x6f, 0x00, 0x2e, 0x40, 0x42, 0x98, 0x2e, 0xa5, 0xb0, 0x11, 0x30, 0x23, 0x2e, 0x5e, 0xf0, 0xfb, 0x6f, 0xc0, 0x5f, 0xb8, 0x2e, 0xaa, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0xed, 0x8f, 0xd9, 0x31, 0x00, 0x00, 0xc6, 0x01, 0x8c, 0x03, 0xc6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x50, 0xf0, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x01, 0x01, 0x02, 0xbc, 0x0f, 0xb8, 0xe0, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x01, 0x01, 0x01, 0xbc, 0x0f, 0xb8, 0xd0, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x01, 0x01, 0x0f, 0xb8, 0xc0, 0x7f, 0x02, 0x30, 0xe6, 0x6f, 0xd4, 0x6f, 0xc3, 0x6f, 0x80, 0x91, 0x04, 0x2f, 0x00, 0x91, 0x02, 0x2f, 0xc0, 0xb2, 0x90, 0x2e, 0xf6, 0x01, 0xf0, 0x6f, 0x0b, 0x2e, 0x24, 0x00, 0x01, 0x82, 0x40, 0x91, 0x14, 0x2f, 0x41, 0x87, 0x27, 0x2e, 0x24, 0x00, 0x00, 0x40, 0x21, 0x2e, 0x1b, 0x00, 0x53, 0x40, 0x10, 0x24, 0x1c, 0x00, 0x13, 0x42, 0x00, 0x2e, 0x41, 0x40, 0x01, 0x42, 0x25, 0x2e, 0x18, 0x00, 0x25, 0x2e, 0x19, 0x00, 0x25, 0x2e, 0x1e, 0x00, 0x50, 0x5f, 0xb8, 0x2e, 0x0b, 0x2e, 0x00, 0x01, 0xd5, 0xbe, 0xd5, 0xba, 0xb5, 0x7f, 0x00, 0x2e, 0x0b, 0x2e, 0x01, 0x01, 0xd3, 0xbe, 0xd3, 0xba, 0xa5, 0x7f, 0x00, 0x2e, 0x0b, 0x2e, 0x00, 0x01, 0xd4, 0xbe, 0xdf, 0xba, 0x95, 0x7f, 0x00, 0x2e, 0x95, 0x6f, 0x0f, 0x2e, 0x1a, 0x00, 0x3d, 0x1a, 0x05, 0x2f, 0x25, 0x2e, 0x18, 0x00, 0x25, 0x2e, 0x19, 0x00, 0x2b, 0x2e, 0x1a, 0x00, 0x80, 0x91, 0x01, 0x2f, 0x06, 0x30, 0x07, 0x2d, 0x06, 0x40, 0x0f, 0x2e, 0x1b, 0x00, 0xb7, 0x05, 0x80, 0xa9, 0xd6, 0x05, 0xb7, 0x23, 0x86, 0x7f, 0x00, 0x91, 0x01, 0x2f, 0x04, 0x30, 0x07, 0x2d, 0x44, 0x40, 0x0d, 0x2e, 0x1c, 0x00, 0x26, 0x05, 0x00, 0xa9, 0x94, 0x05, 0x26, 0x23, 0x74, 0x7f, 0xc0, 0x90, 0x01, 0x2f, 0x00, 0x2e, 0x09, 0x2d, 0x02, 0x86, 0x00, 0x2e, 0xc3, 0x40, 0x09, 0x2e, 0x1d, 0x00, 0xdc, 0x04, 0xc0, 0xa8, 0x93, 0x04, 0x9a, 0x22, 0x62, 0x7f, 0x12, 0x30, 0x84, 0x6f, 0xb3, 0x6f, 0x63, 0x0f, 0x14, 0x30, 0x08, 0x2f, 0x74, 0x6f, 0x63, 0x0f, 0x14, 0x30, 0x04, 0x2f, 0x64, 0x6f, 0x63, 0x0f, 0x14, 0x30, 0x00, 0x2f, 0x04, 0x30, 0x54, 0x7f, 0x40, 0x91, 0x0b, 0x2e, 0x18, 0x00, 0x54, 0x6f, 0xa3, 0x6f, 0x6a, 0x29, 0x1d, 0x2f, 0x00, 0x91, 0x06, 0x30, 0x14, 0x24, 0x1c, 0x00, 0x0d, 0x2f, 0x2d, 0x2e, 0x18, 0x00, 0x05, 0x2e, 0x19, 0x00, 0x81, 0x84, 0x25, 0x2e, 0x19, 0x00, 0x05, 0x2e, 0x19, 0x00, 0x53, 0x0e, 0x2b, 0x2f, 0x2d, 0x2e, 0x1e, 0x00, 0x29, 0x2d, 0x2b, 0x2e, 0x18, 0x00, 0x2d, 0x2e, 0x19, 0x00, 0x0b, 0x2e, 0x18, 0x00, 0x6b, 0x0e, 0x20, 0x2f, 0x25, 0x2e, 0x1e, 0x00, 0x1e, 0x2d, 0x00, 0xb3, 0x05, 0x2f, 0x02, 0x30, 0x25, 0x2e, 0x18, 0x00, 0x25, 0x2e, 0x1e, 0x00, 0x08, 0x2d, 0x2b, 0x2e, 0x18, 0x00, 0x09, 0x2e, 0x18, 0x00, 0x63, 0x0e, 0x01, 0x2f, 0x25, 0x2e, 0x1e, 0x00, 0x02, 0x40, 0x25, 0x2e, 0x1b, 0x00, 0x31, 0x25, 0x00, 0x2e, 0xd5, 0x40, 0x12, 0x24, 0x1c, 0x00, 0x42, 0x25, 0x95, 0x42, 0x00, 0x2e, 0xc3, 0x40, 0x83, 0x42, 0x00, 0x2e, 0x05, 0x2e, 0x1e, 0x00, 0x80, 0xb2, 0x0d, 0x2f, 0x00, 0x40, 0x21, 0x2e, 0x1b, 0x00, 0x50, 0x40, 0x10, 0x43, 0x00, 0x2e, 0x40, 0x40, 0x00, 0x43, 0x20, 0x30, 0x21, 0x2e, 0x5e, 0xf0, 0x02, 0x2d, 0x25, 0x2e, 0x24, 0x00, 0x50, 0x5f, 0xb8, 0x2e, 0x40, 0x30, 0x21, 0x2e, 0xba, 0xf0, 0xb8, 0x2e, 0x80, 0x2e, 0x18, 0x00, 0x70, 0x50, 0xf4, 0x7f, 0xe3, 0x7f, 0xd2, 0x7f, 0xc1, 0x7f, 0x12, 0x30, 0x03, 0x2e, 0x66, 0x00, 0x91, 0x14, 0x92, 0x7f, 0x00, 0x31, 0xc4, 0x6f, 0x95, 0x6f, 0xe3, 0x6f, 0xa5, 0x0f, 0x70, 0x84, 0x01, 0x04, 0x14, 0x2f, 0xd5, 0x6f, 0x00, 0xa9, 0x01, 0x2f, 0xa5, 0x7f, 0x21, 0x2d, 0xdd, 0x04, 0xb3, 0x7f, 0x40, 0xb2, 0xb3, 0x6f, 0x1c, 0x18, 0x06, 0x2f, 0x50, 0xa0, 0x01, 0x2f, 0xba, 0x11, 0x03, 0x2d, 0x71, 0x12, 0xb8, 0x14, 0x8a, 0x0b, 0x6e, 0x00, 0xa1, 0x7f, 0x11, 0x2d, 0xf7, 0x6f, 0xfb, 0x05, 0xb7, 0x7f, 0x25, 0x05, 0xb5, 0x6f, 0x2c, 0x18, 0x40, 0xb2, 0x06, 0x2f, 0x50, 0xa0, 0x01, 0x2f, 0xba, 0x11, 0x03, 0x2d, 0x71, 0x12, 0xb8, 0x14, 0x8a, 0x0b, 0x5e, 0x00, 0xa1, 0x7f, 0x00, 0x2e, 0xa0, 0x6f, 0x90, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0x02, 0x01, 0x8e, 0xbc, 0x01, 0x2e, 0x62, 0x00, 0x9e, 0xb8, 0x01, 0x1a, 0x5f, 0x2f, 0x01, 0x2e, 0x02, 0x01, 0x0e, 0xbc, 0x0e, 0xb8, 0x21, 0x2e, 0x62, 0x00, 0x03, 0x2e, 0x62, 0x00, 0x43, 0xb2, 0x10, 0x24, 0x65, 0x00, 0x3c, 0x2f, 0x42, 0xb2, 0x22, 0x2f, 0x41, 0xb2, 0x06, 0x2f, 0x01, 0x30, 0x11, 0x42, 0x01, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x03, 0x2e, 0x9d, 0x00, 0x5f, 0x90, 0x62, 0x30, 0x11, 0x24, 0x81, 0x00, 0x07, 0x2f, 0x30, 0x25, 0x34, 0x37, 0xd4, 0x42, 0xc2, 0x42, 0xfe, 0x86, 0x00, 0x2e, 0xc1, 0x42, 0x00, 0x2e, 0x07, 0x2e, 0x9d, 0x00, 0xde, 0x90, 0x35, 0x2f, 0x63, 0x36, 0x13, 0x42, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x03, 0x2e, 0x9d, 0x00, 0x5f, 0xb2, 0x52, 0x30, 0x21, 0x32, 0x0a, 0x2f, 0x07, 0x2e, 0x9d, 0x00, 0xde, 0x90, 0x24, 0x2f, 0x23, 0x31, 0x13, 0x42, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x03, 0x32, 0x13, 0x42, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x03, 0x2e, 0x9d, 0x00, 0x5f, 0xb2, 0x42, 0x30, 0x11, 0x31, 0x0a, 0x2f, 0x07, 0x2e, 0x9d, 0x00, 0xde, 0x90, 0x0c, 0x2f, 0xa3, 0x30, 0x13, 0x42, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x63, 0x31, 0x13, 0x42, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x01, 0x42, 0xb8, 0x2e, 0x10, 0x24, 0x78, 0x00, 0x11, 0x24, 0x52, 0xf0, 0x12, 0x40, 0x52, 0x42, 0x28, 0xb5, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x42, 0x42, 0x42, 0x82, 0x00, 0x40, 0x50, 0x42, 0x08, 0xb4, 0x40, 0x42, 0x7e, 0x80, 0xa8, 0xb4, 0x01, 0x42, 0xb8, 0x2e, 0x12, 0x24, 0x71, 0x00, 0x90, 0x40, 0x84, 0x82, 0x20, 0x50, 0x50, 0x42, 0x77, 0x80, 0x82, 0x40, 0x42, 0x42, 0xfb, 0x7f, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x7c, 0x80, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x7c, 0x80, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x77, 0x84, 0x00, 0x2e, 0x90, 0x40, 0x84, 0x82, 0x82, 0x40, 0x50, 0x42, 0x77, 0x80, 0x42, 0x42, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x7c, 0x80, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x7c, 0x80, 0x05, 0x82, 0x00, 0x40, 0x40, 0x42, 0x7c, 0x82, 0xe1, 0x7f, 0x98, 0x2e, 0x03, 0xb1, 0xe2, 0x6f, 0x00, 0x2e, 0x90, 0x42, 0x81, 0x42, 0xbc, 0x82, 0x10, 0x24, 0x33, 0xf0, 0x23, 0x40, 0x02, 0x40, 0xb8, 0xbd, 0x9a, 0x0a, 0x03, 0x80, 0x52, 0x42, 0x00, 0x2e, 0x23, 0x40, 0x02, 0x40, 0xb8, 0xbd, 0x9a, 0x0a, 0x03, 0x80, 0x52, 0x42, 0x00, 0x2e, 0x22, 0x40, 0x00, 0x40, 0x28, 0xbd, 0x10, 0x0a, 0x40, 0x42, 0x00, 0x2e, 0xfb, 0x6f, 0xe0, 0x5f, 0xb8, 0x2e, 0x11, 0x24, 0x28, 0xf0, 0x50, 0x50, 0x60, 0x40, 0xf0, 0x7f, 0x51, 0x25, 0x60, 0x40, 0xe0, 0x7f, 0x00, 0x2e, 0x41, 0x40, 0xd1, 0x7f, 0x00, 0x2e, 0xe2, 0x6f, 0xd0, 0x6f, 0x00, 0xb2, 0xf3, 0x6f, 0xa8, 0xb8, 0x28, 0xbe, 0x59, 0x0a, 0x20, 0x0a, 0x01, 0x2f, 0xb0, 0x5f, 0xb8, 0x2e, 0x45, 0x41, 0xc5, 0x7f, 0x00, 0x2e, 0xc5, 0x6f, 0x40, 0x91, 0x09, 0x2f, 0x05, 0x2e, 0x28, 0xf0, 0xb2, 0x7f, 0x00, 0x2e, 0xb2, 0x6f, 0x1a, 0x1a, 0x07, 0x2f, 0xf0, 0x3f, 0x13, 0x25, 0x05, 0x2d, 0x15, 0x1a, 0x02, 0x2f, 0x10, 0x24, 0xff, 0x00, 0x20, 0x0a, 0xb0, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0x03, 0x01, 0x8f, 0xbc, 0x01, 0x2e, 0x1f, 0x00, 0x9f, 0xb8, 0x01, 0x1a, 0x12, 0x2f, 0x01, 0x2e, 0x03, 0x01, 0x0f, 0xbc, 0x0f, 0xb8, 0x21, 0x2e, 0x1f, 0x00, 0x11, 0x30, 0x05, 0x2e, 0x1f, 0x00, 0x51, 0x08, 0xd2, 0x3f, 0x01, 0x2e, 0x07, 0xf0, 0x02, 0x08, 0x91, 0xbc, 0x01, 0x0a, 0x21, 0x2e, 0x07, 0xf0, 0xb8, 0x2e, 0xb8, 0x2e, 0x50, 0x50, 0xf2, 0x7f, 0xe1, 0x7f, 0x01, 0x30, 0xd1, 0x7f, 0xc1, 0x7f, 0x10, 0x24, 0x91, 0x04, 0xf2, 0x6f, 0xe3, 0x6f, 0x1c, 0x2d, 0xc4, 0x6f, 0x9c, 0x01, 0xd5, 0x6f, 0x86, 0x41, 0x6e, 0x0d, 0xd5, 0x7f, 0xb1, 0x7f, 0x0e, 0x2d, 0xd6, 0x6f, 0xef, 0xba, 0x61, 0xbf, 0x40, 0x91, 0x01, 0x2f, 0xd6, 0x7f, 0x03, 0x2d, 0x70, 0x0d, 0xd5, 0x7f, 0x00, 0x2e, 0xb5, 0x6f, 0x41, 0x8b, 0xb5, 0x7f, 0x00, 0x2e, 0xb5, 0x6f, 0x50, 0xa3, 0xee, 0x2f, 0x01, 0x89, 0xc4, 0x7f, 0x00, 0x2e, 0xc4, 0x6f, 0x62, 0x0e, 0xe0, 0x2f, 0xd0, 0x6f, 0xb0, 0x5f, 0xb8, 0x2e, 0x90, 0x50, 0xd3, 0x7f, 0xfb, 0x7f, 0xc2, 0x7f, 0xb1, 0x7f, 0x11, 0x30, 0xa1, 0x7f, 0x1a, 0x25, 0xc2, 0x6f, 0x72, 0x7f, 0x77, 0x82, 0xb2, 0x6f, 0x82, 0x7f, 0xe2, 0x7f, 0x22, 0x30, 0x98, 0x2e, 0x4d, 0xb1, 0x90, 0x7f, 0x00, 0x2e, 0xe1, 0x6f, 0xd0, 0x6f, 0x41, 0x16, 0x92, 0x6f, 0x01, 0x08, 0x51, 0x08, 0x48, 0x1a, 0x01, 0x2f, 0x01, 0x30, 0xa1, 0x7f, 0x00, 0x2e, 0xfb, 0x6f, 0xa0, 0x6f, 0x70, 0x5f, 0xb8, 0x2e, 0x70, 0x50, 0xe3, 0x7f, 0xfb, 0x7f, 0xc1, 0x7f, 0xd2, 0x7f, 0x1a, 0x25, 0xc0, 0x6f, 0xd2, 0x6f, 0x90, 0x7f, 0xa2, 0x7f, 0x79, 0x82, 0xe2, 0x6f, 0xb2, 0x7f, 0x32, 0x30, 0x98, 0x2e, 0x4d, 0xb1, 0xfb, 0x6f, 0x90, 0x5f, 0xb8, 0x2e, 0xb0, 0x50, 0xa4, 0x7f, 0xfb, 0x7f, 0x93, 0x7f, 0x82, 0x7f, 0x71, 0x7f, 0x00, 0x30, 0xa1, 0x6f, 0xe1, 0x7f, 0x40, 0x42, 0x00, 0x2e, 0x92, 0x6f, 0x83, 0x6f, 0x71, 0x6f, 0xd3, 0x7f, 0xc2, 0x7f, 0xb1, 0x7f, 0x98, 0x2e, 0x7a, 0xb1, 0x60, 0x7f, 0x00, 0x2e, 0x60, 0x6f, 0x01, 0xb2, 0x1e, 0x2f, 0xb1, 0x6f, 0xf2, 0x30, 0x8a, 0x08, 0x13, 0x24, 0xf0, 0x00, 0x4b, 0x08, 0x24, 0xbd, 0x94, 0xb8, 0x51, 0x0a, 0x51, 0x7f, 0x00, 0x2e, 0x51, 0x6f, 0x81, 0x16, 0xd3, 0x6f, 0x9a, 0x08, 0xc4, 0x6f, 0xe1, 0x08, 0xe1, 0x6f, 0x93, 0x0a, 0x42, 0x42, 0x12, 0x24, 0x00, 0xff, 0x43, 0x40, 0x9a, 0x08, 0x14, 0x24, 0xff, 0x00, 0xdc, 0x08, 0xb8, 0xbd, 0x28, 0xb9, 0x9a, 0x0a, 0x42, 0x42, 0x00, 0x2e, 0xfb, 0x6f, 0x50, 0x5f, 0xb8, 0x2e, 0x70, 0x50, 0xd4, 0x7f, 0xfb, 0x7f, 0xc3, 0x7f, 0xa1, 0x7f, 0xb2, 0x7f, 0x02, 0x30, 0x92, 0x7f, 0x00, 0x2e, 0x05, 0x2e, 0x20, 0x00, 0xc4, 0x6f, 0x80, 0xb2, 0x0c, 0x2f, 0x81, 0x90, 0x1a, 0x2f, 0xd2, 0x6f, 0x07, 0x2e, 0x21, 0x00, 0xa1, 0x32, 0x98, 0x2e, 0xaf, 0xb1, 0x02, 0x30, 0x25, 0x2e, 0x20, 0x00, 0x92, 0x7f, 0x10, 0x2d, 0xa1, 0x6f, 0xb2, 0x6f, 0xe4, 0x7f, 0xa3, 0x32, 0x98, 0x2e, 0x9c, 0xb1, 0x21, 0x2e, 0x21, 0x00, 0xe2, 0x6f, 0x03, 0x2e, 0x21, 0x00, 0x81, 0x42, 0x12, 0x30, 0x25, 0x2e, 0x20, 0x00, 0x92, 0x7f, 0x00, 0x2e, 0xfb, 0x6f, 0x90, 0x6f, 0x90, 0x5f, 0xb8, 0x2e, 0x10, 0x50, 0x00, 0x30, 0xf0, 0x7f, 0x12, 0x24, 0x86, 0x00, 0x1b, 0x2d, 0xf1, 0x6f, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0xbc, 0x84, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0x8c, 0x84, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0xbc, 0x84, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0x8c, 0x84, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0xbc, 0x84, 0xd1, 0x00, 0x00, 0x2e, 0xc0, 0x42, 0x41, 0x82, 0xf1, 0x7f, 0xb4, 0x84, 0xf1, 0x6f, 0x43, 0xa2, 0xe1, 0x2f, 0xf0, 0x5f, 0xb8, 0x2e, 0xc0, 0x50, 0x92, 0x7f, 0xfb, 0x7f, 0x81, 0x7f, 0x00, 0x30, 0x60, 0x7f, 0x70, 0x7f, 0x50, 0x7f, 0x00, 0x2e, 0x03, 0x2e, 0x04, 0x01, 0x9d, 0xbc, 0x9e, 0xb8, 0x41, 0x7f, 0x00, 0x2e, 0x42, 0x6f, 0x52, 0x7f, 0xe2, 0x7f, 0x00, 0x2e, 0x83, 0x6f, 0xc4, 0x82, 0xd3, 0x7f, 0x0c, 0x2d, 0x55, 0x6f, 0x7f, 0x89, 0xdc, 0x01, 0x9d, 0x01, 0xcb, 0x41, 0x8b, 0x43, 0xcc, 0x01, 0x4d, 0x01, 0xc7, 0x41, 0x47, 0x43, 0x54, 0x7f, 0x00, 0x2e, 0x54, 0x6f, 0x00, 0xab, 0xf0, 0x2f, 0x9b, 0x6f, 0x8a, 0x00, 0x4b, 0x42, 0xc2, 0x7f, 0xb1, 0x7f, 0x50, 0x7f, 0x7c, 0x80, 0xa0, 0x7f, 0x13, 0x24, 0x09, 0x01, 0x3f, 0x2d, 0x50, 0x6f, 0x18, 0x01, 0xc8, 0x84, 0xc8, 0x00, 0x50, 0x00, 0x05, 0x41, 0xc7, 0x40, 0x44, 0x40, 0x61, 0x6f, 0x73, 0x6f, 0x2f, 0x18, 0x00, 0xb3, 0x0b, 0x2f, 0x10, 0xa1, 0x03, 0x2f, 0x30, 0x89, 0xbc, 0x11, 0xce, 0x17, 0x06, 0x2d, 0x74, 0x13, 0x06, 0x31, 0xb4, 0x05, 0xbe, 0x15, 0xfc, 0x11, 0xae, 0x0b, 0x4e, 0x00, 0xdf, 0x02, 0x61, 0x7f, 0x73, 0x7f, 0xb4, 0x84, 0x01, 0x82, 0xd1, 0x00, 0x88, 0x80, 0xa2, 0x6f, 0x11, 0x01, 0x81, 0x00, 0xc3, 0x40, 0x05, 0x41, 0x84, 0x40, 0x1d, 0x18, 0x72, 0x6f, 0x00, 0xb3, 0x63, 0x6f, 0x0b, 0x2f, 0x10, 0xa1, 0x03, 0x2f, 0x30, 0x89, 0xbc, 0x11, 0xce, 0x17, 0x06, 0x2d, 0x74, 0x13, 0x06, 0x31, 0xb4, 0x05, 0xbe, 0x15, 0xfc, 0x11, 0xae, 0x0b, 0xde, 0x04, 0x97, 0x06, 0x63, 0x7f, 0x72, 0x7f, 0x51, 0x7f, 0x3c, 0x86, 0xb1, 0x6f, 0xe2, 0x6f, 0x50, 0x6f, 0x42, 0x0e, 0xbc, 0x2f, 0xe0, 0x6f, 0xc8, 0x82, 0x98, 0x00, 0x48, 0x00, 0xc0, 0x6f, 0x83, 0x40, 0x04, 0x40, 0x42, 0x40, 0x61, 0x6f, 0x70, 0x6f, 0x80, 0xb2, 0x1c, 0x18, 0x0b, 0x2f, 0x90, 0xa0, 0x03, 0x2f, 0xb0, 0x84, 0xba, 0x11, 0xce, 0x17, 0x06, 0x2d, 0x03, 0x31, 0xda, 0x04, 0xfb, 0x14, 0x32, 0x13, 0xfa, 0x11, 0xa3, 0x0b, 0x4e, 0x00, 0x07, 0x02, 0x61, 0x7f, 0x70, 0x7f, 0x00, 0x2e, 0x72, 0x6f, 0x80, 0xa8, 0x60, 0x6f, 0xd1, 0x6f, 0x13, 0x2f, 0x80, 0x90, 0x03, 0x2f, 0x13, 0x24, 0xff, 0x7f, 0x43, 0x0f, 0x0d, 0x2f, 0xbf, 0xa0, 0x07, 0x2f, 0xbf, 0x90, 0x03, 0x2f, 0x12, 0x24, 0x00, 0x80, 0x42, 0x0e, 0x01, 0x2f, 0x40, 0x42, 0x07, 0x2d, 0x10, 0x24, 0x00, 0x80, 0x40, 0x42, 0x03, 0x2d, 0x10, 0x24, 0xff, 0x7f, 0x40, 0x42, 0x00, 0x2e, 0xfb, 0x6f, 0x40, 0x5f, 0x40, 0x40, 0xb8, 0x2e, 0x11, 0x24, 0x7b, 0x00, 0x30, 0x50, 0x10, 0x30, 0x50, 0x42, 0xfb, 0x7f, 0x10, 0x24, 0x33, 0xf0, 0x23, 0x40, 0x02, 0x40, 0xb8, 0xbd, 0x9a, 0x0a, 0x03, 0x80, 0x52, 0x42, 0x00, 0x2e, 0x23, 0x40, 0x02, 0x40, 0xb8, 0xbd, 0x9a, 0x0a, 0x03, 0x80, 0x52, 0x42, 0x00, 0x2e, 0x23, 0x40, 0x02, 0x40, 0xb8, 0xbd, 0x9a, 0x0a, 0x3c, 0x80, 0x42, 0x42, 0x7e, 0x84, 0xe0, 0x7f, 0x86, 0x82, 0xd1, 0x7f, 0x00, 0x2e, 0x82, 0x40, 0x98, 0x2e, 0x40, 0xb2, 0xd1, 0x6f, 0x7d, 0x82, 0x00, 0x2e, 0x40, 0x42, 0x7e, 0x80, 0x0d, 0x82, 0x02, 0x40, 0xd1, 0x7f, 0x98, 0x2e, 0x40, 0xb2, 0xd1, 0x6f, 0x76, 0x82, 0x00, 0x2e, 0x40, 0x42, 0x7e, 0x80, 0x14, 0x82, 0x02, 0x40, 0xd1, 0x7f, 0x98, 0x2e, 0x40, 0xb2, 0xd1, 0x6f, 0x6f, 0x82, 0x00, 0x2e, 0x40, 0x42, 0x7e, 0x80, 0xe1, 0x6f, 0x12, 0x40, 0x52, 0x42, 0x28, 0xb5, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x28, 0xb5, 0x52, 0x42, 0x00, 0x2e, 0x00, 0x40, 0x50, 0x42, 0x08, 0xb4, 0x40, 0x42, 0x00, 0x2e, 0xfb, 0x6f, 0xd0, 0x5f, 0xb8, 0x2e, 0x10, 0x50, 0x01, 0x2e, 0x55, 0xf0, 0xf0, 0x7f, 0x00, 0x2e, 0xf0, 0x6f, 0x21, 0x2e, 0x55, 0xf0, 0xf0, 0x5f, 0xb8, 0x2e, 0x20, 0x50, 0x00, 0x30, 0xe0, 0x7f, 0xfb, 0x7f, 0x11, 0x24, 0xb1, 0xf0, 0x42, 0x40, 0x43, 0x30, 0x93, 0x0a, 0x42, 0x42, 0x58, 0x82, 0x12, 0x24, 0xaf, 0x00, 0x62, 0x42, 0x12, 0x24, 0xff, 0x00, 0x42, 0x42, 0x69, 0x82, 0x72, 0x3c, 0x43, 0x40, 0x9a, 0x08, 0x83, 0x32, 0x93, 0x0a, 0x42, 0x42, 0x42, 0x82, 0x02, 0x3f, 0x43, 0x40, 0x9a, 0x08, 0x52, 0x42, 0x0b, 0x31, 0x4b, 0x42, 0x7e, 0x82, 0x72, 0x31, 0x42, 0x42, 0x00, 0x2e, 0x03, 0x2e, 0x40, 0xf0, 0x5f, 0xb2, 0x03, 0x2f, 0x03, 0x2e, 0x40, 0xf0, 0x5e, 0x90, 0x27, 0x2f, 0x11, 0x24, 0x00, 0x02, 0x12, 0x24, 0x05, 0x80, 0x13, 0x24, 0xff, 0xb7, 0x1b, 0x24, 0x00, 0xb0, 0x04, 0x30, 0x05, 0x30, 0x56, 0x32, 0x6e, 0x1a, 0x00, 0x2f, 0x25, 0x36, 0x69, 0x1a, 0x01, 0x2f, 0x5b, 0x25, 0x00, 0x2e, 0x56, 0x41, 0x26, 0x0d, 0x06, 0x30, 0xcf, 0xbb, 0x41, 0xbe, 0xc0, 0x91, 0x01, 0x2f, 0x00, 0x2e, 0x01, 0x2d, 0x22, 0x0d, 0x81, 0x8d, 0x90, 0xa1, 0xf5, 0x2f, 0xeb, 0x0e, 0xe8, 0x2f, 0x01, 0x2e, 0x25, 0x00, 0x20, 0x1a, 0x05, 0x2f, 0x20, 0x30, 0xe0, 0x7f, 0x03, 0x2d, 0x30, 0x30, 0xe0, 0x7f, 0x00, 0x2e, 0xe0, 0x6f, 0x00, 0xb2, 0x06, 0x2f, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e, 0x43, 0xb3, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0xfb, 0x6f, 0xe0, 0x5f, 0xb8, 0x2e, 0xa0, 0x50, 0x80, 0x7f, 0xe7, 0x7f, 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0xa2, 0x7f, 0x91, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x43, 0xf0, 0x08, 0xbc, 0x0f, 0xb8, 0x60, 0x7f, 0x00, 0x2e, 0x60, 0x6f, 0x00, 0xb2, 0x01, 0x2f, 0x98, 0x2e, 0xb9, 0xb0, 0x40, 0x30, 0x21, 0x2e, 0xb8, 0xf0, 0xf6, 0x6f, 0x91, 0x6f, 0xa2, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0xe7, 0x6f, 0x7b, 0x6f, 0x80, 0x6f, 0x60, 0x5f, 0xc8, 0x2e, 0xa0, 0x50, 0x80, 0x7f, 0xe7, 0x7f, 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0xa2, 0x7f, 0x91, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x29, 0xf0, 0x08, 0xbc, 0x0f, 0xb8, 0x60, 0x7f, 0x00, 0x2e, 0x60, 0x6f, 0x01, 0x90, 0x1b, 0x2f, 0x01, 0x2e, 0x02, 0x01, 0x0e, 0xbc, 0x0e, 0xb8, 0x00, 0x90, 0x05, 0x2f, 0x01, 0x2e, 0x04, 0x01, 0x0f, 0xbc, 0x0f, 0xb8, 0x01, 0xb2, 0x0d, 0x2f, 0x01, 0x2e, 0x7b, 0x00, 0x01, 0x90, 0x04, 0x2f, 0x98, 0x2e, 0x1a, 0xb2, 0x00, 0x30, 0x21, 0x2e, 0x7b, 0x00, 0x01, 0x2e, 0x37, 0xf0, 0x21, 0x2e, 0x37, 0xf0, 0x02, 0x2d, 0x98, 0x2e, 0xf3, 0xb2, 0x80, 0x30, 0x21, 0x2e, 0xb8, 0xf0, 0xf6, 0x6f, 0x91, 0x6f, 0xa2, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0xe7, 0x6f, 0x7b, 0x6f, 0x80, 0x6f, 0x60, 0x5f, 0xc8, 0x2e, 0x60, 0x50, 0xe7, 0x7f, 0xf6, 0x7f, 0x36, 0x30, 0x0f, 0x2e, 0x01, 0xf0, 0xfe, 0xbf, 0xfe, 0xbb, 0xb7, 0x05, 0xa6, 0x7f, 0xd3, 0x7f, 0xc4, 0x7f, 0xb5, 0x7f, 0x14, 0x24, 0x89, 0xf0, 0x3f, 0x8b, 0x03, 0x41, 0x44, 0x41, 0xb8, 0xbd, 0x9c, 0x0b, 0xa3, 0x6f, 0x14, 0x24, 0x9a, 0x00, 0xb3, 0x11, 0x43, 0x8b, 0x16, 0x43, 0x00, 0x2e, 0x67, 0x41, 0x46, 0x41, 0xf8, 0xbf, 0xbe, 0x0b, 0xb3, 0x11, 0x16, 0x43, 0x43, 0x8d, 0x00, 0x2e, 0xa5, 0x41, 0x86, 0x41, 0xd8, 0xbe, 0x6e, 0x0b, 0xeb, 0x10, 0x03, 0x43, 0x13, 0x30, 0x27, 0x2e, 0x22, 0x00, 0x03, 0x31, 0x27, 0x2e, 0xb8, 0xf0, 0xf6, 0x6f, 0xe7, 0x6f, 0xc4, 0x6f, 0xb5, 0x6f, 0xd3, 0x6f, 0xa0, 0x5f, 0xc8, 0x2e, 0xa0, 0x50, 0x80, 0x7f, 0x91, 0x7f, 0xe7, 0x7f, 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0xa2, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0xb9, 0xf0, 0x60, 0x7f, 0x10, 0x30, 0x61, 0x6f, 0x08, 0x08, 0x00, 0xb2, 0x01, 0x2f, 0x98, 0x2e, 0x9e, 0x00, 0x10, 0x30, 0x21, 0x2e, 0xb9, 0xf0, 0x21, 0x2e, 0x5f, 0xf0, 0xf6, 0x6f, 0x91, 0x6f, 0xa2, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0xe7, 0x6f, 0x7b, 0x6f, 0x80, 0x6f, 0x60, 0x5f, 0xc8, 0x2e, 0x20, 0x50, 0xe7, 0x7f, 0xf6, 0x7f, 0x56, 0x32, 0x0f, 0x2e, 0x58, 0xf0, 0x7e, 0x1a, 0x02, 0x2f, 0x16, 0x30, 0x2d, 0x2e, 0x23, 0x00, 0x16, 0x24, 0x80, 0x00, 0x2d, 0x2e, 0xb9, 0xf0, 0xe7, 0x6f, 0xf6, 0x6f, 0xe0, 0x5f, 0xc8, 0x2e, 0x30, 0x50, 0x04, 0x30, 0xd4, 0x7f, 0xe4, 0x7f, 0xfb, 0x7f, 0x13, 0x24, 0x26, 0xf0, 0xc2, 0x40, 0xc1, 0x86, 0xe4, 0x7f, 0xd2, 0x7f, 0x00, 0x2e, 0xd1, 0x40, 0x18, 0xbc, 0x18, 0xba, 0xd2, 0x6f, 0xe1, 0x6f, 0x90, 0x0a, 0x0c, 0x0b, 0xd2, 0x7f, 0xe4, 0x7f, 0x00, 0x2e, 0xe4, 0x6f, 0xc3, 0x40, 0xe3, 0x0a, 0xdb, 0x6f, 0xdb, 0x7f, 0xe3, 0x7f, 0x13, 0x24, 0x15, 0x01, 0xe2, 0x6f, 0x09, 0x2e, 0x16, 0x01, 0xd1, 0x6f, 0x98, 0x2e, 0xea, 0xb1, 0x21, 0x2e, 0x58, 0xf0, 0x98, 0x2e, 0x43, 0xb3, 0xfb, 0x6f, 0xd0, 0x5f, 0xb8, 0x2e, 0x98, 0x2e, 0x4d, 0xb3, 0x20, 0x26, 0x98, 0x2e, 0xfa, 0x01, 0x98, 0x2e, 0xf5, 0xb4, 0x98, 0x2e, 0xf1, 0xb4, 0x98, 0x2e, 0xde, 0xb4, 0x98, 0x2e, 0xf9, 0xb4, 0x01, 0x2e, 0x40, 0xf0, 0x21, 0x2e, 0x9d, 0x00, 0x10, 0x30, 0x21, 0x2e, 0x59, 0xf0, 0x98, 0x2e, 0x43, 0xb3, 0x21, 0x30, 0x10, 0x24, 0x9a, 0x00, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x05, 0x2e, 0x22, 0x00, 0x80, 0xb2, 0x02, 0x30, 0x05, 0x2f, 0x23, 0x2e, 0x5f, 0xf0, 0x25, 0x2e, 0x22, 0x00, 0x98, 0x2e, 0x17, 0x01, 0x98, 0x2e, 0x31, 0xb1, 0x01, 0x2e, 0x23, 0x00, 0x01, 0x90, 0x00, 0x30, 0xe7, 0x2f, 0x21, 0x2e, 0x23, 0x00, 0x98, 0x2e, 0x80, 0xb4, 0xe3, 0x2d, 0x80, 0x30, 0x21, 0x2e, 0xba, 0xf0, 0x10, 0x24, 0x80, 0x00, 0x03, 0x2e, 0x06, 0xf0, 0x08, 0x0a, 0x21, 0x2e, 0x06, 0xf0, 0x00, 0x3e, 0x03, 0x2e, 0x06, 0xf0, 0x08, 0x08, 0x51, 0x30, 0x01, 0x0a, 0x21, 0x2e, 0x06, 0xf0, 0xb8, 0x2e, 0x00, 0x31, 0x21, 0x2e, 0xba, 0xf0, 0xb8, 0x2e, 0x10, 0x30, 0x21, 0x2e, 0xbb, 0xf0, 0xb8, 0x2e, 0x10, 0x24, 0x80, 0x00, 0x21, 0x2e, 0xbb, 0xf0, 0xb8, 0x2e, 0x1a, 0x24, 0x26, 0x00, 0x80, 0x2e, 0xab, 0xb4, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00, 0x80, 0x2e, 0x18, 0x00}; #endif /* BMI08X_BMI08X_CONFIG_FILE_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi08x/bmi08x_config_file.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
32,336
```c /* * */ #include <zephyr/device.h> #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(bmi270); #include "bmi270.h" enum { INT_FLAGS_INT1, INT_FLAGS_INT2, }; static void bmi270_raise_int_flag(const struct device *dev, int bit) { struct bmi270_data *data = dev->data; atomic_set_bit(&data->int_flags, bit); #if defined(CONFIG_BMI270_TRIGGER_OWN_THREAD) k_sem_give(&data->trig_sem); #elif defined(CONFIG_BMI270_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->trig_work); #endif } static void bmi270_int1_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { struct bmi270_data *data = CONTAINER_OF(cb, struct bmi270_data, int1_cb); bmi270_raise_int_flag(data->dev, INT_FLAGS_INT1); } static void bmi270_int2_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { struct bmi270_data *data = CONTAINER_OF(cb, struct bmi270_data, int2_cb); bmi270_raise_int_flag(data->dev, INT_FLAGS_INT2); } static void bmi270_thread_cb(const struct device *dev) { struct bmi270_data *data = dev->data; int ret; /* INT1 is used for feature interrupts */ if (atomic_test_and_clear_bit(&data->int_flags, INT_FLAGS_INT1)) { uint16_t int_status; ret = bmi270_reg_read(dev, BMI270_REG_INT_STATUS_0, (uint8_t *)&int_status, sizeof(int_status)); if (ret < 0) { LOG_ERR("read interrupt status returned %d", ret); return; } k_mutex_lock(&data->trigger_mutex, K_FOREVER); if (data->motion_handler != NULL) { if (int_status & BMI270_INT_STATUS_ANY_MOTION) { data->motion_handler(dev, data->motion_trigger); } } k_mutex_unlock(&data->trigger_mutex); } /* INT2 is used for data ready interrupts */ if (atomic_test_and_clear_bit(&data->int_flags, INT_FLAGS_INT2)) { k_mutex_lock(&data->trigger_mutex, K_FOREVER); if (data->drdy_handler != NULL) { data->drdy_handler(dev, data->drdy_trigger); } k_mutex_unlock(&data->trigger_mutex); } } #ifdef CONFIG_BMI270_TRIGGER_OWN_THREAD static void bmi270_thread(void *p1, void *p2, void *p3) { ARG_UNUSED(p2); ARG_UNUSED(p3); struct bmi270_data *data = p1; while (1) { k_sem_take(&data->trig_sem, K_FOREVER); bmi270_thread_cb(data->dev); } } #endif #ifdef CONFIG_BMI270_TRIGGER_GLOBAL_THREAD static void bmi270_trig_work_cb(struct k_work *work) { struct bmi270_data *data = CONTAINER_OF(work, struct bmi270_data, trig_work); bmi270_thread_cb(data->dev); } #endif static int bmi270_feature_reg_write(const struct device *dev, const struct bmi270_feature_reg *reg, uint16_t value) { int ret; uint8_t feat_page = reg->page; ret = bmi270_reg_write(dev, BMI270_REG_FEAT_PAGE, &feat_page, 1); if (ret < 0) { LOG_ERR("bmi270_reg_write (0x%02x) failed: %d", BMI270_REG_FEAT_PAGE, ret); return ret; } LOG_DBG("feature reg[0x%02x]@%d = 0x%04x", reg->addr, reg->page, value); ret = bmi270_reg_write(dev, reg->addr, (uint8_t *)&value, 2); if (ret < 0) { LOG_ERR("bmi270_reg_write (0x%02x) failed: %d", reg->addr, ret); return ret; } return 0; } static int bmi270_init_int_pin(const struct gpio_dt_spec *pin, struct gpio_callback *pin_cb, gpio_callback_handler_t handler) { int ret; if (!pin->port) { return 0; } if (!device_is_ready(pin->port)) { LOG_DBG("%s not ready", pin->port->name); return -ENODEV; } gpio_init_callback(pin_cb, handler, BIT(pin->pin)); ret = gpio_pin_configure_dt(pin, GPIO_INPUT); if (ret) { return ret; } ret = gpio_pin_interrupt_configure_dt(pin, GPIO_INT_EDGE_TO_ACTIVE); if (ret) { return ret; } ret = gpio_add_callback(pin->port, pin_cb); if (ret) { return ret; } return 0; } int bmi270_init_interrupts(const struct device *dev) { const struct bmi270_config *cfg = dev->config; struct bmi270_data *data = dev->data; int ret; #if CONFIG_BMI270_TRIGGER_OWN_THREAD k_sem_init(&data->trig_sem, 0, 1); k_thread_create(&data->thread, data->thread_stack, CONFIG_BMI270_THREAD_STACK_SIZE, bmi270_thread, data, NULL, NULL, K_PRIO_COOP(CONFIG_BMI270_THREAD_PRIORITY), 0, K_NO_WAIT); #elif CONFIG_BMI270_TRIGGER_GLOBAL_THREAD k_work_init(&data->trig_work, bmi270_trig_work_cb); #endif ret = bmi270_init_int_pin(&cfg->int1, &data->int1_cb, bmi270_int1_callback); if (ret) { LOG_ERR("Failed to initialize INT1"); return -EINVAL; } ret = bmi270_init_int_pin(&cfg->int2, &data->int2_cb, bmi270_int2_callback); if (ret) { LOG_ERR("Failed to initialize INT2"); return -EINVAL; } if (cfg->int1.port) { uint8_t int1_io_ctrl = BMI270_INT_IO_CTRL_OUTPUT_EN; ret = bmi270_reg_write(dev, BMI270_REG_INT1_IO_CTRL, &int1_io_ctrl, 1); if (ret < 0) { LOG_ERR("failed configuring INT1_IO_CTRL (%d)", ret); return ret; } } if (cfg->int2.port) { uint8_t int2_io_ctrl = BMI270_INT_IO_CTRL_OUTPUT_EN; ret = bmi270_reg_write(dev, BMI270_REG_INT2_IO_CTRL, &int2_io_ctrl, 1); if (ret < 0) { LOG_ERR("failed configuring INT2_IO_CTRL (%d)", ret); return ret; } } return 0; } static int bmi270_anymo_config(const struct device *dev, bool enable) { const struct bmi270_config *cfg = dev->config; struct bmi270_data *data = dev->data; uint16_t anymo_2; int ret; if (enable) { ret = bmi270_feature_reg_write(dev, cfg->feature->anymo_1, data->anymo_1); if (ret < 0) { return ret; } } anymo_2 = data->anymo_2; if (enable) { anymo_2 |= BMI270_ANYMO_2_ENABLE; } ret = bmi270_feature_reg_write(dev, cfg->feature->anymo_2, anymo_2); if (ret < 0) { return ret; } uint8_t int1_map_feat = 0; if (enable) { int1_map_feat |= BMI270_INT_MAP_ANY_MOTION; } ret = bmi270_reg_write(dev, BMI270_REG_INT1_MAP_FEAT, &int1_map_feat, 1); if (ret < 0) { LOG_ERR("failed configuring INT1_MAP_FEAT (%d)", ret); return ret; } return 0; } static int bmi270_drdy_config(const struct device *dev, bool enable) { int ret; uint8_t int_map_data = 0; if (enable) { int_map_data |= BMI270_INT_MAP_DATA_DRDY_INT2; } ret = bmi270_reg_write(dev, BMI270_REG_INT_MAP_DATA, &int_map_data, 1); if (ret < 0) { LOG_ERR("failed configuring INT_MAP_DATA (%d)", ret); return ret; } return 0; } int bmi270_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi270_data *data = dev->data; const struct bmi270_config *cfg = dev->config; switch (trig->type) { case SENSOR_TRIG_MOTION: if (!cfg->int1.port) { return -ENOTSUP; } k_mutex_lock(&data->trigger_mutex, K_FOREVER); data->motion_handler = handler; data->motion_trigger = trig; k_mutex_unlock(&data->trigger_mutex); return bmi270_anymo_config(dev, handler != NULL); case SENSOR_TRIG_DATA_READY: if (!cfg->int2.port) { return -ENOTSUP; } k_mutex_lock(&data->trigger_mutex, K_FOREVER); data->drdy_handler = handler; data->drdy_trigger = trig; k_mutex_unlock(&data->trigger_mutex); return bmi270_drdy_config(dev, handler != NULL); default: return -ENOTSUP; } return 0; } ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,102
```c /* * */ /* * Bus-specific functionality for BMI270s accessed via I2C. */ #include "bmi270.h" static int bmi270_bus_check_i2c(const union bmi270_bus *bus) { return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV; } static int bmi270_reg_read_i2c(const union bmi270_bus *bus, uint8_t start, uint8_t *data, uint16_t len) { return i2c_burst_read_dt(&bus->i2c, start, data, len); } static int bmi270_reg_write_i2c(const union bmi270_bus *bus, uint8_t start, const uint8_t *data, uint16_t len) { return i2c_burst_write_dt(&bus->i2c, start, data, len); } static int bmi270_bus_init_i2c(const union bmi270_bus *bus) { /* I2C is used by default */ return 0; } const struct bmi270_bus_io bmi270_bus_io_i2c = { .check = bmi270_bus_check_i2c, .read = bmi270_reg_read_i2c, .write = bmi270_reg_write_i2c, .init = bmi270_bus_init_i2c, }; ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270_i2c.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
275
```c /* * */ #define DT_DRV_COMPAT bosch_bmi270 #include <zephyr/drivers/sensor.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> #include "bmi270.h" #include "bmi270_config_file.h" LOG_MODULE_REGISTER(bmi270, CONFIG_SENSOR_LOG_LEVEL); #define BMI270_WR_LEN 256 #define BMI270_CONFIG_FILE_RETRIES 15 #define BMI270_CONFIG_FILE_POLL_PERIOD_US 10000 #define BMI270_INTER_WRITE_DELAY_US 1000 static inline int bmi270_bus_check(const struct device *dev) { const struct bmi270_config *cfg = dev->config; return cfg->bus_io->check(&cfg->bus); } static inline int bmi270_bus_init(const struct device *dev) { const struct bmi270_config *cfg = dev->config; return cfg->bus_io->init(&cfg->bus); } int bmi270_reg_read(const struct device *dev, uint8_t reg, uint8_t *data, uint16_t length) { const struct bmi270_config *cfg = dev->config; return cfg->bus_io->read(&cfg->bus, reg, data, length); } int bmi270_reg_write(const struct device *dev, uint8_t reg, const uint8_t *data, uint16_t length) { const struct bmi270_config *cfg = dev->config; return cfg->bus_io->write(&cfg->bus, reg, data, length); } int bmi270_reg_write_with_delay(const struct device *dev, uint8_t reg, const uint8_t *data, uint16_t length, uint32_t delay_us) { int ret = 0; ret = bmi270_reg_write(dev, reg, data, length); if (ret == 0) { k_usleep(delay_us); } return ret; } static void channel_accel_convert(struct sensor_value *val, int64_t raw_val, uint8_t range) { /* 16 bit accelerometer. 2^15 bits represent the range in G */ /* Converting from G to m/s^2 */ raw_val = (raw_val * SENSOR_G * (int64_t) range) / INT16_MAX; val->val1 = raw_val / 1000000LL; val->val2 = raw_val % 1000000LL; } static void channel_gyro_convert(struct sensor_value *val, int64_t raw_val, uint16_t range) { /* 16 bit gyroscope. 2^15 bits represent the range in degrees/s */ /* Converting from degrees/s to radians/s */ val->val1 = ((raw_val * (int64_t) range * SENSOR_PI) / (180LL * INT16_MAX)) / 1000000LL; val->val2 = ((raw_val * (int64_t) range * SENSOR_PI) / (180LL * INT16_MAX)) % 1000000LL; } static uint8_t acc_odr_to_reg(const struct sensor_value *val) { double odr = sensor_value_to_double((struct sensor_value *) val); uint8_t reg = 0; if ((odr >= 0.78125) && (odr < 1.5625)) { reg = BMI270_ACC_ODR_25D32_HZ; } else if ((odr >= 1.5625) && (odr < 3.125)) { reg = BMI270_ACC_ODR_25D16_HZ; } else if ((odr >= 3.125) && (odr < 6.25)) { reg = BMI270_ACC_ODR_25D8_HZ; } else if ((odr >= 6.25) && (odr < 12.5)) { reg = BMI270_ACC_ODR_25D4_HZ; } else if ((odr >= 12.5) && (odr < 25.0)) { reg = BMI270_ACC_ODR_25D2_HZ; } else if ((odr >= 25.0) && (odr < 50.0)) { reg = BMI270_ACC_ODR_25_HZ; } else if ((odr >= 50.0) && (odr < 100.0)) { reg = BMI270_ACC_ODR_50_HZ; } else if ((odr >= 100.0) && (odr < 200.0)) { reg = BMI270_ACC_ODR_100_HZ; } else if ((odr >= 200.0) && (odr < 400.0)) { reg = BMI270_ACC_ODR_200_HZ; } else if ((odr >= 400.0) && (odr < 800.0)) { reg = BMI270_ACC_ODR_400_HZ; } else if ((odr >= 800.0) && (odr < 1600.0)) { reg = BMI270_ACC_ODR_800_HZ; } else if (odr >= 1600.0) { reg = BMI270_ACC_ODR_1600_HZ; } return reg; } static int set_accel_odr_osr(const struct device *dev, const struct sensor_value *odr, const struct sensor_value *osr) { struct bmi270_data *data = dev->data; uint8_t acc_conf, odr_bits, pwr_ctrl, osr_bits; int ret = 0; if (odr || osr) { ret = bmi270_reg_read(dev, BMI270_REG_ACC_CONF, &acc_conf, 1); if (ret != 0) { return ret; } ret = bmi270_reg_read(dev, BMI270_REG_PWR_CTRL, &pwr_ctrl, 1); if (ret != 0) { return ret; } } if (odr) { odr_bits = acc_odr_to_reg(odr); acc_conf = BMI270_SET_BITS_POS_0(acc_conf, BMI270_ACC_ODR, odr_bits); /* If odr_bits is 0, implies that the sampling frequency is 0Hz * or invalid too. */ if (odr_bits) { pwr_ctrl |= BMI270_PWR_CTRL_ACC_EN; } else { pwr_ctrl &= ~BMI270_PWR_CTRL_ACC_EN; } /* If the Sampling frequency (odr) >= 100Hz, enter performance * mode else, power optimized. This also has a consequence * for the OSR */ if (odr_bits >= BMI270_ACC_ODR_100_HZ) { acc_conf = BMI270_SET_BITS(acc_conf, BMI270_ACC_FILT, BMI270_ACC_FILT_PERF_OPT); } else { acc_conf = BMI270_SET_BITS(acc_conf, BMI270_ACC_FILT, BMI270_ACC_FILT_PWR_OPT); } data->acc_odr = odr_bits; } if (osr) { if (data->acc_odr >= BMI270_ACC_ODR_100_HZ) { /* Performance mode */ /* osr->val2 should be unused */ switch (osr->val1) { case 4: osr_bits = BMI270_ACC_BWP_OSR4_AVG1; break; case 2: osr_bits = BMI270_ACC_BWP_OSR2_AVG2; break; case 1: osr_bits = BMI270_ACC_BWP_NORM_AVG4; break; default: osr_bits = BMI270_ACC_BWP_CIC_AVG8; break; } } else { /* Power optimized mode */ /* osr->val2 should be unused */ switch (osr->val1) { case 1: osr_bits = BMI270_ACC_BWP_OSR4_AVG1; break; case 2: osr_bits = BMI270_ACC_BWP_OSR2_AVG2; break; case 4: osr_bits = BMI270_ACC_BWP_NORM_AVG4; break; case 8: osr_bits = BMI270_ACC_BWP_CIC_AVG8; break; case 16: osr_bits = BMI270_ACC_BWP_RES_AVG16; break; case 32: osr_bits = BMI270_ACC_BWP_RES_AVG32; break; case 64: osr_bits = BMI270_ACC_BWP_RES_AVG64; break; case 128: osr_bits = BMI270_ACC_BWP_RES_AVG128; break; default: return -ENOTSUP; } } acc_conf = BMI270_SET_BITS(acc_conf, BMI270_ACC_BWP, osr_bits); } if (odr || osr) { ret = bmi270_reg_write(dev, BMI270_REG_ACC_CONF, &acc_conf, 1); if (ret != 0) { return ret; } /* Assuming we have advance power save enabled */ k_usleep(BMI270_TRANSC_DELAY_SUSPEND); pwr_ctrl &= BMI270_PWR_CTRL_MSK; ret = bmi270_reg_write_with_delay(dev, BMI270_REG_PWR_CTRL, &pwr_ctrl, 1, BMI270_INTER_WRITE_DELAY_US); } return ret; } static int set_accel_range(const struct device *dev, const struct sensor_value *range) { struct bmi270_data *data = dev->data; int ret = 0; uint8_t acc_range, reg; ret = bmi270_reg_read(dev, BMI270_REG_ACC_RANGE, &acc_range, 1); if (ret != 0) { return ret; } /* range->val2 is unused */ switch (range->val1) { case 2: reg = BMI270_ACC_RANGE_2G; data->acc_range = 2; break; case 4: reg = BMI270_ACC_RANGE_4G; data->acc_range = 4; break; case 8: reg = BMI270_ACC_RANGE_8G; data->acc_range = 8; break; case 16: reg = BMI270_ACC_RANGE_16G; data->acc_range = 16; break; default: return -ENOTSUP; } acc_range = BMI270_SET_BITS_POS_0(acc_range, BMI270_ACC_RANGE, reg); ret = bmi270_reg_write_with_delay(dev, BMI270_REG_ACC_RANGE, &acc_range, 1, BMI270_INTER_WRITE_DELAY_US); return ret; } static uint8_t gyr_odr_to_reg(const struct sensor_value *val) { double odr = sensor_value_to_double((struct sensor_value *) val); uint8_t reg = 0; if ((odr >= 25.0) && (odr < 50.0)) { reg = BMI270_GYR_ODR_25_HZ; } else if ((odr >= 50.0) && (odr < 100.0)) { reg = BMI270_GYR_ODR_50_HZ; } else if ((odr >= 100.0) && (odr < 200.0)) { reg = BMI270_GYR_ODR_100_HZ; } else if ((odr >= 200.0) && (odr < 400.0)) { reg = BMI270_GYR_ODR_200_HZ; } else if ((odr >= 400.0) && (odr < 800.0)) { reg = BMI270_GYR_ODR_400_HZ; } else if ((odr >= 800.0) && (odr < 1600.0)) { reg = BMI270_GYR_ODR_800_HZ; } else if ((odr >= 1600.0) && (odr < 3200.0)) { reg = BMI270_GYR_ODR_1600_HZ; } else if (odr >= 3200.0) { reg = BMI270_GYR_ODR_3200_HZ; } return reg; } static int set_gyro_odr_osr(const struct device *dev, const struct sensor_value *odr, const struct sensor_value *osr) { struct bmi270_data *data = dev->data; uint8_t gyr_conf, odr_bits, pwr_ctrl, osr_bits; int ret = 0; if (odr || osr) { ret = bmi270_reg_read(dev, BMI270_REG_GYR_CONF, &gyr_conf, 1); if (ret != 0) { return ret; } ret = bmi270_reg_read(dev, BMI270_REG_PWR_CTRL, &pwr_ctrl, 1); if (ret != 0) { return ret; } } if (odr) { odr_bits = gyr_odr_to_reg(odr); gyr_conf = BMI270_SET_BITS_POS_0(gyr_conf, BMI270_GYR_ODR, odr_bits); /* If odr_bits is 0, implies that the sampling frequency is * 0Hz or invalid too. */ if (odr_bits) { pwr_ctrl |= BMI270_PWR_CTRL_GYR_EN; } else { pwr_ctrl &= ~BMI270_PWR_CTRL_GYR_EN; } /* If the Sampling frequency (odr) >= 100Hz, enter performance * mode else, power optimized. This also has a consequence for * the OSR */ if (odr_bits >= BMI270_GYR_ODR_100_HZ) { gyr_conf = BMI270_SET_BITS(gyr_conf, BMI270_GYR_FILT, BMI270_GYR_FILT_PERF_OPT); gyr_conf = BMI270_SET_BITS(gyr_conf, BMI270_GYR_FILT_NOISE, BMI270_GYR_FILT_NOISE_PERF); } else { gyr_conf = BMI270_SET_BITS(gyr_conf, BMI270_GYR_FILT, BMI270_GYR_FILT_PWR_OPT); gyr_conf = BMI270_SET_BITS(gyr_conf, BMI270_GYR_FILT_NOISE, BMI270_GYR_FILT_NOISE_PWR); } data->gyr_odr = odr_bits; } if (osr) { /* osr->val2 should be unused */ switch (osr->val1) { case 4: osr_bits = BMI270_GYR_BWP_OSR4; break; case 2: osr_bits = BMI270_GYR_BWP_OSR2; break; default: osr_bits = BMI270_GYR_BWP_NORM; break; } gyr_conf = BMI270_SET_BITS(gyr_conf, BMI270_GYR_BWP, osr_bits); } if (odr || osr) { ret = bmi270_reg_write(dev, BMI270_REG_GYR_CONF, &gyr_conf, 1); if (ret != 0) { return ret; } /* Assuming we have advance power save enabled */ k_usleep(BMI270_TRANSC_DELAY_SUSPEND); pwr_ctrl &= BMI270_PWR_CTRL_MSK; ret = bmi270_reg_write_with_delay(dev, BMI270_REG_PWR_CTRL, &pwr_ctrl, 1, BMI270_INTER_WRITE_DELAY_US); } return ret; } static int set_gyro_range(const struct device *dev, const struct sensor_value *range) { struct bmi270_data *data = dev->data; int ret = 0; uint8_t gyr_range, reg; ret = bmi270_reg_read(dev, BMI270_REG_GYR_RANGE, &gyr_range, 1); if (ret != 0) { return ret; } /* range->val2 is unused */ switch (range->val1) { case 125: reg = BMI270_GYR_RANGE_125DPS; data->gyr_range = 125; break; case 250: reg = BMI270_GYR_RANGE_250DPS; data->gyr_range = 250; break; case 500: reg = BMI270_GYR_RANGE_500DPS; data->gyr_range = 500; break; case 1000: reg = BMI270_GYR_RANGE_1000DPS; data->gyr_range = 1000; break; case 2000: reg = BMI270_GYR_RANGE_2000DPS; data->gyr_range = 2000; break; default: return -ENOTSUP; } gyr_range = BMI270_SET_BITS_POS_0(gyr_range, BMI270_GYR_RANGE, reg); ret = bmi270_reg_write_with_delay(dev, BMI270_REG_GYR_RANGE, &gyr_range, 1, BMI270_INTER_WRITE_DELAY_US); return ret; } static int8_t write_config_file(const struct device *dev) { const struct bmi270_config *cfg = dev->config; int8_t ret = 0; uint16_t index = 0; uint8_t addr_array[2] = { 0 }; LOG_DBG("writing config file %s", cfg->feature->name); /* Disable loading of the configuration */ for (index = 0; index < cfg->feature->config_file_len; index += BMI270_WR_LEN) { /* Store 0 to 3 bits of address in first byte */ addr_array[0] = (uint8_t)((index / 2) & 0x0F); /* Store 4 to 11 bits of address in the second byte */ addr_array[1] = (uint8_t)((index / 2) >> 4); ret = bmi270_reg_write_with_delay(dev, BMI270_REG_INIT_ADDR_0, addr_array, 2, BMI270_INTER_WRITE_DELAY_US); if (ret == 0) { ret = bmi270_reg_write_with_delay(dev, BMI270_REG_INIT_DATA, &cfg->feature->config_file[index], BMI270_WR_LEN, BMI270_INTER_WRITE_DELAY_US); } } return ret; } static int bmi270_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmi270_data *data = dev->data; uint8_t buf[12]; int ret; if (chan != SENSOR_CHAN_ALL) { return -ENOTSUP; } ret = bmi270_reg_read(dev, BMI270_REG_ACC_X_LSB, buf, 12); if (ret == 0) { data->ax = (int16_t)sys_get_le16(&buf[0]); data->ay = (int16_t)sys_get_le16(&buf[2]); data->az = (int16_t)sys_get_le16(&buf[4]); data->gx = (int16_t)sys_get_le16(&buf[6]); data->gy = (int16_t)sys_get_le16(&buf[8]); data->gz = (int16_t)sys_get_le16(&buf[10]); } else { data->ax = 0; data->ay = 0; data->az = 0; data->gx = 0; data->gy = 0; data->gz = 0; } return ret; } static int bmi270_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmi270_data *data = dev->data; if (chan == SENSOR_CHAN_ACCEL_X) { channel_accel_convert(val, data->ax, data->acc_range); } else if (chan == SENSOR_CHAN_ACCEL_Y) { channel_accel_convert(val, data->ay, data->acc_range); } else if (chan == SENSOR_CHAN_ACCEL_Z) { channel_accel_convert(val, data->az, data->acc_range); } else if (chan == SENSOR_CHAN_ACCEL_XYZ) { channel_accel_convert(&val[0], data->ax, data->acc_range); channel_accel_convert(&val[1], data->ay, data->acc_range); channel_accel_convert(&val[2], data->az, data->acc_range); } else if (chan == SENSOR_CHAN_GYRO_X) { channel_gyro_convert(val, data->gx, data->gyr_range); } else if (chan == SENSOR_CHAN_GYRO_Y) { channel_gyro_convert(val, data->gy, data->gyr_range); } else if (chan == SENSOR_CHAN_GYRO_Z) { channel_gyro_convert(val, data->gz, data->gyr_range); } else if (chan == SENSOR_CHAN_GYRO_XYZ) { channel_gyro_convert(&val[0], data->gx, data->gyr_range); channel_gyro_convert(&val[1], data->gy, data->gyr_range); channel_gyro_convert(&val[2], data->gz, data->gyr_range); } else { return -ENOTSUP; } return 0; } #if defined(CONFIG_BMI270_TRIGGER) /* ANYMO_1.duration conversion is 20 ms / LSB */ #define ANYMO_1_DURATION_MSEC_TO_LSB(_ms) \ BMI270_ANYMO_1_DURATION(_ms / 20) static int bmi270_write_anymo_threshold(const struct device *dev, struct sensor_value val) { struct bmi270_data *data = dev->data; /* this takes configuration in g. */ if (val.val1 > 0) { LOG_DBG("anymo_threshold set to max"); val.val2 = 1e6; } /* max = BIT_MASK(10) = 1g => 0.49 mg/LSB */ uint16_t lsbs = (val.val2 * BMI270_ANYMO_2_THRESHOLD_MASK) / 1e6; if (!lsbs) { LOG_ERR("Threshold too low!"); return -EINVAL; } uint16_t anymo_2 = BMI270_ANYMO_2_THRESHOLD(lsbs) | BMI270_ANYMO_2_OUT_CONF_BIT_6; data->anymo_2 = anymo_2; return 0; } static int bmi270_write_anymo_duration(const struct device *dev, uint32_t ms) { struct bmi270_data *data = dev->data; uint16_t val = ANYMO_1_DURATION_MSEC_TO_LSB(ms) | BMI270_ANYMO_1_SELECT_XYZ; data->anymo_1 = val; return 0; } #endif /* CONFIG_BMI270_TRIGGER */ static int bmi270_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { int ret = -ENOTSUP; if ((chan == SENSOR_CHAN_ACCEL_X) || (chan == SENSOR_CHAN_ACCEL_Y) || (chan == SENSOR_CHAN_ACCEL_Z) || (chan == SENSOR_CHAN_ACCEL_XYZ)) { switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = set_accel_odr_osr(dev, val, NULL); break; case SENSOR_ATTR_OVERSAMPLING: ret = set_accel_odr_osr(dev, NULL, val); break; case SENSOR_ATTR_FULL_SCALE: ret = set_accel_range(dev, val); break; #if defined(CONFIG_BMI270_TRIGGER) case SENSOR_ATTR_SLOPE_DUR: return bmi270_write_anymo_duration(dev, val->val1); case SENSOR_ATTR_SLOPE_TH: return bmi270_write_anymo_threshold(dev, *val); #endif default: ret = -ENOTSUP; } } else if ((chan == SENSOR_CHAN_GYRO_X) || (chan == SENSOR_CHAN_GYRO_Y) || (chan == SENSOR_CHAN_GYRO_Z) || (chan == SENSOR_CHAN_GYRO_XYZ)) { switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = set_gyro_odr_osr(dev, val, NULL); break; case SENSOR_ATTR_OVERSAMPLING: ret = set_gyro_odr_osr(dev, NULL, val); break; case SENSOR_ATTR_FULL_SCALE: ret = set_gyro_range(dev, val); break; default: ret = -ENOTSUP; } } return ret; } static int bmi270_init(const struct device *dev) { int ret; struct bmi270_data *data = dev->data; uint8_t chip_id; uint8_t soft_reset_cmd; uint8_t init_ctrl; uint8_t msg; uint8_t tries; uint8_t adv_pwr_save; ret = bmi270_bus_check(dev); if (ret < 0) { LOG_ERR("Could not initialize bus"); return ret; } #if CONFIG_BMI270_TRIGGER data->dev = dev; k_mutex_init(&data->trigger_mutex); #endif data->acc_odr = BMI270_ACC_ODR_100_HZ; data->acc_range = 8; data->gyr_odr = BMI270_GYR_ODR_200_HZ; data->gyr_range = 2000; k_usleep(BMI270_POWER_ON_TIME); ret = bmi270_bus_init(dev); if (ret != 0) { LOG_ERR("Could not initiate bus communication"); return ret; } ret = bmi270_reg_read(dev, BMI270_REG_CHIP_ID, &chip_id, 1); if (ret != 0) { return ret; } if (chip_id != BMI270_CHIP_ID) { LOG_ERR("Unexpected chip id (%x). Expected (%x)", chip_id, BMI270_CHIP_ID); return -EIO; } soft_reset_cmd = BMI270_CMD_SOFT_RESET; ret = bmi270_reg_write(dev, BMI270_REG_CMD, &soft_reset_cmd, 1); if (ret != 0) { return ret; } k_usleep(BMI270_SOFT_RESET_TIME); ret = bmi270_reg_read(dev, BMI270_REG_PWR_CONF, &adv_pwr_save, 1); if (ret != 0) { return ret; } adv_pwr_save = BMI270_SET_BITS_POS_0(adv_pwr_save, BMI270_PWR_CONF_ADV_PWR_SAVE, BMI270_PWR_CONF_ADV_PWR_SAVE_DIS); ret = bmi270_reg_write_with_delay(dev, BMI270_REG_PWR_CONF, &adv_pwr_save, 1, BMI270_INTER_WRITE_DELAY_US); if (ret != 0) { return ret; } init_ctrl = BMI270_PREPARE_CONFIG_LOAD; ret = bmi270_reg_write(dev, BMI270_REG_INIT_CTRL, &init_ctrl, 1); if (ret != 0) { return ret; } ret = write_config_file(dev); if (ret != 0) { return ret; } init_ctrl = BMI270_COMPLETE_CONFIG_LOAD; ret = bmi270_reg_write(dev, BMI270_REG_INIT_CTRL, &init_ctrl, 1); if (ret != 0) { return ret; } /* Timeout after BMI270_CONFIG_FILE_RETRIES x * BMI270_CONFIG_FILE_POLL_PERIOD_US microseconds. * If tries is BMI270_CONFIG_FILE_RETRIES by the end of the loop, * report an error */ for (tries = 0; tries <= BMI270_CONFIG_FILE_RETRIES; tries++) { ret = bmi270_reg_read(dev, BMI270_REG_INTERNAL_STATUS, &msg, 1); if (ret != 0) { return ret; } msg &= BMI270_INST_MESSAGE_MSK; if (msg == BMI270_INST_MESSAGE_INIT_OK) { break; } k_usleep(BMI270_CONFIG_FILE_POLL_PERIOD_US); } if (tries == BMI270_CONFIG_FILE_RETRIES) { return -EIO; } #if CONFIG_BMI270_TRIGGER ret = bmi270_init_interrupts(dev); if (ret) { LOG_ERR("bmi270_init_interrupts returned %d", ret); return ret; } #endif adv_pwr_save = BMI270_SET_BITS_POS_0(adv_pwr_save, BMI270_PWR_CONF_ADV_PWR_SAVE, BMI270_PWR_CONF_ADV_PWR_SAVE_EN); ret = bmi270_reg_write_with_delay(dev, BMI270_REG_PWR_CONF, &adv_pwr_save, 1, BMI270_INTER_WRITE_DELAY_US); return ret; } static const struct sensor_driver_api bmi270_driver_api = { .sample_fetch = bmi270_sample_fetch, .channel_get = bmi270_channel_get, .attr_set = bmi270_attr_set, #if defined(CONFIG_BMI270_TRIGGER) .trigger_set = bmi270_trigger_set, #endif }; static const struct bmi270_feature_config bmi270_feature_max_fifo = { .name = "max_fifo", .config_file = bmi270_config_file_max_fifo, .config_file_len = sizeof(bmi270_config_file_max_fifo), }; static const struct bmi270_feature_config bmi270_feature_base = { .name = "base", .config_file = bmi270_config_file_base, .config_file_len = sizeof(bmi270_config_file_base), .anymo_1 = &(struct bmi270_feature_reg){ .page = 1, .addr = 0x3C }, .anymo_2 = &(struct bmi270_feature_reg){ .page = 1, .addr = 0x3E }, }; #define BMI270_FEATURE(inst) ( \ DT_INST_NODE_HAS_COMPAT(inst, bosch_bmi270_base) ? \ &bmi270_feature_base : \ &bmi270_feature_max_fifo) #if CONFIG_BMI270_TRIGGER #define BMI270_CONFIG_INT(inst) \ .int1 = GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, irq_gpios, 0, {}),\ .int2 = GPIO_DT_SPEC_INST_GET_BY_IDX_OR(inst, irq_gpios, 1, {}), #else #define BMI270_CONFIG_INT(inst) #endif /* Initializes a struct bmi270_config for an instance on a SPI bus. */ #define BMI270_CONFIG_SPI(inst) \ .bus.spi = SPI_DT_SPEC_INST_GET( \ inst, BMI270_SPI_OPERATION, 0), \ .bus_io = &bmi270_bus_io_spi, /* Initializes a struct bmi270_config for an instance on an I2C bus. */ #define BMI270_CONFIG_I2C(inst) \ .bus.i2c = I2C_DT_SPEC_INST_GET(inst), \ .bus_io = &bmi270_bus_io_i2c, #define BMI270_CREATE_INST(inst) \ \ static struct bmi270_data bmi270_drv_##inst; \ \ static const struct bmi270_config bmi270_config_##inst = { \ COND_CODE_1(DT_INST_ON_BUS(inst, spi), \ (BMI270_CONFIG_SPI(inst)), \ (BMI270_CONFIG_I2C(inst))) \ .feature = BMI270_FEATURE(inst), \ BMI270_CONFIG_INT(inst) \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, \ bmi270_init, \ NULL, \ &bmi270_drv_##inst, \ &bmi270_config_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &bmi270_driver_api); DT_INST_FOREACH_STATUS_OKAY(BMI270_CREATE_INST); ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
6,976
```unknown # BMI270 6 Axis IMU configuration menuconfig BMI270 bool "BMI270 Inertial measurement unit" default y depends on DT_HAS_BOSCH_BMI270_ENABLED select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI270),i2c) select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI270),spi) help Enable driver for BMI270 I2C-based imu sensor if BMI270 config BMI270_BUS_I2C bool default y depends on $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI270),i2c) config BMI270_BUS_SPI bool default y depends on $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI270),spi) choice BMI270_TRIGGER_MODE prompt "Trigger mode" help Specify the type of triggering to be used by the driver. config BMI270_TRIGGER_NONE bool "No trigger" config BMI270_TRIGGER_GLOBAL_THREAD bool "Use global thread" depends on GPIO select BMI270_TRIGGER config BMI270_TRIGGER_OWN_THREAD bool "Use own thread" depends on GPIO select BMI270_TRIGGER endchoice config BMI270_TRIGGER bool config BMI270_THREAD_PRIORITY int "Thread priority" depends on BMI270_TRIGGER_OWN_THREAD default 10 help Priority of thread used by the driver to handle interrupts. config BMI270_THREAD_STACK_SIZE int "Thread stack size" depends on BMI270_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. endif # BMI270 ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
357
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI270_BMI270_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI270_BMI270_H_ #include <stdint.h> #include <zephyr/device.h> #include <zephyr/sys/atomic.h> #include <zephyr/sys/util.h> #include <zephyr/types.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/spi.h> #include <zephyr/drivers/i2c.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/gpio.h> #define BMI270_REG_CHIP_ID 0x00 #define BMI270_REG_ERROR 0x02 #define BMI270_REG_STATUS 0x03 #define BMI270_REG_AUX_X_LSB 0x04 #define BMI270_REG_ACC_X_LSB 0x0C #define BMI270_REG_GYR_X_LSB 0x12 #define BMI270_REG_SENSORTIME_0 0x18 #define BMI270_REG_EVENT 0x1B #define BMI270_REG_INT_STATUS_0 0x1C #define BMI270_REG_SC_OUT_0 0x1E #define BMI270_REG_WR_GEST_ACT 0x20 #define BMI270_REG_INTERNAL_STATUS 0x21 #define BMI270_REG_TEMPERATURE_0 0x22 #define BMI270_REG_FIFO_LENGTH_0 0x24 #define BMI270_REG_FIFO_DATA 0x26 #define BMI270_REG_FEAT_PAGE 0x2F #define BMI270_REG_FEATURES_0 0x30 #define BMI270_REG_ACC_CONF 0x40 #define BMI270_REG_ACC_RANGE 0x41 #define BMI270_REG_GYR_CONF 0x42 #define BMI270_REG_GYR_RANGE 0x43 #define BMI270_REG_AUX_CONF 0x44 #define BMI270_REG_FIFO_DOWNS 0x45 #define BMI270_REG_FIFO_WTM_0 0x46 #define BMI270_REG_FIFO_CONFIG_0 0x48 #define BMI270_REG_SATURATION 0x4A #define BMI270_REG_AUX_DEV_ID 0x4B #define BMI270_REG_AUX_IF_CONF 0x4C #define BMI270_REG_AUX_RD_ADDR 0x4D #define BMI270_REG_AUX_WR_ADDR 0x4E #define BMI270_REG_AUX_WR_DATA 0x4F #define BMI270_REG_ERR_REG_MSK 0x52 #define BMI270_REG_INT1_IO_CTRL 0x53 #define BMI270_REG_INT2_IO_CTRL 0x54 #define BMI270_REG_INT_LATCH 0x55 #define BMI270_REG_INT1_MAP_FEAT 0x56 #define BMI270_REG_INT2_MAP_FEAT 0x57 #define BMI270_REG_INT_MAP_DATA 0x58 #define BMI270_REG_INIT_CTRL 0x59 #define BMI270_REG_INIT_ADDR_0 0x5B #define BMI270_REG_INIT_DATA 0x5E #define BMI270_REG_INTERNAL_ERROR 0x5F #define BMI270_REG_AUX_IF_TRIM 0x68 #define BMI270_REG_GYR_CRT_CONF 0x69 #define BMI270_REG_NVM_CONF 0x6A #define BMI270_REG_IF_CONF 0x6B #define BMI270_REG_DRV 0x6C #define BMI270_REG_ACC_SELF_TEST 0x6D #define BMI270_REG_GYR_SELF_TEST 0x6E #define BMI270_REG_NV_CONF 0x70 #define BMI270_REG_OFFSET_0 0x71 #define BMI270_REG_PWR_CONF 0x7C #define BMI270_REG_PWR_CTRL 0x7D #define BMI270_REG_CMD 0x7E #define BMI270_REG_MASK GENMASK(6, 0) #define BMI270_ANYMO_1_DURATION_POS 0 #define BMI270_ANYMO_1_DURATION_MASK BIT_MASK(12) #define BMI270_ANYMO_1_DURATION(n) ((n) << BMI270_ANYMO_1_DURATION_POS) #define BMI270_ANYMO_1_SELECT_X BIT(13) #define BMI270_ANYMO_1_SELECT_Y BIT(14) #define BMI270_ANYMO_1_SELECT_Z BIT(15) #define BMI270_ANYMO_1_SELECT_XYZ (BMI270_ANYMO_1_SELECT_X | \ BMI270_ANYMO_1_SELECT_Y | \ BMI270_ANYMO_1_SELECT_Y) #define BMI270_ANYMO_2_THRESHOLD_POS 0 #define BMI270_ANYMO_2_THRESHOLD_MASK BIT_MASK(10) #define BMI270_ANYMO_2_THRESHOLD(n) ((n) << BMI270_ANYMO_2_THRESHOLD_POS) #define BMI270_ANYMO_2_OUT_CONF_POS 11 #define BMI270_ANYMO_2_OUT_CONF_MASK (BIT(11) | BIT(12) | BIT(13) | BIT(14)) #define BMI270_ANYMO_2_ENABLE BIT(15) #define BMI270_ANYMO_2_OUT_CONF_OFF (0x00 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_0 (0x01 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_1 (0x02 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_2 (0x03 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_3 (0x04 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_4 (0x05 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_5 (0x06 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_6 (0x07 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_ANYMO_2_OUT_CONF_BIT_8 (0x08 << BMI270_ANYMO_2_OUT_CONF_POS) #define BMI270_INT_IO_CTRL_LVL BIT(1) /* Output level (0 = active low, 1 = active high) */ #define BMI270_INT_IO_CTRL_OD BIT(2) /* Open-drain (0 = push-pull, 1 = open-drain)*/ #define BMI270_INT_IO_CTRL_OUTPUT_EN BIT(3) /* Output enabled */ #define BMI270_INT_IO_CTRL_INPUT_EN BIT(4) /* Input enabled */ /* Applies to INT1_MAP_FEAT, INT2_MAP_FEAT, INT_STATUS_0 */ #define BMI270_INT_MAP_SIG_MOTION BIT(0) #define BMI270_INT_MAP_STEP_COUNTER BIT(1) #define BMI270_INT_MAP_ACTIVITY BIT(2) #define BMI270_INT_MAP_WRIST_WEAR_WAKEUP BIT(3) #define BMI270_INT_MAP_WRIST_GESTURE BIT(4) #define BMI270_INT_MAP_NO_MOTION BIT(5) #define BMI270_INT_MAP_ANY_MOTION BIT(6) #define BMI270_INT_MAP_DATA_FFULL_INT1 BIT(0) #define BMI270_INT_MAP_DATA_FWM_INT1 BIT(1) #define BMI270_INT_MAP_DATA_DRDY_INT1 BIT(2) #define BMI270_INT_MAP_DATA_ERR_INT1 BIT(3) #define BMI270_INT_MAP_DATA_FFULL_INT2 BIT(4) #define BMI270_INT_MAP_DATA_FWM_INT2 BIT(5) #define BMI270_INT_MAP_DATA_DRDY_INT2 BIT(6) #define BMI270_INT_MAP_DATA_ERR_INT2 BIT(7) #define BMI270_INT_STATUS_ANY_MOTION BIT(6) #define BMI270_CHIP_ID 0x24 #define BMI270_CMD_G_TRIGGER 0x02 #define BMI270_CMD_USR_GAIN 0x03 #define BMI270_CMD_NVM_PROG 0xA0 #define BMI270_CMD_FIFO_FLUSH OxB0 #define BMI270_CMD_SOFT_RESET 0xB6 #define BMI270_POWER_ON_TIME 500 #define BMI270_SOFT_RESET_TIME 2000 #define BMI270_ACC_SUS_TO_NOR_START_UP_TIME 2000 #define BMI270_GYR_SUS_TO_NOR_START_UP_TIME 45000 #define BMI270_GYR_FAST_START_UP_TIME 2000 #define BMI270_TRANSC_DELAY_SUSPEND 450 #define BMI270_TRANSC_DELAY_NORMAL 2 #define BMI270_PREPARE_CONFIG_LOAD 0x00 #define BMI270_COMPLETE_CONFIG_LOAD 0x01 #define BMI270_INST_MESSAGE_MSK 0x0F #define BMI270_INST_MESSAGE_NOT_INIT 0x00 #define BMI270_INST_MESSAGE_INIT_OK 0x01 #define BMI270_INST_MESSAGE_INIT_ERR 0x02 #define BMI270_INST_MESSAGE_DRV_ERR 0x03 #define BMI270_INST_MESSAGE_SNS_STOP 0x04 #define BMI270_INST_MESSAGE_NVM_ERR 0x05 #define BMI270_INST_MESSAGE_STRTUP_ERR 0x06 #define BMI270_INST_MESSAGE_COMPAT_ERR 0x07 #define BMI270_INST_AXES_REMAP_ERROR 0x20 #define BMI270_INST_ODR_50HZ_ERROR 0x40 #define BMI270_PWR_CONF_ADV_PWR_SAVE_MSK 0x01 #define BMI270_PWR_CONF_ADV_PWR_SAVE_EN 0x01 #define BMI270_PWR_CONF_ADV_PWR_SAVE_DIS 0x00 #define BMI270_PWR_CONF_FIFO_SELF_WKUP_MSK 0x02 #define BMI270_PWR_CONF_FIFO_SELF_WKUP_POS 0x01 #define BMI270_PWR_CONF_FIFO_SELF_WKUP_EN 0x01 #define BMI270_PWR_CONF_FIFO_SELF_WKUP_DIS 0x00 #define BMI270_PWR_CONF_FUP_EN_MSK 0x04 #define BMI270_PWR_CONF_FUP_EN_POS 0x02 #define BMI270_PWR_CONF_FUP_EN 0x01 #define BMI270_PWR_CONF_FUP_DIS 0x00 #define BMI270_PWR_CTRL_MSK 0x0F #define BMI270_PWR_CTRL_AUX_EN 0x01 #define BMI270_PWR_CTRL_GYR_EN 0x02 #define BMI270_PWR_CTRL_ACC_EN 0x04 #define BMI270_PWR_CTRL_TEMP_EN 0x08 #define BMI270_ACC_ODR_MSK 0x0F #define BMI270_ACC_ODR_25D32_HZ 0x01 #define BMI270_ACC_ODR_25D16_HZ 0x02 #define BMI270_ACC_ODR_25D8_HZ 0x03 #define BMI270_ACC_ODR_25D4_HZ 0x04 #define BMI270_ACC_ODR_25D2_HZ 0x05 #define BMI270_ACC_ODR_25_HZ 0x06 #define BMI270_ACC_ODR_50_HZ 0x07 #define BMI270_ACC_ODR_100_HZ 0x08 #define BMI270_ACC_ODR_200_HZ 0x09 #define BMI270_ACC_ODR_400_HZ 0x0A #define BMI270_ACC_ODR_800_HZ 0x0B #define BMI270_ACC_ODR_1600_HZ 0x0C #define BMI270_ACC_BWP_MSK 0x30 #define BMI270_ACC_BWP_POS 4 #define BMI270_ACC_BWP_OSR4_AVG1 0x00 #define BMI270_ACC_BWP_OSR2_AVG2 0x01 #define BMI270_ACC_BWP_NORM_AVG4 0x02 #define BMI270_ACC_BWP_CIC_AVG8 0x03 #define BMI270_ACC_BWP_RES_AVG16 0x04 #define BMI270_ACC_BWP_RES_AVG32 0x05 #define BMI270_ACC_BWP_RES_AVG64 0x06 #define BMI270_ACC_BWP_RES_AVG128 0x07 #define BMI270_ACC_FILT_MSK 0x80 #define BMI270_ACC_FILT_POS 7 #define BMI270_ACC_FILT_PWR_OPT 0x00 #define BMI270_ACC_FILT_PERF_OPT 0x01 #define BMI270_ACC_RANGE_MSK 0x03 #define BMI270_ACC_RANGE_2G 0x00 #define BMI270_ACC_RANGE_4G 0x01 #define BMI270_ACC_RANGE_8G 0x02 #define BMI270_ACC_RANGE_16G 0x03 #define BMI270_GYR_ODR_MSK 0x0F #define BMI270_GYR_ODR_25_HZ 0x06 #define BMI270_GYR_ODR_50_HZ 0x07 #define BMI270_GYR_ODR_100_HZ 0x08 #define BMI270_GYR_ODR_200_HZ 0x09 #define BMI270_GYR_ODR_400_HZ 0x0A #define BMI270_GYR_ODR_800_HZ 0x0B #define BMI270_GYR_ODR_1600_HZ 0x0C #define BMI270_GYR_ODR_3200_HZ 0x0D #define BMI270_GYR_BWP_MSK 0x30 #define BMI270_GYR_BWP_POS 4 #define BMI270_GYR_BWP_OSR4 0x00 #define BMI270_GYR_BWP_OSR2 0x01 #define BMI270_GYR_BWP_NORM 0x02 #define BMI270_GYR_FILT_NOISE_MSK 0x40 #define BMI270_GYR_FILT_NOISE_POS 6 #define BMI270_GYR_FILT_NOISE_PWR 0x00 #define BMI270_GYR_FILT_NOISE_PERF 0x01 #define BMI270_GYR_FILT_MSK 0x80 #define BMI270_GYR_FILT_POS 7 #define BMI270_GYR_FILT_PWR_OPT 0x00 #define BMI270_GYR_FILT_PERF_OPT 0x01 #define BMI270_GYR_RANGE_MSK 0x07 #define BMI270_GYR_RANGE_2000DPS 0x00 #define BMI270_GYR_RANGE_1000DPS 0x01 #define BMI270_GYR_RANGE_500DPS 0x02 #define BMI270_GYR_RANGE_250DPS 0x03 #define BMI270_GYR_RANGE_125DPS 0x04 #define BMI270_GYR_OIS_RANGE_MSK 0x80 #define BMI270_GYR_OIS_RANGE_POS 3 #define BMI270_GYR_OIS_RANGE_250DPS 0x00 #define BMI270_GYR_OIS_RANGE_2000DPS 0x01 #define BMI270_SET_BITS(reg_data, bitname, data) \ ((reg_data & ~(bitname##_MSK)) | ((data << bitname##_POS) \ & bitname##_MSK)) #define BMI270_SET_BITS_POS_0(reg_data, bitname, data) \ ((reg_data & ~(bitname##_MSK)) | (data & bitname##_MSK)) struct bmi270_data { int16_t ax, ay, az, gx, gy, gz; uint8_t acc_range, acc_odr, gyr_odr; uint16_t gyr_range; #if CONFIG_BMI270_TRIGGER const struct device *dev; struct k_mutex trigger_mutex; sensor_trigger_handler_t motion_handler; const struct sensor_trigger *motion_trigger; sensor_trigger_handler_t drdy_handler; const struct sensor_trigger *drdy_trigger; struct gpio_callback int1_cb; struct gpio_callback int2_cb; atomic_t int_flags; uint16_t anymo_1; uint16_t anymo_2; #if CONFIG_BMI270_TRIGGER_OWN_THREAD struct k_sem trig_sem; K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMI270_THREAD_STACK_SIZE); struct k_thread thread; #elif CONFIG_BMI270_TRIGGER_GLOBAL_THREAD struct k_work trig_work; #endif #endif /* CONFIG_BMI270_TRIGGER */ }; struct bmi270_feature_reg { /* Which feature page the register resides in */ uint8_t page; uint8_t addr; }; struct bmi270_feature_config { const char *name; const uint8_t *config_file; size_t config_file_len; struct bmi270_feature_reg *anymo_1; struct bmi270_feature_reg *anymo_2; }; union bmi270_bus { #if CONFIG_BMI270_BUS_SPI struct spi_dt_spec spi; #endif #if CONFIG_BMI270_BUS_I2C struct i2c_dt_spec i2c; #endif }; typedef int (*bmi270_bus_check_fn)(const union bmi270_bus *bus); typedef int (*bmi270_bus_init_fn)(const union bmi270_bus *bus); typedef int (*bmi270_reg_read_fn)(const union bmi270_bus *bus, uint8_t start, uint8_t *data, uint16_t len); typedef int (*bmi270_reg_write_fn)(const union bmi270_bus *bus, uint8_t start, const uint8_t *data, uint16_t len); struct bmi270_bus_io { bmi270_bus_check_fn check; bmi270_reg_read_fn read; bmi270_reg_write_fn write; bmi270_bus_init_fn init; }; struct bmi270_config { union bmi270_bus bus; const struct bmi270_bus_io *bus_io; const struct bmi270_feature_config *feature; #if CONFIG_BMI270_TRIGGER struct gpio_dt_spec int1; struct gpio_dt_spec int2; #endif }; #if CONFIG_BMI270_BUS_SPI #define BMI270_SPI_OPERATION (SPI_WORD_SET(8) | SPI_TRANSFER_MSB) #define BMI270_SPI_ACC_DELAY_US 2 extern const struct bmi270_bus_io bmi270_bus_io_spi; #endif #if CONFIG_BMI270_BUS_I2C extern const struct bmi270_bus_io bmi270_bus_io_i2c; #endif int bmi270_reg_read(const struct device *dev, uint8_t reg, uint8_t *data, uint16_t length); int bmi270_reg_write(const struct device *dev, uint8_t reg, const uint8_t *data, uint16_t length); int bmi270_reg_write_with_delay(const struct device *dev, uint8_t reg, const uint8_t *data, uint16_t length, uint32_t delay_us); #ifdef CONFIG_BMI270_TRIGGER int bmi270_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bmi270_init_interrupts(const struct device *dev); #endif #endif /* ZEPHYR_DRIVERS_SENSOR_BMI270_BMI270_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,124
```c /* * */ #define DT_DRV_COMPAT bosch_bma280 #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/sys/util.h> #include <zephyr/kernel.h> #include <zephyr/drivers/sensor.h> #include "bma280.h" #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(BMA280, CONFIG_SENSOR_LOG_LEVEL); static inline void setup_int1(const struct device *dev, bool enable) { const struct bma280_config *config = dev->config; gpio_pin_interrupt_configure_dt(&config->int1_gpio, (enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE)); } int bma280_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { const struct bma280_config *config = dev->config; uint64_t slope_th; if (!config->int1_gpio.port) { return -ENOTSUP; } if (chan != SENSOR_CHAN_ACCEL_XYZ) { return -ENOTSUP; } if (attr == SENSOR_ATTR_SLOPE_TH) { /* slope_th = (val * 10^6 * 2^10) / BMA280_PMU_FULL_RAGE */ slope_th = (uint64_t)val->val1 * 1000000U + (uint64_t)val->val2; slope_th = (slope_th * (1 << 10)) / BMA280_PMU_FULL_RANGE; if (i2c_reg_write_byte_dt(&config->i2c, BMA280_REG_SLOPE_TH, (uint8_t)slope_th) < 0) { LOG_DBG("Could not set slope threshold"); return -EIO; } } else if (attr == SENSOR_ATTR_SLOPE_DUR) { if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_5, BMA280_SLOPE_DUR_MASK, val->val1 << BMA280_SLOPE_DUR_SHIFT) < 0) { LOG_DBG("Could not set slope duration"); return -EIO; } } else { return -ENOTSUP; } return 0; } static void bma280_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { struct bma280_data *drv_data = CONTAINER_OF(cb, struct bma280_data, gpio_cb); ARG_UNUSED(pins); setup_int1(drv_data->dev, false); #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) k_sem_give(&drv_data->gpio_sem); #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) k_work_submit(&drv_data->work); #endif } static void bma280_thread_cb(const struct device *dev) { struct bma280_data *drv_data = dev->data; const struct bma280_config *config = dev->config; uint8_t status = 0U; int err = 0; /* check for data ready */ err = i2c_reg_read_byte_dt(&config->i2c, BMA280_REG_INT_STATUS_1, &status); if (status & BMA280_BIT_DATA_INT_STATUS && drv_data->data_ready_handler != NULL && err == 0) { drv_data->data_ready_handler(dev, drv_data->data_ready_trigger); } /* check for any motion */ err = i2c_reg_read_byte_dt(&config->i2c, BMA280_REG_INT_STATUS_0, &status); if (status & BMA280_BIT_SLOPE_INT_STATUS && drv_data->any_motion_handler != NULL && err == 0) { drv_data->any_motion_handler(dev, drv_data->any_motion_trigger); /* clear latched interrupt */ err = i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_RST_LATCH, BMA280_BIT_INT_LATCH_RESET, BMA280_BIT_INT_LATCH_RESET); if (err < 0) { LOG_DBG("Could not update clear the interrupt"); return; } } setup_int1(dev, true); } #ifdef CONFIG_BMA280_TRIGGER_OWN_THREAD static void bma280_thread(void *p1, void *p2, void *p3) { ARG_UNUSED(p2); ARG_UNUSED(p3); struct bma280_data *drv_data = p1; while (1) { k_sem_take(&drv_data->gpio_sem, K_FOREVER); bma280_thread_cb(drv_data->dev); } } #endif #ifdef CONFIG_BMA280_TRIGGER_GLOBAL_THREAD static void bma280_work_cb(struct k_work *work) { struct bma280_data *drv_data = CONTAINER_OF(work, struct bma280_data, work); bma280_thread_cb(drv_data->dev); } #endif int bma280_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bma280_data *drv_data = dev->data; const struct bma280_config *config = dev->config; if (!config->int1_gpio.port) { return -ENOTSUP; } if (trig->type == SENSOR_TRIG_DATA_READY) { /* disable data ready interrupt while changing trigger params */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_1, BMA280_BIT_DATA_EN, 0) < 0) { LOG_DBG("Could not disable data ready interrupt"); return -EIO; } drv_data->data_ready_handler = handler; if (handler == NULL) { return 0; } drv_data->data_ready_trigger = trig; /* enable data ready interrupt */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_1, BMA280_BIT_DATA_EN, BMA280_BIT_DATA_EN) < 0) { LOG_DBG("Could not enable data ready interrupt"); return -EIO; } } else if (trig->type == SENSOR_TRIG_DELTA) { /* disable any-motion interrupt while changing trigger params */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_0, BMA280_SLOPE_EN_XYZ, 0) < 0) { LOG_DBG("Could not disable data ready interrupt"); return -EIO; } drv_data->any_motion_handler = handler; if (handler == NULL) { return 0; } drv_data->any_motion_trigger = trig; /* enable any-motion interrupt */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_0, BMA280_SLOPE_EN_XYZ, BMA280_SLOPE_EN_XYZ) < 0) { LOG_DBG("Could not enable data ready interrupt"); return -EIO; } } else { return -ENOTSUP; } return 0; } int bma280_init_interrupt(const struct device *dev) { struct bma280_data *drv_data = dev->data; const struct bma280_config *config = dev->config; /* set latched interrupts */ if (i2c_reg_write_byte_dt(&config->i2c, BMA280_REG_INT_RST_LATCH, BMA280_BIT_INT_LATCH_RESET | BMA280_INT_MODE_LATCH) < 0) { LOG_DBG("Could not set latched interrupts"); return -EIO; } /* setup data ready gpio interrupt */ if (!gpio_is_ready_dt(&config->int1_gpio)) { LOG_ERR("GPIO device not ready"); return -ENODEV; } gpio_pin_configure_dt(&config->int1_gpio, GPIO_INPUT); gpio_init_callback(&drv_data->gpio_cb, bma280_gpio_callback, BIT(config->int1_gpio.pin)); if (gpio_add_callback(config->int1_gpio.port, &drv_data->gpio_cb) < 0) { LOG_DBG("Could not set gpio callback"); return -EIO; } /* map data ready interrupt to INT1 */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_MAP_1, BMA280_INT_MAP_1_BIT_DATA, BMA280_INT_MAP_1_BIT_DATA) < 0) { LOG_DBG("Could not map data ready interrupt pin"); return -EIO; } /* map any-motion interrupt to INT1 */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_MAP_0, BMA280_INT_MAP_0_BIT_SLOPE, BMA280_INT_MAP_0_BIT_SLOPE) < 0) { LOG_DBG("Could not map any-motion interrupt pin"); return -EIO; } if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_1, BMA280_BIT_DATA_EN, 0) < 0) { LOG_DBG("Could not disable data ready interrupt"); return -EIO; } /* disable any-motion interrupt */ if (i2c_reg_update_byte_dt(&config->i2c, BMA280_REG_INT_EN_0, BMA280_SLOPE_EN_XYZ, 0) < 0) { LOG_DBG("Could not disable data ready interrupt"); return -EIO; } drv_data->dev = dev; #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) k_sem_init(&drv_data->gpio_sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&drv_data->thread, drv_data->thread_stack, CONFIG_BMA280_THREAD_STACK_SIZE, bma280_thread, drv_data, NULL, NULL, K_PRIO_COOP(CONFIG_BMA280_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) drv_data->work.handler = bma280_work_cb; #endif setup_int1(dev, true); return 0; } ```
/content/code_sandbox/drivers/sensor/bosch/bma280/bma280_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,268
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ #define ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ #include <zephyr/device.h> #include <zephyr/sys/util.h> #include <zephyr/types.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #include <zephyr/kernel.h> #define BMA280_REG_CHIP_ID 0x00 #if DT_INST_PROP(0, is_bmc150) #define BMA280_CHIP_ID 0xFA #else #define BMA280_CHIP_ID 0xFB #endif #define BMA280_REG_PMU_BW 0x10 #if CONFIG_BMA280_PMU_BW_1 #define BMA280_PMU_BW 0x08 #elif CONFIG_BMA280_PMU_BW_2 #define BMA280_PMU_BW 0x09 #elif CONFIG_BMA280_PMU_BW_3 #define BMA280_PMU_BW 0x0A #elif CONFIG_BMA280_PMU_BW_4 #define BMA280_PMU_BW 0x0B #elif CONFIG_BMA280_PMU_BW_5 #define BMA280_PMU_BW 0x0C #elif CONFIG_BMA280_PMU_BW_6 #define BMA280_PMU_BW 0x0D #elif CONFIG_BMA280_PMU_BW_7 #define BMA280_PMU_BW 0x0E #elif CONFIG_BMA280_PMU_BW_8 #define BMA280_PMU_BW 0x0F #endif /* * BMA280_PMU_FULL_RANGE measured in milli-m/s^2 instead * of m/s^2 to avoid using struct sensor_value for it */ #define BMA280_REG_PMU_RANGE 0x0F #if CONFIG_BMA280_PMU_RANGE_2G #define BMA280_PMU_RANGE 0x03 #define BMA280_PMU_FULL_RANGE (4 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_4G #define BMA280_PMU_RANGE 0x05 #define BMA280_PMU_FULL_RANGE (8 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_8G #define BMA280_PMU_RANGE 0x08 #define BMA280_PMU_FULL_RANGE (16 * SENSOR_G) #elif CONFIG_BMA280_PMU_RANGE_16G #define BMA280_PMU_RANGE 0x0C #define BMA280_PMU_FULL_RANGE (32 * SENSOR_G) #endif #define BMA280_REG_TEMP 0x08 #define BMA280_REG_INT_STATUS_0 0x09 #define BMA280_BIT_SLOPE_INT_STATUS BIT(2) #define BMA280_REG_INT_STATUS_1 0x0A #define BMA280_BIT_DATA_INT_STATUS BIT(7) #define BMA280_REG_INT_EN_0 0x16 #define BMA280_BIT_SLOPE_EN_X BIT(0) #define BMA280_BIT_SLOPE_EN_Y BIT(1) #define BMA280_BIT_SLOPE_EN_Z BIT(2) #define BMA280_SLOPE_EN_XYZ (BMA280_BIT_SLOPE_EN_X | \ BMA280_BIT_SLOPE_EN_Y | BMA280_BIT_SLOPE_EN_X) #define BMA280_REG_INT_EN_1 0x17 #define BMA280_BIT_DATA_EN BIT(4) #define BMA280_REG_INT_MAP_0 0x19 #define BMA280_INT_MAP_0_BIT_SLOPE BIT(2) #define BMA280_REG_INT_MAP_1 0x1A #define BMA280_INT_MAP_1_BIT_DATA BIT(0) #define BMA280_REG_INT_RST_LATCH 0x21 #define BMA280_INT_MODE_LATCH 0x0F #define BMA280_BIT_INT_LATCH_RESET BIT(7) #define BMA280_REG_INT_5 0x27 #define BMA280_SLOPE_DUR_SHIFT 0 #define BMA280_SLOPE_DUR_MASK (3 << BMA280_SLOPE_DUR_SHIFT) #define BMA280_REG_SLOPE_TH 0x28 #define BMA280_REG_ACCEL_X_LSB 0x2 #define BMA280_REG_ACCEL_Y_LSB 0x4 #define BMA280_REG_ACCEL_Z_LSB 0x6 #if DT_INST_PROP(0, is_bmc150) #define BMA280_ACCEL_LSB_BITS 4 #define BMA280_ACCEL_LSB_SHIFT 4 #else #define BMA280_ACCEL_LSB_BITS 6 #define BMA280_ACCEL_LSB_SHIFT 2 #endif #define BMA280_ACCEL_LSB_MASK \ (BIT_MASK(BMA280_ACCEL_LSB_BITS) << BMA280_ACCEL_LSB_SHIFT) #define BMA280_REG_ACCEL_X_MSB 0x3 #define BMA280_REG_ACCEL_Y_MSB 0x5 #define BMA280_REG_ACCEL_Z_MSB 0x7 #define BMA280_THREAD_PRIORITY 10 #define BMA280_THREAD_STACKSIZE_UNIT 1024 struct bma280_data { int16_t x_sample; int16_t y_sample; int16_t z_sample; int8_t temp_sample; #ifdef CONFIG_BMA280_TRIGGER const struct device *dev; struct gpio_callback gpio_cb; const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; const struct sensor_trigger *any_motion_trigger; sensor_trigger_handler_t any_motion_handler; #if defined(CONFIG_BMA280_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_BMA280_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem gpio_sem; #elif defined(CONFIG_BMA280_TRIGGER_GLOBAL_THREAD) struct k_work work; #endif #endif /* CONFIG_BMA280_TRIGGER */ }; struct bma280_config { struct i2c_dt_spec i2c; #ifdef CONFIG_BMA280_TRIGGER struct gpio_dt_spec int1_gpio; #endif }; #ifdef CONFIG_BMA280_TRIGGER int bma280_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bma280_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val); int bma280_init_interrupt(const struct device *dev); #endif #endif /* ZEPHYR_DRIVERS_SENSOR_BMA280_BMA280_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bma280/bma280.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,457
```unknown # BMA280 Three Axis Accelerometer configuration options menuconfig BMA280 bool "BMA280 Three Axis Accelerometer Family" default y depends on DT_HAS_BOSCH_BMA280_ENABLED select I2C help Enable driver for BMA280 I2C-based triaxial accelerometer sensor family. if BMA280 choice prompt "Trigger mode" default BMA280_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config BMA280_TRIGGER_NONE bool "No trigger" config BMA280_TRIGGER_GLOBAL_THREAD bool "Use global thread" depends on GPIO select BMA280_TRIGGER config BMA280_TRIGGER_OWN_THREAD bool "Use own thread" depends on GPIO select BMA280_TRIGGER endchoice config BMA280_TRIGGER bool config BMA280_THREAD_PRIORITY int "Thread priority" depends on BMA280_TRIGGER_OWN_THREAD default 10 help Priority of thread used by the driver to handle interrupts. config BMA280_THREAD_STACK_SIZE int "Thread stack size" depends on BMA280_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. choice prompt "Acceleration measurement range" default BMA280_PMU_RANGE_2G help Measurement range for acceleration values. config BMA280_PMU_RANGE_2G bool "+/-2g" config BMA280_PMU_RANGE_4G bool "+/-4g" config BMA280_PMU_RANGE_8G bool "+/-8g" config BMA280_PMU_RANGE_16G bool "+/-16g" endchoice choice prompt "Acceleration data filter bandwidth" default BMA280_PMU_BW_7 help Bandwidth of filtered acceleration data. config BMA280_PMU_BW_1 bool "7.81Hz" config BMA280_PMU_BW_2 bool "15.63HZ" config BMA280_PMU_BW_3 bool "31.25Hz" config BMA280_PMU_BW_4 bool "62.5Hz" config BMA280_PMU_BW_5 bool "125Hz" config BMA280_PMU_BW_6 bool "250HZ" config BMA280_PMU_BW_7 bool "500Hz" config BMA280_PMU_BW_8 bool "unfiltered" endchoice endif # BMA280 ```
/content/code_sandbox/drivers/sensor/bosch/bma280/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
544
```c /* * */ #define DT_DRV_COMPAT bosch_bma280 #include <zephyr/drivers/i2c.h> #include <zephyr/init.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/__assert.h> #include <zephyr/logging/log.h> #include "bma280.h" LOG_MODULE_REGISTER(BMA280, CONFIG_SENSOR_LOG_LEVEL); static int bma280_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bma280_data *drv_data = dev->data; const struct bma280_config *config = dev->config; uint8_t buf[6]; uint8_t lsb; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); /* * since all accel data register addresses are consecutive, * a burst read can be used to read all the samples */ if (i2c_burst_read_dt(&config->i2c, BMA280_REG_ACCEL_X_LSB, buf, 6) < 0) { LOG_DBG("Could not read accel axis data"); return -EIO; } lsb = (buf[0] & BMA280_ACCEL_LSB_MASK) >> BMA280_ACCEL_LSB_SHIFT; drv_data->x_sample = (((int8_t)buf[1]) << BMA280_ACCEL_LSB_BITS) | lsb; lsb = (buf[2] & BMA280_ACCEL_LSB_MASK) >> BMA280_ACCEL_LSB_SHIFT; drv_data->y_sample = (((int8_t)buf[3]) << BMA280_ACCEL_LSB_BITS) | lsb; lsb = (buf[4] & BMA280_ACCEL_LSB_MASK) >> BMA280_ACCEL_LSB_SHIFT; drv_data->z_sample = (((int8_t)buf[5]) << BMA280_ACCEL_LSB_BITS) | lsb; if (i2c_reg_read_byte_dt(&config->i2c, BMA280_REG_TEMP, (uint8_t *)&drv_data->temp_sample) < 0) { LOG_DBG("Could not read temperature data"); return -EIO; } return 0; } static void bma280_channel_accel_convert(struct sensor_value *val, int64_t raw_val) { /* * accel_val = (sample * BMA280_PMU_FULL_RAGE) / * (2^data_width * 10^6) */ raw_val = (raw_val * BMA280_PMU_FULL_RANGE) / (1 << (8 + BMA280_ACCEL_LSB_BITS)); val->val1 = raw_val / 1000000; val->val2 = raw_val % 1000000; /* normalize val to make sure val->val2 is positive */ if (val->val2 < 0) { val->val1 -= 1; val->val2 += 1000000; } } static int bma280_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bma280_data *drv_data = dev->data; /* * See datasheet "Sensor data" section for * more details on processing sample data. */ if (chan == SENSOR_CHAN_ACCEL_X) { bma280_channel_accel_convert(val, drv_data->x_sample); } else if (chan == SENSOR_CHAN_ACCEL_Y) { bma280_channel_accel_convert(val, drv_data->y_sample); } else if (chan == SENSOR_CHAN_ACCEL_Z) { bma280_channel_accel_convert(val, drv_data->z_sample); } else if (chan == SENSOR_CHAN_ACCEL_XYZ) { bma280_channel_accel_convert(val, drv_data->x_sample); bma280_channel_accel_convert(val + 1, drv_data->y_sample); bma280_channel_accel_convert(val + 2, drv_data->z_sample); } else if (chan == SENSOR_CHAN_DIE_TEMP) { /* temperature_val = 23 + sample / 2 */ val->val1 = (drv_data->temp_sample >> 1) + 23; val->val2 = 500000 * (drv_data->temp_sample & 1); return 0; } else { return -ENOTSUP; } return 0; } static const struct sensor_driver_api bma280_driver_api = { #if CONFIG_BMA280_TRIGGER .attr_set = bma280_attr_set, .trigger_set = bma280_trigger_set, #endif .sample_fetch = bma280_sample_fetch, .channel_get = bma280_channel_get, }; int bma280_init(const struct device *dev) { const struct bma280_config *config = dev->config; uint8_t id = 0U; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("I2C bus device not ready"); return -ENODEV; } /* read device ID */ if (i2c_reg_read_byte_dt(&config->i2c, BMA280_REG_CHIP_ID, &id) < 0) { LOG_DBG("Could not read chip id"); return -EIO; } if (id != BMA280_CHIP_ID) { LOG_DBG("Unexpected chip id (%x)", id); return -EIO; } if (i2c_reg_write_byte_dt(&config->i2c, BMA280_REG_PMU_BW, BMA280_PMU_BW) < 0) { LOG_DBG("Could not set data filter bandwidth"); return -EIO; } /* set g-range */ if (i2c_reg_write_byte_dt(&config->i2c, BMA280_REG_PMU_RANGE, BMA280_PMU_RANGE) < 0) { LOG_DBG("Could not set data g-range"); return -EIO; } #ifdef CONFIG_BMA280_TRIGGER if (config->int1_gpio.port) { if (bma280_init_interrupt(dev) < 0) { LOG_DBG("Could not initialize interrupts"); return -EIO; } } #endif return 0; } #define BMA280_DEFINE(inst) \ static struct bma280_data bma280_data_##inst; \ \ static const struct bma280_config bma280_config##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ IF_ENABLED(CONFIG_BMA280_TRIGGER, \ (.int1_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int1_gpios, { 0 }),)) \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, bma280_init, NULL, &bma280_data_##inst, \ &bma280_config##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &bma280_driver_api); \ DT_INST_FOREACH_STATUS_OKAY(BMA280_DEFINE) ```
/content/code_sandbox/drivers/sensor/bosch/bma280/bma280.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,512
```c /* * * * Emulator for the Bosch BMI160 accelerometer / gyro. This supports basic * init and reading of canned samples. It supports both I2C and SPI buses. */ #define DT_DRV_COMPAT bosch_bmi160 #define LOG_LEVEL CONFIG_SPI_LOG_LEVEL #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(bosch_bmi160); #include <zephyr/sys/byteorder.h> #include <bmi160.h> #include <zephyr/device.h> #include <zephyr/drivers/emul.h> #include <zephyr/drivers/emul_sensor.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/i2c_emul.h> #include <zephyr/drivers/spi.h> #include <zephyr/drivers/spi_emul.h> #include <zephyr/sys/util.h> /** Run-time data used by the emulator */ struct bmi160_emul_data { uint8_t pmu_status; /** Current register to read (address) */ uint32_t cur_reg; }; /** Static configuration for the emulator */ struct bmi160_emul_cfg { /** Chip registers */ uint8_t *reg; union { /** Unit address (chip select ordinal) of emulator */ uint16_t chipsel; /** I2C address of emulator */ uint16_t addr; }; }; /* Names for the PMU components */ static const char *const pmu_name[] = {"acc", "gyr", "mag", "INV"}; int emul_bmi160_get_reg_value(const struct emul *target, int reg_number, uint8_t *out, size_t count) { const struct bmi160_emul_cfg *cfg = target->cfg; if (reg_number < 0 || reg_number + count > BMI160_REG_COUNT) { return -EINVAL; } memcpy(out, cfg->reg + reg_number, count); return 0; } static void reg_write(const struct emul *target, int regn, int val) { struct bmi160_emul_data *data = target->data; const struct bmi160_emul_cfg *cfg = target->cfg; LOG_DBG("write %x = %x", regn, val); cfg->reg[regn] = val; switch (regn) { case BMI160_REG_ACC_CONF: LOG_DBG(" * acc conf"); break; case BMI160_REG_ACC_RANGE: LOG_DBG(" * acc range"); break; case BMI160_REG_GYR_CONF: LOG_DBG(" * gyr conf"); break; case BMI160_REG_GYR_RANGE: LOG_DBG(" * gyr range"); break; case BMI160_REG_CMD: switch (val) { case BMI160_CMD_SOFT_RESET: LOG_DBG(" * soft reset"); break; default: if ((val & BMI160_CMD_PMU_BIT) == BMI160_CMD_PMU_BIT) { int which = (val & BMI160_CMD_PMU_MASK) >> BMI160_CMD_PMU_SHIFT; int shift; int pmu_val = val & BMI160_CMD_PMU_VAL_MASK; switch (which) { case 0: shift = BMI160_PMU_STATUS_ACC_POS; break; case 1: shift = BMI160_PMU_STATUS_GYR_POS; break; case 2: default: shift = BMI160_PMU_STATUS_MAG_POS; break; } data->pmu_status &= 3 << shift; data->pmu_status |= pmu_val << shift; LOG_DBG(" * pmu %s = %x, new status %x", pmu_name[which], pmu_val, data->pmu_status); } else { LOG_DBG("Unknown command %x", val); } break; } break; default: LOG_DBG("Unknown write %x", regn); } } static int reg_read(const struct emul *target, int regn) { struct bmi160_emul_data *data = target->data; const struct bmi160_emul_cfg *cfg = target->cfg; int val; LOG_DBG("read %x =", regn); val = cfg->reg[regn]; switch (regn) { case BMI160_REG_CHIPID: LOG_DBG(" * get chipid"); break; case BMI160_REG_PMU_STATUS: LOG_DBG(" * get pmu"); val = data->pmu_status; break; case BMI160_REG_STATUS: LOG_DBG(" * status"); val |= BMI160_DATA_READY_BIT_MASK; break; case BMI160_REG_ACC_CONF: LOG_DBG(" * acc conf"); break; case BMI160_REG_GYR_CONF: LOG_DBG(" * gyr conf"); break; case BMI160_SPI_START: LOG_DBG(" * Bus start"); break; case BMI160_REG_ACC_RANGE: LOG_DBG(" * acc range"); break; case BMI160_REG_GYR_RANGE: LOG_DBG(" * gyr range"); break; default: LOG_DBG("Unknown read %x", regn); } LOG_DBG(" = %x", val); return val; } #if BMI160_BUS_SPI static int bmi160_emul_io_spi(const struct emul *target, const struct spi_config *config, const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs) { struct bmi160_emul_data *data; const struct spi_buf *tx, *txd, *rxd; unsigned int regn, val; int count; ARG_UNUSED(config); data = target->data; __ASSERT_NO_MSG(tx_bufs || rx_bufs); __ASSERT_NO_MSG(!tx_bufs || !rx_bufs || tx_bufs->count == rx_bufs->count); count = tx_bufs ? tx_bufs->count : rx_bufs->count; if (count != 2) { LOG_DBG("Unknown tx_bufs->count %d", count); return -EIO; } tx = tx_bufs->buffers; txd = &tx_bufs->buffers[1]; rxd = rx_bufs ? &rx_bufs->buffers[1] : NULL; if (tx->len != 1) { LOG_DBG("Unknown tx->len %d", tx->len); return -EIO; } regn = *(uint8_t *)tx->buf; if ((regn & BMI160_REG_READ) && rxd == NULL) { LOG_ERR("Cannot read without rxd"); return -EPERM; } if (txd->len == 1) { if (regn & BMI160_REG_READ) { regn &= BMI160_REG_MASK; val = reg_read(target, regn); *(uint8_t *)rxd->buf = val; } else { val = *(uint8_t *)txd->buf; reg_write(target, regn, val); } } else { if (regn & BMI160_REG_READ) { regn &= BMI160_REG_MASK; for (int i = 0; i < txd->len; ++i) { ((uint8_t *)rxd->buf)[i] = reg_read(target, regn + i); } } else { LOG_ERR("Unknown sample write"); return -EIO; } } return 0; } #endif #if BMI160_BUS_I2C static int bmi160_emul_transfer_i2c(const struct emul *target, struct i2c_msg *msgs, int num_msgs, int addr) { struct bmi160_emul_data *data; data = target->data; __ASSERT_NO_MSG(msgs && num_msgs); i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false); switch (num_msgs) { case 2: if (msgs->flags & I2C_MSG_READ) { LOG_ERR("Unexpected read"); return -EIO; } if (msgs->len != 1) { LOG_ERR("Unexpected msg0 length %d", msgs->len); return -EIO; } data->cur_reg = msgs->buf[0]; /* Now process the 'read' part of the message */ msgs++; if (msgs->flags & I2C_MSG_READ) { for (int i = 0; i < msgs->len; ++i) { msgs->buf[i] = reg_read(target, data->cur_reg + i); } } else { if (msgs->len != 1) { LOG_ERR("Unexpected msg1 length %d", msgs->len); } reg_write(target, data->cur_reg, msgs->buf[0]); } break; default: LOG_ERR("Invalid number of messages: %d", num_msgs); return -EIO; } return 0; } #endif /* Device instantiation */ #if BMI160_BUS_SPI static struct spi_emul_api bmi160_emul_api_spi = { .io = bmi160_emul_io_spi, }; #endif #if BMI160_BUS_I2C static struct i2c_emul_api bmi160_emul_api_i2c = { .transfer = bmi160_emul_transfer_i2c, }; #endif static int bmi160_emul_backend_set_channel(const struct emul *target, struct sensor_chan_spec ch, const q31_t *value, int8_t shift) { const struct bmi160_emul_cfg *cfg = target->cfg; int64_t intermediate = *value; q31_t scale; int8_t scale_shift = 0; int reg_lsb; switch (ch.chan_type) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: reg_lsb = BMI160_REG_DATA_ACC_X + (ch.chan_type - SENSOR_CHAN_ACCEL_X) * 2; scale = 0x4e7404ea; switch (FIELD_GET(GENMASK(3, 0), cfg->reg[BMI160_REG_ACC_RANGE])) { case BMI160_ACC_RANGE_4G: scale_shift = 6; break; case BMI160_ACC_RANGE_8G: scale_shift = 7; break; case BMI160_ACC_RANGE_16G: scale_shift = 8; break; default: scale_shift = 5; break; } break; case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: reg_lsb = BMI160_REG_DATA_GYR_X + (ch.chan_type - SENSOR_CHAN_GYRO_X) * 2; scale = 0x45d02bea; switch (FIELD_GET(GENMASK(2, 0), cfg->reg[BMI160_REG_GYR_RANGE])) { case BMI160_GYR_RANGE_2000DPS: scale_shift = 6; break; case BMI160_GYR_RANGE_1000DPS: scale_shift = 5; break; case BMI160_GYR_RANGE_500DPS: scale_shift = 4; break; case BMI160_GYR_RANGE_250DPS: scale_shift = 3; break; case BMI160_GYR_RANGE_125DPS: scale_shift = 2; break; default: return -EINVAL; } break; case SENSOR_CHAN_DIE_TEMP: reg_lsb = BMI160_REG_TEMPERATURE0; scale = 0x8000; scale_shift = 7; break; default: return -EINVAL; } if (shift < scale_shift) { /* Original value doesn't have enough int bits, fix it */ intermediate >>= scale_shift - shift; } else if (shift > 0 && shift > scale_shift) { /* Original value might be out-of-bounds, fix it (we're going to lose precision) */ intermediate <<= shift - scale_shift; } if (ch.chan_type == SENSOR_CHAN_DIE_TEMP) { /* Need to subtract 23C */ intermediate -= INT64_C(23) << (31 - scale_shift); } intermediate = CLAMP(DIV_ROUND_CLOSEST(intermediate * INT16_MAX, scale), INT16_MIN, INT16_MAX); cfg->reg[reg_lsb] = FIELD_GET(GENMASK64(7, 0), intermediate); cfg->reg[reg_lsb + 1] = FIELD_GET(GENMASK64(15, 8), intermediate); return 0; } static int bmi160_emul_backend_get_sample_range(const struct emul *target, struct sensor_chan_spec ch, q31_t *lower, q31_t *upper, q31_t *epsilon, int8_t *shift) { const struct bmi160_emul_cfg *cfg = target->cfg; switch (ch.chan_type) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: { uint8_t acc_range = cfg->reg[BMI160_REG_ACC_RANGE]; switch (acc_range) { case BMI160_ACC_RANGE_2G: *shift = 5; break; case BMI160_ACC_RANGE_4G: *shift = 6; break; case BMI160_ACC_RANGE_8G: *shift = 7; break; case BMI160_ACC_RANGE_16G: *shift = 8; break; default: return -EINVAL; } int64_t intermediate = ((int64_t)(2 * 9.80665 * INT32_MAX)) >> 5; *upper = intermediate; *lower = -(*upper); *epsilon = intermediate * 2 / (1 << (16 - *shift)); return 0; } case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: { uint8_t gyro_range = cfg->reg[BMI160_REG_GYR_RANGE]; switch (gyro_range) { case BMI160_GYR_RANGE_125DPS: *shift = 2; break; case BMI160_GYR_RANGE_250DPS: *shift = 3; break; case BMI160_GYR_RANGE_500DPS: *shift = 4; break; case BMI160_GYR_RANGE_1000DPS: *shift = 5; break; case BMI160_GYR_RANGE_2000DPS: *shift = 6; break; default: return -EINVAL; } int64_t intermediate = (int64_t)(125 * 3.141592654 * INT32_MAX / 180) >> 2; *upper = intermediate; *lower = -(*upper); *epsilon = intermediate * 2 / (1 << (16 - *shift)); return 0; } default: return -EINVAL; } } static int bmi160_emul_backend_set_offset(const struct emul *target, struct sensor_chan_spec ch, const q31_t *values, int8_t shift) { if (ch.chan_type != SENSOR_CHAN_ACCEL_XYZ && ch.chan_type != SENSOR_CHAN_GYRO_XYZ) { return -EINVAL; } const struct bmi160_emul_cfg *cfg = target->cfg; q31_t scale; int8_t scale_shift = 0; if (values[0] == 0 && values[1] == 0 && values[2] == 0) { if (ch.chan_type == SENSOR_CHAN_ACCEL_XYZ) { cfg->reg[BMI160_REG_OFFSET_EN] &= ~BIT(BMI160_ACC_OFS_EN_POS); } else { cfg->reg[BMI160_REG_OFFSET_EN] &= ~BIT(BMI160_GYR_OFS_EN_POS); } } else { if (ch.chan_type == SENSOR_CHAN_ACCEL_XYZ) { cfg->reg[BMI160_REG_OFFSET_EN] |= BIT(BMI160_ACC_OFS_EN_POS); } else { cfg->reg[BMI160_REG_OFFSET_EN] |= BIT(BMI160_GYR_OFS_EN_POS); } } if (ch.chan_type == SENSOR_CHAN_ACCEL_XYZ) { /* * bits = (values[i]mps2 / 9.80665g/mps2) / 0.0039g * = values[i] / 0.038245935mps2/bit * 0.038245935 in Q31 format is 0x4e53e28 with shift 0 */ scale = 0x4e53e28; } else { /* * bits = (values[i]rad/s * 180 / pi) / 0.061deg/s * = values[i] / 0.001064651rad/s */ scale = 0x22e2f0; } for (int i = 0; i < 3; ++i) { int64_t intermediate = values[i]; if (shift > scale_shift) { /* Input uses a bigger scale, we need to increase its value to match */ intermediate <<= (shift - scale_shift); } else if (shift < scale_shift) { /* Scale uses a bigger shift, we need to decrease its value to match */ scale >>= (scale_shift - shift); } int64_t reg_value = intermediate / scale; __ASSERT_NO_MSG(ch.chan_type != SENSOR_CHAN_ACCEL_XYZ || (reg_value >= INT8_MIN && reg_value <= INT8_MAX)); __ASSERT_NO_MSG(ch.chan_type != SENSOR_CHAN_GYRO_XYZ || (reg_value >= -0x1ff - 1 && reg_value <= 0x1ff)); if (ch.chan_type == SENSOR_CHAN_ACCEL_XYZ) { cfg->reg[BMI160_REG_OFFSET_ACC_X + i] = reg_value & 0xff; } else { cfg->reg[BMI160_REG_OFFSET_GYR_X + i] = reg_value & 0xff; cfg->reg[BMI160_REG_OFFSET_EN] = (cfg->reg[BMI160_REG_OFFSET_EN] & ~GENMASK(i * 2 + 1, i * 2)) | (reg_value & GENMASK(9, 8)); } } return 0; } static int bmi160_emul_backend_set_attribute(const struct emul *target, struct sensor_chan_spec ch, enum sensor_attribute attribute, const void *value) { if (attribute == SENSOR_ATTR_OFFSET && (ch.chan_type == SENSOR_CHAN_ACCEL_XYZ || ch.chan_type == SENSOR_CHAN_GYRO_XYZ)) { const struct sensor_three_axis_attribute *attribute_value = value; return bmi160_emul_backend_set_offset(target, ch, attribute_value->values, attribute_value->shift); } return -EINVAL; } static int bmi160_emul_backend_get_attribute_metadata(const struct emul *target, struct sensor_chan_spec ch, enum sensor_attribute attribute, q31_t *min, q31_t *max, q31_t *increment, int8_t *shift) { ARG_UNUSED(target); switch (ch.chan_type) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: if (attribute == SENSOR_ATTR_OFFSET) { /* Offset uses 3.9mg per bit in an 8 bit register: * 0.0039g * 9.8065m/s2: yields the increment in SI units * * INT8_MIN (or MAX) : yields the minimum (or maximum) values * * INT32_MAX >> 3 : converts to q31 format within range [-8, 8] */ *min = (q31_t)((int64_t)(0.0039 * 9.8065 * INT8_MIN * INT32_MAX) >> 3); *max = (q31_t)((int64_t)(0.0039 * 9.8065 * INT8_MAX * INT32_MAX) >> 3); *increment = (q31_t)((int64_t)(0.0039 * 9.8065 * INT32_MAX) >> 3); *shift = 3; return 0; } return -EINVAL; case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: if (attribute == SENSOR_ATTR_OFFSET) { /* Offset uses 0.061deg/s per bit in an 10 bit register: * 0.061deg/s * pi / 180: yields the increment in SI units * * INT10_MIN (or MAX) : yields the minimum (or maximum) values * * INT32_MAX : converts to q31 format within range [-1, 1] */ *min = (q31_t)(0.061 * 3.141593 / 180.0 * -512 * INT32_MAX); *max = (q31_t)(0.061 * 3.141593 / 180.0 * 511 * INT32_MAX); *increment = (q31_t)(0.061 * 3.141593 / 180.0 * INT32_MAX); *shift = 0; return 0; } return -EINVAL; default: return -EINVAL; } } static const struct emul_sensor_driver_api backend_api = { .set_channel = bmi160_emul_backend_set_channel, .get_sample_range = bmi160_emul_backend_get_sample_range, .set_attribute = bmi160_emul_backend_set_attribute, .get_attribute_metadata = bmi160_emul_backend_get_attribute_metadata, }; static int emul_bosch_bmi160_init(const struct emul *target, const struct device *parent) { const struct bmi160_emul_cfg *cfg = target->cfg; struct bmi160_emul_data *data = target->data; uint8_t *reg = cfg->reg; ARG_UNUSED(parent); data->pmu_status = 0; reg[BMI160_REG_CHIPID] = BMI160_CHIP_ID; return 0; } #define BMI160_EMUL_DATA(n) \ static uint8_t bmi160_emul_reg_##n[BMI160_REG_COUNT]; \ static struct bmi160_emul_data bmi160_emul_data_##n; #define BMI160_EMUL_DEFINE(n, bus_api) \ EMUL_DT_INST_DEFINE(n, emul_bosch_bmi160_init, &bmi160_emul_data_##n, \ &bmi160_emul_cfg_##n, &bus_api, &backend_api) /* Instantiation macros used when a device is on a SPI bus */ #define BMI160_EMUL_SPI(n) \ BMI160_EMUL_DATA(n) \ static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = { \ .reg = bmi160_emul_reg_##n, .chipsel = DT_INST_REG_ADDR(n)}; \ BMI160_EMUL_DEFINE(n, bmi160_emul_api_spi) #define BMI160_EMUL_I2C(n) \ BMI160_EMUL_DATA(n) \ static const struct bmi160_emul_cfg bmi160_emul_cfg_##n = {.reg = bmi160_emul_reg_##n, \ .addr = DT_INST_REG_ADDR(n)}; \ BMI160_EMUL_DEFINE(n, bmi160_emul_api_i2c) /* * Main instantiation macro. Use of COND_CODE_1() selects the right * bus-specific macro at preprocessor time. */ #define BMI160_EMUL(n) \ COND_CODE_1(DT_INST_ON_BUS(n, spi), (BMI160_EMUL_SPI(n)), (BMI160_EMUL_I2C(n))) DT_INST_FOREACH_STATUS_OKAY(BMI160_EMUL) ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/emul_bmi160.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,285
```c /* Bosch BMI160 inertial measurement unit driver * * * * Datasheet: * path_to_url */ #include <zephyr/init.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/byteorder.h> #include <zephyr/kernel.h> #include <zephyr/sys/__assert.h> #include <zephyr/pm/pm.h> #include <zephyr/pm/device.h> #include <zephyr/pm/device_runtime.h> #include <zephyr/logging/log.h> #include "bmi160.h" LOG_MODULE_REGISTER(BMI160, CONFIG_SENSOR_LOG_LEVEL); #if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0 #warning "BMI160 driver enabled without any devices" #endif #if BMI160_BUS_SPI static int bmi160_transceive(const struct device *dev, uint8_t reg, bool write, void *buf, size_t length) { const struct bmi160_cfg *cfg = dev->config; const struct spi_buf tx_buf[2] = { { .buf = &reg, .len = 1 }, { .buf = buf, .len = length } }; const struct spi_buf_set tx = { .buffers = tx_buf, .count = buf ? 2 : 1 }; if (!write) { const struct spi_buf_set rx = { .buffers = tx_buf, .count = 2 }; return spi_transceive_dt(&cfg->bus.spi, &tx, &rx); } return spi_write_dt(&cfg->bus.spi, &tx); } bool bmi160_bus_ready_spi(const struct device *dev) { const struct bmi160_cfg *cfg = dev->config; return spi_is_ready_dt(&cfg->bus.spi); } int bmi160_read_spi(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { return bmi160_transceive(dev, reg_addr | BMI160_REG_READ, false, buf, len); } int bmi160_write_spi(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { return bmi160_transceive(dev, reg_addr & BMI160_REG_MASK, true, buf, len); } static const struct bmi160_bus_io bmi160_bus_io_spi = { .ready = bmi160_bus_ready_spi, .read = bmi160_read_spi, .write = bmi160_write_spi, }; #endif /* BMI160_BUS_SPI */ #if BMI160_BUS_I2C bool bmi160_bus_ready_i2c(const struct device *dev) { const struct bmi160_cfg *cfg = dev->config; return device_is_ready(cfg->bus.i2c.bus); } int bmi160_read_i2c(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { const struct bmi160_cfg *cfg = dev->config; return i2c_burst_read_dt(&cfg->bus.i2c, reg_addr, buf, len); } int bmi160_write_i2c(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { const struct bmi160_cfg *cfg = dev->config; return i2c_burst_write_dt(&cfg->bus.i2c, reg_addr, buf, len); } static const struct bmi160_bus_io bmi160_bus_io_i2c = { .ready = bmi160_bus_ready_i2c, .read = bmi160_read_i2c, .write = bmi160_write_i2c, }; #endif int bmi160_read(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { const struct bmi160_cfg *cfg = dev->config; return cfg->bus_io->read(dev, reg_addr, buf, len); } int bmi160_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte) { return bmi160_read(dev, reg_addr, byte, 1); } static int bmi160_word_read(const struct device *dev, uint8_t reg_addr, uint16_t *word) { int rc; rc = bmi160_read(dev, reg_addr, word, 2); if (rc != 0) { return rc; } *word = sys_le16_to_cpu(*word); return 0; } int bmi160_write(const struct device *dev, uint8_t reg_addr, void *buf, uint8_t len) { const struct bmi160_cfg *cfg = dev->config; return cfg->bus_io->write(dev, reg_addr, buf, len); } int bmi160_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte) { return bmi160_write(dev, reg_addr & BMI160_REG_MASK, &byte, 1); } int bmi160_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word) { uint8_t tx_word[2] = { (uint8_t)(word & 0xff), (uint8_t)(word >> 8) }; return bmi160_write(dev, reg_addr & BMI160_REG_MASK, tx_word, 2); } int bmi160_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val) { uint8_t old_val; if (bmi160_byte_read(dev, reg_addr, &old_val) < 0) { return -EIO; } return bmi160_byte_write(dev, reg_addr, (old_val & ~mask) | ((val << pos) & mask)); } static int bmi160_pmu_set(const struct device *dev, union bmi160_pmu_status *pmu_sts) { struct { uint8_t cmd; uint16_t delay_us; /* values taken from page 82 */ } cmds[] = { {BMI160_CMD_PMU_MAG | pmu_sts->mag, 350}, {BMI160_CMD_PMU_ACC | pmu_sts->acc, 3200}, {BMI160_CMD_PMU_GYR | pmu_sts->gyr, 55000} }; size_t i; for (i = 0; i < ARRAY_SIZE(cmds); i++) { union bmi160_pmu_status sts; bool pmu_set = false; if (bmi160_byte_write(dev, BMI160_REG_CMD, cmds[i].cmd) < 0) { return -EIO; } /* * Cannot use a timer here since this is called from the * init function and the timeouts were not initialized yet. */ k_busy_wait(cmds[i].delay_us); /* make sure the PMU_STATUS was set, though */ do { if (bmi160_byte_read(dev, BMI160_REG_PMU_STATUS, &sts.raw) < 0) { return -EIO; } if (i == 0) { pmu_set = (pmu_sts->mag == sts.mag); } else if (i == 1) { pmu_set = (pmu_sts->acc == sts.acc); } else { pmu_set = (pmu_sts->gyr == sts.gyr); } } while (!pmu_set); } /* set the undersampling flag for accelerometer */ return bmi160_reg_field_update(dev, BMI160_REG_ACC_CONF, BMI160_ACC_CONF_US_POS, BMI160_ACC_CONF_US_MASK, pmu_sts->acc != BMI160_PMU_NORMAL); } #if defined(CONFIG_BMI160_GYRO_ODR_RUNTIME) ||\ defined(CONFIG_BMI160_ACCEL_ODR_RUNTIME) /* * Output data rate map with allowed frequencies: * freq = freq_int + freq_milli / 1000 * * Since we don't need a finer frequency resolution than milliHz, use uint16_t * to save some flash. */ struct { uint16_t freq_int; uint16_t freq_milli; /* User should convert to uHz before setting the * SENSOR_ATTR_SAMPLING_FREQUENCY attribute. */ } bmi160_odr_map[] = { {0, 0 }, {0, 781}, {1, 562}, {3, 125}, {6, 250}, {12, 500}, {25, 0 }, {50, 0 }, {100, 0 }, {200, 0 }, {400, 0 }, {800, 0 }, {1600, 0 }, {3200, 0 }, }; static int bmi160_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli) { size_t i; /* An ODR of 0 Hz is not allowed */ if (freq_int == 0U && freq_milli == 0U) { return -EINVAL; } for (i = 0; i < ARRAY_SIZE(bmi160_odr_map); i++) { if (freq_int < bmi160_odr_map[i].freq_int || (freq_int == bmi160_odr_map[i].freq_int && freq_milli <= bmi160_odr_map[i].freq_milli)) { return i; } } return -EINVAL; } #endif #if defined(CONFIG_BMI160_ACCEL_ODR_RUNTIME) static int bmi160_acc_odr_set(const struct device *dev, uint16_t freq_int, uint16_t freq_milli) { int odr = bmi160_freq_to_odr_val(freq_int, freq_milli); if (odr < 0) { return odr; } return bmi160_reg_field_update(dev, BMI160_REG_ACC_CONF, BMI160_ACC_CONF_ODR_POS, BMI160_ACC_CONF_ODR_MASK, (uint8_t) odr); } #endif static const struct bmi160_range bmi160_acc_range_map[] = { {2, BMI160_ACC_RANGE_2G}, {4, BMI160_ACC_RANGE_4G}, {8, BMI160_ACC_RANGE_8G}, {16, BMI160_ACC_RANGE_16G}, }; #define BMI160_ACC_RANGE_MAP_SIZE ARRAY_SIZE(bmi160_acc_range_map) static const struct bmi160_range bmi160_gyr_range_map[] = { {125, BMI160_GYR_RANGE_125DPS}, {250, BMI160_GYR_RANGE_250DPS}, {500, BMI160_GYR_RANGE_500DPS}, {1000, BMI160_GYR_RANGE_1000DPS}, {2000, BMI160_GYR_RANGE_2000DPS}, }; #define BMI160_GYR_RANGE_MAP_SIZE ARRAY_SIZE(bmi160_gyr_range_map) #if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME) ||\ defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME) static int32_t bmi160_range_to_reg_val(uint16_t range, const struct bmi160_range *range_map, uint16_t range_map_size) { int i; for (i = 0; i < range_map_size; i++) { if (range <= range_map[i].range) { return range_map[i].reg_val; } } return -EINVAL; } #endif static int32_t bmi160_reg_val_to_range(uint8_t reg_val, const struct bmi160_range *range_map, uint16_t range_map_size) { int i; for (i = 0; i < range_map_size; i++) { if (reg_val == range_map[i].reg_val) { return range_map[i].range; } } return -EINVAL; } int32_t bmi160_acc_reg_val_to_range(uint8_t reg_val) { return bmi160_reg_val_to_range(reg_val, bmi160_acc_range_map, BMI160_ACC_RANGE_MAP_SIZE); } int32_t bmi160_gyr_reg_val_to_range(uint8_t reg_val) { return bmi160_reg_val_to_range(reg_val, bmi160_gyr_range_map, BMI160_GYR_RANGE_MAP_SIZE); } static int bmi160_do_calibration(const struct device *dev, uint8_t foc_conf) { if (bmi160_byte_write(dev, BMI160_REG_FOC_CONF, foc_conf) < 0) { return -EIO; } if (bmi160_byte_write(dev, BMI160_REG_CMD, BMI160_CMD_START_FOC) < 0) { return -EIO; } k_busy_wait(250000); /* calibration takes a maximum of 250ms */ return 0; } #if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME) static int bmi160_acc_range_set(const struct device *dev, const struct sensor_value *val) { int32_t range_g = sensor_ms2_to_g(val); struct bmi160_data *data = dev->data; int32_t reg_val = bmi160_range_to_reg_val(range_g, bmi160_acc_range_map, BMI160_ACC_RANGE_MAP_SIZE); if (reg_val < 0) { return reg_val; } switch (reg_val & 0xff) { case BMI160_ACC_RANGE_2G: range_g = 2; break; case BMI160_ACC_RANGE_4G: range_g = 4; break; case BMI160_ACC_RANGE_8G: range_g = 8; break; case BMI160_ACC_RANGE_16G: range_g = 16; break; } if (bmi160_byte_write(dev, BMI160_REG_ACC_RANGE, reg_val & 0xff) < 0) { return -EIO; } data->scale.acc_numerator = BMI160_ACC_SCALE_NUMERATOR(range_g); return 0; } #endif #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) /* * Accelerometer offset scale, taken from pg. 79, converted to micro m/s^2: * 3.9 * 9.80665 * 1000 */ #define BMI160_ACC_OFS_LSB 38246 static int bmi160_acc_ofs_set(const struct device *dev, enum sensor_channel chan, const struct sensor_value *ofs) { uint8_t reg_addr[] = { BMI160_REG_OFFSET_ACC_X, BMI160_REG_OFFSET_ACC_Y, BMI160_REG_OFFSET_ACC_Z }; int i; int32_t reg_val; /* we need the offsets for all axis */ if (chan != SENSOR_CHAN_ACCEL_XYZ) { return -ENOTSUP; } for (i = 0; i < BMI160_AXES; i++, ofs++) { /* convert offset to micro m/s^2 */ reg_val = CLAMP(sensor_value_to_micro(ofs) / BMI160_ACC_OFS_LSB, INT8_MIN, INT8_MAX); if (bmi160_byte_write(dev, reg_addr[i], reg_val) < 0) { return -EIO; } } /* activate accel HW compensation */ return bmi160_reg_field_update(dev, BMI160_REG_OFFSET_EN, BMI160_ACC_OFS_EN_POS, BIT(BMI160_ACC_OFS_EN_POS), 1); } static int bmi160_acc_calibrate(const struct device *dev, enum sensor_channel chan, const struct sensor_value *xyz_calib_value) { struct bmi160_data *data = dev->data; uint8_t foc_pos[] = { BMI160_FOC_ACC_X_POS, BMI160_FOC_ACC_Y_POS, BMI160_FOC_ACC_Z_POS, }; int i; uint8_t reg_val = 0U; /* Calibration has to be done in normal mode. */ if (data->pmu_sts.acc != BMI160_PMU_NORMAL) { return -ENOTSUP; } /* * Hardware calibration is done knowing the expected values on all axis. */ if (chan != SENSOR_CHAN_ACCEL_XYZ) { return -ENOTSUP; } for (i = 0; i < BMI160_AXES; i++, xyz_calib_value++) { int32_t accel_g; uint8_t accel_val; accel_g = sensor_ms2_to_g(xyz_calib_value); if (accel_g == 0) { accel_val = 3U; } else if (accel_g == 1) { accel_val = 1U; } else if (accel_g == -1) { accel_val = 2U; } else { accel_val = 0U; } reg_val |= (accel_val << foc_pos[i]); } if (bmi160_do_calibration(dev, reg_val) < 0) { return -EIO; } /* activate accel HW compensation */ return bmi160_reg_field_update(dev, BMI160_REG_OFFSET_EN, BMI160_ACC_OFS_EN_POS, BIT(BMI160_ACC_OFS_EN_POS), 1); } static int bmi160_acc_config(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { switch (attr) { #if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME) case SENSOR_ATTR_FULL_SCALE: return bmi160_acc_range_set(dev, val); #endif #if defined(CONFIG_BMI160_ACCEL_ODR_RUNTIME) case SENSOR_ATTR_SAMPLING_FREQUENCY: return bmi160_acc_odr_set(dev, val->val1, val->val2 / 1000); #endif case SENSOR_ATTR_OFFSET: return bmi160_acc_ofs_set(dev, chan, val); case SENSOR_ATTR_CALIB_TARGET: return bmi160_acc_calibrate(dev, chan, val); #if defined(CONFIG_BMI160_TRIGGER) case SENSOR_ATTR_SLOPE_TH: case SENSOR_ATTR_SLOPE_DUR: return bmi160_acc_slope_config(dev, attr, val); #endif default: LOG_DBG("Accel attribute not supported."); return -ENOTSUP; } return 0; } #endif /* !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) */ #if defined(CONFIG_BMI160_GYRO_ODR_RUNTIME) static int bmi160_gyr_odr_set(const struct device *dev, uint16_t freq_int, uint16_t freq_milli) { int odr = bmi160_freq_to_odr_val(freq_int, freq_milli); if (odr < 0) { return odr; } if (odr < BMI160_ODR_25 || odr > BMI160_ODR_3200) { return -ENOTSUP; } return bmi160_reg_field_update(dev, BMI160_REG_GYR_CONF, BMI160_GYR_CONF_ODR_POS, BMI160_GYR_CONF_ODR_MASK, (uint8_t) odr); } #endif #if defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME) static int bmi160_gyr_range_set(const struct device *dev, const struct sensor_value *val) { uint16_t range = sensor_rad_to_degrees(val); struct bmi160_data *data = dev->data; int32_t reg_val = bmi160_range_to_reg_val(range, bmi160_gyr_range_map, BMI160_GYR_RANGE_MAP_SIZE); if (reg_val < 0) { return reg_val; } switch (reg_val) { case BMI160_GYR_RANGE_125DPS: range = 125; break; case BMI160_GYR_RANGE_250DPS: range = 250; break; case BMI160_GYR_RANGE_500DPS: range = 500; break; case BMI160_GYR_RANGE_1000DPS: range = 1000; break; case BMI160_GYR_RANGE_2000DPS: range = 2000; break; } if (bmi160_byte_write(dev, BMI160_REG_GYR_RANGE, reg_val) < 0) { return -EIO; } data->scale.gyr_numerator = BMI160_GYR_SCALE_NUMERATOR(range); return 0; } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) /* * Gyro offset scale, taken from pg. 79, converted to micro rad/s: * 0.061 * (pi / 180) * 1000000, where pi = 3.141592 */ #define BMI160_GYR_OFS_LSB 1065 static int bmi160_gyr_ofs_set(const struct device *dev, enum sensor_channel chan, const struct sensor_value *ofs) { struct { uint8_t lsb_addr; uint8_t msb_pos; } ofs_desc[] = { {BMI160_REG_OFFSET_GYR_X, BMI160_GYR_MSB_OFS_X_POS}, {BMI160_REG_OFFSET_GYR_Y, BMI160_GYR_MSB_OFS_Y_POS}, {BMI160_REG_OFFSET_GYR_Z, BMI160_GYR_MSB_OFS_Z_POS}, }; int i; int32_t ofs_u; int16_t val; /* we need the offsets for all axis */ if (chan != SENSOR_CHAN_GYRO_XYZ) { return -ENOTSUP; } for (i = 0; i < BMI160_AXES; i++, ofs++) { /* convert offset to micro rad/s */ ofs_u = ofs->val1 * 1000000ULL + ofs->val2; val = CLAMP(ofs_u / BMI160_GYR_OFS_LSB, -512, 511); /* write the LSB */ if (bmi160_byte_write(dev, ofs_desc[i].lsb_addr, val & 0xff) < 0) { return -EIO; } /* write the MSB */ if (bmi160_reg_field_update(dev, BMI160_REG_OFFSET_EN, ofs_desc[i].msb_pos, 0x3 << ofs_desc[i].msb_pos, (val >> 8) & 0x3) < 0) { return -EIO; } } /* activate gyro HW compensation */ return bmi160_reg_field_update(dev, BMI160_REG_OFFSET_EN, BMI160_GYR_OFS_EN_POS, BIT(BMI160_GYR_OFS_EN_POS), 1); } static int bmi160_gyr_calibrate(const struct device *dev, enum sensor_channel chan) { struct bmi160_data *data = dev->data; ARG_UNUSED(chan); /* Calibration has to be done in normal mode. */ if (data->pmu_sts.gyr != BMI160_PMU_NORMAL) { return -ENOTSUP; } if (bmi160_do_calibration(dev, BIT(BMI160_FOC_GYR_EN_POS)) < 0) { return -EIO; } /* activate gyro HW compensation */ return bmi160_reg_field_update(dev, BMI160_REG_OFFSET_EN, BMI160_GYR_OFS_EN_POS, BIT(BMI160_GYR_OFS_EN_POS), 1); } static int bmi160_gyr_config(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { switch (attr) { #if defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME) case SENSOR_ATTR_FULL_SCALE: return bmi160_gyr_range_set(dev, val); #endif #if defined(CONFIG_BMI160_GYRO_ODR_RUNTIME) case SENSOR_ATTR_SAMPLING_FREQUENCY: return bmi160_gyr_odr_set(dev, val->val1, val->val2 / 1000); #endif case SENSOR_ATTR_OFFSET: return bmi160_gyr_ofs_set(dev, chan, val); case SENSOR_ATTR_CALIB_TARGET: return bmi160_gyr_calibrate(dev, chan); default: LOG_DBG("Gyro attribute not supported."); return -ENOTSUP; } return 0; } #endif /* !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) */ static int bmi160_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { switch (chan) { #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: return bmi160_gyr_config(dev, chan, attr, val); #endif #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: return bmi160_acc_config(dev, chan, attr, val); #endif default: LOG_DBG("attr_set() not supported on this channel."); return -ENOTSUP; } return 0; } static int bmi160_attr_get(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) { int rc; if (attr == SENSOR_ATTR_OFFSET) { if (chan != SENSOR_CHAN_ACCEL_XYZ && chan != SENSOR_CHAN_GYRO_XYZ) { return -EINVAL; } int8_t data[7]; rc = bmi160_read(dev, BMI160_REG_OFFSET_ACC_X, data, 7); if (rc != 0) { return rc; } if ((chan == SENSOR_CHAN_ACCEL_XYZ && FIELD_GET(BIT(BMI160_ACC_OFS_EN_POS), data[6]) == 0) || (chan == SENSOR_CHAN_GYRO_XYZ && FIELD_GET(BIT(BMI160_GYR_OFS_EN_POS), data[6]) == 0)) { for (int i = 0; i < 3; ++i) { val[i].val1 = 0; val[i].val2 = 0; } } else { for (int i = 0; i < 3; ++i) { if (chan == SENSOR_CHAN_ACCEL_XYZ) { int32_t ug = data[i] * INT32_C(3900); sensor_ug_to_ms2(ug, &val[i]); } else { int32_t udeg = (FIELD_GET(GENMASK((2 * i) + 1, 2 * i), data[6]) << 8) | data[3 + i]; udeg |= 0 - (udeg & 0x200); udeg *= 61000; sensor_10udegrees_to_rad(udeg / 10, &val[i]); } } } return 0; } if (attr == SENSOR_ATTR_SAMPLING_FREQUENCY) { if (chan == SENSOR_CHAN_ACCEL_XYZ) { int64_t rate_uhz; uint8_t acc_odr; if (IS_ENABLED(CONFIG_BMI160_ACCEL_ODR_RUNTIME)) { /* Read the register */ rc = bmi160_byte_read(dev, BMI160_REG_ACC_CONF, &acc_odr); if (rc != 0) { return rc; } acc_odr = FIELD_GET(BMI160_ACC_CONF_ODR_MASK, acc_odr); } else { acc_odr = BMI160_DEFAULT_ODR_ACC; } rate_uhz = INT64_C(100000000) * BIT(acc_odr) / 256; val->val1 = rate_uhz / 1000000; val->val2 = rate_uhz - val->val1 * 1000000; return 0; } else if (chan == SENSOR_CHAN_GYRO_XYZ) { int64_t rate_uhz; uint8_t gyr_ord; if (IS_ENABLED(CONFIG_BMI160_GYRO_ODR_RUNTIME)) { /* Read the register */ rc = bmi160_byte_read(dev, BMI160_REG_GYR_CONF, &gyr_ord); if (rc != 0) { return rc; } gyr_ord = FIELD_GET(BMI160_GYR_CONF_ODR_MASK, gyr_ord); } else { gyr_ord = BMI160_DEFAULT_ODR_GYR; } rate_uhz = INT64_C(100000000) * BIT(gyr_ord) / 256; val->val1 = rate_uhz / 1000000; val->val2 = rate_uhz - val->val1 * 1000000; return 0; } return -EINVAL; } if (attr == SENSOR_ATTR_FULL_SCALE) { if (chan == SENSOR_CHAN_ACCEL_XYZ) { uint8_t acc_range; if (IS_ENABLED(CONFIG_BMI160_ACCEL_RANGE_RUNTIME)) { rc = bmi160_byte_read(dev, BMI160_REG_ACC_RANGE, &acc_range); if (rc != 0) { return rc; } } else { acc_range = BMI160_DEFAULT_RANGE_ACC; } sensor_g_to_ms2(bmi160_acc_reg_val_to_range(acc_range), val); return 0; } else if (chan == SENSOR_CHAN_GYRO_XYZ) { uint8_t gyr_range; if (IS_ENABLED(CONFIG_BMI160_GYRO_RANGE_RUNTIME)) { rc = bmi160_byte_read(dev, BMI160_REG_GYR_RANGE, &gyr_range); if (rc != 0) { return rc; } } else { gyr_range = BMI160_DEFAULT_RANGE_GYR; } sensor_degrees_to_rad(bmi160_gyr_reg_val_to_range(gyr_range), val); return 0; } return -EINVAL; } return -EINVAL; } static int bmi160_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmi160_data *data = dev->data; uint8_t status; size_t i; int ret = 0; enum pm_device_state pm_state; (void)pm_device_state_get(dev, &pm_state); if (pm_state != PM_DEVICE_STATE_ACTIVE) { LOG_DBG("Device is suspended, fetch is unavailable"); ret = -EIO; goto out; } if (chan == SENSOR_CHAN_DIE_TEMP) { /* Die temperature is only valid when at least one measurement is active */ if (data->pmu_sts.raw == 0U) { return -EINVAL; } return bmi160_word_read(dev, BMI160_REG_TEMPERATURE0, &data->sample.temperature); } __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); status = 0; while ((status & BMI160_DATA_READY_BIT_MASK) == 0) { if (bmi160_byte_read(dev, BMI160_REG_STATUS, &status) < 0) { ret = -EIO; goto out; } } if (bmi160_read(dev, BMI160_SAMPLE_BURST_READ_ADDR, data->sample.raw, BMI160_BUF_SIZE) < 0) { ret = -EIO; goto out; } /* convert samples to cpu endianness */ for (i = 0; i < BMI160_SAMPLE_SIZE; i += 2) { uint16_t *sample = (uint16_t *) &data->sample.raw[i]; *sample = sys_le16_to_cpu(*sample); } out: return ret; } static void bmi160_to_fixed_point(int16_t raw_val, int64_t scale_numerator, uint32_t scale_denominator, struct sensor_value *val) { int64_t converted_val = (int64_t)raw_val * scale_numerator / scale_denominator; val->val1 = converted_val / 1000000; val->val2 = converted_val % 1000000; } static void bmi160_channel_convert(enum sensor_channel chan, int64_t scale_numerator, uint32_t scale_denominator, uint16_t *raw_xyz, struct sensor_value *val) { int i; uint8_t ofs_start, ofs_stop; switch (chan) { case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_GYRO_X: ofs_start = ofs_stop = 0U; break; case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_GYRO_Y: ofs_start = ofs_stop = 1U; break; case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_GYRO_Z: ofs_start = ofs_stop = 2U; break; default: ofs_start = 0U; ofs_stop = 2U; break; } for (i = ofs_start; i <= ofs_stop ; i++, val++) { bmi160_to_fixed_point(raw_xyz[i], scale_numerator, scale_denominator, val); } } #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) static inline void bmi160_gyr_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmi160_data *data = dev->data; bmi160_channel_convert(chan, data->scale.gyr_numerator, BMI160_GYR_SCALE_DENOMINATOR, data->sample.gyr, val); } #endif #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) static inline void bmi160_acc_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bmi160_data *data = dev->data; bmi160_channel_convert(chan, data->scale.acc_numerator, BMI160_ACC_SCALE_DENOMINATOR, data->sample.acc, val); } #endif static int bmi160_temp_channel_get(const struct device *dev, struct sensor_value *val) { struct bmi160_data *data = dev->data; /* the scale is 1/2^9/LSB = 1953 micro degrees */ int32_t temp_micro = BMI160_TEMP_OFFSET * 1000000ULL + data->sample.temperature * 1953ULL; val->val1 = temp_micro / 1000000ULL; val->val2 = temp_micro % 1000000ULL; return 0; } static int bmi160_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { switch (chan) { #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) case SENSOR_CHAN_GYRO_X: case SENSOR_CHAN_GYRO_Y: case SENSOR_CHAN_GYRO_Z: case SENSOR_CHAN_GYRO_XYZ: bmi160_gyr_channel_get(dev, chan, val); return 0; #endif #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) case SENSOR_CHAN_ACCEL_X: case SENSOR_CHAN_ACCEL_Y: case SENSOR_CHAN_ACCEL_Z: case SENSOR_CHAN_ACCEL_XYZ: bmi160_acc_channel_get(dev, chan, val); return 0; #endif case SENSOR_CHAN_DIE_TEMP: return bmi160_temp_channel_get(dev, val); default: LOG_DBG("Channel not supported."); return -ENOTSUP; } return 0; } static const struct sensor_driver_api bmi160_api = { .attr_set = bmi160_attr_set, .attr_get = bmi160_attr_get, #ifdef CONFIG_BMI160_TRIGGER .trigger_set = bmi160_trigger_set, #endif .sample_fetch = bmi160_sample_fetch, .channel_get = bmi160_channel_get, }; static inline int bmi160_resume(const struct device *dev) { struct bmi160_data *data = dev->data; return bmi160_pmu_set(dev, &data->pmu_sts); } static inline int bmi160_suspend(const struct device *dev) { struct bmi160_data *data = dev->data; /* Suspend everything */ union bmi160_pmu_status st = { .acc = BMI160_PMU_SUSPEND, .gyr = BMI160_PMU_SUSPEND, .mag = BMI160_PMU_SUSPEND, }; int ret = bmi160_pmu_set(dev, &st); if (ret == 0) { memset(data->sample.raw, 0, sizeof(data->sample.raw)); } return ret; } int bmi160_init(const struct device *dev) { const struct bmi160_cfg *cfg = dev->config; struct bmi160_data *data = dev->data; uint8_t val = 0U; int32_t acc_range, gyr_range; if (!cfg->bus_io->ready(dev)) { LOG_ERR("Bus not ready"); return -EINVAL; } /* reboot the chip */ if (bmi160_byte_write(dev, BMI160_REG_CMD, BMI160_CMD_SOFT_RESET) < 0) { LOG_DBG("Cannot reboot chip."); return -EIO; } k_busy_wait(1000); /* do a dummy read from 0x7F to activate SPI */ if (bmi160_byte_read(dev, BMI160_SPI_START, &val) < 0) { LOG_DBG("Cannot read from 0x7F.."); return -EIO; } k_busy_wait(150); if (bmi160_byte_read(dev, BMI160_REG_CHIPID, &val) < 0) { LOG_DBG("Failed to read chip id."); return -EIO; } if (val != BMI160_CHIP_ID) { LOG_DBG("Unsupported chip detected (0x%x)!", val); return -ENODEV; } /* set default PMU for gyro, accelerometer */ data->pmu_sts.gyr = BMI160_DEFAULT_PMU_GYR; data->pmu_sts.acc = BMI160_DEFAULT_PMU_ACC; /* compass not supported, yet */ data->pmu_sts.mag = BMI160_PMU_SUSPEND; /* Start in a suspended state (never turning on the mems sensors) if * PM_DEVICE_RUNTIME is enabled. */ #ifdef CONFIG_PM_DEVICE_RUNTIME pm_device_init_suspended(dev); int ret = pm_device_runtime_enable(dev); if (ret < 0 && ret != -ENOSYS) { LOG_ERR("Failed to enabled runtime power management"); return -EIO; } #else /* * The next command will take around 100ms (contains some necessary busy * waits), but we cannot do it in a separate thread since we need to * guarantee the BMI is up and running, before the app's main() is * called. */ if (bmi160_pmu_set(dev, &data->pmu_sts) < 0) { LOG_DBG("Failed to set power mode."); return -EIO; } #endif /* set accelerometer default range */ if (bmi160_byte_write(dev, BMI160_REG_ACC_RANGE, BMI160_DEFAULT_RANGE_ACC) < 0) { LOG_DBG("Cannot set default range for accelerometer."); return -EIO; } acc_range = bmi160_acc_reg_val_to_range(BMI160_DEFAULT_RANGE_ACC); data->scale.acc_numerator = BMI160_ACC_SCALE_NUMERATOR(acc_range); /* set gyro default range */ if (bmi160_byte_write(dev, BMI160_REG_GYR_RANGE, BMI160_DEFAULT_RANGE_GYR) < 0) { LOG_DBG("Cannot set default range for gyroscope."); return -EIO; } gyr_range = bmi160_gyr_reg_val_to_range(BMI160_DEFAULT_RANGE_GYR); data->scale.gyr_numerator = BMI160_GYR_SCALE_NUMERATOR(gyr_range); if (bmi160_reg_field_update(dev, BMI160_REG_ACC_CONF, BMI160_ACC_CONF_ODR_POS, BMI160_ACC_CONF_ODR_MASK, BMI160_DEFAULT_ODR_ACC) < 0) { LOG_DBG("Failed to set accel's default ODR."); return -EIO; } if (bmi160_reg_field_update(dev, BMI160_REG_GYR_CONF, BMI160_GYR_CONF_ODR_POS, BMI160_GYR_CONF_ODR_MASK, BMI160_DEFAULT_ODR_GYR) < 0) { LOG_DBG("Failed to set gyro's default ODR."); return -EIO; } #ifdef CONFIG_BMI160_TRIGGER if (bmi160_trigger_mode_init(dev) < 0) { LOG_DBG("Cannot set up trigger mode."); return -EINVAL; } #endif return 0; } int bmi160_pm(const struct device *dev, enum pm_device_action action) { int ret = 0; switch (action) { case PM_DEVICE_ACTION_RESUME: bmi160_resume(dev); break; case PM_DEVICE_ACTION_SUSPEND: bmi160_suspend(dev); break; default: ret = -ENOTSUP; } return ret; } #if defined(CONFIG_BMI160_TRIGGER) #define BMI160_TRIGGER_CFG(inst) \ .interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), #else #define BMI160_TRIGGER_CFG(inst) #endif #define BMI160_DEVICE_INIT(inst) \ IF_ENABLED(CONFIG_PM_DEVICE_RUNTIME, (PM_DEVICE_DT_INST_DEFINE(inst, bmi160_pm))); \ SENSOR_DEVICE_DT_INST_DEFINE(inst, bmi160_init, \ COND_CODE_1(CONFIG_PM_DEVICE_RUNTIME, (PM_DEVICE_DT_INST_GET(inst)), (NULL)), \ &bmi160_data_##inst, &bmi160_cfg_##inst, \ POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ &bmi160_api); /* Instantiation macros used when a device is on a SPI bus */ #define BMI160_DEFINE_SPI(inst) \ static struct bmi160_data bmi160_data_##inst; \ static const struct bmi160_cfg bmi160_cfg_##inst = { \ .bus.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 0), \ .bus_io = &bmi160_bus_io_spi, \ BMI160_TRIGGER_CFG(inst) \ }; \ BMI160_DEVICE_INIT(inst) /* Instantiation macros used when a device is on an I2C bus */ #define BMI160_CONFIG_I2C(inst) \ { \ .bus.i2c = I2C_DT_SPEC_INST_GET(inst), \ .bus_io = &bmi160_bus_io_i2c, \ BMI160_TRIGGER_CFG(inst) \ } #define BMI160_DEFINE_I2C(inst) \ static struct bmi160_data bmi160_data_##inst; \ static const struct bmi160_cfg bmi160_cfg_##inst = BMI160_CONFIG_I2C(inst); \ BMI160_DEVICE_INIT(inst) /* * Main instantiation macro. Use of COND_CODE_1() selects the right * bus-specific macro at preprocessor time. */ #define BMI160_DEFINE(inst) \ COND_CODE_1(DT_INST_ON_BUS(inst, spi), \ (BMI160_DEFINE_SPI(inst)), \ (BMI160_DEFINE_I2C(inst))) DT_INST_FOREACH_STATUS_OKAY(BMI160_DEFINE) ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/bmi160.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
9,347
```c /* Bosch BMI160 inertial measurement unit driver, trigger implementation * * */ #include <zephyr/kernel.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/gpio.h> #include "bmi160.h" #include <zephyr/logging/log.h> LOG_MODULE_DECLARE(BMI160, CONFIG_SENSOR_LOG_LEVEL); static void bmi160_handle_anymotion(const struct device *dev) { struct bmi160_data *data = dev->data; if (data->handler_anymotion) { data->handler_anymotion(dev, data->trig_anymotion); } } static void bmi160_handle_drdy(const struct device *dev, uint8_t status) { struct bmi160_data *data = dev->data; #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) if (data->handler_drdy_acc && (status & BMI160_STATUS_ACC_DRDY)) { data->handler_drdy_acc(dev, data->trig_drdy_acc); } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) if (data->handler_drdy_gyr && (status & BMI160_STATUS_GYR_DRDY)) { data->handler_drdy_gyr(dev, data->trig_drdy_gyr); } #endif } static void bmi160_handle_interrupts(const struct device *dev) { union { uint8_t raw[5]; struct { uint8_t status; uint8_t int_status[4]; }; } buf; if (bmi160_read(dev, BMI160_REG_STATUS, buf.raw, sizeof(buf)) < 0) { return; } if ((buf.int_status[0] & BMI160_INT_STATUS0_ANYM) && (buf.int_status[2] & (BMI160_INT_STATUS2_ANYM_FIRST_X | BMI160_INT_STATUS2_ANYM_FIRST_Y | BMI160_INT_STATUS2_ANYM_FIRST_Z))) { bmi160_handle_anymotion(dev); } if (buf.int_status[1] & BMI160_INT_STATUS1_DRDY) { bmi160_handle_drdy(dev, buf.status); } } #ifdef CONFIG_BMI160_TRIGGER_OWN_THREAD static K_KERNEL_STACK_DEFINE(bmi160_thread_stack, CONFIG_BMI160_THREAD_STACK_SIZE); static struct k_thread bmi160_thread; static void bmi160_thread_main(void *p1, void *p2, void *p3) { struct bmi160_data *data = p1; while (1) { k_sem_take(&data->sem, K_FOREVER); bmi160_handle_interrupts(data->dev); } } #endif #ifdef CONFIG_BMI160_TRIGGER_GLOBAL_THREAD static void bmi160_work_handler(struct k_work *work) { struct bmi160_data *data = CONTAINER_OF(work, struct bmi160_data, work); bmi160_handle_interrupts(data->dev); } #endif extern struct bmi160_data bmi160_data; static void bmi160_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { struct bmi160_data *data = CONTAINER_OF(cb, struct bmi160_data, gpio_cb); ARG_UNUSED(port); ARG_UNUSED(pin); #if defined(CONFIG_BMI160_TRIGGER_OWN_THREAD) k_sem_give(&data->sem); #elif defined(CONFIG_BMI160_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #endif } static int bmi160_trigger_drdy_set(const struct device *dev, enum sensor_channel chan, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi160_data *data = dev->data; uint8_t drdy_en = 0U; #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) if (chan == SENSOR_CHAN_ACCEL_XYZ) { data->handler_drdy_acc = handler; data->trig_drdy_acc = trig; } if (data->handler_drdy_acc) { drdy_en = BMI160_INT_DRDY_EN; } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) if (chan == SENSOR_CHAN_GYRO_XYZ) { data->handler_drdy_gyr = handler; data->trig_drdy_gyr = trig; } if (data->handler_drdy_gyr) { drdy_en = BMI160_INT_DRDY_EN; } #endif if (bmi160_reg_update(dev, BMI160_REG_INT_EN1, BMI160_INT_DRDY_EN, drdy_en) < 0) { return -EIO; } return 0; } #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) static int bmi160_trigger_anym_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmi160_data *data = dev->data; uint8_t anym_en = 0U; data->handler_anymotion = handler; data->trig_anymotion = trig; if (handler) { anym_en = BMI160_INT_ANYM_X_EN | BMI160_INT_ANYM_Y_EN | BMI160_INT_ANYM_Z_EN; } if (bmi160_reg_update(dev, BMI160_REG_INT_EN0, BMI160_INT_ANYM_MASK, anym_en) < 0) { return -EIO; } return 0; } static int bmi160_trigger_set_acc(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { if (trig->type == SENSOR_TRIG_DATA_READY) { return bmi160_trigger_drdy_set(dev, trig->chan, trig, handler); } else if (trig->type == SENSOR_TRIG_DELTA) { return bmi160_trigger_anym_set(dev, trig, handler); } return -ENOTSUP; } int bmi160_acc_slope_config(const struct device *dev, enum sensor_attribute attr, const struct sensor_value *val) { uint8_t acc_range_g, reg_val; uint32_t slope_th_ums2; if (attr == SENSOR_ATTR_SLOPE_TH) { if (bmi160_byte_read(dev, BMI160_REG_ACC_RANGE, &reg_val) < 0) { return -EIO; } acc_range_g = bmi160_acc_reg_val_to_range(reg_val); slope_th_ums2 = val->val1 * 1000000 + val->val2; /* make sure the provided threshold does not exceed range / 2 */ if (slope_th_ums2 > (acc_range_g / 2 * SENSOR_G)) { return -EINVAL; } reg_val = (slope_th_ums2 - 1) * 512U / (acc_range_g * SENSOR_G); if (bmi160_byte_write(dev, BMI160_REG_INT_MOTION1, reg_val) < 0) { return -EIO; } } else { /* SENSOR_ATTR_SLOPE_DUR */ /* slope duration is measured in number of samples */ if (val->val1 < 1 || val->val1 > 4) { return -ENOTSUP; } if (bmi160_reg_field_update(dev, BMI160_REG_INT_MOTION0, BMI160_ANYM_DUR_POS, BMI160_ANYM_DUR_MASK, val->val1) < 0) { return -EIO; } } return 0; } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) static int bmi160_trigger_set_gyr(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { if (trig->type == SENSOR_TRIG_DATA_READY) { return bmi160_trigger_drdy_set(dev, trig->chan, trig, handler); } return -ENOTSUP; } #endif int bmi160_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) if (trig->chan == SENSOR_CHAN_ACCEL_XYZ) { return bmi160_trigger_set_acc(dev, trig, handler); } #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) if (trig->chan == SENSOR_CHAN_GYRO_XYZ) { return bmi160_trigger_set_gyr(dev, trig, handler); } #endif return -ENOTSUP; } int bmi160_trigger_mode_init(const struct device *dev) { struct bmi160_data *data = dev->data; const struct bmi160_cfg *cfg = dev->config; int ret; if (!gpio_is_ready_dt(&cfg->interrupt)) { LOG_DBG("GPIO port %s not ready", cfg->interrupt.port->name); return -EINVAL; } data->dev = dev; #if defined(CONFIG_BMI160_TRIGGER_OWN_THREAD) k_sem_init(&data->sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&bmi160_thread, bmi160_thread_stack, CONFIG_BMI160_THREAD_STACK_SIZE, bmi160_thread_main, data, NULL, NULL, K_PRIO_COOP(CONFIG_BMI160_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMI160_TRIGGER_GLOBAL_THREAD) data->work.handler = bmi160_work_handler; #endif /* map all interrupts to INT1 pin */ if (bmi160_word_write(dev, BMI160_REG_INT_MAP0, 0xf0ff) < 0) { LOG_DBG("Failed to map interrupts."); return -EIO; } ret = gpio_pin_configure_dt(&cfg->interrupt, GPIO_INPUT); if (ret < 0) { return ret; } gpio_init_callback(&data->gpio_cb, bmi160_gpio_callback, BIT(cfg->interrupt.pin)); ret = gpio_add_callback(cfg->interrupt.port, &data->gpio_cb); if (ret < 0) { return ret; } ret = gpio_pin_interrupt_configure_dt(&cfg->interrupt, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { return ret; } return bmi160_byte_write(dev, BMI160_REG_INT_OUT_CTRL, BMI160_INT1_OUT_EN | BMI160_INT1_EDGE_CTRL); } ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/bmi160_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,234
```objective-c /* * */ #ifndef BMI270_BMI270_CONFIG_FILE_H_ #define BMI270_BMI270_CONFIG_FILE_H_ /* Source : path_to_url#L51 */ static const uint8_t bmi270_config_file_max_fifo[] = { 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x1a, 0x00, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0xc8, 0x2e, 0x00, 0x2e, 0x90, 0x32, 0x21, 0x2e, 0x59, 0xf5, 0x10, 0x30, 0x21, 0x2e, 0x6a, 0xf5, 0x1a, 0x24, 0x22, 0x00, 0x80, 0x2e, 0x3b, 0x00, 0xc8, 0x2e, 0x44, 0x47, 0x22, 0x00, 0x37, 0x00, 0xa4, 0x00, 0xff, 0x0f, 0xd1, 0x00, 0x07, 0xad, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x24, 0xfc, 0xf5, 0x80, 0x30, 0x40, 0x42, 0x50, 0x50, 0x00, 0x30, 0x12, 0x24, 0xeb, 0x00, 0x03, 0x30, 0x00, 0x2e, 0xc1, 0x86, 0x5a, 0x0e, 0xfb, 0x2f, 0x21, 0x2e, 0xfc, 0xf5, 0x13, 0x24, 0x63, 0xf5, 0xe0, 0x3c, 0x48, 0x00, 0x22, 0x30, 0xf7, 0x80, 0xc2, 0x42, 0xe1, 0x7f, 0x3a, 0x25, 0xfc, 0x86, 0xf0, 0x7f, 0x41, 0x33, 0x98, 0x2e, 0xc2, 0xc4, 0xd6, 0x6f, 0xf1, 0x30, 0xf1, 0x08, 0xc4, 0x6f, 0x11, 0x24, 0xff, 0x03, 0x12, 0x24, 0x00, 0xfc, 0x61, 0x09, 0xa2, 0x08, 0x36, 0xbe, 0x2a, 0xb9, 0x13, 0x24, 0x38, 0x00, 0x64, 0xbb, 0xd1, 0xbe, 0x94, 0x0a, 0x71, 0x08, 0xd5, 0x42, 0x21, 0xbd, 0x91, 0xbc, 0xd2, 0x42, 0xc1, 0x42, 0x00, 0xb2, 0xfe, 0x82, 0x05, 0x2f, 0x50, 0x30, 0x21, 0x2e, 0x21, 0xf2, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0xf0, 0x6f, 0x02, 0x30, 0x02, 0x42, 0x20, 0x26, 0xe0, 0x6f, 0x02, 0x31, 0x03, 0x40, 0x9a, 0x0a, 0x02, 0x42, 0xf0, 0x37, 0x05, 0x2e, 0x5e, 0xf7, 0x10, 0x08, 0x12, 0x24, 0x1e, 0xf2, 0x80, 0x42, 0x83, 0x84, 0xf1, 0x7f, 0x0a, 0x25, 0x13, 0x30, 0x83, 0x42, 0x3b, 0x82, 0xf0, 0x6f, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x00, 0x2e, 0x12, 0x40, 0x52, 0x42, 0x3e, 0x84, 0x00, 0x40, 0x40, 0x42, 0x7e, 0x82, 0xe1, 0x7f, 0xf2, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x21, 0x30, 0x23, 0x2e, 0x61, 0xf5, 0xeb, 0x2c, 0xe1, 0x6f }; /* Source: path_to_url#L51 */ static const uint8_t bmi270_config_file_base[] = { 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x3d, 0xb1, 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x91, 0x03, 0x80, 0x2e, 0xbc, 0xb0, 0x80, 0x2e, 0xa3, 0x03, 0xc8, 0x2e, 0x00, 0x2e, 0x80, 0x2e, 0x00, 0xb0, 0x50, 0x30, 0x21, 0x2e, 0x59, 0xf5, 0x10, 0x30, 0x21, 0x2e, 0x6a, 0xf5, 0x80, 0x2e, 0x3b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x08, 0x19, 0x01, 0x00, 0x22, 0x00, 0x75, 0x00, 0x00, 0x10, 0x00, 0x10, 0xd1, 0x00, 0xb3, 0x43, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0xe0, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x19, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xe0, 0xaa, 0x38, 0x05, 0xe0, 0x90, 0x30, 0xfa, 0x00, 0x96, 0x00, 0x4b, 0x09, 0x11, 0x00, 0x11, 0x00, 0x02, 0x00, 0x2d, 0x01, 0xd4, 0x7b, 0x3b, 0x01, 0xdb, 0x7a, 0x04, 0x00, 0x3f, 0x7b, 0xcd, 0x6c, 0xc3, 0x04, 0x85, 0x09, 0xc3, 0x04, 0xec, 0xe6, 0x0c, 0x46, 0x01, 0x00, 0x27, 0x00, 0x19, 0x00, 0x96, 0x00, 0xa0, 0x00, 0x01, 0x00, 0x0c, 0x00, 0xf0, 0x3c, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x32, 0x00, 0x05, 0x00, 0xee, 0x06, 0x04, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x04, 0x00, 0xa8, 0x05, 0xee, 0x06, 0x00, 0x04, 0xbc, 0x02, 0xb3, 0x00, 0x85, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x01, 0x00, 0xb9, 0x00, 0x01, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x2e, 0x00, 0xc1, 0xfd, 0x2d, 0xde, 0x00, 0xeb, 0x00, 0xda, 0x00, 0x00, 0x0c, 0xff, 0x0f, 0x00, 0x04, 0xc0, 0x00, 0x5b, 0xf5, 0xc9, 0x01, 0x1e, 0xf2, 0x80, 0x00, 0x3f, 0xff, 0x19, 0xf4, 0x58, 0xf5, 0x66, 0xf5, 0x64, 0xf5, 0xc0, 0xf1, 0xf0, 0x00, 0xe0, 0x00, 0xcd, 0x01, 0xd3, 0x01, 0xdb, 0x01, 0xff, 0x7f, 0xff, 0x01, 0xe4, 0x00, 0x74, 0xf7, 0xf3, 0x00, 0xfa, 0x00, 0xff, 0x3f, 0xca, 0x03, 0x6c, 0x38, 0x56, 0xfe, 0x44, 0xfd, 0xbc, 0x02, 0xf9, 0x06, 0x00, 0xfc, 0x12, 0x02, 0xae, 0x01, 0x58, 0xfa, 0x9a, 0xfd, 0x77, 0x05, 0xbb, 0x02, 0x96, 0x01, 0x95, 0x01, 0x7f, 0x01, 0x82, 0x01, 0x89, 0x01, 0x87, 0x01, 0x88, 0x01, 0x8a, 0x01, 0x8c, 0x01, 0x8f, 0x01, 0x8d, 0x01, 0x92, 0x01, 0x91, 0x01, 0xdd, 0x00, 0x9f, 0x01, 0x7e, 0x01, 0xdb, 0x00, 0xb6, 0x01, 0x70, 0x69, 0x26, 0xd3, 0x9c, 0x07, 0x1f, 0x05, 0x9d, 0x00, 0x00, 0x08, 0xbc, 0x05, 0x37, 0xfa, 0xa2, 0x01, 0xaa, 0x01, 0xa1, 0x01, 0xa8, 0x01, 0xa0, 0x01, 0xa8, 0x05, 0xb4, 0x01, 0xb4, 0x01, 0xce, 0x00, 0xd0, 0x00, 0xfc, 0x00, 0xc5, 0x01, 0xff, 0xfb, 0xb1, 0x00, 0x00, 0x38, 0x00, 0x30, 0xfd, 0xf5, 0xfc, 0xf5, 0xcd, 0x01, 0xa0, 0x00, 0x5f, 0xff, 0x00, 0x40, 0xff, 0x00, 0x00, 0x80, 0x6d, 0x0f, 0xeb, 0x00, 0x7f, 0xff, 0xc2, 0xf5, 0x68, 0xf7, 0xb3, 0xf1, 0x67, 0x0f, 0x5b, 0x0f, 0x61, 0x0f, 0x80, 0x0f, 0x58, 0xf7, 0x5b, 0xf7, 0x83, 0x0f, 0x86, 0x00, 0x72, 0x0f, 0x85, 0x0f, 0xc6, 0xf1, 0x7f, 0x0f, 0x6c, 0xf7, 0x00, 0xe0, 0x00, 0xff, 0xd1, 0xf5, 0x87, 0x0f, 0x8a, 0x0f, 0xff, 0x03, 0xf0, 0x3f, 0x8b, 0x00, 0x8e, 0x00, 0x90, 0x00, 0xb9, 0x00, 0x2d, 0xf5, 0xca, 0xf5, 0xcb, 0x01, 0x20, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x50, 0x98, 0x2e, 0xd7, 0x0e, 0x50, 0x32, 0x98, 0x2e, 0xfa, 0x03, 0x00, 0x30, 0xf0, 0x7f, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x00, 0x2e, 0x01, 0x80, 0x08, 0xa2, 0xfb, 0x2f, 0x98, 0x2e, 0xba, 0x03, 0x21, 0x2e, 0x19, 0x00, 0x01, 0x2e, 0xee, 0x00, 0x00, 0xb2, 0x07, 0x2f, 0x01, 0x2e, 0x19, 0x00, 0x00, 0xb2, 0x03, 0x2f, 0x01, 0x50, 0x03, 0x52, 0x98, 0x2e, 0x07, 0xcc, 0x01, 0x2e, 0xdd, 0x00, 0x00, 0xb2, 0x27, 0x2f, 0x05, 0x2e, 0x8a, 0x00, 0x05, 0x52, 0x98, 0x2e, 0xc7, 0xc1, 0x03, 0x2e, 0xe9, 0x00, 0x40, 0xb2, 0xf0, 0x7f, 0x08, 0x2f, 0x01, 0x2e, 0x19, 0x00, 0x00, 0xb2, 0x04, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0xe9, 0x00, 0x98, 0x2e, 0xb4, 0xb1, 0x01, 0x2e, 0x18, 0x00, 0x00, 0xb2, 0x10, 0x2f, 0x05, 0x50, 0x98, 0x2e, 0x4d, 0xc3, 0x05, 0x50, 0x98, 0x2e, 0x5a, 0xc7, 0x98, 0x2e, 0xf9, 0xb4, 0x98, 0x2e, 0x54, 0xb2, 0x98, 0x2e, 0x67, 0xb6, 0x98, 0x2e, 0x17, 0xb2, 0x10, 0x30, 0x21, 0x2e, 0x77, 0x00, 0x01, 0x2e, 0xef, 0x00, 0x00, 0xb2, 0x04, 0x2f, 0x98, 0x2e, 0x7a, 0xb7, 0x00, 0x30, 0x21, 0x2e, 0xef, 0x00, 0x01, 0x2e, 0xd4, 0x00, 0x04, 0xae, 0x0b, 0x2f, 0x01, 0x2e, 0xdd, 0x00, 0x00, 0xb2, 0x07, 0x2f, 0x05, 0x52, 0x98, 0x2e, 0x8e, 0x0e, 0x00, 0xb2, 0x02, 0x2f, 0x10, 0x30, 0x21, 0x2e, 0x7d, 0x00, 0x01, 0x2e, 0x7d, 0x00, 0x00, 0x90, 0x90, 0x2e, 0xf1, 0x02, 0x01, 0x2e, 0xd7, 0x00, 0x00, 0xb2, 0x04, 0x2f, 0x98, 0x2e, 0x2f, 0x0e, 0x00, 0x30, 0x21, 0x2e, 0x7b, 0x00, 0x01, 0x2e, 0x7b, 0x00, 0x00, 0xb2, 0x12, 0x2f, 0x01, 0x2e, 0xd4, 0x00, 0x00, 0x90, 0x02, 0x2f, 0x98, 0x2e, 0x1f, 0x0e, 0x09, 0x2d, 0x98, 0x2e, 0x81, 0x0d, 0x01, 0x2e, 0xd4, 0x00, 0x04, 0x90, 0x02, 0x2f, 0x50, 0x32, 0x98, 0x2e, 0xfa, 0x03, 0x00, 0x30, 0x21, 0x2e, 0x7b, 0x00, 0x01, 0x2e, 0x7c, 0x00, 0x00, 0xb2, 0x90, 0x2e, 0x09, 0x03, 0x01, 0x2e, 0x7c, 0x00, 0x01, 0x31, 0x01, 0x08, 0x00, 0xb2, 0x04, 0x2f, 0x98, 0x2e, 0x47, 0xcb, 0x10, 0x30, 0x21, 0x2e, 0x77, 0x00, 0x81, 0x30, 0x01, 0x2e, 0x7c, 0x00, 0x01, 0x08, 0x00, 0xb2, 0x61, 0x2f, 0x03, 0x2e, 0x89, 0x00, 0x01, 0x2e, 0xd4, 0x00, 0x98, 0xbc, 0x98, 0xb8, 0x05, 0xb2, 0x0f, 0x58, 0x23, 0x2f, 0x07, 0x90, 0x09, 0x54, 0x00, 0x30, 0x37, 0x2f, 0x15, 0x41, 0x04, 0x41, 0xdc, 0xbe, 0x44, 0xbe, 0xdc, 0xba, 0x2c, 0x01, 0x61, 0x00, 0x0f, 0x56, 0x4a, 0x0f, 0x0c, 0x2f, 0xd1, 0x42, 0x94, 0xb8, 0xc1, 0x42, 0x11, 0x30, 0x05, 0x2e, 0x6a, 0xf7, 0x2c, 0xbd, 0x2f, 0xb9, 0x80, 0xb2, 0x08, 0x22, 0x98, 0x2e, 0xc3, 0xb7, 0x21, 0x2d, 0x61, 0x30, 0x23, 0x2e, 0xd4, 0x00, 0x98, 0x2e, 0xc3, 0xb7, 0x00, 0x30, 0x21, 0x2e, 0x5a, 0xf5, 0x18, 0x2d, 0xe1, 0x7f, 0x50, 0x30, 0x98, 0x2e, 0xfa, 0x03, 0x0f, 0x52, 0x07, 0x50, 0x50, 0x42, 0x70, 0x30, 0x0d, 0x54, 0x42, 0x42, 0x7e, 0x82, 0xe2, 0x6f, 0x80, 0xb2, 0x42, 0x42, 0x05, 0x2f, 0x21, 0x2e, 0xd4, 0x00, 0x10, 0x30, 0x98, 0x2e, 0xc3, 0xb7, 0x03, 0x2d, 0x60, 0x30, 0x21, 0x2e, 0xd4, 0x00, 0x01, 0x2e, 0xd4, 0x00, 0x06, 0x90, 0x18, 0x2f, 0x01, 0x2e, 0x76, 0x00, 0x0b, 0x54, 0x07, 0x52, 0xe0, 0x7f, 0x98, 0x2e, 0x7a, 0xc1, 0xe1, 0x6f, 0x08, 0x1a, 0x40, 0x30, 0x08, 0x2f, 0x21, 0x2e, 0xd4, 0x00, 0x20, 0x30, 0x98, 0x2e, 0xaf, 0xb7, 0x50, 0x32, 0x98, 0x2e, 0xfa, 0x03, 0x05, 0x2d, 0x98, 0x2e, 0x38, 0x0e, 0x00, 0x30, 0x21, 0x2e, 0xd4, 0x00, 0x00, 0x30, 0x21, 0x2e, 0x7c, 0x00, 0x18, 0x2d, 0x01, 0x2e, 0xd4, 0x00, 0x03, 0xaa, 0x01, 0x2f, 0x98, 0x2e, 0x45, 0x0e, 0x01, 0x2e, 0xd4, 0x00, 0x3f, 0x80, 0x03, 0xa2, 0x01, 0x2f, 0x00, 0x2e, 0x02, 0x2d, 0x98, 0x2e, 0x5b, 0x0e, 0x30, 0x30, 0x98, 0x2e, 0xce, 0xb7, 0x00, 0x30, 0x21, 0x2e, 0x7d, 0x00, 0x50, 0x32, 0x98, 0x2e, 0xfa, 0x03, 0x01, 0x2e, 0x77, 0x00, 0x00, 0xb2, 0x24, 0x2f, 0x98, 0x2e, 0xf5, 0xcb, 0x03, 0x2e, 0xd5, 0x00, 0x11, 0x54, 0x01, 0x0a, 0xbc, 0x84, 0x83, 0x86, 0x21, 0x2e, 0xc9, 0x01, 0xe0, 0x40, 0x13, 0x52, 0xc4, 0x40, 0x82, 0x40, 0xa8, 0xb9, 0x52, 0x42, 0x43, 0xbe, 0x53, 0x42, 0x04, 0x0a, 0x50, 0x42, 0xe1, 0x7f, 0xf0, 0x31, 0x41, 0x40, 0xf2, 0x6f, 0x25, 0xbd, 0x08, 0x08, 0x02, 0x0a, 0xd0, 0x7f, 0x98, 0x2e, 0xa8, 0xcf, 0x06, 0xbc, 0xd1, 0x6f, 0xe2, 0x6f, 0x08, 0x0a, 0x80, 0x42, 0x98, 0x2e, 0x58, 0xb7, 0x00, 0x30, 0x21, 0x2e, 0xee, 0x00, 0x21, 0x2e, 0x77, 0x00, 0x21, 0x2e, 0xdd, 0x00, 0x80, 0x2e, 0xf4, 0x01, 0x1a, 0x24, 0x22, 0x00, 0x80, 0x2e, 0xec, 0x01, 0x10, 0x50, 0xfb, 0x7f, 0x98, 0x2e, 0xf3, 0x03, 0x57, 0x50, 0xfb, 0x6f, 0x01, 0x30, 0x71, 0x54, 0x11, 0x42, 0x42, 0x0e, 0xfc, 0x2f, 0xc0, 0x2e, 0x01, 0x42, 0xf0, 0x5f, 0x80, 0x2e, 0x00, 0xc1, 0xfd, 0x2d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x01, 0x34, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x50, 0xe7, 0x7f, 0xf6, 0x7f, 0x06, 0x32, 0x0f, 0x2e, 0x61, 0xf5, 0xfe, 0x09, 0xc0, 0xb3, 0x04, 0x2f, 0x17, 0x30, 0x2f, 0x2e, 0xef, 0x00, 0x2d, 0x2e, 0x61, 0xf5, 0xf6, 0x6f, 0xe7, 0x6f, 0xe0, 0x5f, 0xc8, 0x2e, 0x20, 0x50, 0xe7, 0x7f, 0xf6, 0x7f, 0x46, 0x30, 0x0f, 0x2e, 0xa4, 0xf1, 0xbe, 0x09, 0x80, 0xb3, 0x06, 0x2f, 0x0d, 0x2e, 0xd4, 0x00, 0x84, 0xaf, 0x02, 0x2f, 0x16, 0x30, 0x2d, 0x2e, 0x7b, 0x00, 0x86, 0x30, 0x2d, 0x2e, 0x60, 0xf5, 0xf6, 0x6f, 0xe7, 0x6f, 0xe0, 0x5f, 0xc8, 0x2e, 0x01, 0x2e, 0x77, 0xf7, 0x09, 0xbc, 0x0f, 0xb8, 0x00, 0xb2, 0x10, 0x50, 0xfb, 0x7f, 0x10, 0x30, 0x0b, 0x2f, 0x03, 0x2e, 0x8a, 0x00, 0x96, 0xbc, 0x9f, 0xb8, 0x40, 0xb2, 0x05, 0x2f, 0x03, 0x2e, 0x68, 0xf7, 0x9e, 0xbc, 0x9f, 0xb8, 0x40, 0xb2, 0x07, 0x2f, 0x03, 0x2e, 0x7e, 0x00, 0x41, 0x90, 0x01, 0x2f, 0x98, 0x2e, 0xdc, 0x03, 0x03, 0x2c, 0x00, 0x30, 0x21, 0x2e, 0x7e, 0x00, 0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x20, 0x50, 0xe0, 0x7f, 0xfb, 0x7f, 0x00, 0x2e, 0x27, 0x50, 0x98, 0x2e, 0x3b, 0xc8, 0x29, 0x50, 0x98, 0x2e, 0xa7, 0xc8, 0x01, 0x50, 0x98, 0x2e, 0x55, 0xcc, 0xe1, 0x6f, 0x2b, 0x50, 0x98, 0x2e, 0xe0, 0xc9, 0xfb, 0x6f, 0x00, 0x30, 0xe0, 0x5f, 0x21, 0x2e, 0x7e, 0x00, 0xb8, 0x2e, 0x73, 0x50, 0x01, 0x30, 0x57, 0x54, 0x11, 0x42, 0x42, 0x0e, 0xfc, 0x2f, 0xb8, 0x2e, 0x21, 0x2e, 0x59, 0xf5, 0x10, 0x30, 0xc0, 0x2e, 0x21, 0x2e, 0x4a, 0xf1, 0x90, 0x50, 0xf7, 0x7f, 0xe6, 0x7f, 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0xa1, 0x7f, 0x90, 0x7f, 0x82, 0x7f, 0x7b, 0x7f, 0x98, 0x2e, 0x35, 0xb7, 0x00, 0xb2, 0x90, 0x2e, 0x97, 0xb0, 0x03, 0x2e, 0x8f, 0x00, 0x07, 0x2e, 0x91, 0x00, 0x05, 0x2e, 0xb1, 0x00, 0x3f, 0xba, 0x9f, 0xb8, 0x01, 0x2e, 0xb1, 0x00, 0xa3, 0xbd, 0x4c, 0x0a, 0x05, 0x2e, 0xb1, 0x00, 0x04, 0xbe, 0xbf, 0xb9, 0xcb, 0x0a, 0x4f, 0xba, 0x22, 0xbd, 0x01, 0x2e, 0xb3, 0x00, 0xdc, 0x0a, 0x2f, 0xb9, 0x03, 0x2e, 0xb8, 0x00, 0x0a, 0xbe, 0x9a, 0x0a, 0xcf, 0xb9, 0x9b, 0xbc, 0x01, 0x2e, 0x97, 0x00, 0x9f, 0xb8, 0x93, 0x0a, 0x0f, 0xbc, 0x91, 0x0a, 0x0f, 0xb8, 0x90, 0x0a, 0x25, 0x2e, 0x18, 0x00, 0x05, 0x2e, 0xc1, 0xf5, 0x2e, 0xbd, 0x2e, 0xb9, 0x01, 0x2e, 0x19, 0x00, 0x31, 0x30, 0x8a, 0x04, 0x00, 0x90, 0x07, 0x2f, 0x01, 0x2e, 0xd4, 0x00, 0x04, 0xa2, 0x03, 0x2f, 0x01, 0x2e, 0x18, 0x00, 0x00, 0xb2, 0x0c, 0x2f, 0x19, 0x50, 0x05, 0x52, 0x98, 0x2e, 0x4d, 0xb7, 0x05, 0x2e, 0x78, 0x00, 0x80, 0x90, 0x10, 0x30, 0x01, 0x2f, 0x21, 0x2e, 0x78, 0x00, 0x25, 0x2e, 0xdd, 0x00, 0x98, 0x2e, 0x3e, 0xb7, 0x00, 0xb2, 0x02, 0x30, 0x01, 0x30, 0x04, 0x2f, 0x01, 0x2e, 0x19, 0x00, 0x00, 0xb2, 0x00, 0x2f, 0x21, 0x30, 0x01, 0x2e, 0xea, 0x00, 0x08, 0x1a, 0x0e, 0x2f, 0x23, 0x2e, 0xea, 0x00, 0x33, 0x30, 0x1b, 0x50, 0x0b, 0x09, 0x01, 0x40, 0x17, 0x56, 0x46, 0xbe, 0x4b, 0x08, 0x4c, 0x0a, 0x01, 0x42, 0x0a, 0x80, 0x15, 0x52, 0x01, 0x42, 0x00, 0x2e, 0x01, 0x2e, 0x18, 0x00, 0x00, 0xb2, 0x1f, 0x2f, 0x03, 0x2e, 0xc0, 0xf5, 0xf0, 0x30, 0x48, 0x08, 0x47, 0xaa, 0x74, 0x30, 0x07, 0x2e, 0x7a, 0x00, 0x61, 0x22, 0x4b, 0x1a, 0x05, 0x2f, 0x07, 0x2e, 0x66, 0xf5, 0xbf, 0xbd, 0xbf, 0xb9, 0xc0, 0x90, 0x0b, 0x2f, 0x1d, 0x56, 0x2b, 0x30, 0xd2, 0x42, 0xdb, 0x42, 0x01, 0x04, 0xc2, 0x42, 0x04, 0xbd, 0xfe, 0x80, 0x81, 0x84, 0x23, 0x2e, 0x7a, 0x00, 0x02, 0x42, 0x02, 0x32, 0x25, 0x2e, 0x62, 0xf5, 0x05, 0x2e, 0xd6, 0x00, 0x81, 0x84, 0x25, 0x2e, 0xd6, 0x00, 0x02, 0x31, 0x25, 0x2e, 0x60, 0xf5, 0x05, 0x2e, 0x8a, 0x00, 0x0b, 0x50, 0x90, 0x08, 0x80, 0xb2, 0x0b, 0x2f, 0x05, 0x2e, 0xca, 0xf5, 0xf0, 0x3e, 0x90, 0x08, 0x25, 0x2e, 0xca, 0xf5, 0x05, 0x2e, 0x59, 0xf5, 0xe0, 0x3f, 0x90, 0x08, 0x25, 0x2e, 0x59, 0xf5, 0x90, 0x6f, 0xa1, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0xe6, 0x6f, 0xf7, 0x6f, 0x7b, 0x6f, 0x82, 0x6f, 0x70, 0x5f, 0xc8, 0x2e, 0xc0, 0x50, 0x90, 0x7f, 0xe5, 0x7f, 0xd4, 0x7f, 0xc3, 0x7f, 0xb1, 0x7f, 0xa2, 0x7f, 0x87, 0x7f, 0xf6, 0x7f, 0x7b, 0x7f, 0x00, 0x2e, 0x01, 0x2e, 0x60, 0xf5, 0x60, 0x7f, 0x98, 0x2e, 0x35, 0xb7, 0x02, 0x30, 0x63, 0x6f, 0x15, 0x52, 0x50, 0x7f, 0x62, 0x7f, 0x5a, 0x2c, 0x02, 0x32, 0x1a, 0x09, 0x00, 0xb3, 0x14, 0x2f, 0x00, 0xb2, 0x03, 0x2f, 0x09, 0x2e, 0x18, 0x00, 0x00, 0x91, 0x0c, 0x2f, 0x43, 0x7f, 0x98, 0x2e, 0x97, 0xb7, 0x1f, 0x50, 0x02, 0x8a, 0x02, 0x32, 0x04, 0x30, 0x25, 0x2e, 0x64, 0xf5, 0x15, 0x52, 0x50, 0x6f, 0x43, 0x6f, 0x44, 0x43, 0x25, 0x2e, 0x60, 0xf5, 0xd9, 0x08, 0xc0, 0xb2, 0x36, 0x2f, 0x98, 0x2e, 0x3e, 0xb7, 0x00, 0xb2, 0x06, 0x2f, 0x01, 0x2e, 0x19, 0x00, 0x00, 0xb2, 0x02, 0x2f, 0x50, 0x6f, 0x00, 0x90, 0x0a, 0x2f, 0x01, 0x2e, 0x79, 0x00, 0x00, 0x90, 0x19, 0x2f, 0x10, 0x30, 0x21, 0x2e, 0x79, 0x00, 0x00, 0x30, 0x98, 0x2e, 0xdc, 0x03, 0x13, 0x2d, 0x01, 0x2e, 0xc3, 0xf5, 0x0c, 0xbc, 0x0f, 0xb8, 0x12, 0x30, 0x10, 0x04, 0x03, 0xb0, 0x26, 0x25, 0x21, 0x50, 0x03, 0x52, 0x98, 0x2e, 0x4d, 0xb7, 0x10, 0x30, 0x21, 0x2e, 0xee, 0x00, 0x02, 0x30, 0x60, 0x7f, 0x25, 0x2e, 0x79, 0x00, 0x60, 0x6f, 0x00, 0x90, 0x05, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0xea, 0x00, 0x15, 0x50, 0x21, 0x2e, 0x64, 0xf5, 0x15, 0x52, 0x23, 0x2e, 0x60, 0xf5, 0x02, 0x32, 0x50, 0x6f, 0x00, 0x90, 0x02, 0x2f, 0x03, 0x30, 0x27, 0x2e, 0x78, 0x00, 0x07, 0x2e, 0x60, 0xf5, 0x1a, 0x09, 0x00, 0x91, 0xa3, 0x2f, 0x19, 0x09, 0x00, 0x91, 0xa0, 0x2f, 0x90, 0x6f, 0xa2, 0x6f, 0xb1, 0x6f, 0xc3, 0x6f, 0xd4, 0x6f, 0xe5, 0x6f, 0x7b, 0x6f, 0xf6, 0x6f, 0x87, 0x6f, 0x40, 0x5f, 0xc8, 0x2e, 0xc0, 0x50, 0xe7, 0x7f, 0xf6, 0x7f, 0x26, 0x30, 0x0f, 0x2e, 0x61, 0xf5, 0x2f, 0x2e, 0x7c, 0x00, 0x0f, 0x2e, 0x7c, 0x00, 0xbe, 0x09, 0xa2, 0x7f, 0x80, 0x7f, 0x80, 0xb3, 0xd5, 0x7f, 0xc4, 0x7f, 0xb3, 0x7f, 0x91, 0x7f, 0x7b, 0x7f, 0x0b, 0x2f, 0x23, 0x50, 0x1a, 0x25, 0x12, 0x40, 0x42, 0x7f, 0x74, 0x82, 0x12, 0x40, 0x52, 0x7f, 0x00, 0x2e, 0x00, 0x40, 0x60, 0x7f, 0x98, 0x2e, 0x6a, 0xd6, 0x81, 0x30, 0x01, 0x2e, 0x7c, 0x00, 0x01, 0x08, 0x00, 0xb2, 0x42, 0x2f, 0x03, 0x2e, 0x89, 0x00, 0x01, 0x2e, 0x89, 0x00, 0x97, 0xbc, 0x06, 0xbc, 0x9f, 0xb8, 0x0f, 0xb8, 0x00, 0x90, 0x23, 0x2e, 0xd8, 0x00, 0x10, 0x30, 0x01, 0x30, 0x2a, 0x2f, 0x03, 0x2e, 0xd4, 0x00, 0x44, 0xb2, 0x05, 0x2f, 0x47, 0xb2, 0x00, 0x30, 0x2d, 0x2f, 0x21, 0x2e, 0x7c, 0x00, 0x2b, 0x2d, 0x03, 0x2e, 0xfd, 0xf5, 0x9e, 0xbc, 0x9f, 0xb8, 0x40, 0x90, 0x14, 0x2f, 0x03, 0x2e, 0xfc, 0xf5, 0x99, 0xbc, 0x9f, 0xb8, 0x40, 0x90, 0x0e, 0x2f, 0x03, 0x2e, 0x49, 0xf1, 0x25, 0x54, 0x4a, 0x08, 0x40, 0x90, 0x08, 0x2f, 0x98, 0x2e, 0x35, 0xb7, 0x00, 0xb2, 0x10, 0x30, 0x03, 0x2f, 0x50, 0x30, 0x21, 0x2e, 0xd4, 0x00, 0x10, 0x2d, 0x98, 0x2e, 0xaf, 0xb7, 0x00, 0x30, 0x21, 0x2e, 0x7c, 0x00, 0x0a, 0x2d, 0x05, 0x2e, 0x69, 0xf7, 0x2d, 0xbd, 0x2f, 0xb9, 0x80, 0xb2, 0x01, 0x2f, 0x21, 0x2e, 0x7d, 0x00, 0x23, 0x2e, 0x7c, 0x00, 0xe0, 0x31, 0x21, 0x2e, 0x61, 0xf5, 0xf6, 0x6f, 0xe7, 0x6f, 0x80, 0x6f, 0xa2, 0x6f, 0xb3, 0x6f, 0xc4, 0x6f, 0xd5, 0x6f, 0x7b, 0x6f, 0x91, 0x6f, 0x40, 0x5f, 0xc8, 0x2e, 0x60, 0x51, 0x0a, 0x25, 0x36, 0x88, 0xf4, 0x7f, 0xeb, 0x7f, 0x00, 0x32, 0x31, 0x52, 0x32, 0x30, 0x13, 0x30, 0x98, 0x2e, 0x15, 0xcb, 0x0a, 0x25, 0x33, 0x84, 0xd2, 0x7f, 0x43, 0x30, 0x05, 0x50, 0x2d, 0x52, 0x98, 0x2e, 0x95, 0xc1, 0xd2, 0x6f, 0x27, 0x52, 0x98, 0x2e, 0xd7, 0xc7, 0x2a, 0x25, 0xb0, 0x86, 0xc0, 0x7f, 0xd3, 0x7f, 0xaf, 0x84, 0x29, 0x50, 0xf1, 0x6f, 0x98, 0x2e, 0x4d, 0xc8, 0x2a, 0x25, 0xae, 0x8a, 0xaa, 0x88, 0xf2, 0x6e, 0x2b, 0x50, 0xc1, 0x6f, 0xd3, 0x6f, 0xf4, 0x7f, 0x98, 0x2e, 0xb6, 0xc8, 0xe0, 0x6e, 0x00, 0xb2, 0x32, 0x2f, 0x33, 0x54, 0x83, 0x86, 0xf1, 0x6f, 0xc3, 0x7f, 0x04, 0x30, 0x30, 0x30, 0xf4, 0x7f, 0xd0, 0x7f, 0xb2, 0x7f, 0xe3, 0x30, 0xc5, 0x6f, 0x56, 0x40, 0x45, 0x41, 0x28, 0x08, 0x03, 0x14, 0x0e, 0xb4, 0x08, 0xbc, 0x82, 0x40, 0x10, 0x0a, 0x2f, 0x54, 0x26, 0x05, 0x91, 0x7f, 0x44, 0x28, 0xa3, 0x7f, 0x98, 0x2e, 0xd9, 0xc0, 0x08, 0xb9, 0x33, 0x30, 0x53, 0x09, 0xc1, 0x6f, 0xd3, 0x6f, 0xf4, 0x6f, 0x83, 0x17, 0x47, 0x40, 0x6c, 0x15, 0xb2, 0x6f, 0xbe, 0x09, 0x75, 0x0b, 0x90, 0x42, 0x45, 0x42, 0x51, 0x0e, 0x32, 0xbc, 0x02, 0x89, 0xa1, 0x6f, 0x7e, 0x86, 0xf4, 0x7f, 0xd0, 0x7f, 0xb2, 0x7f, 0x04, 0x30, 0x91, 0x6f, 0xd6, 0x2f, 0xeb, 0x6f, 0xa0, 0x5e, 0xb8, 0x2e, 0x03, 0x2e, 0x97, 0x00, 0x1b, 0xbc, 0x60, 0x50, 0x9f, 0xbc, 0x0c, 0xb8, 0xf0, 0x7f, 0x40, 0xb2, 0xeb, 0x7f, 0x2b, 0x2f, 0x03, 0x2e, 0x7f, 0x00, 0x41, 0x40, 0x01, 0x2e, 0xc8, 0x00, 0x01, 0x1a, 0x11, 0x2f, 0x37, 0x58, 0x23, 0x2e, 0xc8, 0x00, 0x10, 0x41, 0xa0, 0x7f, 0x38, 0x81, 0x01, 0x41, 0xd0, 0x7f, 0xb1, 0x7f, 0x98, 0x2e, 0x64, 0xcf, 0xd0, 0x6f, 0x07, 0x80, 0xa1, 0x6f, 0x11, 0x42, 0x00, 0x2e, 0xb1, 0x6f, 0x01, 0x42, 0x11, 0x30, 0x01, 0x2e, 0xfc, 0x00, 0x00, 0xa8, 0x03, 0x30, 0xcb, 0x22, 0x4a, 0x25, 0x01, 0x2e, 0x7f, 0x00, 0x3c, 0x89, 0x35, 0x52, 0x05, 0x54, 0x98, 0x2e, 0xc4, 0xce, 0xc1, 0x6f, 0xf0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0x04, 0x2d, 0x01, 0x30, 0xf0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0xeb, 0x6f, 0xa0, 0x5f, 0xb8, 0x2e, 0x03, 0x2e, 0xb3, 0x00, 0x02, 0x32, 0xf0, 0x30, 0x03, 0x31, 0x30, 0x50, 0x8a, 0x08, 0x08, 0x08, 0xcb, 0x08, 0xe0, 0x7f, 0x80, 0xb2, 0xf3, 0x7f, 0xdb, 0x7f, 0x25, 0x2f, 0x03, 0x2e, 0xca, 0x00, 0x41, 0x90, 0x04, 0x2f, 0x01, 0x30, 0x23, 0x2e, 0xca, 0x00, 0x98, 0x2e, 0x3f, 0x03, 0xc0, 0xb2, 0x05, 0x2f, 0x03, 0x2e, 0xda, 0x00, 0x00, 0x30, 0x41, 0x04, 0x23, 0x2e, 0xda, 0x00, 0x98, 0x2e, 0x92, 0xb2, 0x10, 0x25, 0xf0, 0x6f, 0x00, 0xb2, 0x05, 0x2f, 0x01, 0x2e, 0xda, 0x00, 0x02, 0x30, 0x10, 0x04, 0x21, 0x2e, 0xda, 0x00, 0x40, 0xb2, 0x01, 0x2f, 0x23, 0x2e, 0xc8, 0x01, 0xdb, 0x6f, 0xe0, 0x6f, 0xd0, 0x5f, 0x80, 0x2e, 0x95, 0xcf, 0x01, 0x30, 0xe0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0x11, 0x30, 0x23, 0x2e, 0xca, 0x00, 0xdb, 0x6f, 0xd0, 0x5f, 0xb8, 0x2e, 0xd0, 0x50, 0x0a, 0x25, 0x33, 0x84, 0x55, 0x50, 0xd2, 0x7f, 0xe2, 0x7f, 0x03, 0x8c, 0xc0, 0x7f, 0xbb, 0x7f, 0x00, 0x30, 0x05, 0x5a, 0x39, 0x54, 0x51, 0x41, 0xa5, 0x7f, 0x96, 0x7f, 0x80, 0x7f, 0x98, 0x2e, 0xd9, 0xc0, 0x05, 0x30, 0xf5, 0x7f, 0x20, 0x25, 0x91, 0x6f, 0x3b, 0x58, 0x3d, 0x5c, 0x3b, 0x56, 0x98, 0x2e, 0x67, 0xcc, 0xc1, 0x6f, 0xd5, 0x6f, 0x52, 0x40, 0x50, 0x43, 0xc1, 0x7f, 0xd5, 0x7f, 0x10, 0x25, 0x98, 0x2e, 0xfe, 0xc9, 0x10, 0x25, 0x98, 0x2e, 0x74, 0xc0, 0x86, 0x6f, 0x30, 0x28, 0x92, 0x6f, 0x82, 0x8c, 0xa5, 0x6f, 0x6f, 0x52, 0x69, 0x0e, 0x39, 0x54, 0xdb, 0x2f, 0x19, 0xa0, 0x15, 0x30, 0x03, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0x81, 0x01, 0x0a, 0x2d, 0x01, 0x2e, 0x81, 0x01, 0x05, 0x28, 0x42, 0x36, 0x21, 0x2e, 0x81, 0x01, 0x02, 0x0e, 0x01, 0x2f, 0x98, 0x2e, 0xf3, 0x03, 0x57, 0x50, 0x12, 0x30, 0x01, 0x40, 0x98, 0x2e, 0xfe, 0xc9, 0x51, 0x6f, 0x0b, 0x5c, 0x8e, 0x0e, 0x3b, 0x6f, 0x57, 0x58, 0x02, 0x30, 0x21, 0x2e, 0x95, 0x01, 0x45, 0x6f, 0x2a, 0x8d, 0xd2, 0x7f, 0xcb, 0x7f, 0x13, 0x2f, 0x02, 0x30, 0x3f, 0x50, 0xd2, 0x7f, 0xa8, 0x0e, 0x0e, 0x2f, 0xc0, 0x6f, 0x53, 0x54, 0x02, 0x00, 0x51, 0x54, 0x42, 0x0e, 0x10, 0x30, 0x59, 0x52, 0x02, 0x30, 0x01, 0x2f, 0x00, 0x2e, 0x03, 0x2d, 0x50, 0x42, 0x42, 0x42, 0x12, 0x30, 0xd2, 0x7f, 0x80, 0xb2, 0x03, 0x2f, 0x00, 0x30, 0x21, 0x2e, 0x80, 0x01, 0x12, 0x2d, 0x01, 0x2e, 0xc9, 0x00, 0x02, 0x80, 0x05, 0x2e, 0x80, 0x01, 0x11, 0x30, 0x91, 0x28, 0x00, 0x40, 0x25, 0x2e, 0x80, 0x01, 0x10, 0x0e, 0x05, 0x2f, 0x01, 0x2e, 0x7f, 0x01, 0x01, 0x90, 0x01, 0x2f, 0x98, 0x2e, 0xf3, 0x03, 0x00, 0x2e, 0xa0, 0x41, 0x01, 0x90, 0xa6, 0x7f, 0x90, 0x2e, 0xe3, 0xb4, 0x01, 0x2e, 0x95, 0x01, 0x00, 0xa8, 0x90, 0x2e, 0xe3, 0xb4, 0x5b, 0x54, 0x95, 0x80, 0x82, 0x40, 0x80, 0xb2, 0x02, 0x40, 0x2d, 0x8c, 0x3f, 0x52, 0x96, 0x7f, 0x90, 0x2e, 0xc2, 0xb3, 0x29, 0x0e, 0x76, 0x2f, 0x01, 0x2e, 0xc9, 0x00, 0x00, 0x40, 0x81, 0x28, 0x45, 0x52, 0xb3, 0x30, 0x98, 0x2e, 0x0f, 0xca, 0x5d, 0x54, 0x80, 0x7f, 0x00, 0x2e, 0xa1, 0x40, 0x72, 0x7f, 0x82, 0x80, 0x82, 0x40, 0x60, 0x7f, 0x98, 0x2e, 0xfe, 0xc9, 0x10, 0x25, 0x98, 0x2e, 0x74, 0xc0, 0x62, 0x6f, 0x05, 0x30, 0x87, 0x40, 0xc0, 0x91, 0x04, 0x30, 0x05, 0x2f, 0x05, 0x2e, 0x83, 0x01, 0x80, 0xb2, 0x14, 0x30, 0x00, 0x2f, 0x04, 0x30, 0x05, 0x2e, 0xc9, 0x00, 0x73, 0x6f, 0x81, 0x40, 0xe2, 0x40, 0x69, 0x04, 0x11, 0x0f, 0xe1, 0x40, 0x16, 0x30, 0xfe, 0x29, 0xcb, 0x40, 0x02, 0x2f, 0x83, 0x6f, 0x83, 0x0f, 0x22, 0x2f, 0x47, 0x56, 0x13, 0x0f, 0x12, 0x30, 0x77, 0x2f, 0x49, 0x54, 0x42, 0x0e, 0x12, 0x30, 0x73, 0x2f, 0x00, 0x91, 0x0a, 0x2f, 0x01, 0x2e, 0x8b, 0x01, 0x19, 0xa8, 0x02, 0x30, 0x6c, 0x2f, 0x63, 0x50, 0x00, 0x2e, 0x17, 0x42, 0x05, 0x42, 0x68, 0x2c, 0x12, 0x30, 0x0b, 0x25, 0x08, 0x0f, 0x50, 0x30, 0x02, 0x2f, 0x21, 0x2e, 0x83, 0x01, 0x03, 0x2d, 0x40, 0x30, 0x21, 0x2e, 0x83, 0x01, 0x2b, 0x2e, 0x85, 0x01, 0x5a, 0x2c, 0x12, 0x30, 0x00, 0x91, 0x2b, 0x25, 0x04, 0x2f, 0x63, 0x50, 0x02, 0x30, 0x17, 0x42, 0x17, 0x2c, 0x02, 0x42, 0x98, 0x2e, 0xfe, 0xc9, 0x10, 0x25, 0x98, 0x2e, 0x74, 0xc0, 0x05, 0x2e, 0xc9, 0x00, 0x81, 0x84, 0x5b, 0x30, 0x82, 0x40, 0x37, 0x2e, 0x83, 0x01, 0x02, 0x0e, 0x07, 0x2f, 0x5f, 0x52, 0x40, 0x30, 0x62, 0x40, 0x41, 0x40, 0x91, 0x0e, 0x01, 0x2f, 0x21, 0x2e, 0x83, 0x01, 0x05, 0x30, 0x2b, 0x2e, 0x85, 0x01, 0x12, 0x30, 0x36, 0x2c, 0x16, 0x30, 0x15, 0x25, 0x81, 0x7f, 0x98, 0x2e, 0xfe, 0xc9, 0x10, 0x25, 0x98, 0x2e, 0x74, 0xc0, 0x19, 0xa2, 0x16, 0x30, 0x15, 0x2f, 0x05, 0x2e, 0x97, 0x01, 0x80, 0x6f, 0x82, 0x0e, 0x05, 0x2f, 0x01, 0x2e, 0x86, 0x01, 0x06, 0x28, 0x21, 0x2e, 0x86, 0x01, 0x0b, 0x2d, 0x03, 0x2e, 0x87, 0x01, 0x5f, 0x54, 0x4e, 0x28, 0x91, 0x42, 0x00, 0x2e, 0x82, 0x40, 0x90, 0x0e, 0x01, 0x2f, 0x21, 0x2e, 0x88, 0x01, 0x02, 0x30, 0x13, 0x2c, 0x05, 0x30, 0xc0, 0x6f, 0x08, 0x1c, 0xa8, 0x0f, 0x16, 0x30, 0x05, 0x30, 0x5b, 0x50, 0x09, 0x2f, 0x02, 0x80, 0x2d, 0x2e, 0x82, 0x01, 0x05, 0x42, 0x05, 0x80, 0x00, 0x2e, 0x02, 0x42, 0x3e, 0x80, 0x00, 0x2e, 0x06, 0x42, 0x02, 0x30, 0x90, 0x6f, 0x3e, 0x88, 0x01, 0x40, 0x04, 0x41, 0x4c, 0x28, 0x01, 0x42, 0x07, 0x80, 0x10, 0x25, 0x24, 0x40, 0x00, 0x40, 0x00, 0xa8, 0xf5, 0x22, 0x23, 0x29, 0x44, 0x42, 0x7a, 0x82, 0x7e, 0x88, 0x43, 0x40, 0x04, 0x41, 0x00, 0xab, 0xf5, 0x23, 0xdf, 0x28, 0x43, 0x42, 0xd9, 0xa0, 0x14, 0x2f, 0x00, 0x90, 0x02, 0x2f, 0xd2, 0x6f, 0x81, 0xb2, 0x05, 0x2f, 0x63, 0x54, 0x06, 0x28, 0x90, 0x42, 0x85, 0x42, 0x09, 0x2c, 0x02, 0x30, 0x5b, 0x50, 0x03, 0x80, 0x29, 0x2e, 0x7e, 0x01, 0x2b, 0x2e, 0x82, 0x01, 0x05, 0x42, 0x12, 0x30, 0x2b, 0x2e, 0x83, 0x01, 0x45, 0x82, 0x00, 0x2e, 0x40, 0x40, 0x7a, 0x82, 0x02, 0xa0, 0x08, 0x2f, 0x63, 0x50, 0x3b, 0x30, 0x15, 0x42, 0x05, 0x42, 0x37, 0x80, 0x37, 0x2e, 0x7e, 0x01, 0x05, 0x42, 0x12, 0x30, 0x01, 0x2e, 0xc9, 0x00, 0x02, 0x8c, 0x40, 0x40, 0x84, 0x41, 0x7a, 0x8c, 0x04, 0x0f, 0x03, 0x2f, 0x01, 0x2e, 0x8b, 0x01, 0x19, 0xa4, 0x04, 0x2f, 0x2b, 0x2e, 0x82, 0x01, 0x98, 0x2e, 0xf3, 0x03, 0x12, 0x30, 0x81, 0x90, 0x61, 0x52, 0x08, 0x2f, 0x65, 0x42, 0x65, 0x42, 0x43, 0x80, 0x39, 0x84, 0x82, 0x88, 0x05, 0x42, 0x45, 0x42, 0x85, 0x42, 0x05, 0x43, 0x00, 0x2e, 0x80, 0x41, 0x00, 0x90, 0x90, 0x2e, 0xe1, 0xb4, 0x65, 0x54, 0xc1, 0x6f, 0x80, 0x40, 0x00, 0xb2, 0x43, 0x58, 0x69, 0x50, 0x44, 0x2f, 0x55, 0x5c, 0xb7, 0x87, 0x8c, 0x0f, 0x0d, 0x2e, 0x96, 0x01, 0xc4, 0x40, 0x36, 0x2f, 0x41, 0x56, 0x8b, 0x0e, 0x2a, 0x2f, 0x0b, 0x52, 0xa1, 0x0e, 0x0a, 0x2f, 0x05, 0x2e, 0x8f, 0x01, 0x14, 0x25, 0x98, 0x2e, 0xfe, 0xc9, 0x4b, 0x54, 0x02, 0x0f, 0x69, 0x50, 0x05, 0x30, 0x65, 0x54, 0x15, 0x2f, 0x03, 0x2e, 0x8e, 0x01, 0x4d, 0x5c, 0x8e, 0x0f, 0x3a, 0x2f, 0x05, 0x2e, 0x8f, 0x01, 0x98, 0x2e, 0xfe, 0xc9, 0x4f, 0x54, 0x82, 0x0f, 0x05, 0x30, 0x69, 0x50, 0x65, 0x54, 0x30, 0x2f, 0x6d, 0x52, 0x15, 0x30, 0x42, 0x8c, 0x45, 0x42, 0x04, 0x30, 0x2b, 0x2c, 0x84, 0x43, 0x6b, 0x52, 0x42, 0x8c, 0x00, 0x2e, 0x85, 0x43, 0x15, 0x30, 0x24, 0x2c, 0x45, 0x42, 0x8e, 0x0f, 0x20, 0x2f, 0x0d, 0x2e, 0x8e, 0x01, 0xb1, 0x0e, 0x1c, 0x2f, 0x23, 0x2e, 0x8e, 0x01, 0x1a, 0x2d, 0x0e, 0x0e, 0x17, 0x2f, 0xa1, 0x0f, 0x15, 0x2f, 0x23, 0x2e, 0x8d, 0x01, 0x13, 0x2d, 0x98, 0x2e, 0x74, 0xc0, 0x43, 0x54, 0xc2, 0x0e, 0x0a, 0x2f, 0x65, 0x50, 0x04, 0x80, 0x0b, 0x30, 0x06, 0x82, 0x0b, 0x42, 0x79, 0x80, 0x41, 0x40, 0x12, 0x30, 0x25, 0x2e, 0x8c, 0x01, 0x01, 0x42, 0x05, 0x30, 0x69, 0x50, 0x65, 0x54, 0x84, 0x82, 0x43, 0x84, 0xbe, 0x8c, 0x84, 0x40, 0x86, 0x41, 0x26, 0x29, 0x94, 0x42, 0xbe, 0x8e, 0xd5, 0x7f, 0x19, 0xa1, 0x43, 0x40, 0x0b, 0x2e, 0x8c, 0x01, 0x84, 0x40, 0xc7, 0x41, 0x5d, 0x29, 0x27, 0x29, 0x45, 0x42, 0x84, 0x42, 0xc2, 0x7f, 0x01, 0x2f, 0xc0, 0xb3, 0x1d, 0x2f, 0x05, 0x2e, 0x94, 0x01, 0x99, 0xa0, 0x01, 0x2f, 0x80, 0xb3, 0x13, 0x2f, 0x80, 0xb3, 0x18, 0x2f, 0xc0, 0xb3, 0x16, 0x2f, 0x12, 0x40, 0x01, 0x40, 0x92, 0x7f, 0x98, 0x2e, 0x74, 0xc0, 0x92, 0x6f, 0x10, 0x0f, 0x20, 0x30, 0x03, 0x2f, 0x10, 0x30, 0x21, 0x2e, 0x7e, 0x01, 0x0a, 0x2d, 0x21, 0x2e, 0x7e, 0x01, 0x07, 0x2d, 0x20, 0x30, 0x21, 0x2e, 0x7e, 0x01, 0x03, 0x2d, 0x10, 0x30, 0x21, 0x2e, 0x7e, 0x01, 0xc2, 0x6f, 0x01, 0x2e, 0xc9, 0x00, 0xbc, 0x84, 0x02, 0x80, 0x82, 0x40, 0x00, 0x40, 0x90, 0x0e, 0xd5, 0x6f, 0x02, 0x2f, 0x15, 0x30, 0x98, 0x2e, 0xf3, 0x03, 0x41, 0x91, 0x05, 0x30, 0x07, 0x2f, 0x67, 0x50, 0x3d, 0x80, 0x2b, 0x2e, 0x8f, 0x01, 0x05, 0x42, 0x04, 0x80, 0x00, 0x2e, 0x05, 0x42, 0x02, 0x2c, 0x00, 0x30, 0x00, 0x30, 0xa2, 0x6f, 0x98, 0x8a, 0x86, 0x40, 0x80, 0xa7, 0x05, 0x2f, 0x98, 0x2e, 0xf3, 0x03, 0xc0, 0x30, 0x21, 0x2e, 0x95, 0x01, 0x06, 0x25, 0x1a, 0x25, 0xe2, 0x6f, 0x76, 0x82, 0x96, 0x40, 0x56, 0x43, 0x51, 0x0e, 0xfb, 0x2f, 0xbb, 0x6f, 0x30, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0xb8, 0x00, 0x01, 0x31, 0x41, 0x08, 0x40, 0xb2, 0x20, 0x50, 0xf2, 0x30, 0x02, 0x08, 0xfb, 0x7f, 0x01, 0x30, 0x10, 0x2f, 0x05, 0x2e, 0xcc, 0x00, 0x81, 0x90, 0xe0, 0x7f, 0x03, 0x2f, 0x23, 0x2e, 0xcc, 0x00, 0x98, 0x2e, 0x55, 0xb6, 0x98, 0x2e, 0x1d, 0xb5, 0x10, 0x25, 0xfb, 0x6f, 0xe0, 0x6f, 0xe0, 0x5f, 0x80, 0x2e, 0x95, 0xcf, 0x98, 0x2e, 0x95, 0xcf, 0x10, 0x30, 0x21, 0x2e, 0xcc, 0x00, 0xfb, 0x6f, 0xe0, 0x5f, 0xb8, 0x2e, 0x00, 0x51, 0x05, 0x58, 0xeb, 0x7f, 0x2a, 0x25, 0x89, 0x52, 0x6f, 0x5a, 0x89, 0x50, 0x13, 0x41, 0x06, 0x40, 0xb3, 0x01, 0x16, 0x42, 0xcb, 0x16, 0x06, 0x40, 0xf3, 0x02, 0x13, 0x42, 0x65, 0x0e, 0xf5, 0x2f, 0x05, 0x40, 0x14, 0x30, 0x2c, 0x29, 0x04, 0x42, 0x08, 0xa1, 0x00, 0x30, 0x90, 0x2e, 0x52, 0xb6, 0xb3, 0x88, 0xb0, 0x8a, 0xb6, 0x84, 0xa4, 0x7f, 0xc4, 0x7f, 0xb5, 0x7f, 0xd5, 0x7f, 0x92, 0x7f, 0x73, 0x30, 0x04, 0x30, 0x55, 0x40, 0x42, 0x40, 0x8a, 0x17, 0xf3, 0x08, 0x6b, 0x01, 0x90, 0x02, 0x53, 0xb8, 0x4b, 0x82, 0xad, 0xbe, 0x71, 0x7f, 0x45, 0x0a, 0x09, 0x54, 0x84, 0x7f, 0x98, 0x2e, 0xd9, 0xc0, 0xa3, 0x6f, 0x7b, 0x54, 0xd0, 0x42, 0xa3, 0x7f, 0xf2, 0x7f, 0x60, 0x7f, 0x20, 0x25, 0x71, 0x6f, 0x75, 0x5a, 0x77, 0x58, 0x79, 0x5c, 0x75, 0x56, 0x98, 0x2e, 0x67, 0xcc, 0xb1, 0x6f, 0x62, 0x6f, 0x50, 0x42, 0xb1, 0x7f, 0xb3, 0x30, 0x10, 0x25, 0x98, 0x2e, 0x0f, 0xca, 0x84, 0x6f, 0x20, 0x29, 0x71, 0x6f, 0x92, 0x6f, 0xa5, 0x6f, 0x76, 0x82, 0x6a, 0x0e, 0x73, 0x30, 0x00, 0x30, 0xd0, 0x2f, 0xd2, 0x6f, 0xd1, 0x7f, 0xb4, 0x7f, 0x98, 0x2e, 0x2b, 0xb7, 0x15, 0xbd, 0x0b, 0xb8, 0x02, 0x0a, 0xc2, 0x6f, 0xc0, 0x7f, 0x98, 0x2e, 0x2b, 0xb7, 0x15, 0xbd, 0x0b, 0xb8, 0x42, 0x0a, 0xc0, 0x6f, 0x08, 0x17, 0x41, 0x18, 0x89, 0x16, 0xe1, 0x18, 0xd0, 0x18, 0xa1, 0x7f, 0x27, 0x25, 0x16, 0x25, 0x98, 0x2e, 0x79, 0xc0, 0x8b, 0x54, 0x90, 0x7f, 0xb3, 0x30, 0x82, 0x40, 0x80, 0x90, 0x0d, 0x2f, 0x7d, 0x52, 0x92, 0x6f, 0x98, 0x2e, 0x0f, 0xca, 0xb2, 0x6f, 0x90, 0x0e, 0x06, 0x2f, 0x8b, 0x50, 0x14, 0x30, 0x42, 0x6f, 0x51, 0x6f, 0x14, 0x42, 0x12, 0x42, 0x01, 0x42, 0x00, 0x2e, 0x31, 0x6f, 0x98, 0x2e, 0x74, 0xc0, 0x41, 0x6f, 0x80, 0x7f, 0x98, 0x2e, 0x74, 0xc0, 0x82, 0x6f, 0x10, 0x04, 0x43, 0x52, 0x01, 0x0f, 0x05, 0x2e, 0xcb, 0x00, 0x00, 0x30, 0x04, 0x30, 0x21, 0x2f, 0x51, 0x6f, 0x43, 0x58, 0x8c, 0x0e, 0x04, 0x30, 0x1c, 0x2f, 0x85, 0x88, 0x41, 0x6f, 0x04, 0x41, 0x8c, 0x0f, 0x04, 0x30, 0x16, 0x2f, 0x84, 0x88, 0x00, 0x2e, 0x04, 0x41, 0x04, 0x05, 0x8c, 0x0e, 0x04, 0x30, 0x0f, 0x2f, 0x82, 0x88, 0x31, 0x6f, 0x04, 0x41, 0x04, 0x05, 0x8c, 0x0e, 0x04, 0x30, 0x08, 0x2f, 0x83, 0x88, 0x00, 0x2e, 0x04, 0x41, 0x8c, 0x0f, 0x04, 0x30, 0x02, 0x2f, 0x21, 0x2e, 0xad, 0x01, 0x14, 0x30, 0x00, 0x91, 0x14, 0x2f, 0x03, 0x2e, 0xa1, 0x01, 0x41, 0x90, 0x0e, 0x2f, 0x03, 0x2e, 0xad, 0x01, 0x14, 0x30, 0x4c, 0x28, 0x23, 0x2e, 0xad, 0x01, 0x46, 0xa0, 0x06, 0x2f, 0x81, 0x84, 0x8d, 0x52, 0x48, 0x82, 0x82, 0x40, 0x21, 0x2e, 0xa1, 0x01, 0x42, 0x42, 0x5c, 0x2c, 0x02, 0x30, 0x05, 0x2e, 0xaa, 0x01, 0x80, 0xb2, 0x02, 0x30, 0x55, 0x2f, 0x03, 0x2e, 0xa9, 0x01, 0x92, 0x6f, 0xb3, 0x30, 0x98, 0x2e, 0x0f, 0xca, 0xb2, 0x6f, 0x90, 0x0f, 0x00, 0x30, 0x02, 0x30, 0x4a, 0x2f, 0xa2, 0x6f, 0x87, 0x52, 0x91, 0x00, 0x85, 0x52, 0x51, 0x0e, 0x02, 0x2f, 0x00, 0x2e, 0x43, 0x2c, 0x02, 0x30, 0xc2, 0x6f, 0x7f, 0x52, 0x91, 0x0e, 0x02, 0x30, 0x3c, 0x2f, 0x51, 0x6f, 0x81, 0x54, 0x98, 0x2e, 0xfe, 0xc9, 0x10, 0x25, 0xb3, 0x30, 0x21, 0x25, 0x98, 0x2e, 0x0f, 0xca, 0x32, 0x6f, 0xc0, 0x7f, 0xb3, 0x30, 0x12, 0x25, 0x98, 0x2e, 0x0f, 0xca, 0x42, 0x6f, 0xb0, 0x7f, 0xb3, 0x30, 0x12, 0x25, 0x98, 0x2e, 0x0f, 0xca, 0xb2, 0x6f, 0x90, 0x28, 0x83, 0x52, 0x98, 0x2e, 0xfe, 0xc9, 0xc2, 0x6f, 0x90, 0x0f, 0x00, 0x30, 0x02, 0x30, 0x1d, 0x2f, 0x05, 0x2e, 0xa1, 0x01, 0x80, 0xb2, 0x12, 0x30, 0x0f, 0x2f, 0x42, 0x6f, 0x03, 0x2e, 0xab, 0x01, 0x91, 0x0e, 0x02, 0x30, 0x12, 0x2f, 0x52, 0x6f, 0x03, 0x2e, 0xac, 0x01, 0x91, 0x0f, 0x02, 0x30, 0x0c, 0x2f, 0x21, 0x2e, 0xaa, 0x01, 0x0a, 0x2c, 0x12, 0x30, 0x03, 0x2e, 0xcb, 0x00, 0x8d, 0x58, 0x08, 0x89, 0x41, 0x40, 0x11, 0x43, 0x00, 0x43, 0x25, 0x2e, 0xa1, 0x01, 0xd4, 0x6f, 0x8f, 0x52, 0x00, 0x43, 0x3a, 0x89, 0x00, 0x2e, 0x10, 0x43, 0x10, 0x43, 0x61, 0x0e, 0xfb, 0x2f, 0x03, 0x2e, 0xa0, 0x01, 0x11, 0x1a, 0x02, 0x2f, 0x02, 0x25, 0x21, 0x2e, 0xa0, 0x01, 0xeb, 0x6f, 0x00, 0x5f, 0xb8, 0x2e, 0x91, 0x52, 0x10, 0x30, 0x02, 0x30, 0x95, 0x56, 0x52, 0x42, 0x4b, 0x0e, 0xfc, 0x2f, 0x8d, 0x54, 0x88, 0x82, 0x93, 0x56, 0x80, 0x42, 0x53, 0x42, 0x40, 0x42, 0x42, 0x86, 0x83, 0x54, 0xc0, 0x2e, 0xc2, 0x42, 0x00, 0x2e, 0xa3, 0x52, 0x00, 0x51, 0x52, 0x40, 0x47, 0x40, 0x1a, 0x25, 0x01, 0x2e, 0x97, 0x00, 0x8f, 0xbe, 0x72, 0x86, 0xfb, 0x7f, 0x0b, 0x30, 0x7c, 0xbf, 0xa5, 0x50, 0x10, 0x08, 0xdf, 0xba, 0x70, 0x88, 0xf8, 0xbf, 0xcb, 0x42, 0xd3, 0x7f, 0x6c, 0xbb, 0xfc, 0xbb, 0xc5, 0x0a, 0x90, 0x7f, 0x1b, 0x7f, 0x0b, 0x43, 0xc0, 0xb2, 0xe5, 0x7f, 0xb7, 0x7f, 0xa6, 0x7f, 0xc4, 0x7f, 0x90, 0x2e, 0x1c, 0xb7, 0x07, 0x2e, 0xd2, 0x00, 0xc0, 0xb2, 0x0b, 0x2f, 0x97, 0x52, 0x01, 0x2e, 0xcd, 0x00, 0x82, 0x7f, 0x98, 0x2e, 0xbb, 0xcc, 0x0b, 0x30, 0x37, 0x2e, 0xd2, 0x00, 0x82, 0x6f, 0x90, 0x6f, 0x1a, 0x25, 0x00, 0xb2, 0x8b, 0x7f, 0x14, 0x2f, 0xa6, 0xbd, 0x25, 0xbd, 0xb6, 0xb9, 0x2f, 0xb9, 0x80, 0xb2, 0xd4, 0xb0, 0x0c, 0x2f, 0x99, 0x54, 0x9b, 0x56, 0x0b, 0x30, 0x0b, 0x2e, 0xb1, 0x00, 0xa1, 0x58, 0x9b, 0x42, 0xdb, 0x42, 0x6c, 0x09, 0x2b, 0x2e, 0xb1, 0x00, 0x8b, 0x42, 0xcb, 0x42, 0x86, 0x7f, 0x73, 0x84, 0xa7, 0x56, 0xc3, 0x08, 0x39, 0x52, 0x05, 0x50, 0x72, 0x7f, 0x63, 0x7f, 0x98, 0x2e, 0xc2, 0xc0, 0xe1, 0x6f, 0x62, 0x6f, 0xd1, 0x0a, 0x01, 0x2e, 0xcd, 0x00, 0xd5, 0x6f, 0xc4, 0x6f, 0x72, 0x6f, 0x97, 0x52, 0x9d, 0x5c, 0x98, 0x2e, 0x06, 0xcd, 0x23, 0x6f, 0x90, 0x6f, 0x99, 0x52, 0xc0, 0xb2, 0x04, 0xbd, 0x54, 0x40, 0xaf, 0xb9, 0x45, 0x40, 0xe1, 0x7f, 0x02, 0x30, 0x06, 0x2f, 0xc0, 0xb2, 0x02, 0x30, 0x03, 0x2f, 0x9b, 0x5c, 0x12, 0x30, 0x94, 0x43, 0x85, 0x43, 0x03, 0xbf, 0x6f, 0xbb, 0x80, 0xb3, 0x20, 0x2f, 0x06, 0x6f, 0x26, 0x01, 0x16, 0x6f, 0x6e, 0x03, 0x45, 0x42, 0xc0, 0x90, 0x29, 0x2e, 0xce, 0x00, 0x9b, 0x52, 0x14, 0x2f, 0x9b, 0x5c, 0x00, 0x2e, 0x93, 0x41, 0x86, 0x41, 0xe3, 0x04, 0xae, 0x07, 0x80, 0xab, 0x04, 0x2f, 0x80, 0x91, 0x0a, 0x2f, 0x86, 0x6f, 0x73, 0x0f, 0x07, 0x2f, 0x83, 0x6f, 0xc0, 0xb2, 0x04, 0x2f, 0x54, 0x42, 0x45, 0x42, 0x12, 0x30, 0x04, 0x2c, 0x11, 0x30, 0x02, 0x2c, 0x11, 0x30, 0x11, 0x30, 0x02, 0xbc, 0x0f, 0xb8, 0xd2, 0x7f, 0x00, 0xb2, 0x0a, 0x2f, 0x01, 0x2e, 0xfc, 0x00, 0x05, 0x2e, 0xc7, 0x01, 0x10, 0x1a, 0x02, 0x2f, 0x21, 0x2e, 0xc7, 0x01, 0x03, 0x2d, 0x02, 0x2c, 0x01, 0x30, 0x01, 0x30, 0xb0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0xd1, 0x6f, 0xa0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0xe2, 0x6f, 0x9f, 0x52, 0x01, 0x2e, 0xce, 0x00, 0x82, 0x40, 0x50, 0x42, 0x0c, 0x2c, 0x42, 0x42, 0x11, 0x30, 0x23, 0x2e, 0xd2, 0x00, 0x01, 0x30, 0xb0, 0x6f, 0x98, 0x2e, 0x95, 0xcf, 0xa0, 0x6f, 0x01, 0x30, 0x98, 0x2e, 0x95, 0xcf, 0x00, 0x2e, 0xfb, 0x6f, 0x00, 0x5f, 0xb8, 0x2e, 0x83, 0x86, 0x01, 0x30, 0x00, 0x30, 0x94, 0x40, 0x24, 0x18, 0x06, 0x00, 0x53, 0x0e, 0x4f, 0x02, 0xf9, 0x2f, 0xb8, 0x2e, 0xa9, 0x52, 0x00, 0x2e, 0x60, 0x40, 0x41, 0x40, 0x0d, 0xbc, 0x98, 0xbc, 0xc0, 0x2e, 0x01, 0x0a, 0x0f, 0xb8, 0xab, 0x52, 0x53, 0x3c, 0x52, 0x40, 0x40, 0x40, 0x4b, 0x00, 0x82, 0x16, 0x26, 0xb9, 0x01, 0xb8, 0x41, 0x40, 0x10, 0x08, 0x97, 0xb8, 0x01, 0x08, 0xc0, 0x2e, 0x11, 0x30, 0x01, 0x08, 0x43, 0x86, 0x25, 0x40, 0x04, 0x40, 0xd8, 0xbe, 0x2c, 0x0b, 0x22, 0x11, 0x54, 0x42, 0x03, 0x80, 0x4b, 0x0e, 0xf6, 0x2f, 0xb8, 0x2e, 0x9f, 0x50, 0x10, 0x50, 0xad, 0x52, 0x05, 0x2e, 0xd3, 0x00, 0xfb, 0x7f, 0x00, 0x2e, 0x13, 0x40, 0x93, 0x42, 0x41, 0x0e, 0xfb, 0x2f, 0x98, 0x2e, 0xa5, 0xb7, 0x98, 0x2e, 0x87, 0xcf, 0x01, 0x2e, 0xd9, 0x00, 0x00, 0xb2, 0xfb, 0x6f, 0x0b, 0x2f, 0x01, 0x2e, 0x69, 0xf7, 0xb1, 0x3f, 0x01, 0x08, 0x01, 0x30, 0xf0, 0x5f, 0x23, 0x2e, 0xd9, 0x00, 0x21, 0x2e, 0x69, 0xf7, 0x80, 0x2e, 0x7a, 0xb7, 0xf0, 0x5f, 0xb8, 0x2e, 0x01, 0x2e, 0xc0, 0xf8, 0x03, 0x2e, 0xfc, 0xf5, 0x15, 0x54, 0xaf, 0x56, 0x82, 0x08, 0x0b, 0x2e, 0x69, 0xf7, 0xcb, 0x0a, 0xb1, 0x58, 0x80, 0x90, 0xdd, 0xbe, 0x4c, 0x08, 0x5f, 0xb9, 0x59, 0x22, 0x80, 0x90, 0x07, 0x2f, 0x03, 0x34, 0xc3, 0x08, 0xf2, 0x3a, 0x0a, 0x08, 0x02, 0x35, 0xc0, 0x90, 0x4a, 0x0a, 0x48, 0x22, 0xc0, 0x2e, 0x23, 0x2e, 0xfc, 0xf5, 0x10, 0x50, 0xfb, 0x7f, 0x98, 0x2e, 0x56, 0xc7, 0x98, 0x2e, 0x49, 0xc3, 0x10, 0x30, 0xfb, 0x6f, 0xf0, 0x5f, 0x21, 0x2e, 0xcc, 0x00, 0x21, 0x2e, 0xca, 0x00, 0xb8, 0x2e, 0x03, 0x2e, 0xd3, 0x00, 0x16, 0xb8, 0x02, 0x34, 0x4a, 0x0c, 0x21, 0x2e, 0x2d, 0xf5, 0xc0, 0x2e, 0x23, 0x2e, 0xd3, 0x00, 0x03, 0xbc, 0x21, 0x2e, 0xd5, 0x00, 0x03, 0x2e, 0xd5, 0x00, 0x40, 0xb2, 0x10, 0x30, 0x21, 0x2e, 0x77, 0x00, 0x01, 0x30, 0x05, 0x2f, 0x05, 0x2e, 0xd8, 0x00, 0x80, 0x90, 0x01, 0x2f, 0x23, 0x2e, 0x6f, 0xf5, 0xc0, 0x2e, 0x21, 0x2e, 0xd9, 0x00, 0x11, 0x30, 0x81, 0x08, 0x01, 0x2e, 0x6a, 0xf7, 0x71, 0x3f, 0x23, 0xbd, 0x01, 0x08, 0x02, 0x0a, 0xc0, 0x2e, 0x21, 0x2e, 0x6a, 0xf7, 0x30, 0x25, 0x00, 0x30, 0x21, 0x2e, 0x5a, 0xf5, 0x10, 0x50, 0x21, 0x2e, 0x7b, 0x00, 0x21, 0x2e, 0x7c, 0x00, 0xfb, 0x7f, 0x98, 0x2e, 0xc3, 0xb7, 0x40, 0x30, 0x21, 0x2e, 0xd4, 0x00, 0xfb, 0x6f, 0xf0, 0x5f, 0x03, 0x25, 0x80, 0x2e, 0xaf, 0xb7, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x01, 0x2e, 0x5d, 0xf7, 0x08, 0xbc, 0x80, 0xac, 0x0e, 0xbb, 0x02, 0x2f, 0x00, 0x30, 0x41, 0x04, 0x82, 0x06, 0xc0, 0xa4, 0x00, 0x30, 0x11, 0x2f, 0x40, 0xa9, 0x03, 0x2f, 0x40, 0x91, 0x0d, 0x2f, 0x00, 0xa7, 0x0b, 0x2f, 0x80, 0xb3, 0xb3, 0x58, 0x02, 0x2f, 0x90, 0xa1, 0x26, 0x13, 0x20, 0x23, 0x80, 0x90, 0x10, 0x30, 0x01, 0x2f, 0xcc, 0x0e, 0x00, 0x2f, 0x00, 0x30, 0xb8, 0x2e, 0xb5, 0x50, 0x18, 0x08, 0x08, 0xbc, 0x88, 0xb6, 0x0d, 0x17, 0xc6, 0xbd, 0x56, 0xbc, 0xb7, 0x58, 0xda, 0xba, 0x04, 0x01, 0x1d, 0x0a, 0x10, 0x50, 0x05, 0x30, 0x32, 0x25, 0x45, 0x03, 0xfb, 0x7f, 0xf6, 0x30, 0x21, 0x25, 0x98, 0x2e, 0x37, 0xca, 0x16, 0xb5, 0x9a, 0xbc, 0x06, 0xb8, 0x80, 0xa8, 0x41, 0x0a, 0x0e, 0x2f, 0x80, 0x90, 0x02, 0x2f, 0x2d, 0x50, 0x48, 0x0f, 0x09, 0x2f, 0xbf, 0xa0, 0x04, 0x2f, 0xbf, 0x90, 0x06, 0x2f, 0xb7, 0x54, 0xca, 0x0f, 0x03, 0x2f, 0x00, 0x2e, 0x02, 0x2c, 0xb7, 0x52, 0x2d, 0x52, 0xf2, 0x33, 0x98, 0x2e, 0xd9, 0xc0, 0xfb, 0x6f, 0xf1, 0x37, 0xc0, 0x2e, 0x01, 0x08, 0xf0, 0x5f, 0xbf, 0x56, 0xb9, 0x54, 0xd0, 0x40, 0xc4, 0x40, 0x0b, 0x2e, 0xfd, 0xf3, 0xbf, 0x52, 0x90, 0x42, 0x94, 0x42, 0x95, 0x42, 0x05, 0x30, 0xc1, 0x50, 0x0f, 0x88, 0x06, 0x40, 0x04, 0x41, 0x96, 0x42, 0xc5, 0x42, 0x48, 0xbe, 0x73, 0x30, 0x0d, 0x2e, 0xd8, 0x00, 0x4f, 0xba, 0x84, 0x42, 0x03, 0x42, 0x81, 0xb3, 0x02, 0x2f, 0x2b, 0x2e, 0x6f, 0xf5, 0x06, 0x2d, 0x05, 0x2e, 0x77, 0xf7, 0xbd, 0x56, 0x93, 0x08, 0x25, 0x2e, 0x77, 0xf7, 0xbb, 0x54, 0x25, 0x2e, 0xc2, 0xf5, 0x07, 0x2e, 0xfd, 0xf3, 0x42, 0x30, 0xb4, 0x33, 0xda, 0x0a, 0x4c, 0x00, 0x27, 0x2e, 0xfd, 0xf3, 0x43, 0x40, 0xd4, 0x3f, 0xdc, 0x08, 0x43, 0x42, 0x00, 0x2e, 0x00, 0x2e, 0x43, 0x40, 0x24, 0x30, 0xdc, 0x0a, 0x43, 0x42, 0x04, 0x80, 0x03, 0x2e, 0xfd, 0xf3, 0x4a, 0x0a, 0x23, 0x2e, 0xfd, 0xf3, 0x61, 0x34, 0xc0, 0x2e, 0x01, 0x42, 0x00, 0x2e, 0x60, 0x50, 0x1a, 0x25, 0x7a, 0x86, 0xe0, 0x7f, 0xf3, 0x7f, 0x03, 0x25, 0xc3, 0x52, 0x41, 0x84, 0xdb, 0x7f, 0x33, 0x30, 0x98, 0x2e, 0x16, 0xc2, 0x1a, 0x25, 0x7d, 0x82, 0xf0, 0x6f, 0xe2, 0x6f, 0x32, 0x25, 0x16, 0x40, 0x94, 0x40, 0x26, 0x01, 0x85, 0x40, 0x8e, 0x17, 0xc4, 0x42, 0x6e, 0x03, 0x95, 0x42, 0x41, 0x0e, 0xf4, 0x2f, 0xdb, 0x6f, 0xa0, 0x5f, 0xb8, 0x2e, 0xb0, 0x51, 0xfb, 0x7f, 0x98, 0x2e, 0xe8, 0x0d, 0x5a, 0x25, 0x98, 0x2e, 0x0f, 0x0e, 0xcb, 0x58, 0x32, 0x87, 0xc4, 0x7f, 0x65, 0x89, 0x6b, 0x8d, 0xc5, 0x5a, 0x65, 0x7f, 0xe1, 0x7f, 0x83, 0x7f, 0xa6, 0x7f, 0x74, 0x7f, 0xd0, 0x7f, 0xb6, 0x7f, 0x94, 0x7f, 0x17, 0x30, 0xc7, 0x52, 0xc9, 0x54, 0x51, 0x7f, 0x00, 0x2e, 0x85, 0x6f, 0x42, 0x7f, 0x00, 0x2e, 0x51, 0x41, 0x45, 0x81, 0x42, 0x41, 0x13, 0x40, 0x3b, 0x8a, 0x00, 0x40, 0x4b, 0x04, 0xd0, 0x06, 0xc0, 0xac, 0x85, 0x7f, 0x02, 0x2f, 0x02, 0x30, 0x51, 0x04, 0xd3, 0x06, 0x41, 0x84, 0x05, 0x30, 0x5d, 0x02, 0xc9, 0x16, 0xdf, 0x08, 0xd3, 0x00, 0x8d, 0x02, 0xaf, 0xbc, 0xb1, 0xb9, 0x59, 0x0a, 0x65, 0x6f, 0x11, 0x43, 0xa1, 0xb4, 0x52, 0x41, 0x53, 0x41, 0x01, 0x43, 0x34, 0x7f, 0x65, 0x7f, 0x26, 0x31, 0xe5, 0x6f, 0xd4, 0x6f, 0x98, 0x2e, 0x37, 0xca, 0x32, 0x6f, 0x75, 0x6f, 0x83, 0x40, 0x42, 0x41, 0x23, 0x7f, 0x12, 0x7f, 0xf6, 0x30, 0x40, 0x25, 0x51, 0x25, 0x98, 0x2e, 0x37, 0xca, 0x14, 0x6f, 0x20, 0x05, 0x70, 0x6f, 0x25, 0x6f, 0x69, 0x07, 0xa2, 0x6f, 0x31, 0x6f, 0x0b, 0x30, 0x04, 0x42, 0x9b, 0x42, 0x8b, 0x42, 0x55, 0x42, 0x32, 0x7f, 0x40, 0xa9, 0xc3, 0x6f, 0x71, 0x7f, 0x02, 0x30, 0xd0, 0x40, 0xc3, 0x7f, 0x03, 0x2f, 0x40, 0x91, 0x15, 0x2f, 0x00, 0xa7, 0x13, 0x2f, 0x00, 0xa4, 0x11, 0x2f, 0x84, 0xbd, 0x98, 0x2e, 0x79, 0xca, 0x55, 0x6f, 0xb7, 0x54, 0x54, 0x41, 0x82, 0x00, 0xf3, 0x3f, 0x45, 0x41, 0xcb, 0x02, 0xf6, 0x30, 0x98, 0x2e, 0x37, 0xca, 0x35, 0x6f, 0xa4, 0x6f, 0x41, 0x43, 0x03, 0x2c, 0x00, 0x43, 0xa4, 0x6f, 0x35, 0x6f, 0x17, 0x30, 0x42, 0x6f, 0x51, 0x6f, 0x93, 0x40, 0x42, 0x82, 0x00, 0x41, 0xc3, 0x00, 0x03, 0x43, 0x51, 0x7f, 0x00, 0x2e, 0x94, 0x40, 0x41, 0x41, 0x4c, 0x02, 0xc4, 0x6f, 0xd1, 0x56, 0x63, 0x0e, 0x74, 0x6f, 0x51, 0x43, 0xa5, 0x7f, 0x8a, 0x2f, 0x09, 0x2e, 0xd8, 0x00, 0x01, 0xb3, 0x21, 0x2f, 0xcb, 0x58, 0x90, 0x6f, 0x13, 0x41, 0xb6, 0x6f, 0xe4, 0x7f, 0x00, 0x2e, 0x91, 0x41, 0x14, 0x40, 0x92, 0x41, 0x15, 0x40, 0x17, 0x2e, 0x6f, 0xf5, 0xb6, 0x7f, 0xd0, 0x7f, 0xcb, 0x7f, 0x98, 0x2e, 0x00, 0x0c, 0x07, 0x15, 0xc2, 0x6f, 0x14, 0x0b, 0x29, 0x2e, 0x6f, 0xf5, 0xc3, 0xa3, 0xc1, 0x8f, 0xe4, 0x6f, 0xd0, 0x6f, 0xe6, 0x2f, 0x14, 0x30, 0x05, 0x2e, 0x6f, 0xf5, 0x14, 0x0b, 0x29, 0x2e, 0x6f, 0xf5, 0x18, 0x2d, 0xcd, 0x56, 0x04, 0x32, 0xb5, 0x6f, 0x1c, 0x01, 0x51, 0x41, 0x52, 0x41, 0xc3, 0x40, 0xb5, 0x7f, 0xe4, 0x7f, 0x98, 0x2e, 0x1f, 0x0c, 0xe4, 0x6f, 0x21, 0x87, 0x00, 0x43, 0x04, 0x32, 0xcf, 0x54, 0x5a, 0x0e, 0xef, 0x2f, 0x15, 0x54, 0x09, 0x2e, 0x77, 0xf7, 0x22, 0x0b, 0x29, 0x2e, 0x77, 0xf7, 0xfb, 0x6f, 0x50, 0x5e, 0xb8, 0x2e, 0x10, 0x50, 0x01, 0x2e, 0xd4, 0x00, 0x00, 0xb2, 0xfb, 0x7f, 0x51, 0x2f, 0x01, 0xb2, 0x48, 0x2f, 0x02, 0xb2, 0x42, 0x2f, 0x03, 0x90, 0x56, 0x2f, 0xd7, 0x52, 0x79, 0x80, 0x42, 0x40, 0x81, 0x84, 0x00, 0x40, 0x42, 0x42, 0x98, 0x2e, 0x93, 0x0c, 0xd9, 0x54, 0xd7, 0x50, 0xa1, 0x40, 0x98, 0xbd, 0x82, 0x40, 0x3e, 0x82, 0xda, 0x0a, 0x44, 0x40, 0x8b, 0x16, 0xe3, 0x00, 0x53, 0x42, 0x00, 0x2e, 0x43, 0x40, 0x9a, 0x02, 0x52, 0x42, 0x00, 0x2e, 0x41, 0x40, 0x15, 0x54, 0x4a, 0x0e, 0x3a, 0x2f, 0x3a, 0x82, 0x00, 0x30, 0x41, 0x40, 0x21, 0x2e, 0x85, 0x0f, 0x40, 0xb2, 0x0a, 0x2f, 0x98, 0x2e, 0xb1, 0x0c, 0x98, 0x2e, 0x45, 0x0e, 0x98, 0x2e, 0x5b, 0x0e, 0xfb, 0x6f, 0xf0, 0x5f, 0x00, 0x30, 0x80, 0x2e, 0xce, 0xb7, 0xdd, 0x52, 0xd3, 0x54, 0x42, 0x42, 0x4f, 0x84, 0x73, 0x30, 0xdb, 0x52, 0x83, 0x42, 0x1b, 0x30, 0x6b, 0x42, 0x23, 0x30, 0x27, 0x2e, 0xd7, 0x00, 0x37, 0x2e, 0xd4, 0x00, 0x21, 0x2e, 0xd6, 0x00, 0x7a, 0x84, 0x17, 0x2c, 0x42, 0x42, 0x30, 0x30, 0x21, 0x2e, 0xd4, 0x00, 0x12, 0x2d, 0x21, 0x30, 0x00, 0x30, 0x23, 0x2e, 0xd4, 0x00, 0x21, 0x2e, 0x7b, 0xf7, 0x0b, 0x2d, 0x17, 0x30, 0x98, 0x2e, 0x51, 0x0c, 0xd5, 0x50, 0x0c, 0x82, 0x72, 0x30, 0x2f, 0x2e, 0xd4, 0x00, 0x25, 0x2e, 0x7b, 0xf7, 0x40, 0x42, 0x00, 0x2e, 0xfb, 0x6f, 0xf0, 0x5f, 0xb8, 0x2e, 0x70, 0x50, 0x0a, 0x25, 0x39, 0x86, 0xfb, 0x7f, 0xe1, 0x32, 0x62, 0x30, 0x98, 0x2e, 0xc2, 0xc4, 0xb5, 0x56, 0xa5, 0x6f, 0xab, 0x08, 0x91, 0x6f, 0x4b, 0x08, 0xdf, 0x56, 0xc4, 0x6f, 0x23, 0x09, 0x4d, 0xba, 0x93, 0xbc, 0x8c, 0x0b, 0xd1, 0x6f, 0x0b, 0x09, 0xcb, 0x52, 0xe1, 0x5e, 0x56, 0x42, 0xaf, 0x09, 0x4d, 0xba, 0x23, 0xbd, 0x94, 0x0a, 0xe5, 0x6f, 0x68, 0xbb, 0xeb, 0x08, 0xbd, 0xb9, 0x63, 0xbe, 0xfb, 0x6f, 0x52, 0x42, 0xe3, 0x0a, 0xc0, 0x2e, 0x43, 0x42, 0x90, 0x5f, 0xd1, 0x50, 0x03, 0x2e, 0x25, 0xf3, 0x13, 0x40, 0x00, 0x40, 0x9b, 0xbc, 0x9b, 0xb4, 0x08, 0xbd, 0xb8, 0xb9, 0x98, 0xbc, 0xda, 0x0a, 0x08, 0xb6, 0x89, 0x16, 0xc0, 0x2e, 0x19, 0x00, 0x62, 0x02, 0x10, 0x50, 0xfb, 0x7f, 0x98, 0x2e, 0x81, 0x0d, 0x01, 0x2e, 0xd4, 0x00, 0x31, 0x30, 0x08, 0x04, 0xfb, 0x6f, 0x01, 0x30, 0xf0, 0x5f, 0x23, 0x2e, 0xd6, 0x00, 0x21, 0x2e, 0xd7, 0x00, 0xb8, 0x2e, 0x01, 0x2e, 0xd7, 0x00, 0x03, 0x2e, 0xd6, 0x00, 0x48, 0x0e, 0x01, 0x2f, 0x80, 0x2e, 0x1f, 0x0e, 0xb8, 0x2e, 0xe3, 0x50, 0x21, 0x34, 0x01, 0x42, 0x82, 0x30, 0xc1, 0x32, 0x25, 0x2e, 0x62, 0xf5, 0x01, 0x00, 0x22, 0x30, 0x01, 0x40, 0x4a, 0x0a, 0x01, 0x42, 0xb8, 0x2e, 0xe3, 0x54, 0xf0, 0x3b, 0x83, 0x40, 0xd8, 0x08, 0xe5, 0x52, 0x83, 0x42, 0x00, 0x30, 0x83, 0x30, 0x50, 0x42, 0xc4, 0x32, 0x27, 0x2e, 0x64, 0xf5, 0x94, 0x00, 0x50, 0x42, 0x40, 0x42, 0xd3, 0x3f, 0x84, 0x40, 0x7d, 0x82, 0xe3, 0x08, 0x40, 0x42, 0x83, 0x42, 0xb8, 0x2e, 0xdd, 0x52, 0x00, 0x30, 0x40, 0x42, 0x7c, 0x86, 0xb9, 0x52, 0x09, 0x2e, 0x70, 0x0f, 0xbf, 0x54, 0xc4, 0x42, 0xd3, 0x86, 0x54, 0x40, 0x55, 0x40, 0x94, 0x42, 0x85, 0x42, 0x21, 0x2e, 0xd7, 0x00, 0x42, 0x40, 0x25, 0x2e, 0xfd, 0xf3, 0xc0, 0x42, 0x7e, 0x82, 0x05, 0x2e, 0x7d, 0x00, 0x80, 0xb2, 0x14, 0x2f, 0x05, 0x2e, 0x89, 0x00, 0x27, 0xbd, 0x2f, 0xb9, 0x80, 0x90, 0x02, 0x2f, 0x21, 0x2e, 0x6f, 0xf5, 0x0c, 0x2d, 0x07, 0x2e, 0x71, 0x0f, 0x14, 0x30, 0x1c, 0x09, 0x05, 0x2e, 0x77, 0xf7, 0xbd, 0x56, 0x47, 0xbe, 0x93, 0x08, 0x94, 0x0a, 0x25, 0x2e, 0x77, 0xf7, 0xe7, 0x54, 0x50, 0x42, 0x4a, 0x0e, 0xfc, 0x2f, 0xb8, 0x2e, 0x50, 0x50, 0x02, 0x30, 0x43, 0x86, 0xe5, 0x50, 0xfb, 0x7f, 0xe3, 0x7f, 0xd2, 0x7f, 0xc0, 0x7f, 0xb1, 0x7f, 0x00, 0x2e, 0x41, 0x40, 0x00, 0x40, 0x48, 0x04, 0x98, 0x2e, 0x74, 0xc0, 0x1e, 0xaa, 0xd3, 0x6f, 0x14, 0x30, 0xb1, 0x6f, 0xe3, 0x22, 0xc0, 0x6f, 0x52, 0x40, 0xe4, 0x6f, 0x4c, 0x0e, 0x12, 0x42, 0xd3, 0x7f, 0xeb, 0x2f, 0x03, 0x2e, 0x86, 0x0f, 0x40, 0x90, 0x11, 0x30, 0x03, 0x2f, 0x23, 0x2e, 0x86, 0x0f, 0x02, 0x2c, 0x00, 0x30, 0xd0, 0x6f, 0xfb, 0x6f, 0xb0, 0x5f, 0xb8, 0x2e, 0x40, 0x50, 0xf1, 0x7f, 0x0a, 0x25, 0x3c, 0x86, 0xeb, 0x7f, 0x41, 0x33, 0x22, 0x30, 0x98, 0x2e, 0xc2, 0xc4, 0xd3, 0x6f, 0xf4, 0x30, 0xdc, 0x09, 0x47, 0x58, 0xc2, 0x6f, 0x94, 0x09, 0xeb, 0x58, 0x6a, 0xbb, 0xdc, 0x08, 0xb4, 0xb9, 0xb1, 0xbd, 0xe9, 0x5a, 0x95, 0x08, 0x21, 0xbd, 0xf6, 0xbf, 0x77, 0x0b, 0x51, 0xbe, 0xf1, 0x6f, 0xeb, 0x6f, 0x52, 0x42, 0x54, 0x42, 0xc0, 0x2e, 0x43, 0x42, 0xc0, 0x5f, 0x50, 0x50, 0xf5, 0x50, 0x31, 0x30, 0x11, 0x42, 0xfb, 0x7f, 0x7b, 0x30, 0x0b, 0x42, 0x11, 0x30, 0x02, 0x80, 0x23, 0x33, 0x01, 0x42, 0x03, 0x00, 0x07, 0x2e, 0x80, 0x03, 0x05, 0x2e, 0xd3, 0x00, 0x23, 0x52, 0xe2, 0x7f, 0xd3, 0x7f, 0xc0, 0x7f, 0x98, 0x2e, 0xb6, 0x0e, 0xd1, 0x6f, 0x08, 0x0a, 0x1a, 0x25, 0x7b, 0x86, 0xd0, 0x7f, 0x01, 0x33, 0x12, 0x30, 0x98, 0x2e, 0xc2, 0xc4, 0xd1, 0x6f, 0x08, 0x0a, 0x00, 0xb2, 0x0d, 0x2f, 0xe3, 0x6f, 0x01, 0x2e, 0x80, 0x03, 0x51, 0x30, 0xc7, 0x86, 0x23, 0x2e, 0x21, 0xf2, 0x08, 0xbc, 0xc0, 0x42, 0x98, 0x2e, 0xa5, 0xb7, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0xb0, 0x6f, 0x0b, 0xb8, 0x03, 0x2e, 0x1b, 0x00, 0x08, 0x1a, 0xb0, 0x7f, 0x70, 0x30, 0x04, 0x2f, 0x21, 0x2e, 0x21, 0xf2, 0x00, 0x2e, 0x00, 0x2e, 0xd0, 0x2e, 0x98, 0x2e, 0x6d, 0xc0, 0x98, 0x2e, 0x5d, 0xc0, 0xed, 0x50, 0x98, 0x2e, 0x44, 0xcb, 0xef, 0x50, 0x98, 0x2e, 0x46, 0xc3, 0xf1, 0x50, 0x98, 0x2e, 0x53, 0xc7, 0x35, 0x50, 0x98, 0x2e, 0x64, 0xcf, 0x10, 0x30, 0x98, 0x2e, 0xdc, 0x03, 0x20, 0x26, 0xc0, 0x6f, 0x02, 0x31, 0x12, 0x42, 0xab, 0x33, 0x0b, 0x42, 0x37, 0x80, 0x01, 0x30, 0x01, 0x42, 0xf3, 0x37, 0xf7, 0x52, 0xfb, 0x50, 0x44, 0x40, 0xa2, 0x0a, 0x42, 0x42, 0x8b, 0x31, 0x09, 0x2e, 0x5e, 0xf7, 0xf9, 0x54, 0xe3, 0x08, 0x83, 0x42, 0x1b, 0x42, 0x23, 0x33, 0x4b, 0x00, 0xbc, 0x84, 0x0b, 0x40, 0x33, 0x30, 0x83, 0x42, 0x0b, 0x42, 0xe0, 0x7f, 0xd1, 0x7f, 0x98, 0x2e, 0x58, 0xb7, 0xd1, 0x6f, 0x80, 0x30, 0x40, 0x42, 0x03, 0x30, 0xe0, 0x6f, 0xf3, 0x54, 0x04, 0x30, 0x00, 0x2e, 0x00, 0x2e, 0x01, 0x89, 0x62, 0x0e, 0xfa, 0x2f, 0x43, 0x42, 0x11, 0x30, 0xfb, 0x6f, 0xc0, 0x2e, 0x01, 0x42, 0xb0, 0x5f, 0xc1, 0x4a, 0x00, 0x00, 0x6d, 0x57, 0x00, 0x00, 0x77, 0x8e, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xd3, 0xff, 0xff, 0xff, 0xe5, 0xff, 0xff, 0xff, 0xee, 0xe1, 0xff, 0xff, 0x7c, 0x13, 0x00, 0x00, 0x46, 0xe6, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1, 0x80, 0x2e, 0x00, 0xc1 }; #endif /* BMI270_BMI270_CONFIG_FILE_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi270/bmi270_config_file.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
44,429
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI160_EMUL_BMI160_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI160_EMUL_BMI160_H_ #include <zephyr/drivers/emul.h> #include <zephyr/drivers/i2c.h> #ifdef __cplusplus extern "C" { #endif /** * @brief Check if I2C messages are touching a given register (R or W) * * @param[in] msgs The I2C messages in question * @param[in] num_msgs The number of messages in the @p msgs array * @param[in] reg The register to check for * @return True if @p reg is either read or written to * @return False otherwise */ __maybe_unused static bool emul_bmi160_i2c_is_touching_reg(struct i2c_msg *msgs, int num_msgs, uint32_t reg) { if (num_msgs != 2) { return false; } if (msgs[0].len != 1) { return false; } if (i2c_is_read_op(msgs)) { return false; } uint8_t start_reg = msgs[0].buf[0]; uint8_t read_len = msgs[1].len; return (start_reg <= reg) && (reg < start_reg + read_len); } /** * @brief Check if I2C messages are reading a specific register. * * @param[in] msgs The I2C messages in question * @param[in] num_msgs The number of messages in the @p msgs array * @param[in] reg The register to check for * @return True if @p reg is read * @return False otherwise */ __maybe_unused static bool emul_bmi160_i2c_is_reading_reg(struct i2c_msg *msgs, int num_msgs, uint32_t reg) { if (!emul_bmi160_i2c_is_touching_reg(msgs, num_msgs, reg)) { return false; } return i2c_is_read_op(&msgs[1]); } /** * @brief Check if I2C messages are writing to a specific register. * * @param[in] msgs The I2C messages in question * @param[in] num_msgs The number of messages in the @p msgs array * @param[in] reg The register to check for * @return True if @p reg is written * @return False otherwise */ __maybe_unused static bool emul_bmi160_i2c_is_writing_reg(struct i2c_msg *msgs, int num_msgs, uint32_t reg) { if (!emul_bmi160_i2c_is_touching_reg(msgs, num_msgs, reg)) { return false; } return !i2c_is_read_op(&msgs[1]); } /** * @brief Get the internal register value of the emulator * * @param[in] target The emulator in question * @param[in] reg_number The register number to start reading at * @param[out] out Buffer to store the values into * @param[in] count The number of registers to read * @return 0 on success * @return < 0 on error */ int emul_bmi160_get_reg_value(const struct emul *target, int reg_number, uint8_t *out, size_t count); #ifdef __cplusplus } #endif #endif /* ZEPHYR_DRIVERS_SENSOR_BMI160_EMUL_BMI160_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/emul_bmi160.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
750
```unknown # Bosch BMI160 inertial measurement configuration options menuconfig BMI160 bool "Bosch BMI160 inertial measurement unit" default y depends on DT_HAS_BOSCH_BMI160_ENABLED select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI160),i2c) select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI160),spi) help Enable Bosch BMI160 inertial measurement unit that provides acceleration and angular rate measurements. if BMI160 choice prompt "Trigger mode" default BMI160_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config BMI160_TRIGGER_NONE bool "No trigger" config BMI160_TRIGGER_GLOBAL_THREAD bool "Use global thread" select BMI160_TRIGGER config BMI160_TRIGGER_OWN_THREAD bool "Use own thread" select BMI160_TRIGGER endchoice config BMI160_TRIGGER bool config BMI160_THREAD_PRIORITY int "Own thread priority" depends on BMI160_TRIGGER_OWN_THREAD default 10 help The priority of the thread used for handling interrupts. config BMI160_THREAD_STACK_SIZE int "Own thread stack size" depends on BMI160_TRIGGER_OWN_THREAD default 1024 help The thread stack size. choice prompt "Accelerometer power mode" default BMI160_ACCEL_PMU_RUNTIME config BMI160_ACCEL_PMU_RUNTIME bool "Set at runtime." config BMI160_ACCEL_PMU_SUSPEND bool "suspended/not used" config BMI160_ACCEL_PMU_NORMAL bool "normal" config BMI160_ACCEL_PMU_LOW_POWER bool "low power" endchoice choice prompt "Accelerometer range setting" depends on BMI160_ACCEL_PMU_RUNTIME || BMI160_ACCEL_PMU_NORMAL || BMI160_ACCEL_PMU_LOW_POWER default BMI160_ACCEL_RANGE_RUNTIME config BMI160_ACCEL_RANGE_RUNTIME bool "Set at runtime." config BMI160_ACCEL_RANGE_2G bool "2G" config BMI160_ACCEL_RANGE_4G bool "4G" config BMI160_ACCEL_RANGE_8G bool "8G" config BMI160_ACCEL_RANGE_16G bool "16G" endchoice choice prompt "Accelerometer sampling frequency." depends on BMI160_ACCEL_PMU_RUNTIME || BMI160_ACCEL_PMU_NORMAL || BMI160_ACCEL_PMU_LOW_POWER default BMI160_ACCEL_ODR_RUNTIME config BMI160_ACCEL_ODR_RUNTIME bool "Set at runtime." config BMI160_ACCEL_ODR_25_32 depends on BMI160_ACCEL_PMU_LOW_POWER bool "0.78 Hz" config BMI160_ACCEL_ODR_25_16 depends on BMI160_ACCEL_PMU_LOW_POWER bool "1.56 Hz" config BMI160_ACCEL_ODR_25_8 depends on BMI160_ACCEL_PMU_LOW_POWER bool "3.125 Hz" config BMI160_ACCEL_ODR_25_4 depends on BMI160_ACCEL_PMU_LOW_POWER bool "6.25 Hz" config BMI160_ACCEL_ODR_25_2 bool "12.5 Hz" config BMI160_ACCEL_ODR_25 bool "25 Hz" config BMI160_ACCEL_ODR_50 bool "50 Hz" config BMI160_ACCEL_ODR_100 bool "100 Hz" config BMI160_ACCEL_ODR_200 bool "200 Hz" config BMI160_ACCEL_ODR_400 bool "400 Hz" config BMI160_ACCEL_ODR_800 bool "800 Hz" config BMI160_ACCEL_ODR_1600 bool "1600 Hz" endchoice choice prompt "Gyroscope power mode" default BMI160_GYRO_PMU_RUNTIME config BMI160_GYRO_PMU_RUNTIME bool "Set at runtime." config BMI160_GYRO_PMU_SUSPEND bool "suspended/not used" config BMI160_GYRO_PMU_NORMAL bool "normal" config BMI160_GYRO_PMU_FAST_STARTUP bool "fast start-up" endchoice choice prompt "Gyroscope range setting." depends on BMI160_GYRO_PMU_RUNTIME || BMI160_GYRO_PMU_NORMAL || BMI160_GYRO_PMU_FAST_STARTUP default BMI160_GYRO_RANGE_RUNTIME config BMI160_GYRO_RANGE_RUNTIME bool "Set at runtime." config BMI160_GYRO_RANGE_2000DPS bool "2000 DPS" config BMI160_GYRO_RANGE_1000DPS bool "1000 DPS" config BMI160_GYRO_RANGE_500DPS bool "500 DPS" config BMI160_GYRO_RANGE_250DPS bool "250 DPS" config BMI160_GYRO_RANGE_125DPS bool "125 DPS" endchoice choice prompt "Gyroscope sampling frequency." depends on BMI160_GYRO_PMU_RUNTIME || BMI160_GYRO_PMU_NORMAL || BMI160_GYRO_PMU_FAST_STARTUP default BMI160_GYRO_ODR_RUNTIME config BMI160_GYRO_ODR_RUNTIME bool "Set at runtime." config BMI160_GYRO_ODR_25 bool "25 Hz" config BMI160_GYRO_ODR_50 bool "50 Hz" config BMI160_GYRO_ODR_100 bool "100 Hz" config BMI160_GYRO_ODR_200 bool "200 Hz" config BMI160_GYRO_ODR_400 bool "400 Hz" config BMI160_GYRO_ODR_800 bool "800 Hz" config BMI160_GYRO_ODR_1600 bool "1600 Hz" config BMI160_GYRO_ODR_3200 bool "3200 Hz" endchoice config EMUL_BMI160 bool "Emulate a Bosch BMI160 accelerometer" default y depends on EMUL depends on BMI160 help This is an emulator for the Bosch BMI160 accelerometer. It provides readings which follow a simple sequence, thus allowing test code to check that things are working as expected. It supports both I2C and SPI which is why it is not in one of the i2c/ or spi/ directories. endif # BMI160 ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,330
```objective-c /* Bosch BMI160 inertial measurement unit header * * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ #define DT_DRV_COMPAT bosch_bmi160 #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/spi.h> #include <zephyr/kernel.h> #include <zephyr/sys/util.h> #ifdef __cplusplus extern "C" { #endif /* registers */ #define BMI160_REG_CHIPID 0x00 #define BMI160_REG_ERR 0x02 #define BMI160_REG_PMU_STATUS 0x03 #define BMI160_REG_DATA_MAG_X 0x04 #define BMI160_REG_DATA_MAG_Y 0x06 #define BMI160_REG_DATA_MAG_Z 0x08 #define BMI160_REG_DATA_RHALL 0x0A #define BMI160_REG_DATA_GYR_X 0x0C #define BMI160_REG_DATA_GYR_Y 0x0E #define BMI160_REG_DATA_GYR_Z 0x10 #define BMI160_REG_DATA_ACC_X 0x12 #define BMI160_REG_DATA_ACC_Y 0x14 #define BMI160_REG_DATA_ACC_Z 0x16 #define BMI160_REG_SENSORTIME0 0x18 #define BMI160_REG_SENSORTIME1 0x19 #define BMI160_REG_SENSORTIME2 0x1A #define BMI160_REG_STATUS 0x1B #define BMI160_REG_INT_STATUS0 0x1C #define BMI160_REG_INT_STATUS1 0x1D #define BMI160_REG_INT_STATUS2 0x1E #define BMI160_REG_INT_STATUS3 0x1F #define BMI160_REG_TEMPERATURE0 0x20 #define BMI160_REG_TEMPERATURE1 0x21 #define BMI160_REG_FIFO_LENGTH0 0x22 #define BMI160_REG_FIFO_LENGTH1 0x23 #define BMI160_REG_FIFO_DATA 0x24 #define BMI160_REG_ACC_CONF 0x40 #define BMI160_REG_ACC_RANGE 0x41 #define BMI160_REG_GYR_CONF 0x42 #define BMI160_REG_GYR_RANGE 0x43 #define BMI160_REG_MAG_CONF 0x44 #define BMI160_REG_FIFO_DOWNS 0x45 #define BMI160_REG_FIFO_CONFIG0 0x46 #define BMI160_REG_FIFO_CONFIG1 0x47 #define BMI160_REG_MAG_IF0 0x4B #define BMI160_REG_MAG_IF1 0x4C #define BMI160_REG_MAG_IF2 0x4D #define BMI160_REG_MAG_IF3 0x4E #define BMI160_REG_MAG_IF4 0x4F #define BMI160_REG_INT_EN0 0x50 #define BMI160_REG_INT_EN1 0x51 #define BMI160_REG_INT_EN2 0x52 #define BMI160_REG_INT_OUT_CTRL 0x53 #define BMI160_REG_INT_LATCH 0x54 #define BMI160_REG_INT_MAP0 0x55 #define BMI160_REG_INT_MAP1 0x56 #define BMI160_REG_INT_MAP2 0x57 #define BMI160_REG_INT_DATA0 0x58 #define BMI160_REG_INT_DATA1 0x59 #define BMI160_REG_INT_LOWHIGH0 0x5A #define BMI160_REG_INT_LOWHIGH1 0x5B #define BMI160_REG_INT_LOWHIGH2 0x5C #define BMI160_REG_INT_LOWHIGH3 0x5D #define BMI160_REG_INT_LOWHIGH4 0x5E #define BMI160_REG_INT_MOTION0 0x5F #define BMI160_REG_INT_MOTION1 0x60 #define BMI160_REG_INT_MOTION2 0x61 #define BMI160_REG_INT_MOTION3 0x62 #define BMI160_REG_INT_TAP0 0x63 #define BMI160_REG_INT_TAP1 0x64 #define BMI160_REG_INT_ORIENT0 0x65 #define BMI160_REG_INT_ORIENT1 0x66 #define BMI160_REG_INT_FLAT0 0x67 #define BMI160_REG_INT_FLAT1 0x68 #define BMI160_REG_FOC_CONF 0x69 #define BMI160_REG_CONF 0x6A #define BMI160_REG_IF_CONF 0x6B #define BMI160_REG_PMU_TRIGGER 0x6C #define BMI160_REG_SELF_TEST 0x6D #define BMI160_REG_NV_CONF 0x70 #define BMI160_REG_OFFSET_ACC_X 0x71 #define BMI160_REG_OFFSET_ACC_Y 0x72 #define BMI160_REG_OFFSET_ACC_Z 0x73 #define BMI160_REG_OFFSET_GYR_X 0x74 #define BMI160_REG_OFFSET_GYR_Y 0x75 #define BMI160_REG_OFFSET_GYR_Z 0x76 #define BMI160_REG_OFFSET_EN 0x77 #define BMI160_REG_STEP_CNT0 0x78 #define BMI160_REG_STEP_CNT1 0x79 #define BMI160_REG_STEP_CONF0 0x7A #define BMI160_REG_STEP_CONF1 0x7B #define BMI160_REG_CMD 0x7E /* This is not a real register; reading it activates SPI on the BMI160 */ #define BMI160_SPI_START 0x7F #define BMI160_REG_COUNT 0x80 /* Indicates a read operation; bit 7 is clear on write s*/ #define BMI160_REG_READ BIT(7) #define BMI160_REG_MASK 0x7f /* bitfields */ /* BMI160_REG_ERR */ #define BMI160_ERR_FATAL BIT(0) #define BMI160_ERR_CODE BIT(1) #define BMI160_ERR_CODE_MASK (0xf << 1) #define BMI160_ERR_I2C_FAIL BIT(5) #define BMI160_ERR_DROP_CMD BIT(6) #define BMI160_ERR_MAG_DRDY BIT(7) /* BMI160_REG_PMU_STATUS */ #define BMI160_PMU_STATUS_MAG_MASK 0x3 #define BMI160_PMU_STATUS_MAG_POS 0 #define BMI160_PMU_STATUS_GYR_POS 2 #define BMI160_PMU_STATUS_GYR_MASK (0x3 << 2) #define BMI160_PMU_STATUS_ACC_POS 4 #define BMI160_PMU_STATUS_ACC_MASK (0x3 << 4) #define BMI160_PMU_SUSPEND 0 #define BMI160_PMU_NORMAL 1 #define BMI160_PMU_LOW_POWER 2 #define BMI160_PMU_FAST_START 3 /* BMI160_REG_STATUS */ #define BMI160_STATUS_GYR_SELFTEST BIT(1) #define BMI160_STATUS_MAG_MAN_OP BIT(2) #define BMI160_STATUS_FOC_RDY BIT(3) #define BMI160_STATUS_NVM_RDY BIT(4) #define BMI160_STATUS_MAG_DRDY BIT(5) #define BMI160_STATUS_GYR_DRDY BIT(6) #define BMI160_STATUS_ACC_DRDY BIT(7) /* BMI160_REG_INT_STATUS0 */ #define BMI160_INT_STATUS0_STEP BIT(0) #define BMI160_INT_STATUS0_SIGMOT BIT(1) #define BMI160_INT_STATUS0_ANYM BIT(2) #define BMI160_INT_STATUS0_PMU_TRIG BIT(3) #define BMI160_INT_STATUS0_D_TAP BIT(4) #define BMI160_INT_STATUS0_S_TAP BIT(5) #define BMI160_INT_STATUS0_ORIENT BIT(6) #define BMI160_INT_STATUS0_FLAT BIT(7) /* BMI160_REG_INT_STATUS1 */ #define BMI160_INT_STATUS1_HIGHG BIT(2) #define BMI160_INT_STATUS1_LOWG BIT(3) #define BMI160_INT_STATUS1_DRDY BIT(4) #define BMI160_INT_STATUS1_FFULL BIT(5) #define BMI160_INT_STATUS1_FWM BIT(6) #define BMI160_INT_STATUS1_NOMO BIT(7) /* BMI160_REG_INT_STATUS2 */ #define BMI160_INT_STATUS2_ANYM_FIRST_X BIT(0) #define BMI160_INT_STATUS2_ANYM_FIRST_Y BIT(1) #define BMI160_INT_STATUS2_ANYM_FIRST_Z BIT(2) #define BMI160_INT_STATUS2_ANYM_SIGN BIT(3) #define BMI160_INT_STATUS2_TAP_FIRST_X BIT(4) #define BMI160_INT_STATUS2_TAP_FIRST_Y BIT(5) #define BMI160_INT_STATUS2_TAP_FIRST_Z BIT(6) #define BMI160_INT_STATUS2_TAP_SIGN BIT(7) /* BMI160_REG_INT_STATUS3 */ #define BMI160_INT_STATUS3_HIGH_FIRST_X BIT(0) #define BMI160_INT_STATUS3_HIGH_FIRST_Y BIT(1) #define BMI160_INT_STATUS3_HIGH_FIRST_Z BIT(2) #define BMI160_INT_STATUS3_HIGH_SIGN BIT(3) #define BMI160_INT_STATUS3_ORIENT_1_0 BIT(4) #define BMI160_INT_STATUS3_ORIENT_2 BIT(6) #define BMI160_INT_STATUS3_FLAT BIT(7) /* BMI160_REG_ACC_CONF */ #define BMI160_ACC_CONF_ODR_POS 0 #define BMI160_ACC_CONF_ODR_MASK 0xF #define BMI160_ACC_CONF_BWP_POS 4 #define BMI160_ACC_CONF_BWP_MASK (0x7 << 4) #define BMI160_ACC_CONF_US_POS 7 #define BMI160_ACC_CONF_US_MASK BIT(7) /* BMI160_REG_GYRO_CONF */ #define BMI160_GYR_CONF_ODR_POS 0 #define BMI160_GYR_CONF_ODR_MASK 0xF #define BMI160_GYR_CONF_BWP_POS 4 #define BMI160_GYR_CONF_BWP_MASK (0x3 << 4) /* BMI160_REG_OFFSET_EN */ #define BMI160_GYR_OFS_EN_POS 7 #define BMI160_ACC_OFS_EN_POS 6 #define BMI160_GYR_MSB_OFS_Z_POS 4 #define BMI160_GYR_MSB_OFS_Z_MASK (BIT(4) | BIT(5)) #define BMI160_GYR_MSB_OFS_Y_POS 2 #define BMI160_GYR_MSB_OFS_Y_MASK (BIT(2) | BIT(3)) #define BMI160_GYR_MSB_OFS_X_POS 0 #define BMI160_GYR_MSB_OFS_X_MASK (BIT(0) | BIT(1)) /* BMI160_REG_CMD */ #define BMI160_CMD_START_FOC 3 #define BMI160_CMD_PMU_ACC 0x10 #define BMI160_CMD_PMU_GYR 0x14 #define BMI160_CMD_PMU_MAG 0x18 #define BMI160_CMD_SOFT_RESET 0xB6 #define BMI160_CMD_PMU_BIT 0x10 #define BMI160_CMD_PMU_MASK 0x0c #define BMI160_CMD_PMU_SHIFT 2 #define BMI160_CMD_PMU_VAL_MASK 0x3 /* BMI160_REG_FOC_CONF */ #define BMI160_FOC_ACC_Z_POS 0 #define BMI160_FOC_ACC_Y_POS 2 #define BMI160_FOC_ACC_X_POS 4 #define BMI160_FOC_GYR_EN_POS 6 /* BMI160_REG_INT_MOTION0 */ #define BMI160_ANYM_DUR_POS 0 #define BMI160_ANYM_DUR_MASK 0x3 /* BMI160_REG_INT_EN0 */ #define BMI160_INT_FLAT_EN BIT(7) #define BMI160_INT_ORIENT_EN BIT(6) #define BMI160_INT_S_TAP_EN BIT(5) #define BMI160_INT_D_TAP_EN BIT(4) #define BMI160_INT_ANYM_Z_EN BIT(2) #define BMI160_INT_ANYM_Y_EN BIT(1) #define BMI160_INT_ANYM_X_EN BIT(0) #define BMI160_INT_ANYM_MASK (BIT(0) | BIT(1) | BIT(2)) /* BMI160_REG_INT_EN1 */ #define BMI160_INT_FWM_EN BIT(6) #define BMI160_INT_FFULL_EN BIT(5) #define BMI160_INT_DRDY_EN BIT(4) #define BMI160_INT_LOWG_EN BIT(3) #define BMI160_INT_HIGHG_Z_EN BIT(2) #define BMI160_INT_HIGHG_Y_EN BIT(1) #define BMI160_INT_HIGHG_X_EN BIT(0) #define BMI160_INT_HIGHG_MASK (BIT(0) | BIT(1) | BIT(2)) /* BMI160_REG_INT_EN2 */ #define BMI160_INT_STEP_DET_EN BIT(3) #define BMI160_INT_STEP_NOMO_Z_EN BIT(2) #define BMI160_INT_STEP_NOMO_Y_EN BIT(1) #define BMI160_INT_STEP_NOMO_X_EN BIT(0) #define BMI160_INT_STEP_NOMO_MASK (BIT(0) | BIT(1) | BIT(2)) /* BMI160_REG_INT_OUT_CTRL */ #define BMI160_INT2_OUT_EN BIT(7) #define BMI160_INT2_OD BIT(6) #define BMI160_INT2_LVL BIT(5) #define BMI160_INT2_EDGE_CTRL BIT(4) #define BMI160_INT1_OUT_EN BIT(3) #define BMI160_INT1_OD BIT(2) #define BMI160_INT1_LVL BIT(1) #define BMI160_INT1_EDGE_CTRL BIT(0) /* other */ #define BMI160_CHIP_ID 0xD1 #define BMI160_TEMP_OFFSET 23 /* allowed ODR values */ enum bmi160_odr { BMI160_ODR_25_32 = 1, BMI160_ODR_25_16, BMI160_ODR_25_8, BMI160_ODR_25_4, BMI160_ODR_25_2, BMI160_ODR_25, BMI160_ODR_50, BMI160_ODR_100, BMI160_ODR_200, BMI160_ODR_400, BMI160_ODR_800, BMI160_ODR_1600, BMI160_ODR_3200, }; /* Range values for accelerometer */ #define BMI160_ACC_RANGE_2G 0x3 #define BMI160_ACC_RANGE_4G 0x5 #define BMI160_ACC_RANGE_8G 0x8 #define BMI160_ACC_RANGE_16G 0xC /* Range values for gyro */ #define BMI160_GYR_RANGE_2000DPS 0 #define BMI160_GYR_RANGE_1000DPS 1 #define BMI160_GYR_RANGE_500DPS 2 #define BMI160_GYR_RANGE_250DPS 3 #define BMI160_GYR_RANGE_125DPS 4 #define BMI160_ACC_SCALE_NUMERATOR(range_g) (2 * (range_g) * SENSOR_G) #define BMI160_ACC_SCALE_DENOMINATOR UINT16_MAX #define BMI160_GYR_SCALE_NUMERATOR(range_dps) (2 * (range_dps) * SENSOR_PI) #define BMI160_GYR_SCALE_DENOMINATOR (UINT32_C(180) * UINT16_MAX) /* default settings, based on menuconfig options */ /* make sure at least one sensor is active */ #if defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) &&\ defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) #error "Error: You need to activate at least one sensor!" #endif #if defined(CONFIG_BMI160_ACCEL_PMU_RUNTIME) ||\ defined(CONFIG_BMI160_ACCEL_PMU_NORMAL) # define BMI160_DEFAULT_PMU_ACC BMI160_PMU_NORMAL #elif defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) # define BMI160_DEFAULT_PMU_ACC BMI160_PMU_SUSPEND #else # define BMI160_DEFAULT_PMU_ACC BMI160_PMU_LOW_POWER #endif #if defined(CONFIG_BMI160_GYRO_PMU_RUNTIME) ||\ defined(CONFIG_BMI160_GYRO_PMU_NORMAL) # define BMI160_DEFAULT_PMU_GYR BMI160_PMU_NORMAL #elif defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) # define BMI160_DEFAULT_PMU_GYR BMI160_PMU_SUSPEND #else # define BMI160_DEFAULT_PMU_GYR BMI160_PMU_FAST_START #endif #if defined(CONFIG_BMI160_ACCEL_RANGE_RUNTIME) ||\ defined(CONFIG_BMI160_ACCEL_RANGE_2G) # define BMI160_DEFAULT_RANGE_ACC BMI160_ACC_RANGE_2G #elif defined(CONFIG_BMI160_ACCEL_RANGE_4G) # define BMI160_DEFAULT_RANGE_ACC BMI160_ACC_RANGE_4G #elif defined(CONFIG_BMI160_ACCEL_RANGE_8G) # define BMI160_DEFAULT_RANGE_ACC BMI160_ACC_RANGE_8G #else # define BMI160_DEFAULT_RANGE_ACC BMI160_ACC_RANGE_16G #endif #if defined(CONFIG_BMI160_GYRO_RANGE_RUNTIME) ||\ defined(CONFIG_BMI160_GYRO_RANGE_2000DPS) # define BMI160_DEFAULT_RANGE_GYR BMI160_GYR_RANGE_2000DPS #elif defined(CONFIG_BMI160_GYRO_RANGE_1000DPS) # define BMI160_DEFAULT_RANGE_GYR BMI160_GYR_RANGE_1000DPS #elif defined(CONFIG_BMI160_GYRO_RANGE_500DPS) # define BMI160_DEFAULT_RANGE_GYR BMI160_GYR_RANGE_500DPS #elif defined(CONFIG_BMI160_GYRO_RANGE_250DPS) # define BMI160_DEFAULT_RANGE_GYR BMI160_GYR_RANGE_250DPS #else # define BMI160_DEFAULT_RANGE_GYR BMI160_GYR_RANGE_125DPS #endif #if defined(CONFIG_BMI160_ACCEL_ODR_RUNTIME) ||\ defined(CONFIG_BMI160_ACCEL_ODR_100) # define BMI160_DEFAULT_ODR_ACC 8 #elif defined(CONFIG_BMI160_ACCEL_ODR_25_32) # define BMI160_DEFAULT_ODR_ACC 1 #elif defined(CONFIG_BMI160_ACCEL_ODR_25_16) # define BMI160_DEFAULT_ODR_ACC 2 #elif defined(CONFIG_BMI160_ACCEL_ODR_25_8) # define BMI160_DEFAULT_ODR_ACC 3 #elif defined(CONFIG_BMI160_ACCEL_ODR_25_4) # define BMI160_DEFAULT_ODR_ACC 4 #elif defined(CONFIG_BMI160_ACCEL_ODR_25_2) # define BMI160_DEFAULT_ODR_ACC 5 #elif defined(CONFIG_BMI160_ACCEL_ODR_25) # define BMI160_DEFAULT_ODR_ACC 6 #elif defined(CONFIG_BMI160_ACCEL_ODR_50) # define BMI160_DEFAULT_ODR_ACC 7 #elif defined(CONFIG_BMI160_ACCEL_ODR_200) # define BMI160_DEFAULT_ODR_ACC 9 #elif defined(CONFIG_BMI160_ACCEL_ODR_400) # define BMI160_DEFAULT_ODR_ACC 10 #elif defined(CONFIG_BMI160_ACCEL_ODR_800) # define BMI160_DEFAULT_ODR_ACC 11 #else # define BMI160_DEFAULT_ODR_ACC 12 #endif #if defined(CONFIG_BMI160_GYRO_ODR_RUNTIME) ||\ defined(CONFIG_BMI160_GYRO_ODR_100) # define BMI160_DEFAULT_ODR_GYR 8 #elif defined(CONFIG_BMI160_GYRO_ODR_25) # define BMI160_DEFAULT_ODR_GYR 6 #elif defined(CONFIG_BMI160_GYRO_ODR_50) # define BMI160_DEFAULT_ODR_GYR 7 #elif defined(CONFIG_BMI160_GYRO_ODR_200) # define BMI160_DEFAULT_ODR_GYR 9 #elif defined(CONFIG_BMI160_GYRO_ODR_400) # define BMI160_DEFAULT_ODR_GYR 10 #elif defined(CONFIG_BMI160_GYRO_ODR_800) # define BMI160_DEFAULT_ODR_GYR 11 #elif defined(CONFIG_BMI160_GYRO_ODR_1600) # define BMI160_DEFAULT_ODR_GYR 12 #else # define BMI160_DEFAULT_ODR_GYR 13 #endif /* end of default settings */ struct bmi160_range { uint16_t range; uint8_t reg_val; }; #define BMI160_BUS_SPI DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) #define BMI160_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) union bmi160_bus { #if BMI160_BUS_SPI struct spi_dt_spec spi; #endif #if BMI160_BUS_I2C struct i2c_dt_spec i2c; #endif }; typedef bool (*bmi160_bus_ready_fn)(const struct device *dev); typedef int (*bmi160_reg_read_fn)(const struct device *dev, uint8_t reg_addr, void *data, uint8_t len); typedef int (*bmi160_reg_write_fn)(const struct device *dev, uint8_t reg_addr, void *data, uint8_t len); struct bmi160_bus_io { bmi160_bus_ready_fn ready; bmi160_reg_read_fn read; bmi160_reg_write_fn write; }; struct bmi160_cfg { union bmi160_bus bus; const struct bmi160_bus_io *bus_io; #if defined(CONFIG_BMI160_TRIGGER) struct gpio_dt_spec interrupt; #endif }; union bmi160_pmu_status { uint8_t raw; struct { uint8_t mag : 2; uint8_t gyr : 2; uint8_t acc : 2; uint8_t res : 2; }; }; #define BMI160_AXES 3 #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) && \ !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) # define BMI160_SAMPLE_SIZE (2 * BMI160_AXES * sizeof(uint16_t)) #else # define BMI160_SAMPLE_SIZE (BMI160_AXES * sizeof(uint16_t)) #endif #if defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) # define BMI160_SAMPLE_BURST_READ_ADDR BMI160_REG_DATA_ACC_X # define BMI160_DATA_READY_BIT_MASK (1 << 7) #else # define BMI160_SAMPLE_BURST_READ_ADDR BMI160_REG_DATA_GYR_X # define BMI160_DATA_READY_BIT_MASK (1 << 6) #endif #define BMI160_BUF_SIZE (BMI160_SAMPLE_SIZE) /* Each sample has X, Y and Z */ union bmi160_sample { uint8_t raw[BMI160_BUF_SIZE]; uint16_t temperature; struct { #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) uint16_t gyr[BMI160_AXES]; #endif #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) uint16_t acc[BMI160_AXES]; #endif }; }; struct bmi160_scale { /* numerator / denominator => micro m/s^2/lsb */ int32_t acc_numerator; /* numerator / denominator => micro radians/s/lsb */ int64_t gyr_numerator; }; struct bmi160_data { const struct device *bus; #if defined(CONFIG_BMI160_TRIGGER) const struct device *dev; const struct device *gpio; struct gpio_callback gpio_cb; #endif union bmi160_pmu_status pmu_sts; union bmi160_sample sample; struct bmi160_scale scale; #ifdef CONFIG_BMI160_TRIGGER_OWN_THREAD struct k_sem sem; #endif #ifdef CONFIG_BMI160_TRIGGER_GLOBAL_THREAD struct k_work work; #endif #ifdef CONFIG_BMI160_TRIGGER #if !defined(CONFIG_BMI160_ACCEL_PMU_SUSPEND) sensor_trigger_handler_t handler_drdy_acc; const struct sensor_trigger *trig_drdy_acc; sensor_trigger_handler_t handler_anymotion; const struct sensor_trigger *trig_anymotion; #endif #if !defined(CONFIG_BMI160_GYRO_PMU_SUSPEND) sensor_trigger_handler_t handler_drdy_gyr; const struct sensor_trigger *trig_drdy_gyr; #endif #endif /* CONFIG_BMI160_TRIGGER */ }; int bmi160_read(const struct device *dev, uint8_t reg_addr, void *data, uint8_t len); int bmi160_byte_read(const struct device *dev, uint8_t reg_addr, uint8_t *byte); int bmi160_byte_write(const struct device *dev, uint8_t reg_addr, uint8_t byte); int bmi160_word_write(const struct device *dev, uint8_t reg_addr, uint16_t word); int bmi160_reg_field_update(const struct device *dev, uint8_t reg_addr, uint8_t pos, uint8_t mask, uint8_t val); static inline int bmi160_reg_update(const struct device *dev, uint8_t reg_addr, uint8_t mask, uint8_t val) { return bmi160_reg_field_update(dev, reg_addr, 0, mask, val); } int bmi160_trigger_mode_init(const struct device *dev); int bmi160_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bmi160_acc_slope_config(const struct device *dev, enum sensor_attribute attr, const struct sensor_value *val); int32_t bmi160_acc_reg_val_to_range(uint8_t reg_val); int32_t bmi160_gyr_reg_val_to_range(uint8_t reg_val); #ifdef __cplusplus } #endif #endif /* ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi160/bmi160.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
5,606
```c /* * */ /* * Bus-specific functionality for BMP388s accessed via SPI. */ #include <zephyr/logging/log.h> #include "bmp388.h" #if BMP388_BUS_SPI LOG_MODULE_DECLARE(BMP388, CONFIG_SENSOR_LOG_LEVEL); static int bmp388_bus_check_spi(const union bmp388_bus *bus) { return spi_is_ready_dt(&bus->spi) ? 0 : -ENODEV; } static int bmp388_reg_read_spi(const union bmp388_bus *bus, uint8_t start, uint8_t *buf, int size) { uint8_t addr; const struct spi_buf tx_buf = { .buf = &addr, .len = 1 }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; struct spi_buf rx_buf[2]; const struct spi_buf_set rx = { .buffers = rx_buf, .count = ARRAY_SIZE(rx_buf) }; int i; rx_buf[0].buf = NULL; rx_buf[0].len = 1; rx_buf[1].len = 1; for (i = 0; i < size; i++) { int ret; addr = (start + i) | 0x80; rx_buf[1].buf = &buf[i]; ret = spi_transceive_dt(&bus->spi, &tx, &rx); if (ret) { LOG_DBG("spi_transceive FAIL %d\n", ret); return ret; } } return 0; } static int bmp388_reg_write_spi(const union bmp388_bus *bus, uint8_t reg, uint8_t val) { uint8_t cmd[] = { reg & 0x7F, val }; const struct spi_buf tx_buf = { .buf = cmd, .len = sizeof(cmd) }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; int ret; ret = spi_write_dt(&bus->spi, &tx); if (ret) { LOG_DBG("spi_write FAIL %d\n", ret); return ret; } return 0; } const struct bmp388_bus_io bmp388_bus_io_spi = { .check = bmp388_bus_check_spi, .read = bmp388_reg_read_spi, .write = bmp388_reg_write_spi, }; #endif /* BMP388_BUS_SPI */ ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/bmp388_spi.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
525
```c /* * */ /* * Bus-specific functionality for BMP388s accessed via I2C. */ #include "bmp388.h" #if BMP388_BUS_I2C static int bmp388_bus_check_i2c(const union bmp388_bus *bus) { return i2c_is_ready_dt(&bus->i2c) ? 0 : -ENODEV; } static int bmp388_reg_read_i2c(const union bmp388_bus *bus, uint8_t start, uint8_t *buf, int size) { return i2c_burst_read_dt(&bus->i2c, start, buf, size); } static int bmp388_reg_write_i2c(const union bmp388_bus *bus, uint8_t reg, uint8_t val) { return i2c_reg_write_byte_dt(&bus->i2c, reg, val); } const struct bmp388_bus_io bmp388_bus_io_i2c = { .check = bmp388_bus_check_i2c, .read = bmp388_reg_read_i2c, .write = bmp388_reg_write_i2c, }; #endif /* BMP388_BUS_I2C */ ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/bmp388_i2c.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
237
```c /* Bosch BMP388 pressure sensor * * * * Datasheet: * path_to_url */ #include <zephyr/kernel.h> #include <zephyr/pm/device.h> #include <zephyr/logging/log.h> #include "bmp388.h" LOG_MODULE_DECLARE(BMP388, CONFIG_SENSOR_LOG_LEVEL); static void bmp388_handle_interrupts(const void *arg) { const struct device *dev = (const struct device *)arg; struct bmp388_data *data = dev->data; if (data->handler_drdy) { data->handler_drdy(dev, data->trig_drdy); } } #ifdef CONFIG_BMP388_TRIGGER_OWN_THREAD static K_THREAD_STACK_DEFINE(bmp388_thread_stack, CONFIG_BMP388_THREAD_STACK_SIZE); static struct k_thread bmp388_thread; static void bmp388_thread_main(void *arg1, void *unused1, void *unused2) { ARG_UNUSED(unused1); ARG_UNUSED(unused2); const struct device *dev = (const struct device *)arg1; struct bmp388_data *data = dev->data; while (1) { k_sem_take(&data->sem, K_FOREVER); bmp388_handle_interrupts(dev); } } #endif #ifdef CONFIG_BMP388_TRIGGER_GLOBAL_THREAD static void bmp388_work_handler(struct k_work *work) { struct bmp388_data *data = CONTAINER_OF(work, struct bmp388_data, work); bmp388_handle_interrupts(data->dev); } #endif static void bmp388_gpio_callback(const struct device *port, struct gpio_callback *cb, uint32_t pin) { struct bmp388_data *data = CONTAINER_OF(cb, struct bmp388_data, gpio_cb); ARG_UNUSED(port); ARG_UNUSED(pin); #if defined(CONFIG_BMP388_TRIGGER_OWN_THREAD) k_sem_give(&data->sem); #elif defined(CONFIG_BMP388_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #elif defined(CONFIG_BMP388_TRIGGER_DIRECT) bmp388_handle_interrupts(data->dev); #endif } int bmp388_trigger_set( const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bmp388_data *data = dev->data; #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif if (trig->type != SENSOR_TRIG_DATA_READY) { return -ENOTSUP; } if (bmp388_reg_field_update( dev, BMP388_REG_INT_CTRL, BMP388_INT_CTRL_DRDY_EN_MASK, (handler != NULL) << BMP388_INT_CTRL_DRDY_EN_POS) < 0) { LOG_ERR("Failed to enable DRDY interrupt"); return -EIO; } data->handler_drdy = handler; data->trig_drdy = trig; return 0; } int bmp388_trigger_mode_init(const struct device *dev) { struct bmp388_data *data = dev->data; const struct bmp388_config *cfg = dev->config; int ret; if (!gpio_is_ready_dt(&cfg->gpio_int)) { LOG_ERR("INT device is not ready"); return -ENODEV; } #if defined(CONFIG_BMP388_TRIGGER_OWN_THREAD) k_sem_init(&data->sem, 0, 1); k_thread_create( &bmp388_thread, bmp388_thread_stack, CONFIG_BMP388_THREAD_STACK_SIZE, bmp388_thread_main, (void *)dev, NULL, NULL, K_PRIO_COOP(CONFIG_BMP388_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_BMP388_TRIGGER_GLOBAL_THREAD) data->work.handler = bmp388_work_handler; #endif #if defined(CONFIG_BMP388_TRIGGER_GLOBAL_THREAD) || \ defined(CONFIG_BMP388_TRIGGER_DIRECT) data->dev = dev; #endif ret = gpio_pin_configure(cfg->gpio_int.port, cfg->gpio_int.pin, GPIO_INPUT | cfg->gpio_int.dt_flags); if (ret < 0) { return ret; } gpio_init_callback(&data->gpio_cb, bmp388_gpio_callback, BIT(cfg->gpio_int.pin)); ret = gpio_add_callback(cfg->gpio_int.port, &data->gpio_cb); if (ret < 0) { return ret; } ret = gpio_pin_interrupt_configure(cfg->gpio_int.port, cfg->gpio_int.pin, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { return ret; } return 0; } ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/bmp388_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
993
```unknown menuconfig BMP388 bool "Bosch BMP388 pressure sensor" default y depends on DT_HAS_BOSCH_BMP388_ENABLED select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMP388),i2c) select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMP388),spi) help Enable driver for the Bosch BMP388 pressure sensor if BMP388 choice BMP388_TRIGGER_MODE prompt "Trigger mode" default BMP388_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config BMP388_TRIGGER_NONE bool "No trigger" config BMP388_TRIGGER_GLOBAL_THREAD bool "Use global thread" select BMP388_TRIGGER config BMP388_TRIGGER_OWN_THREAD bool "Use own thread" select BMP388_TRIGGER config BMP388_TRIGGER_DIRECT bool "Use IRQ handler" select BMP388_TRIGGER endchoice config BMP388_TRIGGER bool config BMP388_THREAD_PRIORITY int "Own thread priority" depends on BMP388_TRIGGER_OWN_THREAD default 10 help Priority of the thread used by the driver to handle interrupts. config BMP388_THREAD_STACK_SIZE int "Own thread stack size" depends on BMP388_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. config BMP388_ODR_RUNTIME bool "Change ODR at runtime." default y config BMP388_OSR_RUNTIME bool "Change OSR at runtime." default y endif # BMP388 ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
331
```c /* Bosch BMP388 pressure sensor * * * * Datasheet: * path_to_url */ #include <zephyr/logging/log.h> #include <zephyr/sys/byteorder.h> #include <zephyr/pm/device.h> #include "bmp388.h" LOG_MODULE_REGISTER(BMP388, CONFIG_SENSOR_LOG_LEVEL); #if defined(CONFIG_BMP388_ODR_RUNTIME) static const struct { uint16_t freq_int; uint16_t freq_milli; } bmp388_odr_map[] = { { 0, 3 }, /* 25/8192 - 327.68s */ { 0, 6 }, /* 25/4096 - 163.84s */ { 0, 12 }, /* 25/2048 - 81.92s */ { 0, 24 }, /* 25/1024 - 40.96s */ { 0, 49 }, /* 25/512 - 20.48s */ { 0, 98 }, /* 25/256 - 10.24s */ { 0, 195 }, /* 25/128 - 5.12s */ { 0, 391 }, /* 25/64 - 2.56s */ { 0, 781 }, /* 25/32 - 1.28s */ { 1, 563 }, /* 25/16 - 640ms */ { 3, 125 }, /* 25/8 - 320ms */ { 6, 250 }, /* 25/4 - 160ms */ { 12, 500 }, /* 25/2 - 80ms */ { 25, 0 }, /* 25 - 40ms */ { 50, 0 }, /* 50 - 20ms */ { 100, 0 }, /* 100 - 10ms */ { 200, 0 }, /* 200 - 5ms */ }; #endif static inline int bmp388_bus_check(const struct device *dev) { const struct bmp388_config *cfg = dev->config; return cfg->bus_io->check(&cfg->bus); } static inline int bmp388_reg_read(const struct device *dev, uint8_t start, uint8_t *buf, int size) { const struct bmp388_config *cfg = dev->config; return cfg->bus_io->read(&cfg->bus, start, buf, size); } static inline int bmp388_reg_write(const struct device *dev, uint8_t reg, uint8_t val) { const struct bmp388_config *cfg = dev->config; return cfg->bus_io->write(&cfg->bus, reg, val); } int bmp388_reg_field_update(const struct device *dev, uint8_t reg, uint8_t mask, uint8_t val) { int rc = 0; uint8_t old_value, new_value; const struct bmp388_config *cfg = dev->config; rc = cfg->bus_io->read(&cfg->bus, reg, &old_value, 1); if (rc != 0) { return rc; } new_value = (old_value & ~mask) | (val & mask); if (new_value == old_value) { return 0; } return cfg->bus_io->write(&cfg->bus, reg, new_value); } #ifdef CONFIG_BMP388_ODR_RUNTIME static int bmp388_freq_to_odr_val(uint16_t freq_int, uint16_t freq_milli) { size_t i; /* An ODR of 0 Hz is not allowed */ if (freq_int == 0U && freq_milli == 0U) { return -EINVAL; } for (i = 0; i < ARRAY_SIZE(bmp388_odr_map); i++) { if (freq_int < bmp388_odr_map[i].freq_int || (freq_int == bmp388_odr_map[i].freq_int && freq_milli <= bmp388_odr_map[i].freq_milli)) { return (ARRAY_SIZE(bmp388_odr_map) - 1) - i; } } return -EINVAL; } static int bmp388_attr_set_odr(const struct device *dev, uint16_t freq_int, uint16_t freq_milli) { int err; struct bmp388_data *data = dev->data; int odr = bmp388_freq_to_odr_val(freq_int, freq_milli); if (odr < 0) { return odr; } err = bmp388_reg_field_update(dev, BMP388_REG_ODR, BMP388_ODR_MASK, (uint8_t)odr); if (err == 0) { data->odr = odr; } return err; } #endif #ifdef CONFIG_BMP388_OSR_RUNTIME static int bmp388_attr_set_oversampling(const struct device *dev, enum sensor_channel chan, uint16_t val) { uint8_t reg_val = 0; uint32_t pos, mask; int err; struct bmp388_data *data = dev->data; /* Value must be a positive power of 2 <= 32. */ if ((val <= 0) || (val > 32) || ((val & (val - 1)) != 0)) { return -EINVAL; } if (chan == SENSOR_CHAN_PRESS) { pos = BMP388_OSR_PRESSURE_POS; mask = BMP388_OSR_PRESSURE_MASK; } else if ((chan == SENSOR_CHAN_AMBIENT_TEMP) || (chan == SENSOR_CHAN_DIE_TEMP)) { pos = BMP388_OSR_TEMP_POS; mask = BMP388_OSR_TEMP_MASK; } else { return -EINVAL; } /* Determine exponent: this corresponds to register setting. */ while ((val % 2) == 0) { val >>= 1; ++reg_val; } err = bmp388_reg_field_update(dev, BMP388_REG_OSR, mask, reg_val << pos); if (err < 0) { return err; } /* Store for future use in converting RAW values. */ if (chan == SENSOR_CHAN_PRESS) { data->osr_pressure = reg_val; } else { data->osr_temp = reg_val; } return err; } #endif static int bmp388_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { int ret; #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif switch (attr) { #ifdef CONFIG_BMP388_ODR_RUNTIME case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = bmp388_attr_set_odr(dev, val->val1, val->val2 / 1000); break; #endif #ifdef CONFIG_BMP388_OSR_RUNTIME case SENSOR_ATTR_OVERSAMPLING: ret = bmp388_attr_set_oversampling(dev, chan, val->val1); break; #endif default: ret = -EINVAL; } return ret; } static int bmp388_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bmp388_data *bmp388 = dev->data; uint8_t raw[BMP388_SAMPLE_BUFFER_SIZE]; int ret = 0; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); #ifdef CONFIG_PM_DEVICE enum pm_device_state state; (void)pm_device_state_get(dev, &state); if (state != PM_DEVICE_STATE_ACTIVE) { return -EBUSY; } #endif pm_device_busy_set(dev); /* Wait for status to indicate that data is ready. */ raw[0] = 0U; while ((raw[0] & BMP388_STATUS_DRDY_PRESS) == 0U) { ret = bmp388_reg_read(dev, BMP388_REG_STATUS, raw, 1); if (ret < 0) { goto error; } } ret = bmp388_reg_read(dev, BMP388_REG_DATA0, raw, BMP388_SAMPLE_BUFFER_SIZE); if (ret < 0) { goto error; } /* convert samples to 32bit values */ bmp388->sample.press = (uint32_t)raw[0] | ((uint32_t)raw[1] << 8) | ((uint32_t)raw[2] << 16); bmp388->sample.raw_temp = (uint32_t)raw[3] | ((uint32_t)raw[4] << 8) | ((uint32_t)raw[5] << 16); bmp388->sample.comp_temp = 0; error: pm_device_busy_clear(dev); return ret; } static void bmp388_compensate_temp(struct bmp388_data *data) { /* Adapted from: * path_to_url */ int64_t partial_data1; int64_t partial_data2; int64_t partial_data3; int64_t partial_data4; int64_t partial_data5; struct bmp388_cal_data *cal = &data->cal; partial_data1 = ((int64_t)data->sample.raw_temp - (256 * cal->t1)); partial_data2 = cal->t2 * partial_data1; partial_data3 = (partial_data1 * partial_data1); partial_data4 = (int64_t)partial_data3 * cal->t3; partial_data5 = ((int64_t)(partial_data2 * 262144) + partial_data4); /* Store for pressure calculation */ data->sample.comp_temp = partial_data5 / 4294967296; } static int bmp388_temp_channel_get(const struct device *dev, struct sensor_value *val) { struct bmp388_data *data = dev->data; if (data->sample.comp_temp == 0) { bmp388_compensate_temp(data); } int64_t tmp = (data->sample.comp_temp * 250000) / 16384; val->val1 = tmp / 1000000; val->val2 = tmp % 1000000; return 0; } static uint64_t bmp388_compensate_press(struct bmp388_data *data) { /* Adapted from: * path_to_url */ int64_t partial_data1; int64_t partial_data2; int64_t partial_data3; int64_t partial_data4; int64_t partial_data5; int64_t partial_data6; int64_t offset; int64_t sensitivity; uint64_t comp_press; struct bmp388_cal_data *cal = &data->cal; int64_t t_lin = data->sample.comp_temp; uint32_t raw_pressure = data->sample.press; partial_data1 = t_lin * t_lin; partial_data2 = partial_data1 / 64; partial_data3 = (partial_data2 * t_lin) / 256; partial_data4 = (cal->p8 * partial_data3) / 32; partial_data5 = (cal->p7 * partial_data1) * 16; partial_data6 = (cal->p6 * t_lin) * 4194304; offset = (cal->p5 * 140737488355328) + partial_data4 + partial_data5 + partial_data6; partial_data2 = (cal->p4 * partial_data3) / 32; partial_data4 = (cal->p3 * partial_data1) * 4; partial_data5 = (cal->p2 - 16384) * t_lin * 2097152; sensitivity = ((cal->p1 - 16384) * 70368744177664) + partial_data2 + partial_data4 + partial_data5; partial_data1 = (sensitivity / 16777216) * raw_pressure; partial_data2 = cal->p10 * t_lin; partial_data3 = partial_data2 + (65536 * cal->p9); partial_data4 = (partial_data3 * raw_pressure) / 8192; /* Dividing by 10 followed by multiplying by 10 to avoid overflow caused * (raw_pressure * partial_data4) */ partial_data5 = (raw_pressure * (partial_data4 / 10)) / 512; partial_data5 = partial_data5 * 10; partial_data6 = ((int64_t)raw_pressure * (int64_t)raw_pressure); partial_data2 = (cal->p11 * partial_data6) / 65536; partial_data3 = (partial_data2 * raw_pressure) / 128; partial_data4 = (offset / 4) + partial_data1 + partial_data5 + partial_data3; comp_press = (((uint64_t)partial_data4 * 25) / (uint64_t)1099511627776); /* returned value is in hundredths of Pa. */ return comp_press; } static int bmp388_press_channel_get(const struct device *dev, struct sensor_value *val) { struct bmp388_data *data = dev->data; if (data->sample.comp_temp == 0) { bmp388_compensate_temp(data); } uint64_t tmp = bmp388_compensate_press(data); /* tmp is in hundredths of Pa. Convert to kPa as specified in sensor * interface. */ val->val1 = tmp / 100000; val->val2 = (tmp % 100000) * 10; return 0; } static int bmp388_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { switch (chan) { case SENSOR_CHAN_PRESS: bmp388_press_channel_get(dev, val); break; case SENSOR_CHAN_DIE_TEMP: case SENSOR_CHAN_AMBIENT_TEMP: bmp388_temp_channel_get(dev, val); break; default: LOG_DBG("Channel not supported."); return -ENOTSUP; } return 0; } static int bmp388_get_calibration_data(const struct device *dev) { struct bmp388_data *data = dev->data; struct bmp388_cal_data *cal = &data->cal; if (bmp388_reg_read(dev, BMP388_REG_CALIB0, (uint8_t *)cal, sizeof(*cal)) < 0) { return -EIO; } cal->t1 = sys_le16_to_cpu(cal->t1); cal->t2 = sys_le16_to_cpu(cal->t2); cal->p1 = sys_le16_to_cpu(cal->p1); cal->p2 = sys_le16_to_cpu(cal->p2); cal->p5 = sys_le16_to_cpu(cal->p5); cal->p6 = sys_le16_to_cpu(cal->p6); cal->p9 = sys_le16_to_cpu(cal->p9); return 0; } #ifdef CONFIG_PM_DEVICE static int bmp388_pm_action(const struct device *dev, enum pm_device_action action) { uint8_t reg_val; switch (action) { case PM_DEVICE_ACTION_RESUME: reg_val = BMP388_PWR_CTRL_MODE_NORMAL; break; case PM_DEVICE_ACTION_SUSPEND: reg_val = BMP388_PWR_CTRL_MODE_SLEEP; break; default: return -ENOTSUP; } if (bmp388_reg_field_update(dev, BMP388_REG_PWR_CTRL, BMP388_PWR_CTRL_MODE_MASK, reg_val) < 0) { LOG_DBG("Failed to set power mode."); return -EIO; } return 0; } #endif /* CONFIG_PM_DEVICE */ static const struct sensor_driver_api bmp388_api = { .attr_set = bmp388_attr_set, #ifdef CONFIG_BMP388_TRIGGER .trigger_set = bmp388_trigger_set, #endif .sample_fetch = bmp388_sample_fetch, .channel_get = bmp388_channel_get, }; static int bmp388_init(const struct device *dev) { struct bmp388_data *bmp388 = dev->data; const struct bmp388_config *cfg = dev->config; uint8_t val = 0U; if (bmp388_bus_check(dev) < 0) { LOG_DBG("bus check failed"); return -ENODEV; } /* reboot the chip */ if (bmp388_reg_write(dev, BMP388_REG_CMD, BMP388_CMD_SOFT_RESET) < 0) { LOG_ERR("Cannot reboot chip."); return -EIO; } k_busy_wait(2000); if (bmp388_reg_read(dev, BMP388_REG_CHIPID, &val, 1) < 0) { LOG_ERR("Failed to read chip id."); return -EIO; } if (val != BMP388_CHIP_ID) { LOG_ERR("Unsupported chip detected (0x%x)!", val); return -ENODEV; } /* Read calibration data */ if (bmp388_get_calibration_data(dev) < 0) { LOG_ERR("Failed to read calibration data."); return -EIO; } /* Set ODR */ if (bmp388_reg_field_update(dev, BMP388_REG_ODR, BMP388_ODR_MASK, bmp388->odr) < 0) { LOG_ERR("Failed to set ODR."); return -EIO; } /* Set OSR */ val = (bmp388->osr_pressure << BMP388_OSR_PRESSURE_POS); val |= (bmp388->osr_temp << BMP388_OSR_TEMP_POS); if (bmp388_reg_write(dev, BMP388_REG_OSR, val) < 0) { LOG_ERR("Failed to set OSR."); return -EIO; } /* Set IIR filter coefficient */ val = (cfg->iir_filter << BMP388_IIR_FILTER_POS) & BMP388_IIR_FILTER_MASK; if (bmp388_reg_write(dev, BMP388_REG_CONFIG, val) < 0) { LOG_ERR("Failed to set IIR coefficient."); return -EIO; } /* Enable sensors and normal mode*/ if (bmp388_reg_write(dev, BMP388_REG_PWR_CTRL, BMP388_PWR_CTRL_ON) < 0) { LOG_ERR("Failed to enable sensors."); return -EIO; } /* Read error register */ if (bmp388_reg_read(dev, BMP388_REG_ERR_REG, &val, 1) < 0) { LOG_ERR("Failed get sensors error register."); return -EIO; } /* OSR and ODR config not proper */ if (val & BMP388_STATUS_CONF_ERR) { LOG_ERR("OSR and ODR configuration is not proper"); return -EINVAL; } #ifdef CONFIG_BMP388_TRIGGER if (cfg->gpio_int.port != NULL && bmp388_trigger_mode_init(dev) < 0) { LOG_ERR("Cannot set up trigger mode."); return -EINVAL; } #endif return 0; } /* Initializes a struct bmp388_config for an instance on a SPI bus. */ #define BMP388_CONFIG_SPI(inst) \ .bus.spi = SPI_DT_SPEC_INST_GET(inst, BMP388_SPI_OPERATION, 0), \ .bus_io = &bmp388_bus_io_spi, /* Initializes a struct bmp388_config for an instance on an I2C bus. */ #define BMP388_CONFIG_I2C(inst) \ .bus.i2c = I2C_DT_SPEC_INST_GET(inst), \ .bus_io = &bmp388_bus_io_i2c, #define BMP388_BUS_CFG(inst) \ COND_CODE_1(DT_INST_ON_BUS(inst, i2c), \ (BMP388_CONFIG_I2C(inst)), \ (BMP388_CONFIG_SPI(inst))) #if defined(CONFIG_BMP388_TRIGGER) #define BMP388_INT_CFG(inst) \ .gpio_int = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, {0}), #else #define BMP388_INT_CFG(inst) #endif #define BMP388_INST(inst) \ static struct bmp388_data bmp388_data_##inst = { \ .odr = DT_INST_ENUM_IDX(inst, odr), \ .osr_pressure = DT_INST_ENUM_IDX(inst, osr_press), \ .osr_temp = DT_INST_ENUM_IDX(inst, osr_temp), \ }; \ static const struct bmp388_config bmp388_config_##inst = { \ BMP388_BUS_CFG(inst) \ BMP388_INT_CFG(inst) \ .iir_filter = DT_INST_ENUM_IDX(inst, iir_filter), \ }; \ PM_DEVICE_DT_INST_DEFINE(inst, bmp388_pm_action); \ SENSOR_DEVICE_DT_INST_DEFINE( \ inst, \ bmp388_init, \ PM_DEVICE_DT_INST_GET(inst), \ &bmp388_data_##inst, \ &bmp388_config_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &bmp388_api); DT_INST_FOREACH_STATUS_OKAY(BMP388_INST) ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/bmp388.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,560
```objective-c /* Bosch BMP388 pressure sensor * * * * Datasheet: * path_to_url */ #ifndef __BMP388_H #define __BMP388_H #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/spi.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/util.h> #define DT_DRV_COMPAT bosch_bmp388 #define BMP388_BUS_SPI DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) #define BMP388_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) union bmp388_bus { #if BMP388_BUS_SPI struct spi_dt_spec spi; #endif #if BMP388_BUS_I2C struct i2c_dt_spec i2c; #endif }; typedef int (*bmp388_bus_check_fn)(const union bmp388_bus *bus); typedef int (*bmp388_reg_read_fn)(const union bmp388_bus *bus, uint8_t start, uint8_t *buf, int size); typedef int (*bmp388_reg_write_fn)(const union bmp388_bus *bus, uint8_t reg, uint8_t val); struct bmp388_bus_io { bmp388_bus_check_fn check; bmp388_reg_read_fn read; bmp388_reg_write_fn write; }; #if BMP388_BUS_SPI #define BMP388_SPI_OPERATION (SPI_WORD_SET(8) | SPI_TRANSFER_MSB | \ SPI_MODE_CPOL | SPI_MODE_CPHA) extern const struct bmp388_bus_io bmp388_bus_io_spi; #endif #if BMP388_BUS_I2C extern const struct bmp388_bus_io bmp388_bus_io_i2c; #endif /* registers */ #define BMP388_REG_CHIPID 0x00 #define BMP388_REG_ERR_REG 0x02 #define BMP388_REG_STATUS 0x03 #define BMP388_REG_DATA0 0x04 #define BMP388_REG_DATA1 0x05 #define BMP388_REG_DATA2 0x06 #define BMP388_REG_DATA3 0x07 #define BMP388_REG_DATA4 0x08 #define BMP388_REG_DATA5 0x09 #define BMP388_REG_SENSORTIME0 0x0C #define BMP388_REG_SENSORTIME1 0x0D #define BMP388_REG_SENSORTIME2 0x0E #define BMP388_REG_SENSORTIME3 0x0F #define BMP388_REG_EVENT 0x10 #define BMP388_REG_INT_STATUS 0x11 #define BMP388_REG_FIFO_LENGTH0 0x12 #define BMP388_REG_FIFO_LENGTH1 0x13 #define BMP388_REG_FIFO_DATA 0x14 #define BMP388_REG_FIFO_WTM0 0x15 #define BMP388_REG_FIFO_WTM1 0x16 #define BMP388_REG_FIFO_CONFIG1 0x17 #define BMP388_REG_FIFO_CONFIG2 0x18 #define BMP388_REG_INT_CTRL 0x19 #define BMP388_REG_IF_CONF 0x1A #define BMP388_REG_PWR_CTRL 0x1B #define BMP388_REG_OSR 0x1C #define BMP388_REG_ODR 0x1D #define BMP388_REG_CONFIG 0x1F #define BMP388_REG_CALIB0 0x31 #define BMP388_REG_CMD 0x7E /* BMP388_REG_CHIPID */ #define BMP388_CHIP_ID 0x50 /* BMP388_REG_STATUS */ #define BMP388_STATUS_FATAL_ERR BIT(0) #define BMP388_STATUS_CMD_ERR BIT(1) #define BMP388_STATUS_CONF_ERR BIT(2) #define BMP388_STATUS_CMD_RDY BIT(4) #define BMP388_STATUS_DRDY_PRESS BIT(5) #define BMP388_STATUS_DRDY_TEMP BIT(6) /* BMP388_REG_INT_CTRL */ #define BMP388_INT_CTRL_DRDY_EN_POS 6 #define BMP388_INT_CTRL_DRDY_EN_MASK BIT(6) /* BMP388_REG_PWR_CTRL */ #define BMP388_PWR_CTRL_PRESS_EN BIT(0) #define BMP388_PWR_CTRL_TEMP_EN BIT(1) #define BMP388_PWR_CTRL_MODE_POS 4 #define BMP388_PWR_CTRL_MODE_MASK (0x03 << BMP388_PWR_CTRL_MODE_POS) #define BMP388_PWR_CTRL_MODE_SLEEP (0x00 << BMP388_PWR_CTRL_MODE_POS) #define BMP388_PWR_CTRL_MODE_FORCED (0x01 << BMP388_PWR_CTRL_MODE_POS) #define BMP388_PWR_CTRL_MODE_NORMAL (0x03 << BMP388_PWR_CTRL_MODE_POS) /* BMP388_REG_OSR */ #define BMP388_ODR_POS 0 #define BMP388_ODR_MASK 0x1F /* BMP388_REG_ODR */ #define BMP388_OSR_PRESSURE_POS 0 #define BMP388_OSR_PRESSURE_MASK (0x07 << BMP388_OSR_PRESSURE_POS) #define BMP388_OSR_TEMP_POS 3 #define BMP388_OSR_TEMP_MASK (0x07 << BMP388_OSR_TEMP_POS) /* BMP388_REG_CONFIG */ #define BMP388_IIR_FILTER_POS 1 #define BMP388_IIR_FILTER_MASK (0x7 << BMP388_IIR_FILTER_POS) /* BMP388_REG_CMD */ #define BMP388_CMD_FIFO_FLUSH 0xB0 #define BMP388_CMD_SOFT_RESET 0xB6 /* default PWR_CTRL settings */ #define BMP388_PWR_CTRL_ON \ (BMP388_PWR_CTRL_PRESS_EN | \ BMP388_PWR_CTRL_TEMP_EN | \ BMP388_PWR_CTRL_MODE_NORMAL) #define BMP388_PWR_CTRL_OFF 0 #define BMP388_SAMPLE_BUFFER_SIZE (6) struct bmp388_cal_data { uint16_t t1; uint16_t t2; int8_t t3; int16_t p1; int16_t p2; int8_t p3; int8_t p4; uint16_t p5; uint16_t p6; int8_t p7; int8_t p8; int16_t p9; int8_t p10; int8_t p11; } __packed; struct bmp388_sample { uint32_t press; uint32_t raw_temp; int64_t comp_temp; }; struct bmp388_config { union bmp388_bus bus; const struct bmp388_bus_io *bus_io; #ifdef CONFIG_BMP388_TRIGGER struct gpio_dt_spec gpio_int; #endif uint8_t iir_filter; }; struct bmp388_data { uint8_t odr; uint8_t osr_pressure; uint8_t osr_temp; struct bmp388_cal_data cal; #if defined(CONFIG_BMP388_TRIGGER) struct gpio_callback gpio_cb; #endif struct bmp388_sample sample; #ifdef CONFIG_BMP388_TRIGGER_OWN_THREAD struct k_sem sem; #endif #ifdef CONFIG_BMP388_TRIGGER_GLOBAL_THREAD struct k_work work; #endif #if defined(CONFIG_BMP388_TRIGGER_GLOBAL_THREAD) || \ defined(CONFIG_BMP388_TRIGGER_DIRECT) const struct device *dev; #endif #ifdef CONFIG_BMP388_TRIGGER sensor_trigger_handler_t handler_drdy; const struct sensor_trigger *trig_drdy; #endif /* CONFIG_BMP388_TRIGGER */ }; int bmp388_trigger_mode_init(const struct device *dev); int bmp388_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int bmp388_reg_field_update(const struct device *dev, uint8_t reg, uint8_t mask, uint8_t val); #endif /* __BMP388_H */ ```
/content/code_sandbox/drivers/sensor/bosch/bmp388/bmp388.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,617
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_SPI_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_SPI_H_ #include "bmi323.h" #include <zephyr/devicetree.h> #include <zephyr/drivers/spi.h> #define BMI323_DEVICE_SPI_BUS(inst) \ extern const struct bosch_bmi323_bus_api bosch_bmi323_spi_bus_api; \ \ static const struct spi_dt_spec spi_spec##inst = \ SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 0); \ \ static const struct bosch_bmi323_bus bosch_bmi323_bus_api##inst = { \ .context = &spi_spec##inst, .api = &bosch_bmi323_spi_bus_api} #endif /* ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_SPI_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi323/bmi323_spi.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
200
```c /* * */ #include "bmi323.h" #include <zephyr/device.h> #include <zephyr/drivers/spi.h> static int bosch_bmi323_spi_read_words(const void *context, uint8_t offset, uint16_t *words, uint16_t words_count) { const struct spi_dt_spec *spi = (const struct spi_dt_spec *)context; uint8_t address[2]; struct spi_buf transmit_buffer; struct spi_buf_set transmit_buffer_set; struct spi_buf receive_buffers[2]; struct spi_buf_set receive_buffers_set; int ret; address[0] = offset | 0x80; address[1] = 0x00; transmit_buffer.buf = address; transmit_buffer.len = sizeof(address); transmit_buffer_set.buffers = &transmit_buffer; transmit_buffer_set.count = 1; receive_buffers[0].buf = NULL; receive_buffers[0].len = 2; receive_buffers[1].buf = words; receive_buffers[1].len = (words_count * 2); receive_buffers_set.buffers = receive_buffers; receive_buffers_set.count = 2; ret = spi_transceive_dt(spi, &transmit_buffer_set, &receive_buffers_set); k_usleep(2); return ret; } static int bosch_bmi323_spi_write_words(const void *context, uint8_t offset, uint16_t *words, uint16_t words_count) { const struct spi_dt_spec *spi = (const struct spi_dt_spec *)context; uint8_t address; struct spi_buf transmit_buffers[2]; struct spi_buf_set transmit_buffer_set; int ret; address = offset & 0x7F; transmit_buffers[0].buf = &address; transmit_buffers[0].len = 1; transmit_buffers[1].buf = words; transmit_buffers[1].len = (words_count * 2); transmit_buffer_set.buffers = transmit_buffers; transmit_buffer_set.count = 2; ret = spi_write_dt(spi, &transmit_buffer_set); k_usleep(2); return ret; } static int bosch_bmi323_spi_init(const void *context) { const struct spi_dt_spec *spi = (const struct spi_dt_spec *)context; uint16_t sensor_id; int ret; if (spi_is_ready_dt(spi) == false) { return -ENODEV; } ret = bosch_bmi323_spi_read_words(spi, 0, &sensor_id, 1); if (ret < 0) { return ret; } k_usleep(1500); return 0; } const struct bosch_bmi323_bus_api bosch_bmi323_spi_bus_api = { .read_words = bosch_bmi323_spi_read_words, .write_words = bosch_bmi323_spi_write_words, .init = bosch_bmi323_spi_init}; ```
/content/code_sandbox/drivers/sensor/bosch/bmi323/bmi323_spi.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
615
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_H_ #include <zephyr/sys/util.h> #include <zephyr/types.h> #define IMU_BOSCH_BMI323_REG_ACC_DATA_X (0x03) #define IMU_BOSCH_BMI323_REG_ACC_DATA_Y (0x04) #define IMU_BOSCH_BMI323_REG_ACC_DATA_Z (0x05) #define IMU_BOSCH_BMI323_REG_GYRO_DATA_X (0x06) #define IMU_BOSCH_BMI323_REG_GYRO_DATA_Y (0x07) #define IMU_BOSCH_BMI323_REG_GYRO_DATA_Z (0x08) #define IMU_BOSCH_BMI323_REG_TEMP_DATA (0x09) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0 (0x10) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_X_EN_OFFSET (0x03) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_X_EN_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_X_EN_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_X_EN_VAL_EN (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Y_EN_OFFSET (0x04) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Y_EN_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Y_EN_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Y_EN_VAL_EN (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Z_EN_OFFSET (0x05) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Z_EN_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Z_EN_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_IO0_MOTION_Z_EN_VAL_EN (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO2 (0x12) #define IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS (0x14) #define IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS_STATUS_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS_STATUS_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS_STATUS_VAL_SET (0x01) #define IMU_BOSCH_BMI323_REG_INT_STATUS_INT1 (0x0D) #define IMU_BOSCH_BMI323_REG_INT_STATUS_INT2 (0x0E) #define IMU_BOSCH_BMI323_REG_ACC_CONF (0x20) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_SIZE (0x04) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ0P78125 (0x01) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ1P5625 (0x02) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ3P125 (0x03) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ6P25 (0x04) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ12P5 (0x05) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ25 (0x06) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ50 (0x07) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ100 (0x08) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ200 (0x09) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ400 (0x0A) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ800 (0x0B) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ1600 (0x0C) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ3200 (0x0D) #define IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ6400 (0x0E) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_OFFSET (0x04) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_SIZE (0x03) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G2 (0x00) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G4 (0x01) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G8 (0x02) #define IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G16 (0x03) #define IMU_BOSCH_BMI323_REG_ACC_CONF_MODE_OFFSET (0x0C) #define IMU_BOSCH_BMI323_REG_ACC_CONF_MODE_SIZE (0x03) #define IMU_BOSCH_BMI323_REG_ACC_CONF_MODE_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_ACC_CONF_MODE_VAL_LPWR (0x04) #define IMU_BOSCH_BMI323_REG_ACC_CONF_MODE_VAL_HPWR (0x07) #define IMU_BOSCH_BMI323_REG_GYRO_CONF (0x21) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_SIZE (0x04) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ0P78125 (0x01) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ1P5625 (0x02) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ3P125 (0x03) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ6P25 (0x04) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ12P5 (0x05) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ25 (0x06) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ50 (0x07) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ100 (0x08) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ200 (0x09) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ400 (0x0A) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ800 (0x0B) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ1600 (0x0C) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ3200 (0x0D) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ6400 (0x0E) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_OFFSET (0x04) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_SIZE (0x03) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS125 (0x00) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS250 (0x01) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS500 (0x02) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS1000 (0x03) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS2000 (0x04) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_MODE_OFFSET (0x0C) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_MODE_SIZE (0x03) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_MODE_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_MODE_VAL_LPWR (0x04) #define IMU_BOSCH_BMI323_REG_GYRO_CONF_MODE_VAL_HPWR (0x07) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL (0x38) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_LVL_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_LVL_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_LVL_VAL_ACT_LOW (0x00) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_LVL_VAL_ACT_HIGH (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OD_OFFSET (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OD_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OD_VAL_PUSH_PULL (0x00) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OD_VAL_OPEN_DRAIN (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OUTPUT_EN_OFFSET (0x02) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OUTPUT_EN_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OUTPUT_EN_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_IO_INT_CTRL_INT1_OUTPUT_EN_VAL_EN (0x01) #define IMU_BOSCH_BMI323_REG_INT_CONF (0x39) #define IMU_BOSCH_BMI323_REG_INT_CONF_INT_LATCH_OFFSET (0x01) #define IMU_BOSCH_BMI323_REG_INT_CONF_INT_LATCH_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_INT_CONF_INT_LATCH_VAL_NON_LATCHED (0x00) #define IMU_BOSCH_BMI323_REG_INT_CONF_INT_LATCH_VAL_LATCHED (0x01) #define IMU_BOSCH_BMI323_REG_INT_MAP1 (0x3A) #define IMU_BOSCH_BMI323_REG_INT_MAP1_MOTION_OUT_OFFSET (0x02) #define IMU_BOSCH_BMI323_REG_INT_MAP1_MOTION_OUT_SIZE (0x02) #define IMU_BOSCH_BMI323_REG_INT_MAP1_MOTION_OUT_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_INT_MAP1_MOTION_OUT_VAL_INT1 (0x01) #define IMU_BOSCH_BMI323_REG_INT_MAP1_MOTION_OUT_VAL_INT2 (0x02) #define IMU_BOSCH_BMI323_REG_INT_MAP2 (0x3B) #define IMU_BOSCH_BMI323_REG_INT_MAP2_ACC_DRDY_INT_OFFSET (0x0A) #define IMU_BOSCH_BMI323_REG_INT_MAP2_ACC_DRDY_INT_SIZE (0x02) #define IMU_BOSCH_BMI323_REG_INT_MAP2_ACC_DRDY_INT_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_INT_MAP2_ACC_DRDY_INT_VAL_INT1 (0x01) #define IMU_BOSCH_BMI323_REG_INT_MAP2_ACC_DRDY_INT_VAL_INT2 (0x02) #define IMU_BOSCH_BMI323_REG_FEATURE_CTRL (0x40) #define IMU_BOSCH_BMI323_REG_FEATURE_CTRL_ENABLE_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_CTRL_ENABLE_SIZE (0x01) #define IMU_BOSCH_BMI323_REG_FEATURE_CTRL_ENABLE_VAL_DIS (0x00) #define IMU_BOSCH_BMI323_REG_FEATURE_CTRL_ENABLE_VAL_EN (0x01) #define IMU_BOSCH_BMI323_REG_CMD (0x7E) #define IMU_BOSCH_BMI323_REG_CMD_CMD_OFFSET (0x00) #define IMU_BOSCH_BMI323_REG_CMD_CMD_SIZE (0x10) #define IMU_BOSCH_BMI323_REG_CMD_CMD_VAL_SOFT_RESET (0xDEAF) #define IMU_BOSCH_BMI323_REG_MASK(reg, field) \ (BIT_MASK(IMU_BOSCH_BMI323_REG_##reg##_##field##_SIZE) \ << IMU_BOSCH_BMI323_REG_##reg##_##field##_OFFSET) #define IMU_BOSCH_BMI323_REG_VALUE(reg, field, val) \ (IMU_BOSCH_BMI323_REG_##reg##_##field##_VAL_##val \ << IMU_BOSCH_BMI323_REG_##reg##_##field##_OFFSET) #define IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(reg_value, reg, field) \ ((reg_value >> IMU_BOSCH_BMI323_REG_##reg##_##field##_OFFSET) & \ BIT_MASK(IMU_BOSCH_BMI323_REG_##reg##_##field##_SIZE)) struct bosch_bmi323_bus_api { /* Read up to multiple words from the BMI323 */ int (*read_words)(const void *context, uint8_t offset, uint16_t *words, uint16_t words_count); /* Write up to multiple words to the BLI323 */ int (*write_words)(const void *context, uint8_t offset, uint16_t *words, uint16_t words_count); /* Initialize the bus */ int (*init)(const void *context); }; struct bosch_bmi323_bus { const void *context; const struct bosch_bmi323_bus_api *api; }; #endif /* ZEPHYR_DRIVERS_SENSOR_BMI323_BMI323_H_ */ ```
/content/code_sandbox/drivers/sensor/bosch/bmi323/bmi323.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,189
```unknown menuconfig BMI323 bool "BMI323 measurement unit" default y depends on DT_HAS_BOSCH_BMI323_ENABLED help Enable driver for BMI323 IMU sensor. The driver implements the following features: * Enable and disable accelerometer and gyroscope respectively * Set full scale for accelerometer and gyroscope respectively * Set data rate for accelerometer and gyroscope respectively * Get samples (x,y,z) from accelerometer and gyroscope respectively * Get die temperature * Set trigger to accelerometer data ready, and accelerometer any motion. The driver implements device and device runtime power management. If runtime management is used, it is initialized into the suspended state, which soft-resets the device to achieve the lowest possible power consumption, otherwise it is resumed when initialized. When resumed, the bus is initialized, the feature engine is enabled, and INT1 is initialized. The driver only implements the SPI bus at this time. The driver is prepared to be expanded with I2C support in the future. if BMI323 config BMI323_BUS_SPI bool "BMI323 driver support for SPI bus" default y depends on $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BMI323),spi) select SPI endif # BMI323 ```
/content/code_sandbox/drivers/sensor/bosch/bmi323/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
277
```c /* bme680.c - Driver for Bosch Sensortec's BME680 temperature, pressure, * humidity and gas sensor * * path_to_url */ /* * */ #include <zephyr/drivers/gpio.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <zephyr/sys/byteorder.h> #include <zephyr/sys/__assert.h> #include <zephyr/drivers/sensor.h> #include <zephyr/logging/log.h> #include "bme680.h" LOG_MODULE_REGISTER(bme680, CONFIG_SENSOR_LOG_LEVEL); struct bme_data_regs { uint8_t pressure[3]; uint8_t temperature[3]; uint8_t humidity[2]; uint8_t padding[3]; uint8_t gas[2]; } __packed; #if BME680_BUS_SPI static inline bool bme680_is_on_spi(const struct device *dev) { const struct bme680_config *config = dev->config; return config->bus_io == &bme680_bus_io_spi; } #endif static inline int bme680_bus_check(const struct device *dev) { const struct bme680_config *config = dev->config; return config->bus_io->check(&config->bus); } static inline int bme680_reg_read(const struct device *dev, uint8_t start, void *buf, int size) { const struct bme680_config *config = dev->config; return config->bus_io->read(dev, start, buf, size); } static inline int bme680_reg_write(const struct device *dev, uint8_t reg, uint8_t val) { const struct bme680_config *config = dev->config; return config->bus_io->write(dev, reg, val); } static void bme680_calc_temp(struct bme680_data *data, uint32_t adc_temp) { int64_t var1, var2, var3; var1 = ((int32_t)adc_temp >> 3) - ((int32_t)data->par_t1 << 1); var2 = (var1 * (int32_t)data->par_t2) >> 11; var3 = ((var1 >> 1) * (var1 >> 1)) >> 12; var3 = ((var3) * ((int32_t)data->par_t3 << 4)) >> 14; data->t_fine = var2 + var3; data->calc_temp = ((data->t_fine * 5) + 128) >> 8; } static void bme680_calc_press(struct bme680_data *data, uint32_t adc_press) { int32_t var1, var2, var3, calc_press; var1 = (((int32_t)data->t_fine) >> 1) - 64000; var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) * (int32_t)data->par_p6) >> 2; var2 = var2 + ((var1 * (int32_t)data->par_p5) << 1); var2 = (var2 >> 2) + ((int32_t)data->par_p4 << 16); var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) * ((int32_t)data->par_p3 << 5)) >> 3) + (((int32_t)data->par_p2 * var1) >> 1); var1 = var1 >> 18; var1 = ((32768 + var1) * (int32_t)data->par_p1) >> 15; calc_press = 1048576 - adc_press; calc_press = (calc_press - (var2 >> 12)) * ((uint32_t)3125); /* This max value is used to provide precedence to multiplication or * division in the pressure calculation equation to achieve least * loss of precision and avoiding overflows. * i.e Comparing value, signed int 32bit (1 << 30) */ if (calc_press >= (int32_t)0x40000000) { calc_press = ((calc_press / var1) << 1); } else { calc_press = ((calc_press << 1) / var1); } var1 = ((int32_t)data->par_p9 * (int32_t)(((calc_press >> 3) * (calc_press >> 3)) >> 13)) >> 12; var2 = ((int32_t)(calc_press >> 2) * (int32_t)data->par_p8) >> 13; var3 = ((int32_t)(calc_press >> 8) * (int32_t)(calc_press >> 8) * (int32_t)(calc_press >> 8) * (int32_t)data->par_p10) >> 17; data->calc_press = calc_press + ((var1 + var2 + var3 + ((int32_t)data->par_p7 << 7)) >> 4); } static void bme680_calc_humidity(struct bme680_data *data, uint16_t adc_humidity) { int32_t var1, var2_1, var2_2, var2, var3, var4, var5, var6; int32_t temp_scaled, calc_hum; temp_scaled = (((int32_t)data->t_fine * 5) + 128) >> 8; var1 = (int32_t)(adc_humidity - ((int32_t)((int32_t)data->par_h1 * 16))) - (((temp_scaled * (int32_t)data->par_h3) / ((int32_t)100)) >> 1); var2_1 = (int32_t)data->par_h2; var2_2 = ((temp_scaled * (int32_t)data->par_h4) / (int32_t)100) + (((temp_scaled * ((temp_scaled * (int32_t)data->par_h5) / ((int32_t)100))) >> 6) / ((int32_t)100)) + (int32_t)(1 << 14); var2 = (var2_1 * var2_2) >> 10; var3 = var1 * var2; var4 = (int32_t)data->par_h6 << 7; var4 = ((var4) + ((temp_scaled * (int32_t)data->par_h7) / ((int32_t)100))) >> 4; var5 = ((var3 >> 14) * (var3 >> 14)) >> 10; var6 = (var4 * var5) >> 1; calc_hum = (((var3 + var6) >> 10) * ((int32_t)1000)) >> 12; if (calc_hum > 100000) { /* Cap at 100%rH */ calc_hum = 100000; } else if (calc_hum < 0) { calc_hum = 0; } data->calc_humidity = calc_hum; } static void bme680_calc_gas_resistance(struct bme680_data *data, uint8_t gas_range, uint16_t adc_gas_res) { int64_t var1, var3; uint64_t var2; static const uint32_t look_up1[16] = { 2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 2126008810, 2147483647, 2130303777, 2147483647, 2147483647, 2143188679, 2136746228, 2147483647, 2126008810, 2147483647, 2147483647 }; static const uint32_t look_up2[16] = { 4096000000, 2048000000, 1024000000, 512000000, 255744255, 127110228, 64000000, 32258064, 16016016, 8000000, 4000000, 2000000, 1000000, 500000, 250000, 125000 }; var1 = (int64_t)((1340 + (5 * (int64_t)data->range_sw_err)) * ((int64_t)look_up1[gas_range])) >> 16; var2 = (((int64_t)((int64_t)adc_gas_res << 15) - (int64_t)(16777216)) + var1); var3 = (((int64_t)look_up2[gas_range] * (int64_t)var1) >> 9); data->calc_gas_resistance = (uint32_t)((var3 + ((int64_t)var2 >> 1)) / (int64_t)var2); } static uint8_t bme680_calc_res_heat(struct bme680_data *data, uint16_t heatr_temp) { uint8_t heatr_res; int32_t var1, var2, var3, var4, var5; int32_t heatr_res_x100; int32_t amb_temp = 25; /* Assume ambient temperature to be 25 deg C */ if (heatr_temp > 400) { /* Cap temperature */ heatr_temp = 400; } var1 = ((amb_temp * data->par_gh3) / 1000) * 256; var2 = (data->par_gh1 + 784) * (((((data->par_gh2 + 154009) * heatr_temp * 5) / 100) + 3276800) / 10); var3 = var1 + (var2 / 2); var4 = (var3 / (data->res_heat_range + 4)); var5 = (131 * data->res_heat_val) + 65536; heatr_res_x100 = ((var4 / var5) - 250) * 34; heatr_res = (heatr_res_x100 + 50) / 100; return heatr_res; } static uint8_t bme680_calc_gas_wait(uint16_t dur) { uint8_t factor = 0, durval; if (dur >= 0xfc0) { durval = 0xff; /* Max duration*/ } else { while (dur > 0x3F) { dur = dur / 4; factor += 1; } durval = dur + (factor * 64); } return durval; } static int bme680_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bme680_data *data = dev->data; struct bme_data_regs data_regs; uint8_t gas_range; uint32_t adc_temp, adc_press; uint16_t adc_hum, adc_gas_res; uint8_t status; int cnt = 0; int ret; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); /* Trigger the measurement */ ret = bme680_reg_write(dev, BME680_REG_CTRL_MEAS, BME680_CTRL_MEAS_VAL); if (ret < 0) { return ret; } do { /* Wait for a maximum of 250ms for data. * Initial delay after boot has been measured at 170ms. * Subequent triggers are < 1ms. */ if (cnt++ > 250) { return -EAGAIN; } k_sleep(K_MSEC(1)); ret = bme680_reg_read(dev, BME680_REG_MEAS_STATUS, &status, 1); if (ret < 0) { return ret; } } while (!(status & BME680_MSK_NEW_DATA)); LOG_DBG("New data after %d ms", cnt); ret = bme680_reg_read(dev, BME680_REG_FIELD0, &data_regs, sizeof(data_regs)); if (ret < 0) { return ret; } adc_press = sys_get_be24(data_regs.pressure) >> 4; adc_temp = sys_get_be24(data_regs.temperature) >> 4; adc_hum = sys_get_be16(data_regs.humidity); adc_gas_res = sys_get_be16(data_regs.gas) >> 6; data->heatr_stab = data_regs.gas[1] & BME680_MSK_HEATR_STAB; gas_range = data_regs.gas[1] & BME680_MSK_GAS_RANGE; bme680_calc_temp(data, adc_temp); bme680_calc_press(data, adc_press); bme680_calc_humidity(data, adc_hum); bme680_calc_gas_resistance(data, gas_range, adc_gas_res); return 0; } static int bme680_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bme680_data *data = dev->data; switch (chan) { case SENSOR_CHAN_AMBIENT_TEMP: /* * data->calc_temp has a resolution of 0.01 degC. * So 5123 equals 51.23 degC. */ val->val1 = data->calc_temp / 100; val->val2 = data->calc_temp % 100 * 10000; break; case SENSOR_CHAN_PRESS: /* * data->calc_press has a resolution of 1 Pa. * So 96321 equals 96.321 kPa. */ val->val1 = data->calc_press / 1000; val->val2 = (data->calc_press % 1000) * 1000; break; case SENSOR_CHAN_HUMIDITY: /* * data->calc_humidity has a resolution of 0.001 %RH. * So 46333 equals 46.333 %RH. */ val->val1 = data->calc_humidity / 1000; val->val2 = (data->calc_humidity % 1000) * 1000; break; case SENSOR_CHAN_GAS_RES: /* * data->calc_gas_resistance has a resolution of 1 ohm. * So 100000 equals 100000 ohms. */ val->val1 = data->calc_gas_resistance; val->val2 = 0; break; default: return -ENOTSUP; } return 0; } static int bme680_read_compensation(const struct device *dev) { struct bme680_data *data = dev->data; uint8_t buff[BME680_LEN_COEFF_ALL]; int err = 0; err = bme680_reg_read(dev, BME680_REG_COEFF1, buff, BME680_LEN_COEFF1); if (err < 0) { return err; } err = bme680_reg_read(dev, BME680_REG_COEFF2, &buff[BME680_LEN_COEFF1], BME680_LEN_COEFF2); if (err < 0) { return err; } err = bme680_reg_read(dev, BME680_REG_COEFF3, &buff[BME680_LEN_COEFF1 + BME680_LEN_COEFF2], BME680_LEN_COEFF3); if (err < 0) { return err; } /* Temperature related coefficients */ data->par_t1 = (uint16_t)(BME680_CONCAT_BYTES(buff[32], buff[31])); data->par_t2 = (int16_t)(BME680_CONCAT_BYTES(buff[1], buff[0])); data->par_t3 = (uint8_t)(buff[2]); /* Pressure related coefficients */ data->par_p1 = (uint16_t)(BME680_CONCAT_BYTES(buff[5], buff[4])); data->par_p2 = (int16_t)(BME680_CONCAT_BYTES(buff[7], buff[6])); data->par_p3 = (int8_t)buff[8]; data->par_p4 = (int16_t)(BME680_CONCAT_BYTES(buff[11], buff[10])); data->par_p5 = (int16_t)(BME680_CONCAT_BYTES(buff[13], buff[12])); data->par_p6 = (int8_t)(buff[15]); data->par_p7 = (int8_t)(buff[14]); data->par_p8 = (int16_t)(BME680_CONCAT_BYTES(buff[19], buff[18])); data->par_p9 = (int16_t)(BME680_CONCAT_BYTES(buff[21], buff[20])); data->par_p10 = (uint8_t)(buff[22]); /* Humidity related coefficients */ data->par_h1 = (uint16_t)(((uint16_t)buff[25] << 4) | (buff[24] & 0x0f)); data->par_h2 = (uint16_t)(((uint16_t)buff[23] << 4) | ((buff[24]) >> 4)); data->par_h3 = (int8_t)buff[26]; data->par_h4 = (int8_t)buff[27]; data->par_h5 = (int8_t)buff[28]; data->par_h6 = (uint8_t)buff[29]; data->par_h7 = (int8_t)buff[30]; /* Gas heater related coefficients */ data->par_gh1 = (int8_t)buff[35]; data->par_gh2 = (int16_t)(BME680_CONCAT_BYTES(buff[34], buff[33])); data->par_gh3 = (int8_t)buff[36]; data->res_heat_val = (int8_t)buff[37]; data->res_heat_range = ((buff[39] & BME680_MSK_RH_RANGE) >> 4); data->range_sw_err = ((int8_t)(buff[41] & BME680_MSK_RANGE_SW_ERR)) / 16; return 0; } static int bme680_init(const struct device *dev) { struct bme680_data *data = dev->data; int err; err = bme680_bus_check(dev); if (err < 0) { LOG_ERR("Bus not ready for '%s'", dev->name); return err; } #if BME680_BUS_SPI if (bme680_is_on_spi(dev)) { uint8_t mem_page; err = bme680_reg_read(dev, BME680_REG_STATUS, &mem_page, 1); if (err < 0) { return err; } data->mem_page = (mem_page & BME680_SPI_MEM_PAGE_MSK) >> BME680_SPI_MEM_PAGE_POS; } #endif err = bme680_reg_read(dev, BME680_REG_CHIP_ID, &data->chip_id, 1); if (err < 0) { return err; } if (data->chip_id == BME680_CHIP_ID) { LOG_DBG("BME680 chip detected"); } else { LOG_ERR("Bad BME680 chip id: 0x%x", data->chip_id); return -ENOTSUP; } err = bme680_read_compensation(dev); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_CTRL_HUM, BME680_HUMIDITY_OVER); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_CONFIG, BME680_CONFIG_VAL); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_CTRL_GAS_1, BME680_CTRL_GAS_1_VAL); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_RES_HEAT0, bme680_calc_res_heat(data, BME680_HEATR_TEMP)); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_GAS_WAIT0, bme680_calc_gas_wait(BME680_HEATR_DUR_MS)); if (err < 0) { return err; } err = bme680_reg_write(dev, BME680_REG_CTRL_MEAS, BME680_CTRL_MEAS_VAL); return err; } static const struct sensor_driver_api bme680_api_funcs = { .sample_fetch = bme680_sample_fetch, .channel_get = bme680_channel_get, }; /* Initializes a struct bme680_config for an instance on a SPI bus. */ #define BME680_CONFIG_SPI(inst) \ { \ .bus.spi = SPI_DT_SPEC_INST_GET( \ inst, BME680_SPI_OPERATION, 0), \ .bus_io = &bme680_bus_io_spi, \ } /* Initializes a struct bme680_config for an instance on an I2C bus. */ #define BME680_CONFIG_I2C(inst) \ { \ .bus.i2c = I2C_DT_SPEC_INST_GET(inst), \ .bus_io = &bme680_bus_io_i2c, \ } /* * Main instantiation macro, which selects the correct bus-specific * instantiation macros for the instance. */ #define BME680_DEFINE(inst) \ static struct bme680_data bme680_data_##inst; \ static const struct bme680_config bme680_config_##inst = \ COND_CODE_1(DT_INST_ON_BUS(inst, spi), \ (BME680_CONFIG_SPI(inst)), \ (BME680_CONFIG_I2C(inst))); \ SENSOR_DEVICE_DT_INST_DEFINE(inst, \ bme680_init, \ NULL, \ &bme680_data_##inst, \ &bme680_config_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &bme680_api_funcs); /* Create the struct device for every status "okay" node in the devicetree. */ DT_INST_FOREACH_STATUS_OKAY(BME680_DEFINE) ```
/content/code_sandbox/drivers/sensor/bosch/bme680/bme680.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
4,856
```c /* * */ #include "bmi323.h" #include "bmi323_spi.h" #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/pm/device.h> #include <zephyr/pm/device_runtime.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(bosch_bmi323); #define DT_DRV_COMPAT bosch_bmi323 /* Value taken from BMI323 Datasheet section 5.8.1 */ #define IMU_BOSCH_FEATURE_ENGINE_STARTUP_CONFIG (0x012C) #define IMU_BOSCH_DIE_TEMP_OFFSET_MICRO_DEG_CELCIUS (23000000LL) #define IMU_BOSCH_DIE_TEMP_MICRO_DEG_CELCIUS_LSB (1953L) typedef void (*bosch_bmi323_gpio_callback_ptr)(const struct device *dev, struct gpio_callback *cb, uint32_t pins); struct bosch_bmi323_config { const struct bosch_bmi323_bus *bus; const struct gpio_dt_spec int_gpio; const bosch_bmi323_gpio_callback_ptr int_gpio_callback; }; struct bosch_bmi323_data { struct k_mutex lock; struct sensor_value acc_samples[3]; struct sensor_value gyro_samples[3]; struct sensor_value temperature; bool acc_samples_valid; bool gyro_samples_valid; bool temperature_valid; uint32_t acc_full_scale; uint32_t gyro_full_scale; struct gpio_callback gpio_callback; const struct sensor_trigger *trigger; sensor_trigger_handler_t trigger_handler; struct k_work callback_work; const struct device *dev; }; static int bosch_bmi323_bus_init(const struct device *dev) { const struct bosch_bmi323_config *config = (const struct bosch_bmi323_config *)dev->config; const struct bosch_bmi323_bus *bus = config->bus; return bus->api->init(bus->context); } static int bosch_bmi323_bus_read_words(const struct device *dev, uint8_t offset, uint16_t *words, uint16_t words_count) { const struct bosch_bmi323_config *config = (const struct bosch_bmi323_config *)dev->config; const struct bosch_bmi323_bus *bus = config->bus; return bus->api->read_words(bus->context, offset, words, words_count); } static int bosch_bmi323_bus_write_words(const struct device *dev, uint8_t offset, uint16_t *words, uint16_t words_count) { const struct bosch_bmi323_config *config = (const struct bosch_bmi323_config *)dev->config; const struct bosch_bmi323_bus *bus = config->bus; return bus->api->write_words(bus->context, offset, words, words_count); } static int32_t bosch_bmi323_lsb_from_fullscale(int64_t fullscale) { return (fullscale * 1000) / INT16_MAX; } /* lsb is the value of one 1/1000000 LSB */ static int64_t bosch_bmi323_value_to_micro(int16_t value, int32_t lsb) { return ((int64_t)value) * lsb; } /* lsb is the value of one 1/1000000 LSB */ static void bosch_bmi323_value_to_sensor_value(struct sensor_value *result, int16_t value, int32_t lsb) { int64_t ll_value = (int64_t)value * lsb; int32_t int_part = (int32_t)(ll_value / 1000000); int32_t frac_part = (int32_t)(ll_value % 1000000); result->val1 = int_part; result->val2 = frac_part; } static void bosch_bmi323_sensor_value_from_micro(struct sensor_value *result, int64_t micro) { int32_t int_part = (int32_t)(micro / 1000000); int32_t frac_part = (int32_t)(micro % 1000000); result->val1 = int_part; result->val2 = frac_part; } static bool bosch_bmi323_value_is_valid(int16_t value) { return ((uint16_t)value == 0x8000) ? false : true; } static int bosch_bmi323_validate_chip_id(const struct device *dev) { uint16_t sensor_id; int ret; ret = bosch_bmi323_bus_read_words(dev, 0, &sensor_id, 1); if (ret < 0) { return ret; } if ((sensor_id & 0xFF) != 0x43) { return -ENODEV; } return 0; } static int bosch_bmi323_soft_reset(const struct device *dev) { uint16_t cmd; int ret; cmd = IMU_BOSCH_BMI323_REG_VALUE(CMD, CMD, SOFT_RESET); ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_CMD, &cmd, 1); if (ret < 0) { return ret; } k_usleep(1500); return 0; } static int bosch_bmi323_enable_feature_engine(const struct device *dev) { uint16_t buf; int ret; buf = IMU_BOSCH_FEATURE_ENGINE_STARTUP_CONFIG; ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_IO2, &buf, 1); if (ret < 0) { return ret; } buf = IMU_BOSCH_BMI323_REG_VALUE(FEATURE_IO_STATUS, STATUS, SET); ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS, &buf, 1); if (ret < 0) { return ret; } buf = IMU_BOSCH_BMI323_REG_VALUE(FEATURE_CTRL, ENABLE, EN); return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_CTRL, &buf, 1); } static int bosch_bmi323_driver_api_set_acc_odr(const struct device *dev, const struct sensor_value *val) { int ret; uint16_t acc_conf; int64_t odr = sensor_value_to_milli(val); ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } acc_conf &= ~IMU_BOSCH_BMI323_REG_MASK(ACC_CONF, ODR); if (odr <= 782) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ0P78125); } else if (odr <= 1563) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ1P5625); } else if (odr <= 3125) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ3P125); } else if (odr <= 6250) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ6P25); } else if (odr <= 12500) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ12P5); } else if (odr <= 25000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ25); } else if (odr <= 50000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ50); } else if (odr <= 100000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ100); } else if (odr <= 200000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ200); } else if (odr <= 400000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ400); } else if (odr <= 800000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ800); } else if (odr <= 1600000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ1600); } else if (odr <= 3200000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ3200); } else { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, ODR, HZ6400); } return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); } static int bosch_bmi323_driver_api_set_acc_full_scale(const struct device *dev, const struct sensor_value *val) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; uint16_t acc_conf; int64_t fullscale = sensor_value_to_milli(val); ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } acc_conf &= ~IMU_BOSCH_BMI323_REG_MASK(ACC_CONF, RANGE); if (fullscale <= 2000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, RANGE, G2); } else if (fullscale <= 4000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, RANGE, G4); } else if (fullscale <= 8000) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, RANGE, G8); } else { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, RANGE, G16); } data->acc_full_scale = 0; return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); } static int bosch_bmi323_driver_api_set_acc_feature_mask(const struct device *dev, const struct sensor_value *val) { int ret; uint16_t acc_conf; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } acc_conf &= ~IMU_BOSCH_BMI323_REG_MASK(ACC_CONF, MODE); if (val->val1) { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, MODE, HPWR); } else { acc_conf |= IMU_BOSCH_BMI323_REG_VALUE(ACC_CONF, MODE, DIS); } return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); } static int bosch_bmi323_driver_api_set_gyro_odr(const struct device *dev, const struct sensor_value *val) { int ret; uint16_t gyro_conf; int64_t odr = sensor_value_to_milli(val); ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } gyro_conf &= ~IMU_BOSCH_BMI323_REG_MASK(GYRO_CONF, ODR); if (odr <= 782) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ0P78125); } else if (odr <= 1563) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ1P5625); } else if (odr <= 3125) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ3P125); } else if (odr <= 6250) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ6P25); } else if (odr <= 12500) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ12P5); } else if (odr <= 25000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ25); } else if (odr <= 50000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ50); } else if (odr <= 100000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ100); } else if (odr <= 200000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ200); } else if (odr <= 400000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ400); } else if (odr <= 800000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ800); } else if (odr <= 1600000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ1600); } else if (odr <= 3200000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ3200); } else { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, ODR, HZ6400); } return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); } static int bosch_bmi323_driver_api_set_gyro_full_scale(const struct device *dev, const struct sensor_value *val) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; uint16_t gyro_conf; int32_t fullscale = sensor_value_to_milli(val); ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } gyro_conf &= ~IMU_BOSCH_BMI323_REG_MASK(GYRO_CONF, RANGE); if (fullscale <= 125000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, RANGE, DPS125); } else if (fullscale <= 250000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, RANGE, DPS250); } else if (fullscale <= 500000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, RANGE, DPS500); } else if (fullscale <= 1000000) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, RANGE, DPS1000); } else { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, RANGE, DPS2000); } data->gyro_full_scale = 0; return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); } static int bosch_bmi323_driver_api_set_gyro_feature_mask(const struct device *dev, const struct sensor_value *val) { int ret; uint16_t gyro_conf; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } gyro_conf &= ~IMU_BOSCH_BMI323_REG_MASK(GYRO_CONF, MODE); if (val->val1) { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, MODE, HPWR); } else { gyro_conf |= IMU_BOSCH_BMI323_REG_VALUE(GYRO_CONF, MODE, DIS); } return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); } static int bosch_bmi323_driver_api_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; k_mutex_lock(&data->lock, K_FOREVER); switch (chan) { case SENSOR_CHAN_ACCEL_XYZ: switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = bosch_bmi323_driver_api_set_acc_odr(dev, val); break; case SENSOR_ATTR_FULL_SCALE: ret = bosch_bmi323_driver_api_set_acc_full_scale(dev, val); break; case SENSOR_ATTR_FEATURE_MASK: ret = bosch_bmi323_driver_api_set_acc_feature_mask(dev, val); break; default: ret = -ENODEV; break; } break; case SENSOR_CHAN_GYRO_XYZ: switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = bosch_bmi323_driver_api_set_gyro_odr(dev, val); break; case SENSOR_ATTR_FULL_SCALE: ret = bosch_bmi323_driver_api_set_gyro_full_scale(dev, val); break; case SENSOR_ATTR_FEATURE_MASK: ret = bosch_bmi323_driver_api_set_gyro_feature_mask(dev, val); break; default: ret = -ENODEV; break; } break; default: ret = -ENODEV; break; } k_mutex_unlock(&data->lock); return ret; } static int bosch_bmi323_driver_api_get_acc_odr(const struct device *dev, struct sensor_value *val) { uint16_t acc_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } switch (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(acc_conf, ACC_CONF, ODR)) { case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ0P78125: val->val1 = 0; val->val2 = 781250; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ1P5625: val->val1 = 1; val->val2 = 562500; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ3P125: val->val1 = 3; val->val2 = 125000; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ6P25: val->val1 = 6; val->val2 = 250000; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ12P5: val->val1 = 12; val->val2 = 500000; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ25: val->val1 = 25; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ50: val->val1 = 50; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ100: val->val1 = 100; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ200: val->val1 = 200; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ400: val->val1 = 400; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ800: val->val1 = 800; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ1600: val->val1 = 1600; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ3200: val->val1 = 3200; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_ODR_VAL_HZ6400: val->val1 = 6400; val->val2 = 0; break; default: return -EINVAL; } return 0; } static int bosch_bmi323_driver_api_get_acc_full_scale(const struct device *dev, struct sensor_value *val) { uint16_t acc_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } switch (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(acc_conf, ACC_CONF, RANGE)) { case IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G2: val->val1 = 2; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G4: val->val1 = 4; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G8: val->val1 = 8; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_ACC_CONF_RANGE_VAL_G16: val->val1 = 16; val->val2 = 0; break; default: return -EINVAL; } return 0; } static int bosch_bmi323_driver_api_get_acc_feature_mask(const struct device *dev, struct sensor_value *val) { uint16_t acc_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_CONF, &acc_conf, 1); if (ret < 0) { return ret; } if (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(acc_conf, ACC_CONF, MODE)) { val->val1 = 1; val->val2 = 0; } else { val->val1 = 0; val->val2 = 0; } return 0; } static int bosch_bmi323_driver_api_get_gyro_odr(const struct device *dev, struct sensor_value *val) { uint16_t gyro_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } switch (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(gyro_conf, GYRO_CONF, ODR)) { case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ0P78125: val->val1 = 0; val->val2 = 781250; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ1P5625: val->val1 = 1; val->val2 = 562500; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ3P125: val->val1 = 3; val->val2 = 125000; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ6P25: val->val1 = 6; val->val2 = 250000; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ12P5: val->val1 = 12; val->val2 = 500000; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ25: val->val1 = 25; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ50: val->val1 = 50; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ100: val->val1 = 100; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ200: val->val1 = 200; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ400: val->val1 = 400; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ800: val->val1 = 800; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ1600: val->val1 = 1600; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ3200: val->val1 = 3200; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_ODR_VAL_HZ6400: val->val1 = 6400; val->val2 = 0; break; default: return -EINVAL; } return 0; } static int bosch_bmi323_driver_api_get_gyro_full_scale(const struct device *dev, struct sensor_value *val) { uint16_t gyro_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } switch (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(gyro_conf, GYRO_CONF, RANGE)) { case IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS125: val->val1 = 125; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS250: val->val1 = 250; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS500: val->val1 = 500; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS1000: val->val1 = 1000; val->val2 = 0; break; case IMU_BOSCH_BMI323_REG_GYRO_CONF_RANGE_VAL_DPS2000: val->val1 = 2000; val->val2 = 0; break; default: return -EINVAL; } return 0; } static int bosch_bmi323_driver_api_get_gyro_feature_mask(const struct device *dev, struct sensor_value *val) { uint16_t gyro_conf; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_CONF, &gyro_conf, 1); if (ret < 0) { return ret; } if (IMU_BOSCH_BMI323_REG_VALUE_GET_FIELD(gyro_conf, GYRO_CONF, MODE)) { val->val1 = 1; val->val2 = 0; } else { val->val1 = 0; val->val2 = 0; } return 0; } static int bosch_bmi323_driver_api_attr_get(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; k_mutex_lock(&data->lock, K_FOREVER); switch (chan) { case SENSOR_CHAN_ACCEL_XYZ: switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = bosch_bmi323_driver_api_get_acc_odr(dev, val); break; case SENSOR_ATTR_FULL_SCALE: ret = bosch_bmi323_driver_api_get_acc_full_scale(dev, val); break; case SENSOR_ATTR_FEATURE_MASK: ret = bosch_bmi323_driver_api_get_acc_feature_mask(dev, val); break; default: ret = -ENODEV; break; } break; case SENSOR_CHAN_GYRO_XYZ: switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: ret = bosch_bmi323_driver_api_get_gyro_odr(dev, val); break; case SENSOR_ATTR_FULL_SCALE: ret = bosch_bmi323_driver_api_get_gyro_full_scale(dev, val); break; case SENSOR_ATTR_FEATURE_MASK: ret = bosch_bmi323_driver_api_get_gyro_feature_mask(dev, val); break; default: ret = -ENODEV; break; } break; default: ret = -ENODEV; break; } k_mutex_unlock(&data->lock); return ret; } static int bosch_bmi323_driver_api_trigger_set_acc_drdy(const struct device *dev) { uint16_t buf[2]; buf[0] = 0; buf[1] = IMU_BOSCH_BMI323_REG_VALUE(INT_MAP2, ACC_DRDY_INT, INT1); return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_INT_MAP1, buf, 2); } static int bosch_bmi323_driver_api_trigger_set_acc_motion(const struct device *dev) { uint16_t buf[2]; int ret; buf[0] = IMU_BOSCH_BMI323_REG_VALUE(INT_MAP1, MOTION_OUT, INT1); buf[1] = 0; ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_INT_MAP1, buf, 2); if (ret < 0) { return ret; } buf[0] = 0; ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_IO0, buf, 1); if (ret < 0) { return ret; } buf[0] = IMU_BOSCH_BMI323_REG_VALUE(FEATURE_IO0, MOTION_X_EN, EN) | IMU_BOSCH_BMI323_REG_VALUE(FEATURE_IO0, MOTION_Y_EN, EN) | IMU_BOSCH_BMI323_REG_VALUE(FEATURE_IO0, MOTION_Z_EN, EN); ret = bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_IO0, buf, 1); if (ret < 0) { return ret; } buf[0] = 1; return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_FEATURE_IO_STATUS, buf, 1); } static int bosch_bmi323_driver_api_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret = -ENODEV; k_mutex_lock(&data->lock, K_FOREVER); data->trigger = trig; data->trigger_handler = handler; switch (trig->chan) { case SENSOR_CHAN_ACCEL_XYZ: switch (trig->type) { case SENSOR_TRIG_DATA_READY: ret = bosch_bmi323_driver_api_trigger_set_acc_drdy(dev); break; case SENSOR_TRIG_MOTION: ret = bosch_bmi323_driver_api_trigger_set_acc_motion(dev); break; default: break; } break; default: break; } k_mutex_unlock(&data->lock); return ret; } static int bosch_bmi323_driver_api_fetch_acc_samples(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; struct sensor_value full_scale; int16_t *buf = (int16_t *)data->acc_samples; int ret; int32_t lsb; if (data->acc_full_scale == 0) { ret = bosch_bmi323_driver_api_get_acc_full_scale(dev, &full_scale); if (ret < 0) { return ret; } data->acc_full_scale = sensor_value_to_milli(&full_scale); } ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_ACC_DATA_X, (uint16_t *)buf, 3); if (ret < 0) { return ret; } if ((bosch_bmi323_value_is_valid(buf[0]) == false) || (bosch_bmi323_value_is_valid(buf[1]) == false) || (bosch_bmi323_value_is_valid(buf[2]) == false)) { return -ENODATA; } lsb = bosch_bmi323_lsb_from_fullscale(data->acc_full_scale); /* Reuse vector backwards to avoid overwriting the raw values */ bosch_bmi323_value_to_sensor_value(&data->acc_samples[2], buf[2], lsb); bosch_bmi323_value_to_sensor_value(&data->acc_samples[1], buf[1], lsb); bosch_bmi323_value_to_sensor_value(&data->acc_samples[0], buf[0], lsb); data->acc_samples_valid = true; return 0; } static int bosch_bmi323_driver_api_fetch_gyro_samples(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; struct sensor_value full_scale; int16_t *buf = (int16_t *)data->gyro_samples; int ret; int32_t lsb; if (data->gyro_full_scale == 0) { ret = bosch_bmi323_driver_api_get_gyro_full_scale(dev, &full_scale); if (ret < 0) { return ret; } data->gyro_full_scale = sensor_value_to_milli(&full_scale); } ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_GYRO_DATA_X, (uint16_t *)buf, 3); if (ret < 0) { return ret; } if ((bosch_bmi323_value_is_valid(buf[0]) == false) || (bosch_bmi323_value_is_valid(buf[1]) == false) || (bosch_bmi323_value_is_valid(buf[2]) == false)) { return -ENODATA; } lsb = bosch_bmi323_lsb_from_fullscale(data->gyro_full_scale); /* Reuse vector backwards to avoid overwriting the raw values */ bosch_bmi323_value_to_sensor_value(&data->gyro_samples[2], buf[2], lsb); bosch_bmi323_value_to_sensor_value(&data->gyro_samples[1], buf[1], lsb); bosch_bmi323_value_to_sensor_value(&data->gyro_samples[0], buf[0], lsb); data->gyro_samples_valid = true; return 0; } static int bosch_bmi323_driver_api_fetch_temperature(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int16_t buf; int64_t micro; int ret; ret = bosch_bmi323_bus_read_words(dev, IMU_BOSCH_BMI323_REG_TEMP_DATA, &buf, 1); if (ret < 0) { return ret; } if (bosch_bmi323_value_is_valid(buf) == false) { return -ENODATA; } micro = bosch_bmi323_value_to_micro(buf, IMU_BOSCH_DIE_TEMP_MICRO_DEG_CELCIUS_LSB); micro += IMU_BOSCH_DIE_TEMP_OFFSET_MICRO_DEG_CELCIUS; bosch_bmi323_sensor_value_from_micro(&data->temperature, micro); data->temperature_valid = true; return 0; } static int bosch_bmi323_driver_api_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; k_mutex_lock(&data->lock, K_FOREVER); switch (chan) { case SENSOR_CHAN_ACCEL_XYZ: ret = bosch_bmi323_driver_api_fetch_acc_samples(dev); break; case SENSOR_CHAN_GYRO_XYZ: ret = bosch_bmi323_driver_api_fetch_gyro_samples(dev); break; case SENSOR_CHAN_DIE_TEMP: ret = bosch_bmi323_driver_api_fetch_temperature(dev); break; case SENSOR_CHAN_ALL: ret = bosch_bmi323_driver_api_fetch_acc_samples(dev); if (ret < 0) { break; } ret = bosch_bmi323_driver_api_fetch_gyro_samples(dev); if (ret < 0) { break; } ret = bosch_bmi323_driver_api_fetch_temperature(dev); break; default: ret = -ENODEV; break; } k_mutex_unlock(&data->lock); return ret; } static int bosch_bmi323_driver_api_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret = 0; k_mutex_lock(&data->lock, K_FOREVER); switch (chan) { case SENSOR_CHAN_ACCEL_XYZ: if (data->acc_samples_valid == false) { ret = -ENODATA; break; } memcpy(val, data->acc_samples, sizeof(data->acc_samples)); break; case SENSOR_CHAN_GYRO_XYZ: if (data->gyro_samples_valid == false) { ret = -ENODATA; break; } memcpy(val, data->gyro_samples, sizeof(data->gyro_samples)); break; case SENSOR_CHAN_DIE_TEMP: if (data->temperature_valid == false) { ret = -ENODATA; break; } (*val) = data->temperature; break; default: ret = -ENOTSUP; break; } k_mutex_unlock(&data->lock); return ret; } static const struct sensor_driver_api bosch_bmi323_api = { .attr_set = bosch_bmi323_driver_api_attr_set, .attr_get = bosch_bmi323_driver_api_attr_get, .trigger_set = bosch_bmi323_driver_api_trigger_set, .sample_fetch = bosch_bmi323_driver_api_sample_fetch, .channel_get = bosch_bmi323_driver_api_channel_get, }; static void bosch_bmi323_irq_callback(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; k_work_submit(&data->callback_work); } static int bosch_bmi323_init_irq(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; struct bosch_bmi323_config *config = (struct bosch_bmi323_config *)dev->config; int ret; ret = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); if (ret < 0) { return ret; } gpio_init_callback(&data->gpio_callback, config->int_gpio_callback, BIT(config->int_gpio.pin)); ret = gpio_add_callback(config->int_gpio.port, &data->gpio_callback); if (ret < 0) { return ret; } return gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_DISABLE); } static int bosch_bmi323_init_int1(const struct device *dev) { uint16_t buf; buf = IMU_BOSCH_BMI323_REG_VALUE(IO_INT_CTRL, INT1_LVL, ACT_HIGH) | IMU_BOSCH_BMI323_REG_VALUE(IO_INT_CTRL, INT1_OD, PUSH_PULL) | IMU_BOSCH_BMI323_REG_VALUE(IO_INT_CTRL, INT1_OUTPUT_EN, EN); return bosch_bmi323_bus_write_words(dev, IMU_BOSCH_BMI323_REG_IO_INT_CTRL, &buf, 1); } static void bosch_bmi323_irq_callback_handler(struct k_work *item) { struct bosch_bmi323_data *data = CONTAINER_OF(item, struct bosch_bmi323_data, callback_work); k_mutex_lock(&data->lock, K_FOREVER); if (data->trigger_handler != NULL) { data->trigger_handler(data->dev, data->trigger); } k_mutex_unlock(&data->lock); } static int bosch_bmi323_pm_resume(const struct device *dev) { const struct bosch_bmi323_config *config = (const struct bosch_bmi323_config *)dev->config; int ret; ret = bosch_bmi323_bus_init(dev); if (ret < 0) { LOG_WRN("Failed to init bus"); return ret; } ret = bosch_bmi323_validate_chip_id(dev); if (ret < 0) { LOG_WRN("Failed to validate chip id"); return ret; } ret = bosch_bmi323_soft_reset(dev); if (ret < 0) { LOG_WRN("Failed to soft reset chip"); return ret; } ret = bosch_bmi323_bus_init(dev); if (ret < 0) { LOG_WRN("Failed to re-init bus"); return ret; } ret = bosch_bmi323_enable_feature_engine(dev); if (ret < 0) { LOG_WRN("Failed to enable feature engine"); return ret; } ret = bosch_bmi323_init_int1(dev); if (ret < 0) { LOG_WRN("Failed to enable INT1"); return ret; } ret = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); if (ret < 0) { LOG_WRN("Failed to configure int"); } return ret; } #ifdef CONFIG_PM_DEVICE static int bosch_bmi323_pm_suspend(const struct device *dev) { const struct bosch_bmi323_config *config = (const struct bosch_bmi323_config *)dev->config; int ret; ret = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_DISABLE); if (ret < 0) { LOG_WRN("Failed to disable int"); } /* Soft reset device to put it into suspend */ return bosch_bmi323_soft_reset(dev); } #endif /* CONFIG_PM_DEVICE */ #ifdef CONFIG_PM_DEVICE static int bosch_bmi323_pm_action(const struct device *dev, enum pm_device_action action) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; k_mutex_lock(&data->lock, K_FOREVER); switch (action) { case PM_DEVICE_ACTION_RESUME: ret = bosch_bmi323_pm_resume(dev); break; case PM_DEVICE_ACTION_SUSPEND: ret = bosch_bmi323_pm_suspend(dev); break; default: ret = -ENOTSUP; break; } k_mutex_unlock(&data->lock); return ret; } #endif /* CONFIG_PM_DEVICE */ static int bosch_bmi323_init(const struct device *dev) { struct bosch_bmi323_data *data = (struct bosch_bmi323_data *)dev->data; int ret; k_mutex_init(&data->lock); k_work_init(&data->callback_work, bosch_bmi323_irq_callback_handler); data->dev = dev; ret = bosch_bmi323_init_irq(dev); if (ret < 0) { LOG_WRN("Failed to init irq"); return ret; } #ifndef CONFIG_PM_DEVICE_RUNTIME ret = bosch_bmi323_pm_resume(dev); if (ret < 0) { LOG_WRN("Failed to initialize device"); } #else pm_device_init_suspended(dev); ret = pm_device_runtime_enable(dev); if (ret < 0) { LOG_WRN("Failed to enable device pm runtime"); } #endif /* CONFIG_PM_DEVICE_RUNTIME */ return ret; } /* * Currently only support for the SPI bus is implemented. This shall be updated to * select the appropriate bus once I2C is implemented. */ #define BMI323_DEVICE_BUS(inst) \ BUILD_ASSERT(DT_INST_ON_BUS(inst, spi), "Unimplemented bus"); \ BMI323_DEVICE_SPI_BUS(inst) #define BMI323_DEVICE(inst) \ static struct bosch_bmi323_data bosch_bmi323_data_##inst; \ \ BMI323_DEVICE_BUS(inst); \ \ static void bosch_bmi323_irq_callback##inst(const struct device *dev, \ struct gpio_callback *cb, uint32_t pins) \ { \ bosch_bmi323_irq_callback(DEVICE_DT_INST_GET(inst)); \ } \ \ static const struct bosch_bmi323_config bosch_bmi323_config_##inst = { \ .bus = &bosch_bmi323_bus_api##inst, \ .int_gpio = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \ .int_gpio_callback = bosch_bmi323_irq_callback##inst, \ }; \ \ PM_DEVICE_DT_INST_DEFINE(inst, bosch_bmi323_pm_action); \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, bosch_bmi323_init, PM_DEVICE_DT_INST_GET(inst), \ &bosch_bmi323_data_##inst, &bosch_bmi323_config_##inst, \ POST_KERNEL, 99, &bosch_bmi323_api); DT_INST_FOREACH_STATUS_OKAY(BMI323_DEVICE) ```
/content/code_sandbox/drivers/sensor/bosch/bmi323/bmi323.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
10,511
```c /* * */ /* * Bus-specific functionality for BME680s accessed via SPI. */ #include <zephyr/logging/log.h> #include "bme680.h" #if BME680_BUS_SPI LOG_MODULE_DECLARE(bme680, CONFIG_SENSOR_LOG_LEVEL); static int bme680_bus_check_spi(const union bme680_bus *bus) { return spi_is_ready_dt(&bus->spi) ? 0 : -ENODEV; } static inline int bme680_set_mem_page(const struct device *dev, uint8_t addr) { const struct bme680_config *config = dev->config; struct bme680_data *data = dev->data; uint8_t page = (addr > 0x7f) ? 0U : 1U; int err = 0; if (data->mem_page != page) { uint8_t buf[2]; struct spi_buf tx_buf = { .buf = &buf[0], .len = 1, }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1, }; const struct spi_buf rx_buf[] = { { .buf = NULL, .len = 1 }, { .buf = &buf[1], .len = 1 }, }; const struct spi_buf_set rx = { .buffers = rx_buf, .count = ARRAY_SIZE(rx_buf), }; buf[0] = BME680_REG_STATUS | BME680_SPI_READ_BIT; err = spi_transceive_dt(&config->bus.spi, &tx, &rx); if (err < 0) { return err; } if (data->mem_page == 1U) { buf[1] &= ~BME680_SPI_MEM_PAGE_MSK; } else { buf[1] |= BME680_SPI_MEM_PAGE_MSK; } buf[0] = BME680_REG_STATUS & BME680_SPI_WRITE_MSK; tx_buf.len = 2; err = spi_write_dt(&config->bus.spi, &tx); if (err < 0) { return err; } data->mem_page = page; } return err; } static int bme680_reg_write_spi(const struct device *dev, uint8_t reg, uint8_t val) { const struct bme680_config *config = dev->config; int err; uint8_t cmd[] = { reg & BME680_SPI_WRITE_MSK, val }; const struct spi_buf tx_buf = { .buf = cmd, .len = sizeof(cmd) }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; err = bme680_set_mem_page(dev, reg); if (err) { return err; } err = spi_write_dt(&config->bus.spi, &tx); return err; } static int bme680_reg_read_spi(const struct device *dev, uint8_t start, uint8_t *buf, int size) { const struct bme680_config *config = dev->config; int err; uint8_t addr; const struct spi_buf tx_buf = { .buf = &addr, .len = 1 }; const struct spi_buf_set tx = { .buffers = &tx_buf, .count = 1 }; struct spi_buf rx_buf[2]; const struct spi_buf_set rx = { .buffers = rx_buf, .count = ARRAY_SIZE(rx_buf) }; rx_buf[0].buf = NULL; rx_buf[0].len = 1; addr = start | BME680_SPI_READ_BIT; rx_buf[1].buf = buf; rx_buf[1].len = size; err = bme680_set_mem_page(dev, start); if (err) { return err; } err = spi_transceive_dt(&config->bus.spi, &tx, &rx); return err; } const struct bme680_bus_io bme680_bus_io_spi = { .check = bme680_bus_check_spi, .read = bme680_reg_read_spi, .write = bme680_reg_write_spi, }; #endif /* BME680_BUS_SPI */ ```
/content/code_sandbox/drivers/sensor/bosch/bme680/bme680_spi.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
925
```c /* * */ /* * Bus-specific functionality for BME680s accessed via I2C. */ #include "bme680.h" #if BME680_BUS_I2C static int bme680_bus_check_i2c(const union bme680_bus *bus) { return device_is_ready(bus->i2c.bus) ? 0 : -ENODEV; } static int bme680_reg_read_i2c(const struct device *dev, uint8_t start, uint8_t *buf, int size) { const struct bme680_config *config = dev->config; return i2c_burst_read_dt(&config->bus.i2c, start, buf, size); } static int bme680_reg_write_i2c(const struct device *dev, uint8_t reg, uint8_t val) { const struct bme680_config *config = dev->config; return i2c_reg_write_byte_dt(&config->bus.i2c, reg, val); } const struct bme680_bus_io bme680_bus_io_i2c = { .check = bme680_bus_check_i2c, .read = bme680_reg_read_i2c, .write = bme680_reg_write_i2c, }; #endif /* BME680_BUS_I2C */ ```
/content/code_sandbox/drivers/sensor/bosch/bme680/bme680_i2c.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
271
```unknown # BME680 temperature, pressure, humidity and gas sensor configuration options # menuconfig BME680 bool "BME680 sensor" default y depends on DT_HAS_BOSCH_BME680_ENABLED select I2C if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME680),i2c) select SPI if $(dt_compat_on_bus,$(DT_COMPAT_BOSCH_BME680),spi) help Enable driver for BME680 I2C- or SPI- based temperature, pressure, humidity and gas sensor. if BME680 choice prompt "BME680 temperature oversampling" default BME680_TEMP_OVER_2X help Select temperature oversampling for the BME680 sensor. Higher values lead to more accurate readings, but higher power consumption. config BME680_TEMP_OVER_1X bool "x1" config BME680_TEMP_OVER_2X bool "x2" config BME680_TEMP_OVER_4X bool "x4" config BME680_TEMP_OVER_8X bool "x8" config BME680_TEMP_OVER_16X bool "x16" endchoice choice prompt "BME680 pressure oversampling" default BME680_PRESS_OVER_16X help Select pressure oversampling for the BME680 sensor. Higher values lead to more accurate readings, but higher power consumption. config BME680_PRESS_OVER_1X bool "x1" config BME680_PRESS_OVER_2X bool "x2" config BME680_PRESS_OVER_4X bool "x4" config BME680_PRESS_OVER_8X bool "x8" config BME680_PRESS_OVER_16X bool "x16" endchoice choice prompt "BME680 humidity oversampling" default BME680_HUMIDITY_OVER_1X help Select humidity oversampling for the BME680 sensor. Higher values lead to more accurate readings, but higher power consumption. config BME680_HUMIDITY_OVER_1X bool "x1" config BME680_HUMIDITY_OVER_2X bool "x2" config BME680_HUMIDITY_OVER_4X bool "x4" config BME680_HUMIDITY_OVER_8X bool "x8" config BME680_HUMIDITY_OVER_16X bool "x16" endchoice choice prompt "BME680 IIR low-pass filter coefficient" default BME680_FILTER_OFF help Select the filter coefficient for the BME680 sensor. config BME680_FILTER_OFF bool "filter off" config BME680_FILTER_2 bool "2" config BME680_FILTER_4 bool "4" config BME680_FILTER_8 bool "8" config BME680_FILTER_16 bool "16" config BME680_FILTER_32 bool "32" config BME680_FILTER_64 bool "64" config BME680_FILTER_128 bool "128" endchoice choice prompt "BME680 gas sensor's heater temperature in degree Celsius" default BME680_HEATR_TEMP_LP help Select the gas sensor's heater temperature for the BME680 sensor. config BME680_HEATR_TEMP_LP bool "320" config BME680_HEATR_TEMP_ULP bool "400" endchoice choice prompt "BME680 gas sensor's heating duration in milliseconds" default BME680_HEATR_DUR_LP help Select the gas sensor's heating duration for the BME680 sensor. config BME680_HEATR_DUR_LP bool "197" config BME680_HEATR_DUR_ULP bool "1943" endchoice endif # BME680 ```
/content/code_sandbox/drivers/sensor/bosch/bme680/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
827
```unknown # zephyr-keep-sorted-start source "drivers/sensor/maxim/ds18b20/Kconfig" source "drivers/sensor/maxim/max17055/Kconfig" source "drivers/sensor/maxim/max17262/Kconfig" source "drivers/sensor/maxim/max30101/Kconfig" source "drivers/sensor/maxim/max31790/Kconfig" source "drivers/sensor/maxim/max31855/Kconfig" source "drivers/sensor/maxim/max31865/Kconfig" source "drivers/sensor/maxim/max31875/Kconfig" source "drivers/sensor/maxim/max44009/Kconfig" source "drivers/sensor/maxim/max6675/Kconfig" # zephyr-keep-sorted-stop ```
/content/code_sandbox/drivers/sensor/maxim/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
154
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17055_H_ #define ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17055_H_ #include <zephyr/drivers/i2c.h> /* Register addresses */ enum { STATUS = 0x0, REP_CAP = 0x5, REP_SOC = 0x6, INT_TEMP = 0x8, VCELL = 0x9, AVG_CURRENT = 0xb, FULL_CAP_REP = 0x10, TTE = 0x11, ICHG_TERM = 0x1e, CYCLES = 0x17, DESIGN_CAP = 0x18, TTF = 0x20, V_EMPTY = 0x3a, FSTAT = 0x3d, D_QACC = 0x45, D_PACC = 0x46, SOFT_WAKEUP = 0x60, HIB_CFG = 0xba, MODEL_CFG = 0xdb, VFOCV = 0xfb, }; /* Masks */ enum { FSTAT_DNR = 0x0001, HIB_CFG_CLEAR = 0x0000, MODELCFG_REFRESH = 0x8000, SOFT_WAKEUP_CLEAR = 0x0000, SOFT_WAKEUP_WAKEUP = 0x0090, STATUS_POR = 0x0002, VEMPTY_VE = 0xff80, }; struct max17055_data { /* Current cell voltage in units of 1.25/16mV */ uint16_t voltage; /* Current cell open circuit voltage in units of 1.25/16mV */ uint16_t ocv; /* Average current in units of 1.5625uV / Rsense */ int16_t avg_current; /* Remaining capacity as a %age */ uint16_t state_of_charge; /* Internal temperature in units of 1/256 degrees C */ int16_t internal_temp; /* Full charge capacity in 5/Rsense uA */ uint16_t full_cap; /* Remaining capacity in 5/Rsense uA */ uint16_t remaining_cap; /* Time to empty in units of 5.625s */ uint16_t time_to_empty; /* Time to full in units of 5.625s */ uint16_t time_to_full; /* Cycle count in 1/100ths (number of charge/discharge cycles) */ uint16_t cycle_count; /* Design capacity in 5/Rsense uA */ uint16_t design_cap; }; struct max17055_config { struct i2c_dt_spec i2c; /* Value of Rsense resistor in milliohms (typically 5 or 10) */ uint16_t rsense_mohms; /* The design capacity (aka label capacity) of the cell in mAh */ uint16_t design_capacity; /* Design voltage of cell in mV */ uint16_t design_voltage; /* Desired voltage of cell in mV */ uint16_t desired_voltage; /* Desired charging current in mA */ uint16_t desired_charging_current; /* The charge termination current in uA */ uint16_t i_chg_term; /* The empty voltage of the cell in mV */ uint16_t v_empty; }; #endif ```
/content/code_sandbox/drivers/sensor/maxim/max17055/max17055.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
737
```objective-c /* * */ #ifndef __ZEPHYR_DRIVERS_SENSOR_BME680_H__ #define __ZEPHYR_DRIVERS_SENSOR_BME680_H__ #include <zephyr/types.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/spi.h> #include <zephyr/drivers/i2c.h> #define DT_DRV_COMPAT bosch_bme680 #define BME680_BUS_SPI DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) #define BME680_BUS_I2C DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) union bme680_bus { #if BME680_BUS_SPI struct spi_dt_spec spi; #endif #if BME680_BUS_I2C struct i2c_dt_spec i2c; #endif }; typedef int (*bme680_bus_check_fn)(const union bme680_bus *bus); typedef int (*bme680_reg_read_fn)(const struct device *dev, uint8_t start, uint8_t *buf, int size); typedef int (*bme680_reg_write_fn)(const struct device *dev, uint8_t reg, uint8_t val); struct bme680_bus_io { bme680_bus_check_fn check; bme680_reg_read_fn read; bme680_reg_write_fn write; }; #if BME680_BUS_SPI #define BME680_SPI_OPERATION (SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL \ | SPI_MODE_CPHA | SPI_OP_MODE_MASTER) extern const struct bme680_bus_io bme680_bus_io_spi; #endif #if BME680_BUS_I2C extern const struct bme680_bus_io bme680_bus_io_i2c; #endif struct bme680_config { union bme680_bus bus; const struct bme680_bus_io *bus_io; }; #define BME680_CHIP_ID 0x61 #define BME680_LEN_COEFF_ALL 42 #define BME680_LEN_COEFF1 23 #define BME680_LEN_COEFF2 14 #define BME680_LEN_COEFF3 5 #define BME680_REG_COEFF3 0x00 #define BME680_REG_MEAS_STATUS 0x1D #define BME680_REG_FIELD0 0x1F #define BME680_REG_IDAC_HEAT0 0x50 #define BME680_REG_RES_HEAT0 0x5A #define BME680_REG_GAS_WAIT0 0x64 #define BME680_REG_SHD_HEATR_DUR 0x6E #define BME680_REG_CTRL_GAS_0 0x70 #define BME680_REG_CTRL_GAS_1 0x71 #define BME680_REG_CTRL_HUM 0x72 #define BME680_REG_STATUS 0x73 #define BME680_REG_CTRL_MEAS 0x74 #define BME680_REG_CONFIG 0x75 #define BME680_REG_UNIQUE_ID 0x83 #define BME680_REG_COEFF1 0x8a #define BME680_REG_COEFF2 0xe1 #define BME680_REG_CHIP_ID 0xd0 #define BME680_REG_SOFT_RESET 0xe0 #define BME680_MSK_NEW_DATA 0x80 #define BME680_MSK_GAS_RANGE 0x0f #define BME680_MSK_RH_RANGE 0x30 #define BME680_MSK_RANGE_SW_ERR 0xf0 #define BME680_MSK_HEATR_STAB 0x10 #define BME680_SPI_MEM_PAGE_MSK 0x10 #define BME680_SPI_MEM_PAGE_POS 4 #define BME680_SPI_READ_BIT 0x80 #define BME680_SPI_WRITE_MSK 0x7f #if defined CONFIG_BME680_TEMP_OVER_1X #define BME680_TEMP_OVER (1 << 5) #elif defined CONFIG_BME680_TEMP_OVER_2X #define BME680_TEMP_OVER (2 << 5) #elif defined CONFIG_BME680_TEMP_OVER_4X #define BME680_TEMP_OVER (3 << 5) #elif defined CONFIG_BME680_TEMP_OVER_8X #define BME680_TEMP_OVER (4 << 5) #elif defined CONFIG_BME680_TEMP_OVER_16X #define BME680_TEMP_OVER (5 << 5) #endif #if defined CONFIG_BME680_PRESS_OVER_1X #define BME680_PRESS_OVER (1 << 2) #elif defined CONFIG_BME680_PRESS_OVER_2X #define BME680_PRESS_OVER (2 << 2) #elif defined CONFIG_BME680_PRESS_OVER_4X #define BME680_PRESS_OVER (3 << 2) #elif defined CONFIG_BME680_PRESS_OVER_8X #define BME680_PRESS_OVER (4 << 2) #elif defined CONFIG_BME680_PRESS_OVER_16X #define BME680_PRESS_OVER (5 << 2) #endif #if defined CONFIG_BME680_HUMIDITY_OVER_1X #define BME680_HUMIDITY_OVER 1 #elif defined CONFIG_BME680_HUMIDITY_OVER_2X #define BME680_HUMIDITY_OVER 2 #elif defined CONFIG_BME680_HUMIDITY_OVER_4X #define BME680_HUMIDITY_OVER 3 #elif defined CONFIG_BME680_HUMIDITY_OVER_8X #define BME680_HUMIDITY_OVER 4 #elif defined CONFIG_BME680_HUMIDITY_OVER_16X #define BME680_HUMIDITY_OVER 5 #endif #if defined CONFIG_BME680_HEATR_TEMP_LP #define BME680_HEATR_TEMP 320 #elif defined CONFIG_BME680_HEATR_TEMP_ULP #define BME680_HEATR_TEMP 400 #endif #if defined CONFIG_BME680_HEATR_DUR_LP #define BME680_HEATR_DUR_MS 197 #elif defined CONFIG_BME680_HEATR_DUR_ULP #define BME680_HEATR_DUR_MS 1943 #endif #if defined CONFIG_BME680_FILTER_OFF #define BME680_FILTER 0 #elif defined CONFIG_BME680_FILTER_2 #define BME680_FILTER (1 << 2) #elif defined CONFIG_BME680_FILTER_4 #define BME680_FILTER (2 << 2) #elif defined CONFIG_BME680_FILTER_8 #define BME680_FILTER (3 << 2) #elif defined CONFIG_BME680_FILTER_16 #define BME680_FILTER (4 << 2) #elif defined CONFIG_BME680_FILTER_32 #define BME680_FILTER (5 << 2) #elif defined CONFIG_BME680_FILTER_64 #define BME680_FILTER (6 << 2) #elif defined CONFIG_BME680_FILTER_128 #define BME680_FILTER (7 << 2) #endif #define BME680_MODE_SLEEP 0 #define BME680_MODE_FORCED 1 #define BME680_CTRL_MEAS_VAL (BME680_PRESS_OVER | BME680_TEMP_OVER \ | BME680_MODE_FORCED) #define BME680_CONFIG_VAL BME680_FILTER #define BME680_CTRL_GAS_1_VAL 0x10 #define BME680_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb) struct bme680_data { /* Compensation parameters. */ uint16_t par_h1; uint16_t par_h2; int8_t par_h3; int8_t par_h4; int8_t par_h5; uint8_t par_h6; int8_t par_h7; int8_t par_gh1; int16_t par_gh2; int8_t par_gh3; uint16_t par_t1; int16_t par_t2; int8_t par_t3; uint16_t par_p1; int16_t par_p2; int8_t par_p3; int16_t par_p4; int16_t par_p5; int8_t par_p6; int8_t par_p7; int16_t par_p8; int16_t par_p9; uint8_t par_p10; uint8_t res_heat_range; int8_t res_heat_val; int8_t range_sw_err; /* Calculated sensor values. */ int32_t calc_temp; uint32_t calc_press; uint32_t calc_humidity; uint32_t calc_gas_resistance; /* Additional information */ uint8_t heatr_stab; /* Carryover between temperature and pressure/humidity compensation. */ int32_t t_fine; uint8_t chip_id; #if BME680_BUS_SPI uint8_t mem_page; #endif }; #endif /* __ZEPHYR_DRIVERS_SENSOR_BME680_H__ */ ```
/content/code_sandbox/drivers/sensor/bosch/bme680/bme680.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,933
```unknown # config MAX17055 bool "MAX17055 Fuel Gauge" default y depends on DT_HAS_MAXIM_MAX17055_ENABLED select I2C help Enable I2C-based driver for MAX17055 Fuel Gauge. This driver supports reading various sensor settings including charge level percentage, time to full/empty, design voltage, temperature and remaining capacity in mA. ```
/content/code_sandbox/drivers/sensor/maxim/max17055/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
84
```c /* * */ /** * Driver for DS18B20 1-Wire temperature sensors * A datasheet is available at: * path_to_url * * Driver also support the older DS18S20 1-Wire temperature sensors. * path_to_url * * Parasite power configuration is not supported by the driver. */ #include <stdbool.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/sensor/w1_sensor.h> #include "zephyr/drivers/w1.h" #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/util_macro.h> LOG_MODULE_REGISTER(DS18B20, CONFIG_SENSOR_LOG_LEVEL); #define DS18B20_CMD_CONVERT_T 0x44 #define DS18B20_CMD_WRITE_SCRATCHPAD 0x4E #define DS18B20_CMD_READ_SCRATCHPAD 0xBE #define DS18B20_CMD_COPY_SCRATCHPAD 0x48 #define DS18B20_CMD_RECALL_EEPROM 0xB8 #define DS18B20_CMD_READ_POWER_SUPPLY 0xB4 /* resolution is set using bit 5 and 6 of configuration register * macro only valid for values 9 to 12 */ #define DS18B20_RESOLUTION_POS 5 #define DS18B20_RESOLUTION_MASK (BIT_MASK(2) << DS18B20_RESOLUTION_POS) /* convert resolution in bits to scratchpad config format */ #define DS18B20_RESOLUTION(res) ((res - 9) << DS18B20_RESOLUTION_POS) /* convert resolution in bits to array index (for resolution specific elements) */ #define DS18B20_RESOLUTION_INDEX(res) (res - 9) #define DS18B20_FAMILYCODE 0x28 #define DS18S20_FAMILYCODE 0x10 enum chip_type {type_ds18b20, type_ds18s20}; struct ds18b20_scratchpad { int16_t temp; uint8_t alarm_temp_high; uint8_t alarm_temp_low; uint8_t config; uint8_t res[3]; uint8_t crc; } __packed; struct ds18b20_config { const struct device *bus; uint8_t family; uint8_t resolution; enum chip_type chip; }; struct ds18b20_data { struct w1_slave_config config; struct ds18b20_scratchpad scratchpad; bool lazy_loaded; }; static int ds18b20_configure(const struct device *dev); static int ds18b20_read_scratchpad(const struct device *dev, struct ds18b20_scratchpad *scratchpad); /* measure wait time for 9-bit, 10-bit, 11-bit, 12-bit resolution respectively */ static const uint16_t measure_wait_ds18b20_ms[4] = { 94, 188, 376, 750 }; /* ds18s20 always needs 750ms */ static const uint16_t measure_wait_ds18s20_ms = { 750 }; static inline void ds18b20_temperature_from_raw(const struct device *dev, uint8_t *temp_raw, struct sensor_value *val) { const struct ds18b20_config *cfg = dev->config; int16_t temp = sys_get_le16 (temp_raw); if (cfg->chip == type_ds18s20) { val->val1 = temp / 2; val->val2 = (temp % 2) * 5000000; } else { val->val1 = temp / 16; val->val2 = (temp % 16) * 1000000 / 16; } } static inline bool slave_responded(uint8_t *rx_buf, size_t len) { uint8_t cmp_byte = 0xff; for (int i = 0; i < len; i++) { cmp_byte &= rx_buf[i]; } return (cmp_byte == 0xff) ? false : true; } /* * Write scratch pad, read back, then copy to eeprom */ static int ds18b20_write_scratchpad(const struct device *dev, struct ds18b20_scratchpad scratchpad) { struct ds18b20_data *data = dev->data; const struct ds18b20_config *cfg = dev->config; const struct device *bus = cfg->bus; int ret; uint8_t sp_data[4] = { DS18B20_CMD_WRITE_SCRATCHPAD, scratchpad.alarm_temp_high, scratchpad.alarm_temp_low, scratchpad.config }; ret = w1_write_read(bus, &data->config, sp_data, sizeof(sp_data), NULL, 0); if (ret != 0) { return ret; } ret = ds18b20_read_scratchpad(dev, &scratchpad); if (ret != 0) { return ret; } if ((sp_data[3] & DS18B20_RESOLUTION_MASK) != (scratchpad.config & DS18B20_RESOLUTION_MASK)) { return -EIO; } return 0; } static int ds18b20_read_scratchpad(const struct device *dev, struct ds18b20_scratchpad *scratchpad) { struct ds18b20_data *data = dev->data; const struct ds18b20_config *cfg = dev->config; const struct device *bus = cfg->bus; int ret; uint8_t cmd = DS18B20_CMD_READ_SCRATCHPAD; uint8_t crc; memset(scratchpad, 0, sizeof(*scratchpad)); ret = w1_write_read(bus, &data->config, &cmd, 1, (uint8_t *)scratchpad, sizeof(*scratchpad)); if (ret != 0) { return ret; } if (!slave_responded((uint8_t *)scratchpad, sizeof(*scratchpad))) { LOG_WRN("Slave not reachable"); return -ENODEV; } crc = w1_crc8((uint8_t *)scratchpad, sizeof(*scratchpad) - 1); if (crc != scratchpad->crc) { LOG_WRN("CRC does not match"); return -EIO; } return 0; } /* Starts sensor temperature conversion without waiting for completion. */ static int ds18b20_temperature_convert(const struct device *dev) { int ret; struct ds18b20_data *data = dev->data; const struct ds18b20_config *cfg = dev->config; const struct device *bus = cfg->bus; (void)w1_lock_bus(bus); ret = w1_reset_select(bus, &data->config); if (ret != 0) { goto out; } ret = w1_write_byte(bus, DS18B20_CMD_CONVERT_T); out: (void)w1_unlock_bus(bus); return ret; } /* * Write resolution into configuration struct, * but don't write it to the sensor yet. */ static void ds18b20_set_resolution(const struct device *dev, uint8_t resolution) { struct ds18b20_data *data = dev->data; data->scratchpad.config &= ~DS18B20_RESOLUTION_MASK; data->scratchpad.config |= DS18B20_RESOLUTION(resolution); } static uint16_t measure_wait_ms(const struct device *dev) { const struct ds18b20_config *cfg = dev->config; if (cfg->chip == type_ds18s20) { return measure_wait_ds18s20_ms; } return measure_wait_ds18b20_ms[DS18B20_RESOLUTION_INDEX(cfg->resolution)]; } static int ds18b20_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct ds18b20_data *data = dev->data; int status; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP); if (!data->lazy_loaded) { status = ds18b20_configure(dev); if (status < 0) { return status; } data->lazy_loaded = true; } status = ds18b20_temperature_convert(dev); if (status < 0) { LOG_DBG("W1 fetch error"); return status; } k_msleep(measure_wait_ms(dev)); return ds18b20_read_scratchpad(dev, &data->scratchpad); } static int ds18b20_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct ds18b20_data *data = dev->data; if (chan != SENSOR_CHAN_AMBIENT_TEMP) { return -ENOTSUP; } ds18b20_temperature_from_raw(dev, (uint8_t *)&data->scratchpad.temp, val); return 0; } static int ds18b20_configure(const struct device *dev) { const struct ds18b20_config *cfg = dev->config; struct ds18b20_data *data = dev->data; int ret; if (w1_reset_bus(cfg->bus) <= 0) { LOG_ERR("No 1-Wire slaves connected"); return -ENODEV; } /* In single drop configurations the rom can be read from device */ if (w1_get_slave_count(cfg->bus) == 1) { if (w1_rom_to_uint64(&data->config.rom) == 0ULL) { (void)w1_read_rom(cfg->bus, &data->config.rom); } } else if (w1_rom_to_uint64(&data->config.rom) == 0ULL) { LOG_DBG("nr: %d", w1_get_slave_count(cfg->bus)); LOG_ERR("ROM required, because multiple slaves are on the bus"); return -EINVAL; } if ((cfg->family != 0) && (cfg->family != data->config.rom.family)) { LOG_ERR("Found 1-Wire slave is not a %s", dev->name); return -EINVAL; } /* write default configuration */ if (cfg->chip == type_ds18b20) { ds18b20_set_resolution(dev, cfg->resolution); ret = ds18b20_write_scratchpad(dev, data->scratchpad); if (ret < 0) { return ret; } } LOG_DBG("Init %s: ROM=%016llx\n", dev->name, w1_rom_to_uint64(&data->config.rom)); return 0; } int ds18b20_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *thr) { struct ds18b20_data *data = dev->data; if ((enum sensor_attribute_w1)attr != SENSOR_ATTR_W1_ROM) { return -ENOTSUP; } data->lazy_loaded = false; w1_sensor_value_to_rom(thr, &data->config.rom); return 0; } static const struct sensor_driver_api ds18b20_driver_api = { .attr_set = ds18b20_attr_set, .sample_fetch = ds18b20_sample_fetch, .channel_get = ds18b20_channel_get, }; static int ds18b20_init(const struct device *dev) { const struct ds18b20_config *cfg = dev->config; struct ds18b20_data *data = dev->data; if (device_is_ready(cfg->bus) == 0) { LOG_DBG("w1 bus is not ready"); return -ENODEV; } w1_uint64_to_rom(0ULL, &data->config.rom); data->lazy_loaded = false; /* in multidrop configurations the rom is need, but is not set during * driver initialization, therefore do lazy initialization in all cases. */ return 0; } #define DS18B20_CONFIG_INIT(inst, default_family_code, chip_type) \ { \ .bus = DEVICE_DT_GET(DT_INST_BUS(inst)), \ .family = (uint8_t)DT_INST_PROP_OR(inst, family_code, default_family_code), \ .resolution = DT_INST_PROP_OR(inst, resolution, 12), \ .chip = chip_type, \ } #define DS18B20_DEFINE(inst, name, family_code, chip_type) \ static struct ds18b20_data data_##name##_##inst; \ static const struct ds18b20_config config_##name##_##inst = \ DS18B20_CONFIG_INIT(inst, family_code, chip_type); \ SENSOR_DEVICE_DT_INST_DEFINE(inst, \ ds18b20_init, \ NULL, \ &data_##name##_##inst, \ &config_##name##_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &ds18b20_driver_api); #define DT_DRV_COMPAT maxim_ds18b20 DT_INST_FOREACH_STATUS_OKAY_VARGS(DS18B20_DEFINE, DT_DRV_COMPAT, DS18B20_FAMILYCODE, type_ds18b20) #undef DT_DRV_COMPAT #define DT_DRV_COMPAT maxim_ds18s20 DT_INST_FOREACH_STATUS_OKAY_VARGS(DS18B20_DEFINE, DT_DRV_COMPAT, DS18S20_FAMILYCODE, type_ds18s20) #undef DT_DRV_COMPAT ```
/content/code_sandbox/drivers/sensor/maxim/ds18b20/ds18b20.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,896
```unknown # DS18B20 temperature and humidity sensor configuration options config DS18B20 bool "DS18B20 Temperature Sensor" default y depends on DT_HAS_MAXIM_DS18B20_ENABLED || DT_HAS_MAXIM_DS18S20_ENABLED depends on W1_NET help Enable driver for DS18B20 1-Wire temperature sensors. ```
/content/code_sandbox/drivers/sensor/maxim/ds18b20/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
78
```c /* * */ #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(max17055, CONFIG_SENSOR_LOG_LEVEL); #include "max17055.h" #include <zephyr/drivers/sensor/max17055.h> #define DT_DRV_COMPAT maxim_max17055 /** * @brief Read a register value * * Registers have an address and a 16-bit value * * @param priv Private data for the driver * @param reg_addr Register address to read * @param valp Place to put the value on success * @return 0 if successful, or negative error code from I2C API */ static int max17055_reg_read(const struct device *dev, uint8_t reg_addr, int16_t *valp) { const struct max17055_config *config = dev->config; uint8_t i2c_data[2]; int rc; rc = i2c_burst_read_dt(&config->i2c, reg_addr, i2c_data, 2); if (rc < 0) { LOG_ERR("Unable to read register"); return rc; } *valp = sys_get_le16(i2c_data); return 0; } static int max17055_reg_write(const struct device *dev, uint8_t reg_addr, uint16_t val) { const struct max17055_config *config = dev->config; uint8_t buf[3]; buf[0] = reg_addr; sys_put_le16(val, &buf[1]); return i2c_write_dt(&config->i2c, buf, sizeof(buf)); } /** * @brief Convert current in MAX17055 units to milliamps * * @param rsense_mohms Value of Rsense in milliohms * @param val Value to convert (taken from a MAX17055 register) * @return corresponding value in milliamps */ static int current_to_ma(uint16_t rsense_mohms, int16_t val) { return (int32_t)val * 25 / rsense_mohms / 16; /* * 1.5625 */ } /** * @brief Convert current in milliamps to MAX17055 units * * @param rsense_mohms Value of Rsense in milliohms * @param val Value in mA to convert * @return corresponding value in MAX17055 units, ready to write to a register */ static int current_ma_to_max17055(uint16_t rsense_mohms, uint16_t val) { return (int32_t)val * rsense_mohms * 16 / 25; /* / 1.5625 */ } /** * @brief Convert capacity in MAX17055 units to milliamps * * @param rsense_mohms Value of Rsense in milliohms * @param val Value to convert (taken from a MAX17055 register) * @return corresponding value in milliamps */ static int capacity_to_ma(unsigned int rsense_mohms, int16_t val) { int lsb_units, rem; /* Get units for the LSB in uA */ lsb_units = 5 * 1000 / rsense_mohms; /* Get remaining capacity in uA */ rem = val * lsb_units; return rem; } /** * @brief Convert capacity in milliamphours to MAX17055 units * * @param rsense_mohms Value of Rsense in milliohms * @param val_mha Value in milliamphours to convert * @return corresponding value in MAX17055 units, ready to write to a register */ static int capacity_to_max17055(unsigned int rsense_mohms, uint16_t val_mha) { return val_mha * rsense_mohms / 5; } /** * @brief Update empty voltage target in v_empty * * @param v_empty The register value to update * @param val_mv Value in millivolts to convert * @return 0 on success, -EINVAL on invalid val_mv */ static int max17055_update_vempty(uint16_t *v_empty, uint16_t val_mv) { uint32_t val = (val_mv / 10) << 7; if (val & ~VEMPTY_VE) { return -EINVAL; } *v_empty = (*v_empty & ~VEMPTY_VE) | (uint16_t)val; return 0; } static void set_millis(struct sensor_value *val, int val_millis) { val->val1 = val_millis / 1000; val->val2 = (val_millis % 1000) * 1000; } /** * @brief sensor value get * * @param dev MAX17055 device to access * @param chan Channel number to read * @param valp Returns the sensor value read on success * @return 0 if successful * @return -ENOTSUP for unsupported channels */ static int max17055_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *valp) { const struct max17055_config *const config = dev->config; struct max17055_data *const priv = dev->data; unsigned int tmp; switch (chan) { case SENSOR_CHAN_GAUGE_VOLTAGE: /* Get voltage in uV */ tmp = priv->voltage * 1250 / 16; valp->val1 = tmp / 1000000; valp->val2 = tmp % 1000000; break; case SENSOR_CHAN_MAX17055_VFOCV: tmp = priv->ocv * 1250 / 16; valp->val1 = tmp / 1000000; valp->val2 = tmp % 1000000; break; case SENSOR_CHAN_GAUGE_AVG_CURRENT: { int current_ma; current_ma = current_to_ma(config->rsense_mohms, priv->avg_current); set_millis(valp, current_ma); break; } case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE: valp->val1 = priv->state_of_charge / 256; valp->val2 = priv->state_of_charge % 256 * 1000000 / 256; break; case SENSOR_CHAN_GAUGE_TEMP: valp->val1 = priv->internal_temp / 256; valp->val2 = priv->internal_temp % 256 * 1000000 / 256; break; case SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY: tmp = capacity_to_ma(config->rsense_mohms, priv->full_cap); set_millis(valp, tmp); break; case SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY: tmp = capacity_to_ma(config->rsense_mohms, priv->remaining_cap); set_millis(valp, tmp); break; case SENSOR_CHAN_GAUGE_TIME_TO_EMPTY: if (priv->time_to_empty == 0xffff) { valp->val1 = 0; valp->val2 = 0; } else { /* Get time in milli-minutes */ tmp = priv->time_to_empty * 5625 / 60; set_millis(valp, tmp); } break; case SENSOR_CHAN_GAUGE_TIME_TO_FULL: if (priv->time_to_full == 0xffff) { valp->val1 = 0; valp->val2 = 0; } else { /* Get time in milli-minutes */ tmp = priv->time_to_full * 5625 / 60; set_millis(valp, tmp); } break; case SENSOR_CHAN_GAUGE_CYCLE_COUNT: valp->val1 = priv->cycle_count / 100; valp->val2 = priv->cycle_count % 100 * 10000; break; case SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY: tmp = capacity_to_ma(config->rsense_mohms, priv->design_cap); set_millis(valp, tmp); break; case SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE: set_millis(valp, config->design_voltage); break; case SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE: set_millis(valp, config->desired_voltage); break; case SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT: valp->val1 = config->desired_charging_current; valp->val2 = 0; break; default: return -ENOTSUP; } return 0; } static int max17055_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max17055_data *priv = dev->data; int ret = -ENOTSUP; if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_VOLTAGE) { ret = max17055_reg_read(dev, VCELL, &priv->voltage); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || (enum sensor_channel_max17055)chan == SENSOR_CHAN_MAX17055_VFOCV) { ret = max17055_reg_read(dev, VFOCV, &priv->ocv); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_AVG_CURRENT) { ret = max17055_reg_read(dev, AVG_CURRENT, &priv->avg_current); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_STATE_OF_CHARGE) { ret = max17055_reg_read(dev, REP_SOC, &priv->state_of_charge); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_TEMP) { ret = max17055_reg_read(dev, INT_TEMP, &priv->internal_temp); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY) { ret = max17055_reg_read(dev, REP_CAP, &priv->remaining_cap); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY) { ret = max17055_reg_read(dev, FULL_CAP_REP, &priv->full_cap); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_TIME_TO_EMPTY) { ret = max17055_reg_read(dev, TTE, &priv->time_to_empty); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_TIME_TO_FULL) { ret = max17055_reg_read(dev, TTF, &priv->time_to_full); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_CYCLE_COUNT) { ret = max17055_reg_read(dev, CYCLES, &priv->cycle_count); if (ret < 0) { return ret; } } if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY) { ret = max17055_reg_read(dev, DESIGN_CAP, &priv->design_cap); if (ret < 0) { return ret; } } return ret; } static int max17055_exit_hibernate(const struct device *dev) { LOG_DBG("Exit hibernate"); if (max17055_reg_write(dev, SOFT_WAKEUP, SOFT_WAKEUP_WAKEUP)) { return -EIO; } if (max17055_reg_write(dev, HIB_CFG, HIB_CFG_CLEAR)) { return -EIO; } if (max17055_reg_write(dev, SOFT_WAKEUP, SOFT_WAKEUP_CLEAR)) { return -EIO; } return 0; } static int max17055_write_config(const struct device *dev) { const struct max17055_config *config = dev->config; uint16_t design_capacity = capacity_to_max17055(config->rsense_mohms, config->design_capacity); uint16_t d_qacc = design_capacity / 32; uint16_t d_pacc = d_qacc * 44138 / design_capacity; uint16_t i_chg_term = current_ma_to_max17055(config->rsense_mohms, config->i_chg_term); uint16_t v_empty; int ret; LOG_DBG("Writing configuration parameters"); LOG_DBG("DesignCap: %u, dQAcc: %u, IChgTerm: %u, dPAcc: %u", design_capacity, d_qacc, i_chg_term, d_pacc); if (max17055_reg_write(dev, DESIGN_CAP, design_capacity)) { return -EIO; } if (max17055_reg_write(dev, D_QACC, d_qacc)) { return -EIO; } if (max17055_reg_write(dev, ICHG_TERM, i_chg_term)) { return -EIO; } if (max17055_reg_read(dev, V_EMPTY, &v_empty)) { return -EIO; } if (max17055_update_vempty(&v_empty, config->v_empty)) { return -EINVAL; } if (max17055_reg_write(dev, V_EMPTY, v_empty)) { return -EIO; } if (max17055_reg_write(dev, D_PACC, d_pacc)) { return -EIO; } if (max17055_reg_write(dev, MODEL_CFG, MODELCFG_REFRESH)) { return -EIO; } uint16_t model_cfg = MODELCFG_REFRESH; while (model_cfg & MODELCFG_REFRESH) { ret = max17055_reg_read(dev, MODEL_CFG, &model_cfg); if (ret) { return ret; } k_sleep(K_MSEC(10)); } return 0; } static int max17055_init_config(const struct device *dev) { int16_t hib_cfg; if (max17055_reg_read(dev, HIB_CFG, &hib_cfg)) { return -EIO; } if (max17055_exit_hibernate(dev)) { return -EIO; } if (max17055_write_config(dev)) { return -EIO; } if (max17055_reg_write(dev, HIB_CFG, hib_cfg)) { return -EIO; } return 0; } /** * @brief initialise the fuel gauge * * @return 0 for success * @return -EIO on I2C communication error * @return -EINVAL if the I2C controller could not be found */ static int max17055_gauge_init(const struct device *dev) { int16_t tmp; const struct max17055_config *const config = dev->config; int ret; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("Bus device is not ready"); return -ENODEV; } if (max17055_reg_read(dev, STATUS, &tmp)) { return -EIO; } if (!(tmp & STATUS_POR)) { LOG_DBG("No POR event detected - skip device configuration"); return 0; } /* Wait for FSTAT_DNR to be cleared */ tmp = FSTAT_DNR; while (tmp & FSTAT_DNR) { ret = max17055_reg_read(dev, FSTAT, &tmp); if (ret) { return ret; } } if (max17055_init_config(dev)) { return -EIO; } /* Clear PowerOnReset bit */ if (max17055_reg_read(dev, STATUS, &tmp)) { return -EIO; } tmp &= ~STATUS_POR; return max17055_reg_write(dev, STATUS, tmp); } static const struct sensor_driver_api max17055_battery_driver_api = { .sample_fetch = max17055_sample_fetch, .channel_get = max17055_channel_get, }; #define MAX17055_INIT(index) \ static struct max17055_data max17055_driver_##index; \ \ static const struct max17055_config max17055_config_##index = { \ .i2c = I2C_DT_SPEC_INST_GET(index), \ .design_capacity = DT_INST_PROP(index, design_capacity), \ .design_voltage = DT_INST_PROP(index, design_voltage), \ .desired_charging_current = DT_INST_PROP(index, desired_charging_current), \ .desired_voltage = DT_INST_PROP(index, desired_voltage), \ .i_chg_term = DT_INST_PROP(index, i_chg_term), \ .rsense_mohms = DT_INST_PROP(index, rsense_mohms), \ .v_empty = DT_INST_PROP(index, v_empty), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(index, &max17055_gauge_init, \ NULL, \ &max17055_driver_##index, \ &max17055_config_##index, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &max17055_battery_driver_api) DT_INST_FOREACH_STATUS_OKAY(MAX17055_INIT); ```
/content/code_sandbox/drivers/sensor/maxim/max17055/max17055.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,852
```unknown # config MAX17262 bool "MAX17262 Fuel Gauge" default y depends on DT_HAS_MAXIM_MAX17262_ENABLED select I2C help Enable I2C-based driver for MAX17262 Fuel Gauge. This driver supports reading various sensor settings including voltage, current, temperature, time to full/empty and remaining capacity in mAh. ```
/content/code_sandbox/drivers/sensor/maxim/max17262/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
80
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17262_H_ #define ZEPHYR_DRIVERS_SENSOR_BATTERY_MAX17262_H_ #include <zephyr/drivers/i2c.h> #define VOLTAGE_MULTIPLIER_UV 1250 / 16 #define CURRENT_MULTIPLIER_NA 156250 #define TIME_MULTIPLIER_MS 5625 /* Register addresses */ enum { STATUS = 0x00, REP_CAP = 0x05, REP_SOC = 0x06, INT_TEMP = 0x08, VCELL = 0x09, AVG_CURRENT = 0x0b, FULL_CAP_REP = 0x10, TTE = 0x11, CYCLES = 0x17, DESIGN_CAP = 0x18, ICHG_TERM = 0x1E, TTF = 0x20, VEMPTY = 0x3A, FSTAT = 0x3D, COULOMB_COUNTER = 0x4D, SOFT_WAKEUP = 0x60, HIBCFG = 0xBA, MODELCFG = 0xDB, }; /* Masks */ enum { FSTAT_DNR = 0x01, STATUS_POR = 0x02, MODELCFG_REFRESH = 0x8000, }; /* MAX17262 specific channels */ enum max17262_channel { MAX17262_COULOMB_COUNTER, }; struct max17262_data { /* Current cell voltage in units of 1.25/16mV */ uint16_t voltage; /* Average current in units of 156.25uA */ int16_t avg_current; /* Desired charging current in mA */ uint16_t ichg_term; /* Remaining capacity as a %age */ uint16_t state_of_charge; /* Internal temperature in units of 1/256 degrees C */ int16_t internal_temp; /* Full charge capacity in mAh */ uint16_t full_cap; /* Remaining capacity in mAh */ uint16_t remaining_cap; /* Time to empty in seconds */ uint16_t time_to_empty; /* Time to full in seconds */ uint16_t time_to_full; /* Cycle count in 1/100ths (number of charge/discharge cycles) */ uint16_t cycle_count; /* Battery capacity in mAh */ uint16_t design_cap; /* Spent capacity in mAh */ uint16_t coulomb_counter; }; struct max17262_config { struct i2c_dt_spec i2c; /* Value of Rsense resistor in milliohms (typically 5 or 10) */ uint16_t rsense_mohms; /* Design voltage of cell in mV */ uint16_t design_voltage; /* Desired voltage of cell in mV */ uint16_t desired_voltage; /* Desired charging current in mA */ uint16_t desired_charging_current; /* Battery capacity in mAh */ uint16_t design_cap; /* Empty voltage detection in mV */ uint16_t empty_voltage; /* Recovery voltage detection in mV */ uint16_t recovery_voltage; /* Defined charge voltage value in mV */ uint16_t charge_voltage; }; #endif ```
/content/code_sandbox/drivers/sensor/maxim/max17262/max17262.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
706
```c /* * */ #define DT_DRV_COMPAT maxim_max31875 #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/sys/byteorder.h> #include <zephyr/sys/util.h> #include <zephyr/kernel.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/__assert.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(MAX31875, CONFIG_SENSOR_LOG_LEVEL); /* Conversions per second */ #define MAX31875_CONV_PER_SEC_SHIFT 0x01 #define MAX31875_CONV_PER_SEC_0_25 0x00 #define MAX31875_CONV_PER_SEC_1 0x01 #define MAX31875_CONV_PER_SEC_4 0x02 #define MAX31875_CONV_PER_SEC_8 0x03 #define MAX31875_CONV_PER_SEC_MASK (BIT_MASK(2) << MAX31875_CONV_PER_SEC_SHIFT) /* Data format */ #define MAX31875_DATA_FORMAT_SHIFT 0x07 #define MAX31875_DATA_FORMAT_NORMAL 0x00 #define MAX31875_DATA_FORMAT_EXTENDED 0x01 /* These are for shifting the data received */ #define MAX31875_DATA_FORMAT_EXTENDED_SHIFT 0x03 #define MAX31875_DATA_FORMAT_NORMAL_SHIFT 0x04 /* Resolution in bits */ #define MAX31875_RESOLUTION_SHIFT 0x05 #define MAX31875_RESOLUTION_8_BITS 0x00 #define MAX31875_RESOLUTION_9_BITS 0x01 #define MAX31875_RESOLUTION_10_BITS 0x02 #define MAX31875_RESOLUTION_12_BITS 0x03 #define MAX31875_TEMP_SCALE 62500 /** * @brief Macro for creating the MAX31875 configuration register value * * @param mode Data format * @param res Resolution (number of bits) * @param convs Conversions per second */ #define MAX31875_CONFIG(format, res, convs) \ (((format) << (MAX31875_DATA_FORMAT_SHIFT)) | ((res) << (MAX31875_RESOLUTION_SHIFT)) | \ ((convs) << (MAX31875_CONV_PER_SEC_SHIFT))) #define MAX31875_REG_TEMPERATURE 0x00 #define MAX31875_REG_CONFIG 0x01 struct max31875_data { int16_t sample; uint16_t config_reg; }; struct max31875_config { const struct i2c_dt_spec bus; uint8_t conversions_per_second; uint8_t data_format; uint8_t resolution; }; static int max31875_reg_read(const struct max31875_config *cfg, uint8_t reg, uint16_t *val) { int ret; ret = i2c_burst_read_dt(&cfg->bus, reg, (uint8_t *)val, sizeof(*val)); if (ret < 0) { return ret; } *val = sys_be16_to_cpu(*val); return 0; } static int max31875_reg_write(const struct max31875_config *cfg, uint8_t reg, uint16_t val) { uint16_t val_be = sys_cpu_to_be16(val); return i2c_burst_write_dt(&cfg->bus, reg, (uint8_t *)&val_be, 2); } static uint16_t set_config_flags(struct max31875_data *data, uint16_t mask, uint16_t value) { return (data->config_reg & ~mask) | (value & mask); } static int max31875_update_config(const struct device *dev, uint16_t mask, uint16_t val) { int rc; const struct max31875_config *cfg = dev->config; struct max31875_data *data = dev->data; const uint16_t new_val = set_config_flags(data, mask, val); rc = max31875_reg_write(cfg, MAX31875_REG_CONFIG, new_val); /* don't update if write failed */ if (rc == 0) { data->config_reg = new_val; } return rc; } static int max31875_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { int ret; uint16_t value; uint16_t cr; if (chan != SENSOR_CHAN_AMBIENT_TEMP) { return -ENOTSUP; } switch (attr) { case SENSOR_ATTR_FULL_SCALE: /* the sensor supports two ranges -50 to 128 and -50 to 150 */ /* the value contains the upper limit */ if (val->val1 == 128) { value = MAX31875_DATA_FORMAT_NORMAL << MAX31875_DATA_FORMAT_SHIFT; } else if (val->val1 == 150) { value = MAX31875_DATA_FORMAT_EXTENDED << MAX31875_DATA_FORMAT_SHIFT; } else { return -ENOTSUP; } ret = max31875_update_config(dev, MAX31875_DATA_FORMAT_SHIFT, value); if (ret < 0) { LOG_ERR("Failed to set attribute!"); return ret; } break; case SENSOR_ATTR_SAMPLING_FREQUENCY: /* conversion rate in mHz */ cr = val->val1 * 1000 + val->val2 / 1000; /* the sensor supports 0.25Hz, 1Hz, 4Hz and 8Hz */ /* conversion rate */ switch (cr) { case 250: value = MAX31875_CONV_PER_SEC_0_25 << MAX31875_CONV_PER_SEC_SHIFT; break; case 1000: value = MAX31875_CONV_PER_SEC_1 << MAX31875_CONV_PER_SEC_SHIFT; break; case 4000: value = MAX31875_CONV_PER_SEC_4 << MAX31875_CONV_PER_SEC_SHIFT; break; case 8000: value = MAX31875_CONV_PER_SEC_8 << MAX31875_CONV_PER_SEC_SHIFT; break; default: return -ENOTSUP; } ret = max31875_update_config(dev, MAX31875_CONV_PER_SEC_MASK, value); if (ret < 0) { LOG_ERR("Failed to set attribute!"); return ret; } break; default: return -ENOTSUP; } return 0; } static int max31875_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max31875_data *data = dev->data; const struct max31875_config *cfg = dev->config; uint16_t val; int ret; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_AMBIENT_TEMP) { LOG_ERR("Invalid channel provided"); return -ENOTSUP; } ret = max31875_reg_read(cfg, MAX31875_REG_TEMPERATURE, &val); if (ret < 0) { return ret; } if (data->config_reg & BIT(MAX31875_DATA_FORMAT_SHIFT)) { data->sample = arithmetic_shift_right((int16_t)val, MAX31875_DATA_FORMAT_EXTENDED_SHIFT); } else { data->sample = arithmetic_shift_right((int16_t)val, MAX31875_DATA_FORMAT_NORMAL_SHIFT); } return 0; } static int max31875_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max31875_data *data = dev->data; int32_t uval; if (chan != SENSOR_CHAN_AMBIENT_TEMP) { return -ENOTSUP; } uval = data->sample * MAX31875_TEMP_SCALE; val->val1 = uval / 1000000; val->val2 = uval % 1000000; return 0; } static const struct sensor_driver_api max31875_driver_api = { .attr_set = max31875_attr_set, .sample_fetch = max31875_sample_fetch, .channel_get = max31875_channel_get, }; static int max31875_init(const struct device *dev) { const struct max31875_config *cfg = dev->config; struct max31875_data *data = dev->data; if (!device_is_ready(cfg->bus.bus)) { LOG_ERR("I2C dev %s not ready", cfg->bus.bus->name); return -ENODEV; } data->config_reg = MAX31875_CONFIG(cfg->data_format, cfg->resolution, cfg->conversions_per_second); return max31875_update_config(dev, 0, 0); } #define MAX31875_INST(inst) \ static struct max31875_data max31875_data_##inst; \ static const struct max31875_config max31875_config_##inst = { \ .bus = I2C_DT_SPEC_INST_GET(inst), \ .conversions_per_second = DT_INST_ENUM_IDX(inst, conversions_per_second), \ .resolution = DT_INST_ENUM_IDX(inst, resolution), \ .data_format = DT_INST_PROP(inst, extended_mode), \ }; \ SENSOR_DEVICE_DT_INST_DEFINE(inst, max31875_init, NULL, &max31875_data_##inst, \ &max31875_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max31875_driver_api); DT_INST_FOREACH_STATUS_OKAY(MAX31875_INST) ```
/content/code_sandbox/drivers/sensor/maxim/max31875/max31875.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,999
```unknown # MAX31875 temperature sensor configuration options config MAX31875 bool "MAX31875 Temperature Sensor" default y depends on DT_HAS_MAXIM_MAX31875_ENABLED select I2C help Enable the driver for Maxim MAX31875 Low-Power I2C Temperature Sensors. ```
/content/code_sandbox/drivers/sensor/maxim/max31875/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
63
```c /* * */ #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(max17262, CONFIG_SENSOR_LOG_LEVEL); #include "max17262.h" #define DT_DRV_COMPAT maxim_max17262 /** * @brief Read a register value * * Registers have an address and a 16-bit value * * @param dev MAX17262 device to access * @param reg_addr Register address to read * @param valp Place to put the value on success * @return 0 if successful, or negative error code from I2C API */ static int max17262_reg_read(const struct device *dev, uint8_t reg_addr, int16_t *valp) { const struct max17262_config *cfg = dev->config; uint8_t i2c_data[2]; int rc; rc = i2c_burst_read_dt(&cfg->i2c, reg_addr, i2c_data, 2); if (rc < 0) { LOG_ERR("Unable to read register 0x%02x", reg_addr); return rc; } *valp = ((int16_t)i2c_data[1] << 8) | i2c_data[0]; return 0; } /** * @brief Write a register value * * Registers have an address and a 16-bit value * * @param dev MAX17262 device to access * @param reg_addr Register address to write to * @param val Register value to write * @return 0 if successful, or negative error code from I2C API */ static int max17262_reg_write(const struct device *dev, uint8_t reg_addr, int16_t val) { const struct max17262_config *cfg = dev->config; uint8_t i2c_data[3] = {reg_addr, val & 0xFF, (uint16_t)val >> 8}; return i2c_write_dt(&cfg->i2c, i2c_data, sizeof(i2c_data)); } /** * @brief Convert sensor value from millis * * @param val Where to store converted value in sensor_value format * @param val_millis Value in millis */ static void convert_millis(struct sensor_value *val, int32_t val_millis) { val->val1 = val_millis / 1000; val->val2 = (val_millis % 1000) * 1000; } /** * @brief Convert raw register values for specific channel * * @param dev MAX17262 device to access * @param chan Channel number to read * @param valp Returns the sensor value read on success * @return 0 if successful * @return -ENOTSUP for unsupported channels */ static int max17262_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *valp) { const struct max17262_config *const config = dev->config; struct max17262_data *const data = dev->data; int32_t tmp; switch (chan) { case SENSOR_CHAN_GAUGE_VOLTAGE: /* Get voltage in uV */ tmp = data->voltage * VOLTAGE_MULTIPLIER_UV; /* Convert to V */ valp->val1 = tmp / 1000000; valp->val2 = tmp % 1000000; break; case SENSOR_CHAN_GAUGE_AVG_CURRENT: { int current; /* Get avg current in nA */ current = data->avg_current * CURRENT_MULTIPLIER_NA; /* Convert to mA */ valp->val1 = current / 1000000; valp->val2 = current % 1000000; break; } case SENSOR_CHAN_GAUGE_STATE_OF_CHARGE: valp->val1 = data->state_of_charge / 256; valp->val2 = data->state_of_charge % 256 * 1000000 / 256; break; case SENSOR_CHAN_GAUGE_TEMP: valp->val1 = data->internal_temp / 256; valp->val2 = data->internal_temp % 256 * 1000000 / 256; break; case SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY: convert_millis(valp, data->full_cap); break; case SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY: convert_millis(valp, data->remaining_cap); break; case SENSOR_CHAN_GAUGE_TIME_TO_EMPTY: /* Get time in ms */ if (data->time_to_empty == 0xffff) { valp->val1 = 0; valp->val2 = 0; } else { tmp = data->time_to_empty * TIME_MULTIPLIER_MS; convert_millis(valp, tmp); } break; case SENSOR_CHAN_GAUGE_TIME_TO_FULL: /* Get time in ms */ if (data->time_to_full == 0xffff) { valp->val1 = 0; valp->val2 = 0; } else { tmp = data->time_to_full * TIME_MULTIPLIER_MS; convert_millis(valp, tmp); } break; case SENSOR_CHAN_GAUGE_CYCLE_COUNT: valp->val1 = data->cycle_count / 100; valp->val2 = data->cycle_count % 100 * 10000; break; case SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY: convert_millis(valp, data->design_cap); break; case SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE: convert_millis(valp, config->design_voltage); break; case SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE: convert_millis(valp, config->desired_voltage); break; case SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT: valp->val1 = data->ichg_term; valp->val2 = 0; break; case MAX17262_COULOMB_COUNTER: /* Get spent capacity in mAh */ data->coulomb_counter = 0xffff - data->coulomb_counter; valp->val1 = data->coulomb_counter / 2; valp->val2 = data->coulomb_counter % 2 * 10 / 2; break; default: LOG_ERR("Unsupported channel!"); return -ENOTSUP; } return 0; } /** * @brief Read register values for supported channels * * @param dev MAX17262 device to access * @return 0 if successful, or negative error code from I2C API */ static int max17262_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max17262_data *data = dev->data; /* clang-format off */ struct { int reg_addr; int16_t *dest; } regs[] = { { VCELL, &data->voltage }, { AVG_CURRENT, &data->avg_current }, { ICHG_TERM, &data->ichg_term }, { REP_SOC, &data->state_of_charge }, { INT_TEMP, &data->internal_temp }, { REP_CAP, &data->remaining_cap }, { FULL_CAP_REP, &data->full_cap }, { TTE, &data->time_to_empty }, { TTF, &data->time_to_full }, { CYCLES, &data->cycle_count }, { DESIGN_CAP, &data->design_cap }, { COULOMB_COUNTER, &data->coulomb_counter }, }; /* clang-format on */ __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); for (size_t i = 0; i < ARRAY_SIZE(regs); i++) { int rc; rc = max17262_reg_read(dev, regs[i].reg_addr, regs[i].dest); if (rc != 0) { LOG_ERR("Failed to read channel %d", chan); return rc; } } return 0; } /** * @brief Initialise the fuel gauge * * @param dev MAX17262 device to access * @return 0 for success * @return -EINVAL if the I2C controller could not be found */ static int max17262_gauge_init(const struct device *dev) { const struct max17262_config *const config = dev->config; int16_t tmp, hibcfg; int rc; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("Bus device is not ready"); return -ENODEV; } /* Read Status register */ rc = max17262_reg_read(dev, STATUS, &tmp); if (rc) { return rc; } if (!(tmp & STATUS_POR)) { /* * Status.POR bit is set to 1 when MAX17262 detects that * a software or hardware POR event has occurred and * therefore a custom configuration needs to be set... * If POR event did not happen (Status.POR == 0), skip * init and continue with measurements. */ LOG_DBG("No POR event detected - skip device configuration"); return 0; } LOG_DBG("POR detected, setting custom device configuration..."); /** STEP 1 */ rc = max17262_reg_read(dev, FSTAT, &tmp); if (rc) { return rc; } /* Do not continue until FSTAT.DNR bit is cleared */ while (tmp & FSTAT_DNR) { k_sleep(K_MSEC(10)); rc = max17262_reg_read(dev, FSTAT, &tmp); if (rc) { return rc; } } /** STEP 2 */ /* Store original HibCFG value */ rc = max17262_reg_read(dev, HIBCFG, &hibcfg); if (rc) { return rc; } /* Exit Hibernate Mode step 1 */ rc = max17262_reg_write(dev, SOFT_WAKEUP, 0x0090); if (rc) { return rc; } /* Exit Hibernate Mode step 2 */ rc = max17262_reg_write(dev, HIBCFG, 0x0000); if (rc) { return rc; } /* Exit Hibernate Mode step 3 */ rc = max17262_reg_write(dev, SOFT_WAKEUP, 0x0000); if (rc) { return rc; } /** STEP 2.1 --> OPTION 1 EZ Config (No INI file is needed) */ /* Write DesignCap */ rc = max17262_reg_write(dev, DESIGN_CAP, config->design_cap); if (rc) { return rc; } /* Write IChgTerm */ rc = max17262_reg_write(dev, ICHG_TERM, config->desired_charging_current); if (rc) { return rc; } /* Write VEmpty */ rc = max17262_reg_write(dev, VEMPTY, ((config->empty_voltage / 10) << 7) | ((config->recovery_voltage / 40) & 0x7F)); if (rc) { return rc; } /* Write ModelCFG */ if (config->charge_voltage > 4275) { rc = max17262_reg_write(dev, MODELCFG, 0x8400); } else { rc = max17262_reg_write(dev, MODELCFG, 0x8000); } if (rc) { return rc; } /* * Read ModelCFG.Refresh (highest bit), * proceed to Step 3 when ModelCFG.Refresh == 0 */ rc = max17262_reg_read(dev, MODELCFG, &tmp); if (rc) { return rc; } /* Do not continue until ModelCFG.Refresh == 0 */ while (tmp & MODELCFG_REFRESH) { k_sleep(K_MSEC(10)); rc = max17262_reg_read(dev, MODELCFG, &tmp); if (rc) { return rc; } } /* Restore Original HibCFG value */ rc = max17262_reg_write(dev, HIBCFG, hibcfg); if (rc) { return rc; } /** STEP 3 */ /* Read Status register */ rc = max17262_reg_read(dev, STATUS, &tmp); if (rc) { return rc; } /* Clear PowerOnReset bit */ tmp &= ~STATUS_POR; rc = max17262_reg_write(dev, STATUS, tmp); if (rc) { return rc; } return 0; } static const struct sensor_driver_api max17262_battery_driver_api = { .sample_fetch = max17262_sample_fetch, .channel_get = max17262_channel_get, }; #define MAX17262_INIT(n) \ static struct max17262_data max17262_data_##n; \ \ static const struct max17262_config max17262_config_##n = { \ .i2c = I2C_DT_SPEC_INST_GET(n), \ .design_voltage = DT_INST_PROP(n, design_voltage), \ .desired_voltage = DT_INST_PROP(n, desired_voltage), \ .desired_charging_current = DT_INST_PROP(n, desired_charging_current), \ .design_cap = DT_INST_PROP(n, design_cap), \ .empty_voltage = DT_INST_PROP(n, empty_voltage), \ .recovery_voltage = DT_INST_PROP(n, recovery_voltage), \ .charge_voltage = DT_INST_PROP(n, charge_voltage), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(n, &max17262_gauge_init, NULL, &max17262_data_##n, \ &max17262_config_##n, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max17262_battery_driver_api); DT_INST_FOREACH_STATUS_OKAY(MAX17262_INIT) ```
/content/code_sandbox/drivers/sensor/maxim/max17262/max17262.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,062
```unknown # MAX31855 cold-junction compensated thermocouple-to-digital converter configuration options config MAX31855 bool "MAX31855 sensor" default y depends on DT_HAS_MAXIM_MAX31855_ENABLED select SPI help Enable driver for MAX31855 SPI-based Cold-Junction Compensated thermocouple-to-Digital Converter. ```
/content/code_sandbox/drivers/sensor/maxim/max31855/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
74
```c /* * */ #define DT_DRV_COMPAT maxim_max31855 #include <zephyr/kernel.h> #include <zephyr/drivers/sensor.h> #include <zephyr/init.h> #include <zephyr/drivers/gpio.h> #include <zephyr/sys/byteorder.h> #include <zephyr/sys/__assert.h> #include <zephyr/drivers/spi.h> #include <zephyr/logging/log.h> #include <zephyr/types.h> #include <zephyr/device.h> #define THERMOCOUPLE_TEMPERATURE_POS 18 #define INTERNAL_TEMPERATURE_POS 4 #define THERMOCOUPLE_SIGN_BITS 0xffff2000 #define INTERNAL_SIGN_BITS 0xfffff800 #define THERMOCOUPLE_RESOLUTION 25 #define INTERNAL_RESOLUTION 625 LOG_MODULE_REGISTER(MAX31855, CONFIG_SENSOR_LOG_LEVEL); struct max31855_config { struct spi_dt_spec spi; }; struct max31855_data { uint32_t sample; }; static int max31855_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max31855_data *data = dev->data; const struct max31855_config *config = dev->config; int ret; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); struct spi_buf rx_buf = { .buf = &(data->sample), .len = sizeof(data->sample), }; const struct spi_buf_set rx = {.buffers = &rx_buf, .count = 1}; ret = spi_read_dt(&config->spi, &rx); if (ret < 0) { LOG_ERR("max31855_read FAIL %d", ret); return ret; } return 0; } static int max31855_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max31855_data *data = dev->data; uint32_t temp = sys_be32_to_cpu(data->sample); if (temp & BIT(16)) { return -EIO; } switch (chan) { case SENSOR_CHAN_AMBIENT_TEMP: temp = (temp >> THERMOCOUPLE_TEMPERATURE_POS) & 0x3fff; /* if sign bit is set, make value negative */ if (temp & BIT(14)) { temp |= THERMOCOUPLE_SIGN_BITS; } temp = temp * THERMOCOUPLE_RESOLUTION; val->val1 = temp / 100; val->val2 = (temp - val->val1 * 100) * 10000; break; case SENSOR_CHAN_DIE_TEMP: temp = (temp >> INTERNAL_TEMPERATURE_POS) & 0xfff; /* if sign bit is set, make value negative */ if (temp & BIT(12)) { temp |= INTERNAL_SIGN_BITS; } temp = temp * INTERNAL_RESOLUTION; val->val1 = temp / 10000; val->val2 = (temp - val->val1 * 10000) * 100; break; default: return -ENOTSUP; } return 0; } static const struct sensor_driver_api max31855_api = { .sample_fetch = max31855_sample_fetch, .channel_get = max31855_channel_get, }; static int max31855_init(const struct device *dev) { const struct max31855_config *config = dev->config; if (!spi_is_ready_dt(&config->spi)) { LOG_ERR("SPI bus is not ready"); return -ENODEV; } return 0; } #define MAX31855_INIT(n) \ static struct max31855_data max31855_data_##n; \ static const struct max31855_config max31855_config_##n = { \ .spi = SPI_DT_SPEC_INST_GET(n, SPI_OP_MODE_MASTER | SPI_WORD_SET(8U), 0U), \ }; \ SENSOR_DEVICE_DT_INST_DEFINE(n, &max31855_init, NULL, &max31855_data_##n, \ &max31855_config_##n, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max31855_api); DT_INST_FOREACH_STATUS_OKAY(MAX31855_INIT) ```
/content/code_sandbox/drivers/sensor/maxim/max31855/max31855.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
901
```unknown config MAX6675 bool "MAX6675 K-thermocouple to digital converter" default y depends on DT_HAS_MAXIM_MAX6675_ENABLED select SPI help Enable MAX6675 cold-junction-compensated K-thermocouple to digital converter. ```
/content/code_sandbox/drivers/sensor/maxim/max6675/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
65
```c /* * */ #define DT_DRV_COMPAT maxim_max6675 #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/spi.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(max6675, CONFIG_SENSOR_LOG_LEVEL); /** Thermocouple input bit (goes high if thermocouple is disconnected). */ #define THERMOCOUPLE_INPUT BIT(2) /** Temperature position. */ #define TEMPERATURE_POS 3U /** Temperature resolution (cDeg/LSB). */ #define TEMPERATURE_RES 25U struct max6675_config { struct spi_dt_spec spi; }; struct max6675_data { uint16_t sample; }; static int max6675_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max6675_data *data = dev->data; const struct max6675_config *config = dev->config; int ret; uint8_t buf_rx[2]; const struct spi_buf rx_buf = { .buf = buf_rx, .len = ARRAY_SIZE(buf_rx) }; const struct spi_buf_set rx_bufs = { .buffers = &rx_buf, .count = 1U }; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_AMBIENT_TEMP) { return -ENOTSUP; } ret = spi_read_dt(&config->spi, &rx_bufs); if (ret < 0) { return ret; } data->sample = sys_get_be16(buf_rx); if (data->sample & THERMOCOUPLE_INPUT) { LOG_INF("Thermocouple not connected"); return -ENOENT; } return 0; } static int max6675_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max6675_data *data = dev->data; int32_t temperature; if (chan != SENSOR_CHAN_AMBIENT_TEMP) { return -ENOTSUP; } temperature = (data->sample >> TEMPERATURE_POS) * TEMPERATURE_RES; val->val1 = temperature / 100; val->val2 = (temperature - val->val1 * 100) * 10000; return 0; } static const struct sensor_driver_api max6675_api = { .sample_fetch = &max6675_sample_fetch, .channel_get = &max6675_channel_get, }; static int max6675_init(const struct device *dev) { const struct max6675_config *config = dev->config; if (!spi_is_ready_dt(&config->spi)) { LOG_ERR("SPI bus is not ready"); return -ENODEV; } return 0; } #define MAX6675_INIT(n) \ static struct max6675_data max6675_data_##n; \ static const struct max6675_config max6675_config_##n = { \ .spi = SPI_DT_SPEC_INST_GET(n, \ SPI_OP_MODE_MASTER | \ SPI_WORD_SET(8U), \ 0U), \ }; \ SENSOR_DEVICE_DT_INST_DEFINE(n, &max6675_init, NULL, \ &max6675_data_##n, &max6675_config_##n, \ POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ &max6675_api); DT_INST_FOREACH_STATUS_OKAY(MAX6675_INIT) ```
/content/code_sandbox/drivers/sensor/maxim/max6675/max6675.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
738
```objective-c /* * */ #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #define MAX30101_REG_INT_STS1 0x00 #define MAX30101_REG_INT_STS2 0x01 #define MAX30101_REG_INT_EN1 0x02 #define MAX30101_REG_INT_EN2 0x03 #define MAX30101_REG_FIFO_WR 0x04 #define MAX30101_REG_FIFO_OVF 0x05 #define MAX30101_REG_FIFO_RD 0x06 #define MAX30101_REG_FIFO_DATA 0x07 #define MAX30101_REG_FIFO_CFG 0x08 #define MAX30101_REG_MODE_CFG 0x09 #define MAX30101_REG_SPO2_CFG 0x0a #define MAX30101_REG_LED1_PA 0x0c #define MAX30101_REG_LED2_PA 0x0d #define MAX30101_REG_LED3_PA 0x0e #define MAX30101_REG_PILOT_PA 0x10 #define MAX30101_REG_MULTI_LED 0x11 #define MAX30101_REG_TINT 0x1f #define MAX30101_REG_TFRAC 0x20 #define MAX30101_REG_TEMP_CFG 0x21 #define MAX30101_REG_PROX_INT 0x30 #define MAX30101_REG_REV_ID 0xfe #define MAX30101_REG_PART_ID 0xff #define MAX30101_INT_PPG_MASK (1 << 6) #define MAX30101_FIFO_CFG_SMP_AVE_SHIFT 5 #define MAX30101_FIFO_CFG_FIFO_FULL_SHIFT 0 #define MAX30101_FIFO_CFG_ROLLOVER_EN_MASK (1 << 4) #define MAX30101_MODE_CFG_SHDN_MASK (1 << 7) #define MAX30101_MODE_CFG_RESET_MASK (1 << 6) #define MAX30101_SPO2_ADC_RGE_SHIFT 5 #define MAX30101_SPO2_SR_SHIFT 2 #define MAX30101_SPO2_PW_SHIFT 0 #define MAX30101_PART_ID 0x15 #define MAX30101_BYTES_PER_CHANNEL 3 #define MAX30101_MAX_NUM_CHANNELS 3 #define MAX30101_MAX_BYTES_PER_SAMPLE (MAX30101_MAX_NUM_CHANNELS * \ MAX30101_BYTES_PER_CHANNEL) #define MAX30101_SLOT_LED_MASK 0x03 #define MAX30101_FIFO_DATA_BITS 18 #define MAX30101_FIFO_DATA_MASK ((1 << MAX30101_FIFO_DATA_BITS) - 1) enum max30101_mode { MAX30101_MODE_HEART_RATE = 2, MAX30101_MODE_SPO2 = 3, MAX30101_MODE_MULTI_LED = 7, }; enum max30101_slot { MAX30101_SLOT_DISABLED = 0, MAX30101_SLOT_RED_LED1_PA, MAX30101_SLOT_IR_LED2_PA, MAX30101_SLOT_GREEN_LED3_PA, MAX30101_SLOT_RED_PILOT_PA, MAX30101_SLOT_IR_PILOT_PA, MAX30101_SLOT_GREEN_PILOT_PA, }; enum max30101_led_channel { MAX30101_LED_CHANNEL_RED = 0, MAX30101_LED_CHANNEL_IR, MAX30101_LED_CHANNEL_GREEN, }; enum max30101_pw { MAX30101_PW_15BITS = 0, MAX30101_PW_16BITS, MAX30101_PW_17BITS, MAX30101_PW_18BITS, }; struct max30101_config { struct i2c_dt_spec i2c; uint8_t fifo; uint8_t spo2; uint8_t led_pa[MAX30101_MAX_NUM_CHANNELS]; enum max30101_mode mode; enum max30101_slot slot[4]; }; struct max30101_data { uint32_t raw[MAX30101_MAX_NUM_CHANNELS]; uint8_t map[MAX30101_MAX_NUM_CHANNELS]; uint8_t num_channels; }; ```
/content/code_sandbox/drivers/sensor/maxim/max30101/max30101.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
874
```c /* * */ #define DT_DRV_COMPAT maxim_max30101 #include <zephyr/logging/log.h> #include "max30101.h" LOG_MODULE_REGISTER(MAX30101, CONFIG_SENSOR_LOG_LEVEL); static int max30101_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max30101_data *data = dev->data; const struct max30101_config *config = dev->config; uint8_t buffer[MAX30101_MAX_BYTES_PER_SAMPLE]; uint32_t fifo_data; int fifo_chan; int num_bytes; int i; /* Read all the active channels for one sample */ num_bytes = data->num_channels * MAX30101_BYTES_PER_CHANNEL; if (i2c_burst_read_dt(&config->i2c, MAX30101_REG_FIFO_DATA, buffer, num_bytes)) { LOG_ERR("Could not fetch sample"); return -EIO; } fifo_chan = 0; for (i = 0; i < num_bytes; i += 3) { /* Each channel is 18-bits */ fifo_data = (buffer[i] << 16) | (buffer[i + 1] << 8) | (buffer[i + 2]); fifo_data &= MAX30101_FIFO_DATA_MASK; /* Save the raw data */ data->raw[fifo_chan++] = fifo_data; } return 0; } static int max30101_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max30101_data *data = dev->data; enum max30101_led_channel led_chan; int fifo_chan; switch (chan) { case SENSOR_CHAN_RED: led_chan = MAX30101_LED_CHANNEL_RED; break; case SENSOR_CHAN_IR: led_chan = MAX30101_LED_CHANNEL_IR; break; case SENSOR_CHAN_GREEN: led_chan = MAX30101_LED_CHANNEL_GREEN; break; default: LOG_ERR("Unsupported sensor channel"); return -ENOTSUP; } /* Check if the led channel is active by looking up the associated fifo * channel. If the fifo channel isn't valid, then the led channel * isn't active. */ fifo_chan = data->map[led_chan]; if (fifo_chan >= MAX30101_MAX_NUM_CHANNELS) { LOG_ERR("Inactive sensor channel"); return -ENOTSUP; } /* TODO: Scale the raw data to standard units */ val->val1 = data->raw[fifo_chan]; val->val2 = 0; return 0; } static const struct sensor_driver_api max30101_driver_api = { .sample_fetch = max30101_sample_fetch, .channel_get = max30101_channel_get, }; static int max30101_init(const struct device *dev) { const struct max30101_config *config = dev->config; struct max30101_data *data = dev->data; uint8_t part_id; uint8_t mode_cfg; uint32_t led_chan; int fifo_chan; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("Bus device is not ready"); return -ENODEV; } /* Check the part id to make sure this is MAX30101 */ if (i2c_reg_read_byte_dt(&config->i2c, MAX30101_REG_PART_ID, &part_id)) { LOG_ERR("Could not get Part ID"); return -EIO; } if (part_id != MAX30101_PART_ID) { LOG_ERR("Got Part ID 0x%02x, expected 0x%02x", part_id, MAX30101_PART_ID); return -EIO; } /* Reset the sensor */ if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_MODE_CFG, MAX30101_MODE_CFG_RESET_MASK)) { return -EIO; } /* Wait for reset to be cleared */ do { if (i2c_reg_read_byte_dt(&config->i2c, MAX30101_REG_MODE_CFG, &mode_cfg)) { LOG_ERR("Could read mode cfg after reset"); return -EIO; } } while (mode_cfg & MAX30101_MODE_CFG_RESET_MASK); /* Write the FIFO configuration register */ if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_FIFO_CFG, config->fifo)) { return -EIO; } /* Write the mode configuration register */ if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_MODE_CFG, config->mode)) { return -EIO; } /* Write the SpO2 configuration register */ if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_SPO2_CFG, config->spo2)) { return -EIO; } /* Write the LED pulse amplitude registers */ if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_LED1_PA, config->led_pa[0])) { return -EIO; } if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_LED2_PA, config->led_pa[1])) { return -EIO; } if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_LED3_PA, config->led_pa[2])) { return -EIO; } #ifdef CONFIG_MAX30101_MULTI_LED_MODE uint8_t multi_led[2]; /* Write the multi-LED mode control registers */ multi_led[0] = (config->slot[1] << 4) | (config->slot[0]); multi_led[1] = (config->slot[3] << 4) | (config->slot[2]); if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_MULTI_LED, multi_led[0])) { return -EIO; } if (i2c_reg_write_byte_dt(&config->i2c, MAX30101_REG_MULTI_LED + 1, multi_led[1])) { return -EIO; } #endif /* Initialize the channel map and active channel count */ data->num_channels = 0U; for (led_chan = 0U; led_chan < MAX30101_MAX_NUM_CHANNELS; led_chan++) { data->map[led_chan] = MAX30101_MAX_NUM_CHANNELS; } /* Count the number of active channels and build a map that translates * the LED channel number (red/ir/green) to the fifo channel number. */ for (fifo_chan = 0; fifo_chan < MAX30101_MAX_NUM_CHANNELS; fifo_chan++) { led_chan = (config->slot[fifo_chan] & MAX30101_SLOT_LED_MASK)-1; if (led_chan < MAX30101_MAX_NUM_CHANNELS) { data->map[led_chan] = fifo_chan; data->num_channels++; } } return 0; } static struct max30101_config max30101_config = { .i2c = I2C_DT_SPEC_INST_GET(0), .fifo = (CONFIG_MAX30101_SMP_AVE << MAX30101_FIFO_CFG_SMP_AVE_SHIFT) | #ifdef CONFIG_MAX30101_FIFO_ROLLOVER_EN MAX30101_FIFO_CFG_ROLLOVER_EN_MASK | #endif (CONFIG_MAX30101_FIFO_A_FULL << MAX30101_FIFO_CFG_FIFO_FULL_SHIFT), #if defined(CONFIG_MAX30101_HEART_RATE_MODE) .mode = MAX30101_MODE_HEART_RATE, .slot[0] = MAX30101_SLOT_RED_LED1_PA, .slot[1] = MAX30101_SLOT_DISABLED, .slot[2] = MAX30101_SLOT_DISABLED, .slot[3] = MAX30101_SLOT_DISABLED, #elif defined(CONFIG_MAX30101_SPO2_MODE) .mode = MAX30101_MODE_SPO2, .slot[0] = MAX30101_SLOT_RED_LED1_PA, .slot[1] = MAX30101_SLOT_IR_LED2_PA, .slot[2] = MAX30101_SLOT_DISABLED, .slot[3] = MAX30101_SLOT_DISABLED, #else .mode = MAX30101_MODE_MULTI_LED, .slot[0] = CONFIG_MAX30101_SLOT1, .slot[1] = CONFIG_MAX30101_SLOT2, .slot[2] = CONFIG_MAX30101_SLOT3, .slot[3] = CONFIG_MAX30101_SLOT4, #endif .spo2 = (CONFIG_MAX30101_ADC_RGE << MAX30101_SPO2_ADC_RGE_SHIFT) | (CONFIG_MAX30101_SR << MAX30101_SPO2_SR_SHIFT) | (MAX30101_PW_18BITS << MAX30101_SPO2_PW_SHIFT), .led_pa[0] = CONFIG_MAX30101_LED1_PA, .led_pa[1] = CONFIG_MAX30101_LED2_PA, .led_pa[2] = CONFIG_MAX30101_LED3_PA, }; static struct max30101_data max30101_data; SENSOR_DEVICE_DT_INST_DEFINE(0, max30101_init, NULL, &max30101_data, &max30101_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &max30101_driver_api); ```
/content/code_sandbox/drivers/sensor/maxim/max30101/max30101.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,016
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_MAX44009_MAX44009_H_ #define ZEPHYR_DRIVERS_SENSOR_MAX44009_MAX44009_H_ #include <zephyr/sys/util.h> #include <zephyr/drivers/i2c.h> #define MAX44009_SAMPLING_CONTROL_BIT BIT(7) #define MAX44009_CONTINUOUS_SAMPLING BIT(7) #define MAX44009_SAMPLE_EXPONENT_SHIFT 12 #define MAX44009_MANTISSA_HIGH_NIBBLE_MASK 0xf00 #define MAX44009_MANTISSA_LOW_NIBBLE_MASK 0xf #define MAX44009_REG_CONFIG 0x02 #define MAX44009_REG_LUX_HIGH_BYTE 0x03 #define MAX44009_REG_LUX_LOW_BYTE 0x04 struct max44009_data { uint16_t sample; }; struct max44009_config { struct i2c_dt_spec i2c; }; #endif /* _SENSOR_MAX44009_ */ ```
/content/code_sandbox/drivers/sensor/maxim/max44009/max44009.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
205
```unknown # MAX30101 heart rate sensor menuconfig MAX30101 bool "MAX30101 Pulse Oximeter and Heart Rate Sensor" default y depends on DT_HAS_MAXIM_MAX30101_ENABLED select I2C if MAX30101 config MAX30101_SMP_AVE int "Sample averaging" range 0 7 default 0 help To reduce the amount of data throughput, adjacent samples (in each individual channel) can be averaged and decimated on the chip by setting this register. Set to 0 for no averaging. 0 = 1 sample (no averaging) 1 = 2 samples 2 = 4 samples 3 = 8 samples 4 = 16 samples 5 = 32 samples 6 = 32 samples 7 = 32 samples config MAX30101_FIFO_ROLLOVER_EN bool "FIFO rolls on full" help Controls the behavior of the FIFO when the FIFO becomes completely filled with data. If set, the FIFO address rolls over to zero and the FIFO continues to fill with new data. If not set, then the FIFO is not updated until FIFO_DATA is read or the WRITE/READ pointer positions are changed. config MAX30101_FIFO_A_FULL int "FIFO almost full value" range 0 15 default 0 help Set the trigger for the FIFO_A_FULL interrupt choice MAX30101_MODE prompt "Mode control" default MAX30101_MULTI_LED_MODE config MAX30101_HEART_RATE_MODE bool "Heart rate mode" help Set to operate in heart rate only mode. The red LED channel is active. config MAX30101_SPO2_MODE bool "SpO2 mode" help Set to operate in SpO2 mode. The red and IR LED channels are active. config MAX30101_MULTI_LED_MODE bool "Multi-LED mode" help Set to operate in multi-LED mode. The green, red, and/or IR LED channels are active. endchoice config MAX30101_ADC_RGE int "ADC range control" range 0 3 default 2 help Set the ADC's full-scale range. 0 = 7.81 pA/LSB 1 = 15.63 pA/LSB 2 = 31.25 pA/LSB 3 = 62.5 pA/LSB config MAX30101_SR int "ADC sample rate control" range 0 7 default 0 help Set the effective sampling rate with one sample consisting of one pulse/conversion per active LED channel. In SpO2 mode, these means one IR pulse/conversion and one red pulse/conversion per sample period. 0 = 50 Hz 1 = 100 Hz 2 = 200 Hz 3 = 400 Hz 4 = 800 Hz 5 = 1000 Hz 6 = 1600 Hz 7 = 3200 Hz config MAX30101_LED1_PA hex "LED1 (red) pulse amplitude" range 0 0xff default 0xff help Set the pulse amplitude to control the LED1 (red) current. The actual measured LED current for each part can vary significantly due to the trimming methodology. 0x00 = 0.0 mA 0x01 = 0.2 mA 0x02 = 0.4 mA 0x0f = 3.1 mA 0xff = 50.0 mA config MAX30101_LED2_PA hex "LED2 (IR) pulse amplitude" range 0 0xff default 0x33 help Set the pulse amplitude to control the LED2 (IR) current. The actual measured LED current for each part can vary significantly due to the trimming methodology. 0x00 = 0.0 mA 0x01 = 0.2 mA 0x02 = 0.4 mA 0x0f = 3.1 mA 0xff = 50.0 mA config MAX30101_LED3_PA hex "LED3 (green) pulse amplitude" range 0 0xff default 0xff help Set the pulse amplitude to control the LED3 (green) current. The actual measured LED current for each part can vary significantly due to the trimming methodology. 0x00 = 0.0 mA 0x01 = 0.2 mA 0x02 = 0.4 mA 0x0f = 3.1 mA 0xff = 50.0 mA if MAX30101_MULTI_LED_MODE config MAX30101_SLOT1 int "Slot 1" range 0 7 default 3 help Set which LED and pulse amplitude are active in time slot 1. 0: None (disabled) 1: LED1 (red), LED1_PA 2: LED2 (IR), LED2_PA 3: LED3 (green), LED3_PA 4: None (disabled) 5: LED1 (red), PILOT_PA 6: LED2 (IR), PILOT_PA 7: LED3 (green), PILOT_PA config MAX30101_SLOT2 int "Slot 2" range 0 7 default 0 help Set which LED and pulse amplitude are active in time slot 2. 0: None (disabled) 1: LED1 (red), LED1_PA 2: LED2 (IR), LED2_PA 3: LED3 (green), LED3_PA 4: None (disabled) 5: LED1 (red), PILOT_PA 6: LED2 (IR), PILOT_PA 7: LED3 (green), PILOT_PA config MAX30101_SLOT3 int "Slot 3" range 0 7 default 0 help Set which LED and pulse amplitude are active in time slot 3. 0: None (disabled) 1: LED1 (red), LED1_PA 2: LED2 (IR), LED2_PA 3: LED3 (green), LED3_PA 4: None (disabled) 5: LED1 (red), PILOT_PA 6: LED2 (IR), PILOT_PA 7: LED3 (green), PILOT_PA config MAX30101_SLOT4 int "Slot 4" range 0 7 default 0 help Set which LED and pulse amplitude are active in time slot 4. 0: None (disabled) 1: LED1 (red), LED1_PA 2: LED2 (IR), LED2_PA 3: LED3 (green), LED3_PA 4: None (disabled) 5: LED1 (red), PILOT_PA 6: LED2 (IR), PILOT_PA 7: LED3 (green), PILOT_PA endif # MAX30101_MULTI_LED_MODE endif # MAX30101 ```
/content/code_sandbox/drivers/sensor/maxim/max30101/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,635
```unknown # MAX44009 light sensor configuration options config MAX44009 bool "MAX44009 Light Sensor" default y depends on DT_HAS_MAXIM_MAX44009_ENABLED select I2C help Enable driver for MAX44009 light sensors. ```
/content/code_sandbox/drivers/sensor/maxim/max44009/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
55
```c /* * */ #define DT_DRV_COMPAT maxim_max44009 #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/__assert.h> #include <zephyr/logging/log.h> #include "max44009.h" LOG_MODULE_REGISTER(MAX44009, CONFIG_SENSOR_LOG_LEVEL); static int max44009_reg_read(const struct device *dev, uint8_t reg, uint8_t *val, bool send_stop) { const struct max44009_config *config = dev->config; struct i2c_msg msgs[2] = { { .buf = &reg, .len = 1, .flags = I2C_MSG_WRITE, }, { .buf = val, .len = 1, .flags = I2C_MSG_READ, }, }; if (send_stop) { msgs[1].flags |= I2C_MSG_STOP; } if (i2c_transfer_dt(&config->i2c, msgs, 2) != 0) { return -EIO; } return 0; } static int max44009_reg_write(const struct device *dev, uint8_t reg, uint8_t val) { const struct max44009_config *config = dev->config; uint8_t tx_buf[2] = {reg, val}; return i2c_write_dt(&config->i2c, tx_buf, sizeof(tx_buf)); } static int max44009_reg_update(const struct device *dev, uint8_t reg, uint8_t mask, uint8_t val) { uint8_t old_val = 0U; uint8_t new_val = 0U; if (max44009_reg_read(dev, reg, &old_val, true) != 0) { return -EIO; } new_val = old_val & ~mask; new_val |= val & mask; return max44009_reg_write(dev, reg, new_val); } static int max44009_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { uint8_t value; uint32_t cr; if (chan != SENSOR_CHAN_LIGHT) { return -ENOTSUP; } switch (attr) { case SENSOR_ATTR_SAMPLING_FREQUENCY: /* convert rate to mHz */ cr = val->val1 * 1000 + val->val2 / 1000; /* the sensor supports 1.25Hz or continuous conversion */ switch (cr) { case 1250: value = 0U; break; default: value = MAX44009_CONTINUOUS_SAMPLING; } if (max44009_reg_update(dev, MAX44009_REG_CONFIG, MAX44009_SAMPLING_CONTROL_BIT, value) != 0) { LOG_DBG("Failed to set attribute!"); return -EIO; } return 0; default: return -ENOTSUP; } return 0; } static int max44009_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct max44009_data *drv_data = dev->data; uint8_t val_h, val_l; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_LIGHT); drv_data->sample = 0U; if (max44009_reg_read(dev, MAX44009_REG_LUX_HIGH_BYTE, &val_h, false) != 0) { return -EIO; } if (max44009_reg_read(dev, MAX44009_REG_LUX_LOW_BYTE, &val_l, true) != 0) { return -EIO; } drv_data->sample = ((uint16_t)val_h) << 8; drv_data->sample += val_l; return 0; } static int max44009_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max44009_data *drv_data = dev->data; uint32_t uval; if (chan != SENSOR_CHAN_LIGHT) { return -ENOTSUP; } /** * sample consists of 4 bits of exponent and 8 bits of mantissa * bits 15 to 12 are exponent bits * bits 11 to 8 and 3 to 0 are the mantissa bits */ uval = drv_data->sample; uval = (uval & MAX44009_MANTISSA_LOW_NIBBLE_MASK) + ((uval & MAX44009_MANTISSA_HIGH_NIBBLE_MASK) >> 4); uval = uval << (drv_data->sample >> MAX44009_SAMPLE_EXPONENT_SHIFT); /* lux is the integer of sample output multiplied by 0.045. */ val->val1 = (uval * 45U) / 1000; val->val2 = ((uval * 45U) % 1000) * 1000U; return 0; } static const struct sensor_driver_api max44009_driver_api = { .attr_set = max44009_attr_set, .sample_fetch = max44009_sample_fetch, .channel_get = max44009_channel_get, }; int max44009_init(const struct device *dev) { const struct max44009_config *config = dev->config; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("Bus device is not ready"); return -ENODEV; } return 0; } #define MAX44009_DEFINE(inst) \ static struct max44009_data max44009_data_##inst; \ \ static const struct max44009_config max44009_config_##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, max44009_init, NULL, \ &max44009_data_##inst, &max44009_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max44009_driver_api); \ DT_INST_FOREACH_STATUS_OKAY(MAX44009_DEFINE) ```
/content/code_sandbox/drivers/sensor/maxim/max44009/max44009.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,345
```unknown # MAX31865 temperature sensor configuration options config MAX31865 bool "MAX31865 Temperature Sensor" default y depends on DT_HAS_MAXIM_MAX31865_ENABLED select SPI help Enable the driver for Maxim MAX31865 SPI Temperature Sensors. ```
/content/code_sandbox/drivers/sensor/maxim/max31865/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
56
```objective-c /* * */ #ifndef _MAX31865_H #define _MAX31865_H #define DT_DRV_COMPAT maxim_max31865 #include <math.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/sensor/max31865.h> #include <zephyr/drivers/spi.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/sys/util_macro.h> #include <zephyr/sys/byteorder.h> LOG_MODULE_REGISTER(MAX31865, CONFIG_SENSOR_LOG_LEVEL); #define MAX31865_FAULT_HIGH_THRESHOLD BIT(7) #define MAX31865_FAULT_LOW_THRESHOLD BIT(6) #define MAX31865_FAULT_REFIN BIT(5) #define MAX31865_FAULT_REFIN_FORCE BIT(4) #define MAX31865_FAULT_RTDIN_FORCE BIT(3) #define MAX31865_FAULT_VOLTAGE BIT(2) #define MAX31865_FAULT_DETECTION_NONE (0x00 << 2) #define MAX31865_FAULT_DETECTION_AUTO (0x01 << 2) #define MAX31865_FAULT_DETECTION_MANUAL_1 (0x02 << 2) #define MAX31865_FAULT_DETECTION_MANUAL_2 (0x03 << 2) /* Read Register Address */ #define REG_CONFIG 0x00 #define REG_RTD_MSB 0x01 #define REG_RTD_LSB 0x02 #define REG_HIGH_FAULT_THR_MSB 0x03 #define REG_HIGH_FAULT_THR_LSB 0x04 #define REG_LOW_FAULT_THR_MSB 0x05 #define REG_LOW_FAULT_THR_LSB 0x06 #define REG_FAULT_STATUS 0x07 #define WR(reg) ((reg) | 0x80) /* Bitmask to clear fault status bits D5, D3, and D2 */ #define FAULT_BITS_CLEAR_MASK 0x2C /** * RTD data, RTD current, and measurement reference * voltage. The ITS-90 standard is used; other RTDs * may have coefficients defined by the DIN 43760 or * the U.S. Industrial (American) standard. */ #define RTD_A_ITS90 3.9080e-3 #define RTD_A_USINDUSTRIAL 3.9692e-3 #define RTD_A_DIN43760 3.9848e-3 #define RTD_B_ITS90 -5.870e-7 #define RTD_B_USINDUSTRIAL -5.8495e-7 #define RTD_B_DIN43760 -5.8019e-7 /** * RTD coefficient C is required only for temperatures * below 0 deg. C. The selected RTD coefficient set * is specified below. */ #define RTD_A (RTD_A_ITS90) #define RTD_B (RTD_B_ITS90) /* * For under zero, taken from * path_to_url */ static const float A[6] = {-242.02, 2.2228, 2.5859e-3, 4.8260e-6, 2.8183e-8, 1.5243e-10}; struct max31865_data { double temperature; uint8_t config_control_bits; }; /** * Configuration struct to the MAX31865. */ struct max31865_config { const struct spi_dt_spec spi; uint16_t resistance_at_zero; uint16_t resistance_reference; bool conversion_mode; bool one_shot; bool three_wire; uint8_t fault_cycle; bool filter_50hz; uint16_t low_threshold; uint16_t high_threshold; }; /* Bit manipulation macros */ #define TESTBIT(data, pos) ((0u == (data & BIT(pos))) ? 0u : 1u) #endif ```
/content/code_sandbox/drivers/sensor/maxim/max31865/max31865.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
812
```c /* * */ #define DT_DRV_COMPAT maxim_max31790_fan_fault #include <zephyr/drivers/mfd/max31790.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/sensor/max31790.h> #include <zephyr/logging/log.h> #include "max31790_fan_fault.h" LOG_MODULE_REGISTER(MAX31790_FAN_FAULT, CONFIG_SENSOR_LOG_LEVEL); static int max31790_fan_fault_sample_fetch(const struct device *dev, enum sensor_channel chan) { const struct max31790_fan_fault_config *config = dev->config; struct max31790_fan_fault_data *data = dev->data; int result; uint8_t value; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); result = i2c_reg_read_byte_dt(&config->i2c, MAX37190_REGISTER_FANFAULTSTATUS1, &value); if (result != 0) { return result; } data->value = value & 0x3F; return 0; } static int max31790_fan_fault_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max31790_fan_fault_data *data = dev->data; if ((enum sensor_channel_max31790)chan != SENSOR_CHAN_MAX31790_FAN_FAULT) { LOG_ERR("%s: requesting unsupported channel %i", dev->name, chan); return -ENOTSUP; } val->val1 = data->value; val->val2 = 0; return 0; } static const struct sensor_driver_api max31790_fan_fault_api = { .sample_fetch = max31790_fan_fault_sample_fetch, .channel_get = max31790_fan_fault_channel_get, }; static int max31790_fan_fault_init(const struct device *dev) { const struct max31790_fan_fault_config *config = dev->config; if (!i2c_is_ready_dt(&config->i2c)) { LOG_ERR("I2C device not ready"); return -ENODEV; } return 0; } #define MAX31790_FAN_FAULT_INIT(inst) \ static const struct max31790_fan_fault_config max31790_fan_fault_##inst##_config = { \ .i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \ }; \ \ static struct max31790_fan_fault_data max31790_fan_fault_##inst##_data; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, max31790_fan_fault_init, NULL, \ &max31790_fan_fault_##inst##_data, \ &max31790_fan_fault_##inst##_config, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max31790_fan_fault_api); DT_INST_FOREACH_STATUS_OKAY(MAX31790_FAN_FAULT_INIT); ```
/content/code_sandbox/drivers/sensor/maxim/max31790/max31790_fan_fault.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
617
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_FAULT_H_ #define ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_FAULT_H_ #include <zephyr/drivers/i2c.h> struct max31790_fan_fault_config { struct i2c_dt_spec i2c; }; struct max31790_fan_fault_data { uint16_t value; }; #endif /* ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_FAULT_H_ */ ```
/content/code_sandbox/drivers/sensor/maxim/max31790/max31790_fan_fault.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
109
```c /* * */ #define DT_DRV_COMPAT maxim_max31790_fan_speed #include <zephyr/drivers/mfd/max31790.h> #include <zephyr/drivers/sensor.h> #include <zephyr/logging/log.h> #include <zephyr/sys/byteorder.h> #include "max31790_fan_speed.h" #define FACTOR_RPM_TO_HZ 60 #define TACH_COUNT_FREQUENCY (MAX31790_OSCILLATOR_FREQUENCY_IN_HZ / 4) #define TACH_COUNTS_PER_REVOLUTION 2 LOG_MODULE_REGISTER(MAX31790_FAN_SPEED, CONFIG_SENSOR_LOG_LEVEL); static int max31790_fan_speed_sample_fetch(const struct device *dev, enum sensor_channel chan) { const struct max31790_fan_speed_config *config = dev->config; struct max31790_fan_speed_data *data = dev->data; uint16_t tach_count; uint8_t fan_dynamics; uint8_t number_tach_periods_counted; uint8_t speed_range; uint8_t register_address; int result; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); register_address = MAX37190_REGISTER_TACHCOUNTMSB(config->channel_id); result = i2c_write_read_dt(&config->i2c, &register_address, sizeof(register_address), &tach_count, sizeof(tach_count)); tach_count = sys_be16_to_cpu(tach_count); if (result != 0) { return result; } result = i2c_reg_read_byte_dt( &config->i2c, MAX31790_REGISTER_FANDYNAMICS(config->channel_id), &fan_dynamics); if (result != 0) { return result; } tach_count = tach_count >> 5; speed_range = MAX31790_FANXDYNAMCIS_SPEED_RANGE_GET(fan_dynamics); switch (speed_range) { case 0: number_tach_periods_counted = 1; break; case 1: number_tach_periods_counted = 2; break; case 2: number_tach_periods_counted = 4; break; case 3: number_tach_periods_counted = 8; break; case 4: number_tach_periods_counted = 16; break; case 5: __fallthrough; case 6: __fallthrough; case 7: number_tach_periods_counted = 32; break; default: LOG_ERR("%s: invalid speed range %i", dev->name, speed_range); return -EINVAL; } if (tach_count == 0) { LOG_WRN("%s: tach count is zero", dev->name); data->rpm = UINT16_MAX; } else { LOG_DBG("%s: %i tach periods counted, %i tach count", dev->name, number_tach_periods_counted, tach_count); data->rpm = FACTOR_RPM_TO_HZ * TACH_COUNT_FREQUENCY * number_tach_periods_counted / (tach_count * TACH_COUNTS_PER_REVOLUTION); } return 0; } static int max31790_fan_speed_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max31790_fan_speed_data *data = dev->data; if (chan != SENSOR_CHAN_RPM) { LOG_ERR("%s: requesting unsupported channel %i", dev->name, chan); return -ENOTSUP; } val->val1 = data->rpm; val->val2 = 0; return 0; } static const struct sensor_driver_api max31790_fan_speed_api = { .sample_fetch = max31790_fan_speed_sample_fetch, .channel_get = max31790_fan_speed_channel_get, }; static int max31790_fan_speed_init(const struct device *dev) { const struct max31790_fan_speed_config *config = dev->config; if (!i2c_is_ready_dt(&config->i2c)) { LOG_ERR("I2C device not ready"); return -ENODEV; } return 0; } #define MAX31790_FAN_SPEED_INIT(inst) \ static const struct max31790_fan_speed_config max31790_fan_speed_##inst##_config = { \ .i2c = I2C_DT_SPEC_GET(DT_INST_PARENT(inst)), \ .channel_id = DT_INST_PROP(inst, channel) - 1, \ }; \ \ static struct max31790_fan_speed_data max31790_fan_speed_##inst##_data; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, max31790_fan_speed_init, NULL, \ &max31790_fan_speed_##inst##_data, \ &max31790_fan_speed_##inst##_config, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &max31790_fan_speed_api); DT_INST_FOREACH_STATUS_OKAY(MAX31790_FAN_SPEED_INIT); ```
/content/code_sandbox/drivers/sensor/maxim/max31790/max31790_fan_speed.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,078
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_SPEED_H_ #define ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_SPEED_H_ #include <zephyr/drivers/i2c.h> struct max31790_fan_speed_config { struct i2c_dt_spec i2c; uint8_t channel_id; }; struct max31790_fan_speed_data { uint16_t rpm; }; #endif /* ZEPHYR_DRIVERS_SENSOR_MAX31790_MAX31790_FAN_SPEED_H_ */ ```
/content/code_sandbox/drivers/sensor/maxim/max31790/max31790_fan_speed.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
115
```c /* * */ #include "max31865.h" static int max31865_spi_write(const struct device *dev, uint8_t reg, uint8_t *data, size_t len) { const struct max31865_config *cfg = dev->config; const struct spi_buf bufs[] = {{ .buf = &reg, .len = 1, }, {.buf = data, .len = len}}; const struct spi_buf_set tx = {.buffers = bufs, .count = 2}; return spi_write_dt(&cfg->spi, &tx); } static int max31865_spi_read(const struct device *dev, uint8_t reg, uint8_t *data, size_t len) { const struct max31865_config *cfg = dev->config; reg &= 0x7F; const struct spi_buf tx_buf = {.buf = &reg, .len = 1}; const struct spi_buf_set tx = {.buffers = &tx_buf, .count = 1}; struct spi_buf rx_buf[] = {{ .buf = &reg, .len = 1, }, {.buf = data, .len = len}}; const struct spi_buf_set rx = {.buffers = rx_buf, .count = 2}; return spi_transceive_dt(&cfg->spi, &tx, &rx); } /** * @brief Set device configuration register * * @param device device instance * @return 0 if successful, or negative error code from SPI API */ static int configure_device(const struct device *dev) { struct max31865_data *data = dev->data; uint8_t cmd[] = {data->config_control_bits}; int err = max31865_spi_write(dev, WR(REG_CONFIG), cmd, 1); if (err < 0) { LOG_ERR("Error write SPI%d\n", err); } return err; } /** * @brief Set device fail threshold registers * * @param device device instance * @return 0 if successful, or negative error code from SPI API */ static int set_threshold_values(const struct device *dev) { const struct max31865_config *config = dev->config; uint8_t cmd[] = { (config->high_threshold >> 7) & 0x00ff, (config->high_threshold << 1) & 0x00ff, (config->low_threshold >> 7) & 0x00ff, (config->low_threshold << 1) & 0x00ff}; int err = max31865_spi_write(dev, WR(REG_HIGH_FAULT_THR_MSB), cmd, 4); if (err < 0) { LOG_ERR("Error write SPI%d\n", err); } return err; } #ifdef CONFIG_NEWLIB_LIBC /** * Apply the Callendar-Van Dusen equation to convert the RTD resistance * to temperature: * Tr = (-A + SQRT(delta) ) / 2*B * delta = A^2 - 4B*(1-Rt/Ro) * For under zero, taken from * path_to_url * @param resistance measured resistance * @param resistance_0 constant resistance at 0oC * @return calculated temperature */ static double calculate_temperature(double resistance, double resistance_0) { double temperature; double delta = (RTD_A * RTD_A) - 4 * RTD_B * (1.0 - resistance / resistance_0); temperature = (-RTD_A + sqrt(delta)) / (2 * RTD_B); if (temperature > 0.0) { return temperature; } resistance /= resistance_0; resistance *= 100.0; temperature = A[0] + A[1] * resistance + A[2] * pow(resistance, 2) - A[3] * pow(resistance, 3) - A[4] * pow(resistance, 4) + A[5] * pow(resistance, 5); return temperature; } #else /** * Apply a very good linear approximation of the Callendar-Van Dusen equation to convert the RTD * resistance to temperature: * @param resistance measured resistance * @param resistance_0 constant resistance at 0oC * @return calculated temperature */ static double calculate_temperature(double resistance, double resistance_0) { double temperature; temperature = (resistance - resistance_0) / (resistance_0 * RTD_A); return temperature; } #endif /** * @brief Enable/Disable Vbias for MAX31865 * * @param device device instance * @param enable true, turn on vbias, false, turn off vbias * @return 0 if successful, or negative error code from SPI API */ static int max31865_set_vbias(const struct device *dev, bool enable) { struct max31865_data *data = dev->data; WRITE_BIT(data->config_control_bits, 7, enable); return configure_device(dev); } static int max31865_set_three_wire(const struct device *dev, bool enable) { struct max31865_data *data = dev->data; WRITE_BIT(data->config_control_bits, 4, enable); return configure_device(dev); } static char *max31865_error_to_string(uint8_t fault_register) { switch (fault_register) { case 0: return "No error"; case MAX31865_FAULT_VOLTAGE: return "Over/under voltage fault"; case MAX31865_FAULT_RTDIN_FORCE: return "RTDIN- < 0.85*VBIAS (FORCE- open)"; case MAX31865_FAULT_REFIN_FORCE: return "REFIN- < 0.85*VBIAS (FORCE- open)"; case MAX31865_FAULT_REFIN: return "REFIN- > 0.85*VBIAS"; case MAX31865_FAULT_LOW_THRESHOLD: return "RTD below low threshold"; case MAX31865_FAULT_HIGH_THRESHOLD: return "RTD above high threshold"; } return ""; } static int max31865_fault_register(const struct device *dev) { uint8_t fault_register; uint8_t saved_fault_bits; max31865_spi_read(dev, (REG_FAULT_STATUS), &fault_register, 1); struct max31865_data *data = dev->data; saved_fault_bits = data->config_control_bits & FAULT_BITS_CLEAR_MASK; /*Clear fault register */ WRITE_BIT(data->config_control_bits, 1, 1); data->config_control_bits &= ~FAULT_BITS_CLEAR_MASK; configure_device(dev); LOG_ERR("Fault Register: 0x%02x, %s", fault_register, max31865_error_to_string(fault_register)); WRITE_BIT(data->config_control_bits, 1, 0); data->config_control_bits |= saved_fault_bits; return 0; } /** * @brief Get temperature value in oC for device * * @param device device instance * @param temperature measured temperature * @return 0 if successful, or negative error code */ static int max31865_get_temperature(const struct device *dev) { max31865_set_vbias(dev, true); union read_reg_u { uint8_t u8[2]; uint16_t u16; } read_reg; read_reg.u16 = 0; /* Waiting Time for Temerature Conversion (Page 3 of the datasheet)*/ k_sleep(K_MSEC(66)); /* Read resistance measured value */ int err = max31865_spi_read(dev, (REG_RTD_MSB), read_reg.u8, 2); max31865_set_vbias(dev, false); if (err < 0) { LOG_ERR("SPI read %d\n", err); return -EIO; } read_reg.u16 = sys_be16_to_cpu(read_reg.u16); LOG_DBG("RAW: %02X %02X , %04X", read_reg.u8[0], read_reg.u8[1], read_reg.u16); if (TESTBIT(read_reg.u16, 0)) { max31865_fault_register(dev); return -EIO; } const struct max31865_config *config = dev->config; struct max31865_data *data = dev->data; read_reg.u16 = read_reg.u16 >> 1; double resistance = (double)read_reg.u16; resistance /= 32768; resistance *= config->resistance_reference; data->temperature = calculate_temperature(resistance, config->resistance_at_zero); return 0; } static int max31865_init(const struct device *dev) { const struct max31865_config *config = dev->config; if (!spi_is_ready_dt(&config->spi)) { return -ENODEV; } struct max31865_data *data = dev->data; /* Set the confgiuration register */ data->config_control_bits = 0; WRITE_BIT(data->config_control_bits, 6, config->conversion_mode); WRITE_BIT(data->config_control_bits, 5, config->one_shot); data->config_control_bits |= config->fault_cycle & 0b00001100; WRITE_BIT(data->config_control_bits, 0, config->filter_50hz); configure_device(dev); set_threshold_values(dev); max31865_set_vbias(dev, false); max31865_set_three_wire(dev, config->three_wire); return 0; } static int max31865_sample_fetch(const struct device *dev, enum sensor_channel chan) { if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_AMBIENT_TEMP) { LOG_ERR("Invalid channel provided"); return -ENOTSUP; } return max31865_get_temperature(dev); } static int max31865_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct max31865_data *data = dev->data; switch (chan) { case SENSOR_CHAN_AMBIENT_TEMP: return sensor_value_from_double(val, data->temperature); default: return -ENOTSUP; } } static int max31865_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_AMBIENT_TEMP) { LOG_ERR("Invalid channel provided"); return -ENOTSUP; } switch (attr) { case SENSOR_ATTR_MAX31865_THREE_WIRE: return max31865_set_three_wire(dev, val->val1); default: return -ENOTSUP; } } static const struct sensor_driver_api max31865_api_funcs = { .sample_fetch = max31865_sample_fetch, .channel_get = max31865_channel_get, .attr_set = max31865_attr_set, }; #define MAX31865_DEFINE(inst) \ \ static struct max31865_data max31865_data_##inst; \ \ static const struct max31865_config max31865_config_##inst = { \ .spi = SPI_DT_SPEC_INST_GET(inst, SPI_MODE_CPHA | SPI_WORD_SET(8), 0), \ .resistance_at_zero = DT_INST_PROP(inst, resistance_at_zero), \ .resistance_reference = DT_INST_PROP(inst, resistance_reference), \ .conversion_mode = false, \ .one_shot = true, \ .three_wire = DT_INST_PROP(inst, maxim_3_wire), \ .fault_cycle = MAX31865_FAULT_DETECTION_NONE, \ .filter_50hz = DT_INST_PROP(inst, filter_50hz), \ .low_threshold = DT_INST_PROP(inst, low_threshold), \ .high_threshold = DT_INST_PROP(inst, high_threshold), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, max31865_init, NULL, &max31865_data_##inst, \ &max31865_config_##inst, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ &max31865_api_funcs); /* Create the struct device for every status "okay" node in the devicetree. */ DT_INST_FOREACH_STATUS_OKAY(MAX31865_DEFINE) ```
/content/code_sandbox/drivers/sensor/maxim/max31865/max31865.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,596
```unknown # zephyr-keep-sorted-start source "drivers/sensor/seeed/grove/Kconfig" source "drivers/sensor/seeed/hm330x/Kconfig" # zephyr-keep-sorted-stop ```
/content/code_sandbox/drivers/sensor/seeed/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
50
```unknown config MAX31790_SENSOR bool "MAX31790 sensors" default y depends on MAX31790_FAN_SPEED || MAX31790_FAN_FAULT help Enable sensors for the MAX31790 PWM controller. config MAX31790_FAN_SPEED bool "MAX31790 fan speed sensor" default y depends on DT_HAS_MAXIM_MAX31790_FAN_SPEED_ENABLED select MFD help Enable driver for the MAX31790 fan speed sensor. config MAX31790_FAN_FAULT bool "MAX31790 fan fault sensor" default y depends on DT_HAS_MAXIM_MAX31790_FAN_FAULT_ENABLED select MFD help Enable driver for the MAX31790 fan fault sensor. ```
/content/code_sandbox/drivers/sensor/maxim/max31790/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
154
```unknown # Seeed Studio HM330x dust particle sensor configuration options config HM330X bool "HM330X dust particle sensor" default y depends on DT_HAS_SEEED_HM330X_ENABLED select I2C help Enable driver for the HM330X dust particle sensor. ```
/content/code_sandbox/drivers/sensor/seeed/hm330x/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
64
```c /* * */ #define DT_DRV_COMPAT seeed_hm330x #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/init.h> #include <zephyr/logging/log.h> #include <zephyr/sys/__assert.h> LOG_MODULE_REGISTER(HM3301, CONFIG_SENSOR_LOG_LEVEL); #define HM330X_SELECT_COMM_CMD 0X88 #define HM330X_PM_1_0_ATM 10 #define HM330X_PM_2_5_ATM 12 #define HM330X_PM_10_ATM 14 #define HM330X_FRAME_LEN 29 struct hm330x_data { uint16_t pm_1_0_sample; uint16_t pm_2_5_sample; uint16_t pm_10_sample; }; struct hm330x_config { struct i2c_dt_spec i2c; }; static int hm330x_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct hm330x_data *drv_data = dev->data; const struct hm330x_config *config = dev->config; uint8_t buf[HM330X_FRAME_LEN]; uint8_t checksum = 0; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); if (i2c_burst_read_dt(&config->i2c, 0, buf, HM330X_FRAME_LEN) < 0) { return -EIO; } drv_data->pm_1_0_sample = (buf[HM330X_PM_1_0_ATM] << 8) | buf[HM330X_PM_1_0_ATM + 1]; drv_data->pm_2_5_sample = (buf[HM330X_PM_2_5_ATM] << 8) | buf[HM330X_PM_2_5_ATM + 1]; drv_data->pm_10_sample = (buf[HM330X_PM_10_ATM] << 8) | buf[HM330X_PM_10_ATM + 1]; for (int i = 0; i < HM330X_FRAME_LEN - 1; i++) { checksum += buf[i]; } if (checksum != buf[HM330X_FRAME_LEN - 1]) { LOG_ERR("Checksum error"); return -EBADMSG; } return 0; } static int hm330x_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct hm330x_data *drv_data = dev->data; if (chan == SENSOR_CHAN_PM_1_0) { val->val1 = drv_data->pm_1_0_sample; val->val2 = 0; } else if (chan == SENSOR_CHAN_PM_2_5) { val->val1 = drv_data->pm_2_5_sample; val->val2 = 0; } else if (chan == SENSOR_CHAN_PM_10) { val->val1 = drv_data->pm_10_sample; val->val2 = 0; } else { return -ENOTSUP; } return 0; } static const struct sensor_driver_api hm330x_driver_api = { .sample_fetch = hm330x_sample_fetch, .channel_get = hm330x_channel_get }; int hm330x_init(const struct device *dev) { const struct hm330x_config *config = dev->config; if (!i2c_is_ready_dt(&config->i2c)) { LOG_ERR("I2C bus device not ready"); return -ENODEV; } /** Enable I2C communications (module defaults to UART) */ if (i2c_reg_write_byte_dt(&config->i2c, 0, HM330X_SELECT_COMM_CMD) < 0) { LOG_ERR("Failed to switch to I2C"); return -EIO; } return 0; } #define HM330X_DEFINE(inst) \ static struct hm330x_data hm330x_data_##inst; \ \ static const struct hm330x_config hm330x_config##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst) \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, hm330x_init, NULL, &hm330x_data_##inst, \ &hm330x_config##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &hm330x_driver_api); \ DT_INST_FOREACH_STATUS_OKAY(HM330X_DEFINE) ```
/content/code_sandbox/drivers/sensor/seeed/hm330x/hm330x.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
988
```c /* * */ #define DT_DRV_COMPAT seeed_grove_temperature #include <zephyr/drivers/adc.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <math.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(grove_temp, CONFIG_SENSOR_LOG_LEVEL); /* The effect of gain and reference voltage must cancel. */ #ifdef CONFIG_ADC_NRFX_SAADC #define GROVE_GAIN ADC_GAIN_1_4 #define GROVE_REF ADC_REF_VDD_1_4 #define GROVE_RESOLUTION 12 #else #define GROVE_GAIN ADC_GAIN_1 #define GROVE_REF ADC_REF_VDD_1 #define GROVE_RESOLUTION 12 #endif struct gts_data { struct adc_channel_cfg ch_cfg; uint16_t raw; }; struct gts_config { const struct device *adc; int16_t b_const; uint8_t adc_channel; }; static struct adc_sequence_options options = { .extra_samplings = 0, .interval_us = 15, }; static struct adc_sequence adc_table = { .options = &options, }; static int gts_sample_fetch(const struct device *dev, enum sensor_channel chan) { const struct gts_config *cfg = dev->config; return adc_read(cfg->adc, &adc_table); } static int gts_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct gts_data *drv_data = dev->data; const struct gts_config *cfg = dev->config; double dval; /* * The formula for converting the analog value to degrees Celsius * is taken from the sensor reference page: * path_to_url */ dval = (1 / (log((BIT(GROVE_RESOLUTION) - 1.0) / drv_data->raw - 1.0) / cfg->b_const + (1 / 298.15))) - 273.15; val->val1 = (int32_t)dval; val->val2 = ((int32_t)(dval * 1000000)) % 1000000; return 0; } static const struct sensor_driver_api gts_api = { .sample_fetch = &gts_sample_fetch, .channel_get = &gts_channel_get, }; static int gts_init(const struct device *dev) { struct gts_data *drv_data = dev->data; const struct gts_config *cfg = dev->config; if (!device_is_ready(cfg->adc)) { LOG_ERR("ADC device is not ready."); return -EINVAL; } /*Change following parameters according to board if necessary*/ drv_data->ch_cfg = (struct adc_channel_cfg){ .gain = GROVE_GAIN, .reference = GROVE_REF, .acquisition_time = ADC_ACQ_TIME_DEFAULT, .channel_id = cfg->adc_channel, #ifdef CONFIG_ADC_NRFX_SAADC .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + cfg->adc_channel, #endif }; adc_table.buffer = &drv_data->raw; adc_table.buffer_size = sizeof(drv_data->raw); adc_table.resolution = GROVE_RESOLUTION; adc_table.channels = BIT(cfg->adc_channel); adc_channel_setup(cfg->adc, &drv_data->ch_cfg); return 0; } #define GTS_DEFINE(inst) \ static struct gts_data gts_data_##inst; \ \ static const struct gts_config gts_cfg_##inst = { \ .adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \ .b_const = (IS_ENABLED(DT_INST_PROP(inst, v1p0)) \ ? 3975 \ : 4250), \ .adc_channel = DT_INST_IO_CHANNELS_INPUT(inst), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, &gts_init, NULL, \ &gts_data_##inst, &gts_cfg_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &gts_api); \ DT_INST_FOREACH_STATUS_OKAY(GTS_DEFINE) ```
/content/code_sandbox/drivers/sensor/seeed/grove/temperature_sensor.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
942
```unknown # Drivers configuration options for SeeedStudio Grove Devices config GROVE_SENSORS bool "Seeed Grove sensors support" default y depends on DT_HAS_SEEED_GROVE_LIGHT_ENABLED || DT_HAS_SEEED_GROVE_TEMPERATURE_ENABLED help Enable Seeed Grove sensors support. if GROVE_SENSORS config GROVE_LIGHT_SENSOR bool "The Seeed Grove Light Sensor" default y depends on DT_HAS_SEEED_GROVE_LIGHT_ENABLED select ADC help Setting this value will enable driver support for the Grove Light Sensor. config GROVE_TEMPERATURE_SENSOR bool "The Seeed Grove Temperature Sensor" default y depends on DT_HAS_SEEED_GROVE_TEMPERATURE_ENABLED select ADC help Setting this value will enable driver support for the Grove Temperature Sensor. endif # GROVE_SENSORS ```
/content/code_sandbox/drivers/sensor/seeed/grove/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
191
```unknown # zephyr-keep-sorted-start source "drivers/sensor/honeywell/hmc5883l/Kconfig" source "drivers/sensor/honeywell/mpr/Kconfig" source "drivers/sensor/honeywell/sm351lt/Kconfig" # zephyr-keep-sorted-stop ```
/content/code_sandbox/drivers/sensor/honeywell/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
65
```c /* * */ #define DT_DRV_COMPAT seeed_grove_light #include <zephyr/drivers/adc.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <math.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(grove_light, CONFIG_SENSOR_LOG_LEVEL); /* The effect of gain and reference voltage must cancel. */ #ifdef CONFIG_ADC_NRFX_SAADC #define GROVE_GAIN ADC_GAIN_1_4 #define GROVE_REF ADC_REF_VDD_1_4 #define GROVE_RESOLUTION 12 #else #define GROVE_GAIN ADC_GAIN_1 #define GROVE_REF ADC_REF_VDD_1 #define GROVE_RESOLUTION 12 #endif struct gls_data { const struct device *adc; struct adc_channel_cfg ch_cfg; uint16_t raw; }; struct gls_config { const struct device *adc; uint8_t adc_channel; }; static struct adc_sequence_options options = { .interval_us = 12, .extra_samplings = 0, }; static struct adc_sequence adc_table = { .options = &options, }; static int gls_sample_fetch(const struct device *dev, enum sensor_channel chan) { const struct gls_config *cfg = dev->config; return adc_read(cfg->adc, &adc_table); } static int gls_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct gls_data *drv_data = dev->data; uint16_t analog_val = drv_data->raw; double ldr_val, dval; /* * The formula for converting the analog value to lux is taken from * the UPM project: * path_to_url#L161 */ ldr_val = (BIT(GROVE_RESOLUTION) - 1.0 - analog_val) * 10.0 / analog_val; dval = 10000.0 / pow(ldr_val * 15.0, 4.0/3.0); val->val1 = (int32_t)dval; val->val2 = ((int32_t)(dval * 1000000)) % 1000000; return 0; } static const struct sensor_driver_api gls_api = { .sample_fetch = &gls_sample_fetch, .channel_get = &gls_channel_get, }; static int gls_init(const struct device *dev) { struct gls_data *drv_data = dev->data; const struct gls_config *cfg = dev->config; if (!device_is_ready(cfg->adc)) { LOG_ERR("ADC device is not ready."); return -EINVAL; } /*Change following parameters according to board if necessary*/ drv_data->ch_cfg = (struct adc_channel_cfg){ .gain = GROVE_GAIN, .reference = GROVE_REF, .acquisition_time = ADC_ACQ_TIME_DEFAULT, .channel_id = cfg->adc_channel, #ifdef CONFIG_ADC_NRFX_SAADC .input_positive = SAADC_CH_PSELP_PSELP_AnalogInput0 + cfg->adc_channel, #endif }; adc_table.buffer = &drv_data->raw; adc_table.buffer_size = sizeof(drv_data->raw); adc_table.resolution = GROVE_RESOLUTION; adc_table.channels = BIT(cfg->adc_channel); adc_channel_setup(cfg->adc, &drv_data->ch_cfg); return 0; } #define GLS_DEFINE(inst) \ static struct gls_data gls_data_##inst; \ \ static const struct gls_config gls_cfg_##inst = { \ .adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \ .adc_channel = DT_INST_IO_CHANNELS_INPUT(inst), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, &gls_init, NULL, \ &gls_data_##inst, &gls_cfg_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &gls_api); \ DT_INST_FOREACH_STATUS_OKAY(GLS_DEFINE) ```
/content/code_sandbox/drivers/sensor/seeed/grove/light_sensor.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
900
```unknown # SM351LT Magnetoresistive Sensor configuration options menuconfig SM351LT bool "SM351LT Magnetoresistive Sensor" default y depends on DT_HAS_HONEYWELL_SM351LT_ENABLED depends on (GPIO) help Enable GPIO-based driver for SM351LT magnetoresistive sensor. if SM351LT choice SM351LT_TRIGGER_MODE prompt "Trigger mode" help Specify the type of triggering to be used by the driver. config SM351LT_TRIGGER_NONE bool "No trigger" config SM351LT_TRIGGER_GLOBAL_THREAD bool "Use global thread" select SM351LT_TRIGGER config SM351LT_TRIGGER_OWN_THREAD bool "Use own thread" select SM351LT_TRIGGER endchoice config SM351LT_TRIGGER bool config SM351LT_THREAD_PRIORITY int "Thread priority" depends on SM351LT_TRIGGER_OWN_THREAD default 10 help Priority of thread used by the driver to handle interrupts. config SM351LT_THREAD_STACK_SIZE int "Thread stack size" depends on SM351LT_TRIGGER_OWN_THREAD default 512 help Stack size of thread used by the driver to handle interrupts. endif # SM351LT ```
/content/code_sandbox/drivers/sensor/honeywell/sm351lt/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
260
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_SM351LT_SM351LT_H_ #define ZEPHYR_DRIVERS_SENSOR_SM351LT_SM351LT_H_ #include <stdint.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #define SENSOR_ATTR_SM351LT_TRIGGER_TYPE SENSOR_ATTR_PRIV_START struct sm351lt_config { struct gpio_dt_spec int_gpio; }; struct sm351lt_data { bool sample_status; #ifdef CONFIG_SM351LT_TRIGGER const struct device *dev; struct gpio_callback gpio_cb; uint32_t trigger_type; sensor_trigger_handler_t changed_handler; const struct sensor_trigger *changed_trigger; #if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_SM351LT_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem gpio_sem; #elif defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD) struct k_work work; #endif #endif /* CONFIG_SM351LT_TRIGGER */ }; #endif /* ZEPHYR_DRIVERS_SENSOR_SM351LT_SM351LT_H_ */ ```
/content/code_sandbox/drivers/sensor/honeywell/sm351lt/sm351lt.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
227
```c /* * */ #define DT_DRV_COMPAT honeywell_sm351lt #include "sm351lt.h" #include <zephyr/init.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> #include <stdio.h> #include <zephyr/sys/util.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/sensor.h> #include <string.h> LOG_MODULE_REGISTER(SM351LT, CONFIG_SENSOR_LOG_LEVEL); #if CONFIG_SM351LT_TRIGGER static int sm351lt_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { const struct sm351lt_config *const config = dev->config; struct sm351lt_data *data = dev->data; int ret = -ENOTSUP; if (trig->chan == SENSOR_CHAN_PROX) { data->changed_handler = handler; data->changed_trigger = trig; ret = gpio_pin_interrupt_configure_dt(&config->int_gpio, (handler ? data->trigger_type : GPIO_INT_DISABLE)); if (ret < 0) { return ret; } if (handler) { ret = gpio_add_callback(config->int_gpio.port, &data->gpio_cb); } else { ret = gpio_remove_callback(config->int_gpio.port, &data->gpio_cb); } } return ret; } static void sm351lt_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { struct sm351lt_data *data = CONTAINER_OF(cb, struct sm351lt_data, gpio_cb); #if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD) k_sem_give(&data->gpio_sem); #elif defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD) k_work_submit(&data->work); #endif } static void sm351lt_thread_cb(const struct device *dev) { struct sm351lt_data *data = dev->data; if (likely(data->changed_handler != NULL)) { data->changed_handler(dev, data->changed_trigger); } return; } #if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD) static void sm351lt_thread(void *arg1, void *unused2, void *unused3) { struct sm351lt_data *data = arg1; ARG_UNUSED(unused2); ARG_UNUSED(unused3); while (1) { k_sem_take(&data->gpio_sem, K_FOREVER); sm351lt_thread_cb(data->dev); } } #endif #if defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD) static void sm351lt_work_cb(struct k_work *work) { struct sm351lt_data *data = CONTAINER_OF(work, struct sm351lt_data, work); sm351lt_thread_cb(data->dev); } #endif #endif static int sm351lt_sample_fetch(const struct device *dev, enum sensor_channel chan) { const struct sm351lt_config *config = dev->config; struct sm351lt_data *data = dev->data; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_PROX) { return -ENOTSUP; } data->sample_status = gpio_pin_get_dt(&config->int_gpio); return 0; } static int sm351lt_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct sm351lt_data *data = dev->data; if (chan == SENSOR_CHAN_PROX) { val->val1 = data->sample_status; val->val2 = 0; } else { return -ENOTSUP; } return 0; } #if CONFIG_SM351LT_TRIGGER static int sm351lt_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { struct sm351lt_data *data = dev->data; if (chan == SENSOR_CHAN_PROX) { if (attr == SENSOR_ATTR_SM351LT_TRIGGER_TYPE) { /* Interrupt triggering type */ data->trigger_type = val->val1; } else { return -ENOTSUP; } } else { return -ENOTSUP; } return 0; } static int sm351lt_attr_get(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) { struct sm351lt_data *data = dev->data; if (chan == SENSOR_CHAN_PROX) { if (attr == SENSOR_ATTR_SM351LT_TRIGGER_TYPE) { /* Interrupt triggering type */ val->val1 = data->trigger_type; val->val2 = 0; } else { return -ENOTSUP; } } else { return -ENOTSUP; } return 0; } #endif static const struct sensor_driver_api sm351lt_api_funcs = { .sample_fetch = sm351lt_sample_fetch, .channel_get = sm351lt_channel_get, #if CONFIG_SM351LT_TRIGGER .attr_set = sm351lt_attr_set, .attr_get = sm351lt_attr_get, .trigger_set = sm351lt_trigger_set, #endif }; static int sm351lt_init(const struct device *dev) { const struct sm351lt_config *const config = dev->config; uint32_t ret; if (!gpio_is_ready_dt(&config->int_gpio)) { LOG_ERR("GPIO device not ready"); return -ENODEV; } ret = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); if (ret) { LOG_ERR("failed to configure gpio: %d", ret); return ret; } #if defined(CONFIG_SM351LT_TRIGGER) struct sm351lt_data *data = dev->data; data->dev = dev; #if defined(CONFIG_SM351LT_TRIGGER_OWN_THREAD) k_sem_init(&data->gpio_sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&data->thread, data->thread_stack, CONFIG_SM351LT_THREAD_STACK_SIZE, sm351lt_thread, data, NULL, NULL, K_PRIO_COOP(CONFIG_SM351LT_THREAD_PRIORITY), 0, K_NO_WAIT); #if defined(CONFIG_THREAD_NAME) && defined(CONFIG_THREAD_MAX_NAME_LEN) /* Sets up thread name as the device name */ k_thread_name_set(&data->thread, dev->name); #endif #elif defined(CONFIG_SM351LT_TRIGGER_GLOBAL_THREAD) data->work.handler = sm351lt_work_cb; #endif data->trigger_type = GPIO_INT_DISABLE; ret = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_DISABLE); if (ret) { LOG_ERR("failed to configure gpio interrupt: %d", ret); return ret; } /* Setup callback struct but do not add it yet */ gpio_init_callback(&data->gpio_cb, sm351lt_gpio_callback, BIT(config->int_gpio.pin)); #endif return 0; } /* Instantiation macros for each individual device. */ #define SM351LT_DEFINE(inst) \ static struct sm351lt_data sm351lt_data_##inst; \ static const struct sm351lt_config sm351lt_config_##inst = { \ .int_gpio = GPIO_DT_SPEC_INST_GET(inst, gpios), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, \ sm351lt_init, \ NULL, \ &sm351lt_data_##inst, \ &sm351lt_config_##inst, \ POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, \ &sm351lt_api_funcs); /* Main instantiation macro for every configured device in DTS. */ DT_INST_FOREACH_STATUS_OKAY(SM351LT_DEFINE) ```
/content/code_sandbox/drivers/sensor/honeywell/sm351lt/sm351lt.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,652
```c /* mpr.c - Driver for Honeywell MPR pressure sensor series */ /* * */ #define DT_DRV_COMPAT honeywell_mpr #include <errno.h> #include <zephyr/kernel.h> #include <zephyr/sys/__assert.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/i2c.h> #include <zephyr/sys/byteorder.h> #include <zephyr/init.h> #include <zephyr/logging/log.h> #include "mpr.h" #include "mpr_configuration.h" LOG_MODULE_REGISTER(MPR, CONFIG_SENSOR_LOG_LEVEL); static int mpr_init(const struct device *dev) { const struct mpr_config *cfg = dev->config; if (!device_is_ready(cfg->i2c.bus)) { LOG_ERR("Bus device is not ready"); return -ENODEV; } return 0; } static int mpr_read_reg(const struct device *dev) { struct mpr_data *data = dev->data; const struct mpr_config *cfg = dev->config; uint8_t write_buf[] = { MPR_OUTPUT_MEASUREMENT_COMMAND, 0x00, 0x00 }; uint8_t read_buf[4] = { 0x0 }; int rc = i2c_write_dt(&cfg->i2c, write_buf, sizeof(write_buf)); if (rc < 0) { return rc; } uint8_t retries = MPR_REG_READ_MAX_RETRIES; for (; retries > 0; retries--) { k_sleep(K_MSEC(MPR_REG_READ_DATA_CONV_DELAY_MS)); rc = i2c_read_dt(&cfg->i2c, read_buf, sizeof(read_buf)); if (rc < 0) { return rc; } if (!(*read_buf & MPR_STATUS_MASK_POWER_ON) || (*read_buf & MPR_STATUS_MASK_INTEGRITY_TEST_FAILED) || (*read_buf & MPR_STATUS_MASK_MATH_SATURATION)) { return -EIO; } if (!(*read_buf & MPR_STATUS_MASK_BUSY)) { break; } } if (retries == 0) { return -EIO; } data->reg_val = (read_buf[1] << 16) | (read_buf[2] << 8) | read_buf[3]; return 0; } /* (reg_value - out_min) * (p_max - p_min) * pressure = --------------------------------------- + p_min * out_max - out_min * * returns pressure [kPa] * 10^6 */ static inline void mpr_convert_reg(const uint32_t *reg, uint64_t *value) { if (*reg > MPR_OUTPUT_MIN) { *value = (uint64_t)(*reg - MPR_OUTPUT_MIN) * (MPR_P_MAX - MPR_P_MIN); *value *= MPR_CONVERSION_FACTOR; *value /= MPR_OUTPUT_RANGE; *value += MPR_P_MIN; } else { *value = MPR_P_MIN; } } static int mpr_sample_fetch(const struct device *dev, enum sensor_channel chan) { __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_PRESS); return mpr_read_reg(dev); } static int mpr_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { const struct mpr_data *data = dev->data; __ASSERT_NO_MSG(chan == SENSOR_CHAN_PRESS); if (chan != SENSOR_CHAN_PRESS) { return -ENOTSUP; } uint64_t value; mpr_convert_reg(&data->reg_val, &value); val->val1 = value / 1000000; val->val2 = value % 1000000; return 0; } static const struct sensor_driver_api mpr_api_funcs = { .sample_fetch = mpr_sample_fetch, .channel_get = mpr_channel_get, }; #define MPR_DEFINE(inst) \ static struct mpr_data mpr_data_##inst; \ \ static const struct mpr_config mpr_config_##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, mpr_init, NULL, \ &mpr_data_##inst, &mpr_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &mpr_api_funcs); \ DT_INST_FOREACH_STATUS_OKAY(MPR_DEFINE) ```
/content/code_sandbox/drivers/sensor/honeywell/mpr/mpr.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
983
```unknown # MPR pressure sensor configuration options menuconfig MPR bool "MPR pressure sensor" default y depends on DT_HAS_HONEYWELL_MPR_ENABLED select I2C help Enable driver for MPR pressure sensor. if MPR choice prompt "MPR Pressure Range" default MPR_PRESSURE_RANGE_0025 config MPR_PRESSURE_RANGE_0001 bool "0 to 1" config MPR_PRESSURE_RANGE_01_6 bool "0 to 1.6" config MPR_PRESSURE_RANGE_02_5 bool "0 to 2.5" config MPR_PRESSURE_RANGE_0015 bool "0 to 15" config MPR_PRESSURE_RANGE_0025 bool "0 to 25" config MPR_PRESSURE_RANGE_0030 bool "0 to 30" config MPR_PRESSURE_RANGE_0060 bool "0 to 60" config MPR_PRESSURE_RANGE_0100 bool "0 to 100" config MPR_PRESSURE_RANGE_0160 bool "0 to 160" config MPR_PRESSURE_RANGE_0250 bool "0 to 250" config MPR_PRESSURE_RANGE_0400 bool "0 to 400" config MPR_PRESSURE_RANGE_0600 bool "0 to 600" endchoice choice prompt "MPR Pressure Unit" default MPR_PRESSURE_UNIT_P config MPR_PRESSURE_UNIT_P bool "psi" config MPR_PRESSURE_UNIT_K bool "kPa" config MPR_PRESSURE_UNIT_B bool "bar" config MPR_PRESSURE_UNIT_M bool "mbar" endchoice choice prompt "MPR Transfer Function" default MPR_TRANSFER_FUNCTION_A config MPR_TRANSFER_FUNCTION_A bool "A" config MPR_TRANSFER_FUNCTION_B bool "B" config MPR_TRANSFER_FUNCTION_C bool "C" endchoice endif # MPR ```
/content/code_sandbox/drivers/sensor/honeywell/mpr/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
419
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_ #define ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_ /* * Pressure Range * * MIN is always 0 */ #define MPR_P_MIN (0) #if defined(CONFIG_MPR_PRESSURE_RANGE_0001) #define MPR_P_MAX (1) #elif defined(CONFIG_MPR_PRESSURE_RANGE_01_6) #define MPR_P_MAX (1.6) #elif defined(CONFIG_MPR_PRESSURE_RANGE_02_5) #define MPR_P_MAX (2.5) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0015) #define MPR_P_MAX (15) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0025) #define MPR_P_MAX (25) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0030) #define MPR_P_MAX (30) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0060) #define MPR_P_MAX (60) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0100) #define MPR_P_MAX (100) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0160) #define MPR_P_MAX (160) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0250) #define MPR_P_MAX (250) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0400) #define MPR_P_MAX (400) #elif defined(CONFIG_MPR_PRESSURE_RANGE_0600) #define MPR_P_MAX (600) #else #error "MPR: Unknown pressure range." #endif /* * Pressure Unit */ #if defined(CONFIG_MPR_PRESSURE_UNIT_P) /* psi to kPa conversion factor: 6.894757 * 10^6 */ #define MPR_CONVERSION_FACTOR (6894757) #elif defined(CONFIG_MPR_PRESSURE_UNIT_K) /* kPa to kPa conversion factor: 1 * 10^6 */ #define MPR_CONVERSION_FACTOR (1000000) #elif defined(CONFIG_MPR_PRESSURE_UNIT_B) /* bar to kPa conversion factor: 100 * 10^6 */ #define MPR_CONVERSION_FACTOR (100000000) #elif defined(CONFIG_MPR_PRESSURE_UNIT_M) /* mbar to kPa conversion factor: 0.1 * 10^6 */ #define MPR_CONVERSION_FACTOR (100000) #else #error "MPR: Unknown pressure unit." #endif /* * Transfer function */ #if defined(CONFIG_MPR_TRANSFER_FUNCTION_A) #define MPR_OUTPUT_MIN (0x19999A) /* 10% of 2^24 */ #define MPR_OUTPUT_MAX (0xE66666) /* 90% of 2^24 */ #elif defined(CONFIG_MPR_TRANSFER_FUNCTION_B) #define MPR_OUTPUT_MIN (0x66666) /* 2.5% of 2^24 */ #define MPR_OUTPUT_MAX (0x399999) /* 22.5% of 2^24 */ #elif defined(CONFIG_MPR_TRANSFER_FUNCTION_C) #define MPR_OUTPUT_MIN (0x333333) /* 20% of 2^24 */ #define MPR_OUTPUT_MAX (0xCCCCCC) /* 80% of 2^24 */ #else #error "MPR: Unknown pressure reference." #endif #define MPR_OUTPUT_RANGE (MPR_OUTPUT_MAX - MPR_OUTPUT_MIN) #endif /* ZEPHYR_DRIVERS_SENSOR_MPR_CONFIGURATION_H_ */ ```
/content/code_sandbox/drivers/sensor/honeywell/mpr/mpr_configuration.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
691
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_MPR_H_ #define ZEPHYR_DRIVERS_SENSOR_MPR_H_ #include <zephyr/drivers/i2c.h> /* MPR output measurement command */ #define MPR_OUTPUT_MEASUREMENT_COMMAND (0xAA) /* MPR status byte masks */ #define MPR_STATUS_MASK_MATH_SATURATION (0x01) #define MPR_STATUS_MASK_INTEGRITY_TEST_FAILED (0x04) #define MPR_STATUS_MASK_BUSY (0x20) #define MPR_STATUS_MASK_POWER_ON (0x40) /* MPR register read maximum retries */ #ifndef MPR_REG_READ_MAX_RETRIES #define MPR_REG_READ_MAX_RETRIES (3) #endif /* MPR register read data conversion delay [ms] */ #ifndef MPR_REG_READ_DATA_CONV_DELAY_MS #define MPR_REG_READ_DATA_CONV_DELAY_MS (5) #endif struct mpr_data { uint32_t reg_val; }; struct mpr_config { struct i2c_dt_spec i2c; }; int mpr_reg_read(const struct device *dev, uint8_t reg, uint16_t *val); #endif /* ZEPHYR_DRIVERS_SENSOR_MPR_H_ */ ```
/content/code_sandbox/drivers/sensor/honeywell/mpr/mpr.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
250
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_HMC5883L_HMC5883L_H_ #define ZEPHYR_DRIVERS_SENSOR_HMC5883L_HMC5883L_H_ #include <zephyr/device.h> #include <zephyr/sys/util.h> #include <zephyr/types.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #include <zephyr/kernel.h> #define HMC5883L_REG_CONFIG_A 0x00 #define HMC5883L_ODR_SHIFT 2 #define HMC5883L_REG_CONFIG_B 0x01 #define HMC5883L_GAIN_SHIFT 5 #define HMC5883L_REG_MODE 0x02 #define HMC5883L_MODE_CONTINUOUS 0 #define HMC5883L_REG_DATA_START 0x03 #define HMC5883L_REG_CHIP_ID 0x0A #define HMC5883L_CHIP_ID_A 'H' #define HMC5883L_CHIP_ID_B '4' #define HMC5883L_CHIP_ID_C '3' static const char *const hmc5883l_odr_strings[] = { "0.75", "1.5", "3", "7.5", "15", "30", "75" }; static const char *const hmc5883l_fs_strings[] = { "0.88", "1.3", "1.9", "2.5", "4", "4.7", "5.6", "8.1" }; static const uint16_t hmc5883l_gain[] = { 1370, 1090, 820, 660, 440, 390, 330, 230 }; struct hmc5883l_data { int16_t x_sample; int16_t y_sample; int16_t z_sample; uint8_t gain_idx; #ifdef CONFIG_HMC5883L_TRIGGER const struct device *dev; struct gpio_callback gpio_cb; const struct sensor_trigger *data_ready_trigger; sensor_trigger_handler_t data_ready_handler; #if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD) K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_HMC5883L_THREAD_STACK_SIZE); struct k_thread thread; struct k_sem gpio_sem; #elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD) struct k_work work; #endif #endif /* CONFIG_HMC5883L_TRIGGER */ }; struct hmc5883l_config { struct i2c_dt_spec i2c; #ifdef CONFIG_HMC5883L_TRIGGER struct gpio_dt_spec int_gpio; #endif }; #ifdef CONFIG_HMC5883L_TRIGGER int hmc5883l_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); int hmc5883l_init_interrupt(const struct device *dev); #endif #endif /* __SENSOR_HMC5883L__ */ ```
/content/code_sandbox/drivers/sensor/honeywell/hmc5883l/hmc5883l.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
636
```c /* * */ #define DT_DRV_COMPAT honeywell_hmc5883l #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/util.h> #include <zephyr/kernel.h> #include <zephyr/drivers/sensor.h> #include <zephyr/logging/log.h> #include "hmc5883l.h" LOG_MODULE_DECLARE(HMC5883L, CONFIG_SENSOR_LOG_LEVEL); int hmc5883l_trigger_set(const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { struct hmc5883l_data *drv_data = dev->data; const struct hmc5883l_config *config = dev->config; if (!config->int_gpio.port) { return -ENOTSUP; } __ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY); gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_DISABLE); drv_data->data_ready_handler = handler; if (handler == NULL) { return 0; } drv_data->data_ready_trigger = trig; gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); return 0; } static void hmc5883l_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { struct hmc5883l_data *drv_data = CONTAINER_OF(cb, struct hmc5883l_data, gpio_cb); const struct hmc5883l_config *config = drv_data->dev->config; ARG_UNUSED(pins); gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_DISABLE); #if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD) k_sem_give(&drv_data->gpio_sem); #elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD) k_work_submit(&drv_data->work); #endif } static void hmc5883l_thread_cb(const struct device *dev) { struct hmc5883l_data *drv_data = dev->data; const struct hmc5883l_config *config = dev->config; if (drv_data->data_ready_handler != NULL) { drv_data->data_ready_handler(dev, drv_data->data_ready_trigger); } gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); } #ifdef CONFIG_HMC5883L_TRIGGER_OWN_THREAD static void hmc5883l_thread(void *p1, void *p2, void *p3) { ARG_UNUSED(p2); ARG_UNUSED(p3); struct hmc5883l_data *drv_data = p1; while (1) { k_sem_take(&drv_data->gpio_sem, K_FOREVER); hmc5883l_thread_cb(drv_data->dev); } } #endif #ifdef CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD static void hmc5883l_work_cb(struct k_work *work) { struct hmc5883l_data *drv_data = CONTAINER_OF(work, struct hmc5883l_data, work); hmc5883l_thread_cb(drv_data->dev); } #endif int hmc5883l_init_interrupt(const struct device *dev) { struct hmc5883l_data *drv_data = dev->data; const struct hmc5883l_config *config = dev->config; if (!gpio_is_ready_dt(&config->int_gpio)) { LOG_ERR("GPIO device not ready"); return -ENODEV; } gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); gpio_init_callback(&drv_data->gpio_cb, hmc5883l_gpio_callback, BIT(config->int_gpio.pin)); if (gpio_add_callback(config->int_gpio.port, &drv_data->gpio_cb) < 0) { LOG_ERR("Failed to set gpio callback."); return -EIO; } drv_data->dev = dev; #if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD) k_sem_init(&drv_data->gpio_sem, 0, K_SEM_MAX_LIMIT); k_thread_create(&drv_data->thread, drv_data->thread_stack, CONFIG_HMC5883L_THREAD_STACK_SIZE, hmc5883l_thread, drv_data, NULL, NULL, K_PRIO_COOP(CONFIG_HMC5883L_THREAD_PRIORITY), 0, K_NO_WAIT); #elif defined(CONFIG_HMC5883L_TRIGGER_GLOBAL_THREAD) drv_data->work.handler = hmc5883l_work_cb; #endif gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); return 0; } ```
/content/code_sandbox/drivers/sensor/honeywell/hmc5883l/hmc5883l_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
998
```unknown menuconfig HMC5883L bool "HMC5883L magnetometer" default y depends on DT_HAS_HONEYWELL_HMC5883L_ENABLED select I2C help Enable driver for HMC5883L I2C-based magnetometer. if HMC5883L choice prompt "Trigger mode" default HMC5883L_TRIGGER_GLOBAL_THREAD help Specify the type of triggering to be used by the driver. config HMC5883L_TRIGGER_NONE bool "No trigger" config HMC5883L_TRIGGER_GLOBAL_THREAD bool "Use global thread" depends on GPIO select HMC5883L_TRIGGER config HMC5883L_TRIGGER_OWN_THREAD bool "Use own thread" depends on GPIO select HMC5883L_TRIGGER endchoice config HMC5883L_TRIGGER bool config HMC5883L_THREAD_PRIORITY int "Thread priority" depends on HMC5883L_TRIGGER_OWN_THREAD default 10 help Priority of thread used by the driver to handle interrupts. config HMC5883L_THREAD_STACK_SIZE int "Thread stack size" depends on HMC5883L_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. config HMC5883L_ODR string "Output data rate" default "15" help Magnetometer output data rate expressed in samples per second. Data rates supported by the chip are 0.75, 1.5, 3, 7.5, 15, 30 and 75. config HMC5883L_FS string "Full-scale range" default "1.3" help Magnetometer full-scale range. An X value for the config represents a range of +/- X gauss. Valid values are 0.88, 1.3, 1.9, 2.5, 4, 4.7, 5.6 and 8.1. endif # HMC5883L ```
/content/code_sandbox/drivers/sensor/honeywell/hmc5883l/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
447
```unknown # zephyr-keep-sorted-start source "drivers/sensor/ams/ams_as5600/Kconfig" source "drivers/sensor/ams/ams_iAQcore/Kconfig" source "drivers/sensor/ams/ccs811/Kconfig" source "drivers/sensor/ams/ens210/Kconfig" source "drivers/sensor/ams/tcs3400/Kconfig" source "drivers/sensor/ams/tmd2620/Kconfig" source "drivers/sensor/ams/tsl2540/Kconfig" source "drivers/sensor/ams/tsl2561/Kconfig" source "drivers/sensor/ams/tsl2591/Kconfig" # zephyr-keep-sorted-stop ```
/content/code_sandbox/drivers/sensor/ams/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
148
```c /* * */ #define DT_DRV_COMPAT honeywell_hmc5883l #include <zephyr/drivers/i2c.h> #include <zephyr/init.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/byteorder.h> #include <zephyr/drivers/sensor.h> #include <string.h> #include <zephyr/logging/log.h> #include "hmc5883l.h" LOG_MODULE_REGISTER(HMC5883L, CONFIG_SENSOR_LOG_LEVEL); static void hmc5883l_convert(struct sensor_value *val, int16_t raw_val, uint16_t divider) { /* val = raw_val / divider */ val->val1 = raw_val / divider; val->val2 = (((int64_t)raw_val % divider) * 1000000L) / divider; } static int hmc5883l_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct hmc5883l_data *drv_data = dev->data; if (chan == SENSOR_CHAN_MAGN_X) { hmc5883l_convert(val, drv_data->x_sample, hmc5883l_gain[drv_data->gain_idx]); } else if (chan == SENSOR_CHAN_MAGN_Y) { hmc5883l_convert(val, drv_data->y_sample, hmc5883l_gain[drv_data->gain_idx]); } else if (chan == SENSOR_CHAN_MAGN_Z) { hmc5883l_convert(val, drv_data->z_sample, hmc5883l_gain[drv_data->gain_idx]); } else if (chan == SENSOR_CHAN_MAGN_XYZ) { hmc5883l_convert(val, drv_data->x_sample, hmc5883l_gain[drv_data->gain_idx]); hmc5883l_convert(val + 1, drv_data->y_sample, hmc5883l_gain[drv_data->gain_idx]); hmc5883l_convert(val + 2, drv_data->z_sample, hmc5883l_gain[drv_data->gain_idx]); } else { return -ENOTSUP; } return 0; } static int hmc5883l_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct hmc5883l_data *drv_data = dev->data; const struct hmc5883l_config *config = dev->config; int16_t buf[3]; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL); /* fetch magnetometer sample */ if (i2c_burst_read_dt(&config->i2c, HMC5883L_REG_DATA_START, (uint8_t *)buf, 6) < 0) { LOG_ERR("Failed to fetch magnetometer sample."); return -EIO; } drv_data->x_sample = sys_be16_to_cpu(buf[0]); drv_data->z_sample = sys_be16_to_cpu(buf[1]); drv_data->y_sample = sys_be16_to_cpu(buf[2]); return 0; } static const struct sensor_driver_api hmc5883l_driver_api = { #if CONFIG_HMC5883L_TRIGGER .trigger_set = hmc5883l_trigger_set, #endif .sample_fetch = hmc5883l_sample_fetch, .channel_get = hmc5883l_channel_get, }; int hmc5883l_init(const struct device *dev) { struct hmc5883l_data *drv_data = dev->data; const struct hmc5883l_config *config = dev->config; uint8_t chip_cfg[3], id[3], idx; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("I2C bus device not ready"); return -ENODEV; } /* check chip ID */ if (i2c_burst_read_dt(&config->i2c, HMC5883L_REG_CHIP_ID, id, 3) < 0) { LOG_ERR("Failed to read chip ID."); return -EIO; } if (id[0] != HMC5883L_CHIP_ID_A || id[1] != HMC5883L_CHIP_ID_B || id[2] != HMC5883L_CHIP_ID_C) { LOG_ERR("Invalid chip ID."); return -EINVAL; } /* check if CONFIG_HMC5883L_FS is valid */ for (idx = 0U; idx < ARRAY_SIZE(hmc5883l_fs_strings); idx++) { if (!strcmp(hmc5883l_fs_strings[idx], CONFIG_HMC5883L_FS)) { break; } } if (idx == ARRAY_SIZE(hmc5883l_fs_strings)) { LOG_ERR("Invalid full-scale range value."); return -EINVAL; } drv_data->gain_idx = idx; /* check if CONFIG_HMC5883L_ODR is valid */ for (idx = 0U; idx < ARRAY_SIZE(hmc5883l_odr_strings); idx++) { if (!strcmp(hmc5883l_odr_strings[idx], CONFIG_HMC5883L_ODR)) { break; } } if (idx == ARRAY_SIZE(hmc5883l_odr_strings)) { LOG_ERR("Invalid ODR value."); return -EINVAL; } /* configure device */ chip_cfg[0] = idx << HMC5883L_ODR_SHIFT; chip_cfg[1] = drv_data->gain_idx << HMC5883L_GAIN_SHIFT; chip_cfg[2] = HMC5883L_MODE_CONTINUOUS; if (i2c_burst_write_dt(&config->i2c, HMC5883L_REG_CONFIG_A, chip_cfg, 3) < 0) { LOG_ERR("Failed to configure chip."); return -EIO; } #ifdef CONFIG_HMC5883L_TRIGGER if (config->int_gpio.port) { if (hmc5883l_init_interrupt(dev) < 0) { LOG_ERR("Failed to initialize interrupts."); return -EIO; } } #endif return 0; } #define HMC5883L_DEFINE(inst) \ static struct hmc5883l_data hmc5883l_data_##inst; \ \ static const struct hmc5883l_config hmc5883l_config_##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ IF_ENABLED(CONFIG_HMC5883L_TRIGGER, \ (.int_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, int_gpios, { 0 }),)) \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, hmc5883l_init, NULL, \ &hmc5883l_data_##inst, &hmc5883l_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &hmc5883l_driver_api); \ DT_INST_FOREACH_STATUS_OKAY(HMC5883L_DEFINE) ```
/content/code_sandbox/drivers/sensor/honeywell/hmc5883l/hmc5883l.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,523
```c /* * */ #include <zephyr/device.h> #include <zephyr/drivers/gpio.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/sensor.h> #include <zephyr/kernel.h> #include <zephyr/logging/log.h> #include <zephyr/sys/util.h> #include "tmd2620.h" LOG_MODULE_DECLARE(TMD2620, CONFIG_SENSOR_LOG_LEVEL); extern struct tmd2620_data tmd2620_driver; void tmd2620_work_cb(struct k_work *work) { LOG_DBG("Work callback was called back."); struct tmd2620_data *data = CONTAINER_OF(work, struct tmd2620_data, work); const struct device *dev = data->dev; if (data->p_th_handler != NULL) { data->p_th_handler(dev, data->p_th_trigger); } tmd2620_setup_int(dev->config, true); } int tmd2620_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) { LOG_DBG("Setting sensor attributes."); const struct tmd2620_config *config = dev->config; int ret; if (chan != SENSOR_CHAN_PROX) { return -ENOTSUP; } if (attr == SENSOR_ATTR_UPPER_THRESH) { ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PIHT_REG, (255 - (uint8_t)val->val1)); if (ret < 0) { return ret; } } if (attr == SENSOR_ATTR_LOWER_THRESH) { return i2c_reg_write_byte_dt(&config->i2c, TMD2620_PILT_REG, (uint8_t)val->val1); } return 0; } int tmd2620_trigger_set(const struct device *dev, const struct sensor_trigger *trigg, sensor_trigger_handler_t handler) { LOG_DBG("Setting trigger handler."); const struct tmd2620_config *config = dev->config; struct tmd2620_data *data = dev->data; int ret; tmd2620_setup_int(dev->config, false); if (trigg->type != SENSOR_TRIG_THRESHOLD) { return -ENOTSUP; } if (trigg->chan != SENSOR_CHAN_PROX) { return -ENOTSUP; } data->p_th_trigger = trigg; data->p_th_handler = handler; ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_INTENAB_REG, TMD2620_INTENAB_PIEN, TMD2620_INTENAB_PIEN); if (ret < 0) { return ret; } tmd2620_setup_int(config, true); if (gpio_pin_get_dt(&config->int_gpio) > 0) { k_work_submit(&data->work); } return 0; } ```
/content/code_sandbox/drivers/sensor/ams/tmd2620/tmd2620_trigger.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
635
```objective-c /* * */ #include <zephyr/drivers/gpio.h> #ifndef ZEPHYR_DRIVERS_SENSOR_TMD2620_TMD2620_H_ #define ZEPHYR_DRIVERS_SENSOR_TMD2620_TMD2620_H_ #define TMD2620_CHIP_ID (0b110101 << 2) #define TMD2620_ENABLE_REG 0x80 #define TMD2620_ENABLE_WEN BIT(3) #define TMD2620_ENABLE_PEN BIT(2) #define TMD2620_ENABLE_PON BIT(0) /* PRATE register defines the time between proximity measurements * while averaging is turned on. * Formular: time between measurements = REG_VALUE * 88s */ #define TMD2620_PRATE_REG 0x82 /* * WTIME Register defines the wait time between measurements. * Formular: Wait time = (REG_VALUE + 1) * 2.81ms * If the WLONG bit is set: * Formular: Wait time = (REG_VALUE + 1) * 33.8ms */ #define TMD2620_WTIME_REG 0x83 /* * PILT Register defines the low interrupt threshold. * If the value generated by the proximity channel is below the * threshold, PPERS value is reached and PIEN is enabled, the INT pin will be asserted */ #define TMD2620_PILT_REG 0x88 /* * PILT Register defines the high interrupt threshold. * If the value generated by the proximity channel is above the * threshold, PPERS value is reached and PIEN is enabled, the INT pin will be asserted */ #define TMD2620_PIHT_REG 0x8A /* * PERS register controls the interrupt filtering capabilities. * With the PPERS bits its possible to configure how many values out of * the threshold have to be generated until a interrupt is generated. * 0: every read cycle * 1: any proximiy value outside of range * 2: 2 consecutive values outside of range * ... */ #define TMD2620_PERS_REG 0x8C #define TMD2620_PERS_PPERS (BIT(4) | BIT(5) | BIT(6) | BIT(7)) #define TMD2620_CFG0_REG 0x8D #define TMD2620_CFG0_WLONG BIT(2) #define TMD2620_PCFG0_REG 0x8E /* pulse length */ #define TMD2620_PCFG0_PPULSE_LEN_4US 0 #define TMD2620_PCFG0_PPULSE_LEN_8US BIT(6) #define TMD2620_PCFG0_PPULSE_LEN_16US BIT(7) #define TMD2620_PCFG0_PPULSE_LEN_32US (BIT(6) | BIT(7)) #define TMD2620_PCFG0_PPULSE_LEN_MASK TMD2620_PCFG0_PPULSE_LEN_32US /* maximum number of pulses */ #define TMD2620_PCFG0_PPULSE (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5)) #define TMD2620_PCFG1_REG 0x8F /* proximity gain control */ #define TMD2620_PCFG1_PGAIN_X1 0 #define TMD2620_PCFG1_PGAIN_X2 BIT(6) #define TMD2620_PCFG1_PGAIN_X4 BIT(7) #define TMD2620_PCFG1_PGAIN_X8 (BIT(6) | BIT(7)) #define TMD2620_PCFG1_PLDRIVE (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4)) #define TMD2620_REVID_REG 0x91 #define TMD2620_ID_REG 0x92 #define TMD2620_STATUS_REG 0x93 #define TMD2620_STATUS_PSAT BIT(6) #define TMD2620_STATUS_PINT BIT(5) #define TMD2620_STATUS_CINT BIT(3) #define TMD2620_STATUS_ZINT BIT(2) #define TMD2620_STATUS_PSAT_REFLECTIVE BIT(1) #define TMD2620_STATUS_PSAT_AMBIENT BIT(0) /* PDATA contains the 1-byte proximity data */ #define TMD2620_PDATA_REG 0x9C #define TMD2620_REVID2_REG 0x9E #define TMD2620_REVID2_AUX_ID (BIT(0) | BIT(1) | BIT(2) | BIT(3)) #define TMD2620_CFG3_REG 0xAB #define TMD2620_CFG3_INT_READ_CLEAR BIT(7) #define TMD2620_CFG3_SAI BIT(4) #define TMD2620_POFFSET_L_REG 0xC0 #define TMD2620_POFFSET_H_REG 0xC1 #define TMD2620_CALIB_REG 0xD7 #define TMD2620_CALIB_ELECTRICAL BIT(5) #define TMD2620_CALIB_START_OFFSET_CALIB BIT(0) #define TMD2620_CALIBCFG_REG 0xD9 #define TMD2620_CALIBCFG_BINSRCH_TARGET (BIT(5) | BIT(6) | BIT(7)) #define TMD2620_CALIBCFG_PROX_AUTO_OFFSET_ADJUST BIT(3) #define TMD2620_CALIBCFG_PRX_DATA_AVG (BIT(0) | BIT(1) | BIT(2)) #define TMD2620_CALIBSTAT_REG 0xDC #define TMD2620_CALIBSTAT_OFFSET_ADJUSTED BIT(2) #define TMD2620_CALIBSTAT_CALIB_FINISHED BIT(0) #define TMD2620_INTENAB_REG 0xDD #define TMD2620_INTENAB_PSIEN BIT(6) #define TMD2620_INTENAB_PIEN BIT(5) #define TMD2620_INTENAB_CIEN BIT(3) #define TMD2620_INTENAB_ZIEN BIT(2) #define TMD2620_PGAIN_DEFAULT TMD2620_PCFG1_PGAIN_X4 #define TMD2620_PLDRIVE_DEFAULT 7 #define TMD2620_PPULSE_DEFAULT 15 #define TMD2620_PPULSE_LEN_DEFAULT TMD2620_PCFG0_PPULSE_LEN_16US struct tmd2620_config { struct i2c_dt_spec i2c; struct gpio_dt_spec int_gpio; uint8_t inst; uint8_t proximity_gain; uint8_t proximity_pulse_length; uint8_t proximity_pulse_count; uint8_t proximity_high_threshold; uint8_t proximity_low_threshold; uint8_t proximity_led_drive_strength; uint8_t proximity_interrupt_filter; uint8_t enable_wait_mode; uint8_t wait_time_factor; uint8_t wait_long; }; struct tmd2620_data { struct gpio_callback gpio_cb; const struct device *dev; uint8_t pdata; #ifdef CONFIG_TMD2620_TRIGGER sensor_trigger_handler_t p_th_handler; const struct sensor_trigger *p_th_trigger; struct k_work work; #else struct k_sem data_sem; #endif }; static void tmd2620_setup_int(const struct tmd2620_config *config, bool enable) { unsigned int flags = enable ? GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_DISABLE; gpio_pin_interrupt_configure_dt(&config->int_gpio, flags); } #ifdef CONFIG_TMD2620_TRIGGER void tmd2620_work_cb(struct k_work *work); int tmd2620_attr_set(const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val); int tmd2620_trigger_set(const struct device *dev, const struct sensor_trigger *trigg, sensor_trigger_handler_t handler); #endif #endif /* ZEPHYR_DRIVERS_SENSOR_TMD2620_TMD2620_H_ */ ```
/content/code_sandbox/drivers/sensor/ams/tmd2620/tmd2620.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
1,713
```unknown menuconfig TMD2620 bool "OSRAM-AMS TMD2620 Proxmimity Sensor" default y depends on DT_HAS_AMS_TMD2620_ENABLED select I2C help Enable driver for TMD2620 Sensor if TMD2620 choice prompt "Trigger Mode" default TMD2620_TRIGGER_NONE help Specify the type of triggering to be used by the driver. config TMD2620_TRIGGER_NONE bool "No Trigger" config TMD2620_TRIGGER_GLOBAL_THREAD bool "Use global thread" depends on GPIO select TMD2620_TRIGGER endchoice # Trigger Mode config TMD2620_TRIGGER bool endif # TMD2620 ```
/content/code_sandbox/drivers/sensor/ams/tmd2620/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
156
```c /* * */ #define DT_DRV_COMPAT ams_tmd2620 #include <zephyr/device.h> #include <zephyr/drivers/sensor.h> #include <zephyr/drivers/i2c.h> #include <zephyr/pm/device.h> #include <zephyr/sys/__assert.h> #include <zephyr/sys/byteorder.h> #include <zephyr/init.h> #include <zephyr/kernel.h> #include <string.h> #include <zephyr/logging/log.h> #include <zephyr/drivers/gpio.h> #include <stdio.h> #include "tmd2620.h" LOG_MODULE_REGISTER(TMD2620, CONFIG_SENSOR_LOG_LEVEL); static void tmd2620_gpio_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { LOG_DBG("Interrupt Callback was called"); struct tmd2620_data *data = CONTAINER_OF(cb, struct tmd2620_data, gpio_cb); tmd2620_setup_int(data->dev->config, false); #ifdef CONFIG_TMD2620_TRIGGER k_work_submit(&data->work); #else k_sem_give(&data->data_sem); #endif } static int tmd2620_configure_interrupt(const struct device *dev) { struct tmd2620_data *data = dev->data; const struct tmd2620_config *config = dev->config; int ret; LOG_DBG("Configuring Interrupt."); if (!gpio_is_ready_dt(&config->int_gpio)) { LOG_ERR("Interrupt GPIO device not ready"); return -ENODEV; } ret = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); if (ret < 0) { LOG_ERR("Failed to configure interrupt pin"); return ret; } gpio_init_callback(&data->gpio_cb, tmd2620_gpio_callback, BIT(config->int_gpio.pin)); ret = gpio_add_callback(config->int_gpio.port, &data->gpio_cb); if (ret < 0) { LOG_ERR("Failed to set GPIO callback"); return ret; } data->dev = dev; #ifdef CONFIG_TMD2620_TRIGGER data->work.handler = tmd2620_work_cb; #else k_sem_init(&data->data_sem, 0, K_SEM_MAX_LIMIT); #endif return 0; } static int tmd2620_sample_fetch(const struct device *dev, enum sensor_channel chan) { LOG_DBG("Fetching Sample..."); struct tmd2620_data *data = dev->data; const struct tmd2620_config *config = dev->config; uint8_t tmp; int ret; if (chan != SENSOR_CHAN_ALL && chan != SENSOR_CHAN_PROX) { LOG_ERR("Unsupported sensor channel"); return -ENOTSUP; } #ifndef CONFIG_TMD2620_TRIGGER /* enabling interrupt */ ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_INTENAB_REG, TMD2620_INTENAB_PIEN, TMD2620_INTENAB_PIEN); if (ret < 0) { LOG_ERR("Failed enabling interrupt."); return ret; } tmd2620_setup_int(config, true); /* Enabling proximity and powering up device */ tmp = TMD2620_ENABLE_PEN | TMD2620_ENABLE_PON; ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, tmp); if (ret < 0) { LOG_ERR("Failed enabling device."); return ret; } LOG_DBG("waiting for semaphore.."); k_sem_take(&data->data_sem, K_FOREVER); #endif ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_STATUS_REG, &tmp); if (ret < 0) { LOG_ERR("Failed reading status register."); return ret; } LOG_DBG("Status register: 0x%x", tmp); if (tmp & TMD2620_STATUS_PINT) { LOG_DBG("Proximity interrupt detected."); ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_PDATA_REG, &data->pdata); if (ret < 0) { LOG_ERR("Failed reading proximity data."); return ret; } } #ifndef CONFIG_TMD2620_TRIGGER tmp = TMD2620_ENABLE_PEN | TMD2620_ENABLE_PON; /* Disabling proximity and powering down device */ ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, 0); if (ret < 0) { LOG_ERR("Failed powering down device."); return ret; } #endif /* clearing interrupt flag */ ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_STATUS_REG, TMD2620_STATUS_PINT, TMD2620_STATUS_PINT); if (ret < 0) { LOG_ERR("Failed clearing interrupt flag."); return ret; } return 0; } static int tmd2620_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct tmd2620_data *data = dev->data; if (chan == SENSOR_CHAN_PROX) { /* inverting sensor data to fit Zephyr */ val->val1 = (256 - data->pdata); val->val2 = 0; return 0; } return -ENOTSUP; } static int tmd2620_sensor_setup(const struct device *dev) { const struct tmd2620_config *config = dev->config; uint8_t chip_id; uint8_t tmp; int ret; /* trying to read the id twice, as the sensor does not answer the first request */ /* because of this no return code is checked in this line */ (void)i2c_reg_read_byte_dt(&config->i2c, TMD2620_ID_REG, &chip_id); ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_ID_REG, &chip_id); if (ret < 0) { LOG_ERR("Failed reading chip id"); return ret; } if (chip_id != TMD2620_CHIP_ID) { LOG_ERR("Chip id is invalid! Device @%02x is no TMD2620!", config->i2c.addr); return -EIO; } ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_ENABLE_REG, 0); if (ret < 0) { LOG_ERR("ENABLE Register was not cleared"); return ret; } tmp = config->wait_time_factor; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_WTIME_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting wait time"); return ret; } tmp = config->proximity_low_threshold; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PILT_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting PILT"); return ret; } tmp = config->proximity_high_threshold; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PIHT_REG, (255 - tmp)); if (ret < 0) { LOG_ERR("Failed setting PIHT"); return ret; } #ifdef CONFIG_TMD2620_TRIGGER tmp = (config->proximity_interrupt_filter << 3); ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PERS_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting PERS"); return ret; } #endif if (config->wait_long) { tmp = TMD2620_CFG0_WLONG; } else { tmp = 0; } ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_CFG0_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting CFG0"); return ret; } switch (config->proximity_pulse_length) { case 4: tmp = TMD2620_PCFG0_PPULSE_LEN_4US; break; case 8: tmp = TMD2620_PCFG0_PPULSE_LEN_8US; break; case 16: tmp = TMD2620_PCFG0_PPULSE_LEN_16US; break; case 32: tmp = TMD2620_PCFG0_PPULSE_LEN_32US; break; default: LOG_ERR("Invalid proximity pulse length"); return -EINVAL; } tmp |= config->proximity_pulse_count; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PCFG0_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting PPULSE"); return ret; } switch (config->proximity_gain) { case 1: tmp = TMD2620_PCFG1_PGAIN_X1; break; case 2: tmp = TMD2620_PCFG1_PGAIN_X2; break; case 4: tmp = TMD2620_PCFG1_PGAIN_X4; break; case 8: tmp = TMD2620_PCFG1_PGAIN_X8; break; default: LOG_ERR("Invalid proximity gain"); return -EINVAL; } tmp |= config->proximity_led_drive_strength; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PCFG1_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting PCGF1"); return ret; } tmp = TMD2620_CFG3_INT_READ_CLEAR; ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_CFG3_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting CFG3"); return ret; } tmp = 1; /* enable interrupt */ ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_INTENAB_REG, tmp); if (ret < 0) { LOG_ERR("Failed setting INTENAB"); return ret; } if (config->enable_wait_mode) { ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, TMD2620_ENABLE_WEN, TMD2620_ENABLE_WEN); if (ret < 0) { LOG_ERR("Failed enabling wait mode"); return ret; } } return 0; } static int tmd2620_init(const struct device *dev) { const struct tmd2620_config *config = dev->config; struct tmd2620_data *data = dev->data; int ret; #ifdef CONFIG_TMD2620_TRIGGER uint8_t tmp; #endif if (!i2c_is_ready_dt(&config->i2c)) { LOG_ERR("I2C bus not ready!"); return -ENODEV; } data->pdata = 0U; ret = tmd2620_sensor_setup(dev); if (ret < 0) { LOG_ERR("Failed to configure device"); return ret; } LOG_DBG("Device setup complete"); ret = tmd2620_configure_interrupt(dev); if (ret < 0) { LOG_ERR("Failed configuring interrupt!"); return ret; } #ifdef CONFIG_TMD2620_TRIGGER tmp = TMD2620_ENABLE_PEN | TMD2620_ENABLE_PON; ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, tmp); if (ret < 0) { LOG_ERR("Failed enabling device."); return ret; } #endif LOG_DBG("Driver init complete."); return 0; } #ifdef CONFIG_PM_DEVICE static int tmd2620_pm_action(const struct device *dev, enum pm_device_action action) { const struct tmd2620_config *config = dev->config; int ret; switch (action) { case PM_DEVICE_ACTION_RESUME: ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, TMD2620_ENABLE_PON, TMD2620_ENABLE_PON); if (ret < 0) { LOG_ERR("Failed enabling sensor."); return ret; } break; case PM_DEVICE_ACTION_SUSPEND: ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, TMD2620_ENABLE_PON, 0); if (ret < 0) { LOG_ERR("Failed suspending sensor."); return ret; } break; default: return -ENOTSUP; } return 0; } #endif static const struct sensor_driver_api tmd2620_driver_api = { .sample_fetch = tmd2620_sample_fetch, .channel_get = tmd2620_channel_get, #ifdef CONFIG_TMD2620_TRIGGER .attr_set = tmd2620_attr_set, .trigger_set = tmd2620_trigger_set, #endif }; #define TMD2620_INIT_INST(n) \ struct tmd2620_data tmd2620_data_##n; \ static const struct tmd2620_config tmd2620_config_##n = { \ .i2c = I2C_DT_SPEC_INST_GET(n), \ .int_gpio = GPIO_DT_SPEC_INST_GET(n, int_gpios), \ .proximity_gain = DT_INST_PROP(n, proximity_gain), \ .proximity_pulse_length = DT_INST_PROP(n, proximity_pulse_length), \ .proximity_pulse_count = DT_INST_PROP(n, proximity_pulse_count), \ .proximity_high_threshold = DT_INST_PROP(n, proximity_high_threshold), \ .proximity_low_threshold = DT_INST_PROP(n, proximity_low_threshold), \ .proximity_led_drive_strength = DT_INST_PROP(n, proximity_led_drive_strength), \ .proximity_interrupt_filter = DT_INST_PROP(n, proximity_interrupt_filter), \ .enable_wait_mode = DT_INST_PROP(n, enable_wait_mode), \ .wait_time_factor = DT_INST_PROP(n, wait_time_factor), \ .wait_long = DT_INST_PROP(n, wait_long), \ }; \ \ PM_DEVICE_DT_INST_DEFINE(n, tmd2620_pm_action); \ SENSOR_DEVICE_DT_INST_DEFINE(n, tmd2620_init, PM_DEVICE_DT_INST_GET(n), &tmd2620_data_##n, \ &tmd2620_config_##n, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &tmd2620_driver_api); DT_INST_FOREACH_STATUS_OKAY(TMD2620_INIT_INST); ```
/content/code_sandbox/drivers/sensor/ams/tmd2620/tmd2620.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
3,209
```objective-c /* * */ #ifndef ZEPHYR_DRIVERS_SENSOR_ENS210_ENS210_H_ #define ZEPHYR_DRIVERS_SENSOR_ENS210_ENS210_H_ #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/drivers/gpio.h> #include <zephyr/sys/util.h> /* Registers */ #define ENS210_REG_PART_ID 0x00 #define ENS210_REG_UID 0x04 #define ENS210_REG_SYS_CTRL 0x10 #define ENS210_REG_SYS_STAT 0x11 #define ENS210_REG_SENS_RUN 0x21 #define ENS210_REG_SENS_START 0x22 #define ENS210_REG_SENS_STOP 0x23 #define ENS210_REG_SENS_STAT 0x24 #define ENS210_REG_T_VAL 0x30 #define ENS210_REG_H_VAL 0x33 #define ENS210_PART_ID 0x0210 #if defined CONFIG_ENS210_TEMPERATURE_OFF #define ENS210_T_RUN 0 #define ENS210_T_START 0 #elif defined CONFIG_ENS210_TEMPERATURE_SINGLE #define ENS210_T_RUN 0 #define ENS210_T_START 1 #elif defined CONFIG_ENS210_TEMPERATURE_CONTINUOUS #define ENS210_T_RUN 1 #define ENS210_T_START 1 #endif #if defined CONFIG_ENS210_HUMIDITY_OFF #define ENS210_H_RUN 0 #define ENS210_H_START 0 #elif defined CONFIG_ENS210_HUMIDITY_SINGLE #define ENS210_H_RUN 0 #define ENS210_H_START 1 #elif defined CONFIG_ENS210_HUMIDITY_CONTINUOUS #define ENS210_H_RUN 1 #define ENS210_H_START 1 #endif /* * Polynomial * 0b 1000 1001 ~ x^7+x^3+x^0 * 0x 8 9 */ #define ENS210_CRC7_WIDTH 7 #define ENS210_CRC7_POLY 0x89 #define ENS210_CRC7_IVEC ((1UL << ENS210_CRC7_WIDTH) - 1) #define ENS210_CRC7_DATA_WIDTH 17 #define ENS210_CRC7_DATA_MASK ((1UL << ENS210_CRC7_DATA_WIDTH) - 1) #define ENS210_CRC7_DATA_MSB (1UL << (ENS210_CRC7_DATA_WIDTH - 1)) struct ens210_value_data { uint16_t val; uint8_t valid : 1; uint8_t crc7 : 7; } __packed; struct ens210_sys_ctrl { uint8_t low_power : 1; uint8_t reserved : 6; uint8_t reset : 1; } __packed; struct ens210_sys_stat { uint8_t sys_active : 1; uint8_t reserved : 7; } __packed; struct ens210_sens_run { uint8_t t_run : 1; uint8_t h_run : 1; uint8_t reserved : 6; } __packed; struct ens210_sens_start { uint8_t t_start : 1; uint8_t h_start : 1; uint8_t reserved : 6; } __packed; struct ens210_sens_stop { uint8_t t_stop : 1; uint8_t h_stop : 1; uint8_t reserved : 6; } __packed; struct ens210_sens_stat { uint8_t t_stat : 1; uint8_t h_stat : 1; uint8_t reserved : 6; } __packed; struct ens210_data { struct ens210_value_data temp; struct ens210_value_data humidity; }; struct ens210_config { struct i2c_dt_spec i2c; }; #endif /* ZEPHYR_DRIVERS_SENSOR_ENS210_ENS210_H_ */ ```
/content/code_sandbox/drivers/sensor/ams/ens210/ens210.h
objective-c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
878
```unknown # ENS210 Digital Temperature and Humidity sensor configuration options menuconfig ENS210 bool "ENS210 Digital Temperature and Humidity sensor" default y depends on DT_HAS_AMS_ENS210_ENABLED select I2C help Enable driver for ENS210 Digital Temperature and Humidity sensor. if ENS210 choice prompt "Temperature measurement mode" default ENS210_TEMPERATURE_CONTINUOUS help Enable/disable temperature measurements and set measurement mode. config ENS210_TEMPERATURE_OFF bool "Disable temperature measurements" config ENS210_TEMPERATURE_SINGLE bool "Temperature measurements in single shot mode" config ENS210_TEMPERATURE_CONTINUOUS bool "Temperature measurements in continuous mode" endchoice choice prompt "Humidity measurement mode" default ENS210_HUMIDITY_CONTINUOUS help Enable/disable relative humidity measurements and set measurement mode. config ENS210_HUMIDITY_OFF bool "Disable relative humidity measurements" config ENS210_HUMIDITY_SINGLE bool "Relative humidity measurements in single shot mode" config ENS210_HUMIDITY_CONTINUOUS bool "Relative humidity measurements in continuous mode" endchoice config ENS210_CRC_CHECK bool "CRC Check" default y help Check the crc value after data reading. config ENS210_MAX_STAT_RETRIES int "Number of status read retries" default 4 help Number of retries when status reading failed or device not ready. config ENS210_MAX_READ_RETRIES int "Number of value reading retries" default 4 help Number of retries when value reading failed, value not valid or crc not ok. endif # ENS210 ```
/content/code_sandbox/drivers/sensor/ams/ens210/Kconfig
unknown
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
361
```c /* * */ #define DT_DRV_COMPAT ams_ens210 #include <zephyr/device.h> #include <zephyr/drivers/i2c.h> #include <zephyr/kernel.h> #include <zephyr/sys/byteorder.h> #include <zephyr/sys/util.h> #include <zephyr/drivers/sensor.h> #include <zephyr/sys/__assert.h> #include <zephyr/logging/log.h> #include "ens210.h" LOG_MODULE_REGISTER(ENS210, CONFIG_SENSOR_LOG_LEVEL); #ifdef CONFIG_ENS210_CRC_CHECK static uint32_t ens210_crc7(uint32_t bitstream) { uint32_t polynomial = (ENS210_CRC7_POLY << (ENS210_CRC7_DATA_WIDTH - 1)); uint32_t bit = ENS210_CRC7_DATA_MSB << ENS210_CRC7_WIDTH; uint32_t val = (bitstream << ENS210_CRC7_WIDTH) | ENS210_CRC7_IVEC; while (bit & (ENS210_CRC7_DATA_MASK << ENS210_CRC7_WIDTH)) { if (bit & val) { val ^= polynomial; } bit >>= 1; polynomial >>= 1; } return val; } #endif /* CONFIG_ENS210_CRC_CHECK */ #if defined(CONFIG_ENS210_TEMPERATURE_SINGLE) \ || defined(CONFIG_ENS210_HUMIDITY_SINGLE) static int ens210_measure(const struct device *dev, enum sensor_channel chan) { struct ens210_data *drv_data = dev->data; const struct ens210_config *config = dev->config; uint8_t buf; int ret; const struct ens210_sens_start sense_start = { .t_start = ENS210_T_START && (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP), .h_start = ENS210_H_START && (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_HUMIDITY) }; /* Start measuring */ ret = i2c_reg_write_byte_dt(&config->i2c, ENS210_REG_SENS_START, *(uint8_t *)&sense_start); if (ret < 0) { LOG_ERR("Failed to set SENS_START to 0x%x", *(uint8_t *)&sense_start); return -EIO; } /* Wait for measurement to be completed */ do { k_sleep(K_MSEC(2)); ret = i2c_reg_read_byte_dt(&config->i2c, ENS210_REG_SENS_START, &buf); if (ret < 0) { LOG_ERR("Failed to read SENS_STAT"); } } while (buf & *(uint8_t *)&sense_start); return ret; } #endif /* Single shot mode */ static int ens210_sample_fetch(const struct device *dev, enum sensor_channel chan) { struct ens210_data *drv_data = dev->data; const struct ens210_config *config = dev->config; struct ens210_value_data data[2]; int ret, cnt; #ifdef CONFIG_ENS210_CRC_CHECK uint32_t temp_valid, humidity_valid; #endif /* CONFIG_ENS210_CRC_CHECK */ __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP || chan == SENSOR_CHAN_HUMIDITY); #if defined(CONFIG_ENS210_TEMPERATURE_SINGLE) \ || defined(CONFIG_ENS210_HUMIDITY_SINGLE) ret = ens210_measure(dev, chan); if (ret < 0) { LOG_ERR("Failed to measure"); return ret; } #endif /* Single shot mode */ for (cnt = 0; cnt <= CONFIG_ENS210_MAX_READ_RETRIES; cnt++) { ret = i2c_burst_read_dt(&config->i2c, ENS210_REG_T_VAL, (uint8_t *)&data, sizeof(data)); if (ret < 0) { LOG_ERR("Failed to read data"); continue; } /* Get temperature value */ if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP) { if (!data[0].valid) { LOG_WRN("Temperature not valid"); continue; } #ifdef CONFIG_ENS210_CRC_CHECK temp_valid = data[0].val | (data[0].valid << (sizeof(data[0].val) * 8)); if (ens210_crc7(temp_valid) != data[0].crc7) { LOG_WRN("Temperature CRC error"); continue; } #endif /* CONFIG_ENS210_CRC_CHECK */ drv_data->temp = data[0]; } /* Get humidity value */ if (chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_HUMIDITY) { if (!data[1].valid) { LOG_WRN("Humidity not valid"); continue; } #ifdef CONFIG_ENS210_CRC_CHECK humidity_valid = data[1].val | (data[1].valid << (sizeof(data[1].val) * 8)); if (ens210_crc7(humidity_valid) != data[1].crc7) { LOG_WRN("Humidity CRC error"); continue; } #endif /* CONFIG_ENS210_CRC_CHECK */ drv_data->humidity = data[1]; } return 0; } return -EIO; } static int ens210_channel_get(const struct device *dev, enum sensor_channel chan, struct sensor_value *val) { struct ens210_data *drv_data = dev->data; int32_t temp_frac; int32_t humidity_frac; switch (chan) { case SENSOR_CHAN_AMBIENT_TEMP: /* Temperature is in 1/64 Kelvin. Subtract 273.15 for Celsius */ temp_frac = sys_le16_to_cpu(drv_data->temp.val) * (1000000 / 64); temp_frac -= 273150000; val->val1 = temp_frac / 1000000; val->val2 = temp_frac % 1000000; break; case SENSOR_CHAN_HUMIDITY: humidity_frac = sys_le16_to_cpu(drv_data->humidity.val) * (1000000 / 512); val->val1 = humidity_frac / 1000000; val->val2 = humidity_frac % 1000000; break; default: return -ENOTSUP; } return 0; } static int ens210_sys_reset(const struct device *dev) { const struct ens210_config *config = dev->config; const struct ens210_sys_ctrl sys_ctrl = { .low_power = 0, .reset = 1 }; int ret; ret = i2c_reg_write_byte_dt(&config->i2c, ENS210_REG_SYS_CTRL, *(uint8_t *)&sys_ctrl); if (ret < 0) { LOG_ERR("Failed to set SYS_CTRL to 0x%x", *(uint8_t *)&sys_ctrl); } return ret; } static int ens210_sys_enable(const struct device *dev, uint8_t low_power) { const struct ens210_config *config = dev->config; const struct ens210_sys_ctrl sys_ctrl = { .low_power = low_power, .reset = 0 }; int ret; ret = i2c_reg_write_byte_dt(&config->i2c, ENS210_REG_SYS_CTRL, *(uint8_t *)&sys_ctrl); if (ret < 0) { LOG_ERR("Failed to set SYS_CTRL to 0x%x", *(uint8_t *)&sys_ctrl); } return ret; } static int ens210_wait_boot(const struct device *dev) { const struct ens210_config *config = dev->config; int cnt; int ret; struct ens210_sys_stat sys_stat; for (cnt = 0; cnt <= CONFIG_ENS210_MAX_STAT_RETRIES; cnt++) { ret = i2c_reg_read_byte_dt(&config->i2c, ENS210_REG_SYS_STAT, (uint8_t *)&sys_stat); if (ret < 0) { k_sleep(K_MSEC(1)); continue; } if (sys_stat.sys_active) { return 0; } if (cnt == 0) { ens210_sys_reset(dev); } ens210_sys_enable(dev, 0); k_sleep(K_MSEC(2)); } if (ret < 0) { LOG_ERR("Failed to read SYS_STATE"); } LOG_ERR("Sensor is not in active state"); return -EIO; } static const struct sensor_driver_api en210_driver_api = { .sample_fetch = ens210_sample_fetch, .channel_get = ens210_channel_get, }; static int ens210_init(const struct device *dev) { const struct ens210_config *config = dev->config; const struct ens210_sens_run sense_run = { .t_run = ENS210_T_RUN, .h_run = ENS210_H_RUN }; #if defined(CONFIG_ENS210_TEMPERATURE_CONTINUOUS) \ || defined(CONFIG_ENS210_HUMIDITY_CONTINUOUS) const struct ens210_sens_start sense_start = { .t_start = ENS210_T_RUN, .h_start = ENS210_H_RUN }; #endif int ret; uint16_t part_id; if (!device_is_ready(config->i2c.bus)) { LOG_ERR("I2C bus device not ready"); return -ENODEV; } /* Wait until the device is ready. */ ret = ens210_wait_boot(dev); if (ret < 0) { return -EIO; } /* Check Hardware ID. This is only possible after device is ready * and active */ ret = i2c_burst_read_dt(&config->i2c, ENS210_REG_PART_ID, (uint8_t *)&part_id, sizeof(part_id)); if (ret < 0) { LOG_ERR("Failed to read Part ID register"); return -EIO; } if (part_id != ENS210_PART_ID) { LOG_ERR("Part ID does not match. Want 0x%x, got 0x%x", ENS210_PART_ID, part_id); return -EIO; } /* Enable low power mode */ if ((ENS210_T_RUN | ENS210_H_RUN) == 0) { ens210_sys_enable(dev, 1); } /* Set measurement mode*/ ret = i2c_reg_write_byte_dt(&config->i2c, ENS210_REG_SENS_RUN, *(uint8_t *)&sense_run); if (ret < 0) { LOG_ERR("Failed to set SENS_RUN to 0x%x", *(uint8_t *)&sense_run); return -EIO; } #if defined(CONFIG_ENS210_TEMPERATURE_CONTINUOUS) \ || defined(CONFIG_ENS210_HUMIDITY_CONTINUOUS) /* Start measuring */ ret = i2c_reg_write_byte_dt(&config->i2c, ENS210_REG_SENS_START, *(uint8_t *)&sense_start); if (ret < 0) { LOG_ERR("Failed to set SENS_START to 0x%x", *(uint8_t *)&sense_start); return -EIO; } #endif return 0; } #define ENS210_DEFINE(inst) \ static struct ens210_data ens210_data_##inst; \ \ static const struct ens210_config ens210_config_##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ }; \ \ SENSOR_DEVICE_DT_INST_DEFINE(inst, ens210_init, NULL, \ &ens210_data_##inst, &ens210_config_##inst, POST_KERNEL, \ CONFIG_SENSOR_INIT_PRIORITY, &en210_driver_api); \ DT_INST_FOREACH_STATUS_OKAY(ENS210_DEFINE) ```
/content/code_sandbox/drivers/sensor/ams/ens210/ens210.c
c
2016-05-26T17:54:19
2024-08-16T18:09:06
zephyr
zephyrproject-rtos/zephyr
10,307
2,577