USB Composite - Keyboard.press [Please help]

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
innopeace
Posts: 1
Joined: Sun Aug 02, 2020 2:54 pm

USB Composite - Keyboard.press [Please help]

Post by innopeace »

I am upgrading my keypad project from the Arduino Pro Micro to STM32F103.
However, I have a problem using LibMaple (Roger's repo).

Arduino Pro Micro (Atmega 32U) code

Code: Select all

#include "Keyboard.h"

void setup() {
	Keyboard.begin();
}

void loop(){
	Keyboard.press(KEY_F13);  //Arduino Built-in F13
	Keyboard.releaseAll();
	Keyboard.press(0xe1);  //Arduino non bulit-in Numpad 1 (HID usage table 0x59+0x88 =0xe1)
	Keyboard.releseAll();
}
STM32 code (Libmaple)

Code: Select all

#include <USBComposite.h>

USBHID HID;
HIDKeyboard Keyboard(HID);

void setup(){
	HID.begin(HID_KEYBOARD);
	Keyboard.begin();
}

void loop(){
	Keyboard.press(0xf0);  //F13 (0x68+0x88)
	Keyboard.releaseAll();
	Keyboard.press(0xe1);  //Numpad 1 (0x59+0x88)
	Keyboard.releaseAll();
}
In Arduino, either built-in keys or non built-in keys work well.
In STM32 (Libmaple), the built-in keys (say KEY_F12) work well.
However, it seems that non built-in keys do not work.

Thanks in advance for your help in this issue.

Regards,
InnoPeace
a1618
Posts: 1
Joined: Wed Aug 04, 2021 10:36 am

Re: USB Composite - Keyboard.press [Please help]

Post by a1618 »

Hi innopeace,
I encounter the exact issue when I try to make the keyboard using stm32duino.

And after compare USBHID.h with arduino built-in one, I finally solve the problem.

It looks like in LibMaple implementation, they only define LOGICAL_MAXIMUM and USAGE_MAXIMUM to 101 (0x65 in hex).

We could change it to 231 (0xE7 in hex) in order to send the F13+ key.

Modify the file %homepath%\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\USBComposite\USBHID.h
in line 207, change 0x25, 0x65, to 0x25, 0xE7
in line 211, change 0x29, 0x65, to 0x29, 0xE7

Code: Select all

\
    0x95, HID_KEYBOARD_ROLLOVER, 		/*    REPORT_COUNT (6) */ \
    0x75, 0x08,						/*    REPORT_SIZE (8) */ \
    0x15, 0x00,						/*    LOGICAL_MINIMUM (0) */ \
    0x25, 0xE7, /*  <- change 0x65 to 0xE7 LOGICAL_MAXIMUM (231) */ \
    0x05, 0x07,						/*    USAGE_PAGE (Keyboard) */ \
\
    0x19, 0x00,						/*    USAGE_MINIMUM (Reserved (no event indicated)) */ \
    0x29, 0xE7, /*    <- change 0x65 to 0xE7 USAGE_MAXIMUM (Keyboard Application) */ \
    0x81, 0x00,						/*    INPUT (Data,Ary,Abs) */ \
And you should now able to send F13+ keys.

Regards,
a1618
Post Reply

Return to “General discussion”