Skip to content

drivers: sensor: bmm350: add default odr/osr from dts and attr_get api #90078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

XenuIsWatching
Copy link
Member

@XenuIsWatching XenuIsWatching commented May 16, 2025

Add a default odr/osr from the dts and implement the attr_get api

This also adds the ability to set the pad drive strength as well as the interrupt line being od/pp or active high/low.

uint8_t odr_bits;

/* read current state */
ret = bmm350_reg_read(dev, BMM350_REG_PMU_CMD_AGGR_SET, &rx_buf[0], 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = bmm350_reg_read(dev, BMM350_REG_PMU_CMD_AGGR_SET, &rx_buf[0], 3);
ret = bmm350_reg_read(dev, BMM350_REG_PMU_CMD_AGGR_SET, &rx_buf[0], sizeof(rx_buf));

Copy link
Member Author

@XenuIsWatching XenuIsWatching May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed... also made a nit picky cleanup commit which included fixing this in other places

}
}

void mag_reg_to_osr(uint8_t bits, struct sensor_value *val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void mag_reg_to_osr(uint8_t bits, struct sensor_value *val)
static void mag_reg_to_osr(uint8_t bits, struct sensor_value *val)

Comment on lines -713 to +703
case 0:
case 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray change? This doesn't look related to adding default odr/osr

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentional to be consistent with other drivers, which just have a 1 as the no average for osr... I can separate it in to another commit

6.25 - 25/4 - 160ms
3.125 - 25/8 - 320ms
1.5625 - 25/16 - 640ms
default: "100"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to explain in the description why the default value was selected
https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#dt-bindings-default-rules

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just add a note about how this is 'reset' value of the device
image

4 - 4x
2 - 2x
1 - 1x
default: 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to explain in the description why the default value was selected
https://docs.zephyrproject.org/latest/build/dts/bindings-upstream.html#dt-bindings-default-rules

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment #90078 (comment)

@XenuIsWatching XenuIsWatching force-pushed the bmm350-stuff branch 2 times, most recently from b29c3a5 to 4e178b2 Compare May 20, 2025 19:51
@XenuIsWatching XenuIsWatching force-pushed the bmm350-stuff branch 4 times, most recently from 52dfb2b to 7ec33bc Compare May 20, 2025 23:34
@XenuIsWatching
Copy link
Member Author

XenuIsWatching commented May 20, 2025

pinging @maxd-nordic to also take a look

@zephyrproject-rtos zephyrproject-rtos deleted a comment from sonarqubecloud bot May 21, 2025
MaureenHelm
MaureenHelm previously approved these changes May 21, 2025
@XenuIsWatching
Copy link
Member Author

@MaureenHelm sorry, for the churn after your approval, but I found a function where I forgot to change the return code from a int8_t to a int (bmm350_get_compensated_mag_xyz_temp_data_fixed)

@XenuIsWatching XenuIsWatching force-pushed the bmm350-stuff branch 3 times, most recently from 35c710a to 5df74bf Compare May 23, 2025 05:24
Add the attr_get api. Also rename functions where they implied
accelerometer to imply magnetometer.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Add a way to define the default odr and osr with devicetree for
the bmm350.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Fix the oversampling value to be 1 from 0 for no oversampling to be
consistant with other sensor drivers.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
There is a race condition where an interrupt can fire before the
drdy_handler is registered. The drdy_handler will tradionaly
callback the sample get clearing the interrupt... but if it's not
configured and NULL, the interrupt will stay forever latched. Read
the interrupt status to clear the interrupt flag allowing it to
trigger again.

Also, move the serial api function helpers in to the header
allowing them to be used from other c files.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Add configurations for setting the pad drive strength and the
interrupt active high/low and od/pp.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
There were a lot of places where the return value was sum'ed up
which can be slightly easier to read, but can give an odd return
value in the end. This changes it to just return immediately if
an error is seen.

There was also runtime NULL checking of input arguments that are
rather programmer clown prevention. Change these to asserts.

The return value didn't have a consistant type through the file,
make it consistently an int.

This changes the name of the return value of fix_sign to be
signed_value differenating it from the ret name used elsewhere.

Use the sizeof(buffer) as the argument for reg reads and writes
rather than a hard number.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Run clang-format on files

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
This exposes a driver specific function to perform a
magentic reset by the application.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
Copy link

@XenuIsWatching
Copy link
Member Author

Rebased to get around the CI flake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants