this is the Peter Barrett USBHostShell program, a bit modified for being a bit more talkactive, just to let u know how the USB protocol layer is going on, and all the data trasnfers. Also there is a small implementation of HID descriptors, but not functional... yet :S the aim is to at least implement the gamepad HID, and make an array of function pointer to each HID function
HID.h@0:e1e03118b8fe, 2010-09-13 (annotated)
- Committer:
- Sergio
- Date:
- Mon Sep 13 12:40:05 2010 +0000
- Revision:
- 0:e1e03118b8fe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergio | 0:e1e03118b8fe | 1 | |
Sergio | 0:e1e03118b8fe | 2 | #ifndef HID_H |
Sergio | 0:e1e03118b8fe | 3 | #define HID_H |
Sergio | 0:e1e03118b8fe | 4 | |
Sergio | 0:e1e03118b8fe | 5 | #include "USBHost.h" |
Sergio | 0:e1e03118b8fe | 6 | |
Sergio | 0:e1e03118b8fe | 7 | #ifndef u8 |
Sergio | 0:e1e03118b8fe | 8 | typedef unsigned char u8; |
Sergio | 0:e1e03118b8fe | 9 | typedef unsigned short u16; |
Sergio | 0:e1e03118b8fe | 10 | typedef unsigned long u32; |
Sergio | 0:e1e03118b8fe | 11 | |
Sergio | 0:e1e03118b8fe | 12 | typedef char s8; |
Sergio | 0:e1e03118b8fe | 13 | typedef short s16; |
Sergio | 0:e1e03118b8fe | 14 | typedef char s32; |
Sergio | 0:e1e03118b8fe | 15 | #endif |
Sergio | 0:e1e03118b8fe | 16 | |
Sergio | 0:e1e03118b8fe | 17 | |
Sergio | 0:e1e03118b8fe | 18 | |
Sergio | 0:e1e03118b8fe | 19 | |
Sergio | 0:e1e03118b8fe | 20 | enum mode{ INPUT=0x81, OUTPUT=0x91, FEATURE=0xB1}; |
Sergio | 0:e1e03118b8fe | 21 | |
Sergio | 0:e1e03118b8fe | 22 | typedef struct |
Sergio | 0:e1e03118b8fe | 23 | { |
Sergio | 0:e1e03118b8fe | 24 | u8 Usage; |
Sergio | 0:e1e03118b8fe | 25 | u8 LocalMinimun; |
Sergio | 0:e1e03118b8fe | 26 | u16 LocalMaximun; |
Sergio | 0:e1e03118b8fe | 27 | u8 ReportCount; |
Sergio | 0:e1e03118b8fe | 28 | u8 ReportSize; |
Sergio | 0:e1e03118b8fe | 29 | mode coll_mode; //INPUT/OUTPUT//FEATURE. |
Sergio | 0:e1e03118b8fe | 30 | u8 mode_value; |
Sergio | 0:e1e03118b8fe | 31 | }Report; |
Sergio | 0:e1e03118b8fe | 32 | |
Sergio | 0:e1e03118b8fe | 33 | typedef struct |
Sergio | 0:e1e03118b8fe | 34 | { |
Sergio | 0:e1e03118b8fe | 35 | u8 numberofreports; |
Sergio | 0:e1e03118b8fe | 36 | Report* pFirstReport; |
Sergio | 0:e1e03118b8fe | 37 | //All the reports must be allocated in an array |
Sergio | 0:e1e03118b8fe | 38 | //so they can be accessed easily. |
Sergio | 0:e1e03118b8fe | 39 | }Collection; |
Sergio | 0:e1e03118b8fe | 40 | |
Sergio | 0:e1e03118b8fe | 41 | /////////////////////////////////////////////////////////////////////// |
Sergio | 0:e1e03118b8fe | 42 | |
Sergio | 0:e1e03118b8fe | 43 | |
Sergio | 0:e1e03118b8fe | 44 | |
Sergio | 0:e1e03118b8fe | 45 | /* |
Sergio | 0:e1e03118b8fe | 46 | * Constants |
Sergio | 0:e1e03118b8fe | 47 | */ |
Sergio | 0:e1e03118b8fe | 48 | #define PATH_SIZE 10 |
Sergio | 0:e1e03118b8fe | 49 | #define USAGE_TAB_SIZE 50 |
Sergio | 0:e1e03118b8fe | 50 | #define MAX_REPORT 300 |
Sergio | 0:e1e03118b8fe | 51 | #define REPORT_DSC_SIZE 6144 |
Sergio | 0:e1e03118b8fe | 52 | |
Sergio | 0:e1e03118b8fe | 53 | #define SIZE_0 0x00 |
Sergio | 0:e1e03118b8fe | 54 | #define SIZE_1 0x01 |
Sergio | 0:e1e03118b8fe | 55 | #define SIZE_2 0x02 |
Sergio | 0:e1e03118b8fe | 56 | #define SIZE_4 0x03 |
Sergio | 0:e1e03118b8fe | 57 | #define SIZE_MASK 0x03 |
Sergio | 0:e1e03118b8fe | 58 | |
Sergio | 0:e1e03118b8fe | 59 | |
Sergio | 0:e1e03118b8fe | 60 | #define TYPE_MAIN 0x00 |
Sergio | 0:e1e03118b8fe | 61 | #define TYPE_GLOBAL 0x04 |
Sergio | 0:e1e03118b8fe | 62 | #define TYPE_LOCAL 0x08 |
Sergio | 0:e1e03118b8fe | 63 | #define TYPE_MASK 0x0C |
Sergio | 0:e1e03118b8fe | 64 | |
Sergio | 0:e1e03118b8fe | 65 | /* Main items */ |
Sergio | 0:e1e03118b8fe | 66 | #define ITEM_COLLECTION 0xA0 |
Sergio | 0:e1e03118b8fe | 67 | #define ITEM_END_COLLECTION 0xC0 |
Sergio | 0:e1e03118b8fe | 68 | #define ITEM_FEATURE 0xB0 |
Sergio | 0:e1e03118b8fe | 69 | #define ITEM_INPUT 0x80 |
Sergio | 0:e1e03118b8fe | 70 | #define ITEM_OUTPUT 0x90 |
Sergio | 0:e1e03118b8fe | 71 | |
Sergio | 0:e1e03118b8fe | 72 | |
Sergio | 0:e1e03118b8fe | 73 | /* Global items */ |
Sergio | 0:e1e03118b8fe | 74 | #define ITEM_UPAGE 0x04 |
Sergio | 0:e1e03118b8fe | 75 | #define ITEM_LOG_MIN 0x14 |
Sergio | 0:e1e03118b8fe | 76 | #define ITEM_LOG_MAX 0x24 |
Sergio | 0:e1e03118b8fe | 77 | #define ITEM_PHY_MIN 0x34 |
Sergio | 0:e1e03118b8fe | 78 | #define ITEM_PHY_MAX 0x44 |
Sergio | 0:e1e03118b8fe | 79 | #define ITEM_UNIT_EXP 0x54 |
Sergio | 0:e1e03118b8fe | 80 | #define ITEM_UNIT 0x64 |
Sergio | 0:e1e03118b8fe | 81 | #define ITEM_REP_SIZE 0x74 |
Sergio | 0:e1e03118b8fe | 82 | #define ITEM_REP_ID 0x84 |
Sergio | 0:e1e03118b8fe | 83 | #define ITEM_REP_COUNT 0x94 |
Sergio | 0:e1e03118b8fe | 84 | |
Sergio | 0:e1e03118b8fe | 85 | /* Local items */ |
Sergio | 0:e1e03118b8fe | 86 | #define ITEM_USAGE 0x08 |
Sergio | 0:e1e03118b8fe | 87 | #define ITEM_STRING 0x78 |
Sergio | 0:e1e03118b8fe | 88 | |
Sergio | 0:e1e03118b8fe | 89 | /* Long item */ |
Sergio | 0:e1e03118b8fe | 90 | #define ITEM_LONG 0xFC |
Sergio | 0:e1e03118b8fe | 91 | |
Sergio | 0:e1e03118b8fe | 92 | #define ITEM_MASK 0xFC |
Sergio | 0:e1e03118b8fe | 93 | |
Sergio | 0:e1e03118b8fe | 94 | /* Attribute Flags */ |
Sergio | 0:e1e03118b8fe | 95 | #define ATTR_DATA_CST 0x01 |
Sergio | 0:e1e03118b8fe | 96 | #define ATTR_NVOL_VOL 0x80 |
Sergio | 0:e1e03118b8fe | 97 | |
Sergio | 0:e1e03118b8fe | 98 | |
Sergio | 0:e1e03118b8fe | 99 | |
Sergio | 0:e1e03118b8fe | 100 | typedef struct |
Sergio | 0:e1e03118b8fe | 101 | { |
Sergio | 0:e1e03118b8fe | 102 | u8 UPage; |
Sergio | 0:e1e03118b8fe | 103 | u8 Usage; |
Sergio | 0:e1e03118b8fe | 104 | }HIDNode; |
Sergio | 0:e1e03118b8fe | 105 | |
Sergio | 0:e1e03118b8fe | 106 | typedef struct |
Sergio | 0:e1e03118b8fe | 107 | { |
Sergio | 0:e1e03118b8fe | 108 | u8 Size; |
Sergio | 0:e1e03118b8fe | 109 | HIDNode Node[PATH_SIZE]; |
Sergio | 0:e1e03118b8fe | 110 | }HIDPath; |
Sergio | 0:e1e03118b8fe | 111 | |
Sergio | 0:e1e03118b8fe | 112 | |
Sergio | 0:e1e03118b8fe | 113 | typedef struct |
Sergio | 0:e1e03118b8fe | 114 | { |
Sergio | 0:e1e03118b8fe | 115 | u32 Value; |
Sergio | 0:e1e03118b8fe | 116 | HIDPath Path; |
Sergio | 0:e1e03118b8fe | 117 | u8 ReportID; |
Sergio | 0:e1e03118b8fe | 118 | u8 Offset; |
Sergio | 0:e1e03118b8fe | 119 | u8 Size; |
Sergio | 0:e1e03118b8fe | 120 | u8 Type; |
Sergio | 0:e1e03118b8fe | 121 | u8 Attribute; |
Sergio | 0:e1e03118b8fe | 122 | u32 Unit; |
Sergio | 0:e1e03118b8fe | 123 | u8 UnitExp; |
Sergio | 0:e1e03118b8fe | 124 | u32 LogMin; |
Sergio | 0:e1e03118b8fe | 125 | u32 LogMax; |
Sergio | 0:e1e03118b8fe | 126 | u32 PhyMin; |
Sergio | 0:e1e03118b8fe | 127 | u32 PhyMax; |
Sergio | 0:e1e03118b8fe | 128 | } HIDData; |
Sergio | 0:e1e03118b8fe | 129 | |
Sergio | 0:e1e03118b8fe | 130 | typedef struct |
Sergio | 0:e1e03118b8fe | 131 | { |
Sergio | 0:e1e03118b8fe | 132 | u8 ReportDesc[REPORT_DSC_SIZE]; |
Sergio | 0:e1e03118b8fe | 133 | u8 ReportDescSize; |
Sergio | 0:e1e03118b8fe | 134 | u8 Pos; |
Sergio | 0:e1e03118b8fe | 135 | u8 Item; |
Sergio | 0:e1e03118b8fe | 136 | u32 Value; |
Sergio | 0:e1e03118b8fe | 137 | HIDData Data; |
Sergio | 0:e1e03118b8fe | 138 | u8 OffsetTab[MAX_REPORT][3]; |
Sergio | 0:e1e03118b8fe | 139 | u8 ReportCount; |
Sergio | 0:e1e03118b8fe | 140 | u8 Count; |
Sergio | 0:e1e03118b8fe | 141 | u8 UPage; |
Sergio | 0:e1e03118b8fe | 142 | HIDNode UsageTab[USAGE_TAB_SIZE]; |
Sergio | 0:e1e03118b8fe | 143 | u8 UsageSize; |
Sergio | 0:e1e03118b8fe | 144 | u8 nObject; |
Sergio | 0:e1e03118b8fe | 145 | u8 nReport; |
Sergio | 0:e1e03118b8fe | 146 | } HIDParser; |
Sergio | 0:e1e03118b8fe | 147 | |
Sergio | 0:e1e03118b8fe | 148 | |
Sergio | 0:e1e03118b8fe | 149 | |
Sergio | 0:e1e03118b8fe | 150 | int HIDParse(HIDParser* pParser,HIDData* pData); |
Sergio | 0:e1e03118b8fe | 151 | void ResetParser(HIDParser* pParser); |
Sergio | 0:e1e03118b8fe | 152 | int FindObject(HIDParser* pParser, HIDData* pData); |
Sergio | 0:e1e03118b8fe | 153 | void GetValue(const u8* Buff, HIDData* pData); |
Sergio | 0:e1e03118b8fe | 154 | void SetValue(const HIDData* pData, u8* Buf); |
Sergio | 0:e1e03118b8fe | 155 | u8* GetReportOffset(HIDParser* pParser, const u8 ReportID, const u8 ReportType); |
Sergio | 0:e1e03118b8fe | 156 | |
Sergio | 0:e1e03118b8fe | 157 | |
Sergio | 0:e1e03118b8fe | 158 | |
Sergio | 0:e1e03118b8fe | 159 | |
Sergio | 0:e1e03118b8fe | 160 | |
Sergio | 0:e1e03118b8fe | 161 | |
Sergio | 0:e1e03118b8fe | 162 | |
Sergio | 0:e1e03118b8fe | 163 | |
Sergio | 0:e1e03118b8fe | 164 | #endif |