NRFX PWM Pin Polarity

Hello,

I'm using NRFX PWM directly because I need something more custom than zephyr's PWM driver provides. I'm trying to understand what .pin_polarity field in the config does. It does not seem to invert the polarity of the signal.

All .pin_polarity seems to be doing is setting the pin value after PWM has stopped.

.pin_polarity = {true, true, false, false}

.pin_polarity = {false, false, false, false}

-------------------
nrf_pwm_values_individual_t pwm_vals[] = { { 800, 0, 0, 800 },
{ 0, 800, 0, 800 },
{ 0, 0, 0, 800 },
{ 0, 0, 0, 800 } };
nrfx_pwm_t pwm_instance = NRFX_PWM_INSTANCE(HEARTBEATPWM_INST_IDX);

nrfx_pwm_config_t config = {
.output_pins = { 22, 23, NRF_PWM_PIN_NOT_CONNECTED, NRF_PWM_PIN_NOT_CONNECTED },
.pin_inverted = { false, false, false, false },
.irq_priority = NRFX_PWM_DEFAULT_CONFIG_IRQ_PRIORITY,
.base_clock = NRF_PWM_CLK_16MHz,
.count_mode = NRF_PWM_MODE_UP,
.top_value = 800, // 50 µs period (16MHz / 1 prescaler)
.load_mode = NRF_PWM_LOAD_WAVE_FORM,
.step_mode = NRF_PWM_STEP_AUTO,
};

status = nrfx_pwm_init(&pwm_instance, &config, pwm_handler, &pwm_instance);
nrf_pwm_sequence_t seq = { .values.p_individual = pwm_vals,
.length = NRF_PWM_VALUES_LENGTH(pwm_vals),
.repeats = 0,
.end_delay = 0 };

nrfx_pwm_simple_playback(&pwm_instance, &seq, 100, NRFX_PWM_FLAG_LOOP);
-------------------
Is the only way to invert polarity by setting MSB of the PWM to 1 (eg: 800 | (1 << 15))?
Also, I'm a little confused why the default "active" state is LOW. Is that expected?
Related