Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected Member Functions
USBMouseKeyboard Class Reference

USBMouseKeyboard example. More...

#include <USBMouseKeyboard.h>

Inheritance diagram for USBMouseKeyboard:
USBHID Stream USBDevice FileLike NonCopyable< Stream > USBPhyEvents FileHandle FileBase NonCopyable< FileLike > NonCopyable< FileHandle > NonCopyable< FileBase >

Public Member Functions

 USBMouseKeyboard (bool connect_blocking=true, MOUSE_TYPE mouse_type=REL_MOUSE, uint16_t vendor_id=0x0021, uint16_t product_id=0x0011, uint16_t product_release=0x0001)
 Basic constructor. More...
 
 USBMouseKeyboard (USBPhy *phy, MOUSE_TYPE mouse_type=REL_MOUSE, uint16_t vendor_id=0x0021, uint16_t product_id=0x0011, uint16_t product_release=0x0001)
 Fully featured constructor. More...
 
virtual ~USBMouseKeyboard ()
 Destroy this object. More...
 
bool update (int16_t x, int16_t y, uint8_t buttons, int8_t z)
 Write a state of the mouse. More...
 
bool move (int16_t x, int16_t y)
 Move the cursor to (x, y) More...
 
bool press (uint8_t button)
 Press one or several buttons. More...
 
bool release (uint8_t button)
 Release one or several buttons. More...
 
bool doubleClick ()
 Double click (MOUSE_LEFT) More...
 
bool click (uint8_t button)
 Click. More...
 
bool scroll (int8_t z)
 Scrolling. More...
 
bool key_code (uint8_t key, uint8_t modifier=0)
 To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key. More...
 
virtual int _putc (int c)
 Send a character. More...
 
bool media_control (MEDIA_KEY key)
 Control media keys. More...
 
uint8_t lock_status ()
 Read status of lock keys. More...
 
bool ready ()
 Check if this class is ready. More...
 
void wait_ready ()
 Block until this HID device is in the configured state. More...
 
bool send (const HID_REPORT *report)
 Send a Report. More...
 
bool send_nb (const HID_REPORT *report)
 Send a Report. More...
 
bool read (HID_REPORT *report)
 Read a report: blocking. More...
 
bool read_nb (HID_REPORT *report)
 Read a report: non blocking. More...
 
void init ()
 Initialize this instance. More...
 
void deinit ()
 Power down this instance. More...
 
bool configured ()
 Check if the device is configured. More...
 
void connect ()
 Connect a device This method can also be used to resume USB operation when USB power is detected after it was suspended via USBDevice::deinit. More...
 
void disconnect ()
 Disconnect a device. More...
 
void sof_enable ()
 Enable the start of frame interrupt. More...
 
void sof_disable ()
 Disable the start of frame interrupt. More...
 
bool endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback< void()> callback=nullptr)
 Add an endpoint. More...
 
template<typename T >
bool endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, void(T::*callback)())
 Add an endpoint. More...
 
void endpoint_remove (usb_ep_t endpoint)
 Remove an endpoint. More...
 
void endpoint_remove_all ()
 Remove all non-zero endpoints. More...
 
void endpoint_stall (usb_ep_t endpoint)
 Stall an endpoint. More...
 
void endpoint_unstall (usb_ep_t endpoint)
 Un-stall an endpoint. More...
 
uint32_t endpoint_max_packet_size (usb_ep_t endpoint)
 Get the current maximum size for this endpoint. More...
 
void endpoint_abort (usb_ep_t endpoint)
 Abort the current transfer on this endpoint. More...
 
bool read_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
 start a read on the given endpoint More...
 
uint32_t read_finish (usb_ep_t endpoint)
 Get the status of a read. More...
 
bool write_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size)
 Write a data to the given endpoint. More...
 
uint32_t write_finish (usb_ep_t endpoint)
 Get the status of a write. More...
 
virtual int close ()
 Close a file. More...
 
virtual ssize_t write (const void *buffer, size_t length)
 Write the contents of a buffer to a file. More...
 
virtual ssize_t read (void *buffer, size_t length)
 Read the contents of a file into a buffer. More...
 
virtual off_t seek (off_t offset, int whence)
 Move the file position to a given offset from from a given location. More...
 
virtual off_t tell ()
 Get the file position of the file. More...
 
virtual void rewind ()
 Rewind the file position to the beginning of the file. More...
 
virtual int isatty ()
 Check if the file in an interactive terminal device. More...
 
virtual int sync ()
 Flush any buffers associated with the file. More...
 
virtual off_t size ()
 Get the size of the file. More...
 
virtual int truncate (off_t length)
 Truncate or extend a file. More...
 
virtual int set_blocking (bool blocking)
 Set blocking or nonblocking mode of the file operation like read/write. More...
 
virtual bool is_blocking () const
 Check current blocking or nonblocking mode for file operations. More...
 
virtual int enable_input (bool enabled)
 Enable or disable input. More...
 
virtual int enable_output (bool enabled)
 Enable or disable output. More...
 
virtual short poll (short events) const
 Check for poll event flags You can use or ignore the input parameter. More...
 
bool writable () const
 Definition depends on the subclass implementing FileHandle. More...
 
bool readable () const
 Definition depends on the subclass implementing FileHandle. More...
 
virtual void sigio (Callback< void()> func)
 Register a callback on state change of the file. More...
 

Protected Member Functions

virtual void callback_state_change (DeviceState new_state)
 Called when USB changes state. More...
 
virtual void callback_request (const setup_packet_t *setup)
 Called by USBDevice on Endpoint0 request. More...
 
virtual void callback_request_xfer_done (const setup_packet_t *setup, bool aborted)
 Called by USBDevice on data stage completion. More...
 
virtual void callback_power (bool powered)
 Called by USBDevice layer on power state change. More...
 
virtual void callback_sof (int frame_number)
 Called by USBDevice layer on each new USB frame. More...
 
virtual void callback_reset ()
 Called by USBDevice layer on bus reset. More...
 
void complete_request (RequestResult result, uint8_t *data=NULL, uint32_t size=0)
 Called to complete the setup stage of a callback request. More...
 
void complete_request_xfer_done (bool success)
 Called to complete the data stage of a callback request. More...
 
void complete_set_configuration (bool success)
 Called to complete a set configuration command. More...
 
void complete_set_interface (bool success)
 Called to complete a set interface command. More...
 
uint8_t * find_descriptor (uint8_t descriptor_type, uint8_t index=0)
 Find a descriptor type inside the configuration descriptor. More...
 
const usb_ep_table_tendpoint_table ()
 Get the endpoint table of this device. More...
 
virtual void start_process ()
 Callback called to indicate the USB processing needs to be done. More...
 
virtual void lock ()
 Acquire exclusive access to this instance USBDevice. More...
 
virtual void unlock ()
 Release exclusive access to this instance USBDevice. More...
 
virtual void assert_locked ()
 Assert that the current thread of execution holds the lock. More...
 
virtual void lock ()
 Acquire exclusive access to this object. More...
 
virtual void unlock ()
 Release exclusive access to this object. More...
 

Detailed Description

USBMouseKeyboard example.

#include "mbed.h"
#include "USBMouseKeyboard.h"
USBMouseKeyboard key_mouse;
int main(void)
{
while(1)
{
key_mouse.move(20, 0);
key_mouse.printf("Hello From MBED\r\n");
ThisThread::sleep_for(1000);
}
}
#include "mbed.h"
#include "USBMouseKeyboard.h"
USBMouseKeyboard key_mouse(ABS_MOUSE);
int main(void)
{
while(1)
{
key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
key_mouse.printf("Hello from MBED\r\n");
ThisThread::sleep_for(1000);
}
}
Note
Synchronization level: Thread safe

Definition at line 78 of file USBMouseKeyboard.h.

Constructor & Destructor Documentation

USBMouseKeyboard ( bool  connect_blocking = true,
MOUSE_TYPE  mouse_type = REL_MOUSE,
uint16_t  vendor_id = 0x0021,
uint16_t  product_id = 0x0011,
uint16_t  product_release = 0x0001 
)

Basic constructor.

Construct this object optionally connecting and blocking until it is ready.

Note
Do not use this constructor in derived classes.
Parameters
connect_blockingtrue to perform a blocking connect, false to start in a disconnected state
mouse_typeMouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
vendor_idYour vendor_id (default: 0x1234)
product_idYour product_id (default: 0x0001)
product_releaseYour preoduct_release (default: 0x0001)
USBMouseKeyboard ( USBPhy phy,
MOUSE_TYPE  mouse_type = REL_MOUSE,
uint16_t  vendor_id = 0x0021,
uint16_t  product_id = 0x0011,
uint16_t  product_release = 0x0001 
)

Fully featured constructor.

Construct this object with the supplied USBPhy and parameters. The user this object is responsible for calling connect() or init().

Note
Derived classes must use this constructor and call init() or connect() themselves. Derived classes should also call deinit() in their destructor. This ensures that no interrupts can occur when the object is partially constructed or destroyed.
Parameters
phyUSB phy to use
mouse_typeMouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
vendor_idYour vendor_id (default: 0x1234)
product_idYour product_id (default: 0x0001)
product_releaseYour preoduct_release (default: 0x0001)
virtual ~USBMouseKeyboard ( )
virtual

Destroy this object.

Any classes which inherit from this class must call deinit before this destructor runs.

Member Function Documentation

virtual int _putc ( int  c)
virtual

Send a character.

Parameters
ccharacter to be sent
Returns
true if there is no error, false otherwise

Implements Stream.

virtual void assert_locked ( )
protectedvirtualinherited

Assert that the current thread of execution holds the lock.

virtual void callback_power ( bool  powered)
protectedvirtualinherited

Called by USBDevice layer on power state change.

Parameters
poweredtrue if device is powered, false otherwise

Warning: Called in ISR context

Definition at line 342 of file USBDevice.h.

virtual void callback_request ( const setup_packet_t setup)
protectedvirtualinherited

Called by USBDevice on Endpoint0 request.

This is used to handle extensions to standard requests and class specific requests. The function complete_request must be always be called in response to this callback.

Warning: Called in ISR context

Implements USBDevice.

virtual void callback_request_xfer_done ( const setup_packet_t setup,
bool  aborted 
)
protectedvirtualinherited

Called by USBDevice on data stage completion.

The function complete_request_xfer_done must be always be called in response to this callback.

Parameters
setupSetup packet of the current request
abortedfalse if the operation was aborted, true otherwise

Warning: Called in ISR context

Implements USBDevice.

virtual void callback_reset ( )
protectedvirtualinherited

Called by USBDevice layer on bus reset.

complete_reset must be called after the device is fully reset.

Warning: Called in ISR context

Reimplemented in USBCDC_ECM, USBCDC, and USBTester.

Definition at line 370 of file USBDevice.h.

virtual void callback_sof ( int  frame_number)
protectedvirtualinherited

Called by USBDevice layer on each new USB frame.

Callbacks are enabled and disabled by calling sof_enable and sof_disable.

Parameters
frame_numberThe current frame number

Warning: Called in ISR context

Definition at line 357 of file USBDevice.h.

virtual void callback_state_change ( DeviceState  new_state)
protectedvirtualinherited

Called when USB changes state.

Parameters
new_stateThe new state of the USBDevice

Warning: Called in ISR context

Implements USBDevice.

bool click ( uint8_t  button)

Click.

Parameters
buttonstate of the buttons ( ex: clic(MOUSE_LEFT))
Returns
true if there is no error, false otherwise
virtual int close ( )
virtualinherited

Close a file.

Returns
0 on success, negative error code on failure

Implements FileHandle.

void complete_request ( RequestResult  result,
uint8_t *  data = NULL,
uint32_t  size = 0 
)
protectedinherited

Called to complete the setup stage of a callback request.

Possible options that can be passed as a result are:

  • Receive - Start the data OUT phase of this control transfer
  • Send - Start the data IN phase of this control transfer
  • Success - Operation was a success so start the status phase
  • Failure - Operation failed or is unsupported so send a stall
  • PassThrough - Pass on the request for standard processing
Parameters
resultThe result of the setup phase.
dataBuffer to send or receive if the result is Send or Receive
sizeSize to transfer if the result is Send or Receive
void complete_request_xfer_done ( bool  success)
protectedinherited

Called to complete the data stage of a callback request.

Parameters
successtrue if the operation was successful, false otherwise
void complete_set_configuration ( bool  success)
protectedinherited

Called to complete a set configuration command.

Parameters
successtrue if the configuration was set, false otherwise
void complete_set_interface ( bool  success)
protectedinherited

Called to complete a set interface command.

Parameters
successtrue if the interface was set, false otherwise
bool configured ( )
inherited

Check if the device is configured.

Returns
true if configured, false otherwise
void connect ( )
inherited

Connect a device This method can also be used to resume USB operation when USB power is detected after it was suspended via USBDevice::deinit.

void deinit ( )
inherited

Power down this instance.

Disable interrupts and stop sending events. This method can be used for temporary power-saving; This call can allow USB to be temporarily disabled to permit power saving. However, it is up to the user to make sure all the transfers have concluded (for example when USB power is lost). USBDevice::connect can be used to resume USB operation.

void disconnect ( )
inherited

Disconnect a device.

bool doubleClick ( )

Double click (MOUSE_LEFT)

Returns
true if there is no error, false otherwise
virtual int enable_input ( bool  enabled)
virtualinherited

Enable or disable input.

Control enabling of device for input. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow input to be temporarily disabled to permit power saving without losing device state.

Parameters
enabledtrue to enable input, false to disable.
Returns
0 on success
Negative error code on failure

Reimplemented in BufferedSerial, and UnbufferedSerial.

Definition at line 192 of file FileHandle.h.

virtual int enable_output ( bool  enabled)
virtualinherited

Enable or disable output.

Control enabling of device for output. This is primarily intended for temporary power-saving; the overall ability of the device to operate for input and/or output may be fixed at creation time, but this call can allow output to be temporarily disabled to permit power saving without losing device state.

Parameters
enabledtrue to enable output, false to disable.
Returns
0 on success
Negative error code on failure

Reimplemented in BufferedSerial, and UnbufferedSerial.

Definition at line 210 of file FileHandle.h.

void endpoint_abort ( usb_ep_t  endpoint)
inherited

Abort the current transfer on this endpoint.

Parameters
endpointendpoint with transfer to abort
Note
This endpoint must already have been setup with endpoint_add
bool endpoint_add ( usb_ep_t  endpoint,
uint32_t  max_packet,
usb_ep_type_t  type,
mbed::Callback< void()>  callback = nullptr 
)
inherited

Add an endpoint.

Parameters
endpointEndpoint to enable
max_packetMaximum size of a packet which can be sent or received on this endpoint
typeEndpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO
callbackMethod pointer to be called when a packet is transferred
Returns
true if successful, false otherwise
bool endpoint_add ( usb_ep_t  endpoint,
uint32_t  max_packet,
usb_ep_type_t  type,
void(T::*)()  callback 
)
inherited

Add an endpoint.

Parameters
endpointEndpoint to enable
max_packetMaximum size of a packet which can be sent or received on this endpoint
typeEndpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO
callbackMethod pointer to be called when a packet is transferred
Returns
true if successful, false otherwise

Definition at line 162 of file USBDevice.h.

uint32_t endpoint_max_packet_size ( usb_ep_t  endpoint)
inherited

Get the current maximum size for this endpoint.

Return the currently configured maximum packet size, wMaxPacketSize, for this endpoint.

Note
This endpoint must already have been setup with endpoint_add
void endpoint_remove ( usb_ep_t  endpoint)
inherited

Remove an endpoint.

Parameters
endpointEndpoint to disable
Note
This endpoint must already have been setup with endpoint_add
void endpoint_remove_all ( )
inherited

Remove all non-zero endpoints.

void endpoint_stall ( usb_ep_t  endpoint)
inherited

Stall an endpoint.

If there is an ongoing transfer on this endpoint then it will be aborted.

Parameters
endpointEndpoint to stall
Note
You cannot stall endpoint 0 with this function
This endpoint must already have been setup with endpoint_add
const usb_ep_table_t* endpoint_table ( )
protectedinherited

Get the endpoint table of this device.

Returns
Endpoint table of the USBPhy attached to this USBDevice
void endpoint_unstall ( usb_ep_t  endpoint)
inherited

Un-stall an endpoint.

Un-stalling an endpoint resets data toggle back to DATA0. Additionally, if there is an ongoing transfer on this endpoint it will be aborted.

Parameters
endpointEndpoint to un-stall
Note
This endpoint must already have been setup with endpoint_add
uint8_t* find_descriptor ( uint8_t  descriptor_type,
uint8_t  index = 0 
)
protectedinherited

Find a descriptor type inside the configuration descriptor.

Parameters
descriptor_typeType of descriptor to find
indexConfiguration descriptor index ( 0 if only one configuration present )
Returns
A descriptor of the given type or NULL if none were found
void init ( )
inherited

Initialize this instance.

This function must be called before calling any other functions of this class, unless specifically

virtual bool is_blocking ( ) const
virtualinherited

Check current blocking or nonblocking mode for file operations.

Returns
true for blocking mode, false for nonblocking mode.

Reimplemented in BufferedSerial.

Definition at line 174 of file FileHandle.h.

virtual int isatty ( )
virtualinherited

Check if the file in an interactive terminal device.

Returns
True if the file is a terminal
False if the file is not a terminal
Negative error code on failure

Reimplemented from FileHandle.

bool key_code ( uint8_t  key,
uint8_t  modifier = 0 
)

To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key.

//To send CTRL + s (save)
keyboard.keyCode('s', KEY_CTRL);
Parameters
modifierbit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
keycharacter to send
Returns
true if there is no error, false otherwise
virtual void lock ( void  )
protectedvirtualinherited

Acquire exclusive access to this object.

Definition at line 84 of file Stream.h.

virtual void lock ( )
protectedvirtualinherited

Acquire exclusive access to this instance USBDevice.

uint8_t lock_status ( )

Read status of lock keys.

Useful to switch-on/off LEDs according to key pressed. Only the first three bits of the result is important:

  • First bit: NUM_LOCK
  • Second bit: CAPS_LOCK
  • Third bit: SCROLL_LOCK
Returns
status of lock keys
bool media_control ( MEDIA_KEY  key)

Control media keys.

Parameters
keymedia key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
Returns
true if there is no error, false otherwise
bool move ( int16_t  x,
int16_t  y 
)

Move the cursor to (x, y)

Parameters
xx-axis position
yy-axis position
Returns
true if there is no error, false otherwise
virtual short poll ( short  events) const
virtualinherited

Check for poll event flags You can use or ignore the input parameter.

You can return all events or check just the events listed in events. Call is nonblocking - returns instantaneous state of events. Whenever an event occurs, the derived class should call the sigio() callback).

Parameters
eventsbitmask of poll events we're interested in - POLLIN/POLLOUT etc.
Returns
bitmask of poll events that have occurred.

Reimplemented in UnbufferedSerial, and BufferedSerial.

Definition at line 225 of file FileHandle.h.

bool press ( uint8_t  button)

Press one or several buttons.

Parameters
buttonbutton state (ex: press(MOUSE_LEFT))
Returns
true if there is no error, false otherwise
virtual ssize_t read ( void *  buffer,
size_t  size 
)
virtualinherited

Read the contents of a file into a buffer.

Devices acting as FileHandles should follow POSIX semantics:

  • if no data is available, and nonblocking set, return -EAGAIN
  • if no data is available, and blocking set, wait until some data is available
  • If any data is available, call returns immediately
Parameters
bufferThe buffer to read in to
sizeThe number of bytes to read
Returns
The number of bytes read, 0 at end of file, negative error on failure

Implements FileHandle.

bool read ( HID_REPORT report)
inherited

Read a report: blocking.

Parameters
reportpointer to the report to fill
Returns
true if successful
uint32_t read_finish ( usb_ep_t  endpoint)
inherited

Get the status of a read.

Parameters
endpointendpoint to get the status of
Returns
number of bytes read by this endpoint
bool read_nb ( HID_REPORT report)
inherited

Read a report: non blocking.

Parameters
reportpointer to the report to fill
Returns
true if successful
bool read_start ( usb_ep_t  endpoint,
uint8_t *  buffer,
uint32_t  size 
)
inherited

start a read on the given endpoint

Start a read on the given endpoint. The data buffer must remain unchanged until the transfer either completes or is aborted.

Parameters
endpointendpoint to read data from
bufferbuffer to fill with read data
sizeThe size of data to read. This must be greater than or equal to the max packet size for this endpoint
Returns
true if the read was completed, otherwise false
Note
This endpoint must already have been setup with endpoint_add
bool readable ( ) const
inherited

Definition depends on the subclass implementing FileHandle.

For example, if the FileHandle is of type Stream, readable() could return true when there is something available to read.

Returns
true when there is something available to read.

Definition at line 248 of file FileHandle.h.

bool ready ( )
inherited

Check if this class is ready.

Returns
true if the device is in the configured state
bool release ( uint8_t  button)

Release one or several buttons.

Parameters
buttonbutton state (ex: release(MOUSE_LEFT))
Returns
true if there is no error, false otherwise
virtual void rewind ( )
virtualinherited

Rewind the file position to the beginning of the file.

Note
This is equivalent to seek(0, SEEK_SET)

Reimplemented from FileHandle.

bool scroll ( int8_t  z)

Scrolling.

Parameters
zvalue of the wheel (>0 to go down, <0 to go up)
Returns
true if there is no error, false otherwise
virtual off_t seek ( off_t  offset,
int  whence 
)
virtualinherited

Move the file position to a given offset from from a given location.

Parameters
offsetThe offset from whence to move to
whenceThe start of where to seek SEEK_SET to start from beginning of file, SEEK_CUR to start from current position in file, SEEK_END to start from end of file
Returns
The new offset of the file, negative error code on failure

Implements FileHandle.

bool send ( const HID_REPORT report)
inherited

Send a Report.

warning: blocking

Parameters
reportReport which will be sent (a report is defined by all data and the length)
Returns
true if successful
bool send_nb ( const HID_REPORT report)
inherited

Send a Report.

warning: non blocking

Parameters
reportReport which will be sent (a report is defined by all data and the length)
Returns
true if successful
virtual int set_blocking ( bool  blocking)
virtualinherited

Set blocking or nonblocking mode of the file operation like read/write.

Definition depends on the subclass implementing FileHandle. The default is blocking.

Parameters
blockingtrue for blocking mode, false for nonblocking mode.
Returns
0 on success
Negative error code on failure

Reimplemented in BufferedSerial.

Definition at line 165 of file FileHandle.h.

virtual void sigio ( Callback< void()>  func)
virtualinherited

Register a callback on state change of the file.

The specified callback will be called on state changes such as when the file can be written to or read from.

The callback may be called in an interrupt context and should not perform expensive operations.

Note! This is not intended as an attach-like asynchronous API, but rather as a building block for constructing such functionality.

The exact timing of when the registered function is called is not guaranteed and is susceptible to change. It should be used as a cue to make read/write/poll calls to find the current state.

Parameters
funcFunction to call on state change

Reimplemented in BufferedSerial.

Definition at line 270 of file FileHandle.h.

virtual off_t size ( )
virtualinherited

Get the size of the file.

Returns
Size of the file in bytes

Reimplemented from FileHandle.

void sof_disable ( )
inherited

Disable the start of frame interrupt.

Stop calling USBDevice::callback_sof.

void sof_enable ( )
inherited

Enable the start of frame interrupt.

Call USBDevice::callback_sof on every frame.

virtual void start_process ( )
protectedvirtualinherited

Callback called to indicate the USB processing needs to be done.

Implements USBPhyEvents.

virtual int sync ( )
virtualinherited

Flush any buffers associated with the file.

Returns
0 on success, negative error code on failure

Reimplemented from FileHandle.

virtual off_t tell ( )
virtualinherited

Get the file position of the file.

Note
This is equivalent to seek(0, SEEK_CUR)
Returns
The current offset in the file, negative error code on failure

Reimplemented from FileHandle.

virtual int truncate ( off_t  length)
virtualinherited

Truncate or extend a file.

The file's length is set to the specified value. The seek pointer is not changed. If the file is extended, the extended area appears as if it were zero-filled.

Parameters
lengthThe requested new length for the file
Returns
Zero on success, negative error code on failure

Reimplemented in File, and TestFile< FILE_SIZE >.

Definition at line 151 of file FileHandle.h.

virtual void unlock ( void  )
protectedvirtualinherited

Release exclusive access to this object.

Definition at line 91 of file Stream.h.

virtual void unlock ( )
protectedvirtualinherited

Release exclusive access to this instance USBDevice.

bool update ( int16_t  x,
int16_t  y,
uint8_t  buttons,
int8_t  z 
)

Write a state of the mouse.

Parameters
xx-axis position
yy-axis position
buttonsbuttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
zwheel state (>0 to scroll down, <0 to scroll up)
Returns
true if there is no error, false otherwise
void wait_ready ( )
inherited

Block until this HID device is in the configured state.

bool writable ( ) const
inherited

Definition depends on the subclass implementing FileHandle.

For example, if the FileHandle is of type Stream, writable() could return true when there is ample buffer space available for write() calls.

Returns
true if the FileHandle is writable.

Definition at line 237 of file FileHandle.h.

virtual ssize_t write ( const void *  buffer,
size_t  size 
)
virtualinherited

Write the contents of a buffer to a file.

Devices acting as FileHandles should follow POSIX semantics:

  • if blocking, block until all data is written
  • if no data can be written, and nonblocking set, return -EAGAIN
  • if some data can be written, and nonblocking set, write partial

    Parameters
    bufferThe buffer to write from
    sizeThe number of bytes to write
    Returns
    The number of bytes written, negative error on failure

Implements FileHandle.

uint32_t write_finish ( usb_ep_t  endpoint)
inherited

Get the status of a write.

Parameters
endpointendpoint to get the status of
Returns
number of bytes sent by this endpoint
bool write_start ( usb_ep_t  endpoint,
uint8_t *  buffer,
uint32_t  size 
)
inherited

Write a data to the given endpoint.

Write data to an endpoint. The data sent must remain unchanged until the transfer either completes or is aborted.

Parameters
endpointendpoint to write data to
bufferdata to write
sizethe size of data to send. This must be less than or equal to the max packet size of this endpoint
Note
This endpoint must already have been setup with endpoint_add
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.