Only build pairing screen on split central

This commit is contained in:
Joel Spadin 2023-11-05 19:26:26 -06:00
parent 81e301db76
commit 442179d7ea
2 changed files with 16 additions and 11 deletions

View file

@ -53,7 +53,7 @@ config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
endchoice endchoice
if ZMK_BLE if ZMK_BLE && (!ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL)
choice ZMK_DISPLAY_PAIRING_SCREEN choice ZMK_DISPLAY_PAIRING_SCREEN
prompt "Bluetooth pairing screen for displays" prompt "Bluetooth pairing screen for displays"

View file

@ -19,7 +19,12 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/display/status_screen.h> #include <zmk/display/status_screen.h>
#include <zmk/event_manager.h> #include <zmk/event_manager.h>
#if IS_ENABLED(CONFIG_ZMK_BLE)
#define HAS_PAIRING_SCREEN \
(IS_ENABLED(CONFIG_ZMK_DISPLAY_PAIRING_SCREEN_BUILT_IN) || \
IS_ENABLED(CONFIG_ZMK_DISPLAY_PAIRING_SCREEN_CUSTOM))
#if HAS_PAIRING_SCREEN
#include <zmk/ble.h> #include <zmk/ble.h>
#include <zmk/display/pairing_screen.h> #include <zmk/display/pairing_screen.h>
#include <zmk/events/ble_auth_state_changed.h> #include <zmk/events/ble_auth_state_changed.h>
@ -29,7 +34,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
enum screen_type { enum screen_type {
SCREEN_TYPE_STATUS, SCREEN_TYPE_STATUS,
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
SCREEN_TYPE_PAIRING, SCREEN_TYPE_PAIRING,
#endif #endif
}; };
@ -39,12 +44,12 @@ static lv_obj_t *current_screen = NULL;
static bool initialized = false; static bool initialized = false;
static lv_obj_t *status_screen = NULL; static lv_obj_t *status_screen = NULL;
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
static lv_obj_t *pairing_screen = NULL; static lv_obj_t *pairing_screen = NULL;
#endif #endif
__attribute__((weak)) lv_obj_t *zmk_display_status_screen(void) { return NULL; } __attribute__((weak)) lv_obj_t *zmk_display_status_screen(void) { return NULL; }
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
__attribute__((weak)) lv_obj_t *zmk_display_pairing_screen(void) { return NULL; } __attribute__((weak)) lv_obj_t *zmk_display_pairing_screen(void) { return NULL; }
#endif #endif
@ -105,14 +110,14 @@ void zmk_display_blanking_on(void) {
int zmk_display_is_initialized(void) { return initialized; } int zmk_display_is_initialized(void) { return initialized; }
K_MUTEX_DEFINE(screen_state_mutex); K_MUTEX_DEFINE(screen_state_mutex);
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
static struct zmk_ble_auth_state ble_auth_state; static struct zmk_ble_auth_state ble_auth_state;
#endif #endif
static enum screen_type get_screen_type(void) { static enum screen_type get_screen_type(void) {
enum screen_type screen_type = SCREEN_TYPE_STATUS; enum screen_type screen_type = SCREEN_TYPE_STATUS;
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
k_mutex_lock(&screen_state_mutex, K_FOREVER); k_mutex_lock(&screen_state_mutex, K_FOREVER);
if (ble_auth_state.mode != ZMK_BLE_AUTH_MODE_NONE) { if (ble_auth_state.mode != ZMK_BLE_AUTH_MODE_NONE) {
@ -134,7 +139,7 @@ static void update_screen(struct k_work *work) {
new_screen = status_screen; new_screen = status_screen;
break; break;
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
case SCREEN_TYPE_PAIRING: case SCREEN_TYPE_PAIRING:
new_screen = pairing_screen; new_screen = pairing_screen;
break; break;
@ -174,7 +179,7 @@ int zmk_display_init(void) {
zmk_display_initialize_theme(); zmk_display_initialize_theme();
status_screen = zmk_display_status_screen(); status_screen = zmk_display_status_screen();
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
pairing_screen = zmk_display_pairing_screen(); pairing_screen = zmk_display_pairing_screen();
#endif #endif
@ -189,7 +194,7 @@ int zmk_display_init(void) {
return 0; return 0;
} }
#if IS_ENABLED(CONFIG_ZMK_BLE) #if HAS_PAIRING_SCREEN
static int handle_ble_auth_state_changed(const struct zmk_ble_auth_state_changed *ev) { static int handle_ble_auth_state_changed(const struct zmk_ble_auth_state_changed *ev) {
k_mutex_lock(&screen_state_mutex, K_FOREVER); k_mutex_lock(&screen_state_mutex, K_FOREVER);
ble_auth_state = ev->state; ble_auth_state = ev->state;
@ -210,4 +215,4 @@ static int display_event_handler(const zmk_event_t *eh) {
ZMK_LISTENER(display, display_event_handler); ZMK_LISTENER(display, display_event_handler);
ZMK_SUBSCRIPTION(display, zmk_ble_auth_state_changed); ZMK_SUBSCRIPTION(display, zmk_ble_auth_state_changed);
#endif // IS_ENABLED(CONFIG_ZMK_BLE) #endif // HAS_PAIRING_SCREEN