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

Add initial Drop for numerous drivers #2484

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

Conversation

JurajSadel
Copy link
Contributor

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

Please provide a clear and concise description of your changes, including the motivation behind these changes. The context is crucial for the reviewers.

Testing

Describe how you tested your changes.

I will add more info about status/issues I've encountered etc later today or tomorrow morning. Opening as a draft until then.

cc #1382

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.

I'm slightly worried about placing peripherals back into reset. Since we always call reset before/after enable, I think we might do the following changes:

fn reset should just assert reset, and shouldn't release it.
fn enable should just release the reset, and enable clocks
fn disbale should just disable clocks and not assert reset.

@@ -127,8 +127,8 @@ pub(crate) struct PeripheralClockControl;

#[cfg(not(any(esp32c6, esp32h2)))]
impl PeripheralClockControl {
/// Enables and resets the given peripheral
pub(crate) fn enable(peripheral: Peripheral) {
/// Enables and clears reset of the given peripheral.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer true, depending on the value of enable.

Comment on lines +989 to +990
REF_COUNTER.fetch_sub(1, Relaxed);
if REF_COUNTER.load(Relaxed) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
REF_COUNTER.fetch_sub(1, Relaxed);
if REF_COUNTER.load(Relaxed) == 0 {
if REF_COUNTER.fetch_sub(1, Relaxed) == 1 {

There's no reason to read one more time.

Copy link
Contributor

Choose a reason for hiding this comment

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

This Drop also means new_internal should no longer enable clocks. Otherwise it's possible to create Rmt (enables clocks), then drop it (it won't disable clocks because no Channels have been created).

@@ -314,7 +314,7 @@ where
fn new_inner(usb_device: impl Peripheral<P = USB_DEVICE> + 'd) -> Self {
// Do NOT reset the peripheral. Doing so will result in a broken USB JTAG
// connection.
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice);
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that we'll have to make sure dropping UsbSerialJtag doesn't reset the peripheral. Which is borderline impossible to do now :)

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