Comments (6)
Keyboards and mice are very similar, with two subtle differences:
- Keyboards have a lot more keys, and as a result tend to report which key was pressed rather than which keys are pressed, and
- Keyboards report keyDown and keyUp separately, whereas mice always report a movement event.
First, you'll have to modify the USB report descriptors.
- Update the HID report descriptor on https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L78 and replace it with a Keyboard report. Report descriptors start with
0x05, 0x01 /* USAGE_PAGE (Generic Desktop) */
in case you'd like to play around with other descriptor types. This should be a straight copy-and-paste job. An example I just found was:
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs) //1 byte
0x95, 0x01, // REPORT_COUNT (1)
0x75, 0x08, // REPORT_SIZE (8)
0x81, 0x03, // INPUT (Cnst,Var,Abs) //1 byte
0x95, 0x06, // REPORT_COUNT (6)
0x75, 0x08, // REPORT_SIZE (8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x65, // LOGICAL_MAXIMUM (101)
0x05, 0x07, // USAGE_PAGE (Keyboard)
0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, // INPUT (Data,Ary,Abs) //6 bytes
0xc0 // END_COLLECTION
-
Update the packet size at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L144 to be 8 bytes
-
Change the protocol to "1" for keyboard at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L156
Next (and finally), you'll need to modify the packet that gets defined at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L240 and sent at https://github.com/im-tomu/tomu-quickstart/blob/master/usb-hid/usb-hid.c#L257. The mouse descriptor is 4 bytes (first byte is the buttons, next byte is X, next byte is Y, next byte is mouse wheel).
The keyboard descriptor is described at https://damogranlabs.com/2018/02/stm32-usb-hid-mouse-keyboard/ but basically to send an "a" you'd write "{0, 0, 4, 0, 0, 0, 0, 0}", and to send a "release key 'a'" you'd write "{0, 0, 0, 0, 0, 0, 0, 0}".
from tomu-quickstart.
Thank a lot xobs.
Tomu is writing a's now.
In line 217
I also changed the 4 for an 8 (buffer size I suppose)
usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 4, NULL); // previous mouse
usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_INTERRUPT, 8, NULL); // keyboard
from tomu-quickstart.
Neat! Would you like to submit a PR with the keyboard HID example?
from tomu-quickstart.
Of course! Thanks.
I've created another directory named usb-hid-keyboard and transfer the code in there.
But I have never used Git for other purpose than clone... What shall I do now?
from tomu-quickstart.
The easiest is to probably use the Github flow:
- Fork the repository. Click the
Fork
button up top. - Add it as a remote.
git remote add honos https://github.com/Honos2014/tomu-quickstart.git
- Commit your change.
git commit usb-hid-keyboard/Makefile usb-hid-keyboard/yourfilename.c
- Push your change.
git push honos master
- Open a Pull Request. At the top of https://github.com/Honos2014/tomu-quickstart a new button will appear.
from tomu-quickstart.
Closed by 334a395
from tomu-quickstart.
Related Issues (20)
- quickstart documentation should contain links on the programming API HOT 6
- Nothing builds with Ubuntu 18.04 HOT 4
- Documentation Enhancement: Install Arm Embedded Toolchain on macOS with homebrew
- Unable to compile U2F (chopstx) HOT 2
- gpg? HOT 1
- Solid Red light HOT 3
- cbmbasic loaded onto tomu freezes after first keystroke HOT 3
- Inconsistently loading new code HOT 6
- Can't get U2F working HOT 2
- program persistence after unplugging HOT 1
- TOBOOT_CONFIG_FLAG_AUTORUN HOT 4
- brew install dfu-util HOT 1
- Windows 10 wont recognize USB examples HOT 1
- Clarify documentation in readme.md HOT 1
- RFC: mass storage with write support HOT 1
- Issue uploading to tomu HOT 5
- arm-none-eabi/bin/ld: cannot find -lstdc++ error when running make HOT 1
- enhancement: add usb multiplexing sample HOT 1
- Question for HID keyboard example HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tomu-quickstart.