Skip to content

Commit 5bfea38

Browse files
pdunajcarlescufi
authored andcommitted
[nrf fromlist] drivers: pwm: Restore default on re-initialization
Device data is cleared on deinitialization. This operation removes some important information. Let's restore the defaults each time the device is initialized. Upstream PR:zephyrproject-rtos/zephyr#38615 Jira:NCSDK-11329 Signed-off-by: Pawel Dunaj <[email protected]>
1 parent 3ef7602 commit 5bfea38

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

drivers/pwm/pwm_nrfx.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ static const struct pwm_driver_api pwm_nrfx_drv_api_funcs = {
268268
static int pwm_nrfx_init(const struct device *dev)
269269
{
270270
const struct pwm_nrfx_config *config = dev->config;
271+
struct pwm_nrfx_data *data = dev->data;
272+
273+
for (size_t i = 0; i < ARRAY_SIZE(data->current); i++) {
274+
bool inverted = config->initial_config.output_pins[i] & NRFX_PWM_PIN_INVERTED;
275+
uint16_t value = (inverted)?(PWM_NRFX_CH_VALUE_INVERTED):(PWM_NRFX_CH_VALUE_NORMAL);
276+
277+
data->current[i] = value;
278+
};
271279

272280
nrfx_err_t result = nrfx_pwm_init(&config->pwm,
273281
&config->initial_config,
@@ -375,23 +383,12 @@ static int pwm_nrfx_pm_control(const struct device *dev,
375383
(PWM_NRFX_CH_PIN(dev_idx, ch_idx) | \
376384
(PWM_NRFX_IS_INVERTED(dev_idx, ch_idx) ? NRFX_PWM_PIN_INVERTED : 0))
377385

378-
#define PWM_NRFX_DEFAULT_VALUE(dev_idx, ch_idx) \
379-
(PWM_NRFX_IS_INVERTED(dev_idx, ch_idx) ? \
380-
PWM_NRFX_CH_VALUE_INVERTED : PWM_NRFX_CH_VALUE_NORMAL)
381-
382386
#define PWM_NRFX_COUNT_MODE(dev_idx) \
383387
(PWM_PROP(dev_idx, center_aligned) ? \
384388
NRF_PWM_MODE_UP_AND_DOWN : NRF_PWM_MODE_UP)
385389

386390
#define PWM_NRFX_DEVICE(idx) \
387-
static struct pwm_nrfx_data pwm_nrfx_##idx##_data = { \
388-
.current = { \
389-
PWM_NRFX_DEFAULT_VALUE(idx, 0), \
390-
PWM_NRFX_DEFAULT_VALUE(idx, 1), \
391-
PWM_NRFX_DEFAULT_VALUE(idx, 2), \
392-
PWM_NRFX_DEFAULT_VALUE(idx, 3), \
393-
} \
394-
}; \
391+
static struct pwm_nrfx_data pwm_nrfx_##idx##_data; \
395392
static const struct pwm_nrfx_config pwm_nrfx_##idx##config = { \
396393
.pwm = NRFX_PWM_INSTANCE(idx), \
397394
.initial_config = { \

0 commit comments

Comments
 (0)