From 4889a85eddf383192bbd567609c999c1c9913fb0 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 9 Dec 2024 12:07:54 -0500 Subject: [PATCH] bump pinctrl --- go.mod | 2 +- go.sum | 4 ++-- pi5/board.go | 11 +++++------ pi5/board_test.go | 3 +-- rpi/gpio.go | 5 +++-- utils/broadcom.go | 4 ++++ 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 2f1fe8f..f622f59 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/golangci/golangci-lint v1.61.0 github.com/pkg/errors v0.9.1 github.com/rhysd/actionlint v1.6.24 - github.com/viam-modules/pinctrl v0.0.0-20241122191654-83914270ceff + github.com/viam-modules/pinctrl v0.0.0-20241206221207-94ef717afa64 go.uber.org/multierr v1.11.0 go.viam.com/api v0.1.357 go.viam.com/rdk v0.50.0 diff --git a/go.sum b/go.sum index 3c60a0e..2c9ab20 100644 --- a/go.sum +++ b/go.sum @@ -1255,8 +1255,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= -github.com/viam-modules/pinctrl v0.0.0-20241122191654-83914270ceff h1:+2/e59WKCVlaZsZrOPr3nY/rif+KeEVwK9lFZRVz1hk= -github.com/viam-modules/pinctrl v0.0.0-20241122191654-83914270ceff/go.mod h1:klkE1Ll5blcoLTi8abPsujXNyLOY0cte5tHYOjTo5u8= +github.com/viam-modules/pinctrl v0.0.0-20241206221207-94ef717afa64 h1:cITm4d6fKsvPyCk7elRqqLdDgQoXYA80N8y9IHUMseo= +github.com/viam-modules/pinctrl v0.0.0-20241206221207-94ef717afa64/go.mod h1:klkE1Ll5blcoLTi8abPsujXNyLOY0cte5tHYOjTo5u8= github.com/viamrobotics/evdev v0.1.3 h1:mR4HFafvbc5Wx4Vp1AUJp6/aITfVx9AKyXWx+rWjpfc= github.com/viamrobotics/evdev v0.1.3/go.mod h1:N6nuZmPz7HEIpM7esNWwLxbYzqWqLSZkfI/1Sccckqk= github.com/viamrobotics/webrtc/v3 v3.99.10 h1:ykE14wm+HkqMD5Ozq4rvhzzfvnXAu14ak/HzA1OCzfY= diff --git a/pi5/board.go b/pi5/board.go index 54acf6e..59e855d 100644 --- a/pi5/board.go +++ b/pi5/board.go @@ -11,8 +11,6 @@ import ( "sync" "time" - rpiutils "raspberry-pi/utils" - "github.com/pkg/errors" "github.com/viam-modules/pinctrl/pinctrl" "go.uber.org/multierr" @@ -23,6 +21,7 @@ import ( "go.viam.com/rdk/logging" "go.viam.com/rdk/resource" "go.viam.com/utils" + rpiutils "raspberry-pi/utils" ) // Model is the model for a Raspberry Pi 5. @@ -130,7 +129,7 @@ func newBoard( // Initialize the GPIO pins for newName, mapping := range gpioMappings { bcom, _ := rpiutils.BroadcomPinFromHardwareLabel(newName) - b.gpios[bcom] = b.boardPinCtrl.CreateGpioPin(mapping) + b.gpios[bcom] = b.boardPinCtrl.CreateGpioPin(mapping, rpiutils.DefaultPWMFreqHz) } if err := b.Reconfigure(ctx, nil, conf); err != nil { @@ -210,8 +209,7 @@ func (b *pinctrlpi5) reconfigureInterrupts(newConf *rpiutils.Config) error { } // add back the gpio pin to make it available to the user - b.gpios[bcom] = b.boardPinCtrl.CreateGpioPin(b.gpioMappings[oldConfig.Pin]) - + b.gpios[bcom] = b.boardPinCtrl.CreateGpioPin(b.gpioMappings[oldConfig.Pin], rpiutils.DefaultPWMFreqHz) } // add any new interrupts. DigitalInterruptByName will create the interrupt only if we are not already managing it. for _, newConfig := range newConf.Pins { @@ -245,6 +243,7 @@ func (b *pinctrlpi5) addUserDefinedNames(newConf *rpiutils.Config) error { b.userDefinedNames = nameToPin return nil } + func (b *pinctrlpi5) reconfigurePullUpPullDowns(newConf *rpiutils.Config) error { for _, pullConf := range newConf.Pins { pin, ok := b.gpioMappings[pullConf.Pin] @@ -354,7 +353,7 @@ func (b *pinctrlpi5) AnalogNames() []string { } // DigitalInterruptNames returns the names of all known digital interrupts. -// Unimplemented because we do not have an api to communicate this over +// Unimplemented because we do not have an api to communicate this over. func (b *pinctrlpi5) DigitalInterruptNames() []string { return nil } diff --git a/pi5/board_test.go b/pi5/board_test.go index 4c77191..d86f180 100644 --- a/pi5/board_test.go +++ b/pi5/board_test.go @@ -6,12 +6,11 @@ import ( "context" "testing" - rpiutils "raspberry-pi/utils" - "go.viam.com/rdk/components/board/genericlinux" "go.viam.com/rdk/logging" "go.viam.com/rdk/resource" "go.viam.com/test" + rpiutils "raspberry-pi/utils" ) func TestEmptyBoard(t *testing.T) { diff --git a/rpi/gpio.go b/rpi/gpio.go index 9c1b196..d1391b5 100644 --- a/rpi/gpio.go +++ b/rpi/gpio.go @@ -14,10 +14,11 @@ import ( "context" "fmt" + rpiutils "raspberry-pi/utils" + "github.com/pkg/errors" "go.viam.com/rdk/components/board" rdkutils "go.viam.com/rdk/utils" - rpiutils "raspberry-pi/utils" ) // GPIOConfig tracks what each pin is currently configured as @@ -213,7 +214,7 @@ func (pi *piPigpio) SetPWMFreqBcom(bcom int, freqHz uint) error { pi.mu.Lock() defer pi.mu.Unlock() if freqHz == 0 { - freqHz = 800 // Original default from libpigpio + freqHz = rpiutils.DefaultPWMFreqHz } newRes := C.set_PWM_frequency(pi.piID, C.uint(bcom), C.uint(freqHz)) diff --git a/utils/broadcom.go b/utils/broadcom.go index dcc6995..6cc1da0 100644 --- a/utils/broadcom.go +++ b/utils/broadcom.go @@ -3,6 +3,10 @@ package rpiutils import "fmt" +// DefaultPWMFreqHz is the default pwm frequency used for pwms on raspberry pis. +// Original default from libpigpio +const DefaultPWMFreqHz = uint(800) + // piHWPinToBroadcom maps the hardware inscribed pin number to // its Broadcom pin. For the sake of programming, a user typically // knows the hardware pin since they have the board on hand but does