USB Keyboard


Closed Thread
Results 1 to 20 of 20

Thread: USB Keyboard

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default USB Keyboard

    This feels like deep water to me. I 'd like to develop a small keyboard that will send to the PC specific characters when buttons are pressed.

    In short it will be a stripped keyboard with much less keys (F1-F12, number 1-8 and another 8 capital letters).

    Can PBP support such a function? Found for mouse but not a working keyboard emulation.

    Prefer to use 4550 or 45K50 chips.

    Thanks,
    Ioannis

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557

    Default Re: USB Keyboard

    I do believe there is a sub-category in the HID USB category specific to keyboards. Each key has its own command code. If you enumerate as a keyboard, it is just using what has already been developed.

  3. #3
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    955

    Default Re: USB Keyboard

    The easy part is to first verify the mouse code emulates correctly when connected to the PC. This ensures the skeleton is a working one.

    The not so easy thing to do is to get the Descriptor tables for the keyboard matched to what is expected by the PC. Once you have that, it's just a matter of reading/writing to the USB system every mS or so.

    Suggest you look for the 'Descriptor Tool' DT.EXE which will help you build the descriptor table. However, you will need to adjust the tables for PBP

    Good luck

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,569

    Default Re: USB Keyboard

    I have some code (based on something found on the forum I'm sure) that does USB keyboard emulation.
    Letters and numbers I know works but I don't think I implemented F1-F12 etc. I'll dig it out and post it if you're interested.

  5. #5

    Default Re: USB Keyboard


  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Oh, you naughty aerostar! I guess alzheimer is knocking my door...

    Too much info on this USB mess... Lost the links I kept in case I needed them back.

    Thanks people for the info.

    Henrik, if you find your test code, please do post it. Will save me some time I am sure.

    Ioannis

  7. #7
    Join Date
    Sep 2009
    Posts
    750

    Default Re: USB Keyboard

    I made keyboard to use as shortcuts for EAGLE. Should be exactly what you need. I used it on easypic dev board. Pic should be 18F4550.
    Here is complete project My UsbKeyboard.zip

    I created that using many examples from forum...

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Thank you very much pedja089!

    Looks great and very close to what I need to do. have to add a small graphics display and test it on Win 10. Hope Win 10 do not pose any communication problem.

    Really appreciated.
    Ioannis

  9. #9
    Join Date
    Sep 2009
    Posts
    750

    Default Re: USB Keyboard

    I used it on win7, and if I remember correctly on XP. It should work on win10.
    You have keys.PBP, with all defined keys, also in .doc document you have codes.

    Also USBSERVICE should be called every 10mS or so. I wanted to implement it with DT INT, but newer did...
    It should be something like this

    Code:
    INCLUDE "DT_INTS-18.bas"
    INCLUDE "ReEnterPBP-18.bas"
     
    ASM
    INT_LIST  macro		; IntSource,       Label,       Type,  ResetFlag?
            INT_Handler   USB_INT,  _SERVICE_USB,       ASM,  yes 
        endm
        INT_CREATE		; Creates the interrupt processor
    ENDASM
    
    USBINIT                'INITIALIZE USB
    USBSERVICE             'SERVICE USB
    UIE = $7F              'ENABLE USB INTERRUPTS
    UEIE = $9F             'ENABLE USB ERROR INTERRUPTS
    @ INT_ENABLE  USB_INT
    
    
    SERVICE_USB:
        USBSERVICE
    @ INT_RETURN
    This code is also from forum, but never tried it.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Thanks for this tip also. I had in mind to make this Interrupt driven service but in a later stage.

    Ioannis

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Thanks to your help I am making a progress after a lot of experimenting. Sure I do not understand the whole process but anyway...

    I managed to enumerate the PIC and display on an open text file a short string of characters from an 8 byte buffer.

    How can this buffer made bigger? I changed these in the main program
    Code:
    USBBufferSizeTX con 16                                                                                    
    USBBufferSizeRX con 16
    USBBufferCount Var Byte
    USBBufferIn var byte[16]
    USBBufferOut Var Byte[16]
    but still sends only the half buffer.

    Then I changed in the hid_desc.bas file this line

    Code:
    retlw	0x10		; This should be the size of the endpoint buffer
    from 0x08 to 0x10 but still no joy. I attach the descriptor file.

    Any idea?

    Ioannis

    P.S. I also changed

    #define HID_INT_OUT_EP_SIZE 8

    in the descriptor file to 16 but still sends 8 byte buffer...
    Attached Files Attached Files
    Last edited by Ioannis; - 18th December 2021 at 22:06.

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,512

    Default Re: USB Keyboard

    never tried it as hid kb but for a hid cdc anyway the data you need to send must be chunked into usb-tx buffer sized lumps
    then sent a multiple usb transmissions.

    what have you tried ?
    Warning I'm not a teacher

  13. #13
    Join Date
    Sep 2009
    Posts
    750

    Default Re: USB Keyboard

    It is not so easy to change buffer. You must change descriptor file, not just length(If I understand usb correctly).

    You can send one letter and modifier key at time.

    Use this

    Code:
     For i = 0 To 20	
                    lookup i,[KEY_V, KEY_A, KEY_L, KEY_U, KEY_E, KEY_ENTER, 0], USBBufferOut[2]
                    call DoUsbOut
                    IF USBBufferOut[2]=0 THEN EXIT
                Next i
    You can use array
    Code:
     For i = 0 To 20	
                      USBBufferOut[2]= MyArray[i]
                    call DoUsbOut
                    IF USBBufferOut[2]=0 THEN EXIT
                Next i

  14. #14
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    955

    Default Re: USB Keyboard

    If you follow the HID descriptor fields, you will notice you need to change the report count for the report which has to carry more data. The endpoint buffer is just a holding place for the in/out data that is handled by the USB interrupt. I am not very conversant with HID at the moment, but can look it up as I have worked on HID keyboards with PSoC
    Last edited by Jerson; - 19th December 2021 at 04:43. Reason: removed signature

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Quote Originally Posted by richard View Post
    what have you tried ?
    I think every variable or constant I could find in the program and the descriptor file. One at a time or combination of them. The result was sending the 8 wide buffer all the time.

    Quote Originally Posted by pedja089 View Post
    It is not so easy to change buffer. You must change descriptor file, not just length(If I understand usb correctly).

    [/CODE]
    Yes, I found the hard way...

    I guess for now, your approach is the only way to do it. I thought I could escape with just a number change from 8 to 16!

    Jerson, as I noted above, I did change all those variables related to the buffer size (all where at 8 bytes) within descriptor file, but nothing really worked.

    Ioannis

  16. #16
    Join Date
    Sep 2009
    Posts
    750

    Default Re: USB Keyboard

    Along buffer size, you need to change in hid_desc.bas:
    Code:
    ReportDescriptor1
    	retlw   0x05
    	retlw   0x01    ; usage page (generic desktop)
    	retlw   0x09
    	retlw   0x06    ; usage (keyboard)
    	retlw   0xA1
    	retlw   0x01    ; collection (application)
    	retlw   0x05
    	retlw   0x07    ;   usage (Key codes)
    	retlw   0x19
    	retlw   0xE0    ;   usage minimum (224)
    	retlw   0x29
    	retlw   0xE7    ;   usage minimum (231)
    	retlw   0x15
    	retlw   0x00    ;     logical minimum (0)
    	retlw   0x25
    	retlw   0x01    ;     logical maximum (1)
    	retlw   0x75
    	retlw   0x01    ;     report size (1)
    	retlw   0x95
    	retlw   0x08    ;     report count (8)
    	retlw   0x81
    	retlw   0x02    ;     Input (data,variable,absolute)
    	retlw   0x95
    	retlw   0x01    ;     report count (1)
    	retlw   0x75
    	retlw   0x08    ;     report size (8)
    	retlw   0x81
    	retlw   0x01    ;     Input (constant)
    	retlw   0x95
    	retlw   0x05    ;     report count (5)
    	retlw   0x75
    	retlw   0x01    ;     report size (1)
    	retlw   0x05
    	retlw   0x08    ;     usage page (page# for leds)
    	retlw   0x19
    	retlw   0x01    ;     Usage minimum (1)
    	retlw   0x29
    	retlw   0x05    ;     Usage maximum (5)
    	retlw   0x91
    	retlw   0x02    ;     output (data,variable,absolute)
    	retlw   0x95
    	retlw   0x01    ;     report count (1)
    	retlw   0x75
    	retlw   0x03    ;     report size (3)
    	retlw   0x91
    	retlw   0x01    ;     output (constant)
    	retlw   0x95
    	retlw   0x06    ;     report count (6)
    	retlw   0x75
    	retlw   0x08    ;     report size (8)
    	retlw   0x15
    	retlw   0x00    ;     logical minimum (0)
    	retlw   0x25
    	retlw   0x65    ;     logical maximum (101)
    	retlw   0x05
    	retlw   0x07    ;     usage page (keycodes)
    	retlw   0x19
    	retlw   0x00    ;     usage minimum (0)
    	retlw   0x29
    	retlw   0x65    ;     usage maximum (101)
    	retlw   0x81
    	retlw   0x00    ;     input (data, array)	
    	retlw   0xC0    ;   end collection
    EndReportDescriptor1
    If I understand correctly. But I never had any luck with changing descriptor files.

  17. #17
    Join Date
    Sep 2009
    Posts
    750

    Default Re: USB Keyboard

    I think you can find some info in this series:



    Look for nkey roll over descriptor...

  18. #18
    Join Date
    May 2013
    Location
    australia
    Posts
    2,512

    Default Re: USB Keyboard

    if i watch that first video again i could fool myself into believing that one day i might understand usb enough to actually get somewhere with it

    great info pedja089
    Warning I'm not a teacher

  19. #19
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    955

    Default Re: USB Keyboard

    very nice instructive videos

  20. #20
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,980

    Default Re: USB Keyboard

    Quote Originally Posted by pedja089 View Post
    Along buffer size, you need to change in hid_desc.bas:
    Code:
    ReportDescriptor1
    	retlw   0x05
    	retlw   0x01    ; usage page (generic desktop)
    	retlw   0x09
    	retlw   0x06    ; usage (keyboard)
    	retlw   0xA1
    	retlw   0x01    ; collection (application)
    	retlw   0x05
    	retlw   0x07    ;   usage (Key codes)
    	retlw   0x19
    	retlw   0xE0    ;   usage minimum (224)
    	retlw   0x29
    	retlw   0xE7    ;   usage minimum (231)
    	retlw   0x15
    	retlw   0x00    ;     logical minimum (0)
    	retlw   0x25
    	retlw   0x01    ;     logical maximum (1)
    	retlw   0x75
    	retlw   0x01    ;     report size (1)
    	retlw   0x95
    	retlw   0x08    ;     report count (8)
    	retlw   0x81
    	retlw   0x02    ;     Input (data,variable,absolute)
    	retlw   0x95
    	retlw   0x01    ;     report count (1)
    	retlw   0x75
    	retlw   0x08    ;     report size (8)
    	retlw   0x81
    	retlw   0x01    ;     Input (constant)
    	retlw   0x95
    	retlw   0x05    ;     report count (5)
    	retlw   0x75
    	retlw   0x01    ;     report size (1)
    	retlw   0x05
    	retlw   0x08    ;     usage page (page# for leds)
    	retlw   0x19
    	retlw   0x01    ;     Usage minimum (1)
    	retlw   0x29
    	retlw   0x05    ;     Usage maximum (5)
    	retlw   0x91
    	retlw   0x02    ;     output (data,variable,absolute)
    	retlw   0x95
    	retlw   0x01    ;     report count (1)
    	retlw   0x75
    	retlw   0x03    ;     report size (3)
    	retlw   0x91
    	retlw   0x01    ;     output (constant)
    	retlw   0x95
    	retlw   0x06    ;     report count (6)
    	retlw   0x75
    	retlw   0x08    ;     report size (8)
    	retlw   0x15
    	retlw   0x00    ;     logical minimum (0)
    	retlw   0x25
    	retlw   0x65    ;     logical maximum (101)
    	retlw   0x05
    	retlw   0x07    ;     usage page (keycodes)
    	retlw   0x19
    	retlw   0x00    ;     usage minimum (0)
    	retlw   0x29
    	retlw   0x65    ;     usage maximum (101)
    	retlw   0x81
    	retlw   0x00    ;     input (data, array)	
    	retlw   0xC0    ;   end collection
    EndReportDescriptor1
    If I understand correctly. But I never had any luck with changing descriptor files.
    Me too... There is no documentation of all these parameters...

    Will watch the videos. Thanks for the info each and everyone.
    Ioannis

Similar Threads

  1. PIC18F14K50 USB Keyboard firmware
    By ScumariTec in forum USB
    Replies: 0
    Last Post: - 27th January 2021, 11:29
  2. USB keyboard emulator
    By Toley00 in forum USB
    Replies: 12
    Last Post: - 23rd January 2012, 01:57
  3. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 01:04
  4. Replies: 17
    Last Post: - 13th June 2008, 22:33
  5. Replies: 3
    Last Post: - 10th April 2008, 11:02

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts