{"id":13710826,"url":"https://github.com/Elara6331/zig-gpio","last_synced_at":"2025-05-06T20:31:03.858Z","repository":{"id":212011021,"uuid":"730490358","full_name":"Elara6331/zig-gpio","owner":"Elara6331","description":"A Zig library for controlling GPIO lines on Linux systems","archived":false,"fork":false,"pushed_at":"2024-08-19T02:02:04.000Z","size":40,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-19T19:09:14.936Z","etag":null,"topics":["gpio","gpiochip","linux","zig"],"latest_commit_sha":null,"homepage":"https://gitea.elara.ws/Elara6331/zig-gpio","language":"Zig","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/Elara6331.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"liberapay":"Elara6331"}},"created_at":"2023-12-12T03:21:42.000Z","updated_at":"2024-08-19T13:52:48.000Z","dependencies_parsed_at":"2023-12-25T21:23:14.250Z","dependency_job_id":"5cbeadf0-c911-4453-af02-5dc10842557a","html_url":"https://github.com/Elara6331/zig-gpio","commit_stats":null,"previous_names":["elara6331/zig-gpio"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elara6331%2Fzig-gpio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elara6331%2Fzig-gpio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elara6331%2Fzig-gpio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Elara6331%2Fzig-gpio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Elara6331","download_url":"https://codeload.github.com/Elara6331/zig-gpio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224528244,"owners_count":17326322,"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":["gpio","gpiochip","linux","zig"],"created_at":"2024-08-02T23:01:01.182Z","updated_at":"2024-11-13T21:31:00.479Z","avatar_url":"https://github.com/Elara6331.png","language":"Zig","readme":"# zig-gpio\n\n**zig-gpio** is a Zig library for controlling GPIO lines on Linux systems\n\nThis library can be used to access GPIO on devices such as [Raspberry Pis](https://www.raspberrypi.com/) or the [Milk-V Duo](https://milkv.io/duo) (which is the board I created it for and tested it with).\n\nThis is my first Zig project, so I'm open to any suggestions!\n\n_There's a companion article available on my website: https://www.elara.ws/articles/milkv-duo._\n\n## Compatibility\n\n**zig-gpio** uses the v2 character device API, which means it will work on any Linux system running kernel 5.10 or above. All you need to do is find out which `gpiochip` device controls which pin and what the offsets are, which you can do by either finding documentation online, or using the `gpiodetect` and `gpioinfo` tools from this repo or from `libgpiod`.\n\n## Commands\n\n**zig-gpio** provides replacements for some of the `libgpiod` tools, such as `gpiodetect` and `gpioinfo`. You can build all of them using `zig build commands` or specific ones using `zig build \u003ccommand\u003e` (for example: `zig build gpiodetect`).\n\n## Try it yourself!\n\nHere's an example of a really simple program that requests pin 22 from `gpiochip2` and makes it blink at a 1 second interval. That pin offset is the LED of a Milk-V Duo board, so if you're using a different board, make sure to change it.\n\n```zig\nconst std = @import(\"std\");\nconst gpio = @import(\"gpio\");\n\npub fn main() !void {\n    var chip = try gpio.getChip(\"/dev/gpiochip2\");\n    defer chip.close();\n    std.debug.print(\"Chip Name: {s}\\n\", .{chip.name});\n\n    var line = try chip.requestLine(22, .{ .output = true });\n    defer line.close();\n    while (true) {\n        try line.setHigh();\n        std.time.sleep(std.time.ns_per_s);\n        try line.setLow();\n        std.time.sleep(std.time.ns_per_s);\n    }\n}\n```\n\nFor more examples, see the [_examples](_examples) directory. You can build all the examples using the `zig build examples` command.\n\n## Using zig-gpio in your project\n\nIf you don't have a zig project already, you can create one by running `zig init-exe` in a new folder.\n\nTo add `zig-gpio` as a dependency, there are two steps:\n\n1. Add `zig-gpio` to your `build.zig.zon` file\n2. Add `zig-gpio` to your `build.zig` file\n\nIf you don't have a `build.zig.zon` file, create one. If you do, just add `zig-gpio` as a dependency. Here's what it should look like:\n\n```zig\n.{\n    .name = \"my_project\",\n    .version = \"0.0.1\",\n\n    .dependencies = .{\n        .gpio = .{\n            .url = \"https://gitea.elara.ws/Elara6331/zig-gpio/archive/v0.0.2.tar.gz\",\n            .hash = \"1220e3af3194d1154217423d60124ae3a46537c2253dbfb8057e9b550526d2885df1\",\n        }\n    }\n}\n```\n\nThen, in your `build.zig` file, add the following before `b.installArtifact(exe)`:\n\n```zig\nconst gpio = b.dependency(\"gpio\", .{\n    .target = target,\n    .optimize = optimize,\n});\nexe.root_module.addImport(\"gpio\", gpio.module(\"gpio\"));\n```\n\nAnd that's it! You should now be able to use `zig-gpio` via `@import(\"gpio\");`\n","funding_links":["https://liberapay.com/Elara6331"],"categories":["Systems Programming"],"sub_categories":["Embedded Development"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElara6331%2Fzig-gpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FElara6331%2Fzig-gpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FElara6331%2Fzig-gpio/lists"}