File tree Expand file tree Collapse file tree 1 file changed +17
-14
lines changed Expand file tree Collapse file tree 1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change @@ -288,24 +288,27 @@ func (spi SPI) Tx(w, r []byte) error {
288288 // supported.
289289 for len (r ) != 0 || len (w ) != 0 {
290290 // Prepare the SPI transfer: set the DMA pointers and lengths.
291- if len ( r ) != 0 {
292- spi . Bus . RXD . PTR . Set ( uint32 (uintptr ( unsafe . Pointer ( & r [ 0 ])) ))
293- n := uint32 ( len ( r ))
294- if n > 255 {
295- n = 255
291+ // read buffer
292+ nr := uint32 (len ( r ))
293+ if nr > 0 {
294+ if nr > 255 {
295+ nr = 255
296296 }
297- spi .Bus .RXD .MAXCNT .Set (n )
298- r = r [n :]
297+ spi .Bus .RXD .PTR .Set (uint32 ( uintptr ( unsafe . Pointer ( & r [ 0 ]))) )
298+ r = r [nr :]
299299 }
300- if len (w ) != 0 {
301- spi .Bus .TXD .PTR .Set (uint32 (uintptr (unsafe .Pointer (& w [0 ]))))
302- n := uint32 (len (w ))
303- if n > 255 {
304- n = 255
300+ spi .Bus .RXD .MAXCNT .Set (nr )
301+
302+ // write buffer
303+ nw := uint32 (len (w ))
304+ if nw > 0 {
305+ if nw > 255 {
306+ nw = 255
305307 }
306- spi .Bus .TXD .MAXCNT .Set (n )
307- w = w [n :]
308+ spi .Bus .TXD .PTR .Set (uint32 ( uintptr ( unsafe . Pointer ( & w [ 0 ]))) )
309+ w = w [nw :]
308310 }
311+ spi .Bus .TXD .MAXCNT .Set (nw )
309312
310313 // Do the transfer.
311314 // Note: this can be improved by not waiting until the transfer is
You can’t perform that action at this time.
0 commit comments