Skip to content

drivers: sensor: Add support for BH1730 ambient light sensor #89908

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

Merged
merged 1 commit into from
Jun 2, 2025

Conversation

rtborg
Copy link
Contributor

@rtborg rtborg commented May 13, 2025

This commit adds support for BH1730 ambient light sensor.

@github-actions github-actions bot added the area: Sensors Sensors label May 13, 2025
Copy link

Hello @rtborg, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the BH1730 ambient light sensor by introducing a new sensor driver, device tree bindings, and associated build changes.

  • Added a new sensor node in the DTS test file.
  • Introduced DTS binding YAML for the BH1730 sensor.
  • Implemented the sensor driver with configuration (Kconfig, CMakeLists.txt) and driver source code.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/drivers/build_all/sensor/i2c.dtsi Added sensor node for BH1730.
dts/bindings/sensor/rohm,bh1730.yaml New DTS binding file describing sensor properties and defaults.
drivers/sensor/rohm/bh1730/bh1730.c New driver code implementing sensor functionality.
drivers/sensor/rohm/bh1730/Kconfig Added configuration options for the BH1730 sensor.
drivers/sensor/rohm/bh1730/CMakeLists.txt Build file listing new driver source.
drivers/sensor/rohm/Kconfig Updated to include the new sensor driver Kconfig.
drivers/sensor/rohm/CMakeLists.txt Updated to add the BH1730 subdirectory when enabled.
Comments suppressed due to low confidence (1)

drivers/sensor/rohm/bh1730/bh1730.c:29

  • The constant 'BH1730_CONTORL_ADC_EN_POWER_ON_SINGLE_READING' is misspelled; consider renaming it to 'BH1730_CONTROL_ADC_EN_POWER_ON_SINGLE_READING' for clarity.
#define BH1730_CONTORL_ADC_EN_POWER_ON_SINGLE_READING 0x0B

@rtborg rtborg force-pushed the bh1730_sensor branch 2 times, most recently from 9e03ed6 to 9f7d049 Compare May 16, 2025 20:18
@rtborg rtborg requested a review from kartben May 19, 2025 20:30
@rtborg rtborg force-pushed the bh1730_sensor branch 2 times, most recently from 0e381c6 to 37abf2c Compare May 22, 2025 19:50
@rtborg
Copy link
Contributor Author

rtborg commented May 23, 2025

Are there any other comments which need addressing?

Copy link
Member

@MaureenHelm MaureenHelm left a comment

Choose a reason for hiding this comment

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

A couple of small nits, but otherwise LGTM

@rtborg rtborg requested a review from MaureenHelm May 24, 2025 12:30
@rtborg
Copy link
Contributor Author

rtborg commented May 26, 2025

Comments fixed now

@rtborg rtborg force-pushed the bh1730_sensor branch 2 times, most recently from 85bb848 to 242477c Compare June 1, 2025 16:52
This commit adds support for BH1730 ambient light sensor.

Signed-off-by: Borislav Kereziev <b.kereziev@gmail.com>
Copy link

sonarqubecloud bot commented Jun 1, 2025

@kartben kartben merged commit 10e5753 into zephyrproject-rtos:main Jun 2, 2025
26 checks passed
Copy link

github-actions bot commented Jun 2, 2025

Hi @rtborg!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

#define BH1730_CONTROL_ADC_EN_POWER_ON_SINGLE_READING 0x0B
#define BH1730_CONTROL_ADC_EN_POWER_ON 0x03
#define BH1730_CONTROL_ADC_DATA_UPDATED (1 << 4)
#define BH1730_TINT 2.8E-9 /* Internal clock period Tint */
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't appear to be used.

Comment on lines +129 to +142
if (gain_reg_val == 0x0) {
return 1;
}
if (gain_reg_val == 0x01) {
return 2;
}
if (gain_reg_val == 0x02) {
return 64;
}
if (gain_reg_val == 0x03) {
return 128;
}

return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit, this is a bit better (fewer branches):

static uint8_t lookup_table = [1, 2, 64, 128];

if (gain_reg_val >= ARRAY_SIZE(lookup_table)) {
  return 1;
}

return lookup_table[gain_reg_val];

@fouge
Copy link
Contributor

fouge commented Jun 16, 2025

thanks for adding this to Zephyr 🙏

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.

5 participants