Commit Graph

9 Commits

Author SHA1 Message Date
David Brown 5969a10c30 drivers: pwm: rpi_pico: Convert clk calculations to fixed-point
Remove the use of floating point to calculate in
`pwm_rpi_get_cycles_per_sec` to fixed point calculations that result in the
same value.  There is still a division here, which is somewhat slow still,
but the end result about twice fast for the whole path through the led pwm
code.

Even better would be to cache these values, since there is no interface in
this driver to change the configuration past init time.

Signed-off-by: David Brown <david.brown@linaro.org>
2024-10-25 18:11:14 -07:00
TOKITA Hiroshi 275162fd52 drivers: pwm: rpi_pico: Configuring the divide ratio adaptively
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 <tokita.hiroshi@gmail.com>
2024-10-10 10:07:47 +02:00
Jannis Ruellmann 1d9441c872 drivers: rpi_pico_pwm: Fix compilation warnings
return value of pwm_rpi_get_clkdiv contains implicit conversions
from 'float' to 'double', triggered by floating-point operations
involving mixed data types.

Signed-off-by: Jannis Ruellmann <j.ruellmann@kunbus.com>
2024-02-05 19:58:18 +00:00
TOKITA Hiroshi 6ad894eb99 drivers: pwm: rpi_pico: Reset device on init
Resetting PWM device via reset controller on initializing.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-12-20 11:14:24 +01:00
TOKITA Hiroshi e905483bd0 driver: pwm: rpi_pico: Change to use clock controller
Since clock_control has been introduced, use it to obtain the frequency.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2023-12-20 11:14:24 +01:00
Oliver Barta e4fcb32451 drivers: pwm: rpi_pico: fix setting of cycle count per period
pwm_set_wrap() sets the TOP value, not the number of cycles.
Counter will run from 0 to TOP inclusive, generating TOP + 1 cycles.
To get n cycles, we need to set TOP to (n - 1).

The wrong setting made it impossible to achieve 100 % duty cycle, as
there was always one extra cycle.

Fixes: 7e0fff24c7 ("drivers: pwm: add pwm driver for rpi_pico")
Signed-off-by: Oliver Barta <o.barta89@gmail.com>
2023-01-02 13:03:46 +01:00
Jan Hilsdorf c888d6a365 drivers: pwm: rpi_pico: Use “pico_channel” instead of “ch”
pwm_set_chan_level uses slice channels A(=0) or B(=1) and not Zephyr
channel (0..15). So PWM doesn't work for channels > 1. There is already
a function (pwm_rpi_channel_to_pico_channel) which does the right thing,
but it isn't used for pwm_set_chan_level.

Signed-off-by: Jan Hilsdorf <jan.hilsdorf@gmail.com>
2022-10-04 10:36:20 +02:00
Nick Ward 0ad0af70ef drivers: pwm: Use a common initialization priority
As per other peripheral driver types.

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2022-10-03 15:24:38 -04:00
Joep Buruma 7e0fff24c7 drivers: pwm: add pwm driver for rpi_pico
Add pwm driver implementation for rpi pico family.
Adds myself as codeowner of drivers/pwm/*rpi_pico*

Signed-off-by: Joep Buruma <burumaj50@gmail.com>
2022-07-07 15:17:26 +02:00