All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	linux-gpio@vger.kernel.org,
	"Miguel Ojeda" <miguel.ojeda.sandonis@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	stratos-dev@op-lists.linaro.org,
	"Gerard Ryan" <g.m0n3y.2503@gmail.com>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	y86-dev <y86-dev@protonmail.com>
Subject: Re: [libgpiod v2][PATCH V8 5/9] bindings: rust: Add libgpiod crate
Date: Wed, 2 Nov 2022 21:14:51 +0800	[thread overview]
Message-ID: <Y2JtSw+laG5lgCUl@sol> (raw)
In-Reply-To: <08d4095c314caf50430c2eaa733d925122242b12.1667215380.git.viresh.kumar@linaro.org>

On Mon, Oct 31, 2022 at 05:17:13PM +0530, Viresh Kumar wrote:
> Add rust wrapper crate, around the libpiod-sys crate added earlier, to
> provide a convenient interface for the users.
> 
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  bindings/rust/Cargo.toml                     |   1 +
>  bindings/rust/libgpiod/Cargo.toml            |  20 +
>  bindings/rust/libgpiod/src/chip.rs           | 317 ++++++++++++
>  bindings/rust/libgpiod/src/edge_event.rs     | 128 +++++
>  bindings/rust/libgpiod/src/event_buffer.rs   | 102 ++++
>  bindings/rust/libgpiod/src/info_event.rs     |  69 +++
>  bindings/rust/libgpiod/src/lib.rs            | 478 +++++++++++++++++++
>  bindings/rust/libgpiod/src/line_config.rs    | 135 ++++++
>  bindings/rust/libgpiod/src/line_info.rs      | 162 +++++++
>  bindings/rust/libgpiod/src/line_request.rs   | 224 +++++++++
>  bindings/rust/libgpiod/src/line_settings.rs  | 297 ++++++++++++
>  bindings/rust/libgpiod/src/request_config.rs |  95 ++++
>  12 files changed, 2028 insertions(+)
>  create mode 100644 bindings/rust/libgpiod/Cargo.toml
>  create mode 100644 bindings/rust/libgpiod/src/chip.rs
>  create mode 100644 bindings/rust/libgpiod/src/edge_event.rs
>  create mode 100644 bindings/rust/libgpiod/src/event_buffer.rs
>  create mode 100644 bindings/rust/libgpiod/src/info_event.rs
>  create mode 100644 bindings/rust/libgpiod/src/lib.rs
>  create mode 100644 bindings/rust/libgpiod/src/line_config.rs
>  create mode 100644 bindings/rust/libgpiod/src/line_info.rs
>  create mode 100644 bindings/rust/libgpiod/src/line_request.rs
>  create mode 100644 bindings/rust/libgpiod/src/line_settings.rs
>  create mode 100644 bindings/rust/libgpiod/src/request_config.rs
> 
> diff --git a/bindings/rust/Cargo.toml b/bindings/rust/Cargo.toml
> index b9eea6b3a5ea..4fdf4e06ff90 100644
> --- a/bindings/rust/Cargo.toml
> +++ b/bindings/rust/Cargo.toml
> @@ -2,5 +2,6 @@
>  
>  members = [
>      "gpiosim",
> +    "libgpiod",
>      "libgpiod-sys"
>  ]
> diff --git a/bindings/rust/libgpiod/Cargo.toml b/bindings/rust/libgpiod/Cargo.toml
> new file mode 100644
> index 000000000000..ef52fdc198d7
> --- /dev/null
> +++ b/bindings/rust/libgpiod/Cargo.toml
> @@ -0,0 +1,20 @@
> +[package]
> +name = "libgpiod"
> +version = "0.1.0"
> +authors = ["Viresh Kumar <viresh.kumar@linaro.org>"]
> +description = "libgpiod wrappers"
> +repository = "https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git"
> +categories = ["command-line-utilities", "os::linux-apis"]

The command line utilities being the examples?
That is a bit of a stretch.

How about "api-bindings", and maybe "hardware-support" and "embedded"?

> +rust-version = "1.56"
> +keywords = ["libgpiod", "gpio"]
> +license = "Apache-2.0 OR BSD-3-Clause"
> +edition = "2021"
> +
> +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
> +

That link is put there by cargo for YOU.
When you are satisfied with your keys you can delete it.

< --8<-- >

> +    /// Get the file descriptor associated with the chip.
> +    ///
> +    /// The returned file descriptor must not be closed by the caller, else other methods for the
> +    /// `struct Chip` may fail.
> +    pub fn fd(&self) -> Result<u32> {
> +        // SAFETY: `gpiod_chip` is guaranteed to be valid here.
> +        let fd = unsafe { gpiod::gpiod_chip_get_fd(self.ichip.chip) };
> +
> +        if fd < 0 {
> +            Err(Error::OperationFailed(
> +                OperationType::ChipGetFd,
> +                errno::errno(),
> +            ))
> +        } else {
> +            Ok(fd as u32)
> +        }
> +    }

Impl AsRawFd, as per Request.

< --8<-- >

> +/// Line info
> +///
> +/// Exposes functions for retrieving kernel information about both requested and
> +/// free lines.  Line info object contains an immutable snapshot of a line's status.
> +///
> +/// The line info contains all the publicly available information about a
> +/// line, which does not include the line value.  The line must be requested
> +/// to access the line value.
> +
> +#[derive(Debug, Eq, PartialEq)]
> +pub struct Info {
> +    info: *mut gpiod::gpiod_line_info,
> +    from_event: bool,
> +}

The "from_event" flag indicates if the info needs to be freed, or not,
when the Info is dropped, so call it something that indicates that, like
"contained".


Admittedly I'm only skimming this one compared to my v7 review,
but only minor knits that could always be picked up later.

Cheers,
Kent.

  reply	other threads:[~2022-11-02 13:15 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31 11:47 [libgpiod v2][PATCH V8 0/9] bindings: rust: Add libgpiod-sys rust crate Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 1/9] " Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 2/9] bindings: rust: Add pre generated bindings for libgpiod-sys Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 3/9] bindings: rust: Add gpiosim crate Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 4/9] bindings: rust: Add pre generated bindings for gpiosim Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 5/9] bindings: rust: Add libgpiod crate Viresh Kumar
2022-11-02 13:14   ` Kent Gibson [this message]
2022-11-04  5:57     ` Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 6/9] bindings: rust: Add examples to " Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 7/9] bindings: rust: Add tests for " Viresh Kumar
2022-11-02 13:15   ` Kent Gibson
2022-11-04  5:52     ` Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 8/9] bindings: rust: Integrate building of bindings with make Viresh Kumar
2022-10-31 11:47 ` [libgpiod v2][PATCH V8 9/9] bindings: rust: Implement iterator for edge events Viresh Kumar
2022-11-02 13:16   ` Kent Gibson
2022-11-04 11:31     ` Viresh Kumar
2022-11-04 12:33       ` Kent Gibson
2022-11-05  1:20         ` Kent Gibson
2022-11-07  6:13         ` Viresh Kumar

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=Y2JtSw+laG5lgCUl@sol \
    --to=warthog618@gmail.com \
    --cc=alex.bennee@linaro.org \
    --cc=alex.gaynor@gmail.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=g.m0n3y.2503@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=miguel.ojeda.sandonis@gmail.com \
    --cc=stratos-dev@op-lists.linaro.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    --cc=wedsonaf@gmail.com \
    --cc=y86-dev@protonmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.