Difference between revisions of "Component: USB HID (Comms: USB)"
Line 25: | Line 25: | ||
===HID Mouse=== | ===HID Mouse=== | ||
− | Reads a EB014 keypad and depending on the key pressed sends the appropriate movement and button clicks to control the mouse. The speed is set by the speed variable which can range from 1 to 127. | + | Reads a EB014 keypad and depending on the key pressed sends the appropriate movement and button clicks to control the mouse. |
+ | |||
+ | The speed is set by the speed variable which can range from 1 to 127. | ||
+ | |||
{{Fcfile|USB_HID_Mouse.fcfx|Mouse Keypad Example}} | {{Fcfile|USB_HID_Mouse.fcfx|Mouse Keypad Example}} | ||
+ | |||
Key breakdown: 1 = UpLeft, 2=Up, 3=UpRight, 4=Left, 6=Right, 7=DownLeft, 8=Down, 9=DownRight, *=Left Click, #=Right Click. | Key breakdown: 1 = UpLeft, 2=Up, 3=UpRight, 4=Left, 6=Right, 7=DownLeft, 8=Down, 9=DownRight, *=Left Click, #=Right Click. | ||
− | Reads two encoders and moves the mouse cursor based on their movement since the last operation. A switch on pin B0 can be used to toggle the left mouse click on and off and pin B1 can be connected to an LED to show the status of the left mouse button. The EB073 encoders board connected to PortB will allow all of this functionality. | + | Reads two encoders and moves the mouse cursor based on their movement since the last operation. |
+ | |||
+ | A switch on pin B0 can be used to toggle the left mouse click on and off and pin B1 can be connected to an LED to show the status of the left mouse button. | ||
+ | |||
+ | The EB073 encoders board connected to PortB will allow all of this functionality. | ||
+ | |||
+ | |||
{{Fcfile|USB_HID_Etch_A_Sketch.fcfx|Mouse Encoder Example}} | {{Fcfile|USB_HID_Etch_A_Sketch.fcfx|Mouse Encoder Example}} | ||
+ | |||
+ | |||
===HID Keyboard=== | ===HID Keyboard=== | ||
− | Converts a ASCII character into a keypress that will be sent to the USB host device. A demo string is provided which is then broken down into characters and sent to the USB host. | + | Converts a ASCII character into a keypress that will be sent to the USB host device. |
+ | |||
+ | A demo string is provided which is then broken down into characters and sent to the USB host. | ||
+ | |||
{{Fcfile|USB_HID_Keyboard.fcfx|Keyboard Example}} | {{Fcfile|USB_HID_Keyboard.fcfx|Keyboard Example}} | ||
+ | |||
+ | |||
Here is a file showing the standard HID keyboard scan codes to help make sense of the example. | Here is a file showing the standard HID keyboard scan codes to help make sense of the example. | ||
Line 59: | Line 76: | ||
http://www.freebsddiary.org/APC/usb_hid_usages.php | http://www.freebsddiary.org/APC/usb_hid_usages.php | ||
+ | |||
===HID Descriptor Tool=== | ===HID Descriptor Tool=== |
Revision as of 16:12, 16 February 2017
Author | Matrix Ltd |
Version | 1.4 (Development) |
Category | Comms: USB |
Contents
USB HID component
Component to create and communicate using a standard HID type USB class. Compatible with simulation and USB enabled microcontroller devices PIC/dsPIC/AVR. Note that AVR is currently in Beta and may have problems with custom descriptors.
Examples
Here are some examples to get you started with USB HID communications using Flowcode.
HID Mouse
Reads a EB014 keypad and depending on the key pressed sends the appropriate movement and button clicks to control the mouse.
The speed is set by the speed variable which can range from 1 to 127.
Key breakdown: 1 = UpLeft, 2=Up, 3=UpRight, 4=Left, 6=Right, 7=DownLeft, 8=Down, 9=DownRight, *=Left Click, #=Right Click.
Reads two encoders and moves the mouse cursor based on their movement since the last operation.
A switch on pin B0 can be used to toggle the left mouse click on and off and pin B1 can be connected to an LED to show the status of the left mouse button.
The EB073 encoders board connected to PortB will allow all of this functionality.
HID Keyboard
Converts a ASCII character into a keypress that will be sent to the USB host device.
A demo string is provided which is then broken down into characters and sent to the USB host.
Here is a file showing the standard HID keyboard scan codes to help make sense of the example.
File:HID Keyboard Scan Codes.xls
With the example running if you create a text file and highlight the text file then the USB device will populate the file with data.
E.g.
HelloFromYourUSBKeyboardDevice12345
HelloFromYourUSBKeyboardDevice12345
HelloFromYourUSBKeyboardDevice12345
Currently only compatible with the following characters: 0123456789!"£$%^&*()/\*-+ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n\t
A complete list of keyboard scan codes can be found here under section 7 - Keyboards.
http://www.freebsddiary.org/APC/usb_hid_usages.php
HID Descriptor Tool
This tool allows you to create your own descriptors which can then be inserted into the HID descriptor property with the custom descriptor type selected.
Downloadable macro reference
ReceiveByte
Receives a byte from the USB.
Parameters
- BYTE Idx
Return value
SetSerialNumber
Allows the device serial number to be edited.
Parameters
- <- STRING SerialNumber
- This parameter may be returned back to the caller
Return value
- This call does not return a value
SendData
Sends the contents of the transmit buffer to the USB.
Parameters
- This macro has no parameters
Return value
CheckRx
Checks for any incoming data.
Returns the number of data bytes received since the last check.
Parameters
- This macro has no parameters
Return value
UpdateData
Allows a byte of the transmit buffer to be assigned.
Parameters
- BYTE idx
- BYTE value
Return value
- This call does not return a value
ReceiveString
Receives a string of bytes from the USB
Parameters
- BYTE NumBytes
Return value
SendDataDirect
Sends data directly to the USB
Parameters
- <- STRING Data
- This parameter may be returned back to the caller
Return value
Initialise
Starts up the USB connection and waits for the device driver to be correctly installed on the PC.
Parameters
- This macro has no parameters
Return value
Simulation macro reference
This component does not contain any simulation macros
Property reference
Vendor ID
This property is of type Signed integer and can be referenced with the variable name vendor_ID.
USB vendor identifier tied to the manufacturer of the USB device
Product ID
This property is of type Signed integer and can be referenced with the variable name product_ID.
USB product identifier
Device Name
This property is of type Line of text and can be referenced with the variable name dev_name.
Name used to identify the device
Manufacturer
This property is of type Line of text and can be referenced with the variable name dev_manufacturer.
Manufacturer of the device
Major Version
This property is of type Signed integer and can be referenced with the variable name major_version.
Firmware major version
Minor Version
This property is of type Signed integer and can be referenced with the variable name minor_version.
Device firmware minor version
Enumeration Timeout
This property is of type True or false and can be referenced with the variable name enumeration_tout.
Specifies if the initialise routine is allowed to timeout instead of waiting forever for success
Maximum Current (mA)
This property is of type Signed integer and can be referenced with the variable name max_current.
Maximum current the host should source to the device - max 500mA
Country Code
This property is of type Fixed list of ints and can be referenced with the variable name cntry_code.
Specific country code - if required
Descriptor Select
This property is of type Fixed list of ints and can be referenced with the variable name descriptor_Select.
Built in descriptor selection
HID Descriptor
This property is of type Multiple lines of text and can be referenced with the variable name HID_descriptor.
Contents of the HID descriptor
Subclass
This property is of type Fixed list of ints and can be referenced with the variable name subclass.
USB Subclass - Normally only mice and keyboards are boot devices
Interface
This property is of type Fixed list of ints and can be referenced with the variable name interface.
Standard HID interface type
Transmit Packet Size
This property is of type Signed integer and can be referenced with the variable name tx_packet_size.
Number of bytes to send to the PC
Transmit Period (ms)
This property is of type Signed integer and can be referenced with the variable name tx_period.
Delay between transmit packets
Receive Packet Size
This property is of type Signed integer and can be referenced with the variable name rx_packet_size.
Number of bytes to receive from the PC
Receive Period (ms)
This property is of type Signed integer and can be referenced with the variable name rx_period.
Delay between receive packets
Label
This property is of type Line of text and can be referenced with the variable name label.
Simulation label used to indicate the USB HID component on the panel.