Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
USBSerial Class Reference
[USBSerial class]
#include <USBSerial.h>
Inherits USBCDC, and mbed::Stream.
Public Member Functions | |
USBSerial (bool connect_blocking=true, uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001) | |
Basic constructor. | |
USBSerial (USBPhy *phy, uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001) | |
Fully featured constructor. | |
virtual | ~USBSerial () |
Destroy this object. | |
virtual int | _putc (int c) |
Send a character. | |
virtual int | _getc () |
Read a character: blocking. | |
uint8_t | available () |
Check the number of bytes available. | |
bool | connected () |
Check if the terminal is connected. | |
int | readable () |
Determine if there is a character available to read. | |
int | writeable () |
Determine if there is space available to write a character. | |
template<typename T > | |
void | attach (T *tptr, void(T::*mptr)(void)) |
Attach a member function to call when a packet is received. | |
void | attach (void(*fptr)(void)) |
Attach a callback called when a packet is received. | |
void | attach (mbed::Callback< void()> &cb) |
Attach a Callback called when a packet is received. | |
void | attach (void(*fptr)(int baud, int bits, int parity, int stop)) |
Attach a callback to call when serial's settings are changed. | |
bool | ready () |
Check if this class is ready. | |
void | wait_ready () |
Block until the terminal is connected. | |
void | send_nb (uint8_t *buffer, uint32_t size, uint32_t *actual, bool now=true) |
Send what there is room for. | |
void | receive_nb (uint8_t *buffer, uint32_t size, uint32_t *actual) |
Read from the receive buffer. | |
void | init () |
Initialize this instance. | |
void | deinit () |
Power down this instance. | |
bool | configured () |
Check if the device is configured. | |
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. | |
void | disconnect () |
Disconnect a device. | |
void | sof_enable () |
Enable the start of frame interrupt. | |
void | sof_disable () |
Disable the start of frame interrupt. | |
bool | endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type, mbed::Callback< void()> callback=NULL) |
Add an endpoint. | |
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. | |
void | endpoint_remove (usb_ep_t endpoint) |
Remove an endpoint. | |
void | endpoint_remove_all () |
Remove all non-zero endpoints. | |
void | endpoint_stall (usb_ep_t endpoint) |
Stall an endpoint. | |
void | endpoint_unstall (usb_ep_t endpoint) |
Un-stall an endpoint. | |
uint32_t | endpoint_max_packet_size (usb_ep_t endpoint) |
Get the current maximum size for this endpoint. | |
void | endpoint_abort (usb_ep_t endpoint) |
Abort the current transfer on this endpoint. | |
bool | read_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
start a read on the given endpoint | |
uint32_t | read_finish (usb_ep_t endpoint) |
Get the status of a read. | |
bool | write_start (usb_ep_t endpoint, uint8_t *buffer, uint32_t size) |
Write a data to the given endpoint. | |
uint32_t | write_finish (usb_ep_t endpoint) |
Get the status of a write. | |
virtual int | close () |
Close a file. | |
virtual ssize_t | write (const void *buffer, size_t length) |
Write the contents of a buffer to a file. | |
virtual ssize_t | read (void *buffer, size_t length) |
Read the contents of a file into a buffer. | |
virtual off_t | seek (off_t offset, int whence) |
Move the file position to a given offset from from a given location. | |
virtual off_t | tell () |
Get the file position of the file. | |
virtual void | rewind () |
Rewind the file position to the beginning of the file. | |
virtual int | isatty () |
Check if the file in an interactive terminal device. | |
virtual int | sync () |
Flush any buffers associated with the file. | |
virtual off_t | size () |
Get the size of the file. | |
virtual int | truncate (off_t length) |
Truncate or extend a file. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::seek") virtual off_t lseek(off_t offset | |
Move the file position to a given offset from a given location. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::sync") virtual int fsync() | |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk. | |
MBED_DEPRECATED_SINCE ("mbed-os-5.4","Replaced by FileHandle::size") virtual off_t flen() | |
Find the length of the file. | |
virtual int | set_blocking (bool blocking) |
Set blocking or nonblocking mode of the file operation like read/write. | |
virtual bool | is_blocking () const |
Check current blocking or nonblocking mode for file operations. | |
virtual int | enable_input (bool enabled) |
Enable or disable input. | |
virtual int | enable_output (bool enabled) |
Enable or disable output. | |
virtual short | poll (short events) const |
Check for poll event flags You can use or ignore the input parameter. | |
bool | writable () const |
Definition depends on the subclass implementing FileHandle. | |
bool | readable () const |
Definition depends on the subclass implementing FileHandle. | |
virtual void | sigio (Callback< void()> func) |
Register a callback on state change of the file. | |
Protected Member Functions | |
virtual void | callback_power (bool powered) |
Called by USBDevice layer on power state change. | |
virtual void | callback_sof (int frame_number) |
Called by USBDevice layer on each new USB frame. | |
void | complete_request (RequestResult result, uint8_t *data=NULL, uint32_t size=0) |
Called to complete the setup stage of a callback request. | |
void | complete_request_xfer_done (bool success) |
Called to complete the data stage of a callback request. | |
void | complete_set_configuration (bool success) |
Called to complete a set configuration command. | |
void | complete_set_interface (bool success) |
Called to complete a set interface command. | |
uint8_t * | find_descriptor (uint8_t descriptor_type, uint8_t index=0) |
Find a descriptor type inside the configuration descriptor. | |
const usb_ep_table_t * | endpoint_table () |
Get the endpoint table of this device. | |
virtual void | start_process () |
Callback called to indicate the USB processing needs to be done. | |
virtual void | lock () |
Acquire exclusive access to this instance USBDevice. | |
virtual void | unlock () |
Release exclusive access to this instance USBDevice. | |
virtual void | assert_locked () |
Assert that the current thread of execution holds the lock. | |
virtual void | lock () |
Acquire exclusive access to this object. | |
virtual void | unlock () |
Release exclusive access to this object. | |
MBED_DEPRECATED ("Invalid copy construction of a NonCopyable resource.") NonCopyable(const NonCopyable &) | |
NonCopyable copy constructor. | |
MBED_DEPRECATED ("Invalid copy assignment of a NonCopyable resource.") NonCopyable &operator | |
NonCopyable copy assignment operator. |
Detailed Description
USBSerial example.
#include "mbed.h" #include "USBSerial.h" //Virtual serial port over USB USBSerial serial; int main(void) { while(1) { serial.printf("I am a virtual serial port\n"); wait(1); } }
Definition at line 51 of file USBSerial.h.
Constructor & Destructor Documentation
USBSerial | ( | bool | connect_blocking = true , |
uint16_t | vendor_id = 0x1f00 , |
||
uint16_t | product_id = 0x2012 , |
||
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_blocking true to perform a blocking connect, false to start in a disconnected state vendor_id Your vendor_id (default: 0x1f00) product_id Your product_id (default: 0x2012) product_release Your product_release (default: 0x0001)
Definition at line 23 of file USBSerial.cpp.
USBSerial | ( | USBPhy * | phy, |
uint16_t | vendor_id = 0x1f00 , |
||
uint16_t | product_id = 0x2012 , |
||
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:
-
phy USB phy to use vendor_id Your vendor_id (default: 0x1f00) product_id Your product_id (default: 0x2012) product_release Your product_release (default: 0x0001)
Definition at line 36 of file USBSerial.cpp.
~USBSerial | ( | ) | [virtual] |
Destroy this object.
Any classes which inherit from this class must call deinit before this destructor runs.
Definition at line 42 of file USBSerial.cpp.
Member Function Documentation
int _getc | ( | ) | [virtual] |
Read a character: blocking.
- Returns:
- character read
Implements Stream.
Definition at line 56 of file USBSerial.cpp.
int _putc | ( | int | c ) | [virtual] |
Send a character.
You can use puts, printf.
- Parameters:
-
c character to be sent
- Returns:
- true if there is no error, false otherwise
Implements Stream.
Definition at line 47 of file USBSerial.cpp.
void assert_locked | ( | ) | [protected, virtual, inherited] |
Assert that the current thread of execution holds the lock.
Definition at line 1737 of file USBDevice.cpp.
void attach | ( | void(*)(void) | fptr ) |
Attach a callback called when a packet is received.
- Parameters:
-
fptr function pointer
Definition at line 170 of file USBSerial.h.
void attach | ( | mbed::Callback< void()> & | cb ) |
Attach a Callback called when a packet is received.
- Parameters:
-
cb Callback to attach
Definition at line 186 of file USBSerial.h.
void attach | ( | void(*)(int baud, int bits, int parity, int stop) | fptr ) |
Attach a callback to call when serial's settings are changed.
- Parameters:
-
fptr function pointer
Definition at line 200 of file USBSerial.h.
void attach | ( | T * | tptr, |
void(T::*)(void) | mptr | ||
) |
Attach a member function to call when a packet is received.
- Parameters:
-
tptr pointer to the object to call the member function on mptr pointer to the member function to be called
Definition at line 154 of file USBSerial.h.
uint8_t available | ( | ) |
Check the number of bytes available.
- Returns:
- the number of bytes available
Definition at line 76 of file USBSerial.cpp.
virtual void callback_power | ( | bool | powered ) | [protected, virtual, inherited] |
Called by USBDevice layer on power state change.
- Parameters:
-
powered true if device is powered, false otherwise
Warning: Called in ISR context
Definition at line 342 of file USBDevice.h.
virtual void callback_sof | ( | int | frame_number ) | [protected, virtual, inherited] |
Called by USBDevice layer on each new USB frame.
Callbacks are enabled and disabled by calling sof_enable and sof_disable.
- Parameters:
-
frame_number The current frame number
Warning: Called in ISR context
Definition at line 357 of file USBDevice.h.
int close | ( | ) | [virtual, inherited] |
Close a file.
- Returns:
- 0 on success, negative error code on failure
Implements FileHandle.
Definition at line 87 of file Stream.cpp.
void complete_request | ( | RequestResult | result, |
uint8_t * | data = NULL , |
||
uint32_t | size = 0 |
||
) | [protected, inherited] |
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:
-
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
Definition at line 694 of file USBDevice.cpp.
void complete_request_xfer_done | ( | bool | success ) | [protected, inherited] |
Called to complete the data stage of a callback request.
- Parameters:
-
success true if the operation was successful, false otherwise
Definition at line 313 of file USBDevice.cpp.
void complete_set_configuration | ( | bool | success ) | [protected, inherited] |
Called to complete a set configuration command.
- Parameters:
-
success true if the configuration was set, false otherwise
Definition at line 386 of file USBDevice.cpp.
void complete_set_interface | ( | bool | success ) | [protected, inherited] |
Called to complete a set interface command.
- Parameters:
-
success true if the interface was set, false otherwise
Definition at line 466 of file USBDevice.cpp.
bool configured | ( | ) | [inherited] |
Check if the device is configured.
- Returns:
- true if configured, false otherwise
Definition at line 1043 of file USBDevice.cpp.
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.
Reimplemented in USBAudio, and USBMSD.
Definition at line 1054 of file USBDevice.cpp.
bool connected | ( | ) |
Check if the terminal is connected.
- Returns:
- connection status
Definition at line 89 of file USBSerial.cpp.
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.
Definition at line 1030 of file USBDevice.cpp.
void disconnect | ( | void | ) | [inherited] |
Disconnect a device.
Reimplemented in USBAudio, and USBMSD.
Definition at line 1070 of file USBDevice.cpp.
virtual int enable_input | ( | bool | enabled ) | [virtual, inherited] |
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:
-
enabled true to enable input, false to disable.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 236 of file FileHandle.h.
virtual int enable_output | ( | bool | enabled ) | [virtual, inherited] |
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:
-
enabled true to enable output, false to disable.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 254 of file FileHandle.h.
void endpoint_abort | ( | usb_ep_t | endpoint ) | [inherited] |
Abort the current transfer on this endpoint.
- Parameters:
-
endpoint endpoint with transfer to abort
- Note:
- This endpoint must already have been setup with endpoint_add
Definition at line 1396 of file USBDevice.cpp.
bool endpoint_add | ( | usb_ep_t | endpoint, |
uint32_t | max_packet, | ||
usb_ep_type_t | type, | ||
mbed::Callback< void()> | callback = NULL |
||
) | [inherited] |
Add an endpoint.
- Parameters:
-
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
- Returns:
- true if successful, false otherwise
Definition at line 1109 of file USBDevice.cpp.
bool endpoint_add | ( | usb_ep_t | endpoint, |
uint32_t | max_packet, | ||
usb_ep_type_t | type, | ||
void(T::*)() | callback | ||
) | [inherited] |
Add an endpoint.
- Parameters:
-
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
- 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
Definition at line 1380 of file USBDevice.cpp.
void endpoint_remove | ( | usb_ep_t | endpoint ) | [inherited] |
Remove an endpoint.
- Parameters:
-
endpoint Endpoint to disable
- Note:
- This endpoint must already have been setup with endpoint_add
Definition at line 1149 of file USBDevice.cpp.
void endpoint_remove_all | ( | ) | [inherited] |
Remove all non-zero endpoints.
Definition at line 1190 of file USBDevice.cpp.
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:
-
endpoint Endpoint to stall
- Note:
- You cannot stall endpoint 0 with this function
- This endpoint must already have been setup with endpoint_add
Definition at line 1204 of file USBDevice.cpp.
const usb_ep_table_t * endpoint_table | ( | ) | [protected, inherited] |
Get the endpoint table of this device.
Definition at line 1321 of file USBDevice.cpp.
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:
-
endpoint Endpoint to un-stall
- Note:
- This endpoint must already have been setup with endpoint_add
Definition at line 1241 of file USBDevice.cpp.
uint8_t * find_descriptor | ( | uint8_t | descriptor_type, |
uint8_t | index = 0 |
||
) | [protected, inherited] |
Find a descriptor type inside the configuration descriptor.
- Parameters:
-
descriptor_type Type of descriptor to find index Configuration descriptor index ( 0 if only one configuration present )
- Returns:
- A descriptor of the given type or NULL if none were found
Definition at line 1278 of file USBDevice.cpp.
void init | ( | ) | [inherited] |
Initialize this instance.
This function must be called before calling any other functions of this class, unless specifically
Definition at line 1017 of file USBDevice.cpp.
virtual bool is_blocking | ( | ) | const [virtual, inherited] |
Check current blocking or nonblocking mode for file operations.
- Returns:
- true for blocking mode, false for nonblocking mode.
Reimplemented in UARTSerial.
Definition at line 218 of file FileHandle.h.
int isatty | ( | ) | [virtual, inherited] |
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.
Definition at line 140 of file Stream.cpp.
void lock | ( | void | ) | [protected, virtual, inherited] |
Acquire exclusive access to this instance USBDevice.
Definition at line 1714 of file USBDevice.cpp.
virtual void lock | ( | void | ) | [protected, virtual, inherited] |
MBED_DEPRECATED | ( | "Invalid copy assignment of a NonCopyable< FileBase > resource." | ) | [protected, inherited] |
NonCopyable copy assignment operator.
A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.
If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.
MBED_DEPRECATED | ( | "Invalid copy construction of a NonCopyable< FileBase > resource." | ) | const [protected, inherited] |
NonCopyable copy constructor.
A compile time warning is issued when this function is used, and a runtime warning is printed when the copy construction of the noncopyable happens.
If you see this warning, your code is probably doing something unspecified. Copying of noncopyable resources can lead to resource leak and random error.
Definition at line 191 of file NonCopyable.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::size" | |||
) | [inherited] |
Find the length of the file.
- Returns:
- Length of the file
Definition at line 194 of file FileHandle.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::sync" | |||
) | [inherited] |
Flush any buffers associated with the FileHandle, ensuring it is up to date on disk.
- Returns:
- 0 on success or un-needed, -1 on error
Definition at line 182 of file FileHandle.h.
MBED_DEPRECATED_SINCE | ( | "mbed-os-5.4" | , |
"Replaced by FileHandle::seek" | |||
) | [inherited] |
Move the file position to a given offset from a given location.
- Parameters:
-
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.
- Returns:
- new file position on success, -1 on failure or unsupported
virtual short poll | ( | short | events ) | const [virtual, inherited] |
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:
-
events bitmask of poll events we're interested in - POLLIN/POLLOUT etc.
- Returns:
- bitmask of poll events that have occurred.
Reimplemented in UARTSerial, and UnbufferedSerial.
Definition at line 269 of file FileHandle.h.
ssize_t read | ( | void * | buffer, |
size_t | size | ||
) | [virtual, inherited] |
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:
-
buffer The buffer to read in to size The number of bytes to read
- Returns:
- The number of bytes read, 0 at end of file, negative error on failure
Implements FileHandle.
Definition at line 108 of file Stream.cpp.
uint32_t read_finish | ( | usb_ep_t | endpoint ) | [inherited] |
Get the status of a read.
- Parameters:
-
endpoint endpoint to get the status of
- Returns:
- number of bytes read by this endpoint
Definition at line 1489 of file USBDevice.cpp.
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:
-
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
- Returns:
- true if the read was completed, otherwise false
- Note:
- This endpoint must already have been setup with endpoint_add
Definition at line 1431 of file USBDevice.cpp.
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 292 of file FileHandle.h.
int readable | ( | ) |
Determine if there is a character available to read.
- Returns:
- 1 if there is a character available to read, 0 otherwise
Definition at line 131 of file USBSerial.h.
bool ready | ( | ) | [inherited] |
Check if this class is ready.
- Returns:
- true if a terminal is connected, false otherwise
Definition at line 343 of file USBCDC.cpp.
void receive_nb | ( | uint8_t * | buffer, |
uint32_t | size, | ||
uint32_t * | actual | ||
) | [inherited] |
Read from the receive buffer.
- Parameters:
-
buffer buffer to fill with data size maximum number of bytes read actual a pointer to where to store the number of bytes actually received
Definition at line 446 of file USBCDC.cpp.
void rewind | ( | ) | [virtual, inherited] |
Rewind the file position to the beginning of the file.
- Note:
- This is equivalent to seek(0, SEEK_SET)
Reimplemented from FileHandle.
Definition at line 136 of file Stream.cpp.
off_t seek | ( | off_t | offset, |
int | whence | ||
) | [virtual, inherited] |
Move the file position to a given offset from from a given location.
- Parameters:
-
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
- Returns:
- The new offset of the file, negative error code on failure
Implements FileHandle.
Definition at line 126 of file Stream.cpp.
void send_nb | ( | uint8_t * | buffer, |
uint32_t | size, | ||
uint32_t * | actual, | ||
bool | now = true |
||
) | [inherited] |
Send what there is room for.
- Parameters:
-
buffer data to send size maximum number of bytes to send actual a pointer to where to store the number of bytes sent now true to start data transmission, false to wait
Definition at line 378 of file USBCDC.cpp.
virtual int set_blocking | ( | bool | blocking ) | [virtual, inherited] |
Set blocking or nonblocking mode of the file operation like read/write.
Definition depends on the subclass implementing FileHandle. The default is blocking.
- Parameters:
-
blocking true for blocking mode, false for nonblocking mode.
- Returns:
- 0 on success
- Negative error code on failure
Reimplemented in UARTSerial.
Definition at line 209 of file FileHandle.h.
virtual void sigio | ( | Callback< void()> | func ) | [virtual, inherited] |
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:
-
func Function to call on state change
Reimplemented in UARTSerial.
Definition at line 314 of file FileHandle.h.
off_t size | ( | ) | [virtual, inherited] |
Get the size of the file.
- Returns:
- Size of the file in bytes
Reimplemented from FileHandle.
Definition at line 150 of file Stream.cpp.
void sof_disable | ( | ) | [inherited] |
Disable the start of frame interrupt.
Stop calling USBDevice::callback_sof.
Definition at line 1100 of file USBDevice.cpp.
void sof_enable | ( | ) | [inherited] |
Enable the start of frame interrupt.
Call USBDevice::callback_sof on every frame.
Definition at line 1091 of file USBDevice.cpp.
void start_process | ( | ) | [protected, virtual, inherited] |
Callback called to indicate the USB processing needs to be done.
Implements USBPhyEvents.
Definition at line 1705 of file USBDevice.cpp.
int sync | ( | ) | [virtual, inherited] |
Flush any buffers associated with the file.
- Returns:
- 0 on success, negative error code on failure
Reimplemented from FileHandle.
Definition at line 145 of file Stream.cpp.
off_t tell | ( | ) | [virtual, inherited] |
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.
Definition at line 131 of file Stream.cpp.
virtual int truncate | ( | off_t | length ) | [virtual, inherited] |
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:
-
length The requested new length for the file
- Returns:
- Zero on success, negative error code on failure
Reimplemented in File.
Definition at line 151 of file FileHandle.h.
void unlock | ( | void | ) | [protected, virtual, inherited] |
Release exclusive access to this instance USBDevice.
Definition at line 1721 of file USBDevice.cpp.
virtual void unlock | ( | void | ) | [protected, virtual, inherited] |
void wait_ready | ( | ) | [inherited] |
Block until the terminal is connected.
Definition at line 353 of file USBCDC.cpp.
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 281 of file FileHandle.h.
ssize_t write | ( | const void * | buffer, |
size_t | size | ||
) | [virtual, inherited] |
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:
-
buffer The buffer to write from size The number of bytes to write
- Returns:
- The number of bytes written, negative error on failure
Implements FileHandle.
Definition at line 92 of file Stream.cpp.
uint32_t write_finish | ( | usb_ep_t | endpoint ) | [inherited] |
Get the status of a write.
- Parameters:
-
endpoint endpoint to get the status of
- Returns:
- number of bytes sent by this endpoint
Definition at line 1583 of file USBDevice.cpp.
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:
-
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
- Note:
- This endpoint must already have been setup with endpoint_add
Definition at line 1522 of file USBDevice.cpp.
int writeable | ( | ) |
Determine if there is space available to write a character.
- Returns:
- 1 if there is space to write a character, 0 otherwise
Definition at line 142 of file USBSerial.h.
Generated on Tue Jul 12 2022 13:55:38 by
