From 8ca2e09d95ce9b44af8a1ca1250e0710f6623e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Tue, 1 Dec 2020 11:36:25 +0100 Subject: [PATCH 1/2] drivers/include: add NETDEV_SX127X --- drivers/include/net/netdev.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 84958b3155..00043cdcd7 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -292,6 +292,7 @@ typedef enum { NETDEV_NRF802154, NETDEV_STM32_ETH, NETDEV_CC110X, + NETDEV_SX127X, /* add more if needed */ } netdev_type_t; /** @} */ From c526a347707fce502f1735484151ee5b8684d018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20H=C3=BC=C3=9Fler?= Date: Tue, 1 Dec 2020 11:38:17 +0100 Subject: [PATCH 2/2] sx127x: make use of netdev_register() Call netdev_register() in sx127x_setup() and pass the index in auto_init_sx127x() and semtech_loramac_init() --- drivers/include/sx127x.h | 4 +++- drivers/sx127x/sx127x.c | 3 ++- pkg/semtech-loramac/contrib/semtech_loramac.c | 2 +- sys/net/gnrc/netif/init_devs/auto_init_sx127x.c | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/include/sx127x.h b/drivers/include/sx127x.h index 02d59382fb..8871685213 100644 --- a/drivers/include/sx127x.h +++ b/drivers/include/sx127x.h @@ -256,8 +256,10 @@ typedef void (sx127x_dio_irq_handler_t)(sx127x_t *dev); * * @param[in] dev Device descriptor * @param[in] params Parameters for device initialization + * @param[in] index Index of @p params in a global parameter struct array. + * If initialized manually, pass a unique identifier instead. */ -void sx127x_setup(sx127x_t *dev, const sx127x_params_t *params); +void sx127x_setup(sx127x_t *dev, const sx127x_params_t *params, uint8_t index); /** * @brief Resets the SX127X diff --git a/drivers/sx127x/sx127x.c b/drivers/sx127x/sx127x.c index 6a48eb1134..4ca4577cda 100644 --- a/drivers/sx127x/sx127x.c +++ b/drivers/sx127x/sx127x.c @@ -73,11 +73,12 @@ static void sx127x_on_dio1_isr(void *arg); static void sx127x_on_dio2_isr(void *arg); static void sx127x_on_dio3_isr(void *arg); -void sx127x_setup(sx127x_t *dev, const sx127x_params_t *params) +void sx127x_setup(sx127x_t *dev, const sx127x_params_t *params, uint8_t index) { netdev_t *netdev = (netdev_t*) dev; netdev->driver = &sx127x_driver; dev->params = *params; + netdev_register(&dev->netdev, NETDEV_SX127X, index); } int sx127x_reset(const sx127x_t *dev) diff --git a/pkg/semtech-loramac/contrib/semtech_loramac.c b/pkg/semtech-loramac/contrib/semtech_loramac.c index 4b42ee2ffc..8ca300089d 100644 --- a/pkg/semtech-loramac/contrib/semtech_loramac.c +++ b/pkg/semtech-loramac/contrib/semtech_loramac.c @@ -830,7 +830,7 @@ void *_semtech_loramac_event_loop(void *arg) int semtech_loramac_init(semtech_loramac_t *mac) { - sx127x_setup(&sx127x, &sx127x_params[0]); + sx127x_setup(&sx127x, &sx127x_params[0], 0); sx127x.netdev.driver = &sx127x_driver; sx127x.netdev.event_callback = _semtech_loramac_event_cb; diff --git a/sys/net/gnrc/netif/init_devs/auto_init_sx127x.c b/sys/net/gnrc/netif/init_devs/auto_init_sx127x.c index 389d5abeab..f85427e433 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_sx127x.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_sx127x.c @@ -57,7 +57,7 @@ void auto_init_sx127x(void) LOG_DEBUG("[auto_init_netif] initializing sx1276 #%u\n", i); #endif - sx127x_setup(&sx127x_devs[i], &sx127x_params[i]); + sx127x_setup(&sx127x_devs[i], &sx127x_params[i], i); if (IS_USED(MODULE_GNRC_NETIF_LORAWAN)) { /* Currently only one lora device is supported */ assert(SX127X_NUMOF == 1);