Skip to content

Commit

Permalink
Fix USBCV HID tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pschmuckal authored and Gentoli committed Jul 23, 2020
1 parent d9e464c commit a0c746e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 61 deletions.
2 changes: 1 addition & 1 deletion tmk_core/protocol/arm_atsam/usb/udi_device_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ typedef struct {
} udi_hid_raw_desc_t;

typedef struct {
uint8_t array[27];
uint8_t array[28];
} udi_hid_raw_report_desc_t;

# define UDI_HID_RAW_DESC \
Expand Down
10 changes: 7 additions & 3 deletions tmk_core/protocol/arm_atsam/usb/udi_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@
/*
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
*/

#include <string.h>
#include "conf_usb.h"
#include "usb_protocol.h"
#include "udd.h"
#include "udc.h"
#include "udi_hid.h"

COMPILER_WORD_ALIGNED
static uint8_t udi_hid_desc_buf[sizeof(usb_hid_descriptor_t)];

/**
* \ingroup udi_hid_group
* \defgroup udi_hid_group_internal Implementation of HID common library
Expand Down Expand Up @@ -129,8 +132,9 @@ static bool udi_hid_reqstdifaceget_descriptor(uint8_t *report_desc) {
// - or USB_DT_HID_REPORT descriptor
// - or USB_DT_HID_PHYSICAL descriptor
if (USB_DT_HID == (uint8_t)(udd_g_ctrlreq.req.wValue >> 8)) {
// USB_DT_HID descriptor requested then send it
udd_g_ctrlreq.payload = (uint8_t *)ptr_hid_desc;
// USB_DT_HID descriptor requested, copy into word aligned buffer, then send it
memcpy(udi_hid_desc_buf, (uint8_t *)ptr_hid_desc, sizeof(usb_hid_descriptor_t));
udd_g_ctrlreq.payload = udi_hid_desc_buf;
udd_g_ctrlreq.payload_size = min(udd_g_ctrlreq.req.wLength, ptr_hid_desc->bLength);
return true;
}
Expand Down
97 changes: 40 additions & 57 deletions tmk_core/protocol/arm_atsam/usb/udi_hid_kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {{
0x81, 0x02, // Input (Data, Variable, Absolute)
0x81, 0x01, // Input (Constant)
0x19, 0x00, // Usage Minimum (0)
0x29, 0xFF, // Usage Maximum (255)
0x29, 0x65, // Usage Maximum (255) --> 101
0x15, 0x00, // Logical Minimum (0)
0x25, 0xFF, // Logical Maximum (255)
0x25, 0x65, // Logical Maximum (255) --> 101
0x75, 0x08, // Report Size (8)
0x95, 0x06, // Report Count (6)
0x81, 0x00, // Input (Data, Array)
Expand Down Expand Up @@ -643,19 +643,19 @@ static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE];

COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{
0x06, 0xBC, 0xFF, // Usage Page (Drop mfgr specific)
0x0A, 0x34, 0x02, // Usage (Drop mfgr specific)
0xA1, 0x01, // Collection (Application)
0x75, 0x08, // Report Size (8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0xFF, // Logical Maximum (255)
0x95, 0x40, // Report Count
0x09, 0x01, // Usage (Input)
0x81, 0x02, // Input (Data
0x95, 0x40, // Report Count
0x09, 0x02, // Usage (Output)
0x91, 0x02, // Output (Data
0xC0, // End Collection - Consumer Control
0x06, 0xBC, 0xFF, // Usage Page (Drop mfgr specific)
0x0A, 0x34, 0x02, // Usage (Drop mfgr specific)
0xA1, 0x01, // Collection (Application)
0x75, 0x08, // Report Size (8)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (0x00FF) = 255
0x95, 0x40, // Report Count
0x09, 0x01, // Usage (Input)
0x81, 0x02, // Input (Data)
0x95, 0x40, // Report Count
0x09, 0x02, // Usage (Output)
0x91, 0x02, // Output (Data)
0xC0, // End Collection - Consumer Control
}};

static bool udi_hid_raw_setreport(void);
Expand All @@ -669,7 +669,6 @@ __attribute__((weak)) void raw_hid_receive(uint8_t *data, uint8_t length) {
// so users can opt to not handle data coming in.
}


/**
* \brief Enable reception of out report
*
Expand All @@ -683,20 +682,16 @@ bool udi_hid_raw_enable(void) {
udi_hid_raw_protocol = 0;
udi_hid_raw_b_report_trans_ongoing = false;
memset(udi_hid_raw_report, 0, UDI_HID_RAW_REPORT_SIZE);
if (!udi_hid_raw_report_out_enable()) // PS120919
return false;
if (!udi_hid_raw_report_out_enable()) // PS120919
return false;
return UDI_HID_RAW_ENABLE_EXT();
}

void udi_hid_raw_disable(void) { UDI_HID_RAW_DISABLE_EXT(); }

bool udi_hid_raw_setup(void) {
return udi_hid_setup(&udi_hid_raw_rate, &udi_hid_raw_protocol, (uint8_t *)&udi_hid_raw_report_desc, udi_hid_raw_setreport);
}
bool udi_hid_raw_setup(void) { return udi_hid_setup(&udi_hid_raw_rate, &udi_hid_raw_protocol, (uint8_t *)&udi_hid_raw_report_desc, udi_hid_raw_setreport); }

uint8_t udi_hid_raw_getsetting(void) {
return 0;
}
uint8_t udi_hid_raw_getsetting(void) { return 0; }

static bool udi_hid_raw_setreport(void) {
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (UDI_HID_RAW_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
Expand Down Expand Up @@ -732,37 +727,26 @@ static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_raw_b_report_trans_ongoing = false;
//if (udi_hid_raw_b_report_valid) {
// if (udi_hid_raw_b_report_valid) {
// udi_hid_raw_send_report(); // retrigger if more data
//}
}

static void udi_hid_raw_setreport_valid(void) {}

static void udi_hid_raw_report_out_received(udd_ep_status_t status, iram_size_t nb_received, udd_ep_id_t ep) {
UNUSED(ep);
if (UDD_EP_TRANSFER_OK != status) return; // Abort reception

static void udi_hid_raw_report_out_received(udd_ep_status_t status,
iram_size_t nb_received, udd_ep_id_t ep)
{
UNUSED(ep);
if (UDD_EP_TRANSFER_OK != status)
return; // Abort reception

if (sizeof(udi_hid_raw_report_out) == nb_received) {
// need to turn off IRQs?
memcpy( udi_hid_raw_report_out_cp, udi_hid_raw_report_out, sizeof(udi_hid_raw_report_out )); // Make a copy of report (necessary?)
raw_hid_receive( udi_hid_raw_report_out_cp, RAW_EPSIZE );
}
udi_hid_raw_report_out_enable();
if (sizeof(udi_hid_raw_report_out) == nb_received) {
// need to turn off IRQs?
memcpy(udi_hid_raw_report_out_cp, udi_hid_raw_report_out, sizeof(udi_hid_raw_report_out)); // Make a copy of report (necessary?)
raw_hid_receive(udi_hid_raw_report_out_cp, RAW_EPSIZE);
}
udi_hid_raw_report_out_enable();
}

static bool udi_hid_raw_report_out_enable(void)
{
return udd_ep_run(UDI_HID_RAW_EP_OUT,
false,
(uint8_t *) &udi_hid_raw_report_out,
sizeof(udi_hid_raw_report_out),
udi_hid_raw_report_out_received);
}
static bool udi_hid_raw_report_out_enable(void) { return udd_ep_run(UDI_HID_RAW_EP_OUT, false, (uint8_t *)&udi_hid_raw_report_out, sizeof(udi_hid_raw_report_out), udi_hid_raw_report_out_received); }

void raw_hid_send(uint8_t *data, uint8_t length) {
uint32_t irqflags;
Expand All @@ -771,20 +755,20 @@ void raw_hid_send(uint8_t *data, uint8_t length) {
return;
}

while (udi_hid_raw_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete
while (udi_hid_raw_b_report_trans_ongoing) {
} // Wait for any previous transfers to complete

irqflags = __get_PRIMASK();
__disable_irq();
__DMB();
irqflags = __get_PRIMASK();
__disable_irq();
__DMB();

memcpy(udi_hid_raw_report, data, length); // Copy data into the send buffer
memcpy(udi_hid_raw_report, data, length); // Copy data into the send buffer

//udi_hid_raw_b_report_valid = 1; // Set report valid
udi_hid_raw_send_report(length); // Send report
// udi_hid_raw_b_report_valid = 1; // Set report valid
udi_hid_raw_send_report(length); // Send report

__DMB();
__set_PRIMASK(irqflags);
__DMB();
__set_PRIMASK(irqflags);
}

#endif // RAW
Expand Down Expand Up @@ -906,4 +890,3 @@ static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
static void udi_hid_con_setreport_valid(void) {}

#endif // CON

0 comments on commit a0c746e

Please sign in to comment.