Skip to content

Commit 08b2d01

Browse files
committed
feat(src/machine/nrf52xxx/spi): implement io.Reader, io.Writer
Signed-off-by: Paul Schroeder <[email protected]>
1 parent 5c202bd commit 08b2d01

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/machine/machine_nrf52xxx.go

+10
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,16 @@ func (spi *SPI) Tx(w, r []byte) error {
338338
return nil
339339
}
340340

341+
// Read implements [io.Reader]. And reads as many bytes as the given buffer is long
342+
func (spi *SPI) Read(r []byte) (int, error) {
343+
return len(r), spi.Tx(nil, r)
344+
}
345+
346+
// Write implements [io.Writer]. And writes as long as there are bytes in w.
347+
func (spi *SPI) Write(w []byte) (int, error) {
348+
return len(w), spi.Tx(w, nil)
349+
}
350+
341351
// PWM is one PWM peripheral, which consists of a counter and multiple output
342352
// channels (that can be connected to actual pins). You can set the frequency
343353
// using SetPeriod, but only for all the channels in this PWM peripheral at

0 commit comments

Comments
 (0)