USBKeyboard example. More...
#include <USBKeyboard.h>
Public Member Functions | |
USBKeyboard (bool connect_blocking=true, uint16_t vendor_id=0x1235, uint16_t product_id=0x0050, uint16_t product_release=0x0001) | |
Basic constructor. More... | |
USBKeyboard (USBPhy *phy, uint16_t vendor_id=0x1235, uint16_t product_id=0x0050, uint16_t product_release=0x0001) | |
Fully featured constructor. More... | |
virtual | ~USBKeyboard () |
Destroy this object. 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. 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, ep_cb_t callback=NULL) |
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) |
Unstall 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 | truncate (off_t length) |
Truncate or extend a file. More... | |
virtual off_t | lseek (off_t offset, int whence) |
Move the file position to a given offset from a given location. More... | |
virtual int | fsync () |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk. More... | |
virtual off_t | flen () |
Find the length of the 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_t * | endpoint_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 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 void | lock () |
Acquire exclusive access to this object. More... | |
virtual void | unlock () |
Release exclusive access to this object. More... | |
USBKeyboard example.
Definition at line 98 of file USBKeyboard.h.
USBKeyboard | ( | bool | connect_blocking = true , |
uint16_t | vendor_id = 0x1235 , |
||
uint16_t | product_id = 0x0050 , |
||
uint16_t | product_release = 0x0001 |
||
) |
Basic constructor.
Construct this object optionally connecting and blocking until it is ready.
connect_blocking | true to perform a blocking connect, false to start in a disconnected state |
vendor_id | Your vendor_id |
product_id | Your product_id |
product_release | Your product_release |
USBKeyboard | ( | USBPhy * | phy, |
uint16_t | vendor_id = 0x1235 , |
||
uint16_t | product_id = 0x0050 , |
||
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().
phy | USB phy to use |
vendor_id | Your vendor_id |
product_id | Your product_id |
product_release | Your product_release |
|
virtual |
Destroy this object.
Any classes which inherit from this class must call deinit before this destructor runs.
|
virtual |
Send a character.
c | character to be sent |
Implements Stream.
|
protectedvirtualinherited |
Assert that the current thread of execution holds the lock.
|
protectedvirtualinherited |
Called by USBDevice layer on power state change.
powered | true if device is powered, false otherwise |
Warning: Called in ISR context
Definition at line 341 of file USBDevice.h.
|
protectedvirtualinherited |
|
protectedvirtualinherited |
Called by USBDevice on data stage completion.
The function complete_request_xfer_done must be always be called in response to this callback.
setup | Setup packet of the current request |
aborted | false if the operation was aborted, true otherwise |
Warning: Called in ISR context
Implements USBDevice.
|
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 369 of file USBDevice.h.
|
protectedvirtualinherited |
Called by USBDevice layer on each new USB frame.
Callbacks are enabled and disabled by calling sof_enable and sof_disable.
frame_number | The current frame number |
Warning: Called in ISR context
Definition at line 356 of file USBDevice.h.
|
protectedvirtualinherited |
|
protectedvirtualinherited |
|
protectedinherited |
Called to complete the setup stage of a callback request.
Possible options that can be passed as a result are:
result | The result of the setup phase. |
data | Buffer to send or receive if the result is Send or Receive |
size | Size to transfer if the result is Send or Receive |
|
protectedinherited |
Called to complete the data stage of a callback request.
success | true if the operation was successful, false otherwise |
|
protectedinherited |
Called to complete a set configuration command.
success | true if the configuration was set, false otherwise |
|
protectedinherited |
Called to complete a set interface command.
success | true if the interface was set, false otherwise |
|
inherited |
Check if the device is configured.
|
inherited |
Connect a device.
|
inherited |
Power down this instance.
Disable interrupts and stop sending events.
|
inherited |
Disconnect a device.
|
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.
enabled | true to enable input, false to disable. |
Reimplemented in UARTSerial.
Definition at line 236 of file FileHandle.h.
|
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.
enabled | true to enable output, false to disable. |
Reimplemented in UARTSerial.
Definition at line 254 of file FileHandle.h.
|
inherited |
Abort the current transfer on this endpoint.
endpoint | endpoint with transfer to abort |
|
inherited |
Add an endpoint.
endpoint | Endpoint to enable |
max_packet | Maximum size of a packet which can be sent or received on this endpoint |
type | Endpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO |
callback | Method pointer to be called when a packet is transferred |
|
inherited |
Add an endpoint.
endpoint | Endpoint to enable |
max_packet | Maximum size of a packet which can be sent or received on this endpoint |
type | Endpoint type - USB_EP_TYPE_BULK, USB_EP_TYPE_INT or USB_EP_TYPE_ISO |
callback | Method pointer to be called when a packet is transferred |
Definition at line 161 of file USBDevice.h.
|
inherited |
Get the current maximum size for this endpoint.
Return the currently configured maximum packet size, wMaxPacketSize, for this endpoint.
|
inherited |
Remove an endpoint.
endpoint | Endpoint to disable |
|
inherited |
Remove all non-zero endpoints.
|
inherited |
Stall an endpoint.
If there is an ongoing transfer on this endpoint then it will be aborted.
endpoint | Endpoint to stall |
|
protectedinherited |
|
inherited |
Unstall an endpoint.
Unstalling an endpoint resets data toggle back to DATA0. Additionally, if there is an ongoing transfer on this endpoint it will be aborted.
endpoint | Endpoint to unstall |
|
protectedinherited |
Find a descriptor type inside the configuration descriptor.
descriptor_type | Type of descriptor to find |
index | Configuration descriptor index ( 0 if only one configuration present ) |
|
virtualinherited |
Find the length of the file.
Definition at line 195 of file FileHandle.h.
|
virtualinherited |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk.
Definition at line 183 of file FileHandle.h.
|
inherited |
Initialize this instance.
This function must be called before calling any other functions of this class, unless specifically
|
virtualinherited |
Check current blocking or nonblocking mode for file operations.
Reimplemented in UARTSerial.
Definition at line 218 of file FileHandle.h.
|
protectedvirtualinherited |
Check if the file in an interactive terminal device.
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.
modifier | bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0) |
key | character to send |
|
protectedvirtualinherited |
|
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:
|
virtualinherited |
Move the file position to a given offset from a given location.
offset | The offset from whence to move to |
whence | SEEK_SET for the start of the file, SEEK_CUR for the current file position, or SEEK_END for the end of the file. |
Definition at line 169 of file FileHandle.h.
bool media_control | ( | MEDIA_KEY | key | ) |
Control media keys.
key | media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN) |
|
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).
events | bitmask of poll events we're interested in - POLLIN/POLLOUT etc. |
Reimplemented in UARTSerial.
Definition at line 269 of file FileHandle.h.
|
protectedvirtualinherited |
Read the contents of a file into a buffer.
Devices acting as FileHandles should follow POSIX semantics:
buffer | The buffer to read in to |
size | The number of bytes to read |
Implements FileHandle.
|
inherited |
Read a report: blocking.
report | pointer to the report to fill |
|
inherited |
Get the status of a read.
endpoint | endpoint to get the status of |
|
inherited |
Read a report: non blocking.
report | pointer to the report to fill |
|
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.
endpoint | endpoint to read data from |
buffer | buffer to fill with read data |
size | The size of data to read. This must be greater than or equal to the max packet size for this endpoint |
|
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.
Definition at line 292 of file FileHandle.h.
|
inherited |
Check if this class is ready.
|
protectedvirtualinherited |
Rewind the file position to the beginning of the file.
Reimplemented from FileHandle.
|
protectedvirtualinherited |
Move the file position to a given offset from from a given location.
offset | The offset from whence to move to |
whence | The 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 |
Implements FileHandle.
|
inherited |
Send a Report.
warning: blocking
report | Report which will be sent (a report is defined by all data and the length) |
|
inherited |
Send a Report.
warning: non blocking
report | Report which will be sent (a report is defined by all data and the length) |
|
virtualinherited |
Set blocking or nonblocking mode of the file operation like read/write.
Definition depends on the subclass implementing FileHandle. The default is blocking.
blocking | true for blocking mode, false for nonblocking mode. |
Reimplemented in UARTSerial.
Definition at line 209 of file FileHandle.h.
|
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.
func | Function to call on state change |
Reimplemented in UARTSerial.
Definition at line 314 of file FileHandle.h.
|
protectedvirtualinherited |
|
inherited |
Disable the start of frame interrupt.
Stop calling USBDevice::callback_sof.
|
inherited |
Enable the start of frame interrupt.
Call USBDevice::callback_sof on every frame.
|
protectedvirtualinherited |
Callback called to indicate the USB processing needs to be done.
Implements USBPhyEvents.
|
protectedvirtualinherited |
Flush any buffers associated with the file.
Reimplemented from FileHandle.
|
protectedvirtualinherited |
Get the file position of the file.
Reimplemented from FileHandle.
|
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.
length | The requested new length for the file |
Reimplemented in File, and TestFile< FILE_SIZE >.
Definition at line 151 of file FileHandle.h.
|
protectedvirtualinherited |
|
protectedvirtualinherited |
Release exclusive access to this instance USBDevice.
|
inherited |
Block until this HID device is in the configured state.
|
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.
Definition at line 281 of file FileHandle.h.
|
protectedvirtualinherited |
Write the contents of a buffer to a file.
Devices acting as FileHandles should follow POSIX semantics:
if some data can be written, and nonblocking set, write partial
buffer | The buffer to write from |
size | The number of bytes to write |
Implements FileHandle.
|
inherited |
Get the status of a write.
endpoint | endpoint to get the status of |
|
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.
endpoint | endpoint to write data to |
buffer | data to write |
size | the size of data to send. This must be less than or equal to the max packet size of this endpoint |