Skip to content

Commit

Permalink
[nrf52] Read keyboard LED reports
Browse files Browse the repository at this point in the history
Because on nRF52 all of our USB interfaces have OUT endpoints, we are
not getting CapsLock etc. LED states through set_report_cb(). Instead
we have to register an int_out_ready callback and read them from
there.

We still don't forward LED states to the devices connected over
Bluetooth, but it should now be possible to use LED states as inputs,
for layers etc., same as on the RP2040 version.
  • Loading branch information
jfedor2 committed Jan 3, 2025
1 parent 8885f21 commit f2650b3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions firmware-bluetooth/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static const struct device* hid_dev0;
static const struct device* hid_dev1; // config interface

struct report_type {
uint8_t conn_idx;
uint16_t interface;
uint8_t len;
uint8_t data[65];
};
Expand Down Expand Up @@ -503,7 +503,7 @@ static uint8_t hogp_notify_cb(struct bt_hogp* hogp, struct bt_hogp_rep_info* rep
}

static struct report_type buf;
buf.conn_idx = hogp_index(hogp);
buf.interface = hogp_index(hogp) << 8;
buf.len = bt_hogp_rep_size(rep) + 1;
buf.data[0] = bt_hogp_rep_id(rep);

Expand Down Expand Up @@ -676,6 +676,16 @@ static void int_in_ready_cb0(const struct device* dev) {
k_sem_give(&usb_sem0);
}

static void int_out_ready_cb0(const struct device* dev) {
static struct report_type buf;
uint32_t len;
if (CHK(hid_int_ep_read(hid_dev0, buf.data, sizeof(buf.data), &len))) {
buf.interface = OUR_OUT_INTERFACE;
buf.len = len;
CHK(k_msgq_put(&report_q, &buf, K_NO_WAIT));
}
}

static void int_in_ready_cb1(const struct device* dev) {
k_sem_give(&usb_sem1);
}
Expand All @@ -684,6 +694,7 @@ static const struct hid_ops ops0 = {
.get_report = get_report_cb,
.set_report = set_report_cb,
.int_in_ready = int_in_ready_cb0,
.int_out_ready = int_out_ready_cb0,
};

static const struct hid_ops ops1 = {
Expand Down Expand Up @@ -912,7 +923,7 @@ int main() {

while (true) {
if (!process_pending && !k_msgq_get(&report_q, &incoming_report, K_NO_WAIT)) {
handle_received_report(incoming_report.data, incoming_report.len, (uint16_t) incoming_report.conn_idx << 8);
handle_received_report(incoming_report.data, incoming_report.len, (uint16_t) incoming_report.interface);
process_pending = true;
}
if (atomic_test_and_clear_bit(tick_pending, 0)) {
Expand Down

0 comments on commit f2650b3

Please sign in to comment.