Skip to content

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

Open
DaneSlattery wants to merge 1 commit into
mainfrom
dms_idf_example
Open

Update to latest embedded-hal, include std example#11
DaneSlattery wants to merge 1 commit into
mainfrom
dms_idf_example

Conversation

@DaneSlattery

Copy link
Copy Markdown
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
Copy Markdown
Owner Author

Addresses #8

Comment thread examples/polling_idf.rs

Copy link
Copy Markdown
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
Copy Markdown
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.

@beeb beeb Apr 15, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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

@beeb beeb Apr 17, 2024

Copy link
Copy Markdown
Collaborator

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

@DaneSlattery DaneSlattery Apr 18, 2024

Copy link
Copy Markdown
Owner Author

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
Copy Markdown
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