Skip to content

Commit d11c518

Browse files
maje-embrlubos
authored andcommitted
samples: peripheral_power_profiling: Add Kconfig option to disable LEDs
Add Kconfig option to disable LEDs for power saving. Signed-off-by: Marcin Jelinski <[email protected]>
1 parent e968a58 commit d11c518

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

samples/bluetooth/peripheral_power_profiling/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ config BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MAX
7171
help
7272
Non-connectable advertising maximum interval in 0.625 milliseconds unit.
7373

74+
config BT_POWER_PROFILING_LED_DISABLED
75+
bool "Disable LEDs"
76+
help
77+
Disables the LEDs to reduce power consumption.
78+
7479
config SETTINGS
7580
default y
7681

samples/bluetooth/peripheral_power_profiling/README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MIN - Non-connectable adv
218218
CONFIG_BT_POWER_PROFILING_NON_CONNECTABLE_ADV_INTERVAL_MAX - Non-connectable advertising maximum interval
219219
Sets the non-connectable advertising maximum interval in 0.625 milliseconds unit.
220220

221+
.. _CONFIG_BT_POWER_PROFILING_LED_DISABLED:
222+
223+
CONFIG_BT_POWER_PROFILING_LED_DISABLED - Disable LEDs
224+
Disables the LEDs to reduce power consumption.
225+
221226
Building and running
222227
********************
223228

samples/bluetooth/peripheral_power_profiling/src/main.c

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,46 @@ static const struct bt_le_adv_param *non_connectable_ad_params =
112112
NON_CONNECTABLE_ADV_INTERVAL_MAX,
113113
NULL);
114114

115+
static int leds_init(void)
116+
{
117+
if (IS_ENABLED(CONFIG_BT_POWER_PROFILING_LED_DISABLED)) {
118+
return 0;
119+
} else {
120+
return dk_leds_init();
121+
}
122+
}
123+
124+
static int set_led(uint8_t led_idx, uint32_t val)
125+
{
126+
if (IS_ENABLED(CONFIG_BT_POWER_PROFILING_LED_DISABLED)) {
127+
ARG_UNUSED(led_idx);
128+
ARG_UNUSED(val);
129+
return 0;
130+
} else {
131+
return dk_set_led(led_idx, val);
132+
}
133+
}
134+
135+
static int set_led_on(uint8_t led_idx)
136+
{
137+
if (IS_ENABLED(CONFIG_BT_POWER_PROFILING_LED_DISABLED)) {
138+
ARG_UNUSED(led_idx);
139+
return 0;
140+
} else {
141+
return dk_set_led_on(led_idx);
142+
}
143+
}
144+
145+
static int set_led_off(uint8_t led_idx)
146+
{
147+
if (IS_ENABLED(CONFIG_BT_POWER_PROFILING_LED_DISABLED)) {
148+
ARG_UNUSED(led_idx);
149+
return 0;
150+
} else {
151+
return dk_set_led_off(led_idx);
152+
}
153+
}
154+
115155
static void nfc_callback(void *context, nfc_t2t_event_t event, const uint8_t *data,
116156
size_t data_length)
117157
{
@@ -127,12 +167,12 @@ static void nfc_callback(void *context, nfc_t2t_event_t event, const uint8_t *da
127167
return;
128168
}
129169

130-
dk_set_led_on(NFC_FIELD_STATUS_LED);
170+
set_led_on(NFC_FIELD_STATUS_LED);
131171
adv_permission = true;
132172
break;
133173

134174
case NFC_T2T_EVENT_FIELD_OFF:
135-
dk_set_led_off(NFC_FIELD_STATUS_LED);
175+
set_led_off(NFC_FIELD_STATUS_LED);
136176
break;
137177

138178
case NFC_T2T_EVENT_DATA_READ:
@@ -162,14 +202,14 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
162202
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
163203
printk("Connected %s\n", addr);
164204

165-
dk_set_led_on(CON_STATUS_LED);
205+
set_led_on(CON_STATUS_LED);
166206
}
167207

168208
static void disconnected(struct bt_conn *conn, uint8_t reason)
169209
{
170210
printk("Disconnected, reason 0x%02x %s\n", reason, bt_hci_err_to_str(reason));
171211

172-
dk_set_led_off(CON_STATUS_LED);
212+
set_led_off(CON_STATUS_LED);
173213

174214
atomic_set(&notify_pipeline, NOTIFICATION_PIPELINE_SIZE);
175215

@@ -627,7 +667,7 @@ static void system_off(void)
627667
/* Clear the reset reason if it didn't do previously. */
628668
nrfx_reset_reason_clear(nrfx_reset_reason_get());
629669

630-
dk_set_led_off(RUN_STATUS_LED);
670+
set_led_off(RUN_STATUS_LED);
631671

632672
if (IS_ENABLED(CONFIG_PM_DEVICE) && IS_ENABLED(CONFIG_SERIAL)) {
633673
static const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
@@ -689,7 +729,7 @@ int main(void)
689729
/* Read the button state after booting to check if advertising start is needed. */
690730
dk_read_buttons(&button_state, &has_changed);
691731

692-
err = dk_leds_init();
732+
err = leds_init();
693733
if (err) {
694734
printk("LEDs init failed (err %d)\n", err);
695735
return 0;
@@ -754,7 +794,7 @@ int main(void)
754794
}
755795

756796
for (;;) {
757-
dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
797+
set_led(RUN_STATUS_LED, (++blink_status) % 2);
758798
k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
759799
}
760800
}

0 commit comments

Comments
 (0)