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 ctimer based pwm implementation #196

Merged
merged 5 commits into from
Jan 13, 2020

Conversation

david-sawatzke
Copy link
Member

@david-sawatzke david-sawatzke commented Jan 11, 2020

No description provided.

@david-sawatzke david-sawatzke changed the title Add initial ctimer pwm implementation Add ctimer based pwm implementation Jan 11, 2020
@david-sawatzke
Copy link
Member Author

@hannobraun RegProxy really feels like it should have an unsafe new method, since I think you can otherwise create race conditions. Is there any reason it's not currently?

@david-sawatzke david-sawatzke marked this pull request as ready for review January 12, 2020 22:36
@hannobraun
Copy link
Member

Thank you, @david-sawatzke! I intend to take a look later today.

RegProxy really feels like it should have an unsafe new method, since I think you can otherwise create race conditions. Is there any reason it's not currently?

I don't remember my reasoning back then in detail, but I think the key is this bit of documentation:

/// Please note that all of this isn't really different from the raw API
/// generated by svd2rust, as multiple shared references to the same
/// register can exist there, and a shared reference is all that's required
/// to have full control over a register.

Basically, RegProxy doesn't enable anything you can't already do with raw registers.

The whole thing is a huge hack anyway. I still hope that rust-embedded/svd2rust#213 will get implemented some day.

@hannobraun
Copy link
Member

Addendum to my comment earlier: I forgot that RegProxy::new doesn't have an argument. In its current form, it should definitely be unsafe. I think what I said earlier would make sense, if RegProxy took a reference to the register, just to prove the caller has access.

But yeah, all of it is a bit of a mess. I think it's fine, because it's just an internal helper, but I wouldn't mind making its constructor unsafe.

Copy link
Member

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thank you, looking good!

I'm not very familiar with CTIMER and didn't review the register access code in detail, but I tested the example and it works great.

Two notes:

  • I think this needs a rebase (as indicated by the SWM workaround I pointed out, which probably shouldn't compile on current master).
  • I'm not sure that the naming is really on point. start_pwm seems to be appropriately named, but it returns UnconfiguredPwmPin, which seems already weird (It's not configured? I though I already started it?). The way I understand it, everything is configured and running, it just doesn't output to any pin.

Suggestion: Rename UnconfiguredPwmPin to DetachedPwmPin and configure to attach. I believe that would be clearer. (We could also use UnassignedPwmPin and assign, but that conflicts with the SWM nomenclature and would be confusing for that reason.)

examples/ctimer_fade.rs Outdated Show resolved Hide resolved
@david-sawatzke
Copy link
Member Author

Suggestion: Rename UnconfiguredPwmPin to DetachedPwmPin and configure to attach. I believe that would be clearer

Thanks for the suggestion, it's more obvious what happens that way

Copy link
Member

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thanks, that's perfect now!

I found some typos, but I believe I'll be able to apply my own suggestions, once I've submitted this review.

src/ctimer.rs Outdated
ct: CTIMER0,
}

/// An detached [`CTimerPwmPin`]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// An detached [`CTimerPwmPin`]
/// A detached [`CTimerPwmPin`]

src/ctimer.rs Outdated

/// An detached [`CTimerPwmPin`]
///
/// Use `attach` to assing an output to it
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Use `attach` to assing an output to it
/// Use `attach` to assign an output to it.

src/ctimer.rs Outdated
}

impl<CTOutput> DetachedPwmPin<CTOutput> {
/// Assings a pin to an `DetachedPwmPin`,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Assings a pin to an `DetachedPwmPin`,
/// Assigns a pin to a `DetachedPwmPin`,

@hannobraun
Copy link
Member

Seems I don't have permissions to commit to your branch. You will have to apply the suggestions. Feel free to merge yourself, once you did that.

As suggested by @hannobraun, makes it clearer what's going on
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