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

Update to latest embedded-hal, include std example #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DaneSlattery
Copy link
Owner

Fixes examples
Adds a std example, although this does not build in this environment.
Upgrades to the embedded-hal version 1 release, with new trait defs.

@DaneSlattery DaneSlattery self-assigned this Mar 2, 2024
@DaneSlattery
Copy link
Owner Author

Addresses #8

Copy link
Collaborator

Choose a reason for hiding this comment

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

The critical section implementation using IsrCriticalSection should be added here

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think that implementation may lock this crate into the idf use case, where I would like to keep it no-std. Are you referring to this? https://github.com/beeb/coffee-scale-app/blob/main/rs/src/critical_section.rs. We should look into some way to support both.

Copy link
Collaborator

@beeb beeb Apr 15, 2024

Choose a reason for hiding this comment

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

Yes exactly, the critical section above is required for the IDF example. It's not required for no-std, as the esp32-rs crates already provide the required critical section implementation. But the provided one for idf is not sufficient to ensure correct reading of the hx711, because it is thread-local only as I understand.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Perhaps we should upstream the change into esp-idf-hal?

Copy link
Owner Author

Choose a reason for hiding this comment

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

https://docs.rs/critical-section/latest/critical_section/#usage-in-libraries says not to provide this in libraries, I think we should follow their advice.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course this only applies to the example, we should not implement it for the library. I'm talking about example code specifically, since consumers of the library will need to implement the critical section when using idf

Copy link
Collaborator

@beeb beeb Apr 17, 2024

Choose a reason for hiding this comment

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

@DaneSlattery I commented on your PR over at esp-idf-hal

Copy link
Owner Author

@DaneSlattery DaneSlattery Apr 18, 2024

Choose a reason for hiding this comment

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

I'm starting to think the one provided by default is actually safe across threads and interrupts, see here, they call interrupt::free, which runs the critical section with interrupts disabled. However, whether it is safe across multiple threads or CPUs is another question, and I don't know enough about the details.

https://github.com/esp-rs/esp-idf-hal/blob/e30d7ab708065d48f8a96e32993bde3ff3946370/src/task.rs#L448

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried it but had bad readings, the scheduler is free to launch tasks with high priority during the critical section as far as I understood. I discussed this at length on matrix with the team.

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.

2 participants