diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 0d211ef7493..4c3e6280f31 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -115,6 +115,7 @@ if (CONFIG_ZMK_STUDIO) zephyr_nanopb_sources(app proto/zmk/studio.proto + proto/zmk/meta.proto proto/zmk/core.proto proto/zmk/behaviors.proto proto/zmk/keymap.proto diff --git a/app/include/zmk/studio/rpc.h b/app/include/zmk/studio/rpc.h index c7c0b5d350a..bd10f5b7ee0 100644 --- a/app/include/zmk/studio/rpc.h +++ b/app/include/zmk/studio/rpc.h @@ -3,7 +3,7 @@ #include -#include +#include struct zmk_rpc_subsystem; @@ -39,8 +39,7 @@ struct zmk_rpc_subsystem_handler { } \ } \ LOG_ERR("No handler func found for %d", which_req); \ - zmk_Response fallback_resp = zmk_Response_init_zero; \ - return fallback_resp; \ + return ZMK_RPC_RESPONSE(meta, simple_error, zmk_meta_ErrorConditions_RPC_NOT_FOUND); \ } \ STRUCT_SECTION_ITERABLE(zmk_rpc_subsystem, prefix##_subsystem) = { \ .func = subsystem_func_##prefix, \ @@ -52,7 +51,7 @@ struct zmk_rpc_subsystem_handler { prefix##_subsystem_handler_##request_id) = { \ .func = request_id, \ .subsystem_choice = zmk_Request_##prefix##_tag, \ - .request_choice = zmk_##prefix##_response_##request_id##_tag, \ + .request_choice = zmk_##prefix##_Response_##request_id##_tag, \ }; #define ZMK_RPC_RESPONSE(subsys, _type, ...) \ @@ -68,7 +67,7 @@ struct zmk_rpc_subsystem_handler { .subsys = \ { \ .which_response_type = \ - zmk_##subsys##_response_##_type##_tag, \ + zmk_##subsys##_Response_##_type##_tag, \ .response_type = {._type = __VA_ARGS__}, \ }, \ }, \ diff --git a/app/proto/zmk/behaviors.options b/app/proto/zmk/behaviors.options index 377bc718c84..4e76e7790d6 100644 --- a/app/proto/zmk/behaviors.options +++ b/app/proto/zmk/behaviors.options @@ -1,2 +1,3 @@ -zmk.behaviors.list_all_behaviors_response.behaviors max_count:20 -zmk.behaviors.get_behavior_details_response.friendly_name max_size:20 \ No newline at end of file +zmk.behaviors.ListAllBehaviorsResponse.behaviors max_count:20 +zmk.behaviors.GetBehaviorDetailsResponse.friendly_name max_size:20 +zmk.behaviors.behavior_binding_parameter_details.name max_size:20 \ No newline at end of file diff --git a/app/proto/zmk/behaviors.proto b/app/proto/zmk/behaviors.proto index 7fb5ea3186b..9f874f1fe8d 100644 --- a/app/proto/zmk/behaviors.proto +++ b/app/proto/zmk/behaviors.proto @@ -2,29 +2,29 @@ syntax = "proto3"; package zmk.behaviors; -message request { +message Request { oneof request_type { bool list_all_behaviors = 1; - get_behavior_details_request get_behavior_details = 2; + GetBehaviorDetailsRequest get_behavior_details = 2; } } -message get_behavior_details_request { +message GetBehaviorDetailsRequest { uint32 behavior_id = 1; } -message response { +message Response { oneof response_type { - list_all_behaviors_response list_all_behaviors = 1; - get_behavior_details_response get_behavior_details = 2; + ListAllBehaviorsResponse list_all_behaviors = 1; + GetBehaviorDetailsResponse get_behavior_details = 2; } } -message list_all_behaviors_response { +message ListAllBehaviorsResponse { repeated uint32 behaviors = 1; } -message get_behavior_details_response { +message GetBehaviorDetailsResponse { uint32 id = 1; string friendly_name = 2; behavior_binding_parameter_details param1 = 3; @@ -36,8 +36,24 @@ message behavior_binding_parameter_details { string name = 2; } -enum behavior_binding_parameter_domain { - Nil = 0; - HIDUsage = 1; - LayerIndex = 2; +message behavior_binding_parameter_domain { + oneof type { + behavior_binding_parameter_domain_standard standard = 1; + behavior_binding_parameter_domain_custom custom = 2; + } +} + +message behavior_binding_parameter_domain_custom { + repeated behavior_binding_parameter_value_description values = 1; +} + +message behavior_binding_parameter_value_description { + int32 value = 1; + string name = 2; +} + +enum behavior_binding_parameter_domain_standard { + NIL = 0; + HID_USAGE = 1; + LAYER_INDEX = 2; } \ No newline at end of file diff --git a/app/proto/zmk/core.proto b/app/proto/zmk/core.proto index db8ad06afb8..930c3109fc6 100644 --- a/app/proto/zmk/core.proto +++ b/app/proto/zmk/core.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package zmk.core; -message request { +message Request { oneof request_type { bool get_lock_status = 1; bool unlock_request = 2; @@ -10,12 +10,12 @@ message request { } } -message get_lock_status_response { +message GetLockStatusResponse { bool locked = 1; } -message response { +message Response { oneof response_type { - get_lock_status_response get_lock_status = 1; + GetLockStatusResponse get_lock_status = 1; } } \ No newline at end of file diff --git a/app/proto/zmk/keymap.proto b/app/proto/zmk/keymap.proto index 9ae37788e5b..6ec2c9950ba 100644 --- a/app/proto/zmk/keymap.proto +++ b/app/proto/zmk/keymap.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package zmk.keymap; -message request { +message Request { oneof request_type { bool get_layer_summaries = 1; } diff --git a/app/proto/zmk/meta.proto b/app/proto/zmk/meta.proto new file mode 100644 index 00000000000..7a7ae92efbb --- /dev/null +++ b/app/proto/zmk/meta.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package zmk.meta; + +enum ErrorConditions { + GENERIC = 0; + RPC_NOT_FOUND = 1; + MSG_DECODE_FAILED = 2; + MSG_ENCODE_FAILED = 3; +} + +message Response { + oneof response_type { + ErrorConditions simple_error = 1; + } +} \ No newline at end of file diff --git a/app/proto/zmk/studio.proto b/app/proto/zmk/studio.proto index a2e71c87852..95e7442086e 100644 --- a/app/proto/zmk/studio.proto +++ b/app/proto/zmk/studio.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package zmk; +import "meta.proto"; import "core.proto"; import "behaviors.proto"; import "keymap.proto"; @@ -11,29 +12,12 @@ message Request { uint32 request_id = 1; oneof subsystem { - zmk.core.request core = 2; - zmk.keymap.request keymap = 3; - zmk.behaviors.request behaviors = 4; + zmk.core.Request core = 2; + zmk.keymap.Request keymap = 3; + zmk.behaviors.Request behaviors = 4; } } - -// keymap_request = { -// (0: get_layers_summary) -// } - -// behavior_request = { -// (0: list_all_behaviors) / -// (1: get_behavior_details) -// } - -// get_layers_summary = nil - -// list_all_behaviors = nil -// get_behavior_details = [ behavior_id: uint ] - -// ; Responses - message Response { oneof type { RequestResponse request_response = 1; @@ -44,12 +28,12 @@ message Response { message RequestResponse { uint32 request_id = 1; oneof subsystem { - zmk.core.response core = 2; - zmk.behaviors.response behaviors = 4; + zmk.meta.Response meta = 2; + zmk.core.Response core = 3; + zmk.behaviors.Response behaviors = 4; } } message Notification { uint32 notification_type = 1; - } diff --git a/app/src/studio/core_subsystem.c b/app/src/studio/core_subsystem.c index 8c869ade9a6..846b2c99b97 100644 --- a/app/src/studio/core_subsystem.c +++ b/app/src/studio/core_subsystem.c @@ -9,7 +9,7 @@ ZMK_RPC_SUBSYSTEM(core) #define CORE_RESPONSE(type, ...) ZMK_RPC_RESPONSE(core, type, __VA_ARGS__) zmk_Response get_lock_status(const zmk_Request *req) { - zmk_core_get_lock_status_response resp = zmk_core_get_lock_status_response_init_zero; + zmk_core_GetLockStatusResponse resp = zmk_core_GetLockStatusResponse_init_zero; resp.locked = true; return CORE_RESPONSE(get_lock_status, resp); diff --git a/app/src/studio/gatt_rpc_interface.c b/app/src/studio/gatt_rpc_interface.c index 05d219d9e02..89e33376786 100644 --- a/app/src/studio/gatt_rpc_interface.c +++ b/app/src/studio/gatt_rpc_interface.c @@ -19,8 +19,6 @@ #include #include -#include - #include LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); diff --git a/app/src/studio/rpc.c b/app/src/studio/rpc.c index 61adef7b710..18288831e62 100644 --- a/app/src/studio/rpc.c +++ b/app/src/studio/rpc.c @@ -8,10 +8,9 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include zmk_Response zmk_rpc_handle_request(const zmk_Request *req) { - LOG_WRN("Got a req of union type: %d", req->which_subsystem); + LOG_DBG("Request for subsystem %d", req->which_subsystem); STRUCT_SECTION_FOREACH(zmk_rpc_subsystem, sub) { if (sub->subsystem_choice == req->which_subsystem) { - LOG_WRN("Found a func!"); zmk_Response resp = sub->func(sub, req); resp.type.request_response.request_id = req->request_id; @@ -19,10 +18,7 @@ zmk_Response zmk_rpc_handle_request(const zmk_Request *req) { } } - LOG_WRN("No HANDLER FOUND"); - // TODO: NOT SUPPORTED - zmk_Response resp = zmk_Response_init_zero; - return resp; + return ZMK_RPC_RESPONSE(meta, simple_error, zmk_meta_ErrorConditions_RPC_NOT_FOUND); } static struct zmk_rpc_subsystem *find_subsystem_for_choice(uint8_t choice) { @@ -46,8 +42,6 @@ static int zmk_rpc_init(void) { __ASSERT(sub != NULL, "RPC Handler for unknown subsystem choice %d", handler->subsystem_choice); - LOG_DBG("Init handler %d sub %d", handler->request_choice, sub->subsystem_choice); - if (prev_choice < 0) { sub->handlers_start_index = i; } else if ((prev_choice != handler->subsystem_choice) && prev_sub) { diff --git a/app/src/studio/uart_rpc_interface.c b/app/src/studio/uart_rpc_interface.c index 028bad0269f..e876a03fe4f 100644 --- a/app/src/studio/uart_rpc_interface.c +++ b/app/src/studio/uart_rpc_interface.c @@ -14,14 +14,9 @@ #include "common.h" -// #include -// #include - #include #include -#include - LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #include