2016-02-07 10:51 PM
Hello.
Long time ago i asked question, about HID and messages. I have working example on wake up/sleep, and basic audio commands like play/pause, volume up/down, text/previous track. But I need few additional commands, like home, enter, arrow keys, and so on. In my code, i have this program:/*
discriptor = 1 ;
0 : Sleep
1 : Wake up
discriptor = 2
0 : Next 1
1 : Previous 2
2 : Stop 4
3 : Play/Pause 8
4 : Mute 16
5 : Volume Up 32
6 : Volume Down 64
7 : 0 (padding) */
USBD_Init(&USB_OTG_dev,USB_OTG_FS_CORE_ID,&USR_desc, &USBD_HID_cb, &USR_cb);
HID_Buffer[0]=1;// discriptor = 1 ;
HID_Buffer[1] = 2;//1b : Wake up
USBD_HID_SendReport(&USB_OTG_dev, HID_Buffer, 2);
I know that it has something to do with :
usbd_conf.h
#define USBD_CFG_MAX_NUM 1
#define USBD_ITF_MAX_NUM 1
#define USB_MAX_STR_DESC_SIZ 64
usbd_hid_core.c
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
{
// system control collection
0x85, 0x01, // REPORT_ID
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x80, // USAGE (System Control)
0xa1, 0x01, // COLLECTION (Application)
0x19, 0x82, // USAGE_MINIMUM (System Sleep)
0x29, 0x83, // USAGE_MAXIMUM (System Wake Up)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
// -------------------- padding bits
0x95, 0x06, // REPORT_COUNT (6)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xc0, // END_COLLECTION
// Consumer control collection
0x85, 0x02, // REPORT_ID
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- common global items
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
// -------------------- misc bits
0x95, 0x05, // REPORT_COUNT (5)
0x09, 0xb5, // USAGE (Scan Next Track)
0x09, 0xb6, // USAGE (Scan Previous Track)
0x09, 0xb7, // USAGE (Stop)
0x09, 0xcd, // USAGE (Play/Pause)
0x09, 0xe2, // USAGE (Mute)
0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs
// -------------------- volume up/down bits
0x95, 0x02, // REPORT_COUNT (2)
0x09, 0xe9, // USAGE (Volume Up)
0x09, 0xea, // USAGE (Volume Down)
0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs
// -------------------- padding bit
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
0xc0 // END_COLLECTION
};
Can any one give example, how can i add commands, like arrow keys, enter, tab, home ? I would be very grateful.
P.S IAR ARM project for this is attached to this
#usb
2016-02-09 06:34 AM
> how can i add commands, like arrow keys, enter, tab, home ?
These keys belong to Keyboard HID device. And then, append standard keyboard collection with unique report ID after the Consumer control collection.usbd_conf.h
//#define HID_IN_PACKET 4
#define HID_IN_PACKET 8
usbd_hid_core.h
//#define HID_MOUSE_REPORT_DESC_SIZE 68
#define HID_MOUSE_REPORT_DESC_SIZE (68 + 37)
usbd_hid_core.c
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
{
// system control collection
0x85, 0x01, // REPORT_ID
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x80, // USAGE (System Control)
0xa1, 0x01, // COLLECTION (Application)
0x19, 0x82, // USAGE_MINIMUM (System Sleep)
0x29, 0x83, // USAGE_MAXIMUM (System Wake Up)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
// -------------------- padding bits
0x95, 0x06, // REPORT_COUNT (6)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xc0, // END_COLLECTION
// Consumer control collection
0x85, 0x02, // REPORT_ID
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- common global items
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
// -------------------- misc bits
0x95, 0x05, // REPORT_COUNT (5)
0x09, 0xb5, // USAGE (Scan Next Track)
0x09, 0xb6, // USAGE (Scan Previous Track)
0x09, 0xb7, // USAGE (Stop)
0x09, 0xcd, // USAGE (Play/Pause)
0x09, 0xe2, // USAGE (Mute)
0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs
// -------------------- volume up/down bits
0x95, 0x02, // REPORT_COUNT (2)
0x09, 0xe9, // USAGE (Volume Up)
0x09, 0xea, // USAGE (Volume Down)
0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs
// -------------------- padding bit
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
0xc0 // END_COLLECTION
// Keyboard collection
0x85, 0x03, // REPORT_ID
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- modifier keys
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x81, 0x02, // INPUT (Data,Var,Abs)
// -------------------- keycode array
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x06, // REPORT_COUNT (6)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
The format of keyboard report is,
offset
0 report ID (3)
1 bit map of modifier keys
2 keycode array[0]
3 :
4 :
5 :
6 :
7 keycode array[5]
The keycodes (Usages) are,
right arrow: 0x4F
left arrow: 0x50
down arrow: 0x51
up arrow: 0x52
enter: 0x28
tab : 0x2B
home : 0x4A
For other keys, look in HID Usage Table, ''10 Keyboard/Keypad Page (0x07)'' section.
http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
The device sends the keyboard report both at push down / release of a key
{0x03, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00} // push enter key
{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // release enter key
Also, two or more keys (up to 6) are pushed at the same time.
Here is a sequence.
{0x03, 0x00, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00} // push right arrow
{0x03, 0x00, 0x4F, 0x52, 0x00, 0x00, 0x00, 0x00} // push up arrow, with right
{0x03, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00} // release right arrow, but don't release up
{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // release up arrow
Tsuneo
2016-04-12 02:14 PM
Hello
Just get my controller board, and start testing this code. For some reason windows can't install it correctly, it says device could not start, with old code, it works ( aka not hardware problem) Any idea why ? (just in case, will attach my project in IAR ARM) Any help would be very helpful :) ________________ Attachments : STM32F411.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0f8&d=%2Fa%2F0X0000000blk%2F7LWWgsfjyhMlVKQqEz.cVLQ03xB.plNJ37Tn7fHshtU&asPdf=false2016-04-16 02:42 AM
just to be shure, triplechecked everything, and run on my hardware sample code from stm32_f105-07_f2_f4_usb-host-device_lib, and it works, but not with this code. Can't find why :(
//usbd_hid_core.c
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __ALIGN_END =
{
// system control collection
0x85, 0x01, // REPORT_ID
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x80, // USAGE (System Control)
0xa1, 0x01, // COLLECTION (Application)
0x19, 0x82, // USAGE_MINIMUM (System Sleep)
0x29, 0x83, // USAGE_MAXIMUM (System Wake Up)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x06, // INPUT (Data,Var,Rel)
// -------------------- padding bits
0x95, 0x06, // REPORT_COUNT (6)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xc0, // END_COLLECTION
// Consumer control collection
0x85, 0x02, // REPORT_ID
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- common global items
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
// -------------------- misc bits
0x95, 0x05, // REPORT_COUNT (5)
0x09, 0xb5, // USAGE (Scan Next Track)
0x09, 0xb6, // USAGE (Scan Previous Track)
0x09, 0xb7, // USAGE (Stop)
0x09, 0xcd, // USAGE (Play/Pause)
0x09, 0xe2, // USAGE (Mute)
0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs
// -------------------- volume up/down bits
0x95, 0x02, // REPORT_COUNT (2)
0x09, 0xe9, // USAGE (Volume Up)
0x09, 0xea, // USAGE (Volume Down)
0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs
// -------------------- padding bit
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
0xc0, // END_COLLECTION
// Keyboard collection
0x85, 0x03, // REPORT_ID
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- modifier keys
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x81, 0x02, // INPUT (Data,Var,Abs)
// -------------------- keycode array
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x06, // REPORT_COUNT (6)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs)
0xc0 // END_COLLECTION
};
// usbd_hid_core.h
#define USB_HID_CONFIG_DESC_SIZ 34
#define USB_HID_DESC_SIZ 9
#define HID_MOUSE_REPORT_DESC_SIZE 105//(68 + 37)
#define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22
#define HID_HS_BINTERVAL 0x07
#define HID_FS_BINTERVAL 0x0A
#define HID_REQ_SET_PROTOCOL 0x0B
#define HID_REQ_GET_PROTOCOL 0x03
#define HID_REQ_SET_IDLE 0x0A
#define HID_REQ_GET_IDLE 0x02
#define HID_REQ_SET_REPORT 0x09
#define HID_REQ_GET_REPORT 0x01
#ifndef __USBD_CONF__H__
#define __USBD_CONF__H__
#include ''usb_conf.h''
#define USBD_CFG_MAX_NUM 1
#define USBD_ITF_MAX_NUM 1
#define USB_MAX_STR_DESC_SIZ 64
#define USBD_SELF_POWERED
#define USBD_DYNAMIC_DESCRIPTOR_CHANGE_ENABLED
#define HID_IN_EP 0x81
#define HID_IN_PACKET 8
#endif /* __USBD_CONF__H__ */
windows still thinks that device can't start, and it does nothing :( Any one ? Will try to read about USB, but it is hard to get whole picture !
2016-04-22 12:29 PM
Any one ?