Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of USBDevice by
Revision 73:803bc631881e, committed 2018-08-25
- Comitter:
- Lybfip
- Date:
- Sat Aug 25 07:54:43 2018 +0000
- Parent:
- 72:8c3160323201
- Commit message:
- ???????????
Changed in this revision
diff -r 8c3160323201 -r 803bc631881e USBHID/USBHID_Types.h --- a/USBHID/USBHID_Types.h Sat Aug 18 06:37:49 2018 +0000 +++ b/USBHID/USBHID_Types.h Sat Aug 25 07:54:43 2018 +0000 @@ -78,8 +78,8 @@ #define DELIMITER(size) (0xa8 | size) /* HID Report */ -/* Where report IDs are used the first byte of 'data' will be the */ -/* report ID and 'length' will include this report ID byte. */ +/* レポートIDが使用される場合、'データ'の最初のバイトはレポートIDになり、 */ +/* '長さ'にはこのレポートIDバイトが含まれます。 */ #define MAX_HID_REPORT_SIZE (64)
diff -r 8c3160323201 -r 803bc631881e USBHID/USBKeyboard.cpp --- a/USBHID/USBKeyboard.cpp Sat Aug 18 06:37:49 2018 +0000 +++ b/USBHID/USBKeyboard.cpp Sat Aug 25 07:54:43 2018 +0000 @@ -183,7 +183,7 @@ {0x4a, 0}, /* HOME */ {0x4b, 0}, /* PAGE_UP */ {0x4e, 0}, /* PAGE_DOWN */ - + {0x4f, 0}, /* RIGHT_ARROW */ {0x50, 0}, /* LEFT_ARROW */ {0x51, 0}, /* DOWN_ARROW */ @@ -344,7 +344,7 @@ {0x4a, 0}, /* HOME */ {0x4b, 0}, /* PAGE_UP */ {0x4e, 0}, /* PAGE_DOWN */ - + {0x4f, 0}, /* RIGHT_ARROW */ {0x50, 0}, /* LEFT_ARROW */ {0x51, 0}, /* DOWN_ARROW */ @@ -355,7 +355,8 @@ /// /// reportDesc /// -uint8_t * USBKeyboard::reportDesc() { +uint8_t * USBKeyboard::reportDesc() +{ static uint8_t reportDescriptor[] = { USAGE_PAGE(1), 0x01, // 標準デスクトップ USAGE(1), 0x06, // キーボード @@ -425,14 +426,15 @@ /// /// EP1_OUT_callback /// -bool USBKeyboard::EP1_OUT_callback() { +bool USBKeyboard::EP1_OUT_callback() +{ uint32_t bytesRead = 0; uint8_t led[65]; USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE); - + // led[0]はレポートIDなので、我々はled[1]を取ります。 lock_status = led[1] & 0x07; - + // データを受信できるようにエンドポイントをアクティブ化します。 if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE)) return false; @@ -442,21 +444,24 @@ /// /// ロックステータスを返す /// -uint8_t USBKeyboard::lockStatus() { +uint8_t USBKeyboard::lockStatus() +{ return lock_status; } /// /// 文字を送信する /// -int USBKeyboard::_putc(int c) { +int USBKeyboard::_putc(int c) +{ return keyCode(c, keymap[c].modifier); } /// /// キーコード /// -bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) { +bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) +{ // シミューレートされたキーボードキーを送信します。成功した場合はtrueを返します。 HID_REPORT report; @@ -487,10 +492,73 @@ } +uint8_t downKey = 0; // ダウン中のキー + +/// +/// キーダウン +/// +bool USBKeyboard::keyDown(uint8_t key) +{ + // シミューレートされたキーボードキーを送信します。成功した場合はtrueを返します。 + HID_REPORT report; + + report.data[0] = REPORT_ID_KEYBOARD; + report.data[1] = keymap[key].modifier; + report.data[2] = 0; + report.data[3] = keymap[key].usage; + report.data[4] = 0; + report.data[5] = 0; + report.data[6] = 0; + report.data[7] = 0; + report.data[8] = 0; + + report.length = 9; + + if (!send(&report)) { + return false; + } + + downKey = key; // ダウンしたキーを保存 + + return true; +} + +/// +/// キーアップ +/// +bool USBKeyboard::keyUp(uint8_t key) +{ + // ダウンしたキーと異なるキーなら終了 + if (downKey != key) return; + + // キーアップをシミュレートします。 + HID_REPORT report; + + report.data[0] = REPORT_ID_KEYBOARD; + report.data[1] = 0; + report.data[2] = 0; + report.data[3] = 0; + report.data[4] = 0; + report.data[5] = 0; + report.data[6] = 0; + report.data[7] = 0; + report.data[8] = 0; + + report.length = 9; + + if (!send(&report)) { + return false; + } + + return true; +} + + /// /// メディアコントロール /// -bool USBKeyboard::mediaControl(MEDIA_KEY key) { +bool USBKeyboard::mediaControl(MEDIA_KEY key) +{ HID_REPORT report; report.data[0] = REPORT_ID_VOLUME; @@ -520,7 +588,8 @@ /// /// Descの設定 /// -uint8_t * USBKeyboard::configurationDesc() { +uint8_t * USBKeyboard::configurationDesc() +{ static uint8_t configurationDescriptor[] = { CONFIGURATION_DESCRIPTOR_LENGTH,// bLength CONFIGURATION_DESCRIPTOR, // bDescriptorType
diff -r 8c3160323201 -r 803bc631881e USBHID/USBKeyboard.h --- a/USBHID/USBKeyboard.h Sat Aug 18 06:37:49 2018 +0000 +++ b/USBHID/USBKeyboard.h Sat Aug 25 07:54:43 2018 +0000 @@ -109,7 +109,7 @@ }; /** - * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key + * 修飾子(CTRL, SHIFT, ALT)とキーで定義された文字を送信します。 * * @code * //To send CTRL + s (save) @@ -117,61 +117,71 @@ * @endcode * * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) - * @param key character to send + * @param key 送信するキャラクタ * @returns true if there is no error, false otherwise */ + /// + /// キーコード + /// bool keyCode(uint8_t key, uint8_t modifier = 0); + /// キーダウン /// + bool keyDown(uint8_t key); + + /// キーアップ /// + bool keyUp(uint8_t); + /** - * Send a character + * キャラクタを送信します。 * - * @param c character to be sent - * @returns true if there is no error, false otherwise + * @param c 送信するキャラクタ + * @returns エラーがない場合はtrueを返し、そうでない場合はfalseを返します。 */ virtual int _putc(int c); /** - * Control media keys + * メディアキーを制御する * - * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) + * @param key 押されたメディアキー (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) * @returns true if there is no error, false otherwise */ bool mediaControl(MEDIA_KEY key); /* - * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength. + * レポート記述子を定義します。警告:このメソッドは、レポート記述子の長さをreportLengthに格納する必要があります。 * - * @returns pointer to the report descriptor + * @returns レポート記述子へのポインタ */ virtual uint8_t * reportDesc(); /* - * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys + * OUTエンドポイントでデータが受信されたときに呼び出されます。LOCKキーのLEDをスイッチするのに便利です。 * * @returns if handle by subclass, return true */ virtual bool EP1_OUT_callback(); /** - * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important: - * - First bit: NUM_LOCK - * - Second bit: CAPS_LOCK - * - Third bit: SCROLL_LOCK + * ロックキーの状態を読み取ります。押されたキーに応じてLEDをスイッチオン/オフするのに便利です。 + * 結果の最初の3ビットのみが重要です。 + * - 最初のビット: NUM_LOCK + * - 二番目のビット: CAPS_LOCK + * - 三番目のビット: SCROLL_LOCK * - * @returns status of lock keys + * @returns ロックキーのステータス */ uint8_t lockStatus(); protected: /* - * Get configuration descriptor + * 構成記述子を取得する。 * - * @returns pointer to the configuration descriptor + * @returns 構成記述子へのポインタ */ virtual uint8_t * configurationDesc(); private: - //dummy otherwise it doesn,t compile (we must define all methods of an abstract class) + // それ以外の場合は、それはコンパイルされません(抽象クラスのすべてのメソッドを定義する必要があります)。 virtual int _getc() { return -1; };