I want to use ppi to drive PWM. Attachment is my code files, it can't work.
How should I configure it.
I want to use ppi to drive PWM. Attachment is my code files, it can't work.
How should I configure it.
bool pwm_play_ppi_task_event_init(pwm_play_t *pp)
{
#if defined(__ZEPHYR__)
//Has IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?
// IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE_INST_GET(0)), IRQ_PRIO_LOWEST,
// NRFX_GPIOTE_INST_HANDLER_GET(0), 0, 0);
#endif
nrfx_err_t err;
if(NULL == pp)return false;
nrfx_gpiote_trigger_config_t trigger_config = {
.trigger = pp->trigger,
.p_in_channel = &pp->gpiote_channel,
};
nrfx_gpiote_input_pin_config_t input_pin_config = {
.p_trigger_config = &trigger_config,
.p_pull_config = &pp->pin_pull,
.p_handler_config = &pp->gpiote_handler,
};
err = nrfx_gpiote_init(&pp->gpiote, NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
if (err != NRFX_SUCCESS && err != NRFX_ERROR_ALREADY) {
LOG_ERR("gpiote_init failed with: %x\n", err);
return false;
}
err = nrfx_gpiote_channel_alloc(&pp->gpiote, &pp->gpiote_channel);
if (err != NRFX_SUCCESS) {
LOG_ERR("gpiote_channel_alloc failed with: %x\n", err);
return false;
}
err = nrfx_gpiote_input_configure(&pp->gpiote, pp->pin, &input_pin_config);
if (err != NRFX_SUCCESS) {
LOG_ERR("gpiote_input_configure failed with: %x\n", err);
return false;
}
nrfx_gpiote_trigger_enable(&pp->gpiote, pp->pin, true);
err = nrfx_gppi_channel_alloc(&pp->gppi_channel);
if (err != NRFX_SUCCESS) {
LOG_ERR("gppi_channel_alloc failed with: %x\n", err);
return false;
}
nrfx_gppi_channel_endpoints_setup(pp->gppi_channel,
nrfx_gpiote_in_event_address_get(&pp->gpiote, pp->pin), pp->task_addres);
LOG_INF("gppi_channel %u, gpiote_channel %u, task_addres %u", pp->gppi_channel, pp->gpiote_channel, pp->task_addres);
return true;
}
These code can work.
bool pwm_play_ppi_task_event_init(pwm_play_t *pp)
{
#if defined(__ZEPHYR__)
//Has IRQ_CONNECT or IRQ_DIRECT_CONNECT accidentally been invoked on the same irq multiple times?
// IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE_INST_GET(0)), IRQ_PRIO_LOWEST,
// NRFX_GPIOTE_INST_HANDLER_GET(0), 0, 0);
#endif
nrfx_err_t err;
if(NULL == pp)return false;
nrfx_gpiote_trigger_config_t trigger_config = {
.trigger = pp->trigger,
.p_in_channel = &pp->gpiote_channel,
};
nrfx_gpiote_input_pin_config_t input_pin_config = {
.p_trigger_config = &trigger_config,
.p_pull_config = &pp->pin_pull,
.p_handler_config = &pp->gpiote_handler,
};
err = nrfx_gpiote_init(&pp->gpiote, NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
if (err != NRFX_SUCCESS && err != NRFX_ERROR_ALREADY) {
LOG_ERR("gpiote_init failed with: %x\n", err);
return false;
}
err = nrfx_gpiote_channel_alloc(&pp->gpiote, &pp->gpiote_channel);
if (err != NRFX_SUCCESS) {
LOG_ERR("gpiote_channel_alloc failed with: %x\n", err);
return false;
}
err = nrfx_gpiote_input_configure(&pp->gpiote, pp->pin, &input_pin_config);
if (err != NRFX_SUCCESS) {
LOG_ERR("gpiote_input_configure failed with: %x\n", err);
return false;
}
nrfx_gpiote_trigger_enable(&pp->gpiote, pp->pin, true);
err = nrfx_gppi_channel_alloc(&pp->gppi_channel);
if (err != NRFX_SUCCESS) {
LOG_ERR("gppi_channel_alloc failed with: %x\n", err);
return false;
}
nrfx_gppi_channel_endpoints_setup(pp->gppi_channel,
nrfx_gpiote_in_event_address_get(&pp->gpiote, pp->pin), pp->task_addres);
LOG_INF("gppi_channel %u, gpiote_channel %u, task_addres %u", pp->gppi_channel, pp->gpiote_channel, pp->task_addres);
return true;
}
These code can work.