Skip to content

Commit

Permalink
bump pinctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnN193 committed Dec 9, 2024
1 parent 5a2a737 commit 4889a85
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 5 additions & 6 deletions pi5/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pi5/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions rpi/gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions utils/broadcom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4889a85

Please sign in to comment.