Skip to content

Commit 1e177ce

Browse files
MarkusLassilarlubos
authored andcommitted
lib: modem_slm: GPIO to configurable
Change GPIO from gpio0 to configurable via application devicetree. Signed-off-by: Markus Lassila <[email protected]>
1 parent d97238f commit 1e177ce

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

doc/nrf/libraries/modem/modem_slm.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ Optionally configure the following Kconfig options based on need:
4141
* :kconfig:option:`CONFIG_MODEM_SLM_SHELL` - Enables the shell function in the Modem SLM library, which is not enabled by default.
4242
* :kconfig:option:`CONFIG_MODEM_SLM_INDICATE_PIN` - Configures the optional indicator GPIO, which is not configured by default.
4343

44-
The application must use Zephyr chosen nodes in devicetree to select UART device. For example:
44+
The application must use Zephyr ``chosen`` nodes in devicetree to select UART device.
45+
Additionally, GPIO can also be selected.
46+
For example:
4547

4648
.. code-block:: devicetree
4749
4850
/ {
4951
chosen {
5052
ncs,slm-uart = &uart1;
53+
ncs,slm-gpio = &gpio0;
5154
};
5255
};
5356

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ Modem libraries
453453
* The deprecated Kconfig option ``CONFIG_NRF_MODEM_LIB_SYS_INIT``.
454454
* The deprecated Kconfig option ``CONFIG_NRF_MODEM_LIB_IPC_IRQ_PRIO_OVERRIDE``.
455455

456+
* :ref:`lib_modem_slm`:
457+
458+
* Changed the GPIO used to be configurable using devicetree.
459+
456460
* :ref:`pdn_readme` library:
457461

458462
* Fixed a potential issue where the library tries to free the PDN context twice, causing the application to crash.

lib/modem_slm/modem_slm.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ static enum at_cmd_state slm_at_state;
4242
RING_BUF_DECLARE(slm_data_rb, SLM_AT_CMD_RESPONSE_MAX_LEN);
4343
static struct k_work slm_data_work;
4444

45+
#if DT_HAS_CHOSEN(ncs_slm_gpio)
46+
static const struct device *gpio_dev = DEVICE_DT_GET(DT_CHOSEN(ncs_slm_gpio));
47+
#else
4548
static const struct device *gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
49+
#endif
4650
static struct k_work_delayable gpio_wakeup_work;
4751
static slm_ind_handler_t ind_handler;
4852

@@ -59,7 +63,7 @@ static void gpio_wakeup_wk(struct k_work *work)
5963
ARG_UNUSED(work);
6064

6165
if (gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN, 0) != 0) {
62-
LOG_WRN("GPIO_0 set error");
66+
LOG_WRN("GPIO set error");
6367
}
6468
LOG_DBG("Stop wake-up");
6569
}
@@ -338,27 +342,27 @@ static int gpio_init(void)
338342
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN,
339343
GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW);
340344
if (err) {
341-
LOG_ERR("GPIO_0 config error: %d", err);
345+
LOG_ERR("GPIO config error: %d", err);
342346
return err;
343347
}
344348

345349
#if (CONFIG_MODEM_SLM_INDICATE_PIN >= 0)
346350
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
347351
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW);
348352
if (err) {
349-
LOG_ERR("GPIO_0 config error: %d", err);
353+
LOG_ERR("GPIO config error: %d", err);
350354
return err;
351355
}
352356

353357
gpio_init_callback(&gpio_cb, gpio_cb_func, BIT(CONFIG_MODEM_SLM_INDICATE_PIN));
354358
err = gpio_add_callback(gpio_dev, &gpio_cb);
355359
if (err) {
356-
LOG_WRN("GPIO_0 add callback error: %d", err);
360+
LOG_WRN("GPIO add callback error: %d", err);
357361
}
358362
err = gpio_pin_interrupt_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
359363
GPIO_INT_LEVEL_LOW);
360364
if (err) {
361-
LOG_WRN("GPIO_0 enable callback error: %d", err);
365+
LOG_WRN("GPIO enable callback error: %d", err);
362366
}
363367
#endif
364368

@@ -447,7 +451,7 @@ int modem_slm_wake_up(void)
447451

448452
err = gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN, 1);
449453
if (err) {
450-
LOG_ERR("GPIO_0 set error: %d", err);
454+
LOG_ERR("GPIO set error: %d", err);
451455
} else {
452456
k_work_reschedule(&gpio_wakeup_work, K_MSEC(CONFIG_MODEM_SLM_WAKEUP_TIME));
453457
}

samples/cellular/slm_shell/boards/nrf52840dk_nrf52840.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/ {
88
chosen {
99
ncs,slm-uart = &uart1;
10+
ncs,slm-gpio = &gpio0;
1011
};
1112
};
1213

samples/cellular/slm_shell/boards/nrf5340dk_nrf5340_cpuapp.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/ {
88
chosen {
99
ncs,slm-uart = &uart2;
10+
ncs,slm-gpio = &gpio0;
1011
};
1112
};
1213

samples/cellular/slm_shell/boards/nrf7002dk_nrf5340_cpuapp.overlay

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/ {
88
chosen {
99
ncs,slm-uart = &uart2;
10+
ncs,slm-gpio = &gpio0;
1011
};
1112
};
1213

0 commit comments

Comments
 (0)