View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 354
|
usb driver & speed problem-Solved! |
Posted: Fri May 24, 2019 12:01 pm |
|
|
Hello All,
I face strange problem using CCS example "ex_usb_keyboard.c". I using it to send data from rfid reader to PC like keyboard send keys!
It's work OK, except when data have same characters in sequence!
For example : "12345AA678". Send only one 'A' caracter. Any idea what could be the problem?
Some part of code:
Code: |
void usb_keyboard_task(void)
{
unsigned int8 tx_msg[7];
unsigned int8 leds;
unsigned int16 scancode;
if(usb_tbe(1))
{
memset(tx_msg, 0x00, sizeof(tx_msg));
if(FlagNewCard){
scancode = ToHidKeyboardScancode(CardIdBuff[CardIdIndex++]);
if (bit_test(scancode, 8))
tx_msg[0] = KB_MODIFIER_LEFT_SHIFT;
tx_msg[2] = scancode;
if(CardIdIndex > 10)
FlagNewCard = FALSE;
}
usb_put_packet(1, tx_msg, sizeof(tx_msg), USB_DTS_TOGGLE);
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.a
//we won't do anything with it.
if (usb_kbhit(1))
{
usb_get_packet(1, &leds, 1);
}
} |
CCS ver.5.076
PIC18F24K50
Best Regards!
Last edited by kmp84 on Wed Jun 12, 2019 6:49 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Fri May 24, 2019 12:46 pm |
|
|
A search here would have found the answer, Look at this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=43330&highlight=usb+keyboard>
Look my reply (one from the end). |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Sat May 25, 2019 2:43 am |
|
|
Hello,
Thanks mr.Ttelmah! I didn't search enough! Problem solved!
I also want to ask you is it possible to speed-up incoming data to PC or send data as one packet not byte by byte ?
My edited function code:
Code: |
void usb_keyboard_task(void)
{
unsigned int8 tx_msg[7];
unsigned int8 leds;
unsigned int16 scancode;
static unsigned int16 last_scancode;
if(usb_tbe(1))
{
memset(tx_msg, 0x00, sizeof(tx_msg));
if(FlagNewCard){
scancode = ToHidKeyboardScancode(CardIdBuff[CardIdIndex++]);
if(scancode == last_scancode){
scancode = 0;
CardIdIndex--;
}
if (bit_test(scancode, 8))
tx_msg[0] = KB_MODIFIER_LEFT_SHIFT;
tx_msg[2] = scancode;
if(CardIdIndex > 10)
FlagNewCard = FALSE;
last_scancode = scancode;
}
//printf("\r\ntx_mes size:%u, scancode=%LX", sizeof(tx_msg), scancode);
usb_put_packet(1, tx_msg, sizeof(tx_msg), USB_DTS_TOGGLE);
}
//receive NUM LOCK, CAPS LOCK, etc LED status from PC.a
//we won't do anything with it.
if (usb_kbhit(1))
{
usb_get_packet(1, &leds, 1);
}
} |
Best Regards! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sat May 25, 2019 11:53 pm |
|
|
USB itself never sends 'byte by byte'. The communications will be a packet.
8, 16, 32 or 64 bytes. There is a maximum of one packet every mSec for an
HID device. However the Windows keyboard driver does itself not call
the HID device terribly quickly. Remember the keyboard interface is designed
to handle the original PS/2 'traffic', which was limited to a maximum of
16.7Kbaud. It is this that the USB interface handling replicates. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Mon May 27, 2019 2:34 am |
|
|
Hello,
I'm not familiar with USB and KBD protocol, but have USB barcode scanner, which also is recognize as my USB reader (HID Keyboard Device) and data are send to PC (Notepad) 3-4 times faster!
Best Regards! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon May 27, 2019 5:07 am |
|
|
In Windows 'Accessibility options'. Turn off 'filter keys'. This otherwise adds
a short delay to the handling of quick key sequences.
Also the key will generally be handled quicker by Windows if you always
send a key released message. Otherwise the keyboard response is limited
by the key repeat timing in Windows. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
|
Posted: Mon May 27, 2019 6:14 am |
|
|
Hi Mr.Ttelmah,
What is structure of " key released message"? I tried to insert '0x00' between my data bytes, but the speed is slower!
Thanks, |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon May 27, 2019 7:57 am |
|
|
Have you tried turning off filter keys?. This makes a huge difference...
You can speed things by up to a factor of 6, by sending multiple keys per
packet.
Currently you are sending one scancode in tx_msg[2]
However the keyboard message will accept up to six scancodes
in tx_msg[2] to tx_msg[7]
So six keys per message, where you are currently sending one....
The '0' message is 'all released', so works reliably. The key released code
is the key scancode with bit 7 set.
So if you put your scancode into tx_msg[2], then the scancode|0x80
into tx_msg[3], then the next scancode into tx_msg[4], and this again
or 0x80 in tx_msg[5], another code into tx_msg[6] and this again or'ed
with 0x80 in tx_msg[7], you will send three complete key pressed and
released sequences in one packet. However _caveat_, 'filter keys', will
reject short scancodes. It is designed to prevent people accidentally
typing a value, by momentary touches on things like touch screens.
Settings
Ease of Access
Keyboard
Use filter keys
Turn this off to allow short key presses to work. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 354
|
speed problem Solved! |
Posted: Wed Jun 12, 2019 6:48 am |
|
|
Hello,
Excuse me for the late answer!
The problem with speed of incomming data was task, which serve EM4095 basestation driver. Now if I have new card I just stop EM4095 task and data are send to PC very fast!
Some part of code:
Code: |
for(;;){
CurTick = get_ticks();
// service low level USB operations.
usb_task();
if(usb_enumerated()){
usb_keyboard_task();
if(!FlagNewCard){
EM4095_Task();
}
} |
Best Regards! |
|
|
|