-
Notifications
You must be signed in to change notification settings - Fork 8.3k
driver: sensor: max30101 Enable multiple instance, data acquisition and add trigger support #96632
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
driver: sensor: max30101 Enable multiple instance, data acquisition and add trigger support #96632
Conversation
|
Hello @Sokario, and thank you very much for your first pull request to the Zephyr project! |
47dbde8 to
f7cd45e
Compare
c198089 to
8086146
Compare
|
I had an error on twister pass (native_sim) for sensor_shell. Discovered that I needed to modify
Discovered an odity with |
8086146 to
36ba139
Compare
MaureenHelm
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.
Any chance you're planning to implement the sensor async API?
| .slot = MAX30101_SLOT_CFG(n), \ | ||
| }; \ | ||
| static struct max30101_data max30101_data_##n; \ | ||
| DEVICE_DT_INST_DEFINE(n, max30101_init, NULL, &max30101_data_##n, &max30101_config_##n, \ |
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_DEVICE_DT_INST_DEFINE
| smp-sr: | ||
| type: int | ||
| default: 50 | ||
| enum: | ||
| - 50 # 50 Hz | ||
| - 100 # 100 Hz | ||
| - 200 # 200 Hz | ||
| - 400 # 400 Hz | ||
| - 800 # 800 Hz | ||
| - 1000 # 1000 Hz | ||
| - 1600 # 1600 Hz | ||
| - 3200 # 3200 Hz | ||
| description: | | ||
| 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. Default set to 50 Hz. | ||
| led-pw: | ||
| type: int | ||
| default: 69 | ||
| enum: | ||
| - 69 # 69 us | 15 bits resolution | ||
| - 118 # 118 us | 16 bits resolution | ||
| - 215 # 215 us | 17 bits resolution | ||
| - 411 # 411 us | 18 bits resolution | ||
| description: | | ||
| Set the pulse width for each LED to control the integration time | ||
| of the ADC in us. The ADC resolution is directly related to the | ||
| integration time. Default set to 69 us. | ||
| led-pa: | ||
| type: uint8-array | ||
| default: [0xff, 0xff, 0xff] | ||
| description: | | ||
| Set the pulse amplitude to control the LED current. The actual | ||
| measured LED current for each part can vary significantly due to the | ||
| trimming methodology. Default set to [0xff, 0xff, 0xff]. | ||
| [0]: Red LED | ||
| [1]: IR LED | ||
| [2]: Green LED | ||
| Value range: 0x00 - 0xFF | 0.0 mA - 50.0 mA | ||
| led-slot: | ||
| type: array | ||
| default: [0, 0, 0, 0] | ||
| description: | | ||
| Set which LED are active in time each slot for Multi-LED mode only. | ||
| 0: None (Disabled) | ||
| 1: Red LED | ||
| 2: InfraRed LED | ||
| 3: Green LED | ||
| Default set to [0, 0, 0, 0]. |
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.
Update the descriptions to explain why the specific default values were chosen. Often they are chosen to match hardware reset values
36ba139 to
f952e9f
Compare
8eb7a25 to
d3b946c
Compare
|
I had to modify once again the EDIT: I understood why, it was because of the hard coded value of the channel used to test the attribute. My modification should fix any future issue. EDIT 2: I also added a commit to automatically get the right number of channel to test in |
0309c38 to
76e2eb3
Compare
|
While working on async API, I noticed SENSOR_TRIG_FIFO_FULL wasn't the best suited for |
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 support for multiple instances, trigger functionality, and enhanced data acquisition for the MAX30101 heart rate sensor. It moves configuration from compile-time Kconfig options to device tree bindings, enabling multiple sensor instances with different configurations.
- Replaced Kconfig-based configuration with device tree bindings for multi-instance support
- Added interrupt/trigger support with new sensor channels and trigger types
- Enhanced FIFO data handling with better channel mapping and optional die temperature acquisition
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| dts/bindings/sensor/maxim,max30101.yaml | Device tree binding definition with configuration properties |
| drivers/sensor/maxim/max30101/max30101.c | Refactored driver for device tree configuration and enhanced data handling |
| drivers/sensor/maxim/max30101/max30101.h | Updated constants and data structures for multi-instance and trigger support |
| drivers/sensor/maxim/max30101/max30101_trigger.c | New trigger/interrupt handling implementation |
| drivers/sensor/maxim/max30101/Kconfig | Simplified Kconfig with trigger-specific options |
| include/zephyr/drivers/sensor.h | Added new sensor channel and trigger type enums |
| samples/sensor/heart_rate/src/main.c | Updated sample to demonstrate trigger functionality |
| tests/drivers/build_all/sensor/i2c.dtsi | Added required device tree property for test |
| samples/sensor/sensor_shell/pytest/test_sensor_shell.py | Made test more robust by dynamically detecting channel count |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| mask = MAX30101_INT_ALC_OVF_MASK; | ||
| index = MAX30101_ALC_CB_INDEX; | ||
| } else { | ||
| LOG_ERR("Only SENSOR_CHAN_LIGHT are supported for overflow trigger"); |
Copilot
AI
Oct 9, 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.
Corrected 'SENSOR_CHAN_LIGHT' to 'SENSOR_CHAN_AMBIENT_LIGHT' to match the actual check on line 95.
| LOG_ERR("Only SENSOR_CHAN_LIGHT are supported for overflow trigger"); | |
| LOG_ERR("Only SENSOR_CHAN_AMBIENT_LIGHT is supported for overflow trigger"); |
| return 0; | ||
| } | ||
|
|
||
| /* The work-queue is shared across all instances, hence it is initialized separatedly */ |
Copilot
AI
Oct 9, 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.
Corrected spelling of 'separatedly' to 'separately'.
| /* The work-queue is shared across all instances, hence it is initialized separatedly */ | |
| /* The work-queue is shared across all instances, hence it is initialized separately */ |
| 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. Only one RED puls/conversion in HR mode. |
Copilot
AI
Oct 9, 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.
Corrected spelling of 'puls' to 'pulse'.
| period. Only one RED puls/conversion in HR mode. | |
| period. Only one RED pulse/conversion in HR mode. |
| 2: InfraRed LED | ||
| 3: Green LED | ||
| Default set to [0, 0, 0, 0], no LED activated in multi-LED mode. | ||
| User needs to chose wich LED is active for each slot. |
Copilot
AI
Oct 9, 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.
Corrected spelling: 'chose' should be 'choose' and 'wich' should be 'which'.
| User needs to chose wich LED is active for each slot. | |
| User needs to choose which LED is active for each slot. |
The max30101 sensor driver doesn't support multiple instance. Update Kconfig and maxim,max30101.yaml for instance based configuration. Propagate changes over existing files. Signed-off-by: Logan Saint-Germain <l.saintgermain@catie.fr>
76e2eb3 to
79bb9af
Compare
|
Thank you @kartben for the review from copilot. I added the suggestions in the corresponding commits. |
d2678b7 to
ff33276
Compare
The max30101 sensor driver doesn't support triggers. Add `.trigger_set` API and corresponding Kconfig and device tree parameters. Add `SENSOR_CHAN_AMBIENT_LIGHT` and `SENSOR_TRIG_OVERFLOW`. Signed-off-by: Logan Saint-Germain <l.saintgermain@catie.fr>
ff33276 to
7923c1f
Compare
| positions are changed. | ||
| config MAX30101_DIE_TEMPERATURE | ||
| bool "Die temperature acquisition" | ||
| default n |
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.
default n is already the default and should therefore be omitted.
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.
Thank you, @maass-hamburg — it might have been an artifact from testing. Good catch, and thanks for taking the time to review it.
I’ve made the changes; now we just need to wait for the CI to finish.
EDIT: Thank you as well for triggering the CI — it’s much appreciated.
The max30101 allows to configure time slots in samples acquisition. It is now supported by adding matrix mapping for the slot/fifo indexing. When a channel is present multiple times, the resulting sample from the `sensor_channel_get` is averaging each entry. Added Die temperature sample acquisition with `CONFIG_MAX30101_DIS_TEMPERATURE` Kconfig. Signed-off-by: Logan Saint-Germain <l.saintgermain@catie.fr>
…tests Use of the `sensor get` help. No channel provided allows the sensor_shell to iterate through every channels. Getting the last channel gives the last channel index and therefor the channel count. Provide futur proofing for new channels. Signed-off-by: Logan Saint-Germain <l.saintgermain@catie.fr>
7923c1f to
52a93b3
Compare
|
|
Hi @Sokario! 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! 🪁 |
|
Thanks everyone for the reviews, feedback, and quick actions! |



This pull request adds multiple instance, triggers support and enhance data recovery for the MAXIM MAX30101.
MAXIM MAX30101 sensor multi-instance support:
MAXIM MAX30101 sensor triggers support:
irq-gpiosdevice tree parameter.max30101_trigger.cand updatedCMakeLists.txtandmax30101.c.sample.yamlandREADME.rstaccordingly.sensor_shell.candtest_sensor_shell.pyto match the tow newly added enumerators.test_sensor_shell.pyto automatically adapt to futur modification of sensor_channel.MAXIM MAX30101 sensor
sample_fetchenhancement:MAX30101 datasheet.