usbapp - USB Functional operation#

Adaptation status unknown

Note

This page document is automatically generated by this file. If there is any error, please submit issue or help modify pr, thank you!

Tip

This library has its own demo,click this link to view demo examples of usbapp

Constant#

constant

type

explanation

usbapp.NO_READY

number

NO_READY Event

usbapp.READY

number

READY Event

usbapp.SEND_OK

number

SEND_OK Event

usbapp.NEW_DATA

number

NEW_DATA Event

usbapp.set_id(id, vid, pid)#

USB Set the VID and PID

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

int

vid Little Endian Format

int

pid Little Endian Format

Return Value

None

Examples

usbapp.set_id(0, 0x1234, 0x5678)

usbapp.hid_mode(id, mode, buff_size)#

USB HID Device Mode

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

int

mode,Currently 0 is keyboard, 1 is custom

int

buff_size,It can only be 8,16,32,64. If it is keyboard mode or other values are filled in, it will automatically be 8

Return Value

None

Examples

usbapp.hid_mode(0, 0) -- usb hid Keyboard mode
usbapp.hid_mode(0, 1) -- usb hid Custom mode for USB interaction

usbapp.start(id)#

Boot USB device

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

-- Start USB
usbapp.start(0)

usbapp.stop(id)#

Turn off USB device

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

-- Close USB
usbapp.stop(0)

usbapp.vhid_upload(id, data)#

USB HID Device upload data

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

string

Data. Note that the available characters of HID are limited, basically only visible characters are supported, and unsupported characters will be replaced with spaces..

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

-- HID Upload data
usbapp.vhid_upload(0, "1234") -- usb hid will simulate knocking out 1234

usbapp.hid_tx(id, data, start, len)#

USB HID Device uploads user-defined data

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

string

or zbuff Note that it will be automatically filled when the amount of data is insufficient 0

int

Optional. Data is valid only if it is zbuff. The starting position of the data to be sent is 0

int

Optional. Data is valid only if it is zbuff. The length of the data to be sent is valid data in zbuff by default. The maximum value does not exceed the maximum space of zbuff.

Return Value

return value type

explanation

bool

Returns true on success, otherwise false

Examples

-- HID Upload data
usbapp.hid_tx(0, "1234") -- usb hid Upload 0x 31 0x 32 0x 33 0x 34 N 0

usbapp.hid_rx(id, buff)#

buff Read the received data in the form, read all the data at one time and store it in buff. If there is not enough space in buff, it will automatically expand. Currently, only air105 supports this operation.

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

zbuff

zbuff Object

Return Value

return value type

explanation

int

Returns the length of the read and moves the zbuff pointer backward

Examples

usbapp.hid_rx(0, buff)

usbapp.vhid_cancel_upload(id)#

USB HID Device cancels uploading data

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

Return Value

return value type

explanation

nil

No return value

Examples

-- Cancel uploading data, usually not required
usbapp.vhid_cancel_upload(0)

usbapp.udisk_attach_sdhc(id)#

USB U Disk device mount SDHC,TF card

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

Return Value

return value type

explanation

nil

No return value

Examples

usbapp.udisk_attach_sdhc(0)

usbapp.udisk_detach_sdhc(id)#

USB U Disk device removal mount SDHC,TF card

Parameters

Incoming Value Type

Explanation

int

the device id. the default value is 0

Return Value

return value type

explanation

nil

No return value

Examples

usbapp.udisk_detach_sdhc(0)