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

[RSDK-10192] [RSDK-10199] Update PWM logic for ESP-IDF 5 #440

Open
wants to merge 3 commits into
base: RSDK-8990-platform-modernization
Choose a base branch
from

Conversation

gvaradarajan
Copy link
Member

@gvaradarajan will test on hardware when more of the platform modernization tickets are satisfied.

@gvaradarajan gvaradarajan requested a review from a team as a code owner March 21, 2025 20:38
Copy link
Member

@npmenard npmenard left a comment

Choose a reason for hiding this comment

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

Not sure about the direction here :P

impl LedcTimerWrapper<'_> {
fn new(id: u8, frequency_hz: u32) -> Result<Self, Esp32PwmError> {
let timer_config = TimerConfig::default().frequency(frequency_hz.Hz());
let timer = OnceCell::new();
let _ = timer.set(create_timer_driver(id, &timer_config)?);
let _ = timer.set(LedcTimerOption::new(timer, &timer_config)?);
Copy link
Member

Choose a reason for hiding this comment

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

you change the signature of the function it doesn't take a oncecell anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think I did? Which function do you mean?

Copy link
Member

Choose a reason for hiding this comment

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

LedcTimerOption::new takes a u8 and not a OnceCell

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I'm still confused, create_timer_driver didn't take a OnceCell either, what function are we talking about again?

Copy link
Member

Choose a reason for hiding this comment

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

LedcTimerOption::new(timer: u8, conf: &TimerConfig) takes an u8 but you pass timer as first arg. I think you meant id :P

Copy link
Member Author

Choose a reason for hiding this comment

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

ohhhh, thank you.


impl LedcTimerOption<'_> {
pub fn new(timer: u8, conf: &TimerConfig) -> Result<Self, Esp32PwmError> {
match timer {
Copy link
Member

Choose a reason for hiding this comment

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

need to cover the default case

Copy link
Member Author

Choose a reason for hiding this comment

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

ah, you're right, I missed that. My bad


pub fn timer(&self) -> ledc_timer_t {
match self {
Timer0(_) => TIMER0::timer(),
Copy link
Member

Choose a reason for hiding this comment

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

where are these symbols coming from

Copy link
Member Author

Choose a reason for hiding this comment

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

imported above from esp_idf_svc::hal::ledc

Copy link
Member

Choose a reason for hiding this comment

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

I don't see Timer0 is it defined elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

L. 169?

Copy link
Member

Choose a reason for hiding this comment

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

oh i see then the syntax should be Self::Timer0

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, this PR's a real mess huh?

@@ -109,8 +109,7 @@ impl<'a> PwmDriver<'a> {

pub fn get_timer_frequency(&self) -> u32 {
let timer: ledc_timer_t = (self.timer_number as u8).into();
// TODO(RSDK-10199): SpeedMode is now a trait in ESP-IDF 5
unsafe { ledc_get_freq(SpeedMode::LowSpeed.into(), timer) }
unsafe { ledc_get_freq(LowSpeed::SPEED_MODE, timer) }
Copy link
Member

Choose a reason for hiding this comment

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

i don't think LowSpeed is an enum anymore

Copy link
Member Author

@gvaradarajan gvaradarajan Mar 25, 2025

Choose a reason for hiding this comment

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

It's not, it's a struct implementing the SpeedMode trait, but the trait contains a variable called SPEED_MODE

Copy link
Member

Choose a reason for hiding this comment

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

I think they are private

Copy link
Member Author

@gvaradarajan gvaradarajan Mar 26, 2025

Choose a reason for hiding this comment

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

can trait variables be private? I didn't think they could

EDIT: I've confirmed that public/private visibility does not exist for things inside traits (although you can make the trait itself private by not exporting it)

@gvaradarajan
Copy link
Member Author

Not sure about the direction here :P

@npmenard, thoughts on what kind of direction you'd prefer?

@gvaradarajan gvaradarajan requested a review from npmenard March 25, 2025 01:30
@@ -166,6 +165,50 @@ impl From<PwmChannel> for usize {
}
}

pub enum LedcTimerOption<'a> {
Timer0(LedcTimerDriver<'a, TIMER0>),
Copy link
Member

Choose a reason for hiding this comment

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

There is a couple of place where LedcTimerDriver is returned or used would need to add the new generic param

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