[riot-notifications] [RIOT-OS/RIOT] drivers/sx126x: Add support for Nucleo -WL55JC (#16579)

José Alamos notifications at github.com
Mon Jun 28 16:28:50 CEST 2021


+1 to the idea of supporting both the SPI and external at the same time. This is something it has shown limitations in the past (e.g samr21-xpro + openlabs).

The pattern described above is similar to the HW-SW "tri-state" case of the Radio HAL, in which either a feature is fully implemented in SW, it's absent because all devices implement it or there's a CAP based interface that distinguish both cases in cases there's a mixture of radios, where some of them implement a feature and some others not.

For this scenario, it can be implemented with minimal #ifdefs like this, although it's just a matter of taste:

```c

static inline void sx126x_periph_hal_reset(sx126x_t *dev)
{
    (void) dev;
    assert(SX126X_SUBGHZ_RADIO):
#if SX126X_SUBGHZ_RADIO
    RCC->CSR |= RCC_CSR_RFRST;
    RCC->CSR &= ~RCC_CSR_RFRST;
    /* it takes 100us for the radio to be ready after reset */
    ztimer_sleep(ZTIMER_USEC, 100);
    
     /* Wait while reset is done */
    while (IsRFUnderReset() != 0UL){}

    /* Asserts the reset signal of the Radio peripheral */
    PWR->SUBGHZSPICR |= PWR_SUBGHZSPICR_NSS;

    /* Enable EXTI 44 : Radio IRQ ITs for CPU1 */
    EXTI_EnableIT_32_63(EXTI_IMR2_IM44);

    /* Enable wakeup signal of the Radio peripheral */
    PWR_SetRadioBusyTrigger(PWR_CR3_EWRFBUSY);

    /* Clear Pending Flag */
    PWR->SCR = PWR_SCR_CWRFBUSYF;

     sx126x_radio_sleepstatus = true;
#endif
     return 0;
}

sx126x_hal_status_t sx126x_hal_reset(const void *context)
{
   DEBUG("[sx126x_hal] reset\n");

   sx126x_t *dev = (sx126x_t *)context;

   if (SX126X_SUBGHZ_RADIO == dev ) {
        sx126x_periph_hal_reset(dev);
   }
   else {
       gpio_set(dev->params->reset_pin);
       gpio_clear(dev->params->reset_pin);
       /* it takes 100us for the radio to be ready after reset */
       ztimer_sleep(ZTIMER_USEC, 100);
       gpio_set(dev->params->reset_pin);
   }
   return 0;
}
```

I think the compiler should be able to optimize out the branches automatically if there's only one kind of radios or both are present. If not, we can add an extra module to differentiate both cases.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16579#issuecomment-869733858
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210628/7edf16b3/attachment.htm>


More information about the notifications mailing list