Skip to content

Commit dfcb7ad

Browse files
drivers: sensor: bmm350: add default odr/osr
Add a way to define the default odr and osr with devicetree for the bmm350. Signed-off-by: Ryan McClelland <[email protected]>
1 parent a6d8832 commit dfcb7ad

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

drivers/sensor/bosch/bmm350/bmm350.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ static uint8_t mag_odr_to_reg(const struct sensor_value *val)
710710
static uint8_t mag_osr_to_reg(const struct sensor_value *val)
711711
{
712712
switch (val->val1) {
713-
case 0:
713+
case 1:
714714
return BMM350_NO_AVERAGING;
715715
case 2:
716716
return BMM350_AVERAGING_2;
@@ -1053,9 +1053,12 @@ static int pm_action(const struct device *dev, enum pm_device_action action)
10531053
static int bmm350_init(const struct device *dev)
10541054
{
10551055
int err = 0;
1056+
const struct bmm350_config *config = dev->config;
10561057
struct bmm350_data *data = dev->data;
1057-
const struct sensor_value odr = {100, 0};
1058-
const struct sensor_value osr = {2, 0};
1058+
const struct sensor_value osr = {config->default_osr, 0};
1059+
struct sensor_value odr;
1060+
1061+
mag_reg_to_odr(config->default_odr, &odr);
10591062

10601063
err = bmm350_bus_check(dev);
10611064
if (err < 0) {
@@ -1078,8 +1081,9 @@ static int bmm350_init(const struct device *dev)
10781081
/* Assign axis_en with all axis enabled (BMM350_EN_XYZ_MSK) */
10791082
data->axis_en = BMM350_EN_XYZ_MSK;
10801083

1081-
/* Initialize to 100Hz, averaging between 2 samples by default */
1084+
/* Initialize to odr and osr */
10821085
if (set_mag_odr_osr(dev, &odr, &osr) < 0) {
1086+
LOG_ERR("failed to set default odr and osr");
10831087
return -EIO;
10841088
}
10851089

@@ -1095,6 +1099,8 @@ static int bmm350_init(const struct device *dev)
10951099
static const struct bmm350_config bmm350_config_##inst = { \
10961100
.bus.i2c = I2C_DT_SPEC_INST_GET(inst), \
10971101
.bus_io = &bmm350_bus_io_i2c, \
1102+
.default_odr = DT_INST_ENUM_IDX(inst, odr) + BMM350_DATA_RATE_400HZ, \
1103+
.default_osr = DT_INST_PROP(inst, osr), \
10981104
BMM350_INT_CFG(inst)}; \
10991105
\
11001106
PM_DEVICE_DT_INST_DEFINE(inst, pm_action); \

drivers/sensor/bosch/bmm350/bmm350.h

+2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ struct bmm350_config {
452452
struct bmm350_bus bus;
453453
const struct bmm350_bus_io *bus_io;
454454
struct gpio_dt_spec drdy_int;
455+
uint8_t default_odr;
456+
uint8_t default_osr;
455457
};
456458

457459
struct bmm350_data {

dts/bindings/sensor/bosch,bmm350.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,43 @@ properties:
1010
description: |
1111
This property specifies the connection for data ready pin.
1212
The polarity default is active high when sensor data is ready.
13+
14+
odr:
15+
type: string
16+
description: |
17+
Default output data rate in Hz. Only the following values are allowed:
18+
400 - 400 - 2.5ms
19+
200 - 200 - 5ms
20+
100 - 100 - 10ms
21+
50 - 50 - 20ms
22+
25 - 25 - 40ms
23+
12.5 - 25/2 - 80ms
24+
6.25 - 25/4 - 160ms
25+
3.125 - 25/8 - 320ms
26+
1.5625 - 25/16 - 640ms
27+
default: "100"
28+
enum:
29+
- "400"
30+
- "200"
31+
- "100"
32+
- "50"
33+
- "25"
34+
- "12.5"
35+
- "6.25"
36+
- "3.125"
37+
- "1.5625"
38+
39+
osr:
40+
type: int
41+
description: |
42+
Default oversampling. Only the following values are allowed:
43+
8 - 8x
44+
4 - 4x
45+
2 - 2x
46+
1 - 1x
47+
default: 2
48+
enum:
49+
- 1
50+
- 2
51+
- 4
52+
- 8

0 commit comments

Comments
 (0)