From c21ba5478475fbe27d9ca2bd4b4ccf9dabae4631 Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Sat, 11 Sep 2021 20:52:44 +0200 Subject: [PATCH] chore: bump periph.io dependencies --- Dockerfile | 4 +-- Makefile | 6 ++-- build-docker.sh | 0 go.mod | 2 +- go.sum | 3 +- led/led.go | 8 ++--- vendor/modules.txt | 2 +- vendor/periph.io/x/d2xx/README.md | 34 ++++++++++++++++++-- vendor/periph.io/x/d2xx/d2xx.go | 19 +++++++++-- vendor/periph.io/x/d2xx/d2xx_darwin_amd64.go | 1 + vendor/periph.io/x/d2xx/d2xx_linux_amd64.go | 3 +- vendor/periph.io/x/d2xx/d2xx_linux_arm.go | 3 +- vendor/periph.io/x/d2xx/d2xx_linux_arm64.go | 13 ++++++++ vendor/periph.io/x/d2xx/d2xx_posix.go | 2 ++ vendor/periph.io/x/d2xx/d2xx_posix_no_cgo.go | 4 +-- vendor/periph.io/x/d2xx/d2xx_posix_other.go | 3 ++ vendor/periph.io/x/d2xx/d2xx_windows.go | 18 ++++++++--- vendor/periph.io/x/d2xx/doc.go | 7 ++-- vendor/periph.io/x/d2xx/test.sh | 32 ++++++++++++++---- 19 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 build-docker.sh create mode 100644 vendor/periph.io/x/d2xx/d2xx_linux_arm64.go diff --git a/Dockerfile b/Dockerfile index 644a21b..246353b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM golang:1.17-alpine AS builder +FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.17-alpine AS builder ARG TARGETPLATFORM ARG BUILDPLATFORM @@ -9,7 +9,7 @@ ADD . . RUN GOOS=$(echo $TARGETPLATFORM | cut -f1 -d/) && \ GOARCH=$(echo $TARGETPLATFORM | cut -f2 -d/) && \ GOARM=$(echo $TARGETPLATFORM | cut -f3 -d/ | sed "s/v//" ) && \ - CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor -tags netgo ./cmd/rc-led/ + CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor -tags netgo,no_d2xx ./cmd/rc-led/ #ARG GOOS=linux diff --git a/Makefile b/Makefile index 10260d8..4720222 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,11 @@ .PHONY: test docker -DOCKER_IMG = cyrilix/robocar-led +DOCKER_IMG = docker.io/cyrilix/robocar-led + +rc-led: binary-amd64 test: - go test -race -mod vendor ./cmd/rc-led ./part ./led + go test -race -tags no_d2xx ./cmd/rc-led ./part ./led docker: docker buildx build . --platform linux/arm/7,linux/arm64,linux/amd64 -t ${DOCKER_IMG} --push diff --git a/build-docker.sh b/build-docker.sh new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod index f817dab..258b066 100644 --- a/go.mod +++ b/go.mod @@ -18,5 +18,5 @@ require ( golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect google.golang.org/protobuf v1.26.0 // indirect - periph.io/x/d2xx v0.0.1 // indirect + periph.io/x/d2xx v0.0.3 // indirect ) diff --git a/go.sum b/go.sum index 028b875..b74377c 100644 --- a/go.sum +++ b/go.sum @@ -126,7 +126,8 @@ gotest.tools v0.0.0-20181223230014-1083505acf35/go.mod h1:R//lfYlUuTOTfblYI3lGoA honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= periph.io/x/conn/v3 v3.6.8 h1:fnNSwSoKPzpoLOSxml70EInaP6YrrqcucP3KDfNxpmU= periph.io/x/conn/v3 v3.6.8/go.mod h1:3OD27w9YVa5DS97VsUxsPGzD9Qrm5Ny7cF5b6xMMIWg= -periph.io/x/d2xx v0.0.1 h1:7iCO/aVK6k9GSZ45DcpMU8sOOcVLCqO/cheSm7nMUG0= periph.io/x/d2xx v0.0.1/go.mod h1:38Euaaj+s6l0faIRHh32a+PrjXvxFTFkPBEQI0TKg34= +periph.io/x/d2xx v0.0.3 h1:BE8XcIdxabu9ZzAr1UXxSz88T9Txki6Xyo8aJ1qZvks= +periph.io/x/d2xx v0.0.3/go.mod h1:38Euaaj+s6l0faIRHh32a+PrjXvxFTFkPBEQI0TKg34= periph.io/x/host/v3 v3.7.0 h1:9CP/j0FcJmR+PRHlNzAmhV6Mt3GXoWnPmRhknJlQhnE= periph.io/x/host/v3 v3.7.0/go.mod h1:okb5m0yUYLTM/dnMYWMBX47w4owTzyCPLpZUQb35nhs= diff --git a/led/led.go b/led/led.go index 2c65323..176d5c3 100644 --- a/led/led.go +++ b/led/led.go @@ -4,7 +4,7 @@ import ( log "github.com/sirupsen/logrus" "periph.io/x/conn/v3/gpio" "periph.io/x/host/v3" - "periph.io/x/host/v3/bcm283x" + "periph.io/x/host/v3/rpi" "sync" "time" ) @@ -19,9 +19,9 @@ func init() { func New() *PiColorLed { led := PiColorLed{ - pinRed: bcm283x.GPIO23, - pinGreen: bcm283x.GPIO24, - pinBlue: bcm283x.GPIO25, + pinRed: rpi.P1_16, + pinGreen: rpi.P1_18, + pinBlue: rpi.P1_22, redValue: 0, greenValue: 0, blueValue: 0, diff --git a/vendor/modules.txt b/vendor/modules.txt index fb32fee..ad65704 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -75,7 +75,7 @@ periph.io/x/conn/v3/pin periph.io/x/conn/v3/pin/pinreg periph.io/x/conn/v3/spi periph.io/x/conn/v3/spi/spireg -# periph.io/x/d2xx v0.0.1 +# periph.io/x/d2xx v0.0.3 ## explicit; go 1.13 periph.io/x/d2xx # periph.io/x/host/v3 v3.7.0 diff --git a/vendor/periph.io/x/d2xx/README.md b/vendor/periph.io/x/d2xx/README.md index 7a3f660..d88b512 100644 --- a/vendor/periph.io/x/d2xx/README.md +++ b/vendor/periph.io/x/d2xx/README.md @@ -3,9 +3,6 @@ Package d2xx is a thin Go wrapper for the Future Technology "D2XX" driver at https://ftdichip.com/drivers/d2xx-drivers/. -See https://periph.io/device/ftdi/ for more details, and how to configure -the host to be able to use this driver. - This package is not Go idiomatic. You will want to use https://periph.io/x/host/v3/ftdi (or later) instead. @@ -14,3 +11,34 @@ But if you really want, here it goes: This Go package includes third party software. See [third_party/README.md](third_party/README.md). + +## Configuration + +See https://periph.io/device/ftdi/ to configure the host to be able to use this +driver. + +## Availability + +On darwin_amd64, linux_amd64 linux_arm (v6, v7 compatible) and linux_arm64 (v8), +cgo is required. If cgo is disabled (via `CGO_ENABLED=0`), all functions in this +driver return error [NoCGO](https://periph.io/x/d2xx#NoCGO). + +On Windows, cgo is not required. If the dynamic library is not found at runtime, +[Missing](https://periph.io/x/d2xx#Missing) is returned. + +## bcm2385 + +On linux_arm (v6), hard-float is required. For cross compilation, this +means arm-linux-gnueabihf-gcc is preferred to arm-linux-gnueabi-gcc. Using +hardfloat causes a segfault on Raspberry Pi 1, Zero and Zero Wireless. It is +recommended to disable this driver if targeting these hosts, see below. + +## Disabling + +To disable this driver, build with tag `no_d2xx`, e.g. + +``` +go install -tags no_d2xx periph.io/x/cmd/gpio-list@latest +``` + +This will behave has if cgo was disabled, even on Windows. diff --git a/vendor/periph.io/x/d2xx/d2xx.go b/vendor/periph.io/x/d2xx/d2xx.go index 79890c3..c004aca 100644 --- a/vendor/periph.io/x/d2xx/d2xx.go +++ b/vendor/periph.io/x/d2xx/d2xx.go @@ -14,9 +14,8 @@ type Err int // These are additional synthetic error codes. const ( // NoCGO is returned when the package was compiled without cgo, thus the d2xx - // library is unavailable. - // - // This is never returned on Windows. + // library is unavailable or the library was disabled via the `no_d2xx` build + // tag. NoCGO Err = -2 // Missing is returned when the dynamic library is not available. Missing Err = -1 @@ -117,16 +116,30 @@ type Handle interface { var _ Handle = handle(0) // Version returns the library's version. +// +// 0, 0, 0 is returned if the library is unavailable. func Version() (uint8, uint8, uint8) { return version() } // CreateDeviceInfoList discovers the currently found devices. +// +// If the driver is disabled via build tag `no_d2xx`, or on posix +// `CGO_ENABLED=0` environment variable, NoCGO is returned. +// +// On Windows, Missing is returned if the dynamic library is not found at +// runtime. func CreateDeviceInfoList() (int, Err) { return createDeviceInfoList() } // Open opens the ith device discovered. +// +// If the driver is disabled via build tag `no_d2xx`, or on posix +// `CGO_ENABLED=0` environment variable, NoCGO is returned. +// +// On Windows, Missing is returned if the dynamic library is not found at +// runtime. func Open(i int) (Handle, Err) { return open(i) } diff --git a/vendor/periph.io/x/d2xx/d2xx_darwin_amd64.go b/vendor/periph.io/x/d2xx/d2xx_darwin_amd64.go index 3fa84a9..af05345 100644 --- a/vendor/periph.io/x/d2xx/d2xx_darwin_amd64.go +++ b/vendor/periph.io/x/d2xx/d2xx_darwin_amd64.go @@ -3,6 +3,7 @@ // that can be found in the LICENSE file. // +build cgo +// +build !no_d2xx package d2xx diff --git a/vendor/periph.io/x/d2xx/d2xx_linux_amd64.go b/vendor/periph.io/x/d2xx/d2xx_linux_amd64.go index cb3b46d..a11052c 100644 --- a/vendor/periph.io/x/d2xx/d2xx_linux_amd64.go +++ b/vendor/periph.io/x/d2xx/d2xx_linux_amd64.go @@ -3,10 +3,11 @@ // that can be found in the LICENSE file. // +build cgo +// +build !no_d2xx package d2xx /* -#cgo LDFLAGS: ${SRCDIR}/third_party/libftd2xx_linux_amd64_v1.4.6.a +#cgo LDFLAGS: ${SRCDIR}/third_party/libftd2xx_linux_amd64_v1.4.24.a */ import "C" diff --git a/vendor/periph.io/x/d2xx/d2xx_linux_arm.go b/vendor/periph.io/x/d2xx/d2xx_linux_arm.go index 014592c..b6081ee 100644 --- a/vendor/periph.io/x/d2xx/d2xx_linux_arm.go +++ b/vendor/periph.io/x/d2xx/d2xx_linux_arm.go @@ -3,6 +3,7 @@ // that can be found in the LICENSE file. // +build cgo +// +build !no_d2xx package d2xx @@ -10,6 +11,6 @@ package d2xx // optimal ARM architecture. /* -#cgo LDFLAGS: ${SRCDIR}/third_party/libftd2xx_linux_arm6hf_v1.4.6.a +#cgo LDFLAGS: ${SRCDIR}/third_party/libftd2xx_linux_arm6hf_v1.4.24.a */ import "C" diff --git a/vendor/periph.io/x/d2xx/d2xx_linux_arm64.go b/vendor/periph.io/x/d2xx/d2xx_linux_arm64.go new file mode 100644 index 0000000..4d951ca --- /dev/null +++ b/vendor/periph.io/x/d2xx/d2xx_linux_arm64.go @@ -0,0 +1,13 @@ +// Copyright 2021 The Periph Authors. All rights reserved. +// Use of this source code is governed under the Apache License, Version 2.0 +// that can be found in the LICENSE file. + +// +build cgo +// +build !no_d2xx + +package d2xx + +/* +#cgo LDFLAGS: ${SRCDIR}/third_party/libftd2xx_linux_arm64_v1.4.24.a +*/ +import "C" diff --git a/vendor/periph.io/x/d2xx/d2xx_posix.go b/vendor/periph.io/x/d2xx/d2xx_posix.go index 5cc3d52..40119e1 100644 --- a/vendor/periph.io/x/d2xx/d2xx_posix.go +++ b/vendor/periph.io/x/d2xx/d2xx_posix.go @@ -2,7 +2,9 @@ // Use of this source code is governed under the Apache License, Version 2.0 // that can be found in the LICENSE file. +// +build cgo // +build !windows +// +build !no_d2xx package d2xx diff --git a/vendor/periph.io/x/d2xx/d2xx_posix_no_cgo.go b/vendor/periph.io/x/d2xx/d2xx_posix_no_cgo.go index cc2382f..5fbbc8f 100644 --- a/vendor/periph.io/x/d2xx/d2xx_posix_no_cgo.go +++ b/vendor/periph.io/x/d2xx/d2xx_posix_no_cgo.go @@ -2,8 +2,8 @@ // Use of this source code is governed under the Apache License, Version 2.0 // that can be found in the LICENSE file. -// +build !cgo -// +build !windows +// +build !cgo no_d2xx +// +build !windows no_d2xx package d2xx diff --git a/vendor/periph.io/x/d2xx/d2xx_posix_other.go b/vendor/periph.io/x/d2xx/d2xx_posix_other.go index 09a0538..8db5d18 100644 --- a/vendor/periph.io/x/d2xx/d2xx_posix_other.go +++ b/vendor/periph.io/x/d2xx/d2xx_posix_other.go @@ -7,9 +7,12 @@ // +build !linux,!amd64 // +build !linux,!arm // +build !windows +// +build !no_d2xx package d2xx +// This assumes the library is installed and available for linking. + /* #cgo LDFLAGS: -lftd2xx */ diff --git a/vendor/periph.io/x/d2xx/d2xx_windows.go b/vendor/periph.io/x/d2xx/d2xx_windows.go index 2c840ce..8429f34 100644 --- a/vendor/periph.io/x/d2xx/d2xx_windows.go +++ b/vendor/periph.io/x/d2xx/d2xx_windows.go @@ -2,6 +2,8 @@ // Use of this source code is governed under the Apache License, Version 2.0 // that can be found in the LICENSE file. +// +build !no_d2xx + package d2xx import ( @@ -22,15 +24,21 @@ func version() (uint8, uint8, uint8) { } func createDeviceInfoList() (int, Err) { - var num uint32 - r1, _, _ := pCreateDeviceInfoList.Call(uintptr(unsafe.Pointer(&num))) - return int(num), Err(r1) + if pCreateDeviceInfoList != nil { + var num uint32 + r1, _, _ := pCreateDeviceInfoList.Call(uintptr(unsafe.Pointer(&num))) + return int(num), Err(r1) + } + return 0, Missing } func open(i int) (Handle, Err) { var h handle - r1, _, _ := pOpen.Call(uintptr(i), uintptr(unsafe.Pointer(&h))) - return h, Err(r1) + if pOpen != nil { + r1, _, _ := pOpen.Call(uintptr(i), uintptr(unsafe.Pointer(&h))) + return h, Err(r1) + } + return h, Missing } func (h handle) Close() Err { diff --git a/vendor/periph.io/x/d2xx/doc.go b/vendor/periph.io/x/d2xx/doc.go index 12e0c59..116e5e8 100644 --- a/vendor/periph.io/x/d2xx/doc.go +++ b/vendor/periph.io/x/d2xx/doc.go @@ -5,9 +5,9 @@ // Package d2xx is a thin Go wrapper for the Future Technology "D2XX" driver. // // This package is not Go idiomatic. You want to use -// https://periph.io/x/host/v3/ftdi instead. +// https://periph.io/x/host/v3/ftdi (or later) instead. // -// A binary copy of the d2xx driver is included for linux and macOS. They are +// A static library of the d2xx driver is included for linux and macOS. They are // from https://ftdichip.com/drivers/d2xx-drivers/. See third_party/README.md // for more details. // @@ -15,7 +15,4 @@ // // See https://periph.io/device/ftdi/ for more details, and how to configure // the host to be able to use this driver. -// -// Windows 10 automatically fetches the driver from Windows Update upon -// connecting a FTDI device on the firt time, so no need to download a driver. package d2xx diff --git a/vendor/periph.io/x/d2xx/test.sh b/vendor/periph.io/x/d2xx/test.sh index a491258..5356949 100644 --- a/vendor/periph.io/x/d2xx/test.sh +++ b/vendor/periph.io/x/d2xx/test.sh @@ -4,8 +4,6 @@ # that can be found in the LICENSE file. # Builds the package on multiple OSes to confirm it builds fine. -# -# It is recommended to use the -i flag so subsequent runs are much faster. set -eu @@ -13,13 +11,33 @@ cd `dirname $0` OPT=$* +# Do not set CGO_ENABLED, as we want the default behavior when cross compiling, +# which is different from when CGO_ENABLED=1. +export -n CGO_ENABLED + +# Cleanup. +export -n GOOS +export -n GOARCH + function build { - echo "Testing on $1/$2" - GOOS=$1 GOARCH=$2 go build $OPT + export GOOS=$1 + export GOARCH=$2 + echo "Building on $GOOS/$GOARCH" + go build $OPT + echo "Building on $GOOS/$GOARCH - no_d2xx" + go build -tags no_d2xx $OPT + echo "Building on $GOOS/$GOARCH - no cgo" + CGO_ENABLED=0 go build $OPT + echo "Building on $GOOS/$GOARCH - no cgo, no_d2xx" + CGO_ENABLED=0 go build -tags no_d2xx $OPT } -build darwin amd64 -build linux amd64 -build linux arm +CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc build linux amd64 +# Requires: sudo apt install gcc-arm-linux-gnueabihf +CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc build linux arm +# Requires: sudo apt install gcc-aarch64-linux-gnu +CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc build linux arm64 + build linux 386 build windows amd64 +build darwin amd64