Difference between revisions of "Component: USB HID (Comms: USB)"
Line 17: | Line 17: | ||
==Component Source Code== | ==Component Source Code== | ||
− | Please click here to download the component source project: [https://www.flowcode.co.uk/ | + | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_USBHID.fcfx FC_Comp_Source_USBHID.fcfx] |
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_USBHID.fcfx FC_Comp_Source_USBHID.fcfx] | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_USBHID.fcfx FC_Comp_Source_USBHID.fcfx] | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
Line 46: | Line 48: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
Line 132: | Line 136: | ||
==Macro reference== | ==Macro reference== | ||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveByte''' | ||
+ | |- | ||
+ | | colspan="2" | Receives a byte from the USB. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Idx | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetSerialNumber''' | ||
+ | |- | ||
+ | | colspan="2" | Allows the device serial number to be edited. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" | SerialNumber | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendData''' | ||
+ | |- | ||
+ | | colspan="2" | Sends the contents of the transmit buffer to the USB. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CheckRx''' | ||
+ | |- | ||
+ | | colspan="2" | Checks for any incoming data. Returns the number of data bytes received since the last check. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''UpdateData''' | ||
+ | |- | ||
+ | | colspan="2" | Allows a byte of the transmit buffer to be assigned. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | idx | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | value | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReceiveString''' | ||
+ | |- | ||
+ | | colspan="2" | Receives a string of bytes from the USB | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | NumBytes | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SendDataDirect''' | ||
+ | |- | ||
+ | | colspan="2" | Sends data directly to the USB | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-string-icon.png]] - STRING | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | ||
+ | |- | ||
+ | | colspan="2" | Starts up the USB connection and waits for the device driver to be correctly installed on the PC. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ==Property reference== | ||
+ | |||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | USB Properties | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
+ | | width="90%" | Vendor ID | ||
+ | |- | ||
+ | | colspan="2" | USB vendor identifier tied to the manufacturer of the USB device | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-21-icon.png]] | ||
+ | | width="90%" | Product ID | ||
+ | |- | ||
+ | | colspan="2" | USB product identifier | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
+ | | width="90%" | Device Name | ||
+ | |- | ||
+ | | colspan="2" | Name used to identify the device | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
+ | | width="90%" | Manufacturer | ||
+ | |- | ||
+ | | colspan="2" | Manufacturer of the device | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Major Version | ||
+ | |- | ||
+ | | colspan="2" | Firmware major version | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Minor Version | ||
+ | |- | ||
+ | | colspan="2" | Device firmware minor version | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
+ | | width="90%" | Enumeration Timeout | ||
+ | |- | ||
+ | | colspan="2" | Specifies if the initialise routine is allowed to timeout instead of waiting forever for success | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Maximum Current (mA) | ||
+ | |- | ||
+ | | colspan="2" | Maximum current the host should source to the device - max 500mA | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Country Code | ||
+ | |- | ||
+ | | colspan="2" | Specific country code - if required | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Descriptor Select | ||
+ | |- | ||
+ | | colspan="2" | Built in descriptor selection | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-11-icon.png]] | ||
+ | | width="90%" | HID Descriptor | ||
+ | |- | ||
+ | | colspan="2" | Contents of the HID descriptor | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Subclass | ||
+ | |- | ||
+ | | colspan="2" | USB Subclass - Normally only mice and keyboards are boot devices | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Interface | ||
+ | |- | ||
+ | | colspan="2" | Standard HID interface type | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Transmit Packet Size | ||
+ | |- | ||
+ | | colspan="2" | Number of bytes to send to the PC | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Transmit Period (ms) | ||
+ | |- | ||
+ | | colspan="2" | Delay between transmit packets | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Receive Packet Size | ||
+ | |- | ||
+ | | colspan="2" | Number of bytes to receive from the PC | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Receive Period (ms) | ||
+ | |- | ||
+ | | colspan="2" | Delay between receive packets | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
+ | | width="90%" | Label | ||
+ | |- | ||
+ | | colspan="2" | Simulation label used to indicate the USB HID component on the panel. | ||
+ | |}==Macro reference== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" |
Revision as of 10:00, 27 January 2023
Author | Matrix Ltd |
Version | 1.4 |
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.
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.
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.
Macro reference
![]() |
ReceiveByte |
Receives a byte from the USB. | |
![]() |
Idx |
![]() |
Return |
![]() |
SetSerialNumber |
Allows the device serial number to be edited. | |
![]() |
SerialNumber |
![]() |
Return |
![]() |
SendData |
Sends the contents of the transmit buffer to the USB. | |
![]() |
Return |
![]() |
CheckRx |
Checks for any incoming data. Returns the number of data bytes received since the last check. | |
![]() |
Return |
![]() |
UpdateData |
Allows a byte of the transmit buffer to be assigned. | |
![]() |
idx |
![]() |
value |
![]() |
Return |
![]() |
ReceiveString |
Receives a string of bytes from the USB | |
![]() |
NumBytes |
![]() |
Return |
![]() |
SendDataDirect |
Sends data directly to the USB | |
![]() |
Data |
![]() |
Return |
![]() |
Initialise |
Starts up the USB connection and waits for the device driver to be correctly installed on the PC. | |
![]() |
Return |
Property reference
==Macro reference==
![]() |
ReceiveByte |
Receives a byte from the USB. | |
![]() |
Idx |
![]() |
Return |
![]() |
SetSerialNumber |
Allows the device serial number to be edited. | |
![]() |
SerialNumber |
![]() |
Return |
![]() |
SendData |
Sends the contents of the transmit buffer to the USB. | |
![]() |
Return |
![]() |
CheckRx |
Checks for any incoming data. Returns the number of data bytes received since the last check. | |
![]() |
Return |
![]() |
UpdateData |
Allows a byte of the transmit buffer to be assigned. | |
![]() |
idx |
![]() |
value |
![]() |
Return |
![]() |
ReceiveString |
Receives a string of bytes from the USB | |
![]() |
NumBytes |
![]() |
Return |
![]() |
SendDataDirect |
Sends data directly to the USB | |
![]() |
Data |
![]() |
Return |
![]() |
Initialise |
Starts up the USB connection and waits for the device driver to be correctly installed on the PC. | |
![]() |
Return |
Property reference
==Macro reference==
![]() |
ReceiveByte |
Receives a byte from the USB. | |
![]() |
Idx |
![]() |
Return |
![]() |
SetSerialNumber |
Allows the device serial number to be edited. | |
![]() |
SerialNumber |
![]() |
Return |
![]() |
SendData |
Sends the contents of the transmit buffer to the USB. | |
![]() |
Return |
![]() |
CheckRx |
Checks for any incoming data. Returns the number of data bytes received since the last check. | |
![]() |
Return |
![]() |
UpdateData |
Allows a byte of the transmit buffer to be assigned. | |
![]() |
idx |
![]() |
value |
![]() |
Return |
![]() |
ReceiveString |
Receives a string of bytes from the USB | |
![]() |
NumBytes |
![]() |
Return |
![]() |
SendDataDirect |
Sends data directly to the USB | |
![]() |
Data |
![]() |
Return |
![]() |
Initialise |
Starts up the USB connection and waits for the device driver to be correctly installed on the PC. | |
![]() |
Return |
Property reference
==Macro reference==
![]() |
ReceiveByte |
Receives a byte from the USB. | |
![]() |
Idx |
![]() |
Return |
![]() |
SetSerialNumber |
Allows the device serial number to be edited. | |
![]() |
SerialNumber |
![]() |
Return |
![]() |
SendData |
Sends the contents of the transmit buffer to the USB. | |
![]() |
Return |
![]() |
CheckRx |
Checks for any incoming data. Returns the number of data bytes received since the last check. | |
![]() |
Return |
![]() |
UpdateData |
Allows a byte of the transmit buffer to be assigned. | |
![]() |
idx |
![]() |
value |
![]() |
Return |
![]() |
ReceiveString |
Receives a string of bytes from the USB | |
![]() |
NumBytes |
![]() |
Return |
![]() |
SendDataDirect |
Sends data directly to the USB | |
![]() |
Data |
![]() |
Return |
![]() |
Initialise |
Starts up the USB connection and waits for the device driver to be correctly installed on the PC. | |
![]() |
Return |