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

Support 3-wire-SPI #2919

Merged
merged 10 commits into from
Jan 17, 2025
Merged

Support 3-wire-SPI #2919

merged 10 commits into from
Jan 17, 2025

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented Jan 9, 2025

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Implement 3-wire half-duplex SPI.

Closes #2687
Closes #1826

Testing

While there is an adapted hil-test I used a C3 to simulate a slave-device and checked the implementation works for me

|| (address != Address::None && address.mode() != DataMode::SingleThreeWire)
|| data_mode != DataMode::SingleThreeWire)
{
return Err(Error::ArgumentsInvalid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use Unsupported instead?

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 was considering that (and actually I used it first) but the description suggests something else (well I could change the description ofc) - but on the other hand looking at how it's currently used it might be fine - I don't have a preference - happy to change it

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to have two different error variants that mean the same thing. Why something isn't supported is, in my opinion, not that important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

really no preference on my side - maybe there are more opinions on that - if not I will remove ArgumentsInvalid

(maybe rename Unsupported to OperationUnsupported?)

@bjoernQ bjoernQ marked this pull request as ready for review January 9, 2025 14:33
esp-hal/src/spi/master.rs Show resolved Hide resolved
Comment on lines 100 to 112
pub enum DataMode {
/// `Single` Data Mode - 1 bit, 2 wires.
/// Clock, CS and one data line (SIO0)
SingleThreeWire,
/// `Single` Data Mode - 1 bit, two data lines. (SIO0, SIO1)
Single,
/// `Dual` Data Mode - 2 bit, 2 wires
/// `Dual` Data Mode - 2 bits, two data lines. (SIO0, SIO1)
Dual,
/// `Quad` Data Mode - 4 bit, 4 wires
/// `Quad` Data Mode - 4 bit, 4 data lines. (SIO0 .. SIO3)
Quad,
#[cfg(spi_octal)]
/// `Octal` Data Mode - 8 bit, 8 wires
/// `Octal` Data Mode - 8 bit, 8 data lines. (SIO0 .. SIO7)
Octal,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wild thought here with regards to naming consistency.
I think it actually makes more sense for Single to mean "3 wire half duplex".
This way, Single, Dual, Quad and Octal all mean half duplex and the name strictly refers to the number of data pins used.
Then there can be a special mode for when there are two data lines that aren't used at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense - and did that. Maybe the now Single variant should be named ThreeWire to make things more obvious? I think three-wire and four-wire are more common names

Copy link
Contributor

Choose a reason for hiding this comment

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

My issue with the "FourWire" name is that both Dual and Quad use four wires and it'll be somewhat unclear that this means "Single" but over the full duplex wiring.

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 - I'm open to naming suggestions

Copy link
Collaborator

Choose a reason for hiding this comment

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

Some inspiration

  • HalfAndHalf
  • DualHalves
  • Couple
  • Half
  • TwoHalves
  • SingleSplit
  • Split
  • Pair
  • Serial
  • SingleWithTwoWires
  • Single(SingleMode::ThreeWire)

@bjoernQ bjoernQ force-pushed the three-wire-spi branch 2 times, most recently from c177bd6 to 7091b11 Compare January 17, 2025 12:41
Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

My concerns have been resolved

esp-hal/src/spi/master.rs Outdated Show resolved Hide resolved
esp-hal/src/spi/master.rs Show resolved Hide resolved
Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

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

Thanks. I guess we might want to mark the half-duplex pin setters as unstable as the half duplex transfers themselves are unstable, but that's not a huge deal.

@MabezDev MabezDev added this pull request to the merge queue Jan 17, 2025
Merged via the queue into esp-rs:main with commit 5f2c0ec Jan 17, 2025
28 checks passed
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.

SPI: one of the half-duplex modes is not supported Expose SPI sio() setting
4 participants