From 689ce0c1aa9fb622f684d7e7128d0395f1431ba2 Mon Sep 17 00:00:00 2001 From: Benedek Kupper Date: Sat, 9 Dec 2023 23:05:42 +0100 Subject: [PATCH] extend report protocol methods, fix initialization --- hid-rp/hid/report.hpp | 2 +- hid-rp/hid/report_protocol.hpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hid-rp/hid/report.hpp b/hid-rp/hid/report.hpp index 844006b..becca9f 100644 --- a/hid-rp/hid/report.hpp +++ b/hid-rp/hid/report.hpp @@ -76,7 +76,7 @@ namespace hid constexpr bool operator !=(const selector& rhs) const = default; private: - std::array storage_; + std::array storage_{}; }; struct id_base diff --git a/hid-rp/hid/report_protocol.hpp b/hid-rp/hid/report_protocol.hpp index 181f423..8b70894 100644 --- a/hid-rp/hid/report_protocol.hpp +++ b/hid-rp/hid/report_protocol.hpp @@ -33,12 +33,40 @@ struct report_protocol_properties { return std::max(max_input_size, std::max(max_output_size, max_feature_size)); } + constexpr size_type max_report_size(report::type type) const + { + switch (type) + { + case report::type::INPUT: + return max_input_size; + case report::type::OUTPUT: + return max_output_size; + case report::type::FEATURE: + return max_feature_size; + default: + return 0; + } + } constexpr bool uses_report_ids() const { return max_report_id() >= report::id::min(); } constexpr report::id::type max_report_id() const { return std::max(max_input_id, std::max(max_output_id, max_feature_id)); } + constexpr report::id::type max_report_id(report::type type) const + { + switch (type) + { + case report::type::INPUT: + return max_input_id; + case report::type::OUTPUT: + return max_output_id; + case report::type::FEATURE: + return max_feature_id; + default: + return 0; + } + } /// @brief Define the report protocol properties, with no report ID use. /// @param max_input_size: The size of the longest INPUT report in bytes, including the report