Skip to content

Commit 227f6dc

Browse files
committed
feat(src/machine/nrf52xxx/spi): implement io.Reader, io.Writer
Signed-off-by: Paul Schroeder <milkpirate@users.noreply.github.com>
1 parent 2c8aead commit 227f6dc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/machine/machine_nrf52xxx.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ func (spi SPI) Tx(w, r []byte) error {
330330
return nil
331331
}
332332

333+
// Read implements [io.Reader]. And reads as many bytes as the given buffer is long
334+
func (spi *SPI) Read(r []byte) (int, error) {
335+
return spi.Tx(nil, r), len(r)
336+
}
337+
338+
// Write implements [io.Writer]. And writes as long as there are bytes in w.
339+
func (spi *SPI) Write(w []byte) (int, error) {
340+
return spi.Tx(w, nil), len(w)
341+
}
342+
333343
// PWM is one PWM peripheral, which consists of a counter and multiple output
334344
// channels (that can be connected to actual pins). You can set the frequency
335345
// using SetPeriod, but only for all the channels in this PWM peripheral at

0 commit comments

Comments
 (0)