USB 機器を PC に刺したときにまず PC によって読み取られる、その USB 機器の全ての情報を書いたデータ列です。
一応 USB 仕様書に書式が載っていますが、それで全てではありません。独自のデバイスを造るならこれだけでも問題ありませんが、キーボードだのマウスだの CD ドライブだの、標準のドライバで機能するようなモノを造るときには、またそれぞれ追加の書式が決まっています。面倒ですね !
そしてここでは HID に限ってその仕様書の所在と、具体例を紹介いたします ... とは言っても私もまだまだわからないことはたくさんありますが。
HID とは Human Interface Device の略で、まあ人間から PC への入力機器と思って多分間違いありません。マウスとか、キーボードとか、ジョイスティックとか、タブレットも含まれるのでしょうか ?
それで HID の descriptor table を書くにあたって必要なドキュメントは現在こちらにあります。この中の
Device Class Definition for Human Interface Devices (HID)
とゆーのと
HID Usage Tables
とゆーのが必須です。
ちなみに EZ-USB には descriptor table の初期設定値があります。その内容は EZ-USB Technical Reference Manual の Appendix A, B にありますが、長いので詳細は省略。
さて共通部分の descriptor table の書式ですが、こんな感じです。
device descriptor。最初に処理される descriptor table です。書式は以下の通り。
データ番号 (各 1 バイト) |
固定値 | 意味 |
---|---|---|
0x00 | 0x12 | device descriptor データ長、18 バイト固定。 |
0x01 | 0x01 | descriptor type、0x01 は device descriptor の番号。下で一覧を表示。 |
0x02 | - | USB 規格番号 (Low)。例えばバージョン 1.10 ならコンマ以下の 2 桁を 10 進っぽく 0x10 と書く。 |
0x03 | - | USB 規格番号 (High)。例えばバージョン 1.10 ならコンマより上 2 桁を 10 進っぽく 0x01 と書く。 |
0x04 | - | Device Class。下の方で一覧を表示。(HID なら 0x00 推奨) |
0x05 | - | Device Sub-Class。下の方で一覧を表示。 |
0x06 | - | Device Protocol。下の方で一覧を表示。 |
0x07 | - | EP0 の最大パケット長。EZ-USB なら 0x40 (64 バイト)。 |
0x08 | - | Vender ID (Low) |
0x09 | - | Vender ID (High) |
0x0A | - | Product ID (Low) |
0x0B | - | Product ID (High) |
0x0C | - | Device Release Number (Low)、これも 10 進っぽく書く。 |
0x0D | - | Device Release Number (High)、これも 10 進っぽく書く。 |
0x0E | - | String descriptor (製造元) への index。String descriptor 用意しなければ 0x00 でいいと思われる。 |
0x0F | - | String descriptor (製品名) への index。String descriptor 用意しなければ 0x00 でいいと思われる。 |
0x10 | - | String descriptor (シリアル番号) への index。String descriptor 用意しなければ 0x00 でいいと思われる。 |
0x11 | - | Configuration の総数。 |
更に configuration descriptor です、が、これは interface 部分、endpoint 部分、HID 部分など全部を含みます。HID 部分は後から説明することにします。
データ番号 (各 1 バイト) |
固定値 | 意味 |
---|---|---|
0x00 | 0x09 | configuration descriptor データ長、9 バイト固定。 |
0x01 | 0x02 | descriptor type、0x02 は configuration descriptor の番号。下で一覧を表示。 |
0x02 | - | 全 descriptor (config + interface + endpoint + class- or vendor-specific descriptor) のデータ長、の Low 部分。(16 進の下 2 桁) |
0x03 | - | 全 descriptor (config + interface + endpoint + class- or vendor-specific descriptor) のデータ長、の High 部分。(16 進の上 2 桁) |
0x04 | - | この configuration の持つ interface の数。 |
0x05 | - | この configuration の番号。(非ゼロ) |
0x06 | - | String descriptor (configuration) への index。String descriptor 用意しなければ 0x00 でいいと思われる。 |
0x07 | - | Attributes bitmap describing configuration characteristics (謎、0x00 でいいと思う) |
0x08 | - | 最大電流 (mA/2) |
以下続けて interface 毎の設定 | ||
0x09 | 0x09 | interface descriptor データ長、9 バイト固定。 |
0x0A | 0x04 | descriptor type、0x04 は interface descriptor の番号。下で一覧を表示。 |
0x0B | - | interface 番号。 |
0x0C | - | この interface 設定を使うときの、alternate setting 番号。 |
0x0D | - | String descriptor (interface) への index。String descriptor 用意しなければ 0x00 でいいと思われる。 |
0x0E | - | この interface が使う endpoint の数。 |
0x0F | - | Class code。下で一覧を表示。(HID なら 0x03) |
0x10 | - | Subclass code。下で一覧を表示。 |
0x11 | - | Protocol code。下で一覧を表示。 |
0x12 | - | Index of string describing this interface (謎、0x00 でも多分良し) |
以下続けて HID descriptor | ||
0x13 | 0x09 | HID descriptor データ長、9 バイト固定。 |
0x14 | 0x21 | descriptor type、0x21 は HID descriptor の番号。下で一覧を表示。 |
0x15 | - | HID Class Specification release (HID 仕様番号) の Low 部分。(小数点以下を 10 進っぽく書く) |
0x16 | - | HID Class Specification release (HID 仕様番号) の High 部分。(小数点より上を 10 進っぽく書く) |
0x17 | - | Country code。通常は使わない (0x00) が、どおしても使いたい場合は下の表参照。 |
0x18 | - | class descriptor (HID の場合は report descriptor) の数。 |
0x19 | 0x22 | class descriptor (HID の場合は report descriptor) の descriptor type。 |
0x1A | - | report descriptor のデータ長 (Low) |
0x1B | - | report descriptor のデータ長 (High) |
以下続けて endpoint descriptor | ||
0x1C | 0x07 | endpoint descriptor のデータ長、7 バイト固定。 |
0x1D | 0x05 | descriptor type、0x05 は endpoint descriptor の番号。下で一覧を表示。 |
0x1E | - | endpoint address、下で説明。 |
0x1F | - | endpoint attribute、下で説明。 |
0x20 | - | Maximum packet size (Low) |
0x21 | - | Maximum packet size (High) |
0x22 | - | interrupt の場合、polling 時間間隔 (ms) |
以下これを全ての設定について繰り返し書く。 | ||
0x23 | - | ... |
とは言うものの ... 私は基本的に configuration も interface も endpoint 設定も一つのモノしか書いたことがありませんので、複数あったときにどういう順番で並べるのかは、あまりよくわかりません。大変無責任で申し訳ないですが !
以下、2 進数を用いて説明。例えば
0x80 = 10000000
において、右端を第 0 ビットとする。
ここで言う endpoint address とはマイコン内部のアドレスの事では無く、endpoint 番号と IN/OUT のフラグを組み合わせたものです。
まず第 0-3 ビットが endpoint 番号です。第 0 ビットが 1 の位に相当します。
第 7 ビットが IN/OUT のフラグです。IN/OUT の区別は私も良く忘れるのですが ... OUT が PC から USB への output、IN が USB から PC への input です。
そして OUT = 0、IN = 1 とします。
具体例としては、endpoint 1 の OUT ならば 0x01。endpoint 15 の IN ならば、0x8F となります。
ここでは transaction 種類を指定します。上の endpoint address で用いた「2 進数表記で右端を第 0 ビットとする」の規則にしたがって説明します。
第 0-1 ビットが transaction 種別です。
transaction | 値 (2 進) |
---|---|
Control | 00 |
Isochronous | 01 |
Bulk | 10 |
Interrupt | 11 |
第 2-3 ビットは isochronous の場合のオプションです。私もよく知りませんが。
意味 | 値 (2 進) |
---|---|
No synchronization | 00 |
Asynchronous | 01 |
Adaptive | 10 |
Synchronous | 11 |
第 4-5 ビットは Usage type とかいうものらしいです。... 誰か私に教えてください ? 多分通常は 00 でいいと思いますが。
意味 | 値 (2 進) |
---|---|
Data endpoint | 00 |
Feedback endpoint | 01 |
Implicit feedback data endpoint | 10 |
Reserved | 11 |
こんなの、pdf 見ていただいた方が正確なんですが、まあそんな事言わずに一応載せておきます。
Descriptor type | 値 |
---|---|
Device | 0x01 |
Configuration | 0x02 |
String | 0x03 |
Interface | 0x04 |
Endpoint | 0x05 |
Device_Qualifier | 0x06 |
Other_Speed_Configuration | 0x07 |
Interface_Power | 0x08 |
HID | 0x21 |
report | 0x22 |
HID は device descriptor では 0x00、interface descriptor では 0x03。
意味 | 値 |
---|---|
Interface descriptor の class code 参照 | 0x00 |
Audio | 0x01 |
Communications and CDC Control | 0x02 |
HID | 0x03 |
Physical | 0x05 |
Image | 0x06 |
Printer | 0x07 |
Mass storage | 0x08 |
Hub | 0x09 |
CDC-Data | 0x0A |
Smart Card | 0x0B |
Content Security | 0x0D |
Video | 0x0E |
Personal Healthcare | 0x0F |
Diagnostic Device | 0xDC |
Wireless Controller | 0xE0 |
Miscellaneous | 0xEF |
Application Specific | 0xFE |
Vendor Specific | 0xFF |
HID のみ記載。キーボードとマウスの場合は boot interface subclass を選択。
意味 | 値 |
---|---|
No subclass | 0x00 |
Boot interface subclass | 0x01 |
HID のみ記載、usbclass で boot interface を指定したときのみ有効、それ以外は 0x00。
意味 | 値 |
---|---|
None | 0x00 |
キーボード | 0x01 |
マウス | 0x02 |
HID のみ記載、通常は 0x00 で良し。
意味 | 値 |
---|---|
Not supported | 0x00 |
Arabic | 0x01 |
Belgian | 0x02 |
Canadian-Bilingual | 0x03 |
Canadian-French | 0x04 |
Czech Republic | 0x05 |
Danish | 0x06 |
Finnish | 0x07 |
French | 0x08 |
German | 0x09 |
Greek | 0x0A |
Hebrew | 0x0B |
Hungary | 0x0C |
International (ISO) | 0x0D |
Italian | 0x0E |
Japan (Katakana) | 0x0F |
Korean | 0x10 |
Latin American | 0x11 |