16
16
17
17
LOG_MODULE_REGISTER (mdm_slm , CONFIG_MODEM_SLM_LOG_LEVEL );
18
18
19
- BUILD_ASSERT (CONFIG_MODEM_SLM_POWER_PIN >= 0 , "Power pin not configured" );
19
+ BUILD_ASSERT (DT_NODE_HAS_PROP ( DT_NODELABEL ( slm_gpio_pins ), power_gpios ) , "Power pin not configured" );
20
20
21
21
#define UART_RX_MARGIN_MS 10
22
22
#define UART_RX_TIMEOUT_US 2000
@@ -78,6 +78,14 @@ static struct k_work_delayable gpio_power_pin_disable_work;
78
78
static slm_ind_handler_t ind_handler ;
79
79
static slm_ind_handler_t ind_handler_backup ;
80
80
81
+ /* TODO: handle if ncs_slm_gpio is set to other than gpio0 */
82
+ static const struct gpio_dt_spec power_pin_member =
83
+ GPIO_DT_SPEC_GET_OR (DT_NODELABEL (slm_gpio_pins ), power_gpios , {0 });
84
+ static const struct gpio_dt_spec indicate_pin_member =
85
+ GPIO_DT_SPEC_GET_OR (DT_NODELABEL (slm_gpio_pins ), indicate_gpios , {0 });
86
+ static const int power_pin_time_ms =
87
+ DT_PROP (DT_NODELABEL (slm_gpio_pins ), power_gpios_active_time_ms );
88
+
81
89
#if defined(CONFIG_MODEM_SLM_SHELL )
82
90
static const struct shell * global_shell ;
83
91
static const char at_usage_str [] = "Usage: slm <at_command>" ;
@@ -99,20 +107,19 @@ static int indicate_pin_enable(void)
99
107
int err = 0 ;
100
108
101
109
if (!indicate_pin_enabled ) {
102
- err = gpio_pin_configure ( gpio_dev , CONFIG_MODEM_SLM_INDICATE_PIN ,
103
- GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW );
110
+ err = gpio_pin_configure_dt ( & indicate_pin_member ,
111
+ GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_LOW );
104
112
if (err ) {
105
113
LOG_ERR ("GPIO config error: %d" , err );
106
114
return err ;
107
115
}
108
116
109
- gpio_init_callback (& gpio_cb , gpio_cb_func , BIT (CONFIG_MODEM_SLM_INDICATE_PIN ));
117
+ gpio_init_callback (& gpio_cb , gpio_cb_func , BIT (indicate_pin_member . pin ));
110
118
err = gpio_add_callback (gpio_dev , & gpio_cb );
111
119
if (err ) {
112
120
LOG_WRN ("GPIO add callback error: %d" , err );
113
121
}
114
- err = gpio_pin_interrupt_configure (gpio_dev , CONFIG_MODEM_SLM_INDICATE_PIN ,
115
- GPIO_INT_LEVEL_LOW );
122
+ err = gpio_pin_interrupt_configure_dt (& indicate_pin_member , GPIO_INT_LEVEL_LOW );
116
123
if (err ) {
117
124
LOG_WRN ("GPIO interrupt configure error: %d" , err );
118
125
}
@@ -128,9 +135,8 @@ static void indicate_pin_disable(void)
128
135
#if (CONFIG_MODEM_SLM_INDICATE_PIN >= 0 )
129
136
if (indicate_pin_enabled ) {
130
137
gpio_remove_callback (gpio_dev , & gpio_cb );
131
- gpio_pin_interrupt_configure (gpio_dev , CONFIG_MODEM_SLM_INDICATE_PIN ,
132
- GPIO_INT_DISABLE );
133
- gpio_pin_configure (gpio_dev , CONFIG_MODEM_SLM_INDICATE_PIN , GPIO_DISCONNECTED );
138
+ gpio_pin_interrupt_configure_dt (& indicate_pin_member , GPIO_INT_DISABLE );
139
+ gpio_pin_configure_dt (& indicate_pin_member , GPIO_DISCONNECTED );
134
140
indicate_pin_enabled = false;
135
141
LOG_DBG ("Indicate pin disabled" );
136
142
}
@@ -141,7 +147,7 @@ static void gpio_power_pin_disable_work_fn(struct k_work *work)
141
147
{
142
148
ARG_UNUSED (work );
143
149
144
- if (gpio_pin_set ( gpio_dev , CONFIG_MODEM_SLM_POWER_PIN , 0 ) != 0 ) {
150
+ if (gpio_pin_set_dt ( & power_pin_member , 0 ) != 0 ) {
145
151
LOG_WRN ("GPIO set error" );
146
152
}
147
153
/* When SLM is woken up, indicate pin must be enabled */
@@ -537,13 +543,13 @@ static struct gpio_callback gpio_cb;
537
543
538
544
static void gpio_cb_func (const struct device * dev , struct gpio_callback * gpio_cb , uint32_t pins )
539
545
{
540
- if ((BIT (CONFIG_MODEM_SLM_INDICATE_PIN ) & pins ) == 0 ) {
546
+ if ((BIT (indicate_pin_member . pin ) & pins ) == 0 ) {
541
547
return ;
542
548
}
543
549
544
550
if (k_work_delayable_is_pending (& gpio_power_pin_disable_work )) {
545
551
(void )k_work_cancel_delayable (& gpio_power_pin_disable_work );
546
- (void )gpio_pin_set ( gpio_dev , CONFIG_MODEM_SLM_POWER_PIN , 0 );
552
+ (void )gpio_pin_set_dt ( & power_pin_member , 0 );
547
553
} else {
548
554
/* Disable indicate pin so that callbacks doesn't keep on coming. */
549
555
indicate_pin_disable ();
@@ -566,9 +572,10 @@ static int gpio_init(void)
566
572
LOG_ERR ("GPIO controller not ready" );
567
573
return - ENODEV ;
568
574
}
575
+ LOG_WRN ("power_pin_member %d" , power_pin_member .pin );
576
+ LOG_WRN ("indicate_pin_member %d" , indicate_pin_member .pin );
569
577
570
- err = gpio_pin_configure (gpio_dev , CONFIG_MODEM_SLM_POWER_PIN ,
571
- GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW );
578
+ err = gpio_pin_configure_dt (& power_pin_member , GPIO_OUTPUT_INACTIVE | GPIO_ACTIVE_LOW );
572
579
if (err ) {
573
580
LOG_ERR ("GPIO config error: %d" , err );
574
581
return err ;
@@ -621,7 +628,7 @@ int modem_slm_uninit(void)
621
628
{
622
629
rx_disable ();
623
630
624
- gpio_pin_configure ( gpio_dev , CONFIG_MODEM_SLM_POWER_PIN , GPIO_DISCONNECTED );
631
+ gpio_pin_configure_dt ( & power_pin_member , GPIO_DISCONNECTED );
625
632
626
633
indicate_pin_disable ();
627
634
@@ -646,7 +653,7 @@ int modem_slm_register_ind(slm_ind_handler_t handler, bool wakeup)
646
653
* Due to errata 4, Always configure PIN_CNF[n].INPUT before PIN_CNF[n].SENSE.
647
654
* At this moment indicate pin has already been configured as INPUT at init_gpio().
648
655
*/
649
- nrf_gpio_cfg_sense_set (CONFIG_MODEM_SLM_INDICATE_PIN , NRF_GPIO_PIN_SENSE_LOW );
656
+ nrf_gpio_cfg_sense_set (indicate_pin_member . pin , NRF_GPIO_PIN_SENSE_LOW );
650
657
}
651
658
652
659
return 0 ;
@@ -663,15 +670,15 @@ int modem_slm_power_pin_toggle(void)
663
670
return 0 ;
664
671
}
665
672
666
- LOG_INF ("Enable power pin" );
673
+ LOG_INF ("Enable power pin for %d ms" , power_pin_time_ms );
667
674
668
- err = gpio_pin_set ( gpio_dev , CONFIG_MODEM_SLM_POWER_PIN , 1 );
675
+ err = gpio_pin_set_dt ( & power_pin_member , 1 );
669
676
if (err ) {
670
677
LOG_ERR ("GPIO set error: %d" , err );
671
678
} else {
672
679
k_work_reschedule (
673
680
& gpio_power_pin_disable_work ,
674
- K_MSEC (CONFIG_MODEM_SLM_POWER_PIN_TIME ));
681
+ K_MSEC (power_pin_time_ms ));
675
682
}
676
683
677
684
return 0 ;
0 commit comments