#include "samd51j18a.h"
#include "d51_util.h"
#include "conf_usb.h"
#include "usb_protocol.h"
#include "udd.h"
#include "udc.h"
#include "udi_device_conf.h"
#include "udi_hid.h"
#include "udi_hid_kbd.h"
#include <string.h>
#include "report.h"
#include "usb_descriptor_common.h"
bool udi_hid_kbd_enable(void);
void udi_hid_kbd_disable(void);
bool udi_hid_kbd_setup(void);
uint8_t udi_hid_kbd_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_kbd = {
.enable = (bool (*)(void))udi_hid_kbd_enable,
.disable = (void (*)(void))udi_hid_kbd_disable,
.setup = (bool (*)(void))udi_hid_kbd_setup,
.getsetting = (uint8_t(*)(void))udi_hid_kbd_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_kbd_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_kbd_protocol;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_kbd_report_set;
bool udi_hid_kbd_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_kbd_report[UDI_HID_KBD_REPORT_SIZE];
volatile bool udi_hid_kbd_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_kbd_report_trans[UDI_HID_KBD_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_kbd_report_desc_t udi_hid_kbd_report_desc = {{
0x05, 0x01, 0x09, 0x06, 0xA1, 0x01, 0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0x81, 0x01, 0x19, 0x00, 0x29, 0xFF, 0x15, 0x00, 0x25, 0xFF, 0x95, 0x06, 0x75, 0x08, 0x81, 0x00,
0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x15, 0x00, 0x25, 0x01, 0x95, 0x05, 0x75, 0x01, 0x91, 0x02, 0x95, 0x03, 0x91, 0x01, 0xC0 }};
static bool udi_hid_kbd_setreport(void);
static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
static void udi_hid_kbd_setreport_valid(void);
bool udi_hid_kbd_enable(void) {
udi_hid_kbd_rate = 0;
udi_hid_kbd_protocol = 0;
udi_hid_kbd_b_report_trans_ongoing = false;
memset(udi_hid_kbd_report, 0, UDI_HID_KBD_REPORT_SIZE);
udi_hid_kbd_b_report_valid = false;
return UDI_HID_KBD_ENABLE_EXT();
}
void udi_hid_kbd_disable(void) { UDI_HID_KBD_DISABLE_EXT(); }
bool udi_hid_kbd_setup(void) { return udi_hid_setup(&udi_hid_kbd_rate, &udi_hid_kbd_protocol, (uint8_t *)&udi_hid_kbd_report_desc, udi_hid_kbd_setreport); }
uint8_t udi_hid_kbd_getsetting(void) { return 0; }
static bool udi_hid_kbd_setreport(void) {
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
udd_g_ctrlreq.payload = &udi_hid_kbd_report_set;
udd_g_ctrlreq.callback = udi_hid_kbd_setreport_valid;
udd_g_ctrlreq.payload_size = 1;
return true;
}
return false;
}
bool udi_hid_kbd_send_report(void) {
if (!main_b_kbd_enable) {
return false;
}
if (udi_hid_kbd_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_kbd_report_trans, udi_hid_kbd_report, UDI_HID_KBD_REPORT_SIZE);
udi_hid_kbd_b_report_valid = false;
udi_hid_kbd_b_report_trans_ongoing = udd_ep_run(UDI_HID_KBD_EP_IN | USB_EP_DIR_IN, false, udi_hid_kbd_report_trans, UDI_HID_KBD_REPORT_SIZE, udi_hid_kbd_report_sent);
return udi_hid_kbd_b_report_trans_ongoing;
}
static void udi_hid_kbd_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_kbd_b_report_trans_ongoing = false;
if (udi_hid_kbd_b_report_valid) {
udi_hid_kbd_send_report();
}
}
static void udi_hid_kbd_setreport_valid(void) {
}
#ifdef NKRO_ENABLE
bool udi_hid_nkro_enable(void);
void udi_hid_nkro_disable(void);
bool udi_hid_nkro_setup(void);
uint8_t udi_hid_nkro_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_nkro = {
.enable = (bool (*)(void))udi_hid_nkro_enable,
.disable = (void (*)(void))udi_hid_nkro_disable,
.setup = (bool (*)(void))udi_hid_nkro_setup,
.getsetting = (uint8_t(*)(void))udi_hid_nkro_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_nkro_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_nkro_protocol;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_nkro_report_set;
bool udi_hid_nkro_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_nkro_report[UDI_HID_NKRO_REPORT_SIZE];
volatile bool udi_hid_nkro_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_nkro_report_trans[UDI_HID_NKRO_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_nkro_report_desc_t udi_hid_nkro_report_desc = {{
0x05, 0x01, 0x09, 0x06, 0xA1, 0x01,
0x05, 0x07, 0x19, 0xE0, 0x29, 0xE7, 0x15, 0x00, 0x25, 0x01, 0x95, 0x08, 0x75, 0x01, 0x81, 0x02, 0x05, 0x07, 0x19, 0x00, 0x29, 0xF7, 0x15, 0x00, 0x25, 0x01, 0x95, 0xF8, 0x75, 0x01, 0x81, 0x02,
0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x95, 0x05, 0x75, 0x01, 0x91, 0x02, 0x95, 0x01, 0x75, 0x03, 0x91, 0x03, 0xC0 }};
static bool udi_hid_nkro_setreport(void);
static void udi_hid_nkro_setreport_valid(void);
static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
bool udi_hid_nkro_enable(void) {
udi_hid_nkro_rate = 0;
udi_hid_nkro_protocol = 0;
udi_hid_nkro_b_report_trans_ongoing = false;
memset(udi_hid_nkro_report, 0, UDI_HID_NKRO_REPORT_SIZE);
udi_hid_nkro_b_report_valid = false;
return UDI_HID_NKRO_ENABLE_EXT();
}
void udi_hid_nkro_disable(void) { UDI_HID_NKRO_DISABLE_EXT(); }
bool udi_hid_nkro_setup(void) { return udi_hid_setup(&udi_hid_nkro_rate, &udi_hid_nkro_protocol, (uint8_t *)&udi_hid_nkro_report_desc, udi_hid_nkro_setreport); }
uint8_t udi_hid_nkro_getsetting(void) { return 0; }
static bool udi_hid_nkro_setreport(void) {
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
udd_g_ctrlreq.payload = &udi_hid_nkro_report_set;
udd_g_ctrlreq.callback = udi_hid_nkro_setreport_valid; udd_g_ctrlreq.payload_size = 1;
return true;
}
return false;
}
bool udi_hid_nkro_send_report(void) {
if (!main_b_nkro_enable) {
return false;
}
if (udi_hid_nkro_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_nkro_report_trans, udi_hid_nkro_report, UDI_HID_NKRO_REPORT_SIZE);
udi_hid_nkro_b_report_valid = false;
udi_hid_nkro_b_report_trans_ongoing = udd_ep_run(UDI_HID_NKRO_EP_IN | USB_EP_DIR_IN, false, udi_hid_nkro_report_trans, UDI_HID_NKRO_REPORT_SIZE, udi_hid_nkro_report_sent);
return udi_hid_nkro_b_report_trans_ongoing;
}
static void udi_hid_nkro_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_nkro_b_report_trans_ongoing = false;
if (udi_hid_nkro_b_report_valid) {
udi_hid_nkro_send_report();
}
}
static void udi_hid_nkro_setreport_valid(void) {
}
#endif
#ifdef EXTRAKEY_ENABLE
bool udi_hid_exk_enable(void);
void udi_hid_exk_disable(void);
bool udi_hid_exk_setup(void);
uint8_t udi_hid_exk_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_exk = {
.enable = (bool (*)(void))udi_hid_exk_enable,
.disable = (void (*)(void))udi_hid_exk_disable,
.setup = (bool (*)(void))udi_hid_exk_setup,
.getsetting = (uint8_t(*)(void))udi_hid_exk_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_exk_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_exk_protocol;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_exk_report_set;
bool udi_hid_exk_b_report_valid;
COMPILER_WORD_ALIGNED
udi_hid_exk_report_t udi_hid_exk_report;
static bool udi_hid_exk_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_exk_report_trans[UDI_HID_EXK_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{
0x05, 0x01, 0x09, 0x80, 0xA1, 0x01, 0x85, REPORT_ID_SYSTEM, 0x19, 0x01, 0x2A, 0xB7, 0x00, 0x15, 0x01, 0x26, 0xB7, 0x00, 0x95, 0x01, 0x75, 0x10, 0x81, 0x00, 0xC0,
0x05, 0x0C, 0x09, 0x01, 0xA1, 0x01, 0x85, REPORT_ID_CONSUMER, 0x19, 0x01, 0x2A, 0xA0, 0x02, 0x15, 0x01, 0x26, 0xA0, 0x02, 0x95, 0x01, 0x75, 0x10, 0x81, 0x00, 0xC0 }};
static bool udi_hid_exk_setreport(void);
static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
static void udi_hid_exk_setreport_valid(void);
bool udi_hid_exk_enable(void) {
udi_hid_exk_rate = 0;
udi_hid_exk_protocol = 0;
udi_hid_exk_b_report_trans_ongoing = false;
memset(udi_hid_exk_report.raw, 0, UDI_HID_EXK_REPORT_SIZE);
udi_hid_exk_b_report_valid = false;
return UDI_HID_EXK_ENABLE_EXT();
}
void udi_hid_exk_disable(void) { UDI_HID_EXK_DISABLE_EXT(); }
bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, udi_hid_exk_setreport); }
uint8_t udi_hid_exk_getsetting(void) { return 0; }
static bool udi_hid_exk_setreport(void) {
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
udd_g_ctrlreq.payload = &udi_hid_exk_report_set;
udd_g_ctrlreq.callback = udi_hid_exk_setreport_valid;
udd_g_ctrlreq.payload_size = 1;
return true;
}
return false;
}
bool udi_hid_exk_send_report(void) {
if (!main_b_exk_enable) {
return false;
}
if (udi_hid_exk_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_exk_report_trans, udi_hid_exk_report.raw, UDI_HID_EXK_REPORT_SIZE);
udi_hid_exk_b_report_valid = false;
udi_hid_exk_b_report_trans_ongoing = udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, false, udi_hid_exk_report_trans, UDI_HID_EXK_REPORT_SIZE, udi_hid_exk_report_sent);
return udi_hid_exk_b_report_trans_ongoing;
}
static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_exk_b_report_trans_ongoing = false;
if (udi_hid_exk_b_report_valid) {
udi_hid_exk_send_report();
}
}
static void udi_hid_exk_setreport_valid(void) {}
#endif
#ifdef MOUSE_ENABLE
bool udi_hid_mou_enable(void);
void udi_hid_mou_disable(void);
bool udi_hid_mou_setup(void);
uint8_t udi_hid_mou_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_mou = {
.enable = (bool (*)(void))udi_hid_mou_enable,
.disable = (void (*)(void))udi_hid_mou_disable,
.setup = (bool (*)(void))udi_hid_mou_setup,
.getsetting = (uint8_t(*)(void))udi_hid_mou_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_mou_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_mou_protocol;
bool udi_hid_mou_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_mou_report[UDI_HID_MOU_REPORT_SIZE];
static bool udi_hid_mou_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_mou_report_trans[UDI_HID_MOU_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_mou_report_desc_t udi_hid_mou_report_desc = {{
0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x05, 0x15, 0x00, 0x25, 0x01, 0x95, 0x05, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x03, 0x81, 0x01,
0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x95, 0x02, 0x75, 0x08, 0x81, 0x06,
0x09, 0x38, 0x15, 0x81, 0x25, 0x7F, 0x95, 0x01, 0x75, 0x08, 0x81, 0x06,
0x05, 0x0C, 0x0A, 0x38, 0x02, 0x15, 0x81, 0x25, 0x7F, 0x95, 0x01, 0x75, 0x08, 0x81, 0x06, 0xC0, 0xC0 }};
static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
bool udi_hid_mou_enable(void) {
udi_hid_mou_rate = 0;
udi_hid_mou_protocol = 0;
udi_hid_mou_b_report_trans_ongoing = false;
memset(udi_hid_mou_report, 0, UDI_HID_MOU_REPORT_SIZE);
udi_hid_mou_b_report_valid = false;
return UDI_HID_MOU_ENABLE_EXT();
}
void udi_hid_mou_disable(void) { UDI_HID_MOU_DISABLE_EXT(); }
bool udi_hid_mou_setup(void) { return udi_hid_setup(&udi_hid_mou_rate, &udi_hid_mou_protocol, (uint8_t *)&udi_hid_mou_report_desc, NULL); }
uint8_t udi_hid_mou_getsetting(void) { return 0; }
bool udi_hid_mou_send_report(void) {
if (!main_b_mou_enable) {
return false;
}
if (udi_hid_mou_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_mou_report_trans, udi_hid_mou_report, UDI_HID_MOU_REPORT_SIZE);
udi_hid_mou_b_report_valid = false;
udi_hid_mou_b_report_trans_ongoing = udd_ep_run(UDI_HID_MOU_EP_IN | USB_EP_DIR_IN, false, udi_hid_mou_report_trans, UDI_HID_MOU_REPORT_SIZE, udi_hid_mou_report_sent);
return udi_hid_mou_b_report_trans_ongoing;
}
static void udi_hid_mou_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_mou_b_report_trans_ongoing = false;
if (udi_hid_mou_b_report_valid) {
udi_hid_mou_send_report();
}
}
#endif
#ifdef RAW_ENABLE
bool udi_hid_raw_enable(void);
void udi_hid_raw_disable(void);
bool udi_hid_raw_setup(void);
uint8_t udi_hid_raw_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_raw = {
.enable = (bool (*)(void))udi_hid_raw_enable,
.disable = (void (*)(void))udi_hid_raw_disable,
.setup = (bool (*)(void))udi_hid_raw_setup,
.getsetting = (uint8_t(*)(void))udi_hid_raw_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_raw_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_raw_protocol;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_raw_report_set[UDI_HID_RAW_REPORT_SIZE];
static bool udi_hid_raw_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_raw_report[UDI_HID_RAW_REPORT_SIZE];
static bool udi_hid_raw_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_raw_report_trans[UDI_HID_RAW_REPORT_SIZE];
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_raw_report_recv[UDI_HID_RAW_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_raw_report_desc_t udi_hid_raw_report_desc = {{
0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, 0x09, RAW_USAGE_ID, 0xA1, 0x01, 0x75, 0x08, 0x15, 0x00, 0x25, 0xFF, 0x09, 0x62, 0x95, RAW_EPSIZE, 0x81, 0x02, 0x09, 0x63, 0x95, RAW_EPSIZE, 0x91, 0x02, 0xC0 }};
static bool udi_hid_raw_setreport(void);
static void udi_hid_raw_setreport_valid(void);
static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
static void udi_hid_raw_report_rcvd(udd_ep_status_t status, iram_size_t nb_rcvd, udd_ep_id_t ep);
bool udi_hid_raw_enable(void) {
udi_hid_raw_rate = 0;
udi_hid_raw_protocol = 0;
udi_hid_raw_b_report_trans_ongoing = false;
memset(udi_hid_raw_report, 0, UDI_HID_RAW_REPORT_SIZE);
udi_hid_raw_b_report_valid = 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); }
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)) {
udd_g_ctrlreq.payload = udi_hid_raw_report_set;
udd_g_ctrlreq.callback = udi_hid_raw_setreport_valid; udd_g_ctrlreq.payload_size = UDI_HID_RAW_REPORT_SIZE;
return true;
}
return false;
}
bool udi_hid_raw_send_report(void) {
if (!main_b_raw_enable) {
return false;
}
if (udi_hid_raw_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_raw_report_trans, udi_hid_raw_report, UDI_HID_RAW_REPORT_SIZE);
udi_hid_raw_b_report_valid = false;
udi_hid_raw_b_report_trans_ongoing = udd_ep_run(UDI_HID_RAW_EP_IN | USB_EP_DIR_IN, false, udi_hid_raw_report_trans, UDI_HID_RAW_REPORT_SIZE, udi_hid_raw_report_sent);
return udi_hid_raw_b_report_trans_ongoing;
}
static void udi_hid_raw_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_raw_b_report_trans_ongoing = false;
if (udi_hid_raw_b_report_valid) {
udi_hid_raw_send_report();
}
}
static void udi_hid_raw_setreport_valid(void) {}
void raw_hid_send(uint8_t *data, uint8_t length) {
if (main_b_raw_enable && !udi_hid_raw_b_report_trans_ongoing && length == UDI_HID_RAW_REPORT_SIZE) {
memcpy(udi_hid_raw_report, data, UDI_HID_RAW_REPORT_SIZE);
udi_hid_raw_send_report();
}
}
bool udi_hid_raw_receive_report(void) {
if (!main_b_raw_enable) {
return false;
}
return udd_ep_run(UDI_HID_RAW_EP_OUT | USB_EP_DIR_OUT, false, udi_hid_raw_report_recv, UDI_HID_RAW_REPORT_SIZE, udi_hid_raw_report_rcvd);
}
static void udi_hid_raw_report_rcvd(udd_ep_status_t status, iram_size_t nb_rcvd, udd_ep_id_t ep) {
UNUSED(ep);
if (status == UDD_EP_TRANSFER_OK && nb_rcvd == UDI_HID_RAW_REPORT_SIZE) {
UDI_HID_RAW_RECEIVE(udi_hid_raw_report_recv, UDI_HID_RAW_REPORT_SIZE);
}
}
#endif
#ifdef CONSOLE_ENABLE
bool udi_hid_con_enable(void);
void udi_hid_con_disable(void);
bool udi_hid_con_setup(void);
uint8_t udi_hid_con_getsetting(void);
UDC_DESC_STORAGE udi_api_t udi_api_hid_con = {
.enable = (bool (*)(void))udi_hid_con_enable,
.disable = (void (*)(void))udi_hid_con_disable,
.setup = (bool (*)(void))udi_hid_con_setup,
.getsetting = (uint8_t(*)(void))udi_hid_con_getsetting,
.sof_notify = NULL,
};
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_con_rate;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_con_protocol;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_con_report_set[UDI_HID_CON_REPORT_SIZE];
bool udi_hid_con_b_report_valid;
COMPILER_WORD_ALIGNED
uint8_t udi_hid_con_report[UDI_HID_CON_REPORT_SIZE];
volatile bool udi_hid_con_b_report_trans_ongoing;
COMPILER_WORD_ALIGNED
static uint8_t udi_hid_con_report_trans[UDI_HID_CON_REPORT_SIZE];
COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE udi_hid_con_report_desc_t udi_hid_con_report_desc = {{
0x06, 0x31, 0xFF, 0x09, 0x74, 0xA1, 0x01, 0x09, 0x75, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x95, CONSOLE_EPSIZE, 0x75, 0x08, 0x81, 0x02, 0x09, 0x76, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x95, CONSOLE_EPSIZE, 0x75, 0x08, 0x91, 0x02, 0xC0 }};
static bool udi_hid_con_setreport(void);
static void udi_hid_con_setreport_valid(void);
static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
bool udi_hid_con_enable(void) {
udi_hid_con_rate = 0;
udi_hid_con_protocol = 0;
udi_hid_con_b_report_trans_ongoing = false;
memset(udi_hid_con_report, 0, UDI_HID_CON_REPORT_SIZE);
udi_hid_con_b_report_valid = false;
return UDI_HID_CON_ENABLE_EXT();
}
void udi_hid_con_disable(void) { UDI_HID_CON_DISABLE_EXT(); }
bool udi_hid_con_setup(void) { return udi_hid_setup(&udi_hid_con_rate, &udi_hid_con_protocol, (uint8_t *)&udi_hid_con_report_desc, udi_hid_con_setreport); }
uint8_t udi_hid_con_getsetting(void) { return 0; }
static bool udi_hid_con_setreport(void) {
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (UDI_HID_CON_REPORT_SIZE == udd_g_ctrlreq.req.wLength)) {
udd_g_ctrlreq.payload = udi_hid_con_report_set;
udd_g_ctrlreq.callback = udi_hid_con_setreport_valid;
udd_g_ctrlreq.payload_size = UDI_HID_CON_REPORT_SIZE;
return true;
}
return false;
}
bool udi_hid_con_send_report(void) {
if (!main_b_con_enable) {
return false;
}
if (udi_hid_con_b_report_trans_ongoing) {
return false;
}
memcpy(udi_hid_con_report_trans, udi_hid_con_report, UDI_HID_CON_REPORT_SIZE);
udi_hid_con_b_report_valid = false;
udi_hid_con_b_report_trans_ongoing = udd_ep_run(UDI_HID_CON_EP_IN | USB_EP_DIR_IN, false, udi_hid_con_report_trans, UDI_HID_CON_REPORT_SIZE, udi_hid_con_report_sent);
return udi_hid_con_b_report_trans_ongoing;
}
static void udi_hid_con_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep) {
UNUSED(status);
UNUSED(nb_sent);
UNUSED(ep);
udi_hid_con_b_report_trans_ongoing = false;
if (udi_hid_con_b_report_valid) {
udi_hid_con_send_report();
}
}
static void udi_hid_con_setreport_valid(void) {}
#endif