-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: sensor: add support for ALS31300 3D Hall Effect Sensor #94248
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
drivers: sensor: add support for ALS31300 3D Hall Effect Sensor #94248
Conversation
56c4273 to
04ceaf7
Compare
|
|
Also, please address the Issues raised by SonarQube |
There was a problem hiding this 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 driver support for the Allegro Microsystems ALS31300 3-axis linear Hall Effect sensor with I2C interface. The implementation provides both synchronous sensor API and asynchronous RTIO API support for magnetic field measurements on X, Y, and Z axes along with device temperature readings.
- Complete driver implementation for ALS31300 3D Hall Effect sensor with I2C communication
- Standard Zephyr sensor API support for sample_fetch/channel_get operations
- RTIO-based asynchronous API implementation with proper encoding/decoding functions
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/drivers/build_all/sensor/i2c.dtsi |
Adds test device tree node for build verification |
dts/bindings/sensor/allegro,als31300.yaml |
Device tree binding definition for the sensor |
drivers/sensor/als31300/als31300.h |
Header file with register definitions, bit masks, and data structures |
drivers/sensor/als31300/als31300.c |
Main driver implementation with sensor API and RTIO support |
drivers/sensor/als31300/Kconfig |
Configuration options for the driver |
drivers/sensor/als31300/CMakeLists.txt |
Build configuration for the driver |
drivers/sensor/Kconfig |
Integration of driver configuration into main sensor Kconfig |
drivers/sensor/CMakeLists.txt |
Integration of driver build into main sensor CMakeLists |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| description: Allegro ALS31300 3D Linear Hall Effect Sensor | ||
|
|
||
| compatible: "allegro,als31300" |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compatible string uses 'allegro' vendor prefix, but the expected format should be 'allegromicro' to match the company name Allegro Microsystems. This should be consistent with other Allegro device bindings.
| compatible: "allegro,als31300" | |
| compatible: "allegromicro,als31300" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not applicable, after checking this will break build
drivers/sensor/als31300/als31300.c
Outdated
| * Bits [6:4] = 0 → Low-power count = 0.5ms (doesn't matter in Active Mode) | ||
| * Bits [31:7] = 0 → Reserved (should be 0) | ||
| */ | ||
| ret = i2c_reg_write_byte_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, reg27_value); |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function i2c_reg_write_byte_dt() expects a uint8_t value but reg27_value is declared as uint32_t. This will only write the lowest byte and ignore the upper 24 bits, which may not configure the device correctly.
| ret = i2c_reg_write_byte_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, reg27_value); | |
| ret = i2c_reg_write_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, (uint8_t *)®27_value, sizeof(reg27_value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is required i2c_reg_write_byte_dt
drivers/sensor/als31300/als31300.c
Outdated
| uint8_t test_val[4]; | ||
|
|
||
| ret = i2c_reg_read_byte_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, test_val); |
Copilot
AI
Sep 1, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function i2c_reg_read_byte_dt() expects a uint8_t* parameter but test_val is declared as uint8_t[4]. This function only reads a single byte, not 4 bytes as the array suggests.
| uint8_t test_val[4]; | |
| ret = i2c_reg_read_byte_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, test_val); | |
| uint8_t test_val; | |
| ret = i2c_reg_read_byte_dt(&cfg->i2c, ALS31300_REG_VOLATILE_27, &test_val); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, now I am following your suggestion
cbd86fa to
eb0c088
Compare
9aa1e02 to
e58b74c
Compare
f73cde1 to
518883a
Compare
ubieda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks!
drivers/sensor/als31300/als31300.c
Outdated
| * @param raw_value Signed 12-bit magnetic field value | ||
| * @return Magnetic field in microgauss | ||
| */ | ||
| int32_t als31300_convert_to_gauss(const struct device *dev, int16_t raw_value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this function take a device pointer argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will delete it, I thought it might be used in the future, but this will simplify it
drivers/sensor/als31300/als31300.c
Outdated
| /* Convert microcelsius to sensor_value format */ | ||
| val->val1 = converted_val / 1000000; | ||
| val->val2 = converted_val % 1000000; | ||
|
|
||
| /* Handle negative temperatures properly */ | ||
| if (converted_val < 0 && val->val2 != 0) { | ||
| val->val1 -= 1; | ||
| val->val2 = 1000000 + val->val2; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use sensor_value_from_micro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I added this as well
drivers/sensor/als31300/als31300.c
Outdated
| /* Convert microgauss to sensor_value format */ | ||
| val->val1 = converted_val / 1000000; | ||
| val->val2 = converted_val % 1000000; | ||
| /* Handle negative values properly */ | ||
| if (converted_val < 0 && val->val2 != 0) { | ||
| val->val1 -= 1; | ||
| val->val2 = 1000000 + val->val2; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
drivers/sensor/als31300/als31300.c
Outdated
| return 0; | ||
| } | ||
|
|
||
| static const struct sensor_driver_api als31300_api = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use DEVICE_API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I included it
drivers/sensor/als31300/als31300.c
Outdated
| /* Small delay to ensure the mode change takes effect */ | ||
| k_msleep(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this particular value for the delay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was meant for testing at first. I tested and functionality is not affected, so I will delete it.
Add driver for Allegro Microsystems ALS31300 3-axis linear Hall Effect sensor. The driver supports: - I2C communication interface - X, Y, Z magnetic field measurements - Device temperature readings Signed-off-by: Fabian Barraez <fabianbarraez@gmail.com>
518883a to
0e14a50
Compare
|



Overview
This PR adds driver support for the Allegro Microsystems ALS31300 3-axis linear Hall Effect sensor with I2C interface.
Features Implemented
Hardware Details
The ALS31300 is a 3D linear Hall Effect sensor that provides 12-bit digital output proportional to the magnetic field strength in each axis. The sensor communicates via I2C and is commonly used in:
Testing
Files Modified/Added
drivers/sensor/als31300/- Driver implementationdts/bindings/sensor/allegromicro,als31300.yaml- Device tree bindingsdrivers/sensor/CMakeLists.txt- Build integrationdrivers/sensor/Kconfig- Configuration optionsReferences