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

drivers: pwm: rpi_pico: Configuring the divide ratio adaptively #78786

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

soburi
Copy link
Member

@soburi soburi commented Sep 20, 2024

As with many other implementations, we should set the division ratio to a value that corresponds to the interval specified in the API.

If the divider-int-0 or variations of these for each channel properties
are not specified, or if these is 0,
the driver dynamically configures the division ratio by specified cycles.

The driver will operate at the specified division ratio if a non-zero
value is specified for divider-int-0.
This is unchanged from previous behavior.

Please specify divider-int-0 explicitly to make the same behavior as
before.

In addition, the default device tree properties related to the division
ratio have been removed.

@soburi soburi marked this pull request as ready for review September 21, 2024 01:34
@soburi soburi requested a review from yonsch as a code owner September 21, 2024 01:34
@zephyrbot zephyrbot added platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico) area: LED Label to identify LED subsystem area: Samples Samples area: PWM Pulse Width Modulation Release Notes To be mentioned in the release notes labels Sep 21, 2024
@soburi soburi marked this pull request as draft September 21, 2024 01:38
@soburi soburi marked this pull request as ready for review September 21, 2024 02:13
@@ -16,88 +16,72 @@ properties:

divider-int-0:
type: int
default: 1
description: |
The integral part of the divider for pwm slice 0.
This number should be in the range 1 - 255. Defaults
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it still default to the reset value?

Copy link
Member Author

@soburi soburi Sep 22, 2024

Choose a reason for hiding this comment

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

yonsch
yonsch previously approved these changes Sep 22, 2024
Copy link
Collaborator

@simonguinot simonguinot left a comment

Choose a reason for hiding this comment

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

Hi @soburi,

The LED part looks OK but I am not sure about the PWM driver. Please find some questions and suggestions below.

#define PWM_INST_RPI_SLICE_DIVIDER(idx, n) \
{ \
.integral = DT_INST_PROP_OR(idx, UTIL_CAT(divider_int_, n), 0), \
.frac = DT_INST_PROP_OR(idx, UTIL_CAT(divider_frac_, n), 0), \
Copy link
Collaborator

Choose a reason for hiding this comment

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

You use trailing spaces for the lines above but tabs for those below (PWM_RPI_INIT).

Copy link
Member Author

@soburi soburi Oct 2, 2024

Choose a reason for hiding this comment

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

Fixed it.

@@ -16,88 +16,72 @@ properties:

divider-int-0:
Copy link
Collaborator

@simonguinot simonguinot Oct 1, 2024

Choose a reason for hiding this comment

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

Out of curiosity what is the interest for a user to manually set/force the divider value of a PWM ? After all a user only wants ->set_cycles() to succeed. If the divider is set/forced, I suspect this limits the supported cycle range (period and pulse)...

Copy link
Member Author

@soburi soburi Oct 2, 2024

Choose a reason for hiding this comment

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

Your understanding is correct.
This may be useful when creating deterministically precise waveforms, but I don't think it's necessary for most use cases.
However, since this is the current specification, it must be maintained.
This PR intends to relax the limitation.

@@ -16,88 +16,72 @@ properties:

divider-int-0:
type: int
default: 1
description: |
The integral part of the divider for pwm slice 0.
This number should be in the range 1 - 255. Defaults
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually 0 is also a supported/valid value for the driver. It means "automatic divider handling". Honestly, I find the whole thing confusing... It's not clear that not setting this value or setting it to 0 leaves the driver to take care of everything. Also we are kind of hijacking a device-tree hardware attribute by using an unsupported value to control a special behavior of the driver.

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 forgot to update the description.
The "automatic divider handling" behavior is extended in this PR.
I added a description of this feature.

# SPDX-License-Identifier: Apache-2.0

config BLINK_DURATION_SHORT
int "LED on and off times for short-cycle blinking demo"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Blinking delay for short cycle demo`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. I applied it.

int "LED on and off times for short-cycle blinking demo"
default 100
help
Specifies the LED blinking time in milliseconds in the short-cycle
Copy link
Collaborator

Choose a reason for hiding this comment

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

And maybe: Specifies the LED on/off delay in milliseconds for short cycle blinking demonstration.

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 applied it.

# Copyright (c) 2024 TOKITA Hiroshi
# SPDX-License-Identifier: Apache-2.0

config BLINK_DURATION_SHORT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: BLINK_DELAY_SHORT

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 applied it.

Specifies the delay time for the fade demo of the PWM-LED sample.
The fade demo increases the brightness by 1 percent point every
time this delay time elapses and ends when it reaches the value
of MAX_BRIGHTNESS.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: The brightness gradually increases by one level each time this delay elapses.

Let's not talk about percent. When we will update the maximum brightness to 255, we might forget to update this comment :)

Copy link
Member Author

@soburi soburi Oct 2, 2024

Choose a reason for hiding this comment

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

I applied it.

Let's not talk about percent. When we will update the maximum brightness to 255, we might forget to update this comment :)

OK. I got it.

int "delay time for fade demo"
default 10
help
Specifies the delay time for the fade demo of the PWM-LED sample.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: Specifies the delay in milliseconds for ...

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 applied it.

err = led_blink(led_pwm, led, 100, 100);
#if CONFIG_BLINK_DURATION_SHORT > 0
/* Start LED blinking (short cycle) */
err = led_blink(led_pwm, led, CONFIG_BLINK_DURATION_SHORT, CONFIG_BLINK_DURATION_SHORT);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optionally, limit the line length to 80 columns, to stay consistent with the rest of the code.

Copy link
Member Author

@soburi soburi Oct 2, 2024

Choose a reason for hiding this comment

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

I want to conform basically to the clang-format settings.

ColumnLimit: 100

If the `divider-int-0` or variations of these for each channel properties
are not specified, or if these is 0,
the driver dynamically configures the division ratio by specified cycles.

The driver will operate at the specified division ratio if a non-zero
value is specified for `divider-int-0`.
This is unchanged from previous behavior.

Please specify ``divider-int-0`` explicitly to make the same behavior as
before.

In addition, the default device tree properties related to the division
ratio have been removed.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Make the blinking and fading parameters adjustable so that samples
can be run on devices that support only short periods.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Tweaking the parameters to go the sample without any errors.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add test configuration for rpi_pico

Signed-off-by: TOKITA Hiroshi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: LED Label to identify LED subsystem area: PWM Pulse Width Modulation area: Samples Samples platform: Raspberry Pi Pico Raspberry Pi Pico (RPi Pico) Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants