Browse Source

Refactor based on recent discussion - Add back 'Layer Count'

zvecr 4 years ago
parent
commit
dab3a4fde0
4 changed files with 36 additions and 13 deletions
  1. 18 2
      data/xap/xap_0.2.0.hjson
  2. 6 4
      docs/xap_0.2.0.md
  3. 7 7
      lib/python/qmk/cli/xap/xap.py
  4. 5 0
      quantum/xap/xap_handlers.c

+ 18 - 2
data/xap/xap_0.2.0.hjson

@@ -24,6 +24,14 @@
                     return_constant: XAP_ROUTE_KEYMAP_CAPABILITIES
                 }
                 0x02: {
+                    type: command
+                    name: Get Layer Count
+                    define: GET_LAYER_COUNT
+                    description: Query maximum number of layers that can be addressed within the keymap.
+                    return_type: u8
+                    return_execute: keymap_get_layer_count
+                }
+                0x03: {
                     type: command
                     name: Get Keycode
                     define: GET_KEYMAP_KEYCODE
@@ -47,7 +55,7 @@
                     return_type: u16
                     return_execute: get_keymap_keycode
                 }
-                0x03: {
+                0x04: {
                     type: command
                     name: Get Encoder Keycode
                     define: GET_ENCODER_KEYCODE
@@ -98,6 +106,14 @@
                     return_constant: XAP_ROUTE_REMAPPING_CAPABILITIES
                 }
                 0x02: {
+                    type: command
+                    name: Get Layer Count
+                    define: GET_DYNAMIC_LAYER_COUNT
+                    description: Query maximum number of layers that can be addressed within the keymap.
+                    return_type: u8
+                    return_constant: DYNAMIC_KEYMAP_LAYER_COUNT
+                }
+                0x03: {
                     type: command
                     name: Set Keycode
                     define: SET_KEYMAP_KEYCODE
@@ -125,7 +141,7 @@
                     ]
                     return_execute: dynamic_keymap_set_keycode
                 }
-                0x03: {
+                0x04: {
                     type: command
                     name: Set Encoder Keycode
                     define: SET_ENCODER_KEYCODE

+ 6 - 4
docs/xap_0.2.0.md

@@ -128,8 +128,9 @@ This subsystem allows for query of currently configured keycodes.
 | Name | Route | Tags | Payloads | Description |
 | -- | -- | -- | -- | -- |
 | Capabilities Query | `0x04 0x01` |  |<br>__Response:__ `u32`| Keymap subsystem capabilities query. Each bit should be considered as a "usable" route within this subsystem.|
-| Get Keycode | `0x04 0x02` |  |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Row: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Column: `u8`<br>__Response:__ `u16`| Query the Keycode at the requested location.|
-| Get Encoder Keycode | `0x04 0x03` |  |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Encoder: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Clockwise: `u8`<br>__Response:__ `u16`| Query the Keycode at the requested location.|
+| Get Layer Count | `0x04 0x02` |  |<br>__Response:__ `u8`| Query maximum number of layers that can be addressed within the keymap.|
+| Get Keycode | `0x04 0x03` |  |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Row: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Column: `u8`<br>__Response:__ `u16`| Query the Keycode at the requested location.|
+| Get Encoder Keycode | `0x04 0x04` |  |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Encoder: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Clockwise: `u8`<br>__Response:__ `u16`| Query the Keycode at the requested location.|
 
 ### Remapping - `0x05`
 This subsystem allows for live reassignment of keycodes without rebuilding the firmware.
@@ -138,8 +139,9 @@ This subsystem allows for live reassignment of keycodes without rebuilding the f
 | Name | Route | Tags | Payloads | Description |
 | -- | -- | -- | -- | -- |
 | Capabilities Query | `0x05 0x01` |  |<br>__Response:__ `u32`| Remapping subsystem capabilities query. Each bit should be considered as a "usable" route within this subsystem.|
-| Set Keycode | `0x05 0x02` | __Secure__ |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Row: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Column: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Keycode: `u16`| Modify the Keycode at the requested location.|
-| Set Encoder Keycode | `0x05 0x03` | __Secure__ |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Encoder: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Clockwise: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Keycode: `u16`| Modify the Keycode at the requested location.|
+| Get Layer Count | `0x05 0x02` |  |<br>__Response:__ `u8`| Query maximum number of layers that can be addressed within the keymap.|
+| Set Keycode | `0x05 0x03` | __Secure__ |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Row: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Column: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Keycode: `u16`| Modify the Keycode at the requested location.|
+| Set Encoder Keycode | `0x05 0x04` | __Secure__ |<br>__Request:__<br>&nbsp;&nbsp;&nbsp;&nbsp;* Layer: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Encoder: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Clockwise: `u8`<br>&nbsp;&nbsp;&nbsp;&nbsp;* Keycode: `u16`| Modify the Keycode at the requested location.|
 
 ### Lighting - `0x06`
 This subsystem allows for control over the lighting subsystem.

+ 7 - 7
lib/python/qmk/cli/xap/xap.py

@@ -165,21 +165,21 @@ def _list_devices():
 
 # def xap_dummy(device):
 #     # get layer count
-#     layers = _xap_transaction(device, 0x04, 0x00)
+#     layers = _xap_transaction(device, 0x04, 0x02)
 #     layers = int.from_bytes(layers, "little")
 #     print(f'layers:{layers}')
 
 #     # get keycode [layer:0, row:0, col:0]
-#     # keycode = _xap_transaction(device, 0x04, 0x02, b"\x00\x00\x00")
+#     # keycode = _xap_transaction(device, 0x04, 0x03, b"\x00\x00\x00")
 
 #     # get encoder [layer:0, index:0, clockwise:0]
-#     keycode = _xap_transaction(device, 0x04, 0x03, b"\x00\x00\x00")
+#     keycode = _xap_transaction(device, 0x04, 0x04, b"\x00\x00\x00")
 
 #     keycode = int.from_bytes(keycode, "little")
 #     print(f'keycode:{KEYCODE_MAP.get(keycode, "unknown")}[{keycode}]')
 
 #     # set encoder [layer:0, index:0, clockwise:0, keycode:KC_A]
-#     _xap_transaction(device, 0x05, 0x03, b"\x00\x00\x00\x04\00")
+#     _xap_transaction(device, 0x05, 0x04, b"\x00\x00\x00\x04\00")
 
 
 def xap_broadcast_listen(device):
@@ -235,7 +235,7 @@ class XAPShell(cmd.Cmd):
             cli.log.error("Invalid args")
             return
 
-        keycode = _xap_transaction(self.device, 0x04, 0x02, data)
+        keycode = _xap_transaction(self.device, 0x04, 0x03, data)
         keycode = int.from_bytes(keycode, "little")
         print(f'keycode:{self.keycodes.get(keycode, "unknown")}[{keycode}]')
 
@@ -254,7 +254,7 @@ class XAPShell(cmd.Cmd):
         for r in range(rows):
             for c in range(cols):
                 q = data + r.to_bytes(1, byteorder='little') + c.to_bytes(1, byteorder='little')
-                keycode = _xap_transaction(self.device, 0x04, 0x02, q)
+                keycode = _xap_transaction(self.device, 0x04, 0x03, q)
                 keycode = int.from_bytes(keycode, "little")
                 print(f'| {self.keycodes.get(keycode, "unknown").ljust(7)} ', end='', flush=True)
             print('|')
@@ -276,7 +276,7 @@ class XAPShell(cmd.Cmd):
         keycodes = []
         for item in layout:
             q = data + bytes(item['matrix'])
-            keycode = _xap_transaction(self.device, 0x04, 0x02, q)
+            keycode = _xap_transaction(self.device, 0x04, 0x03, q)
             keycode = int.from_bytes(keycode, "little")
             keycodes.append(self.keycodes.get(keycode, "???"))
 

+ 5 - 0
quantum/xap/xap_handlers.c

@@ -104,6 +104,11 @@ bool xap_respond_get_hardware_id(xap_token_t token, const void *data, size_t len
     return xap_respond_data(token, &ret, sizeof(ret));
 }
 
+bool xap_respond_keymap_get_layer_count(xap_token_t token, const void *data, size_t length) {
+    uint8_t ret = keymap_layer_count();
+    return xap_respond_data(token, &ret, sizeof(ret));
+}
+
 bool xap_respond_get_keymap_keycode(xap_token_t token, const void *data, size_t length) {
     if (length != sizeof(xap_route_keymap_get_keymap_keycode_arg_t)) {
         return false;