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

Francisco notifications at github.com
Mon Jun 28 09:21:15 CEST 2021


@fjmolinas commented on this pull request.

In general I think there is a problem with the `ifdef CPU...` approach, it does not allow for example for the `BOARD` to have an sx1276x breakout + subghz, I think this should be handled differently.

When working on this the method I came up with was  forward declaring the `subghz` `sx126x descriptor and then using that for conditional initalization:

```c
#if defined(CPU_FAM_STM32WL) && IS_ACTIVE(MODULE_SX126X)
/**
 * @name    Sub-GHz radio (LoRa) configuration
 * @{
 */
#define SX126X_PARAM_SPI                    (SPI_DEV(1))
#define SX126X_PARAM_REGULATOR     SX126X_REG_MODE_LDO
/* forward declaration */
typedef struct sx126x sx126x_t;
extern sx126x_t *sx126x_subghz;
#define SX126X_SUBGHZ_RADIO                 sx126x_subghz
/** @} */
#endif
```

So for example for the reset function:

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

    sx126x_t *dev = (sx126x_t *)context;

#ifdef SX126X_SUBGHZ_RADIO
    if (SX126X_SUBGHZ_RADIO == dev ) {
        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;
        return 0;
    }
#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);
#endif
    return 0;
}
```

Do you have another suggestion @jia200x @akshaim ?



-- 
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#pullrequestreview-693628674
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210628/6860bd12/attachment-0001.htm>


More information about the notifications mailing list