USBHIDDevice Class

USBHIDDevice Class

Description
A class used for creating and managing USB HID device class.

Syntax
class USBHIDDevice

Members

Public Constructors
The public constructor should not be used as this class is intended to be a singleton class. Access member functions using the object instance named USBHIDDev.
Public Methods 
USBHIDDevice::setReportDescriptorConfigure the HID report descriptor.
USBHIDDevice::setUSBEndpointMPSConfigure USB endpoint maximum packet size.
USBHIDDevice::setUSBEndpointIntervalConfigure USB endpoint polling interval.
USBHIDDevice::setVIDSet USB vendor ID value.
USBHIDDevice::setPIDSet USB product ID value.
USBHIDDevice::setManufacturerStringSet USB manufacturer string.
USBHIDDevice::setModelStringSet USB product model name string.
USBHIDDevice::setSerialStringSet USB product serial number string.
USBHIDDevice::USBconnectedCheck if the USB port is connected to a host
USBHIDDevice::beginStart USB HID device
USBHIDDevice::endStop USB HID device
USBHIDDevice::inputReportSend a HID input report

USBHIDDevice::setReportDescriptor

Description
Configure the HID report descriptor.

Syntax
void setReportDescriptor(uint8_t* report_desc, uint16_t len);

Parameters
report_desc: pointer to buffer containing HID report descriptor.
len: HID report descriptor length in number of bytes.

Returns
NA

Example Code
Example: USBHIDGamepad
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBHIDGamepad/USBHIDGamepad.ino)

Notes and Warnings
Default HID report descriptor is configured for mouse + keyboard + consumer control. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setUSBEndpointMPS

Description
Configure USB endpoint maximum packet size.

Syntax
void setUSBEndpointMPS(uint8_t max_packet_size);

Parameters
max_packet_size: maximum HID report packet size in bytes.

Returns
NA

Example Code
Example: USBHIDGamepad
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBHIDGamepad/USBHIDGamepad.ino)

Notes and Warnings
The USB endpoint maximum packet size should correspond to the size of the largest HID report defined in the HID report descriptor. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setUSBEndpointInterval

Description
Configure USB endpoint polling interval.

Syntax
void setUSBEndpointInterval(uint8_t poll_interval);

Parameters
poll_interval: polling interval for USB interrupt endpoint, expressed in milliseconds.

Returns
NA

Example Code
NA
<
Notes and Warnings
Default polling interval is set at the minimum of 1 millisecond. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setVID

Description
Set USB vendor ID value.

Syntax
void setVID(uint16_t VID);

Parameters
VID: vendor ID

Returns
NA

Example Code
NA

Notes and Warnings
The VID should be configured before USBHIDDevice::begin() function is called. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setPID

Description
Set USB product ID value.

Syntax
void setPID(uint16_t PID);

Parameters
PID: product ID

Returns
NA

Example Code
NA

Notes and Warnings
The PID should be configured before USBHIDDevice::begin() function is called. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setManufacturerString

Description
Set USB manufacturer string.

Syntax
void setManufacturerString(const char* manufacturer);

Parameters
manufacturer: Character string containing manufacturer name. Default “Realtek”.

Returns
NA

Example Code
NA

Notes and Warnings
The manufacturer string should be configured before USBHIDDevice::begin() function is called. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setModelString

Description
Set USB product model name string.

Syntax
void setModelString(const char* model);

Parameters
model: Character string containing model name. Default “Realtek USB HID”.

Returns
NA

Example Code
NA

Notes and Warnings
The model string should be configured before USBHIDDevice::begin() function is called. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::setSerialString

Description
Set USB product serial number string.

Syntax
void setSerialString(const char* serial);

Parameters
serial: Character string containing serial number. Default “0123456789”.

Returns
NA

Example Code
NA

Notes and Warnings
The serial string should be configured before USBHIDDevice::begin() function is called. “USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::USBconnected

Description
Check if the USB port is connected to a host.

Syntax
uint8_t USBconnected(void);

Parameters
NA

Returns
This function returns TRUE as 1 if the USB port is connected to a host, FALSE as 0 if it is not connected.

Example Code
Example: USBHIDGamepad
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBHIDGamepad/USBHIDGamepad.ino)

Notes and Warnings
“USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::begin

Description
Start USB HID device.

Syntax
void begin(void);

Parameters
NA

Returns
NA

Example Code
Example: USBHIDGamepad
(https://github.com/ambiot/ambd_arduino/blob/dev/Arduino_package/hardware/libraries/USB/examples/USBHIDGamepad/USBHIDGamepad.ino)

Notes and Warnings
“USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::end

Description
Stop USB HID device.

Syntax
void end(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“USBHIDDevice.h” must be included to use the class function.

USBHIDDevice::inputReport

Description
Send a HID input report.

Syntax
void inputReport(uint8_t reportID, uint8_t* data, uint16_t len);

Parameters
reportID: HID report ID of input report.
data: pointer to HID input report data to send.
len: length of HID input report data in bytes.

Returns
NA

Example Code
NA

Notes and Warnings
A reportID value of 0 is not a valid report ID and will send an input report without the report ID field. “USBHIDDevice.h” must be included to use the class function.

请先确认已安装QQ通讯软体