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

nRF52: set SPI TX/RX lengths even data is empty. Fixes #3868 #3877

Merged
merged 2 commits into from
Aug 24, 2023

Conversation

perttierkkila
Copy link
Contributor

No description provided.

@@ -296,6 +296,8 @@ func (spi SPI) Tx(w, r []byte) error {
}
spi.Bus.RXD.MAXCNT.Set(n)
r = r[n:]
} else {
Copy link
Member

@deadprogram deadprogram Aug 23, 2023

Choose a reason for hiding this comment

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

Just wondering if perhaps a better syntax for this entire section might be something like this:

		nr := uint32(len(r))
		if nr > 255 {
			nr = 255
		}
		if nr != 0 {
			spi.Bus.RXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&r[0]))))
			r = r[nr:]
		}
		spi.Bus.RXD.MAXCNT.Set(nr)

		nw := uint32(len(w))
		if nw > 255 {
			nw = 255
		}
		if nw != 0 {
			spi.Bus.TXD.PTR.Set(uint32(uintptr(unsafe.Pointer(&w[0]))))
			w = w[nw:]
		}
		spi.Bus.TXD.MAXCNT.Set(nw)

Copy link
Member

@deadprogram deadprogram left a comment

Choose a reason for hiding this comment

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

I like the way you made this change @perttierkkila thanks!

I will squash/merge this once it passes all CI test.

@perttierkkila
Copy link
Contributor Author

Thank you! I was a bit shy at first to do the change properly and tried to keep changes in minimum and refactored it now as it should be. It reduces one branching when no data :)

@deadprogram
Copy link
Member

Now going to squash/merge. Thanks again @perttierkkila

@deadprogram deadprogram merged commit 806498f into tinygo-org:dev Aug 24, 2023
13 checks passed
@perttierkkila perttierkkila deleted the nrf52-spi-tx-fix branch August 24, 2023 11:20
Copy link
Member

@aykevl aykevl left a comment

Choose a reason for hiding this comment

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

Heh, probably a bug I originally introduced. In any case, thanks for fixing it :D

deadprogram pushed a commit that referenced this pull request Sep 17, 2023
machine/hrf: Set SPI TX/RX lengths even data is empty. Fixes #3868
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants