I need to implement a keyboard with the USB HID library. I have done it before but now I need to add auto repeat / typematic (when a key is held down it repeats itself). Is there an option for that or do I have to manually program it?
Thanks!!
guy
Joined: 21 Oct 2005 Posts: 297
solution!
Posted: Thu Feb 05, 2015 1:21 pm
Darren from CCS tech support helped me with this one so I'll share it with you:
Quote:
While the key is held down the BIOS and OS handle what to do.
So the auto repeat is handled in the BIOS/Windows. I looked into the example code in ex_usb_keyboard.c and saw that in each iteration usb_keyboard_task() sends either a character or an empty array which signals that no key is pressed.
Code:
/////////////////////////////////////////////////////////////////////////////
//
// usb_keyboard_task()
//
// Sends a packet of keyboard data. The protocol was specified in the HID
// report descriptor (see usb_desc_kbmouse.h), and is:
// tx_msg[0] = modifier (see kb_modifier_t)
// tx_msg[1] = const 0
// tx_msg[2:6] = an array of held down keys. a=4, b=5, etc.
// if msg[2:7]={0} then no keys are held down
//
// rx_msg[0] = 5bit bitmap of led status
//
/////////////////////////////////////////////////////////////////////////////
What I did is to make tx_msg a global array that is NOT cleared each time but instead keeps track of the pressed keys (in index 2-6 of the array). When a key is released the suitable entry in the array is set to 0 which signals Key Released. Works great! My code is a little sloppy so I didn't upload it but let me know if someone needs actual code.
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