Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module periph.io/x/host/v3
go 1.22.6

require (
periph.io/x/conn/v3 v3.7.1
periph.io/x/conn/v3 v3.7.2
periph.io/x/d2xx v0.1.1
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
periph.io/x/conn/v3 v3.7.1 h1:tMjNv3WO8jEz/ePuXl7y++2zYi8LsQ5otbmqGKy3Myg=
periph.io/x/conn/v3 v3.7.1/go.mod h1:c+HCVjkzbf09XzcqZu/t+U8Ss/2QuJj0jgRF6Nye838=
periph.io/x/conn/v3 v3.7.2 h1:qt9dE6XGP5ljbFnCKRJ9OOCoiOyBGlw7JZgoi72zZ1s=
periph.io/x/conn/v3 v3.7.2/go.mod h1:Ao0b4sFRo4QOx6c1tROJU1fLJN1hUIYggjOrkIVnpGg=
periph.io/x/d2xx v0.1.1 h1:LHp+u+qAWLB5THrTT/AzyjdvfUhllvDF5wBJP7uvn+U=
periph.io/x/d2xx v0.1.1/go.mod h1:rLM321G11Fc14Pp088khBkmXb70Pxx/kCPaIK7uRUBc=
6 changes: 3 additions & 3 deletions gpioioctl/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func testRotary(chip *gpioioctl.GPIOChip, stateLine, dataLine, buttonLine string
log.Fatal(err)
}
defer ls.Close()
statePinNumber := uint32(ls.ByOffset(0).Number())
buttonPinNumber := uint32(ls.ByOffset(2).Number())
statePinNumber := ls.ByOffset(0).Number()
buttonPinNumber := ls.ByOffset(2).Number()

var tLast = time.Now().Add(-1 * time.Second)
var halting bool
Expand All @@ -68,7 +68,7 @@ func testRotary(chip *gpioioctl.GPIOChip, stateLine, dataLine, buttonLine string
}
tLast = tNow
if lineNumber == statePinNumber {
var bits uint64
var bits gpio.GPIOValue
tDeadline := tNow.UnixNano() + 20_000_000
var consecutive uint64
for time.Now().UnixNano() < tDeadline {
Expand Down
57 changes: 37 additions & 20 deletions gpioioctl/lineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"fmt"
"log"
"os"
"sync"
"time"

"periph.io/x/conn/v3/gpio"
"periph.io/x/conn/v3/physic"
"periph.io/x/conn/v3/pin"
"sync"
"time"
)

// LineConfigOverride is an override for a LineSet configuration.
Expand Down Expand Up @@ -147,6 +147,14 @@
return ls.lines
}

func (ls *LineSet) Pins() []pin.Pin {
pins := make([]pin.Pin, len(ls.lines))
for ix, l := range ls.lines {
pins[ix] = l
}
return pins

Check warning on line 155 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L150-L155

Added lines #L150 - L155 were not covered by tests
}

// Interrupt any calls to WaitForEdge().
func (ls *LineSet) Halt() error {
if ls.fEdge != nil {
Expand All @@ -163,33 +171,33 @@
// bits is the values for each line in the bit set.
//
// mask is a bitmask indicating which bits should be applied.
func (ls *LineSet) Out(bits, mask uint64) error {
func (ls *LineSet) Out(bits, mask gpio.GPIOValue) error {

Check warning on line 174 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L174

Added line #L174 was not covered by tests
ls.mu.Lock()
defer ls.mu.Unlock()
var data gpio_v2_line_values
data.bits = bits
data.bits = uint64(bits)

Check warning on line 178 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L178

Added line #L178 was not covered by tests
if mask == 0 {
mask = (1 << ls.LineCount()) - 1
}
data.mask = mask
data.mask = uint64(mask)

Check warning on line 182 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L182

Added line #L182 was not covered by tests
return ioctl_set_gpio_v2_line_values(uintptr(ls.fd), &data)
}

// Read the pins in this LineSet. This is done as one syscall to the
// operating system and will be very fast. mask is a bitmask of set pins
// to read. If 0, then all pins are read.
func (ls *LineSet) Read(mask uint64) (uint64, error) {
func (ls *LineSet) Read(mask gpio.GPIOValue) (gpio.GPIOValue, error) {

Check warning on line 189 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L189

Added line #L189 was not covered by tests
ls.mu.Lock()
defer ls.mu.Unlock()
if mask == 0 {
mask = (1 << ls.LineCount()) - 1
}
var lvalues gpio_v2_line_values
lvalues.mask = mask
lvalues.mask = uint64(mask)

Check warning on line 196 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L196

Added line #L196 was not covered by tests
if err := ioctl_get_gpio_v2_line_values(uintptr(ls.fd), &lvalues); err != nil {
return 0, err
}
return lvalues.bits, nil
return gpio.GPIOValue(lvalues.bits), nil

Check warning on line 200 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L200

Added line #L200 was not covered by tests
}

func (ls *LineSet) MarshalJSON() ([]byte, error) {
Expand All @@ -216,7 +224,7 @@
// then the edge returned will be gpio.NoEdge
//
// err - Error value if any.
func (ls *LineSet) WaitForEdge(timeout time.Duration) (number uint32, edge gpio.Edge, err error) {
func (ls *LineSet) WaitForEdge(timeout time.Duration) (number int, edge gpio.Edge, err error) {

Check warning on line 227 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L227

Added line #L227 was not covered by tests
number = 0
edge = gpio.NoEdge
if ls.fEdge == nil {
Expand Down Expand Up @@ -248,21 +256,28 @@
} else if event.Id == _GPIO_V2_LINE_EVENT_FALLING_EDGE {
edge = gpio.FallingEdge
}
number = uint32(event.Offset)
number = int(event.Offset)

Check warning on line 259 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L259

Added line #L259 was not covered by tests
return
}

// ByOffset returns a line by it's offset in the LineSet.
func (ls *LineSet) ByOffset(offset int) *LineSetLine {
// ByOffset returns a line by it's offset in the LineSet. See ByName() for an
// example that casts the return value to a LineSetLine
func (ls *LineSet) ByOffset(offset int) pin.Pin {

Check warning on line 265 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L265

Added line #L265 was not covered by tests
if offset < 0 || offset >= len(ls.lines) {
return nil
}
return ls.lines[offset]
}

// ByName returns a Line by name from the LineSet.
func (ls *LineSet) ByName(name string) *LineSetLine {

// ByName returns a Line by name from the LineSet. To cast the returned value
// to a LineSet line, use:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be better as an example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, you're recommending duplicating the example on ByName() to the doc for ByOffset()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about creating a toy example in example_test.go but it was really just a nit, don't bother.

//
// var lsl *gpioioctl.LineSetLine
// lsl, ok := ls.ByNumber(line0.Number()).(*gpioioctl.LineSetLine)
// if !ok {
// log.Fatal("error converting to LineSetLine")
// }
func (ls *LineSet) ByName(name string) pin.Pin {

Check warning on line 280 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L280

Added line #L280 was not covered by tests
for _, line := range ls.lines {
if line.Name() == name {
return line
Expand All @@ -272,8 +287,9 @@
}

// LineNumber Return a line from the LineSet via it's GPIO line
// number.
func (ls *LineSet) ByNumber(number int) *LineSetLine {
// number. See ByName() for an example that casts the return value to a
// LineSetLine
func (ls *LineSet) ByNumber(number int) pin.Pin {

Check warning on line 292 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L292

Added line #L292 was not covered by tests
for _, line := range ls.lines {
if line.Number() == number {
return line
Expand Down Expand Up @@ -325,7 +341,7 @@

// Out writes to this specific GPIO line.
func (lsl *LineSetLine) Out(l gpio.Level) error {
var mask, bits uint64
var mask, bits gpio.GPIOValue

Check warning on line 344 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L344

Added line #L344 was not covered by tests
mask = 1 << lsl.offset
if l {
bits |= mask
Expand Down Expand Up @@ -353,7 +369,7 @@

// Read returns the value of this specific line.
func (lsl *LineSetLine) Read() gpio.Level {
var mask uint64 = 1 << lsl.offset
var mask gpio.GPIOValue = 1 << lsl.offset

Check warning on line 372 in gpioioctl/lineset.go

View check run for this annotation

Codecov / codecov/patch

gpioioctl/lineset.go#L372

Added line #L372 was not covered by tests
bits, err := lsl.parent.Read(mask)
if err != nil {
log.Printf("LineSetLine.Read() Error reading line %d. Error: %s\n", lsl.number, err)
Expand Down Expand Up @@ -411,6 +427,7 @@
}

// Ensure that Interfaces for these types are implemented fully.
var _ gpio.Group = &LineSet{}
var _ gpio.PinIO = &LineSetLine{}
var _ gpio.PinIn = &LineSetLine{}
var _ gpio.PinOut = &LineSetLine{}
Loading