Skip to content

Commit

Permalink
lib: modem_slm: GPIO to configurable
Browse files Browse the repository at this point in the history
Change GPIO from gpio0 to configurable via application devicetree.

Signed-off-by: Markus Lassila <[email protected]>
  • Loading branch information
MarkusLassila authored and rlubos committed Nov 17, 2023
1 parent d97238f commit 1e177ce
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion doc/nrf/libraries/modem/modem_slm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ Optionally configure the following Kconfig options based on need:
* :kconfig:option:`CONFIG_MODEM_SLM_SHELL` - Enables the shell function in the Modem SLM library, which is not enabled by default.
* :kconfig:option:`CONFIG_MODEM_SLM_INDICATE_PIN` - Configures the optional indicator GPIO, which is not configured by default.

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

.. code-block:: devicetree
/ {
chosen {
ncs,slm-uart = &uart1;
ncs,slm-gpio = &gpio0;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ Modem libraries
* The deprecated Kconfig option ``CONFIG_NRF_MODEM_LIB_SYS_INIT``.
* The deprecated Kconfig option ``CONFIG_NRF_MODEM_LIB_IPC_IRQ_PRIO_OVERRIDE``.

* :ref:`lib_modem_slm`:

* Changed the GPIO used to be configurable using devicetree.

* :ref:`pdn_readme` library:

* Fixed a potential issue where the library tries to free the PDN context twice, causing the application to crash.
Expand Down
16 changes: 10 additions & 6 deletions lib/modem_slm/modem_slm.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ static enum at_cmd_state slm_at_state;
RING_BUF_DECLARE(slm_data_rb, SLM_AT_CMD_RESPONSE_MAX_LEN);
static struct k_work slm_data_work;

#if DT_HAS_CHOSEN(ncs_slm_gpio)
static const struct device *gpio_dev = DEVICE_DT_GET(DT_CHOSEN(ncs_slm_gpio));
#else
static const struct device *gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
#endif
static struct k_work_delayable gpio_wakeup_work;
static slm_ind_handler_t ind_handler;

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

if (gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN, 0) != 0) {
LOG_WRN("GPIO_0 set error");
LOG_WRN("GPIO set error");
}
LOG_DBG("Stop wake-up");
}
Expand Down Expand Up @@ -338,27 +342,27 @@ static int gpio_init(void)
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN,
GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW);
if (err) {
LOG_ERR("GPIO_0 config error: %d", err);
LOG_ERR("GPIO config error: %d", err);
return err;
}

#if (CONFIG_MODEM_SLM_INDICATE_PIN >= 0)
err = gpio_pin_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW);
if (err) {
LOG_ERR("GPIO_0 config error: %d", err);
LOG_ERR("GPIO config error: %d", err);
return err;
}

gpio_init_callback(&gpio_cb, gpio_cb_func, BIT(CONFIG_MODEM_SLM_INDICATE_PIN));
err = gpio_add_callback(gpio_dev, &gpio_cb);
if (err) {
LOG_WRN("GPIO_0 add callback error: %d", err);
LOG_WRN("GPIO add callback error: %d", err);
}
err = gpio_pin_interrupt_configure(gpio_dev, CONFIG_MODEM_SLM_INDICATE_PIN,
GPIO_INT_LEVEL_LOW);
if (err) {
LOG_WRN("GPIO_0 enable callback error: %d", err);
LOG_WRN("GPIO enable callback error: %d", err);
}
#endif

Expand Down Expand Up @@ -447,7 +451,7 @@ int modem_slm_wake_up(void)

err = gpio_pin_set(gpio_dev, CONFIG_MODEM_SLM_WAKEUP_PIN, 1);
if (err) {
LOG_ERR("GPIO_0 set error: %d", err);
LOG_ERR("GPIO set error: %d", err);
} else {
k_work_reschedule(&gpio_wakeup_work, K_MSEC(CONFIG_MODEM_SLM_WAKEUP_TIME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/ {
chosen {
ncs,slm-uart = &uart1;
ncs,slm-gpio = &gpio0;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/ {
chosen {
ncs,slm-uart = &uart2;
ncs,slm-gpio = &gpio0;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/ {
chosen {
ncs,slm-uart = &uart2;
ncs,slm-gpio = &gpio0;
};
};

Expand Down

0 comments on commit 1e177ce

Please sign in to comment.