-
Notifications
You must be signed in to change notification settings - Fork 5
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
DaneSlattery
wants to merge
1
commit into
main
Choose a base branch
from
dms_idf_example
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// currently does not build in in this no-std environment. copy the code elsewhere | ||
use esp_idf_svc::hal::{delay, gpio::PinDriver, peripherals::Peripherals}; | ||
use loadcell::{hx711::HX711, LoadCell}; | ||
|
||
fn main() { | ||
esp_idf_svc::sys::link_patches(); | ||
esp_idf_svc::log::EspLogger::initialize_default(); | ||
|
||
let peripherals = Peripherals::take().unwrap(); | ||
let dt = PinDriver::input(peripherals.pins.gpio1).unwrap(); | ||
let sck = PinDriver::output(peripherals.pins.gpio10).unwrap(); | ||
let mut load_sensor = HX711::new(sck, dt, delay::FreeRtos); | ||
|
||
load_sensor.tare(16); | ||
load_sensor.set_scale(1.0); | ||
|
||
loop { | ||
if load_sensor.is_ready() { | ||
let reading = load_sensor.read_scaled(); | ||
log::info!("Last Reading = {:?}", reading); | ||
} | ||
|
||
delay::FreeRtos::delay_ms(1000u32); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 hereThere was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/esp-rs/esp-idf-hal/actions/runs/8685940536/job/23816424436?pr=405
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.