Component: USB HID (Comms: USB)

From Flowcode Help
Jump to navigationJump to search
Author Matrix Ltd
Version 1.4
Category Comms: USB


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.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_USBHID.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_USBHID.fcfx

Detailed description

No detailed description exists yet for this component

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.

FC6 Icon.png 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.


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.


FC6 Icon.png Mouse Encoder Example


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.

FC6 Icon.png Keyboard Example


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.

File:HID Descriptor Tool.zip






Macro reference

CheckRx

Fc9-comp-macro.png CheckRx
Checks for any incoming data. Returns the number of data bytes received since the last check. 
Fc9-u8-icon.png - BYTE Return


Initialise

Fc9-comp-macro.png Initialise
Starts up the USB connection and waits for the device driver to be correctly installed on the PC.  
Fc9-u8-icon.png - BYTE Return


ReceiveByte

Fc9-comp-macro.png ReceiveByte
Receives a byte from the USB. 
Fc9-u8-icon.png - BYTE Idx
 
Fc9-u8-icon.png - BYTE Return


ReceiveString

Fc9-comp-macro.png ReceiveString
Receives a string of bytes from the USB 
Fc9-u8-icon.png - BYTE NumBytes
 
Fc9-string-icon.png - STRING Return


SendData

Fc9-comp-macro.png SendData
Sends the contents of the transmit buffer to the USB. 
Fc9-u8-icon.png - BYTE Return


SendDataDirect

Fc9-comp-macro.png SendDataDirect
Sends data directly to the USB 
Fc9-string-icon.png - STRING Data
 
Fc9-u8-icon.png - BYTE Return


SetSerialNumber

Fc9-comp-macro.png SetSerialNumber
Allows the device serial number to be edited. 
Fc9-string-icon.png - STRING SerialNumber
 
Fc9-void-icon.png - VOID Return


UpdateData

Fc9-comp-macro.png UpdateData
Allows a byte of the transmit buffer to be assigned. 
Fc9-u8-icon.png - BYTE idx
 
Fc9-u8-icon.png - BYTE value
 
Fc9-void-icon.png - VOID Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png USB Properties
Fc9-type-21-icon.png Vendor ID
USB vendor identifier tied to the manufacturer of the USB device 
Fc9-type-21-icon.png Product ID
USB product identifier 
Fc9-type-10-icon.png Device Name
Name used to identify the device 
Fc9-type-10-icon.png Manufacturer
Manufacturer of the device 
Fc9-type-14-icon.png Major Version
Firmware major version 
Fc9-type-14-icon.png Minor Version
Device firmware minor version  
Fc9-type-7-icon.png Enumeration Timeout
Specifies if the initialise routine is allowed to timeout instead of waiting forever for success 
Fc9-type-14-icon.png Maximum Current (mA)
Maximum current the host should source to the device - max 500mA 
Fc9-type-16-icon.png Country Code
Specific country code - if required 
Fc9-type-16-icon.png Descriptor Select
Built in descriptor selection  
Fc9-type-11-icon.png HID Descriptor
Contents of the HID descriptor 
Fc9-type-16-icon.png Subclass
USB Subclass - Normally only mice and keyboards are boot devices 
Fc9-type-16-icon.png Interface
Standard HID interface type 
Fc9-type-14-icon.png Transmit Packet Size
Number of bytes to send to the PC  
Fc9-type-14-icon.png Transmit Period (ms)
Delay between transmit packets 
Fc9-type-14-icon.png Receive Packet Size
Number of bytes to receive from the PC 
Fc9-type-14-icon.png Receive Period (ms)
Delay between receive packets 
Fc9-conn-icon.png Simulation
Fc9-type-10-icon.png Label
Simulation label used to indicate the USB HID component on the panel.