@@ -25,11 +25,13 @@ LOG_MODULE_REGISTER(pwm_nrf5_sw, CONFIG_PWM_LOG_LEVEL);
25
25
#if DT_NODE_HAS_COMPAT (GENERATOR_NODE , nordic_nrf_rtc )
26
26
#define USE_RTC 1
27
27
#define GENERATOR_ADDR ((NRF_RTC_Type *) DT_REG_ADDR(GENERATOR_NODE))
28
+ #define GENERATOR_BITS 24
28
29
BUILD_ASSERT (DT_INST_PROP (0 , clock_prescaler ) == 0 ,
29
30
"Only clock-prescaler = <0> is supported when used with RTC" );
30
31
#else
31
32
#define USE_RTC 0
32
33
#define GENERATOR_ADDR ((NRF_TIMER_Type *) DT_REG_ADDR(GENERATOR_NODE))
34
+ #define GENERATOR_BITS DT_PROP(GENERATOR_NODE, max_bit_width)
33
35
#endif
34
36
35
37
#define PWM_0_MAP_SIZE DT_INST_PROP_LEN(0, channel_gpios)
@@ -145,10 +147,8 @@ static int pwm_nrf5_sw_set_cycles(const struct device *dev, uint32_t channel,
145
147
return - EINVAL ;
146
148
}
147
149
} else {
148
- /* TODO: if the assigned NRF_TIMER supports higher bit
149
- * resolution, use that info in config struct.
150
- */
151
- if (period_cycles > UINT16_MAX ) {
150
+ if (GENERATOR_BITS < 32 &&
151
+ period_cycles > BIT_MASK (GENERATOR_BITS )) {
152
152
LOG_ERR ("Too long period (%u), adjust PWM prescaler!" ,
153
153
period_cycles );
154
154
return - EINVAL ;
@@ -369,7 +369,9 @@ static int pwm_nrf5_sw_init(const struct device *dev)
369
369
/* setup HF timer */
370
370
nrf_timer_mode_set (timer , NRF_TIMER_MODE_TIMER );
371
371
nrf_timer_prescaler_set (timer , config -> prescaler );
372
- nrf_timer_bit_width_set (timer , NRF_TIMER_BIT_WIDTH_16 );
372
+ nrf_timer_bit_width_set (timer ,
373
+ GENERATOR_BITS == 32 ? NRF_TIMER_BIT_WIDTH_32
374
+ : NRF_TIMER_BIT_WIDTH_16 );
373
375
nrf_timer_shorts_enable (timer ,
374
376
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK );
375
377
}
0 commit comments