From: Brandon Saint-John <branstj@gmail.com>
To: Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com>
Cc: Brandon Saint-John <branstj@gmail.com>,
Jonathan Cameron <jic23@kernel.org>,
linux-iio@vger.kernel.org, rust-for-linux@vger.kernel.org,
linux-kernel@vger.kernel.org, Miguel Ojeda <ojeda@kernel.org>,
Igor Korotin <igor.korotin.linux@gmail.com>
Subject: Re: [RFC PATCH v3 3/4] iio: position: add Rust driver for ams AS5600
Date: Thu, 28 May 2026 22:37:56 -0700 [thread overview]
Message-ID: <20260529053803.3256031-1-branstj@gmail.com> (raw)
In-Reply-To: <20260524132824.54918-4-muchamadcoirulanwar@gmail.com>
On Sun, 24 May 2026 20:28:22 +0700 Muchamad Coirul Anwar <muchamadcoirulanwar@gmail.com> wrote:
> +//! Driver for ams AS5600 12-bit magnetic rotary position sensor.
> +//!
> +//! Datasheet: https://ams.com/documents/20143/36005/AS5600_DS000365_5-00.pdf
Small nitpick, but going to the above link doesn't resolve to a pdf.
The link that works as of today for me is:
https://look.ams-osram.com/m/7059eac7531a86fd/original/AS5600-DS000365.pdf
> +fn err_enodata() -> Error {
> + Error::from_errno(-(ENODATA as i32))
> +}
Later on it's probably better to add ENODATA to kernel::error::code instead of the helper.
> +#[derive(Clone, Copy)]
> +struct As5600Io(*mut i2c_client);
> +
You can replace the *mut i2c_client with an ARef<I2cClient>. The
kernel::impl_device_context_into_aref! macro is run on &I2cClient<Core>
so you can call ARef::from on dev instead of casting it to the raw pointer
to hold it.
Then it saves you from repeating a few different parts, like redoing unsafe impls,
recasting back to I2cClient<Core> in try_readN, etc.
> +impl IoCapable<u8> for As5600Io {}
> +impl IoCapable<u16> for As5600Io {}
None of the read_u16 or IoCapable<u16> are used at this point, so those traits/methods
could be dropped.
As a side note, in the most recent rust-next branch, there are a few changes with IoCapable
so maybe worth rebasing at some point to get those changes. IoCapable isn't a marker trait
anymore so I get compile errors trying to rebase there.
> +#[pin_data]
> +struct As5600Priv<T> {
> + #[pin]
> + io_lock: Mutex<As5600HwState<T>>,
> + channels: KBox<[iio_chan_spec; 1]>,
> +}
> +
> +/// Encapsulates the I/O interface and its runtime health state.
> +///
> +/// This prevents operations on a known-dead bus (Circuit Breaker pattern).
> +struct As5600HwState<T> {
> + io: T,
> + state: DeviceState,
> +}
Could As5600Priv/HwState hold the As5600Io directly instead of a generic T?
As5600Priv was not generic over T in v2, and since As5600Io implements Io/IoCapable
and the sensor only uses the I2C bus it doesn't seem like it needs to be generic,
at least at the moment.
> +impl<T: Io + IoCapable<u8> + Unpin> IioDriver for As5600Priv<T> {
> + fn read_raw(&self, _chan: *const iio_chan_spec, mask: isize) -> Result<IioVal> {
> + match mask {
> + // IIO_CHAN_INFO_RAW — read the 12-bit raw angle value.
> + m if m == iio_chan_info_enum_IIO_CHAN_INFO_RAW as isize => {
Ideally in the future, the iio_chan_info_enum_* variants can be wrapped in an Rust
enum with an #[repr] attribute. At this stage, match isn't as useful as it could be
since you still need to call "if m == ...".
Sent using hkml (https://github.com/sjp38/hackermail)
next prev parent reply other threads:[~2026-05-29 5:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-24 13:28 [RFC PATCH v3 0/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-05-24 13:28 ` [RFC PATCH v3 1/4] i2c: rust: implement kernel::io::Io trait for I2cClient Muchamad Coirul Anwar
2026-05-28 15:25 ` Jonathan Cameron
2026-06-01 7:58 ` Muchamad Coirul Anwar
2026-06-01 9:05 ` Jonathan Cameron
2026-06-02 8:11 ` Muchamad Coirul Anwar
2026-06-02 11:59 ` Jonathan Cameron
2026-05-24 13:28 ` [RFC PATCH v3 2/4] rust: add minimal IIO subsystem abstractions Muchamad Coirul Anwar
2026-05-28 16:09 ` Jonathan Cameron
2026-06-01 8:30 ` Muchamad Coirul Anwar
2026-06-01 9:10 ` Jonathan Cameron
2026-05-24 13:28 ` [RFC PATCH v3 3/4] iio: position: add Rust driver for ams AS5600 Muchamad Coirul Anwar
2026-05-28 16:08 ` Jonathan Cameron
2026-06-01 11:11 ` Muchamad Coirul Anwar
2026-06-02 12:06 ` Jonathan Cameron
2026-06-03 8:52 ` Muchamad Coirul Anwar
2026-05-29 5:37 ` Brandon Saint-John [this message]
2026-06-01 11:33 ` Muchamad Coirul Anwar
2026-05-24 13:28 ` [RFC PATCH v3 4/4] iio: position: as5600: add Kconfig and Makefile entries Muchamad Coirul Anwar
2026-05-28 16:09 ` Jonathan Cameron
2026-06-01 8:00 ` Muchamad Coirul Anwar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260529053803.3256031-1-branstj@gmail.com \
--to=branstj@gmail.com \
--cc=igor.korotin.linux@gmail.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=muchamadcoirulanwar@gmail.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox