2022-10-16 19:24:37 +00:00
|
|
|
{{ constants.GPL2_HEADER_C_LIKE }}
|
|
|
|
{{ constants.GENERATED_HEADER_C_LIKE }}
|
2022-10-16 02:19:15 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2023-01-06 02:49:37 +00:00
|
|
|
#include <stdbool.h>
|
2022-10-16 02:19:15 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Versions and identifiers
|
|
|
|
|
|
|
|
#define XAP_BCD_VERSION UINT32_C({{ xap.version | triplet_to_bcd }})
|
|
|
|
#define QMK_BCD_VERSION UINT32_C({{ qmk_version | triplet_to_bcd }})
|
|
|
|
#define XAP_KEYBOARD_IDENTIFIER UINT32_C({{ keyboard | fnv1a_32 }})
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Response flag definitions
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for bit,data in xap.response_flags.bits | dictsort %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define {{ xap.response_flags.define_prefix }}_{{ data.define | to_snake | upper }} (UINT32_C(1) << ({{ bit }}))
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define {{ xap.response_flags.define_prefix }}_FAILED 0x00
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Broadcast message definitions
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for message_id,data in xap.broadcast_messages.messages | dictsort %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define {{ xap.broadcast_messages.define_prefix }}_{{ data.define | to_snake | upper }} {{ message_id }}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% if 'return_type' in data %}
|
2022-10-16 02:19:15 +00:00
|
|
|
void {{ xap.broadcast_messages.define_prefix | lower }}_{{ data.define | to_snake | lower }}({{ data.return_type | type_to_c('value') }});
|
2023-01-06 02:49:37 +00:00
|
|
|
{% else %}
|
2022-10-16 02:19:15 +00:00
|
|
|
void {{ xap.broadcast_messages.define_prefix | lower }}_{{ data.define | to_snake | lower }}(const void *data, size_t length);
|
|
|
|
{% endif %}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define XAP_BROADCAST_TOKEN 0xFFFF
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Type definitions
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for name,data in xap.type_definitions | dictsort %}
|
|
|
|
{% if data.type != 'struct' %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef {{ data.type | type_to_c('xap_'+(name|to_snake|lower)+'_t') }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endif %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% endfor %}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for name,data in xap.type_definitions | dictsort %}
|
|
|
|
{% if data.type == 'struct' %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef struct {
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for member in data.struct_members %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{{ member.type | type_to_c(member.name) }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
} __attribute__((__packed__)) xap_{{ name | to_snake | lower }}_t{{ data.type | type_to_c_after }};
|
|
|
|
_Static_assert(sizeof(xap_{{ name | to_snake | lower }}_t) == {{ data.struct_length }}, "xap_{{ name | to_snake | lower }}_t needs to be {{ data.struct_length }} bytes in size");
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endif %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Route definitions
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% macro export_route_types(prefix, container) %}
|
|
|
|
{% if 'routes' in container %}
|
|
|
|
{% for route, data in container.routes | dictsort %}
|
|
|
|
{% set this_prefix_uc = (prefix + '_' + data.define) | upper %}
|
|
|
|
{% set this_prefix_lc = this_prefix_uc | lower %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% if 'request_struct_members' in data %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef struct {
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for member in data.request_struct_members %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{{ member.type | type_to_c(member.name|lower) }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
} __attribute__((__packed__)) {{ this_prefix_lc | to_snake | lower }}_arg_t;
|
|
|
|
_Static_assert(sizeof({{ this_prefix_lc | to_snake | lower }}_arg_t) == {{ data.request_struct_length }}, "{{ this_prefix_lc | to_snake | lower }}_arg_t needs to be {{ data.request_struct_length }} bytes in size");
|
2023-01-06 02:49:37 +00:00
|
|
|
{% elif 'request_type' in data %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef {{ data.request_type | type_to_c(this_prefix_lc+'_arg_t') }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endif %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% if 'return_struct_members' in data %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef struct {
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for member in data.return_struct_members %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{{ member.type | type_to_c(member.name|lower) }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
} __attribute__((__packed__)) {{ this_prefix_lc | to_snake | lower }}_t;
|
|
|
|
_Static_assert(sizeof({{ this_prefix_lc | to_snake | lower }}_t) == {{ data.return_struct_length }}, "{{ this_prefix_lc | to_snake | lower }}_t needs to be {{ data.return_struct_length }} bytes in size");
|
2023-01-06 02:49:37 +00:00
|
|
|
{% elif 'return_type' in data %}
|
|
|
|
{% if '[' in data.return_type %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef struct __attribute__((__packed__)) { {{ data.return_type | type_to_c('x') }}; } {{ this_prefix_lc }}_t;
|
2023-01-06 02:49:37 +00:00
|
|
|
{% else %}
|
2022-10-16 02:19:15 +00:00
|
|
|
typedef {{ data.return_type | type_to_c(this_prefix_lc+'_t') }};
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endif %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endif %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{{ export_route_types(this_prefix_lc, data) }}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
|
|
|
{{ export_route_types('xap_route', xap) }}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Capabilities IDs
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% macro export_route_ids(prefix, container) %}
|
|
|
|
{% if 'routes' in container %}
|
|
|
|
{% for route, data in container.routes | dictsort %}
|
|
|
|
{% set this_prefix_uc = (prefix + '_' + data.define) | upper %}
|
|
|
|
{% set this_prefix_lc = this_prefix_uc | lower %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define {{ this_prefix_uc }} {{ route }}
|
|
|
|
{{ export_route_ids(this_prefix_uc, data) }}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
|
|
|
{{ export_route_ids('XAP_ROUTE', xap) }}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Capabilities Masks
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% macro export_route_masks(prefix, container, preprocessor_condition) %}
|
|
|
|
{% if 'routes' in container %}
|
|
|
|
{% for route, data in container.routes | dictsort %}
|
|
|
|
{% set this_prefix_uc = (prefix + '_' + data.define) | upper %}
|
|
|
|
{% set this_prefix_lc = this_prefix_uc | lower %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% if 'enable_if_preprocessor' in data %}
|
|
|
|
{% if preprocessor_condition == 'TRUE' %}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% set condition = "(" + data.enable_if_preprocessor + ")" %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% else %}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% set condition = "(" + preprocessor_condition + " && (" + data.enable_if_preprocessor + "))" %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% endif %}
|
|
|
|
{% else %}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% set condition = preprocessor_condition %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if condition == 'TRUE' %}
|
|
|
|
#define {{ this_prefix_uc }}_MASK (UINT32_C(1) << ({{ this_prefix_uc }}))
|
|
|
|
{% else %}
|
|
|
|
#if ({{ condition }})
|
|
|
|
#define {{ this_prefix_uc }}_MASK (UINT32_C(1) << ({{ this_prefix_uc }}))
|
|
|
|
#else // ({{ condition }})
|
|
|
|
#define {{ this_prefix_uc }}_MASK 0
|
|
|
|
#endif // ({{ condition }})
|
|
|
|
{% endif %}
|
|
|
|
{{ export_route_masks(this_prefix_uc, data, condition) }}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
|
|
|
{{ export_route_masks('XAP_ROUTE', xap, 'TRUE') }}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Capabilities Values
|
|
|
|
|
2023-01-06 02:49:37 +00:00
|
|
|
{% macro export_route_capabilities(prefix, container) %}
|
|
|
|
{% if 'routes' in container %}
|
2022-10-16 02:19:15 +00:00
|
|
|
#define {{ prefix }}_CAPABILITIES (0 \
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for route, data in container.routes | dictsort %}
|
|
|
|
{% set this_prefix_uc = (prefix + '_' + data.define) | upper %}
|
2022-10-16 02:19:15 +00:00
|
|
|
| ({{ this_prefix_uc }}_MASK) \
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
2022-10-16 02:19:15 +00:00
|
|
|
)
|
2023-01-06 02:49:37 +00:00
|
|
|
{% for route, data in container.routes | dictsort %}
|
|
|
|
{% set this_prefix_uc = (prefix + '_' + data.define) | upper %}
|
2022-10-16 02:19:15 +00:00
|
|
|
{{ export_route_capabilities(this_prefix_uc, data) }}
|
2023-01-06 02:49:37 +00:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% endmacro %}
|
2022-10-16 02:19:15 +00:00
|
|
|
|
|
|
|
{{ export_route_capabilities('XAP_ROUTE', xap) }}
|