summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/vusb/vusb.h
blob: c5cb27ded6844653718d1280182a9945d444d52d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Copyright 2011 Jun Wako <wakojun@gmail.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "host_driver.h"
#include <usbdrv/usbdrv.h>

typedef struct usbDescriptorHeader {
    uchar bLength;
    uchar bDescriptorType;
} __attribute__((packed)) usbDescriptorHeader_t;

typedef struct usbDeviceDescriptor {
    usbDescriptorHeader_t header;
    unsigned              bcdUSB;
    uchar                 bDeviceClass;
    uchar                 bDeviceSubClass;
    uchar                 bDeviceProtocol;
    uchar                 bMaxPacketSize0;
    unsigned              idVendor;
    unsigned              idProduct;
    unsigned              bcdDevice;
    uchar                 iManufacturer;
    uchar                 iProduct;
    uchar                 iSerialNumber;
    uchar                 bNumConfigurations;
} __attribute__((packed)) usbDeviceDescriptor_t;

typedef struct usbConfigurationDescriptorHeader {
    usbDescriptorHeader_t header;
    unsigned              wTotalLength;
    uchar                 bNumInterfaces;
    uchar                 bConfigurationValue;
    uchar                 iConfiguration;
    uchar                 bmAttributes;
    uchar                 bMaxPower;
} __attribute__((packed)) usbConfigurationDescriptorHeader_t;

typedef struct usbStringDescriptor {
    usbDescriptorHeader_t header;
    int                   bString[];
} __attribute__((packed)) usbStringDescriptor_t;

typedef struct usbInterfaceDescriptor {
    usbDescriptorHeader_t header;
    uchar                 bInterfaceNumber;
    uchar                 bAlternateSetting;
    uchar                 bNumEndpoints;
    uchar                 bInterfaceClass;
    uchar                 bInterfaceSubClass;
    uchar                 bInterfaceProtocol;
    uchar                 iInterface;
} __attribute__((packed)) usbInterfaceDescriptor_t;

typedef struct usbEndpointDescriptor {
    usbDescriptorHeader_t header;
    uchar                 bEndpointAddress;
    uchar                 bmAttributes;
    unsigned              wMaxPacketSize;
    uchar                 bInterval;
} __attribute__((packed)) usbEndpointDescriptor_t;

typedef struct usbHIDDescriptor {
    usbDescriptorHeader_t header;
    unsigned              bcdHID;
    uchar                 bCountryCode;
    uchar                 bNumDescriptors;
    uchar                 bDescriptorType;
    unsigned              wDescriptorLength;
} __attribute__((packed)) usbHIDDescriptor_t;

typedef struct usbConfigurationDescriptor {
    usbConfigurationDescriptorHeader_t header;

#ifndef KEYBOARD_SHARED_EP
    usbInterfaceDescriptor_t keyboardInterface;
    usbHIDDescriptor_t       keyboardHID;
    usbEndpointDescriptor_t  keyboardINEndpoint;
#else
    usbInterfaceDescriptor_t sharedInterface;
    usbHIDDescriptor_t       sharedHID;
    usbEndpointDescriptor_t  sharedINEndpoint;
#endif

#if defined(RAW_ENABLE)
    usbInterfaceDescriptor_t rawInterface;
    usbHIDDescriptor_t       rawHID;
    usbEndpointDescriptor_t  rawINEndpoint;
    usbEndpointDescriptor_t  rawOUTEndpoint;
#endif

#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
    usbInterfaceDescriptor_t sharedInterface;
    usbHIDDescriptor_t       sharedHID;
    usbEndpointDescriptor_t  sharedINEndpoint;
#endif

#if defined(CONSOLE_ENABLE)
    usbInterfaceDescriptor_t consoleInterface;
    usbHIDDescriptor_t       consoleHID;
    usbEndpointDescriptor_t  consoleINEndpoint;
    usbEndpointDescriptor_t  consoleOUTEndpoint;
#endif
} __attribute__((packed)) usbConfigurationDescriptor_t;

extern bool vusb_suspended;

host_driver_t *vusb_driver(void);
void           vusb_transfer_keyboard(void);