Skip to content

Commit

Permalink
fix(build): Remove feature-specific code when SPLIT_BLE, RGB_UNDERGLO…
Browse files Browse the repository at this point in the history
…W or BACKLIGHT isn't enabled
  • Loading branch information
DerDreschner committed Jun 26, 2023
1 parent f7fee3e commit 1560cf6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/include/zmk/split/bluetooth/central.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event, bool state);

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
int zmk_split_bt_update_led(struct zmk_periph_led *periph);
int zmk_split_bt_update_bl(struct backlight_state *periph);
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
int zmk_split_bt_update_bl(struct backlight_state *periph);
#endif
6 changes: 5 additions & 1 deletion app/include/zmk/split/bluetooth/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ struct zmk_split_run_behavior_payload {
char behavior_dev[ZMK_SPLIT_RUN_BEHAVIOR_DEV_LEN];
} __packed;

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
struct zmk_split_update_led_data {
uint8_t layer;
uint8_t indicators;
} __packed;
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
struct zmk_split_update_bl_data {
uint8_t brightness;
bool on;
} __packed;
#endif

int zmk_split_bt_position_pressed(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
int zmk_split_bt_position_released(uint8_t position);
6 changes: 6 additions & 0 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ static struct rgb_underglow_state state;

static struct zmk_periph_led led_data;

#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
static bool last_ble_state[2];
#endif

static bool triggered;

Expand Down Expand Up @@ -328,6 +330,7 @@ static void zmk_rgb_underglow_effect_kinesis() {
zmk_rgb_underglow_central_send();
}
#else
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
// leds for peripheral(right) side
/* if (zmk_ble_active_profile_is_open()) {
pixels[0].r = CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE * last_ble_state[0];
Expand Down Expand Up @@ -361,6 +364,7 @@ static void zmk_rgb_underglow_effect_kinesis() {
}
state.animation_step++;
} else {
#endif
// set first led as LED_NUMLOCK
pixels[2].r =
(led_data.indicators & ZMK_LED_NUMLOCK_BIT) * CONFIG_ZMK_RGB_UNDERGLOW_BRT_SCALE;
Expand Down Expand Up @@ -423,8 +427,10 @@ static void zmk_rgb_underglow_effect_kinesis() {
pixels[0].b = 0;
break;
}
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE)
}
#endif
#endif
}

static void zmk_rgb_underglow_effect_test() {
Expand Down
11 changes: 11 additions & 0 deletions app/src/split/bluetooth/central.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *bi
return split_bt_invoke_behavior_payload(wrapper);
}

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
K_THREAD_STACK_DEFINE(split_central_split_led_q_stack,
CONFIG_ZMK_SPLIT_BLE_CENTRAL_SPLIT_LED_STACK_SIZE);

Expand Down Expand Up @@ -686,7 +687,9 @@ int zmk_split_bt_update_led(struct zmk_periph_led *periph) {

return split_bt_update_led_payload(payload);
}
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
K_THREAD_STACK_DEFINE(split_central_split_bl_q_stack,
CONFIG_ZMK_SPLIT_BLE_CENTRAL_SPLIT_BL_STACK_SIZE);

Expand Down Expand Up @@ -744,17 +747,25 @@ int zmk_split_bt_update_bl(struct backlight_state *periph) {

return split_bt_update_bl_payload(payload);
}
#endif

int zmk_split_bt_central_init(const struct device *_arg) {
k_work_queue_start(&split_central_split_run_q, split_central_split_run_q_stack,
K_THREAD_STACK_SIZEOF(split_central_split_run_q_stack),
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
k_work_queue_start(&split_central_split_led_q, split_central_split_led_q_stack,
K_THREAD_STACK_SIZEOF(split_central_split_led_q_stack),
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
k_work_queue_start(&split_central_split_bl_q, split_central_split_bl_q_stack,
K_THREAD_STACK_SIZEOF(split_central_split_bl_q_stack),
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);
#endif

bt_conn_cb_register(&conn_callbacks);

return start_scan();
Expand Down
17 changes: 17 additions & 0 deletions app/src/split/bluetooth/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ static uint8_t num_of_positions = ZMK_KEYMAP_LEN;
static uint8_t position_state[POS_STATE_LEN];

static struct zmk_split_run_behavior_payload behavior_run_payload;

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
static struct zmk_split_update_led_data update_led_data;
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
static struct zmk_split_update_bl_data update_bl_data;
#endif

static ssize_t split_svc_pos_state(struct bt_conn *conn, const struct bt_gatt_attr *attrs,
void *buf, uint16_t len, uint16_t offset) {
Expand Down Expand Up @@ -83,6 +89,7 @@ static ssize_t split_svc_run_behavior(struct bt_conn *conn, const struct bt_gatt
return len;
}

#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW)
static ssize_t split_svc_update_led(struct bt_conn *conn, const struct bt_gatt_attr *attrs,
const void *buf, uint16_t len, uint16_t offset, uint8_t flags) {
struct zmk_split_update_led_data *payload = attrs->user_data;
Expand All @@ -103,7 +110,9 @@ static ssize_t split_svc_update_led(struct bt_conn *conn, const struct bt_gatt_a

return len;
}
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
static ssize_t split_svc_update_bl(struct bt_conn *conn, const struct bt_gatt_attr *attrs,
const void *buf, uint16_t len, uint16_t offset, uint8_t flags) {
struct zmk_split_update_bl_data *payload = attrs->user_data;
Expand All @@ -124,6 +133,7 @@ static ssize_t split_svc_update_bl(struct bt_conn *conn, const struct bt_gatt_at

return len;
}
#endif

static ssize_t split_svc_num_of_positions(struct bt_conn *conn, const struct bt_gatt_attr *attrs,
void *buf, uint16_t len, uint16_t offset) {
Expand All @@ -143,12 +153,19 @@ BT_GATT_SERVICE_DEFINE(
BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_RUN_BEHAVIOR_UUID),
BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE_ENCRYPT, NULL,
split_svc_run_behavior, &behavior_run_payload),

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_UPDATE_LED_UUID),
BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE_ENCRYPT, NULL,
split_svc_update_led, &update_led_data),
#endif

#if IS_ENABLED(CONFIG_ZMK_BACKLIGHT)
BT_GATT_CHARACTERISTIC(BT_UUID_DECLARE_128(ZMK_SPLIT_BT_CHAR_UPDATE_BL_UUID),
BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE_ENCRYPT, NULL,
split_svc_update_bl, &update_bl_data),
#endif

BT_GATT_DESCRIPTOR(BT_UUID_NUM_OF_DIGITALS, BT_GATT_PERM_READ, split_svc_num_of_positions, NULL,
&num_of_positions), );

Expand Down

0 comments on commit 1560cf6

Please sign in to comment.