Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/nrf52xxx/spi/improve #4699

Draft
wants to merge 6 commits into
base: dev
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat(src/machine/nrf52xxx/spi): implement io.Reader, io.Writer
Signed-off-by: Paul Schroeder <milkpirate@users.noreply.github.com>
milkpirate committed Jan 14, 2025
commit 08b2d01b6b70f73022d31af9701d15d3097e1f0f
10 changes: 10 additions & 0 deletions src/machine/machine_nrf52xxx.go
Original file line number Diff line number Diff line change
@@ -338,6 +338,16 @@ func (spi *SPI) Tx(w, r []byte) error {
return nil
}

// Read implements [io.Reader]. And reads as many bytes as the given buffer is long
func (spi *SPI) Read(r []byte) (int, error) {
return len(r), spi.Tx(nil, r)
}

// Write implements [io.Writer]. And writes as long as there are bytes in w.
func (spi *SPI) Write(w []byte) (int, error) {
return len(w), spi.Tx(w, nil)
}

Comment on lines +349 to +358
Copy link
Contributor

Choose a reason for hiding this comment

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

Read and Write are not part of the SPI interface. It is easy enough to implement an abstraction if needed that works for all SPI hardwares of all MCUs

func writeSPI(w []byte, spi interface {Tx(w,r []byte) error}) (int,error) {
    return len(w), spi.Tx(w,nil)
}

Copy link
Author

@milkpirate milkpirate Jan 18, 2025

Choose a reason for hiding this comment

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

Yeah, lets do it! Actually I was surprised that SPI is not supplying it, since it would have seemed the more natural way to interface with SPI than the current one. Can you point me to the relevant file/code section?

// PWM is one PWM peripheral, which consists of a counter and multiple output
// channels (that can be connected to actual pins). You can set the frequency
// using SetPeriod, but only for all the channels in this PWM peripheral at