Skip to content

Commit

Permalink
migrate to events
Browse files Browse the repository at this point in the history
  • Loading branch information
zzeneg committed Dec 26, 2024
1 parent 29341e1 commit e2203a7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if (CONFIG_RAW_HID)
zephyr_library()

zephyr_library_sources(src/raw_hid.c)
zephyr_library_sources(src/events.c)
zephyr_library_sources(src/usb_hid.c)

if (CONFIG_ZMK_BLE)
Expand Down
10 changes: 10 additions & 0 deletions include/raw_hid/events.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <zmk/event_manager.h>

struct raw_hid_received_event {
uint8_t *data;
uint8_t length;
};

ZMK_EVENT_DECLARE(raw_hid_received_event);
2 changes: 0 additions & 2 deletions include/raw_hid/raw_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,3 @@ static const uint8_t raw_hid_report_desc[] = {

HID_END_COLLECTION,
};

void process_raw_hid_data(uint8_t *data);
6 changes: 6 additions & 0 deletions src/events.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <raw_hid/events.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

ZMK_EVENT_IMPL(raw_hid_received_event);
3 changes: 2 additions & 1 deletion src/hog.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <raw_hid/raw_hid.h>
#include <raw_hid/events.h>

#include <zephyr/bluetooth/gatt.h>

Expand Down Expand Up @@ -66,7 +67,7 @@ static ssize_t write_hids_raw_hid_report(struct bt_conn *conn, const struct bt_g
}

uint8_t *data = (uint8_t *)buf;
process_raw_hid_data(data);
raise_raw_hid_received_event((struct raw_hid_received_event){.data = data, .length = len});

return len;
}
Expand Down
10 changes: 0 additions & 10 deletions src/raw_hid.c

This file was deleted.

3 changes: 2 additions & 1 deletion src/usb_hid.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <raw_hid/raw_hid.h>
#include <raw_hid/events.h>

#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
Expand Down Expand Up @@ -30,7 +31,7 @@ static int set_report_cb(const struct device *dev, struct usb_setup_packet *setu
return -ENOTSUP;
}

process_raw_hid_data(*data);
raise_raw_hid_received_event((struct raw_hid_received_event){.data = *data, .length = *len});

return 0;
}
Expand Down

0 comments on commit e2203a7

Please sign in to comment.