mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-04-07 22:35:42 +00:00
Add types codegen
This commit is contained in:
parent
ffcdfc6c03
commit
53052228df
@ -101,10 +101,6 @@
|
|||||||
'''
|
'''
|
||||||
A high-level area of functionality within XAP.
|
A high-level area of functionality within XAP.
|
||||||
'''
|
'''
|
||||||
ID:
|
|
||||||
'''
|
|
||||||
A single octet / 8-bit byte.
|
|
||||||
'''
|
|
||||||
Route:
|
Route:
|
||||||
'''
|
'''
|
||||||
A sequence of _IDs_ describing the route to invoke a _handler_.
|
A sequence of _IDs_ describing the route to invoke a _handler_.
|
||||||
@ -113,24 +109,72 @@
|
|||||||
'''
|
'''
|
||||||
A piece of code that is executed when a specific _route_ is received.
|
A piece of code that is executed when a specific _route_ is received.
|
||||||
'''
|
'''
|
||||||
Token:
|
|
||||||
'''
|
|
||||||
A `u16` associated with a specific request as well as its corresponding response.
|
|
||||||
'''
|
|
||||||
Response:
|
Response:
|
||||||
'''
|
'''
|
||||||
The data sent back to the host during execution of a _handler_.
|
The data sent back to the host during execution of a _handler_.
|
||||||
'''
|
'''
|
||||||
"Response Flags":
|
|
||||||
'''
|
|
||||||
An `u8` containing the status of the request.
|
|
||||||
'''
|
|
||||||
Payload:
|
Payload:
|
||||||
'''
|
'''
|
||||||
Any received data appended to the _route_, which gets delivered to the _handler_ when received.
|
Any received data appended to the _route_, which gets delivered to the _handler_ when received.
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
types: {
|
||||||
|
identifier: {
|
||||||
|
name: ID
|
||||||
|
description: Subsystem/Route ID
|
||||||
|
type: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
response_flags: {
|
||||||
|
name: Response Flags
|
||||||
|
description: Contains the status of the request
|
||||||
|
type: u8
|
||||||
|
}
|
||||||
|
|
||||||
|
token: {
|
||||||
|
name: Token
|
||||||
|
description: ID associated with a specific request as well as its corresponding response
|
||||||
|
type: u16
|
||||||
|
}
|
||||||
|
|
||||||
|
request_header: {
|
||||||
|
name: Request Header
|
||||||
|
description: asdf
|
||||||
|
type: struct
|
||||||
|
struct_members: [
|
||||||
|
{
|
||||||
|
type: token
|
||||||
|
name: token
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: u8
|
||||||
|
name: length
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
response_header: {
|
||||||
|
name: Response Header
|
||||||
|
description: asdf
|
||||||
|
type: struct
|
||||||
|
struct_members: [
|
||||||
|
{
|
||||||
|
type: token
|
||||||
|
name: token
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: response_flags
|
||||||
|
name: flags
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: u8
|
||||||
|
name: length
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response_flags: {
|
response_flags: {
|
||||||
define_prefix: XAP_RESPONSE_FLAG
|
define_prefix: XAP_RESPONSE_FLAG
|
||||||
bits: {
|
bits: {
|
||||||
|
@ -9,6 +9,24 @@ from qmk.constants import GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE
|
|||||||
from qmk.xap.common import latest_xap_defs, route_conditions
|
from qmk.xap.common import latest_xap_defs, route_conditions
|
||||||
|
|
||||||
|
|
||||||
|
def _get_c_type(xap_type):
|
||||||
|
if xap_type == 'bool':
|
||||||
|
return 'bool'
|
||||||
|
elif xap_type == 'u8':
|
||||||
|
return 'uint8_t'
|
||||||
|
elif xap_type == 'u16':
|
||||||
|
return 'uint16_t'
|
||||||
|
elif xap_type == 'u32':
|
||||||
|
return 'uint32_t'
|
||||||
|
elif xap_type == 'u64':
|
||||||
|
return 'uint64_t'
|
||||||
|
elif xap_type == 'struct':
|
||||||
|
return 'struct'
|
||||||
|
elif xap_type == 'string':
|
||||||
|
return 'const char *'
|
||||||
|
return 'unknown'
|
||||||
|
|
||||||
|
|
||||||
def _append_route_defines(lines, container, container_id=None, route_stack=None):
|
def _append_route_defines(lines, container, container_id=None, route_stack=None):
|
||||||
"""Handles building the list of the XAP routes, combining parent and child names together, as well as the route number.
|
"""Handles building the list of the XAP routes, combining parent and child names together, as well as the route number.
|
||||||
"""
|
"""
|
||||||
@ -105,25 +123,29 @@ def _append_types(lines, container):
|
|||||||
|
|
||||||
# Add special
|
# Add special
|
||||||
lines.append(f'#define {prefix}_FAILED 0x00')
|
lines.append(f'#define {prefix}_FAILED 0x00')
|
||||||
|
lines.append('')
|
||||||
|
|
||||||
# TODO: define this in xap_*.hjson
|
additional_types = {}
|
||||||
lines.append(
|
types = container.get('types', {})
|
||||||
'''
|
for key, value in types.items():
|
||||||
typedef uint8_t xap_identifier_t;
|
data_type = _get_c_type(value['type'])
|
||||||
typedef uint8_t xap_response_flags_t;
|
additional_types[key] = f'xap_{key}_t'
|
||||||
typedef uint16_t xap_token_t;
|
|
||||||
|
|
||||||
typedef struct {
|
for key, value in types.items():
|
||||||
xap_token_t token;
|
data_type = _get_c_type(value['type'])
|
||||||
uint8_t length;
|
if data_type == 'struct':
|
||||||
} xap_request_header_t;
|
members = value['struct_members']
|
||||||
|
|
||||||
typedef struct {
|
lines.append(f'typedef {data_type} {{')
|
||||||
xap_token_t token;
|
for member in members:
|
||||||
xap_response_flags_t flags;
|
member_name = member["name"]
|
||||||
uint8_t length;
|
member_type = _get_c_type(member["type"])
|
||||||
} xap_response_header_t;'''
|
if member_type == 'unknown':
|
||||||
)
|
member_type = additional_types[member["type"]]
|
||||||
|
lines.append(f' {member_type} {member_name};')
|
||||||
|
lines.append(f'}} xap_{key}_t;')
|
||||||
|
else:
|
||||||
|
lines.append(f'typedef {data_type} xap_{key}_t;')
|
||||||
|
|
||||||
|
|
||||||
def generate_header(output_file, keyboard):
|
def generate_header(output_file, keyboard):
|
||||||
|
Loading…
Reference in New Issue
Block a user