forked from RCSN/CherryDAP
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
572 additions
and
460 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// Created by HalfSweet on 24-9-25. | ||
// | ||
|
||
#include "hid_comm.h" | ||
#include "usbd_core.h" | ||
|
||
#include "dap_main.h" | ||
|
||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t read_buffer[HID_PACKET_SIZE]; | ||
USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t write_buffer[HID_PACKET_SIZE]; | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
/*!< custom hid report descriptor */ | ||
const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE] = { | ||
/* USER CODE BEGIN 0 */ | ||
0x06, 0x00, 0xff, /* USAGE_PAGE (Vendor Defined Page 1) */ | ||
0x09, 0x01, /* USAGE (Vendor Usage 1) */ | ||
0xa1, 0x01, /* COLLECTION (Application) */ | ||
0x85, 0x02, /* REPORT ID (0x02) */ | ||
0x09, 0x02, /* USAGE (Vendor Usage 1) */ | ||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
0x25, 0xff, /*LOGICAL_MAXIMUM (255) */ | ||
0x75, 0x08, /* REPORT_SIZE (8) */ | ||
0x96, 0xff, 0x03, /* REPORT_COUNT (1023) */ | ||
0x81, 0x02, /* INPUT (Data,Var,Abs) */ | ||
/* <___________________________________________________> */ | ||
0x85, 0x01, /* REPORT ID (0x01) */ | ||
0x09, 0x03, /* USAGE (Vendor Usage 1) */ | ||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */ | ||
0x75, 0x08, /* REPORT_SIZE (8) */ | ||
0x96, 0xff, 0x03, /* REPORT_COUNT (1023) */ | ||
0x91, 0x02, /* OUTPUT (Data,Var,Abs) */ | ||
|
||
/* <___________________________________________________> */ | ||
0x85, 0x03, /* REPORT ID (0x03) */ | ||
0x09, 0x04, /* USAGE (Vendor Usage 1) */ | ||
0x15, 0x00, /* LOGICAL_MINIMUM (0) */ | ||
0x25, 0xff, /* LOGICAL_MAXIMUM (255) */ | ||
0x75, 0x08, /* REPORT_SIZE (8) */ | ||
0x96, 0xff, 0x03, /* REPORT_COUNT (1023) */ | ||
0xb1, 0x02, /* FEATURE (Data,Var,Abs) */ | ||
/* USER CODE END 0 */ | ||
0xC0 /* END_COLLECTION */ | ||
}; | ||
#endif | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
|
||
__WEAK void usbd_hid_custom_in_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) | ||
{ | ||
(void) busid; | ||
USB_LOG_RAW("actual in len:%d\r\n", nbytes); | ||
// custom_state = HID_STATE_IDLE; | ||
} | ||
|
||
__WEAK void usbd_hid_custom_out_callback(uint8_t busid, uint8_t ep, uint32_t nbytes) | ||
{ | ||
(void) busid; | ||
USB_LOG_RAW("actual out len:%d\r\n", nbytes); | ||
usbd_ep_start_read(0, ep, read_buffer, HID_PACKET_SIZE); | ||
read_buffer[0] = 0x02; /* IN: report id */ | ||
usbd_ep_start_write(0, HID_IN_EP, read_buffer, nbytes); | ||
} | ||
|
||
struct usbd_endpoint hid_custom_in_ep = { | ||
.ep_cb = usbd_hid_custom_in_callback, | ||
.ep_addr = HID_IN_EP | ||
}; | ||
|
||
struct usbd_endpoint hid_custom_out_ep = { | ||
.ep_cb = usbd_hid_custom_out_callback, | ||
.ep_addr = HID_OUT_EP | ||
}; | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// Created by HalfSweet on 24-9-25. | ||
// | ||
|
||
#ifndef HSLINK_PRO_HID_COMM_H | ||
#define HSLINK_PRO_HID_COMM_H | ||
|
||
#include <stdint.h> | ||
#include "usbd_core.h" | ||
#include "usbd_hid.h" | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
|
||
#define HID_IN_EP 0x88 | ||
#define HID_OUT_EP 0x09 | ||
|
||
#ifdef CONFIG_USB_HS | ||
#define HID_PACKET_SIZE 1024 | ||
#else | ||
#define HID_PACKET_SIZE 64 | ||
#endif | ||
|
||
#endif | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
#define HID_IN_EP 0x88 | ||
#define HID_OUT_EP 0x09 | ||
|
||
#ifdef CONFIG_USB_HS | ||
#define HID_PACKET_SIZE 1024 | ||
#else | ||
#define HID_PACKET_SIZE 64 | ||
#endif | ||
|
||
#endif | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
#define CONFIG_HID_DESCRIPTOR_LEN (9 + 9 + 7 + 7) | ||
#define CONFIG_HID_INTF_NUM 1 | ||
#define HID_CUSTOM_REPORT_DESC_SIZE 53 | ||
#define HIDRAW_INTERVAL 4 | ||
#define HID_INTF_NUM (MSC_INTF_NUM + 1) | ||
|
||
#else | ||
#define CONFIG_HID_DESCRIPTOR_LEN 0 | ||
#define CONFIG_HID_INTF_NUM 0 | ||
#define HID_INTF_NUM (MSC_INTF_NUM) | ||
#endif | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
#define HID_DESC() \ | ||
/************** Descriptor of Custom interface *****************/ \ | ||
0x09, /* bLength: Interface Descriptor size */ \ | ||
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType: Interface descriptor type */ \ | ||
HID_INTF_NUM, /* bInterfaceNumber: Number of Interface */ \ | ||
0x00, /* bAlternateSetting: Alternate setting */ \ | ||
0x02, /* bNumEndpoints */ \ | ||
0x03, /* bInterfaceClass: HID */ \ | ||
0x01, /* bInterfaceSubClass : 1=BOOT, 0=no boot */ \ | ||
0x00, /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */ \ | ||
0, /* iInterface: Index of string descriptor */ \ | ||
/******************** Descriptor of Custom HID ********************/ \ | ||
0x09, /* bLength: HID Descriptor size */ \ | ||
HID_DESCRIPTOR_TYPE_HID, /* bDescriptorType: HID */ \ | ||
0x11, /* bcdHID: HID Class Spec release number */ \ | ||
0x01, \ | ||
0x00, /* bCountryCode: Hardware target country */ \ | ||
0x01, /* bNumDescriptors: Number of HID class descriptors to follow */ \ | ||
0x22, /* bDescriptorType */ \ | ||
HID_CUSTOM_REPORT_DESC_SIZE, /* wItemLength: Total length of Report descriptor */ \ | ||
0x00, \ | ||
/******************** Descriptor of Custom in endpoint ********************/ \ | ||
0x07, /* bLength: Endpoint Descriptor size */ \ | ||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \ | ||
HID_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */ \ | ||
0x03, /* bmAttributes: Interrupt endpoint */ \ | ||
WBVAL(HID_PACKET_SIZE), /* wMaxPacketSize: 4 Byte max */ \ | ||
HIDRAW_INTERVAL, /* bInterval: Polling Interval */ \ | ||
/******************** Descriptor of Custom out endpoint ********************/ \ | ||
0x07, /* bLength: Endpoint Descriptor size */ \ | ||
USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType: */ \ | ||
HID_OUT_EP, /* bEndpointAddress: Endpoint Address (IN) */ \ | ||
0x03, /* bmAttributes: Interrupt endpoint */ \ | ||
WBVAL(HID_PACKET_SIZE), /* wMaxPacketSize: 4 Byte max */ \ | ||
HIDRAW_INTERVAL, /* bInterval: Polling Interval */ | ||
#endif | ||
|
||
#ifdef CONFIG_USE_HID_CONFIG | ||
extern struct usbd_endpoint hid_custom_in_ep; | ||
extern struct usbd_endpoint hid_custom_out_ep; | ||
|
||
extern const uint8_t hid_custom_report_desc[HID_CUSTOM_REPORT_DESC_SIZE]; | ||
#endif | ||
|
||
#endif //HSLINK_PRO_HID_COMM_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.