Using nrfx drivers with Zephyr device tree

I'd like to use playback feature of PWM. There is NRFX function for that: nrfx_pwm_complex_playback(). This function, like other NRFX drivers, needs appropriate instance structure, here it's nrfx_pwm_t. The instance variable can be created with NRFX_PWM_INSTANCE. But now we have NCS and device trees. I already have PWM in device tree and I use it with functions such as pwm_set_dt(). How can I use nrfx_pwm_complex_playback() now? I don't see any way to initialize nrfx_pwm_t variable using pwm_dt_spec variable. Should I use NCS device tree and old NRFX device instance at the same time? It would give messy code.

Parents Reply
  • Hi!

    Yes, I know I can use the nrfx driver and I have seen this example. My concern is the coexistence of device tree and nrfx. For example I have the PWM pin configured in device tree. With nrfx I need to configure it second time with NRFX_PWM_DEFAULT_CONFIG() macro. It's not flexible and can lead to mistakes. So I'm looking for a way in which nrfx driver could use config from device tree. This is what I came up with:

    static const struct pwm_dt_spec buzzer = PWM_DT_SPEC_GET(DT_NODELABEL(buzzer_pwm));
    
    const nrfx_pwm_t *pwm = buzzer.dev->config;
    const int PLAYBACK_COUNT = 1;
    nrf_pwm_sequence_t seq[2]; //not initialized, but this is just an example
    nrfx_pwm_t instance;
    instance.p_reg = pwm->p_reg;
    nrfx_pwm_complex_playback(&instance, &seq[0], &seq[1], PLAYBACK_COUNT, NRFX_PWM_FLAG_LOOP);

Children
No Data
Related