Hello,
I would like some help in understanding how HID over GATT works in the nRF Connect SDK.
I'm digging into the peripheral_hid_mouse example, and I don't understand how to structure the data, for example mouse movement is sent like this:
uint8_t x_buff[2]; uint8_t y_buff[2]; uint8_t buffer[INPUT_REP_MOVEMENT_LEN]; int16_t x = MAX(MIN(x_delta, 0x07ff), -0x07ff); int16_t y = MAX(MIN(y_delta, 0x07ff), -0x07ff); /* Convert to little-endian. */ sys_put_le16(x, x_buff); sys_put_le16(y, y_buff); /* Encode report. */ BUILD_ASSERT(sizeof(buffer) == 3, "Only 2 axis, 12-bit each, are supported"); buffer[0] = x_buff[0]; buffer[1] = (y_buff[0] << 4) | (x_buff[1] & 0x0f); buffer[2] = (y_buff[1] << 4) | (y_buff[0] >> 4); bt_hids_inp_rep_send(&hids_obj, conn_mode[i].conn, INPUT_REP_MOVEMENT_INDEX, buffer, sizeof(buffer), NULL);
My questions:
- Why are mouse movements converted to little endian? In the standard HID mouse example there is no need for this and the mouse works the same
- Why are the X/Y displacement values sent across three bytes? My understanding is that you either send 2 bytes as 8 bits per axis or 4 bytes as 16 bit per axis
After digging a bit I tried the following code with no success:
// Send movement buffer[0] = x_buff[0]; buffer[1] = (y_buff[0] << 4) | (x_buff[1] & 0x0f); buffer[2] = (y_buff[1] << 4) | (y_buff[0] >> 4); bt_hids_inp_rep_send(&hids_obj, conn_mode.conn, INPUT_REP_MOVEMENT_INDEX, buffer, sizeof(buffer), NULL); // Send a right click buffer[0] = 0b10000000; buffer[1] = 0x0; buffer[2] = 0x0; bt_hids_inp_rep_send(&hids_obj, conn_mode.conn, INPUT_REP_BUTTONS_INDEX, buffer, sizeof(buffer), NULL);
The general question here is, how do I properly send both buttons and movement data with bt_hids_inp_rep_send()?
Thanks