Skip to content

feat(ble): expose multiple battery services for split peripherals, with configurable user descriptions - #1038

Merged
HaoboGu merged 12 commits into
rmk-rs:mainfrom
kot149:feat/peripheral-battery-gatt
Aug 19, 2026
Merged

feat(ble): expose multiple battery services for split peripherals, with configurable user descriptions#1038
HaoboGu merged 12 commits into
rmk-rs:mainfrom
kot149:feat/peripheral-battery-gatt

Conversation

@kot149

@kot149 kot149 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

resolves #710

  • Expose battery levels from configured split peripherals through standard Battery Service instances on the central's BLE GATT server, including host-readable and notifiable levels for each peripheral.
  • Add configurable battery_user_description values for the central and split peripheral Battery Level characteristics through [ble], [split.central], and [[split.peripheral]], with descriptive defaults for each battery service.

Testing

Tested with a split keyboard (one split peripheral), using Microsoft Bluetooth LE Explorer and zmk-battery-center and verified:

  • the battery level can be read
  • the Characteristic User Description can be read
  • the bettery level update is notified
image
image

Only tested with a single peripheral. Configurations with two or more peripherals should also work but not tested.

Specification reference

This implementation follows the Bluetooth SIG Battery Service Specification v1.1, especially the requirements for multiple Battery Service instances and unique Characteristic Presentation Format Description values for each Battery Level characteristic:
https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/BAS_v1.1/out/en/index-en.html

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 398.4 KiB 398.7 KiB +0.07% ⬆️ +44 0 +272
use_config/nrf52840_ble 440.6 KiB 440.8 KiB +0.03% ⬆️ -108 0 +272
use_config/nrf52840_ble_split (central) 502.5 KiB 506.3 KiB +0.75% ⬆️ +2816 0 +1080
use_config/nrf52840_ble_split (peripheral) 317.5 KiB 317.5 KiB -0.01% ⬇️ -68 +8 0
use_config/pi_pico_w_ble 673.3 KiB 673.9 KiB +0.09% ⬆️ +356 0 +272
use_config/rp2040 146.1 KiB 146.1 KiB +0.00% 0 0 0
use_config/rp2040_split (central) 159.7 KiB 159.7 KiB +0.00% ⬆️ +4 0 0
use_config/rp2040_split (peripheral) 27.9 KiB 27.9 KiB +0.00% 0 0 0
use_config/stm32f1 62.7 KiB 62.7 KiB +0.00% 0 0 0
use_config/stm32h7 100.9 KiB 100.9 KiB +0.00% ⬆️ +4 0 0
use_rust/nrf52832_ble 385.7 KiB 386.8 KiB +0.26% ⬆️ +792 0 +272
use_rust/nrf52840_ble 436.1 KiB 436.2 KiB +0.04% ⬆️ -72 0 +272
use_rust/nrf52840_ble_split (central) 505.8 KiB 508.4 KiB +0.51% ⬆️ +2012 0 +680
use_rust/nrf52840_ble_split (peripheral) 315.3 KiB 315.2 KiB -0.04% ⬇️ -144 +8 0
use_rust/pi_pico_w_ble 672.6 KiB 673.2 KiB +0.09% ⬆️ +368 0 +272
use_rust/rp2040 145.5 KiB 145.5 KiB +0.00% 0 0 0
use_rust/rp2040_split (central) 158.4 KiB 158.4 KiB +0.00% 0 0 0
use_rust/rp2040_split (peripheral) 28.2 KiB 28.2 KiB +0.00% 0 0 0
use_rust/stm32f1 61.9 KiB 61.9 KiB +0.00% ⬇️ -4 0 0
use_rust/stm32h7 119.3 KiB 119.3 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52832_ble — 398.4 KiB → 398.7 KiB (+0.07% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 365720	   8620	  33952	 408292	  63ae4	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 365676	   8620	  33680	 407976	  639a8	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.84Ki  [ = ]       0    .debug_str
  +0.1% +2.44Ki  [ = ]       0    .debug_info
  +0.1%    +766  [ = ]       0    .debug_loc
  +0.1%    +339  [ = ]       0    .strtab
  [ = ]       0  +0.8%    +272    .bss
  +0.0%     +64  [ = ]       0    .debug_ranges
  +0.1%     +64  [ = ]       0    .symtab
  +0.1%     +44  [ = ]       0    .debug_frame
  +0.0%     +28  +0.0%     +28    .text
  +0.1%     +24  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
  +0.0%      +1  [ = ]       0    .debug_line
 -21.1%     -12  [ = ]       0    [Unmapped]
  +0.1% +6.59Ki  +0.1%    +316    TOTAL
use_config/nrf52840_ble — 440.6 KiB → 440.8 KiB (+0.03% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 398748	   8628	  43984	 451360	  6e320	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 398856	   8628	  43712	 451196	  6e27c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.41Ki  [ = ]       0    .debug_str
  +0.1% +1.62Ki  [ = ]       0    .debug_info
  +0.1%    +514  [ = ]       0    .strtab
  +0.1%    +277  [ = ]       0    .debug_line
  [ = ]       0  +0.6%    +272    .bss
  +0.2%    +224  [ = ]       0    .symtab
  +0.2%    +108  [ = ]       0    .debug_frame
  +0.1%     +56  [ = ]       0    .debug_aranges
  +0.5%     +39  [ = ]       0    .debug_abbrev
  +0.0%     +16  +0.0%     +16    .rodata
   +30%     +15  [ = ]       0    [Unmapped]
  -0.0%    -124  -0.0%    -124    .text
  -0.3%    -728  [ = ]       0    .debug_ranges
  -0.4% -2.87Ki  [ = ]       0    .debug_loc
  +0.0% +1.56Ki  +0.0%    +164    TOTAL
use_config/nrf52840_ble_split (central) — 502.5 KiB → 506.3 KiB (+0.75% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 459652	   8684	  50136	 518472	  7e948	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 456836	   8684	  49056	 514576	  7da10	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +1.2% +56.5Ki  [ = ]       0    .debug_str
  +1.1% +25.1Ki  [ = ]       0    .debug_info
  +0.8% +7.00Ki  [ = ]       0    .debug_loc
  +2.0% +4.90Ki  [ = ]       0    .debug_ranges
  +0.6% +2.49Ki  +0.6% +2.49Ki    .text
  +0.7% +2.44Ki  [ = ]       0    .debug_line
  +0.5% +2.16Ki  [ = ]       0    .strtab
  [ = ]       0  +2.2% +1.05Ki    .bss
  +0.7%   +1024  [ = ]       0    .symtab
  +1.1%    +580  [ = ]       0    .debug_frame
  +0.6%    +268  +0.6%    +268    .rodata
  +0.5%    +232  [ = ]       0    .debug_aranges
  -3.0%      -2  [ = ]       0    [Unmapped]
  -0.6%     -48  [ = ]       0    .debug_abbrev
  +1.0%  +102Ki  +0.8% +3.80Ki    TOTAL
use_config/nrf52840_ble_split (peripheral) — 317.5 KiB → 317.5 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 291396	   8508	  25184	 325088	  4f5e0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 291464	   8500	  25184	 325148	  4f61c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +3.59Ki  [ = ]       0    .debug_str
  +0.1%   +1021  [ = ]       0    .debug_info
  +0.2%     +16  [ = ]       0    .debug_abbrev
  +0.1%      +8  +0.1%      +8    .data
  -4.1%      -2  [ = ]       0    [Unmapped]
  -0.0%     -68  -0.0%     -68    .text
  -0.2%     -80  [ = ]       0    .debug_aranges
  -0.0%    -116  [ = ]       0    .debug_line
  -0.9%    -296  [ = ]       0    .debug_frame
  -0.5%    -464  [ = ]       0    .symtab
  -0.5%    -808  [ = ]       0    .debug_ranges
  -0.5% -1.26Ki  [ = ]       0    .strtab
  -0.9% -4.75Ki  [ = ]       0    .debug_loc
  -0.0% -3.19Ki  -0.0%     -60    TOTAL
use_config/pi_pico_w_ble — 673.3 KiB → 673.9 KiB (+0.09% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 636076	      0	  54016	 690092	  a87ac	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 635720	      0	  53744	 689464	  a8538	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.85Ki  [ = ]       0    .debug_loc
  +0.1% +1.68Ki  [ = ]       0    .debug_info
  +0.0% +1.61Ki  [ = ]       0    .debug_str
  +0.3%    +728  [ = ]       0    .debug_ranges
  +0.1%    +368  [ = ]       0    .strtab
  +0.1%    +336  +0.1%    +336    .text
  +0.1%    +307  [ = ]       0    .debug_line
  [ = ]       0  +0.5%    +272    .bss
  +0.1%     +48  [ = ]       0    .symtab
  +0.1%     +28  [ = ]       0    .debug_frame
  +0.0%     +20  +0.0%     +20    .rodata
  +0.0%     +16  [ = ]       0    .debug_aranges
  -6.9%      -5  [ = ]       0    [Unmapped]
  -0.4%     -39  [ = ]       0    .debug_abbrev
  +0.1% +6.91Ki  +0.1%    +628    TOTAL
use_config/rp2040 — 146.1 KiB → 146.1 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135672	      0	  13900	 149572	  24844	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135672	      0	  13900	 149572	  24844	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL
use_config/rp2040_split (central) — 159.7 KiB → 159.7 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148716	      0	  14844	 163560	  27ee8	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148712	      0	  14844	 163556	  27ee4	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +19  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .text
  +0.0%      +3  [ = ]       0    .debug_line
  +0.0%      +1  [ = ]       0    .debug_str
 -16.3%      -7  [ = ]       0    [Unmapped]
  +0.0%     +20  +0.0%      +4    TOTAL
use_config/rp2040_split (peripheral) — 27.9 KiB → 27.9 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25696	     60	   2804	  28560	   6f90	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +5  [ = ]       0    .debug_info
  +0.0%      +1  [ = ]       0    .debug_str
  -3.9%      -2  [ = ]       0    [Unmapped]
  +0.0%      +4  [ = ]       0    TOTAL
use_config/stm32f1 — 62.7 KiB → 62.7 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57784	     28	   6360	  64172	   faac	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57784	     28	   6360	  64172	   faac	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL
use_config/stm32h7 — 100.9 KiB → 100.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  94908	    264	   8112	 103284	  19374	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  94904	    264	   8112	 103280	  19370	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.34Ki  [ = ]       0    .debug_str
  +0.2%    +108  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  -4.5%      -2  [ = ]       0    [Unmapped]
  -0.0%     -52  [ = ]       0    .debug_info
  +0.0% +1.40Ki  +0.0%      +4    TOTAL
use_rust/nrf52832_ble — 385.7 KiB → 386.8 KiB (+0.26% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 353544	   8620	  33896	 396060	  60b1c	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 352752	   8620	  33624	 394996	  606f4	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.5% +3.07Ki  [ = ]       0    .debug_loc
  +0.1% +1.83Ki  [ = ]       0    .debug_info
  +0.0% +1.51Ki  [ = ]       0    .debug_str
  +0.3%    +842  [ = ]       0    .strtab
  +0.2%    +776  +0.2%    +776    .text
  +0.5%    +640  [ = ]       0    .symtab
  +0.1%    +413  [ = ]       0    .debug_line
  +0.7%    +316  [ = ]       0    .debug_frame
  [ = ]       0  +0.8%    +272    .bss
  +0.4%    +152  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
  +9.6%      +5  [ = ]       0    [Unmapped]
  -0.1%    -240  [ = ]       0    .debug_ranges
  +0.1% +9.25Ki  +0.3% +1.04Ki    TOTAL
use_rust/nrf52840_ble — 436.1 KiB → 436.2 KiB (+0.04% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 396876	   8628	  41216	 446720	  6d100	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 396948	   8628	  40944	 446520	  6d038	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.35Ki  [ = ]       0    .debug_info
  +0.1% +2.16Ki  [ = ]       0    .debug_str
  +0.1%    +309  [ = ]       0    .strtab
  [ = ]       0  +0.7%    +272    .bss
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +16  +0.0%     +16    .rodata
  +0.0%     +12  [ = ]       0    .debug_frame
  +0.0%      +8  [ = ]       0    .debug_aranges
 -32.9%     -24  [ = ]       0    [Unmapped]
  -0.0%     -88  -0.0%     -88    .text
  -0.1%    -286  [ = ]       0    .debug_line
  -0.4%    -856  [ = ]       0    .debug_ranges
  -0.2% -1.55Ki  [ = ]       0    .debug_loc
  +0.0% +2.10Ki  +0.0%    +200    TOTAL
use_rust/nrf52840_ble_split (central) — 505.8 KiB → 508.4 KiB (+0.51% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 460264	   8684	  51688	 520636	  7f1bc	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 458252	   8684	  51008	 517944	  7e738	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.6% +30.3Ki  [ = ]       0    .debug_str
  +0.5% +11.3Ki  [ = ]       0    .debug_info
  +0.5% +4.43Ki  [ = ]       0    .debug_loc
  +0.8% +3.06Ki  [ = ]       0    .strtab
  +1.0% +2.44Ki  [ = ]       0    .debug_ranges
  +0.5% +1.93Ki  +0.5% +1.93Ki    .text
  +0.4% +1.53Ki  [ = ]       0    .debug_line
  [ = ]       0  +1.4%    +680    .bss
  +0.2%    +336  [ = ]       0    .symtab
  +0.3%    +188  [ = ]       0    .debug_frame
  +0.1%     +72  [ = ]       0    .debug_aranges
  +0.1%     +32  +0.1%     +32    .rodata
  -0.4%     -38  [ = ]       0    .debug_abbrev
  +0.6% +55.6Ki  +0.5% +2.63Ki    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 315.3 KiB → 315.2 KiB (-0.04% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 289308	   8508	  24952	 322768	  4ecd0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 289452	   8500	  24952	 322904	  4ed58	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +3.65Ki  [ = ]       0    .debug_str
  +0.1% +1.13Ki  [ = ]       0    .debug_info
  +0.2%     +16  [ = ]       0    .debug_abbrev
  +0.1%      +8  +0.1%      +8    .data
  +5.9%      +3  [ = ]       0    [Unmapped]
  -0.1%     -56  [ = ]       0    .debug_aranges
  -0.1%    -144  -0.1%    -144    .text
  -0.7%    -248  [ = ]       0    .debug_frame
  -0.1%    -334  [ = ]       0    .debug_line
  -0.4%    -400  [ = ]       0    .symtab
  -0.7% -1.14Ki  [ = ]       0    .debug_ranges
  -0.5% -1.19Ki  [ = ]       0    .strtab
  -0.4% -2.30Ki  [ = ]       0    .debug_loc
  -0.0%    -996  -0.0%    -136    TOTAL
use_rust/pi_pico_w_ble — 672.6 KiB → 673.2 KiB (+0.09% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 635700	      0	  53696	 689396	  a84f4	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 635332	      0	  53424	 688756	  a8274	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.88Ki  [ = ]       0    .debug_info
  +0.2% +1.85Ki  [ = ]       0    .debug_loc
  +0.3%    +728  [ = ]       0    .debug_ranges
  +0.1%    +431  [ = ]       0    .debug_line
  +0.1%    +352  +0.1%    +352    .text
  [ = ]       0  +0.5%    +272    .bss
  +0.1%     +48  [ = ]       0    .symtab
  +0.1%     +28  [ = ]       0    .debug_frame
   +45%     +19  [ = ]       0    [Unmapped]
  +0.0%     +16  [ = ]       0    .debug_aranges
  +0.0%     +16  +0.0%     +16    .rodata
  -0.1%    -285  [ = ]       0    .strtab
  -0.1% -3.21Ki  [ = ]       0    .debug_str
  +0.0% +1.85Ki  +0.1%    +640    TOTAL
use_rust/rp2040 — 145.5 KiB → 145.5 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135300	      0	  13732	 149032	  24628	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135300	      0	  13732	 149032	  24628	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +173  [ = ]       0    .debug_str
  +0.0%     +80  [ = ]       0    .debug_info
  +0.0%     +66  [ = ]       0    .debug_line
  +0.0%      +9  [ = ]       0    .strtab
  -4.4%      -2  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +316  [ = ]       0    TOTAL
use_rust/rp2040_split (central) — 158.4 KiB → 158.4 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 147624	      0	  14588	 162212	  279a4	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 147624	      0	  14588	 162212	  279a4	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +146  [ = ]       0    .debug_line
  +0.0%     +70  [ = ]       0    .debug_str
  +0.0%     +16  [ = ]       0    .debug_info
  +0.0%      +1  [ = ]       0    .strtab
  +2.3%      +1  [ = ]       0    [Unmapped]
  -0.0%     -10  [ = ]       0    .debug_loc
  +0.0%    +224  [ = ]       0    TOTAL
use_rust/rp2040_split (peripheral) — 28.2 KiB → 28.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25796	     60	   3068	  28924	   70fc	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +5  [ = ]       0    .debug_info
  +0.0%      +2  [ = ]       0    .debug_str
  +0.0%      +1  [ = ]       0    .strtab
  +0.0%      +8  [ = ]       0    TOTAL
use_rust/stm32f1 — 61.9 KiB → 61.9 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57120	     28	   6280	  63428	   f7c4	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  57124	     28	   6280	  63432	   f7c8	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +63  [ = ]       0    .debug_str
  +0.0%     +52  [ = ]       0    .debug_info
  +0.0%      +9  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  +0.0%    +120  -0.0%      -4    TOTAL
use_rust/stm32h7 — 119.3 KiB → 119.3 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 107796	    320	  14012	 122128	  1dd10	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 107792	    320	  14012	 122124	  1dd0c	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +10  [ = ]       0    .debug_loc
  +0.0%      +9  [ = ]       0    .strtab
  +0.0%      +6  [ = ]       0    .debug_info
  +0.0%      +4  +0.0%      +4    .text
 -10.4%      -7  [ = ]       0    [Unmapped]
  -0.0%     -37  [ = ]       0    .debug_str
  -0.1%    -137  [ = ]       0    .debug_line
  -0.0%    -152  +0.0%      +4    TOTAL

@kot149
kot149 force-pushed the feat/peripheral-battery-gatt branch from d071129 to 7cb7ca6 Compare August 9, 2026 12:24
@kot149
kot149 marked this pull request as ready for review August 9, 2026 14:49
Comment thread rmk-config/src/resolved/build_constants.rs Outdated
Comment thread rmk-config/src/resolved/build_constants.rs Outdated
@HaoboGu

HaoboGu commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Do you have any idea why Flash/RAM increases that much for split central?

Comment thread rmk-config/src/resolved/build_constants.rs Outdated
Comment thread rmk/src/ble/ble_server.rs Outdated
Comment thread rmk/Cargo.toml Outdated
Comment thread rmk-config/src/resolved/build_constants.rs
Comment thread rmk/src/ble/mod.rs Outdated
Comment thread rmk/src/ble/battery_service.rs Outdated
Comment thread rmk/src/ble/battery_service.rs Outdated
@kot149

kot149 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

Do you have any idea why Flash/RAM increases that much for split central?

The largest avoidable cause was enabling trouble-host's 128-byte client ATT table for every split build, as you mentioned. I removed the default ATT table expansion and now generate Peripheral Battery Services only for peripherals with battery_adc_pin configured. This reduced the split central overhead as follows:

  • use_config: .text +4,920 -> +2,956 bytes, .data +128 -> 0 bytes, .bss +1,864 -> +1,080 bytes
  • use_rust: .text +4,136 -> +2,040 bytes, .data +128 -> 0 bytes, .bss +1,864 -> +680 bytes

The remaining increase comes from the new GATT descriptors and, when configured, the additional Battery Service and notification handling. The common +272 B .bss in BLE builds is mainly the cost of the two new descriptors on the central Battery Level characteristic. Split peripheral builds now have no .bss increase.

Comment thread rmk/src/ble/battery_service.rs Outdated
Comment thread rmk-config/src/resolved/build_constants.rs
Comment thread rmk/src/ble/battery_service.rs Outdated

@HaoboGu HaoboGu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good! I have only 1 more comment: when the split peripheral disconnects, will the battery level for peripheral be set to 0 or marked disconnected somehow?

@kot149

kot149 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

when the split peripheral disconnects, will the battery level for peripheral be set to 0 or marked disconnected somehow?

The Battery Service does not have a standard value for "disconnected" or "unknown", and 0 means an actual 0% battery level.
Currently, the last reported battery level is kept until the central is restarted, and when the central starts up with the peripheral disconnected, the GATT Battery Level remains at its initial value of 0%, since the last reported value is only stored in RAM. This might seem inconsistent, but treating 0% as disconnected also feels unnatural to me.

@HaoboGu

HaoboGu commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

That's fine, thank you very much for your effort! I'm merging it

@HaoboGu
HaoboGu merged commit f8da274 into rmk-rs:main Aug 19, 2026
62 checks passed
@kot149
kot149 deleted the feat/peripheral-battery-gatt branch August 19, 2026 14:59
@alxzh

alxzh commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

How did you make it show up in the zmk-battery-center? Does it require any special configuration?

@kot149

kot149 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@alxzh

How did you make it show up in the zmk-battery-center? Does it require any special configuration?

No special configuration is required; only battery_adc_pin for your split peripheral is needed (battery_user_description is optional).
Updating the GATT structure might require re-pairing the BLE host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Battery reporting for peripheral split half is missing

3 participants