Skip to content

Commit d58dcfa

Browse files
lorenzgopherbot
authored andcommitted
unix: add GPIO constants and structs
This adds everything needed to use Linux's GPIO V2 UAPI, including the ioctls, structs and constants. As on some architectures char is signed by default and the UAPI doesn't make it unsigned explicitly a mkpost fixup is used to make the types more usable (by things like unix.ByteSliceToString). Change-Id: Icdb0ca4a225316ca5e948e21ab21789636297a57 Reviewed-on: https://go-review.googlesource.com/c/sys/+/752623 Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
1 parent 397d5f8 commit d58dcfa

18 files changed

Lines changed: 177 additions & 0 deletions

unix/linux/types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ struct termios2 {
117117
#include <linux/fs.h>
118118
#include <linux/fsverity.h>
119119
#include <linux/genetlink.h>
120+
#include <linux/gpio.h>
120121
#include <linux/hdreg.h>
121122
#include <linux/hidraw.h>
122123
#include <linux/icmp.h>
@@ -6297,3 +6298,34 @@ const (
62976298
MPOL_PREFERRED_MANY = C.MPOL_PREFERRED_MANY
62986299
MPOL_WEIGHTED_INTERLEAVE = C.MPOL_WEIGHTED_INTERLEAVE
62996300
)
6301+
6302+
// GPIO API
6303+
const (
6304+
GPIO_GET_CHIPINFO_IOCTL = C.GPIO_GET_CHIPINFO_IOCTL
6305+
GPIO_V2_GET_LINEINFO_IOCTL = C.GPIO_V2_GET_LINEINFO_IOCTL
6306+
GPIO_V2_GET_LINE_IOCTL = C.GPIO_V2_GET_LINE_IOCTL
6307+
GPIO_V2_LINE_GET_VALUES_IOCTL = C.GPIO_V2_LINE_GET_VALUES_IOCTL
6308+
GPIO_V2_LINE_SET_VALUES_IOCTL = C.GPIO_V2_LINE_SET_VALUES_IOCTL
6309+
GPIO_V2_GET_LINEINFO_WATCH_IOCTL = C.GPIO_V2_GET_LINEINFO_WATCH_IOCTL
6310+
GPIO_GET_LINEINFO_UNWATCH_IOCTL = C.GPIO_GET_LINEINFO_UNWATCH_IOCTL
6311+
)
6312+
const (
6313+
GPIO_V2_LINE_ATTR_ID_FLAGS = C.GPIO_V2_LINE_ATTR_ID_FLAGS
6314+
GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES = C.GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES
6315+
GPIO_V2_LINE_ATTR_ID_DEBOUNCE = C.GPIO_V2_LINE_ATTR_ID_DEBOUNCE
6316+
GPIO_V2_LINE_CHANGED_REQUESTED = C.GPIO_V2_LINE_CHANGED_REQUESTED
6317+
GPIO_V2_LINE_CHANGED_RELEASED = C.GPIO_V2_LINE_CHANGED_RELEASED
6318+
GPIO_V2_LINE_CHANGED_CONFIG = C.GPIO_V2_LINE_CHANGED_CONFIG
6319+
GPIO_V2_LINE_EVENT_RISING_EDGE = C.GPIO_V2_LINE_EVENT_RISING_EDGE
6320+
GPIO_V2_LINE_EVENT_FALLING_EDGE = C.GPIO_V2_LINE_EVENT_FALLING_EDGE
6321+
)
6322+
6323+
type GPIOChipInfo C.struct_gpiochip_info
6324+
type GPIOV2LineValues C.struct_gpio_v2_line_values
6325+
type GPIOV2LineAttribute C.struct_gpio_v2_line_attribute
6326+
type GPIOV2LineConfigAttribute C.struct_gpio_v2_line_config_attribute
6327+
type GPIOV2LineConfig C.struct_gpio_v2_line_config
6328+
type GPIOV2LineRequest C.struct_gpio_v2_line_request
6329+
type GPIOV2LineInfo C.struct_gpio_v2_line_info
6330+
type GPIOV2LineInfoChanged C.struct_gpio_v2_line_info_changed
6331+
type GPIOV2LineEvent C.struct_gpio_v2_line_event

unix/mkpost.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ func main() {
194194
b = bytes.Replace(b, s, newNames, 1)
195195
}
196196

197+
// Convert []int8 to []byte in GPIO structs
198+
convertGPIONames := regexp.MustCompile(`(Name|Label|Consumer)(\s+)\[(\d+)\]u?int8`)
199+
gpioTypes := regexp.MustCompile(`type GPIO\S+ struct {[^}]*}`)
200+
gpioStructs := gpioTypes.FindAll(b, -1)
201+
for _, s := range gpioStructs {
202+
newNames := convertGPIONames.ReplaceAll(s, []byte("$1$2[$3]byte"))
203+
b = bytes.Replace(b, s, newNames, 1)
204+
}
205+
197206
// Convert []int8 to []byte in ctl_info ioctl interface
198207
convertCtlInfoName := regexp.MustCompile(`(Name)(\s+)\[(\d+)\]int8`)
199208
ctlInfoType := regexp.MustCompile(`type CtlInfo struct {[^}]*}`)

unix/ztypes_linux.go

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_386.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_amd64.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_arm.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_arm64.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_loong64.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_mips.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_linux_mips64.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)