{"id":15626384,"url":"https://github.com/warthog618/go-gpiocdev","last_synced_at":"2025-04-08T09:12:26.154Z","repository":{"id":47496776,"uuid":"206445879","full_name":"warthog618/go-gpiocdev","owner":"warthog618","description":"A native Go library for accessing GPIO lines on Linux platforms using the GPIO character device","archived":false,"fork":false,"pushed_at":"2025-02-25T02:38:15.000Z","size":1828,"stargazers_count":454,"open_issues_count":1,"forks_count":42,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-01T08:38:52.928Z","etag":null,"topics":["go","golang","gpio","gpio-character-device","gpio-library","libgpiod","linux","linux-gpio","pin"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/warthog618.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-05T01:13:10.000Z","updated_at":"2025-03-31T13:17:19.000Z","dependencies_parsed_at":"2024-05-31T01:41:09.872Z","dependency_job_id":"066de76f-5d4a-44dc-9a8b-71595ea7dbd9","html_url":"https://github.com/warthog618/go-gpiocdev","commit_stats":{"total_commits":400,"total_committers":4,"mean_commits":100.0,"dds":0.007499999999999951,"last_synced_commit":"796bf41876678e01a94d99f761432a71310abce8"},"previous_names":["warthog618/gpiod"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fgo-gpiocdev","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fgo-gpiocdev/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fgo-gpiocdev/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/warthog618%2Fgo-gpiocdev/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/warthog618","download_url":"https://codeload.github.com/warthog618/go-gpiocdev/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809964,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","gpio","gpio-character-device","gpio-library","libgpiod","linux","linux-gpio","pin"],"created_at":"2024-10-03T10:12:15.542Z","updated_at":"2025-04-08T09:12:26.127Z","avatar_url":"https://github.com/warthog618.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2019 Kent Gibson \u003cwarthog618@gmail.com\u003e\n\nSPDX-License-Identifier: MIT\n--\u003e\n\n# gpiocdev\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/warthog618/go-gpiocdev/go.yml?logo=github\u0026branch=master)](https://github.com/warthog618/go-gpiocdev/actions/workflows/go.yml)\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/warthog618/go-gpiocdev)](https://pkg.go.dev/github.com/warthog618/go-gpiocdev)\n[![Go Report Card](https://goreportcard.com/badge/github.com/warthog618/go-gpiocdev)](https://goreportcard.com/report/github.com/warthog618/go-gpiocdev)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/warthog618/go-gpiocdev/blob/master/LICENSE)\n\nA native Go library for Linux GPIO.\n\n**gpiocdev** is a library for accessing GPIO pins/lines on Linux platforms using\nthe GPIO character device.\n\nThe goal of this library is to provide the Go equivalent of the C\n**[libgpiod](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/)**\nlibrary. The intent is not to mirror the **libgpiod** API but to provide the\nequivalent functionality.\n\n## Features\n\nSupports the following functionality per line and for collections of lines:\n\n- direction (input/output)\u003csup\u003e**1**\u003c/sup\u003e\n- write (active/inactive)\n- read (active/inactive)\n- active high/low (defaults to high)\n- output mode (push-pull/open-drain/open-source)\n- pull up/down\u003csup\u003e**2**\u003c/sup\u003e\n- watches and edge detection (rising/falling/both)\n- chip and line labels\n- debouncing input lines\u003csup\u003e**3**\u003c/sup\u003e\n- different configurations for lines within a collection\u003csup\u003e**3**\u003c/sup\u003e\n\n\u003csup\u003e**1**\u003c/sup\u003e Dynamically changing line direction without releasing the line\nrequires Linux 5.5 or later.\n\n\u003csup\u003e**2**\u003c/sup\u003e Requires Linux 5.5 or later.\n\n\u003csup\u003e**3**\u003c/sup\u003e Requires Linux 5.10 or later.\n\nAll library functions are safe to call from different goroutines.\n\n## Quick Start\n\nA simple piece of wire example that reads the value of an input line (pin 2) and\nwrites its value to an output line (pin 3):\n\n```go\nimport \"github.com/warthog618/go-gpiocdev\"\n\n...\n\nin, _ := gpiocdev.RequestLine(\"gpiochip0\", 2, gpiocdev.AsInput)\nval, _ := in.Value()\nout, _ := gpiocdev.RequestLine(\"gpiochip0\", 3, gpiocdev.AsOutput(val))\n\n...\n```\n\nError handling and releasing of resources omitted for brevity.\n\n## Usage\n\n```go\nimport \"github.com/warthog618/go-gpiocdev\"\n```\n\nError handling is omitted from the following examples for brevity.\n\n### Line Requests\n\nTo read or alter the value of a\n[line](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Line) it must first be\nrequested using [*gpiocdev.RequestLine*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#RequestLine):\n\n```go\nl, _ := gpiocdev.RequestLine(\"gpiochip0\", 4)   // in its existing state\n```\n\nor from the [*Chip*](#chip-initialization) object using\n[*Chip.RequestLine*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Chip.RequestLine):\n\n```go\nl, _ := c.RequestLine(4)                    // from a Chip object\n```\n\nThe offset parameter identifies the line on the chip, and is specific to the\nGPIO chip.  To improve readability, convenience mappings can be provided for\nspecific devices, such as the Raspberry Pi:\n\n```go\nl, _ := c.RequestLine(rpi.J8p7)             // using Raspberry Pi J8 mapping\n```\n\nThe initial configuration of the line can be set by providing line\n[configuration options](#configuration-options), as shown in this *AsOutput*\nexample:\n\n```go\nl, _ := gpiocdev.RequestLine(\"gpiochip0\", 4, gpiocdev.AsOutput(1))  // as an output line\n```\n\nMultiple lines from the same chip may be requested as a collection of\n[lines](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Lines) using\n[*gpiocdev.RequestLines*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#RequestLines)\n\n```go\nll, _ := gpiocdev.RequestLines(\"gpiochip0\", []int{0, 1, 2, 3}, gpiocdev.AsOutput(0, 0, 1, 1))\n```\n\n or from a Chip object using\n[*Chip.RequestLines*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Chip.RequestLines):\n\n```go\nll, _ := c.RequestLines([]int{0, 1, 2, 3}, gpiocdev.AsOutput(0, 0, 1, 1))\n```\n\nWhen no longer required, the line(s) should be closed to release resources:\n\n```go\nl.Close()\nll.Close()\n```\n\n### Line Values\n\nLines must be requsted using [*RequestLine*](#line-requests) before their\nvalues can be accessed.\n\n#### Read Input\n\nThe current line value can be read with the\n[*Value*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Line.Value)\nmethod:\n\n```go\nr, _ := l.Value()  // Read state from line (active / inactive)\n```\n\nFor collections of lines, the level of all lines is read simultaneously using\nthe [*Values*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Lines.SetValues)\nmethod:\n\n```go\nrr := []int{0, 0, 0, 0} // buffer to read into...\nll.Values(rr)           // Read the state of a collection of lines\n```\n\n#### Write Output\n\nFor lines requested as *output*, the current line value can be set with the\n[*SetValue*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Line.SetValue)\nmethod:\n\n```go\nl.SetValue(1)     // Set line active\nl.SetValue(0)     // Set line inactive\n```\n\nAlso refer to the [toggle_line_value](examples/toggle_line_value/main.go) example.\n\nFor collections of lines, all lines are set simultaneously using the\n[*SetValues*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Lines.SetValues)\nmethod:\n\n```go\nll.SetValues([]int{0, 1, 0, 1}) // Set a collection of lines\n```\n\n#### Edge Watches\n\nThe value of an input line can be watched and trigger calls to handler\nfunctions.\n\nThe watch can be on rising or falling edges, or both.\n\nThe events are passed to a handler function provided using the\n*WithEventHandler(eh)* option.  The handler function is passed a\n[*LineEvent*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#LineEvent), which\ncontains details of the edge event including the offset of the triggering line,\nthe time the edge was detected and the type of edge detected:\n\n```go\nfunc handler(evt gpiocdev.LineEvent) {\n  // handle edge event\n}\n\nl, _ = c.RequestLine(rpi.J8p7, gpiocdev.WithEventHandler(handler), gpiocdev.WithBothEdges)\n```\n\nTo maintain event ordering, the event handler is called serially from a\ngoroutine that reads the events from the kernel.  The event handler is expected\nto be short lived, and so should hand off any potentially blocking operations to\na separate goroutine.\n\nAn edge watch can be removed by closing the line:\n\n```go\nl.Close()\n```\n\nor by reconfiguring the requested lines to disable edge detection:\n\n```go\nl.Reconfigure(gpiocdev.WithoutEdges)\n```\n\nNote that the *Close* waits for the event handler to return and so must not be\ncalled from the event handler context - it should be called from a separate\ngoroutine.\n\nAlso see the [watch_line_value](examples/watch_line_value/main.go) example.\n\n### Line Configuration\n\nLine configuration is set via [options](#configuration-options) to\n*Chip.RequestLine(s)* and *Line.Reconfigure*.  These override any default which\nmay be set in *NewChip*.\n\nNote that configuration options applied to a collection of lines apply to all\nlines in the collection, unless they are applied to a subset of the requested\nlines using the *WithLines* option.\n\n#### Reconfiguration\n\nRequested lines may be reconfigured using the Reconfigure method:\n\n```go\nl.Reconfigure(gpiocdev.AsInput)            // set direction to Input\nll.Reconfigure(gpiocdev.AsOutput(1, 0))    // set direction to Output (and values to active and inactive)\n```\n\nThe *Line.Reconfigure* method accepts differential changes to the configuration\nfor the lines, so option categories not specified or overridden by the specified\nchanges will remain unchanged.\n\nThe *Line.Reconfigure* method requires Linux 5.5 or later.\n\n#### Complex Configurations\n\nIt is sometimes necessary for the configuration of lines within a request to\nhave slightly different configurations.  Line options may be applied to a subset\nof requested lines using the *WithLines(offsets, options)* option.\n\nThe following example requests a set of output lines and sets some of the lines\nin the request to active low:\n\n```go\nll, _ = c.RequestLines([]int{0, 1, 2, 3}, gpiocdev.AsOutput(0, 0, 1, 1),\n    gpiocdev.WithLines([]int{0, 3}, gpiocdev.AsActiveLow),\n    gpiocdev.AsOpenDrain)\n```\n\nThe configuration of the subset of lines inherits the configuration of the\nrequest at the point the *WithLines* is invoked.  Subsequent changes to the\nrequest configuration do not alter the configuration of the subset - in the\nexample above, lines 0 and 3 will not be configured as open-drain.\n\nOnce a line's configuration has branched from the request configuration it can\nonly be altered with *WithLines* options:\n\n```go\nll.Reconfigure(gpiocdev.WithLines([]int{0}, gpiocdev.AsActiveHigh))\n```\n\nor reset to the request configuration using the *Defaulted* option:\n\n```go\nll.Reconfigure(gpiocdev.WithLines([]int{3}, gpiocdev.Defaulted))\n```\n\nComplex configurations require Linux 5.10 or later.\n\n### Chip Initialization\n\nThe Chip object is used to discover details about avaialble lines and can be used\nto request lines from a GPIO chip.\n\nA Chip object is constructed using the\n[*NewChip*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#NewChip) function.\n\n```go\nc, _ := gpiocdev.NewChip(\"gpiochip0\")\n```\n\nThe parameter is the chip name, which corresponds to the name of the device in\nthe **/dev** directory, so in this example **/dev/gpiochip0**.\n\nThe list of currently available GPIO chips is returned by the *Chips* function:\n\n```go\ncc := gpiocdev.Chips()\n```\n\nDefault attributes for Lines requested from the Chip can be set via\n[configuration options](#configuration-options) to\n[*NewChip*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#NewChip).\n\n```go\nc, _ := gpiocdev.NewChip(\"gpiochip0\", gpiocdev.WithConsumer(\"myapp\"))\n```\n\nIn this example the consumer label is defaulted to \"myapp\".\n\nWhen no longer required, the chip should be closed to release resources:\n\n```go\nc.Close()\n```\n\nClosing a chip does not close or otherwise alter the state of any lines\nrequested from the chip.\n\n### Line Info\n\n[Info](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#LineInfo) about a line can\nbe read at any time from the chip using the\n[*LineInfo*](https://pkg.go.dev/github.com/warthog618/go-gpiocdev#Chip.LineInfo)\nmethod:\n\n```go\ninf, _ := c.LineInfo(4)\ninf, _ := c.LineInfo(rpi.J8p7) // Using Raspberry Pi J8 mapping\n```\n\nNote that the line info does not include the value.  The line must be requested\nfrom the chip to access the value.\n\nOnce requested, the line info can also be read from the line:\n\n```go\ninf, _ := l.Info()\ninfs, _ := ll.Info()\n```\n\n#### Info Watches\n\nChanges to the line info can be monitored by adding an info watch for the line:\n\n```go\nfunc infoChangeHandler( evt gpiocdev.LineInfoChangeEvent) {\n    // handle change in line info\n}\n\ninf, _ := c.WatchLineInfo(4, infoChangeHandler)\n```\n\nNote that the info watch does not monitor the line value (active or inactive)\nonly its configuration.  Refer to [Edge Watches](#edge-watches) for monitoring\nline value.\n\nAn info watch can be cancelled by unwatching:\n\n```go\nc.UnwatchLineInfo(4)\n```\n\nor by closing the chip.\n\n#### Categories\n\nMost line configuration options belong to one of the following categories:\n\n- Active Level\n- Direction\n- Bias\n- Drive\n- Debounce\n- Edge Detection\n- Event Clock\n\nOnly one option from each category may be applied.  If multiple options from a\ncategory are applied then all but the last are ignored.\n\n##### Active Level\n\nThe values used throughout the API for line values are the logical value, which\nis 0 for inactive and 1 for active. The physical value considered active can be\ncontrolled using the *AsActiveHigh* and *AsActiveLow* options:\n\n```go\nl, _ := c.RequestLine(4, gpiocdev.AsActiveLow) // during request\nl.Reconfigure(gpiocdev.AsActiveHigh)           // once requested\n```\n\nLines are typically active high by default.\n\n##### Direction\n\nThe line direction can be controlled using the *AsInput* and *AsOutput* options:\n\n```go\nl, _ := c.RequestLine(4, gpiocdev.AsInput) // during request\nl.Reconfigure(gpiocdev.AsInput)            // set direction to Input\nl.Reconfigure(gpiocdev.AsOutput(0))        // set direction to Output (and value to inactive)\n```\n\n##### Bias\n\nThe bias options control the pull up/down state of the line:\n\n```go\nl, _ = c.RequestLine(4, gpiocdev.WithPullUp) // during request\nl.Reconfigure(gpiocdev.WithBiasDisabled)     // once requested\n```\n\nThe bias options require Linux 5.5 or later.\n\n##### Drive\n\nThe drive options control how an output line is driven when active and inactive:\n\n```go\nl,_ := c.RequestLine(4, gpiocdev.AsOpenDrain) // during request\nl.Reconfigure(gpiocdev.AsOpenSource)          // once requested\n```\n\nThe default drive for output lines is push-pull, which actively drives the line\nin both directions.\n\n##### Debounce\n\nInput lines may be debounced using the *WithDebounce* option.  The debouncing will\nbe performed by the underlying hardware, if supported, else by the Linux\nkernel.\n\n```go\nperiod := 10 * time.Millisecond\nl, _ = c.RequestLine(4, gpiocdev.WithDebounce(period))// during request\nl.Reconfigure(gpiocdev.WithDebounce(period))         // once requested\n```\n\nThe WithDebounce option requires Linux 5.10 or later.\n\n##### Edge Detection\n\nThe edge options control which edges on input lines will generate edge events.\nEdge events are passed to the event handler specified in the *WithEventHandler(eh)*\noption.\n\nBy default edge detection is not enabled on requested lines.\n\nRefer to [Edge Watches](#edge-watches) for examples of the edge detection options.\n\n##### Event Clock\n\nThe event clock options control the source clock used to timestamp edge events.\nThis is only useful for Linux kernels 5.11 and later - prior to that the clock\nsource is fixed.\n\nThe event clock source used by the kernel has changed over time as follows:\n\nKernel Version | Clock source\n--- | ---\npre-5.7 | CLOCK_REALTIME\n5.7 - 5.10 | CLOCK_MONOTONIC\n5.11 and later | configurable (defaults to CLOCK_MONOTONIC)\n\nDetermining which clock the edge event timestamps contain is currently left as\nan exercise for the user.\n\n#### Configuration Options\n\nThe available configuration options are:\n\nOption | Category | Description\n---|---|---\n*WithConsumer*\u003csup\u003e**1**\u003c/sup\u003e | Info | Set the consumer label for the lines\n*AsActiveLow* | Level | Treat a low physical line value as active\n*AsActiveHigh* | Level | Treat a high physical line value as active (**default**)\n*AsInput* | Direction | Request lines as input\n*AsIs*\u003csup\u003e**2**\u003c/sup\u003e | Direction | Request lines in their current input/output state (**default**)\n*AsOutput(\\\u003cvalues\\\u003e...)*\u003csup\u003e**3**\u003c/sup\u003e | Direction | Request lines as output with the provided values\n*AsPushPull* | Drive | Request output lines drive both high and low (**default**)\n*AsOpenDrain* | Drive | Request lines as open drain outputs\n*AsOpenSource* | Drive | Request lines as open source outputs\n*WithEventHandler(eh)\u003csup\u003e**1**\u003c/sup\u003e* |  | Send edge events detected on requested lines to the provided handler\n*WithEventBufferSize(num)\u003csup\u003e**1**,**5**\u003c/sup\u003e* |  | Suggest the minimum number of events that can be stored in the kernel event buffer for the requested lines\n*WithFallingEdge* | Edge Detection\u003csup\u003e**3**\u003c/sup\u003e | Request lines with falling edge detection\n*WithRisingEdge* | Edge Detection\u003csup\u003e**3**\u003c/sup\u003e | Request lines with rising edge detection\n*WithBothEdges* | Edge Detection\u003csup\u003e**3**\u003c/sup\u003e | Request lines with rising and falling edge detection\n*WithoutEdges*\u003csup\u003e**5**\u003c/sup\u003e | Edge Detection\u003csup\u003e**3**\u003c/sup\u003e | Request lines with edge detection disabled (**default**)\n*WithBiasAsIs* | Bias\u003csup\u003e**4**\u003c/sup\u003e | Request the lines have their bias setting left unaltered (**default**)\n*WithBiasDisabled* | Bias\u003csup\u003e**4**\u003c/sup\u003e | Request the lines have internal bias disabled\n*WithPullDown* | Bias\u003csup\u003e**4**\u003c/sup\u003e | Request the lines have internal pull-down enabled\n*WithPullUp* | Bias\u003csup\u003e**4**\u003c/sup\u003e | Request the lines have internal pull-up enabled\n*WithDebounce(period)*\u003csup\u003e**5**\u003c/sup\u003e | Debounce | Request the lines be debounced with the provided period\n*WithMonotonicEventClock* | Event Clock | Request the timestamp in edge events use the monotonic clock (**default**)\n*WithRealtimeEventClock*\u003csup\u003e**6**\u003c/sup\u003e | Event Clock | Request the timestamp in edge events use the realtime clock\n*WithLines(offsets, options...)*\u003csup\u003e**3**,**5**\u003c/sup\u003e |  | Specify configuration options for a subset of lines in a request\n*Defaulted*\u003csup\u003e**5**\u003c/sup\u003e |  | Reset the configuration for a request to the default configuration, or the configuration of a particular line in a request to the default for that request\n\nThe options described as **default** are generally not required, except to\noverride other options earlier in a chain of configuration options.\n\n\u003csup\u003e**1**\u003c/sup\u003e Can be applied to either *NewChip* or *Chip.RequestLine*, but\ncannot be used with *Line.Reconfigure*.\n\n\u003csup\u003e**2**\u003c/sup\u003e Can be applied to *Chip.RequestLine*, but cannot be used\nwith *NewChip* or *Line.Reconfigure*.\n\n\u003csup\u003e**3**\u003c/sup\u003e Can be applied to either *Chip.RequestLine* or\n*Line.Reconfigure*, but cannot be used with *NewChip*.\n\n\u003csup\u003e**4**\u003c/sup\u003e Requires Linux 5.5 or later.\n\n\u003csup\u003e**5**\u003c/sup\u003e Requires Linux 5.10 or later.\n\n\u003csup\u003e**6**\u003c/sup\u003e Requires Linux 5.11 or later.\n\n## Installation\n\nOn Linux:\n\n```shell\ngo get github.com/warthog618/go-gpiocdev\n```\n\nFor other platforms, where you intend to cross-compile for Linux, don't attempt\nto compile the package when it is installed:\n\n```shell\ngo get -d github.com/warthog618/go-gpiocdev\n```\n\n## Tools\n\nA companion package, **[gpiocdev-cli](https://github.com/warthog618/go-gpiocdev-cli)** provides a command line tool that allows\nmanual or scripted manipulation of GPIO lines.  This utility combines the Go\nequivalent of all the **libgpiod** command line tools into a single tool.\n\n## Tests\n\nThe library is fully tested, other than some error cases and sanity checks that\nare difficult to trigger.\n\nThe tests require a kernel release 5.19 or later to run, built with\n**CONFIG_GPIO_SIM** set or as a module.\n\nThe tests must be run as root, to allow contruction of **gpio-sims**.\nThey can still be built as an unprivileged user, e.g.\n\n```shell\n$ go test -c\n```\n\nbut must be run as root.\n\nThe tests can also be cross-compiled for other platforms.\ne.g. build tests for a Raspberry Pi using:\n\n```shell\n$ GOOS=linux GOARCH=arm GOARM=6 go test -c\n```\n\nLater Pis can also use ARM7 (GOARM=7).\n\n### Benchmarks\n\nThe tests include benchmarks on reads, writes, bulk reads and writes,  and\ninterrupt latency.\n\nThese are the results from a Raspberry Pi Zero W running Linux 6.4 and built\nwith go1.20.6:\n\n```shell\n$ ./go-gpiocdev.test -test.bench=.*\ngoos: linux\ngoarch: arm\npkg: github.com/warthog618/go-gpiocdev\nBenchmarkChipNewClose     \t     248\t   4381075 ns/op\nBenchmarkLineInfo         \t   24651\t     47278 ns/op\nBenchmarkLineReconfigure  \t   20312\t     55273 ns/op\nBenchmarkLineValue        \t   71774\t     14933 ns/op\nBenchmarkLinesValues      \t   54920\t     24659 ns/op\nBenchmarkLineSetValue     \t   73359\t     16501 ns/op\nBenchmarkLinesSetValues   \t   53557\t     21056 ns/op\nBenchmarkInterruptLatency \t     105\t  10407929 ns/op\nPASS\n```\n\nThe latency benchmark is no longer representative as the measurement now depends\non how quickly **gpio-sim** can toggle lines, and that is considerably slower\nthan how quickly **gpiocdev** responds.  For comparison, the same test using\nlooped Raspberry Pi lines produced a result of ~640μsec on the same platform.\n\nAnd on a Raspberry Pi 4 running Linux 6.4 (32bit kernel) and built with go1.20.6:\n\n```shell\n$ ./go-gpiocdev.test -test.bench=.*\ngoos: linux\ngoarch: arm\npkg: github.com/warthog618/go-gpiocdev\nBenchmarkChipNewClose-4       \t    9727\t    118291 ns/op\nBenchmarkLineInfo-4           \t  185316\t      6104 ns/op\nBenchmarkLineReconfigure-4    \t  364795\t      3205 ns/op\nBenchmarkLineValue-4          \t 1072785\t      1061 ns/op\nBenchmarkLinesValues-4        \t  816200\t      1428 ns/op\nBenchmarkLineSetValue-4       \t 1015972\t      1150 ns/op\nBenchmarkLinesSetValues-4     \t  715154\t      1717 ns/op\nBenchmarkInterruptLatency-4   \t   18439\t     61145 ns/op\nPASS\n```\n\n## Prerequisites\n\nThe library targets Linux with support for the GPIO character device API.  That\ngenerally means that **/dev/gpiochip0** exists.\n\nThe caller must have access to the character device - typically\n**/dev/gpiochip0**.  That is generally root unless you have changed the\npermissions of that device.\n\nThe Bias line options and the Line.Reconfigure method both require Linux 5.5 or\nlater.\n\nDebounce and other uAPI v2 features require Linux 5.10 or later.\n\nThe requirements for each [configuration option](#configuration-options) are\nnoted in that section.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarthog618%2Fgo-gpiocdev","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwarthog618%2Fgo-gpiocdev","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwarthog618%2Fgo-gpiocdev/lists"}