@@ -26,18 +26,80 @@ struct zis_entry {
2626
2727static const struct zis_entry proxy_inputs [] = {DT_INST_FOREACH_STATUS_OKAY (ZIS_ENTRY )};
2828
29+ static uint16_t proxy_active_keys [DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT )]
30+ [CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS ];
31+
32+ static int replace_active_key (size_t input , uint16_t find , uint16_t replace ) {
33+ for (size_t k = 0 ; k < CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS ; k ++ ) {
34+ if (proxy_active_keys [input ][k ] == find ) {
35+ proxy_active_keys [input ][k ] = replace ;
36+ return 0 ;
37+ }
38+ }
39+
40+ return - ENODEV ;
41+ }
42+
2943int zmk_input_split_report_peripheral_event (uint8_t reg , uint8_t type , uint16_t code , int32_t value ,
3044 bool sync ) {
3145 LOG_DBG ("Got peripheral event for %d!" , reg );
3246 for (size_t i = 0 ; i < ARRAY_SIZE (proxy_inputs ); i ++ ) {
3347 if (reg == proxy_inputs [i ].reg ) {
48+ if (type == INPUT_EV_KEY ) {
49+ uint16_t find , replace ;
50+
51+ if (value ) {
52+ find = 0 ;
53+ replace = code ;
54+ } else {
55+ find = code ;
56+ replace = 0 ;
57+ }
58+
59+ int ret = replace_active_key (i , find , replace );
60+ if (ret < 0 ) {
61+ LOG_WRN ("Failed to %s key %d" , value ? "track pressed" : "untrack released" ,
62+ ret );
63+ }
64+ }
3465 return input_report (proxy_inputs [i ].dev , type , code , value , sync , K_NO_WAIT );
3566 }
3667 }
3768
3869 return - ENODEV ;
3970}
4071
72+ int zmk_input_split_peripheral_disconnected (uint8_t reg ) {
73+ for (size_t i = 0 ; i < ARRAY_SIZE (proxy_inputs ); i ++ ) {
74+ if (reg == proxy_inputs [i ].reg ) {
75+ uint16_t prev = 0 ;
76+ for (size_t k = 0 ; k < CONFIG_ZMK_INPUT_SPLIT_MAX_TRACKED_KEYS ; k ++ ) {
77+ if (proxy_active_keys [i ][k ] != 0 ) {
78+ if (prev != 0 ) {
79+ int ret = input_report (proxy_inputs [i ].dev , INPUT_EV_KEY , prev , 0 , false,
80+ K_NO_WAIT );
81+ if (ret < 0 ) {
82+ LOG_WRN ("Failed to report release event on disconnect (%d)" , ret );
83+ }
84+ }
85+
86+ prev = proxy_active_keys [i ][k ];
87+ proxy_active_keys [i ][k ] = 0 ;
88+ }
89+ }
90+
91+ if (prev != 0 ) {
92+ int ret = input_report (proxy_inputs [i ].dev , INPUT_EV_KEY , prev , 0 , true, K_NO_WAIT );
93+ if (ret < 0 ) {
94+ LOG_WRN ("Failed to report release event on disconnect (%d)" , ret );
95+ }
96+ }
97+ }
98+ }
99+
100+ return - ENODEV ;
101+ }
102+
41103#define ZIS_INST (n ) \
42104 DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, \
43105 CONFIG_ZMK_INPUT_SPLIT_INIT_PRIORITY, NULL);
@@ -78,4 +140,4 @@ int zmk_input_split_report_peripheral_event(uint8_t reg, uint8_t type, uint16_t
78140
79141#endif
80142
81- DT_INST_FOREACH_STATUS_OKAY (ZIS_INST )
143+ DT_INST_FOREACH_STATUS_OKAY (ZIS_INST )
0 commit comments