Skip to content

Fix an issue that charging via usb port will close ble#681

Open
L1cardo wants to merge 1 commit intoHaoboGu:mainfrom
L1cardo:patch-1
Open

Fix an issue that charging via usb port will close ble#681
L1cardo wants to merge 1 commit intoHaoboGu:mainfrom
L1cardo:patch-1

Conversation

@L1cardo
Copy link

@L1cardo L1cardo commented Dec 21, 2025

In the current implementation, as long as the USB cable is plugged in and voltage (VBUS) is detected, the enabled callback will trigger and emit the USB_ENABLED signal, which causes the keyboard to try to switch to USB mode and turn off Bluetooth regardless of whether it is connected to a computer or a charger.

My solution is to move the timing of triggering the USB_ENABLED signal from enabled (only powered on) to configured (the computer host has configured the device).
This way:

  1. When connected to the charger: only enabled will be triggered and the USB_ENABLED signal will not be sent. The keyboard will maintain the Bluetooth connection or continue to broadcast.
  2. When connected to the computer: the host will configure the device, trigger configured, send the USB_ENABLED signal, and switch the keyboard to USB mode.

目前的实现中,只要USB 线插入并检测到电压(VBUS),enabled 回调就会触发并发出 USB_ENABLED 信号,这导致键盘无论连接的是电脑还是充电器,都会尝试切换到 USB 模式并关闭蓝牙。

我的方案是将触发 USB_ENABLED 信号的时机从 enabled(仅通电)移动到 configured(电脑主机已配置设备)。
这样:
1.连接充电器时:只会触发 enabled,不会发出 USB_ENABLED信号,键盘将保持蓝牙连接或继续广播。
2. 连接电脑时:主机会配置设备,触发 configured,发出 USB_ENABLED信号,键盘场换到 USB 模式。

@github-actions
Copy link

Binary Size Report

use_config/nrf52832_ble

 text data bss dec hex	filename 319328 5072 31676 356076 56eec	rmk-nrf52832 
Diff
 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_config/nrf52840_ble

 text data bss dec hex	filename 356108 5072 44788 405968 631d0	rmk-nrf52840 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.0% +177 [ = ] 0 .debug_info +0.0% +95 [ = ] 0 .debug_line +0.1% +64 [ = ] 0 .symtab +0.0% +56 +0.0% +56 .text +0.0% +50 [ = ] 0 .strtab +0.0% +44 [ = ] 0 .debug_str +0.1% +36 [ = ] 0 .debug_frame +0.0% +16 [ = ] 0 .debug_aranges +0.0% +16 [ = ] 0 .debug_ranges +0.0% +11 [ = ] 0 .debug_loc +15% +7 [ = ] 0 [Unmapped] +0.0% +572 +0.0% +56 TOTAL 

use_config/nrf52840_ble_split

 text data bss dec hex	filename 429584 6376 43236 479196 74fdc	central text data bss dec hex	filename 282832 5740 25820 314392 4cc18	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +178 [ = ] 0 .debug_info +0.0% +95 [ = ] 0 .debug_line +0.0% +64 [ = ] 0 .symtab +0.0% +56 +0.0% +56 .text +0.0% +50 [ = ] 0 .strtab +0.0% +44 [ = ] 0 .debug_str +0.1% +36 [ = ] 0 .debug_frame +0.0% +16 [ = ] 0 .debug_aranges +0.0% +16 [ = ] 0 .debug_ranges +31% +14 [ = ] 0 [Unmapped] +0.0% +11 [ = ] 0 .debug_loc +0.0% +580 +0.0% +56 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_rust/nrf52840_ble_split

 text data bss dec hex	filename 434876 6376 48860 490112 77a80	central text data bss dec hex	filename 281164 5196 24588 310948 4bea4	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +178 [ = ] 0 .debug_info +0.0% +95 [ = ] 0 .debug_line +0.0% +64 [ = ] 0 .symtab +0.0% +56 +0.0% +56 .text +0.0% +50 [ = ] 0 .strtab +0.0% +44 [ = ] 0 .debug_str +0.1% +36 [ = ] 0 .debug_frame +0.0% +16 [ = ] 0 .debug_aranges +0.0% +16 [ = ] 0 .debug_ranges +0.0% +11 [ = ] 0 .debug_loc -38.2% -26 [ = ] 0 [Unmapped] +0.0% +540 +0.0% +56 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_config/pi_pico_w_ble

 text data bss dec hex	filename 590756 0 53108 643864 9d318	rmk-pi-pico-w 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.0% +340 [ = ] 0 .debug_info +0.0% +81 [ = ] 0 .debug_loc +0.0% +60 +0.0% +60 .text +0.0% +55 [ = ] 0 .debug_line +21% +8 [ = ] 0 [Unmapped] +0.0% +4 [ = ] 0 .debug_frame +0.0% +548 +0.0% +60 TOTAL 

use_config/pi_pico_w_ble_split

 text data bss dec hex	filename 623876 0 59788 683664 a6e90	central text data bss dec hex	filename 495660 0 41880 537540 833c4	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +346 [ = ] 0 .debug_info +0.0% +81 [ = ] 0 .debug_loc +0.0% +60 +0.0% +60 .text +0.0% +55 [ = ] 0 .debug_line +0.0% +4 [ = ] 0 .debug_frame +4.9% +2 [ = ] 0 [Unmapped] +0.0% +548 +0.0% +60 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_rust/pi_pico_w_ble_split

 text data bss dec hex	filename 624008 0 60100 684108 a704c	central text data bss dec hex	filename 495996 0 41880 537876 83514	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +346 [ = ] 0 .debug_info +0.0% +81 [ = ] 0 .debug_loc +0.0% +60 +0.0% +60 .text +0.0% +55 [ = ] 0 .debug_line +18% +6 [ = ] 0 [Unmapped] +0.0% +4 [ = ] 0 .debug_frame +0.0% +552 +0.0% +60 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_config/rp2040

 text data bss dec hex	filename 135608 0 14636 150244 24ae4	rmk-rp2040 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.0% +108 [ = ] 0 .debug_loc +0.1% +85 [ = ] 0 .strtab +0.0% +83 [ = ] 0 .debug_info +0.0% +73 [ = ] 0 .debug_line +0.2% +48 [ = ] 0 .symtab +0.0% +44 +0.0% +44 .text +0.2% +36 [ = ] 0 .debug_frame +68% +23 [ = ] 0 [Unmapped] +0.1% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_ranges +0.0% +516 +0.0% +44 TOTAL 

use_config/rp2040_split

 text data bss dec hex	filename 149376 0 16144 165520 28690	central text data bss dec hex	filename 33688 0 2848 36536 8eb8	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +108 [ = ] 0 .debug_loc +0.1% +85 [ = ] 0 .strtab +0.0% +83 [ = ] 0 .debug_info +0.0% +73 [ = ] 0 .debug_line +0.1% +48 [ = ] 0 .symtab +0.0% +44 +0.0% +44 .text +0.2% +36 [ = ] 0 .debug_frame +0.1% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_ranges -15.8% -9 [ = ] 0 [Unmapped] +0.0% +484 +0.0% +44 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_rust/rp2040_split

 text data bss dec hex	filename 148624 0 15740 164364 2820c	central text data bss dec hex	filename 34376 0 3096 37472 9260	peripheral 
Diff

Central Diff

 FILE SIZE VM SIZE -------------- -------------- +0.0% +108 [ = ] 0 .debug_loc +0.1% +85 [ = ] 0 .strtab +0.0% +83 [ = ] 0 .debug_info +0.0% +73 [ = ] 0 .debug_line +0.1% +48 [ = ] 0 .symtab +0.0% +44 +0.0% +44 .text +0.2% +36 [ = ] 0 .debug_frame +32% +15 [ = ] 0 [Unmapped] +0.1% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_ranges +0.0% +508 +0.0% +44 TOTAL 

Peripheral Diff

 FILE SIZE VM SIZE -------------- -------------- [ = ] 0 [ = ] 0 TOTAL 

use_config/stm32f1

 text data bss dec hex	filename 51144 24 6832 58000 e290	rmk-stm32f1 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.3% +85 [ = ] 0 .strtab +0.1% +65 [ = ] 0 .debug_line +0.3% +48 [ = ] 0 .symtab +0.0% +45 [ = ] 0 .debug_info +0.3% +36 [ = ] 0 .debug_frame +0.1% +36 +0.1% +36 .text +0.1% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_loc +0.0% +8 [ = ] 0 .debug_ranges -5.9% -3 [ = ] 0 [Unmapped] +0.0% +336 +0.1% +36 TOTAL 

use_config/stm32f4

 text data bss dec hex	filename 141432 320 16000 157752 26838	rmk-stm32f4 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.0% +92 [ = ] 0 .debug_loc +0.1% +85 [ = ] 0 .strtab +0.0% +83 [ = ] 0 .debug_info +0.0% +81 [ = ] 0 .debug_line +0.1% +48 [ = ] 0 .symtab +0.0% +44 +0.0% +44 .text +0.2% +36 [ = ] 0 .debug_frame +39% +15 [ = ] 0 [Unmapped] +0.0% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_ranges +0.0% +500 +0.0% +44 TOTAL 

use_config/stm32h7

 text data bss dec hex	filename 126864 264 15216 142344 22c08	rmk-stm32h7 
Diff
 FILE SIZE VM SIZE -------------- -------------- +0.1% +85 [ = ] 0 .strtab +0.0% +65 [ = ] 0 .debug_line +0.1% +48 [ = ] 0 .symtab +0.0% +45 [ = ] 0 .debug_info +0.0% +40 +0.0% +40 .text +0.2% +36 [ = ] 0 .debug_frame +0.0% +8 [ = ] 0 .debug_aranges +0.0% +8 [ = ] 0 .debug_loc +0.0% +8 [ = ] 0 .debug_ranges -10.8% -7 [ = ] 0 [Unmapped] +0.0% +336 +0.0% +40 TOTAL 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant