From 81a53ac5b624c90c27310d1c6b9daabe1a8ad565 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 31 Mar 2022 21:08:18 +0100 Subject: [PATCH] gen RESPONSE_FLAG defines --- data/xap/xap_0.0.1.hjson | 2 +- .../qmk/xap/gen_firmware/header_generator.py | 36 +++++++++++++++++++ quantum/xap/xap.h | 22 +----------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/data/xap/xap_0.0.1.hjson b/data/xap/xap_0.0.1.hjson index 9b19526244..328207768e 100755 --- a/data/xap/xap_0.0.1.hjson +++ b/data/xap/xap_0.0.1.hjson @@ -132,7 +132,7 @@ } response_flags: { - define_prefix: XAP_RESP + define_prefix: XAP_RESPONSE_FLAG bits: { 0: { name: Success diff --git a/lib/python/qmk/xap/gen_firmware/header_generator.py b/lib/python/qmk/xap/gen_firmware/header_generator.py index 42d54e1960..6cc9ff8816 100755 --- a/lib/python/qmk/xap/gen_firmware/header_generator.py +++ b/lib/python/qmk/xap/gen_firmware/header_generator.py @@ -94,6 +94,38 @@ def _append_route_capabilities(lines, container, container_id=None, route_stack= route_stack.pop() +def _append_types(lines, container): + """Handles creating the various constants, types, defines, etc. + """ + response_flags = container.get('response_flags', {}) + prefix = response_flags['define_prefix'] + for key, value in response_flags['bits'].items(): + define = value.get('define') + lines.append(f'#define {prefix}_{define} (1ul << ({key}))') + + # Add special + lines.append(f'#define {prefix}_FAILED 0x00') + + # TODO: define this in xap_*.hjson + lines.append( + ''' +typedef uint8_t xap_identifier_t; +typedef uint8_t xap_response_flags_t; +typedef uint16_t xap_token_t; + +typedef struct { + xap_token_t token; + uint8_t length; +} xap_request_header_t; + +typedef struct { + xap_token_t token; + xap_response_flags_t flags; + uint8_t length; +} xap_response_header_t;''' + ) + + def generate_header(output_file, keyboard): """Generates the XAP protocol header file, generated during normal build. """ @@ -112,6 +144,10 @@ def generate_header(output_file, keyboard): lines.append(f'#define XAP_KEYBOARD_IDENTIFIER 0x{keyboard_id:08X}ul') lines.append('') + # Types + _append_types(lines, xap_defs) + lines.append('') + # Append the route and command defines _append_route_defines(lines, xap_defs) lines.append('') diff --git a/quantum/xap/xap.h b/quantum/xap/xap.h index 828531a92b..7c43d90e27 100644 --- a/quantum/xap/xap.h +++ b/quantum/xap/xap.h @@ -19,9 +19,7 @@ #include #include -typedef uint8_t xap_identifier_t; -typedef uint8_t xap_response_flags_t; -typedef uint16_t xap_token_t; +#include #ifndef XAP_SUBSYSTEM_VERSION_KB # define XAP_SUBSYSTEM_VERSION_KB 0 @@ -31,27 +29,9 @@ typedef uint16_t xap_token_t; # define XAP_SUBSYSTEM_VERSION_USER 0 #endif -#define XAP_RESPONSE_FLAG_FAILED 0 -#define XAP_RESPONSE_FLAG_SUCCESS (1 << 0) -#define XAP_RESPONSE_FLAG_SECURE_FAILURE (1 << 1) - void xap_respond_failure(xap_token_t token, xap_response_flags_t response_flags); bool xap_respond_u32(xap_token_t token, uint32_t value); bool xap_respond_data(xap_token_t token, const void *data, size_t length); bool xap_respond_data_P(xap_token_t token, const void *data, size_t length); void xap_send(xap_token_t token, xap_response_flags_t response_flags, const void *data, size_t length); - -// TODO: gen from xap defs? -typedef struct { - xap_token_t token; - uint8_t length; -} xap_request_header_t; - -typedef struct { - xap_token_t token; - xap_response_flags_t flags; - uint8_t length; -} xap_response_header_t; - -#include