diff --git a/CMakeLists.txt b/CMakeLists.txt index cf90457..6f7b8e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,3 +31,5 @@ target_link_libraries(${PROJECT_NAME} PUBLIC etl hid-rp ) + +add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8658291..415f0bc 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,12 +1,12 @@ -set(C2USB_EXAMPLES_PUBLIC_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/leds_saving_keyboard.hpp - PARENT_SCOPE +add_library(${PROJECT_NAME}-example-hid) +target_sources(${PROJECT_NAME}-example-hid + PUBLIC + leds_saving_keyboard.hpp ) - -set(C2USB_EXAMPLES_PRIVATE_HEADERS - PARENT_SCOPE +target_include_directories(${PROJECT_NAME}-example-hid + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} ) - -set(C2USB_EXAMPLES_SOURCES - PARENT_SCOPE +target_link_libraries(${PROJECT_NAME}-example-hid PUBLIC + ${PROJECT_NAME} ) diff --git a/examples/leds_saving_keyboard.hpp b/examples/leds_saving_keyboard.hpp index eb1997a..b3bb337 100644 --- a/examples/leds_saving_keyboard.hpp +++ b/examples/leds_saving_keyboard.hpp @@ -33,20 +33,11 @@ class leds_saving_keyboard : public hid::application } leds_saving_keyboard(hid::page::keyboard_keypad key, hid::page::leds led) - : hid::application(report_prot()), - key_(static_cast(key)), - led_mask_(1 << (static_cast(led) - 1)) + : hid::application(report_prot()), key_(key), led_(led) {} auto send_key(bool set) { - if (set) - { - keys_buffer_.scancodes[0] = key_; - } - else - { - keys_buffer_.scancodes[0] = 0; - } + keys_buffer_.scancodes.set(key_, set); return send_report(&keys_buffer_); } void start(hid::protocol prot) override @@ -59,7 +50,7 @@ class leds_saving_keyboard : public hid::application { auto* out_report = reinterpret_cast(data.data()); - if ((out_report->leds & led_mask_) != 0) + if (out_report->leds.test(led_)) { send_key(true); } @@ -67,7 +58,7 @@ class leds_saving_keyboard : public hid::application } void in_report_sent(const std::span& data) override { - if (keys_buffer_.scancodes[0] == key_) + if (keys_buffer_.scancodes.test(key_)) { send_key(false); } @@ -80,8 +71,8 @@ class leds_saving_keyboard : public hid::application private: C2USB_USB_TRANSFER_ALIGN(keys_report, keys_buffer_){}; - const uint8_t key_{}; - const uint8_t led_mask_{}; + const hid::page::keyboard_keypad key_{}; + const hid::page::leds led_{}; C2USB_USB_TRANSFER_ALIGN(kb_leds_report, leds_buffer_){}; hid::protocol prot_{}; }; diff --git a/modules/hid-rp b/modules/hid-rp index 64c6dd6..7020f2f 160000 --- a/modules/hid-rp +++ b/modules/hid-rp @@ -1 +1 @@ -Subproject commit 64c6dd649e17dca023ea8bf6527c948a658f347f +Subproject commit 7020f2f9050440747fe1ba4c270d9d4843c449a8