drivers: pwm: nrf_sw: convert to timer phandle instead instance number
So far 'timer-instance' DT property was the way to configure TIMER which was used for generating PWM signal. Replace that by using 'generator' phandle, so we get prepared for supporting RTC instances as PWM signal generator. Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
parent
4f868cd9fa
commit
0d58960abb
10 changed files with 34 additions and 15 deletions
|
@ -16,11 +16,22 @@
|
|||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(pwm_nrf5_sw);
|
||||
|
||||
BUILD_ASSERT(DT_INST_NODE_HAS_PROP(0, timer_instance) !=
|
||||
DT_INST_NODE_HAS_PROP(0, generator),
|
||||
"Please define either the timer-instance or generator property, but not both");
|
||||
|
||||
#if DT_INST_NODE_HAS_PROP(0, timer_instance)
|
||||
#define GENERATOR_ADDR _CONCAT(NRF_TIMER, DT_INST_PROP(0, timer_instance))
|
||||
#define GENERATOR_CC_NUM \
|
||||
_CONCAT(_CONCAT(TIMER, DT_INST_PROP(0, timer_instance)), _CC_NUM)
|
||||
#else /* DT_INST_NODE_HAS_PROP(0, timer_instance) */
|
||||
#define GENERATOR_NODE DT_PHANDLE(DT_DRV_INST(0), generator)
|
||||
#define GENERATOR_ADDR ((NRF_TIMER_Type *) DT_REG_ADDR(GENERATOR_NODE))
|
||||
#define GENERATOR_CC_NUM DT_PROP(GENERATOR_NODE, cc_num)
|
||||
#endif /* DT_INST_NODE_HAS_PROP(0, timer_instance) */
|
||||
|
||||
/* One compare channel is needed to set the PWM period, hence +1. */
|
||||
#if ((DT_INST_PROP(0, channel_count) + 1) > \
|
||||
(_CONCAT( \
|
||||
_CONCAT(TIMER, DT_INST_PROP(0, timer_instance)), \
|
||||
_CC_NUM)))
|
||||
#if ((DT_INST_PROP(0, channel_count) + 1) > GENERATOR_CC_NUM)
|
||||
#error "Invalid number of PWM channels configured."
|
||||
#endif
|
||||
#define PWM_0_MAP_SIZE DT_INST_PROP(0, channel_count)
|
||||
|
@ -257,7 +268,7 @@ static int pwm_nrf5_sw_init(const struct device *dev)
|
|||
}
|
||||
|
||||
static const struct pwm_config pwm_nrf5_sw_0_config = {
|
||||
.timer = _CONCAT(NRF_TIMER, DT_INST_PROP(0, timer_instance)),
|
||||
.timer = GENERATOR_ADDR,
|
||||
.ppi_base = DT_INST_PROP(0, ppi_base),
|
||||
.gpiote_base = DT_INST_PROP(0, gpiote_base),
|
||||
.map_size = PWM_0_MAP_SIZE,
|
||||
|
|
|
@ -231,7 +231,7 @@
|
|||
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <1>;
|
||||
generator = <&timer1>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <7>;
|
||||
|
|
|
@ -219,7 +219,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <7>;
|
||||
|
|
|
@ -221,7 +221,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -244,7 +244,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -255,7 +255,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -319,7 +319,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -375,7 +375,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -396,7 +396,7 @@
|
|||
};
|
||||
|
||||
&sw_pwm {
|
||||
timer-instance = <2>;
|
||||
generator = <&timer2>;
|
||||
channel-count = <3>;
|
||||
clock-prescaler = <0>;
|
||||
ppi-base = <14>;
|
||||
|
|
|
@ -5,10 +5,18 @@ compatible: "nordic,nrf-sw-pwm"
|
|||
include: [pwm-controller.yaml, base.yaml]
|
||||
|
||||
properties:
|
||||
generator:
|
||||
type: phandle
|
||||
description: Reference to TIMER instance for generating PWM output signals
|
||||
required: false
|
||||
|
||||
timer-instance:
|
||||
type: int
|
||||
description: Timer instance to use for generating the PWM output signals
|
||||
required: true
|
||||
description: |
|
||||
Timer instance to use for generating the PWM output signals. Deprecated
|
||||
in favour of 'generator' property.
|
||||
required: false
|
||||
deprecated: true
|
||||
|
||||
channel-count:
|
||||
type: int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue