Skip to content

Commit

Permalink
make digitalInterruptByName helper for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnN193 committed Dec 10, 2024
1 parent b7c3936 commit 2b90e1d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pi5/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func (b *pinctrlpi5) Reconfigure(
return err
}

b.mu.Lock()
defer b.mu.Unlock()

// make sure every pin has a name. We already know every pin has a pin
for _, c := range newConf.Pins {
if c.Name == "" {
Expand Down Expand Up @@ -216,7 +219,7 @@ func (b *pinctrlpi5) reconfigureInterrupts(newConf *rpiutils.Config) error {
if newConfig.Type != rpiutils.PinInterrupt {
continue
}
if _, err := b.DigitalInterruptByName(newConfig.Name); err != nil {
if _, err := b.digitalInterruptByName(newConfig.Name); err != nil {
return err
}
}
Expand Down Expand Up @@ -291,10 +294,8 @@ func (b *pinctrlpi5) AnalogByName(name string) (board.Analog, error) {
return nil, errors.New("analogs not supported")
}

// DigitalInterruptByName returns the interrupt by the given name if it exists.
func (b *pinctrlpi5) DigitalInterruptByName(name string) (board.DigitalInterrupt, error) {
b.mu.Lock()
defer b.mu.Unlock()
// the implementation of digitalInterruptByName. The board mutex should be locked before calling this.
func (b *pinctrlpi5) digitalInterruptByName(name string) (board.DigitalInterrupt, error) {
// first check if the pinName is a user defined name
bcom, ok := b.userDefinedNames[name]
if !ok {
Expand Down Expand Up @@ -347,6 +348,13 @@ func (b *pinctrlpi5) DigitalInterruptByName(name string) (board.DigitalInterrupt
return interrupt, nil
}

// DigitalInterruptByName returns the interrupt by the given name if it exists.
func (b *pinctrlpi5) DigitalInterruptByName(name string) (board.DigitalInterrupt, error) {
b.mu.Lock()
defer b.mu.Unlock()
return b.digitalInterruptByName(name)
}

// AnalogNames returns the names of all known analog pins.
func (b *pinctrlpi5) AnalogNames() []string {
return []string{}
Expand Down

0 comments on commit 2b90e1d

Please sign in to comment.