Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Comments

bitbang/spi cleanup#268

Merged
maruel merged 3 commits intogoogle:masterfrom
Ulexus:bitbang-spi-cleanup
Aug 6, 2018
Merged

bitbang/spi cleanup#268
maruel merged 3 commits intogoogle:masterfrom
Ulexus:bitbang-spi-cleanup

Conversation

@Ulexus
Copy link
Contributor

@Ulexus Ulexus commented Aug 6, 2018

Changes based on feedback from @maruel

  • precalculate clock idle polarity and remove clockOn()/clockOff()
  • check for higher (unknown) modes and reject them
  • move internal functions down, to be grouped together

 - precalculate clock idle polarity and remove clockOn()/clockOff()
 - check for higher (unknown) modes and reject them
 - move internal functions down, to be grouped together
s.spiConn.readAfterClockPulse = mode&spi.Mode1 == spi.Mode1

// Set clock idle polarity
if mode&spi.Mode2 == spi.Mode2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit of a hack but you can do:

s.spiConn.clockIdle = gpio.Level(mode&spi.Mode2 == spi.Mode2)

Also, we would want to have the pin setup to idle state right here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't normally compress the logic so much, but since the rest of the connect options are handled similarly, that sounds reasonable.

@maruel
Copy link
Contributor

maruel commented Aug 6, 2018

gohci


// Set clock idle polarity, ensuring an idle clock to start
s.spiConn.clockIdle = gpio.Level(mode&spi.Mode2 == spi.Mode2)
s.spiConn.sck.Out(s.spiConn.clockIdle)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the error. Also set CS too when NoCS is not set, and MISO and MOSI as In()/Out(Low?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ignore MISO/MOSI/CS, that's done above. Just check the error and it'll be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I'm not so sure all the pin initialization shouldn't be moved to Connect() anyway, in the realm of expected results. My assumption would be that if there is a separate Connect(), the initial SPI device creation would not modify the hardware. The rest of the codebase, however, does not appear to make that distinction. This is definitely in the nit domain.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point.

This was done this way initially so the failure (aka an invalid pin) would occur earlier at SPI instantiation, because Connect() is called within a device driver, which would be confusing for the users.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that is totally understandable. Thanks for the reviewing!

@maruel
Copy link
Contributor

maruel commented Aug 6, 2018

gohci

@maruel maruel merged commit ef46f26 into google:master Aug 6, 2018
@Ulexus Ulexus deleted the bitbang-spi-cleanup branch August 6, 2018 17:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants