|
|
View previous topic :: View next topic |
Author |
Message |
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
USB HID - How Implement to allow Volume Up/Down? |
Posted: Sun Mar 28, 2021 9:26 am |
|
|
Hi, I am using CCS USB HID libraries with ex_usb_keyboard.c example. It works perfectly for sending characters ('a' to 'z').
But I need to be able to control multimedia options with the PIC with buttons, such as volume up / down, play / pause, or suspend the computer.
The codes for volume up / down are supposed to be:
0x80 Keyboard Volume Up, 0x81 Keyboard Volume Down
But, substituting them in:
tx_msg [2] = 0x81;
does nothing, can anyone point to a good resource or share any code that involves multimedia buttons? What sort of descriptors do I need? Any other big changes?
Thanks _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9228 Location: Greensville,Ontario
|
|
Posted: Sun Mar 28, 2021 10:07 am |
|
|
From my foggy memory...
It used to be TWO 'key scan codes', 1st one 'selects' the key, 2nd one 'releases' it.
Maybe look at what's involved in sending 'A' as scan codes ? As 'any' key pressed should be like any other key pressed. |
|
|
Jerson
Joined: 31 Jul 2009 Posts: 125 Location: Bombay, India
|
|
Posted: Sun Mar 28, 2021 9:08 pm |
|
|
On a PSoC, I have created a composite USB HID device that has a keyboard IN, keyboard OUT and Multimedia keys end points to handle volume and transport keys.
A lot of your work would involve writing the correct HID descriptors for your composite USB device. You might be able to find onlne resources like the HID descriptor tool which has many examples in it. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Tue Mar 30, 2021 1:20 pm |
|
|
Some tips for you.
Code: | const char USB_CLASS_SPECIFIC_DESC[] = {
//hid report descriptor for interface 1 (keyboard)
0x05, 0x01, //usage page (generic desktop) //52, 53
0x09, 0x06, //usage (keyboard) //54, 55
0xA1, 0x01, //collection (application) //56, 57
0x85, 0x01, /* Report ID1 */
0x05, 0x07, //usage page (key codes) //58, 59
0x19, 0xE0, //usage min (224) //60, 61
0x29, 0xE7, //usage max (231) //62, 63
0x15, 0x00, //logical min (0) //64, 65
0x25, 0x01, //logical max (1) //66, 67
0x75, 0x01, //report size (1) //68, 69
0x95, 0x08, //report count (8) //70, 71
0x81, 0x02, //input (data, variable, absolute) [modifier byte] //72, 73
0x95, 0x01, //report count (1) //74, 75
0x75, 0x08, //report size (8) //76, 77
0x81, 0x01, //input (constant) [reserved byte] //78, 79
0x95, 0x05, //report count (5) //80, 81
0x75, 0x01, //report size (1) //82, 83
0x05, 0x08, //usage page (page# for leds) //84, 85
0x19, 0x01, //usage min (1) //86, 87
0x29, 0x05, //usage max (5) //88, 89
0x91, 0x02, //output (data, var, abs) [led report] //90, 91
0x95, 0x01, //report count (1) //92, 93
0x75, 0x03, //report size (3) //94, 95
0x91, 0x01, //output (constant) [led report padding] //96, 97
0x95, 0x05, //report count (5) //98, 99
0x75, 0x08, //report size (8) //100, 101
0x15, 0x00, //logical min (0) //102, 103
0x25, 0x65, //logical max (101) //104, 105
0x05, 0x07, //usage page (key codes) //106, 107
0x19, 0x00, //usage min (0) //108, 109
0x29, 0x65, //usage max (101) //110, 111
0x81, 0x00, //input (data, array) //112, 113
0xC0, //end collection //114
//
0x05, 0x0C, /* Usage Page (Consumer Devices) */
0x09, 0x01, /* Usage (Consumer Control) */
0xA1, 0x01, /* Collection (Application) */
0x85, 0x02, /* Report ID=2 */
0x05, 0x0C, /* Usage Page (Consumer Devices) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x07, /* Report Count (7) */
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) */
0x09, 0xE9, /* Usage (Volume Up) */
0x09, 0xEA, /* Usage (Volume Down) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x81, 0x01, /* Input (Constant) */
0xC0, /* End Collection */ |
Code: | #define REPT_ID01 1 //TECLADO NORMAL
#define REPT_ID02 2 //TECLADO MULTIMIDIA |
Send;
Code: | Media_msg[0]=REPT_ID02; // REPORT ID02
Media_msg[1]=0x40; // VOLUME DOWN |
With these tips someone else will help you. |
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Thu Apr 01, 2021 12:05 pm |
|
|
Hello vtrx, thanks, before asking for help in the forum, I had already put what you wrote in "const char USB_CLASS_SPECIFIC_DESC [] ="
vtrx wrote: |
.....
Code: | const char USB_CLASS_SPECIFIC_DESC[] = {
..........0xC0, //end collection //114
//
0x05, 0x0C, /* Usage Page (Consumer Devices) */
0x09, 0x01, /* Usage (Consumer Control) */
0xA1, 0x01, /* Collection (Application) */
0x85, 0x02, /* Report ID=2 */
0x05, 0x0C, /* Usage Page (Consumer Devices) */
0x15, 0x00, /* Logical Minimum (0) */
0x25, 0x01, /* Logical Maximum (1) */
0x75, 0x01, /* Report Size (1) */
0x95, 0x07, /* Report Count (7) */
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) */
0x09, 0xE9, /* Usage (Volume Up) */
0x09, 0xEA, /* Usage (Volume Down) */
0x81, 0x02, /* Input (Data, Variable, Absolute) */
0x95, 0x01, /* Report Count (1) */
0x81, 0x01, /* Input (Constant) */
0xC0, /* End Collection */ |
. |
I have doubts here in this part of the code you use: media_msg [0] ..
in my case I use the same CCS example and use tx_msg [0] ...
replace your code in mine, it does not give an error when compiling but when pressing a button, the pic does not send anything to the PC
vtrx wrote: |
Code: | #define REPT_ID01 1 //TECLADO NORMAL
#define REPT_ID02 2 //TECLADO MULTIMIDIA |
Send;
Code: | Media_msg[0]=REPT_ID02; // REPORT ID02
Media_msg[1]=0x40; // VOLUME DOWN |
With these tips someone else will help you. |
Regards _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sat Apr 03, 2021 4:51 pm |
|
|
Post a link with CCS example complete. |
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Mon Apr 05, 2021 7:06 pm |
|
|
vtrx wrote: | Post a link with CCS example complete. |
Hi bro, aquí esta el link al code
[url] https://www.mediafire.com/folder/yeaoteolraht4/CCS_Foro [/url]
es a partir de la línea 224
it's from code line 224
void usb_keyboard_task(void) {....}
regards _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Sun Apr 11, 2021 11:33 am |
|
|
thanks Bro, it works without problems, I was checking your code and it has several things that I did not take into account,
one more question, how do you do to send the enter key?
I tried to use the code that I already used, but adapted to yours and it doesn't work for me.
I see that the volume up and down codes are different, where can I find more information about the codes?
Regards _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sun Apr 11, 2021 12:11 pm |
|
|
https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
Code: | tx_msg[0]=REPT_ID01; // keyboard normal
tx_msg[1]=0x28 ; // ENTER
usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE);
delay_ms(10);
tx_msg[0]=REPT_ID01; // keyboard normal
tx_msg[1]=0; // RELEASE BUTTON
usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE); |
|
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Sun Apr 11, 2021 7:32 pm |
|
|
vtrx wrote: | https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2
Code: | tx_msg[0]=REPT_ID01; // keyboard normal
tx_msg[1]=0x28 ; // ENTER
usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE);
delay_ms(10);
tx_msg[0]=REPT_ID01; // keyboard normal
tx_msg[1]=0; // RELEASE BUTTON
usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE); |
|
Thanks,
The code you share with me for the enter key is similar to what I tried to do, but it doesn't work.
I will keep trying.
The list of codes for the keys of the usb keyboard, I already knew it but you use different codes for the volume keys
Regards _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Mon Apr 12, 2021 4:36 am |
|
|
Media key uses 7 bits;
Code: | 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) */
0x09, 0xE9, /* Usage (Volume Up) */
0x09, 0xEA, /* Usage (Volume Down) |
(0000000)
Scan Next Track = bit0 (0x01 = 0000 0001)
Scan Previous Track= bit1 (0x02 = 0000 0010)
Stop = bit2 (0x04 = 0000 0100)
Play / Pause = bit3 (0x08 = 0000 1000)
Mute = bit4 (0x10 = 0001 0000)
Volume Up = bit5 (0x20 = 0010 0000)
Volume Down = bit6 (0x40 = 0100 0000)
New code:
https://drive.google.com/file/d/1a1V6VzzhN3m5rFLZU8XXnrN4uhR2JEzX/view?usp=sharing |
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Mon Apr 12, 2021 3:07 pm |
|
|
vtrx wrote: | Media key uses 7 bits;
Code: | 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) */
0x09, 0xE9, /* Usage (Volume Up) */
0x09, 0xEA, /* Usage (Volume Down) |
(0000000)
Scan Next Track = bit0 (0x01 = 0000 0001)
Scan Previous Track= bit1 (0x02 = 0000 0010)
Stop = bit2 (0x04 = 0000 0100)
Play / Pause = bit3 (0x08 = 0000 1000)
Mute = bit4 (0x10 = 0001 0000)
Volume Up = bit5 (0x20 = 0010 0000)
Volume Down = bit6 (0x40 = 0100 0000)
New code:
https://drive.google.com/file/d/1a1V6VzzhN3m5rFLZU8XXnrN4uhR2JEzX/view?usp=sharing |
Thanks, I already understood how works the code for the multimedia keyboard , I could even add the sleep button
with the help of this pdf
http://www2.ece.rochester.edu/~parihar/pres/Report_MultiMedia-KB.pdf
but, the normal keyboard still doesn't work 😂🤣🤣🤣 _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Mon Apr 12, 2021 4:32 pm |
|
|
I just tested using the new code I posted, everything works.
Use portb7 as the button.
Code: | void main(void)
{ //programa principal
port_b_pullups (true);
usb_init();
while(true) //laço principal do programa
{
usb_task();
usb_debug_task();
if (usb_enumerated())
{
usb_keyboard_task();
delay_ms(50);
}
}
} |
Code: | void usb_keyboard_task(void) {
// static int8 tx_msg[7]={0,0,0,0,0,0,0};
static int8 tx_msg[8]={0,0,0,0,0,0,0,0};
static int8 Media_msg[2]={0,0};
static int8 leds;
if(input(PIN_B7)==0)
{
tx_msg[0]=REPT_ID01; // NORMAL KEYBOARD
tx_msg[1]=0X00; // SPECIAL KEYS(CRT,SHIFT ETC)
tx_msg[2]=0X00; // RESERVED
tx_msg[3]=0X28; // ENTER KEY (NORMAL KEYS HERE)
while(!usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE));
delay_ms(10);
tx_msg[0]=REPT_ID01; // NORMAL KEYBOARD
tx_msg[1]=0X00; // SPECIAL KEYS(CRT,SHIFT ETC)
tx_msg[2]=0X00; // RESERVED
tx_msg[3]=0X00; // RELEASE
while(!usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE));
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.
//we won't do anything with it.
if (usb_kbhit(2)) {
usb_get_packet(2, &leds, 1);
}
} |
Media:
Code: | void usb_keyboard_task(void) {
// static int8 tx_msg[7]={0,0,0,0,0,0,0};
static int8 tx_msg[8]={0,0,0,0,0,0,0,0};
static int8 Media_msg[2]={0,0};
static int8 leds;
if(input(PIN_B7)==0)
{
Media_msg[0]=REPT_ID02; // REPORT ID02
Media_msg[1]=0x40; // VOLUME DOWN
while(!usb_put_packet(2,Media_msg,2,USB_DTS_TOGGLE));
delay_ms(10);
Media_msg[0]=REPT_ID02; // REPORT ID02
Media_msg[1]=0x00; // RELEASE
while(!usb_put_packet(2,Media_msg,2,USB_DTS_TOGGLE));
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.
//we won't do anything with it.
if (usb_kbhit(2)) {
usb_get_packet(2, &leds, 1);
}
} |
|
|
|
pictrance
Joined: 18 Jul 2010 Posts: 14 Location: Puebla, Mexico
|
|
Posted: Tue Apr 13, 2021 2:35 pm |
|
|
vtrx wrote: | I just tested using the new code I posted, everything works.
Use portb7 as the button.
Code: | void usb_keyboard_task(void) {
// static int8 tx_msg[7]={0,0,0,0,0,0,0};
static int8 tx_msg[8]={0,0,0,0,0,0,0,0};
static int8 Media_msg[2]={0,0};
static int8 leds;
if(input(PIN_B7)==0)
{
tx_msg[0]=REPT_ID01; // NORMAL KEYBOARD
tx_msg[1]=0X00; // SPECIAL KEYS(CRT,SHIFT ETC)
tx_msg[2]=0X00; // RESERVED
tx_msg[3]=0X28; // ENTER KEY (NORMAL KEYS HERE)
while(!usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE));
delay_ms(10);
tx_msg[0]=REPT_ID01; // NORMAL KEYBOARD
tx_msg[1]=0X00; // SPECIAL KEYS(CRT,SHIFT ETC)
tx_msg[2]=0X00; // RESERVED
tx_msg[3]=0X00; // RELEASE
while(!usb_put_packet(2,tx_msg,sizeof(tx_msg),USB_DTS_TOGGLE));
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.
//we won't do anything with it.
if (usb_kbhit(2)) {
usb_get_packet(2, &leds, 1);
}
} |
|
sorry, im stupid,
I already saw the error, the error is in: tx_msg [7]
must be: tx_msg [8]
Code: | // static int8 tx_msg[7]={0,0,0,0,0,0,0};
static int8 tx_msg[8]={0,0,0,0,0,0,0,0}; |
because tx_msg [0]: is the device ID
and the remaining tx_msg [x] are for the device protocol
I'm sorry bro, thanks for the help. _________________ Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|