Skip to content

Commit

Permalink
update hid-rp
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Feb 19, 2024
1 parent ea4a631 commit 1781c62
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ target_link_libraries(${PROJECT_NAME} PUBLIC
etl
hid-rp
)

add_subdirectory(examples)
18 changes: 9 additions & 9 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
21 changes: 6 additions & 15 deletions examples/leds_saving_keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(key)),
led_mask_(1 << (static_cast<uint8_t>(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
Expand All @@ -59,15 +50,15 @@ class leds_saving_keyboard : public hid::application
{
auto* out_report = reinterpret_cast<const kb_leds_report*>(data.data());

if ((out_report->leds & led_mask_) != 0)
if (out_report->leds.test(led_))
{
send_key(true);
}
receive_report(&leds_buffer_);
}
void in_report_sent(const std::span<const uint8_t>& data) override
{
if (keys_buffer_.scancodes[0] == key_)
if (keys_buffer_.scancodes.test(key_))
{
send_key(false);
}
Expand All @@ -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_{};
};
Expand Down

0 comments on commit 1781c62

Please sign in to comment.