1919
2020LOG_MODULE_REGISTER (main );
2121
22+ #define HAS_DBG_BUTTON_2 DT_NODE_EXISTS(DBG_BUTTON_2_NODE)
23+ #define HAS_DBG_BUTTON_3 DT_NODE_EXISTS(DBG_BUTTON_3_NODE)
24+
2225// --- GPIOs ---
2326const struct gpio_dt_spec ble_cnfg_ready =
2427 GPIO_DT_SPEC_GET (BLE_CNFG_READY_NODE , gpios );
2528const struct gpio_dt_spec led = GPIO_DT_SPEC_GET (LED_NODE , gpios );
2629const struct gpio_dt_spec data_ready = GPIO_DT_SPEC_GET (DATA_READY_NODE , gpios );
30+ #if HAS_DBG_BUTTON_2
2731const struct gpio_dt_spec dbg_button_2 =
2832 GPIO_DT_SPEC_GET (DBG_BUTTON_2_NODE , gpios );
33+ #endif
34+ #if HAS_DBG_BUTTON_3
2935const struct gpio_dt_spec dbg_button_3 =
3036 GPIO_DT_SPEC_GET (DBG_BUTTON_3_NODE , gpios );
37+ #endif
3138
3239// callback for data-ready GPIO interrupt, triggering SPIM transfer
3340struct gpio_callback data_ready_cb ;
41+ #if HAS_DBG_BUTTON_2
3442struct gpio_callback dbg_button_2_cb ;
43+ #endif
44+ #if HAS_DBG_BUTTON_3
3545struct gpio_callback dbg_button_3_cb ;
46+ #endif
3647
3748int64_t last_gpio_interrupt_time = 0 ;
3849static void gpio_interrupt_handler (const struct device * dev ,
@@ -120,17 +131,28 @@ int main(void)
120131
121132 LOG_INF ("Initializing GPIOs..." );
122133 if (!gpio_is_ready_dt (& led ) || !gpio_is_ready_dt (& data_ready ) ||
123- !gpio_is_ready_dt (& ble_cnfg_ready ) || !gpio_is_ready_dt (& dbg_button_2 ) ||
124- !gpio_is_ready_dt (& dbg_button_3 ))
134+ !gpio_is_ready_dt (& ble_cnfg_ready )
135+ #if HAS_DBG_BUTTON_2
136+ || !gpio_is_ready_dt (& dbg_button_2 )
137+ #endif
138+ #if HAS_DBG_BUTTON_3
139+ || !gpio_is_ready_dt (& dbg_button_3 )
140+ #endif
141+ )
125142 {
126143 LOG_ERR ("GPIO devices not ready." );
127144 return 0 ;
128145 }
129146 err = gpio_pin_configure_dt (& led , GPIO_OUTPUT_LOW ) |
130147 gpio_pin_configure_dt (& ble_cnfg_ready , GPIO_OUTPUT_LOW ) |
131- gpio_pin_configure_dt (& data_ready , GPIO_INPUT ) |
132- gpio_pin_configure_dt (& dbg_button_2 , GPIO_INPUT ) |
133- gpio_pin_configure_dt (& dbg_button_3 , GPIO_INPUT );
148+ gpio_pin_configure_dt (& data_ready , GPIO_INPUT )
149+ #if HAS_DBG_BUTTON_2
150+ | gpio_pin_configure_dt (& dbg_button_2 , GPIO_INPUT )
151+ #endif
152+ #if HAS_DBG_BUTTON_3
153+ | gpio_pin_configure_dt (& dbg_button_3 , GPIO_INPUT )
154+ #endif
155+ ;
134156 if (err < 0 )
135157 {
136158 LOG_ERR ("Error configuring GPIO pins" );
@@ -149,15 +171,19 @@ int main(void)
149171 return err ;
150172 }
151173
174+ #if HAS_DBG_BUTTON_2
152175 gpio_init_callback (& dbg_button_2_cb , dbg_button_2_handler ,
153176 BIT (dbg_button_2 .pin ));
154177 gpio_add_callback_dt (& dbg_button_2 , & dbg_button_2_cb );
155178 gpio_pin_interrupt_configure_dt (& dbg_button_2 , GPIO_INT_EDGE_TO_ACTIVE );
179+ #endif
156180
181+ #if HAS_DBG_BUTTON_3
157182 gpio_init_callback (& dbg_button_3_cb , dbg_button_3_handler ,
158183 BIT (dbg_button_3 .pin ));
159184 gpio_add_callback_dt (& dbg_button_3 , & dbg_button_3_cb );
160185 gpio_pin_interrupt_configure_dt (& dbg_button_3 , GPIO_INT_EDGE_TO_ACTIVE );
186+ #endif
161187
162188 LOG_INF ("Initializing settings subsystem" );
163189 err = settings_subsys_init ();
0 commit comments