![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Acts a USB HID keyboard, and socket server. Forwards characters from TCP ip socket to keyboard
Dependencies: mbed EthernetNetIf
USBKeyboardMouse/usbdevice.h@1:d866a9d23e49, 2018-12-14 (annotated)
- Committer:
- henryeherman
- Date:
- Fri Dec 14 01:15:44 2018 +0000
- Revision:
- 1:d866a9d23e49
- Parent:
- 0:beb124b81ef5
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
henryeherman | 0:beb124b81ef5 | 1 | /* usbdevice.h */ |
henryeherman | 0:beb124b81ef5 | 2 | /* Generic USB device */ |
henryeherman | 0:beb124b81ef5 | 3 | /* Copyright (c) Phil Wright 2008 */ |
henryeherman | 0:beb124b81ef5 | 4 | |
henryeherman | 0:beb124b81ef5 | 5 | #ifndef USBDEVICE_H |
henryeherman | 0:beb124b81ef5 | 6 | #define USBDEVICE_H |
henryeherman | 0:beb124b81ef5 | 7 | |
henryeherman | 0:beb124b81ef5 | 8 | #include "usbdc.h" |
henryeherman | 0:beb124b81ef5 | 9 | |
henryeherman | 0:beb124b81ef5 | 10 | /* Endpoint packet sizes */ |
henryeherman | 0:beb124b81ef5 | 11 | #define MAX_PACKET_SIZE_EP0 (64) |
henryeherman | 0:beb124b81ef5 | 12 | |
henryeherman | 0:beb124b81ef5 | 13 | /* bmRequestType.dataTransferDirection */ |
henryeherman | 0:beb124b81ef5 | 14 | #define HOST_TO_DEVICE (0) |
henryeherman | 0:beb124b81ef5 | 15 | #define DEVICE_TO_HOST (1) |
henryeherman | 0:beb124b81ef5 | 16 | |
henryeherman | 0:beb124b81ef5 | 17 | /* bmRequestType.Type*/ |
henryeherman | 0:beb124b81ef5 | 18 | #define STANDARD_TYPE (0) |
henryeherman | 0:beb124b81ef5 | 19 | #define CLASS_TYPE (1) |
henryeherman | 0:beb124b81ef5 | 20 | #define VENDOR_TYPE (2) |
henryeherman | 0:beb124b81ef5 | 21 | #define RESERVED_TYPE (3) |
henryeherman | 0:beb124b81ef5 | 22 | |
henryeherman | 0:beb124b81ef5 | 23 | /* bmRequestType.Recipient */ |
henryeherman | 0:beb124b81ef5 | 24 | #define DEVICE_RECIPIENT (0) |
henryeherman | 0:beb124b81ef5 | 25 | #define INTERFACE_RECIPIENT (1) |
henryeherman | 0:beb124b81ef5 | 26 | #define ENDPOINT_RECIPIENT (2) |
henryeherman | 0:beb124b81ef5 | 27 | #define OTHER_RECIPIENT (3) |
henryeherman | 0:beb124b81ef5 | 28 | |
henryeherman | 0:beb124b81ef5 | 29 | /* Descriptors */ |
henryeherman | 0:beb124b81ef5 | 30 | #define DESCRIPTOR_TYPE(wValue) (wValue >> 8) |
henryeherman | 0:beb124b81ef5 | 31 | #define DESCRIPTOR_INDEX(wValue) (wValue & 0xf) |
henryeherman | 0:beb124b81ef5 | 32 | |
henryeherman | 0:beb124b81ef5 | 33 | /* Descriptor type */ |
henryeherman | 0:beb124b81ef5 | 34 | #define DEVICE_DESCRIPTOR (1) |
henryeherman | 0:beb124b81ef5 | 35 | #define CONFIGURATION_DESCRIPTOR (2) |
henryeherman | 0:beb124b81ef5 | 36 | #define STRING_DESCRIPTOR (3) |
henryeherman | 0:beb124b81ef5 | 37 | #define INTERFACE_DESCRIPTOR (4) |
henryeherman | 0:beb124b81ef5 | 38 | #define ENDPOINT_DESCRIPTOR (5) |
henryeherman | 0:beb124b81ef5 | 39 | |
henryeherman | 0:beb124b81ef5 | 40 | typedef struct { |
henryeherman | 0:beb124b81ef5 | 41 | struct { |
henryeherman | 0:beb124b81ef5 | 42 | unsigned char dataTransferDirection; |
henryeherman | 0:beb124b81ef5 | 43 | unsigned char Type; |
henryeherman | 0:beb124b81ef5 | 44 | unsigned char Recipient; |
henryeherman | 0:beb124b81ef5 | 45 | } bmRequestType; |
henryeherman | 0:beb124b81ef5 | 46 | unsigned char bRequest; |
henryeherman | 0:beb124b81ef5 | 47 | unsigned short wValue; |
henryeherman | 0:beb124b81ef5 | 48 | unsigned short wIndex; |
henryeherman | 0:beb124b81ef5 | 49 | unsigned short wLength; |
henryeherman | 0:beb124b81ef5 | 50 | } SETUP_PACKET; |
henryeherman | 0:beb124b81ef5 | 51 | |
henryeherman | 0:beb124b81ef5 | 52 | typedef struct { |
henryeherman | 0:beb124b81ef5 | 53 | SETUP_PACKET setup; |
henryeherman | 0:beb124b81ef5 | 54 | unsigned char *ptr; |
henryeherman | 0:beb124b81ef5 | 55 | unsigned long remaining; |
henryeherman | 0:beb124b81ef5 | 56 | unsigned char direction; |
henryeherman | 0:beb124b81ef5 | 57 | bool zlp; |
henryeherman | 0:beb124b81ef5 | 58 | } CONTROL_TRANSFER; |
henryeherman | 0:beb124b81ef5 | 59 | |
henryeherman | 0:beb124b81ef5 | 60 | typedef enum {ATTACHED, POWERED, DEFAULT, ADDRESS, CONFIGURED} DEVICE_STATE; |
henryeherman | 0:beb124b81ef5 | 61 | |
henryeherman | 0:beb124b81ef5 | 62 | typedef struct { |
henryeherman | 0:beb124b81ef5 | 63 | DEVICE_STATE state; |
henryeherman | 0:beb124b81ef5 | 64 | unsigned char configuration; |
henryeherman | 0:beb124b81ef5 | 65 | bool suspended; |
henryeherman | 0:beb124b81ef5 | 66 | } USB_DEVICE; |
henryeherman | 0:beb124b81ef5 | 67 | |
henryeherman | 0:beb124b81ef5 | 68 | class usbdevice : public usbdc |
henryeherman | 0:beb124b81ef5 | 69 | { |
henryeherman | 0:beb124b81ef5 | 70 | public: |
henryeherman | 0:beb124b81ef5 | 71 | usbdevice(); |
henryeherman | 0:beb124b81ef5 | 72 | protected: |
henryeherman | 0:beb124b81ef5 | 73 | virtual void endpointEventEP0Setup(void); |
henryeherman | 0:beb124b81ef5 | 74 | virtual void endpointEventEP0In(void); |
henryeherman | 0:beb124b81ef5 | 75 | virtual void endpointEventEP0Out(void); |
henryeherman | 0:beb124b81ef5 | 76 | virtual bool requestSetup(void); |
henryeherman | 0:beb124b81ef5 | 77 | virtual bool requestOut(void); |
henryeherman | 0:beb124b81ef5 | 78 | virtual void deviceEventReset(void); |
henryeherman | 0:beb124b81ef5 | 79 | virtual bool requestGetDescriptor(void); |
henryeherman | 0:beb124b81ef5 | 80 | bool requestSetAddress(void); |
henryeherman | 0:beb124b81ef5 | 81 | virtual bool requestSetConfiguration(void); |
henryeherman | 0:beb124b81ef5 | 82 | virtual bool requestGetConfiguration(void); |
henryeherman | 0:beb124b81ef5 | 83 | bool requestGetStatus(void); |
henryeherman | 0:beb124b81ef5 | 84 | virtual bool requestSetInterface(void); |
henryeherman | 0:beb124b81ef5 | 85 | virtual bool requestGetInterface(void); |
henryeherman | 0:beb124b81ef5 | 86 | bool requestSetFeature(void); |
henryeherman | 0:beb124b81ef5 | 87 | bool requestClearFeature(void); |
henryeherman | 0:beb124b81ef5 | 88 | CONTROL_TRANSFER transfer; |
henryeherman | 0:beb124b81ef5 | 89 | USB_DEVICE device; |
henryeherman | 0:beb124b81ef5 | 90 | private: |
henryeherman | 0:beb124b81ef5 | 91 | bool controlIn(void); |
henryeherman | 0:beb124b81ef5 | 92 | bool controlOut(void); |
henryeherman | 0:beb124b81ef5 | 93 | bool controlSetup(void); |
henryeherman | 0:beb124b81ef5 | 94 | void decodeSetupPacket(unsigned char *data, SETUP_PACKET *packet); |
henryeherman | 0:beb124b81ef5 | 95 | }; |
henryeherman | 0:beb124b81ef5 | 96 | |
henryeherman | 0:beb124b81ef5 | 97 | #endif |