Skip to content
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: ams_as5600: Rewrite driver to enhance configuration #86532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

c-ewing
Copy link

@c-ewing c-ewing commented Mar 3, 2025

This is a complete rewrite of the existing AS5600 driver. Device registers and configuration are supported through the fetch and get API using channels and attributes. The device tree binding was updated to cover all configurable options of the device. The device is now initialized to the state defined in the device tree on init or its power on reset state if a setting is not configured.

This rewrite referenced the AS5600 datasheet and has been tested against hardware.

This is my first time touching Zephyr and I would greatly appreciate any and all feedback! I understand large PRs are not recommended but I wasn't sure how to split this up and am certainly willing to adjust and split this into multiple PRs.

@zephyrbot zephyrbot added the area: Sensors Sensors label Mar 3, 2025
Copy link

github-actions bot commented Mar 3, 2025

Hello @c-ewing, 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. 😊

@@ -1,12 +1,172 @@
# AS5600 Angular position sensor configuration option

# Copyright (c) 2022, Felipe Neves.
# Copyright (c) 2025, Cameron Ewing
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the common practice is to add a second copyright line

Copy link
Author

Choose a reason for hiding this comment

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

This file was reverted as part of moving the wrongly placed configuration options and this should be resolved. The only other instance of removing his copyright was also fixed in ams_as5600.c.

Comment on lines 31 to 37
config AS5600_ANGULAR_RANGE
int "Maximum angular range"
range 205 4096
default 4096
help
Maximum angular range (min. 205; max. 4096)
The minimum angular range is 18 degrees (205 steps).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this not inferred from end - start?

Copy link
Author

Choose a reason for hiding this comment

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

Although true that the angular range can be computed from the end and start positions, the AS5600 datasheet explicitly documents a method that uses a start position and an angular range to configure the device. To fully support all programming options as described by the manufacturer, I’ve retained the angular range setting in the driver. For reference, please see Figure 26 (Option C: Programming a Maximum Angular Range Through the I²C Interface on page 24 of the datasheet.

That being said I don't use the start and angular range configuration in my setup and am willing to remove it or directly document the different programming options to provide more clarity on its use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets see what this looks like when using devicetree bindings and take it from there.

Comment on lines 16 to 37
config AS5600_START_POSITION
int "Start position"
default 0
range 0 4095
help
Start position (min. 0; max. 4095)
Difference between Start and End position must be at least 18 degrees (205 steps).
config AS5600_END_POSITION
int "End position"
default 0
range 0 4095
help
End position (min. 0; max. 4095)
Difference between Start and End position must be at least 18 degrees (205 steps).

config AS5600_ANGULAR_RANGE
int "Maximum angular range"
range 205 4096
default 4096
help
Maximum angular range (min. 205; max. 4096)
The minimum angular range is 18 degrees (205 steps).
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of these don't seem to belong in Kconfig, what if I wanted 2 of these sensors with different ranges? I think they belong in devicetree.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Almost all these kconfigs belong as devicetree bindings since we don't want them to affect every instance of this sensor.

Copy link
Author

Choose a reason for hiding this comment

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

This is corrected and retested in the latest commit.

I started working on the driver with device tree configuration and then somewhere along the lines got my wires crossed and moved it all to Kconfig. Sorry!

@c-ewing c-ewing force-pushed the as5600-driver-improvement branch from 23b285e to 889f21c Compare March 4, 2025 04:23
@c-ewing c-ewing changed the title drivers: sensor: ams_as5600: Rewrite driver to support attributes/channels/Kconfig drivers: sensor: ams_as5600: Rewrite driver to enhance configuration Mar 4, 2025
This is a complete rewrite of the existing AS5600 driver. Device registers
and configuration are supported through the fetch and get API using
channels and attributes. The device tree binding was updated to cover all
configurable options of the device. The device is now initialized to the
state defined in the device tree on init or its power on reset state if a
setting is not configured.

Signed-off-by: Cameron Ewing <cameronramsayewing@gmail.com>
@c-ewing c-ewing force-pushed the as5600-driver-improvement branch from 889f21c to cd65082 Compare March 4, 2025 09:36
@c-ewing
Copy link
Author

c-ewing commented Mar 5, 2025

I believe I’ve addressed all the initial concerns mentioned above. When you have time, I would greatly appreciate a second review of my proposed changes.

Thanks again for your time, patience, and guidance.

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.

4 participants