1
0
mirror of https://github.com/whowechina/chu_pico.git synced 2024-11-24 11:00:10 +01:00

Small progress (issue in 2nd interface)

This commit is contained in:
whowechina 2023-09-06 22:44:39 +08:00
parent 1b77bea2ba
commit ededdc3317
4 changed files with 93 additions and 63 deletions

View File

@ -96,12 +96,14 @@ static void core0_loop()
slider_update();
air_update();
#if 0
static uint16_t old_touch = 0;
uint16_t touch = slider_hw_touch(0);
if (touch != old_touch) {
printf("Touch: %04x\n", touch);
old_touch = touch;
}
#endif
hid_joy.axis = 0;
for (int i = 0; i < 16; i++) {
bool k1 = slider_touched(i * 2);
@ -116,9 +118,6 @@ static void core0_loop()
uint8_t r = k1 ? 255 : 0;
uint8_t g = k2 ? 255 : 0;
if (k1 || k2) {
printf("U:%3d D:%3d\n", slider_delta(i * 2), slider_delta(i * 2 + 1));
}
rgb_key_color(i, rgb32(r, g, g, false));
}
hid_joy.axis ^= 0x80808080; // some magic number from CrazyRedMachine
@ -158,6 +157,7 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type, uint8_t *buffer,
uint16_t reqlen)
{
printf("Get from USB %d-%d\n", report_id, report_type);
return 0;
}
@ -167,10 +167,13 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
hid_report_type_t report_type, uint8_t const *buffer,
uint16_t bufsize)
{
if ((report_id == REPORT_ID_LIGHTS) &&
(report_type == HID_REPORT_TYPE_OUTPUT)) {
if (bufsize >= 0) {
return;
if (report_type == HID_REPORT_TYPE_OUTPUT) {
if (report_id == REPORT_ID_LED_SLIDER_15) {
printf("Slider 16: %d\n", bufsize);
} else if (report_id == REPORT_ID_LED_SLIDER_16) {
printf("Slider 15: %d\n", bufsize);
} else if (report_id == REPORT_ID_LED_TOWER_6) {
printf("Tower 6: %d\n", bufsize);
}
}
}

View File

@ -96,7 +96,7 @@ extern "C" {
#endif
//------------- CLASS -------------//
#define CFG_TUD_HID 1
#define CFG_TUD_HID 2
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 0
#define CFG_TUD_MIDI 0

View File

@ -51,8 +51,8 @@ tusb_desc_device_t desc_device_joy = {
.bDeviceProtocol = 0x00,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = 0x0f0d,
.idProduct = 0x4092,
.idVendor = 0xcf0d,
.idProduct = 0x4032,
.bcdDevice = 0x0100,
.iManufacturer = 0x01,
@ -73,24 +73,35 @@ uint8_t const* tud_descriptor_device_cb(void) {
uint8_t const desc_hid_report_joy[] = {
GAMECON_REPORT_DESC_JOYSTICK(HID_REPORT_ID(REPORT_ID_JOYSTICK)),
GAMECON_REPORT_DESC_LIGHTS(HID_REPORT_ID(REPORT_ID_LIGHTS))
};
uint8_t const desc_hid_report_led[] = {
GAMECON_REPORT_DESC_LED_SLIDER_16(HID_REPORT_ID(REPORT_ID_LED_SLIDER_16)),
GAMECON_REPORT_DESC_LED_SLIDER_15(HID_REPORT_ID(REPORT_ID_LED_SLIDER_15)),
GAMECON_REPORT_DESC_LED_TOWER_6(HID_REPORT_ID(REPORT_ID_LED_TOWER_6)),
GAMECON_REPORT_DESC_LED_COMPRESSED(HID_REPORT_ID(REPORT_ID_LED_COMPRESSED)),
};
// Invoked when received GET HID REPORT DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const* tud_hid_descriptor_report_cb(uint8_t itf) {
(void)itf;
uint8_t const* tud_hid_descriptor_report_cb(uint8_t itf)
{
if (itf == 0) {
return desc_hid_report_joy;
}
else {
return desc_hid_report_led;
}
}
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
enum { ITF_NUM_HID, ITF_NUM_CDC, ITF_NUM_CDC_DATA, ITF_NUM_TOTAL };
enum { ITF_NUM_HID, ITF_NUM_LED, ITF_NUM_CDC, ITF_NUM_TOTAL };
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_DESC_LEN + TUD_CDC_DESC_LEN)
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + 1 * TUD_HID_DESC_LEN + TUD_CDC_DESC_LEN)
#define EPNUM_HID 0x84
#define EPNUM_CDC_NOTIF 0x81
@ -109,6 +120,11 @@ uint8_t const desc_configuration_joy[] = {
sizeof(desc_hid_report_joy), EPNUM_HID,
CFG_TUD_HID_EP_BUFSIZE, 1),
/*
TUD_HID_DESCRIPTOR(ITF_NUM_LED, 0, HID_ITF_PROTOCOL_NONE,
sizeof(desc_hid_report_led), EPNUM_HID,
CFG_TUD_HID_EP_BUFSIZE, 1),
*/
TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, EPNUM_CDC_NOTIF,
8, EPNUM_CDC_OUT, EPNUM_CDC_IN, 64)
@ -131,18 +147,7 @@ const char *string_desc_arr[] = {
(const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
"WHowe" , // 1: Manufacturer
"Chu Pico Controller", // 2: Product
"654321", // 3: Serials, should use chip ID
"Button 1",
"Button 2",
"Button 3",
"Button 4",
"Button 5",
"Button 6",
"Button 7",
"E1",
"E2",
"E3",
"E4"
"333434", // 3: Serials, should use chip ID
};
static uint16_t _desc_str[64];
@ -179,17 +184,8 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
}
}
// first byte is length (including header), second byte is string type
_desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * chr_count + 2);
return _desc_str;
}
void konami_mode()
{
desc_device_joy.idVendor = 0x1ccf;
desc_device_joy.idProduct = 0x8048;
string_desc_arr[1] = "Konami Amusement";
string_desc_arr[2] = "beatmania IIDX controller premium model";
}

View File

@ -6,9 +6,10 @@
enum {
REPORT_ID_JOYSTICK = 1,
REPORT_ID_LIGHTS,
REPORT_ID_KEYBOARD,
REPORT_ID_MOUSE,
REPORT_ID_LED_SLIDER_16 = 4,
REPORT_ID_LED_SLIDER_15 = 5,
REPORT_ID_LED_TOWER_6 = 6,
REPORT_ID_LED_COMPRESSED = 11,
};
// because they are missing from tusb_hid.h
@ -54,33 +55,63 @@ enum {
\
HID_COLLECTION_END
// Light Map
#define GAMECON_REPORT_DESC_LIGHTS(...) \
/*
report id 4 : slider first 48 leds (16 rgb zones, brg order)
report id 5 : slider remaining 45 leds (15 rgb zones, brg order)
report id 6 : tower 18 leds (6 rgb, brg order)
*/
// Slider First 16 LEDs
#define GAMECON_REPORT_DESC_LED_SLIDER_16(...) \
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(0x00), \
HID_COLLECTION(HID_COLLECTION_APPLICATION), \
__VA_ARGS__ HID_REPORT_COUNT(11), /* LED NUM */ \
HID_REPORT_SIZE(8), HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), HID_STRING_MINIMUM(4), \
HID_STRING_MAXIMUM(16), HID_USAGE_MIN(1), HID_USAGE_MAX(16), \
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), HID_REPORT_COUNT(1), \
HID_REPORT_SIZE(8), /*Padding*/ \
__VA_ARGS__ HID_REPORT_COUNT(48), HID_REPORT_SIZE(8), \
HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), \
HID_USAGE_MIN(1), HID_USAGE_MAX(48), \
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
HID_COLLECTION_END
// NKRO Descriptor
#define GAMECON_REPORT_DESC_NKRO(...) \
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(HID_USAGE_PAGE_KEYBOARD), \
// Slider Remaining 15 LEDs
#define GAMECON_REPORT_DESC_LED_SLIDER_15(...) \
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(0x00), \
HID_COLLECTION(HID_COLLECTION_APPLICATION), \
__VA_ARGS__ HID_REPORT_SIZE(1), HID_REPORT_COUNT(8), \
HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), HID_USAGE_MIN(224), \
HID_USAGE_MAX(231), HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), \
HID_INPUT(HID_VARIABLE), HID_REPORT_SIZE(1), HID_REPORT_COUNT(31 * 8), \
HID_LOGICAL_MIN(0), HID_LOGICAL_MAX(1), \
HID_USAGE_PAGE(HID_USAGE_PAGE_KEYBOARD), HID_USAGE_MIN(0), \
HID_USAGE_MAX(31 * 8 - 1), HID_INPUT(HID_VARIABLE), HID_COLLECTION_END
__VA_ARGS__ HID_REPORT_COUNT(45), HID_REPORT_SIZE(8), \
HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), \
HID_USAGE_MIN(1), HID_USAGE_MAX(45), \
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
HID_COLLECTION_END
// Tower LEDs
#define GAMECON_REPORT_DESC_LED_TOWER_6(...) \
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(0x00), \
HID_COLLECTION(HID_COLLECTION_APPLICATION), \
__VA_ARGS__ HID_REPORT_COUNT(18), HID_REPORT_SIZE(8), \
HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), \
HID_USAGE_MIN(1), HID_USAGE_MAX(18), \
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
HID_COLLECTION_END
/* Enable Konami spoof mode */
void konami_mode();
// LEDs Compressed
#define GAMECON_REPORT_DESC_LED_COMPRESSED(...) \
HID_USAGE_PAGE(HID_USAGE_PAGE_DESKTOP), HID_USAGE(0x00), \
HID_COLLECTION(HID_COLLECTION_APPLICATION), \
__VA_ARGS__ HID_REPORT_COUNT(62), HID_REPORT_SIZE(8), \
HID_LOGICAL_MIN(0x00), HID_LOGICAL_MAX_N(0x00ff, 2), \
HID_USAGE_PAGE(HID_USAGE_PAGE_ORDINAL), \
HID_STRING_MINIMUM(4), HID_STRING_MAXIMUM(16), \
HID_USAGE_MIN(1), HID_USAGE_MAX(62), \
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
HID_REPORT_COUNT(1), HID_REPORT_SIZE(8), \
HID_INPUT(HID_CONSTANT | HID_VARIABLE | HID_ABSOLUTE), \
HID_COLLECTION_END
#endif /* USB_DESCRIPTORS_H_ */