Public Types | Public Member Functions | Static Public Member Functions

mxusb::Endpoint Class Reference

#include <usb.h>

List of all members.

Public Types

enum  Direction { IN = 0x80, OUT = 0 }

Public Member Functions

bool isInSideEnabled () const
bool IRQisInSideEnabled () const
bool isOutSideEnabled () const
bool IRQisOutSideEnabled () const
unsigned short inSize () const
unsigned short IRQinSize () const
unsigned short outSize () const
unsigned short IRQoutSize () const
bool write (const unsigned char *data, int size, int &written)
bool read (unsigned char *data, int &readBytes)
bool IRQwrite (const unsigned char *data, int size, int &written)
bool IRQread (unsigned char *data, int &readBytes)

Static Public Member Functions

static Endpoint get (unsigned char epNum)
static Endpoint IRQget (unsigned char epNum)
static const int maxNumEndpoints ()

Detailed Description

Every endpoint, except endpoint zero, have an associated Endpoint class that allows user code to read/write data to that endpoint. Beware that endpoints can change their status (enabled/disabled/direction) at any time because of a SET_CONFIGURATION issued by the host.


Member Enumeration Documentation

Possible endpoint directions

Enumerator:
IN 

Device to host.

OUT 

Host to device.


Member Function Documentation

Endpoint mxusb::Endpoint::get ( unsigned char  epNum  )  [static]

Allows to access an endpoint.

Parameters:
epNum Endpoint number, must be in range 1<=epNum<maxNumEndpoints() or behaviour is undefined.
Returns:
the endpoint class that allows to read/write from that endpoint
unsigned short mxusb::Endpoint::inSize (  )  const
Returns:
size of the buffer used for the IN side of the endpoint, as specified in the endpoint descriptor. Returned value is meaningful only when the endpoint side is enabled.
static Endpoint mxusb::Endpoint::IRQget ( unsigned char  epNum  )  [inline, static]

Allows to access an endpoint from an IRQ or when interrupts are disabled.

Parameters:
epNum Endpoint number, must be in range 1<=epNum<maxNumEndpoints() or behaviour is undefined.
Returns:
the endpoint class that allows to read/write from that endpoint
unsigned short mxusb::Endpoint::IRQinSize (  )  const [inline]
Returns:
size of the buffer used for the IN side of the endpoint, as specified in the endpoint descriptor. Returned value is meaningful only when the endpoint side is enabled.
bool mxusb::Endpoint::IRQisInSideEnabled (  )  const [inline]
Returns:
true if IN side of the endpoint is enabled. Before the host selects a configuration all endpoints are disabled.
bool mxusb::Endpoint::IRQisOutSideEnabled (  )  const [inline]
Returns:
true if OUT side of the endpoint is enabled. Before the host selects a configuration all endpoints are disabled.
unsigned short mxusb::Endpoint::IRQoutSize (  )  const [inline]
Returns:
size of the buffer used for the IN side of the endpoint, as specified in the endpoint descriptor. Returned value is meaningful only when the endpoint side is enabled.
bool mxusb::Endpoint::IRQread ( unsigned char *  data,
int &  readBytes 
)

Read data from an endpoint. Enpoint OUT side must be enabled. This is a nonblocking call that returns immediately. It must be called with interrupts disabled or within an IRQ (such as a Callback).

Parameters:
data buffer where read data is stored. Buffer size must be at least Endpoint::outSize()
readBytes number of bytes actually read. User code should inspect readBytes even in case of errors, since some bytes might be read before the error.
Returns:
false in case of errors, or if the host suspended/reconfigured the device
bool mxusb::Endpoint::IRQwrite ( const unsigned char *  data,
int  size,
int &  written 
)

Write data to an endpoint. Enpoint IN side must be enabled. This is a nonblocking call that returns immediately. It must be called with interrupts disabled or within an IRQ (such as a Callback). Because of the existence of a buffer, when the function returns some data might still be in the buffer waiting for the host to read it.

Parameters:
data data to write
size size of data to write.
written number of bytes actually written. Contrary to write() even if no errors occurred, this value can be lower than size. User code should inspect written in case of errors to know the number of bytes written before the error.
Returns:
false in case of errors, or if the host suspended/reconfigured the device
bool mxusb::Endpoint::isInSideEnabled (  )  const
Returns:
true if IN side of the endpoint is enabled. Before the host selects a configuration all endpoints are disabled.
bool mxusb::Endpoint::isOutSideEnabled (  )  const
Returns:
true if OUT side of the endpoint is enabled. Before the host selects a configuration all endpoints are disabled.
const int mxusb::Endpoint::maxNumEndpoints (  )  [static]
Returns:
the maximum number of endpoints that the the USB peripheral supports.
unsigned short mxusb::Endpoint::outSize (  )  const
Returns:
size of the buffer used for the IN side of the endpoint, as specified in the endpoint descriptor. Returned value is meaningful only when the endpoint side is enabled.
bool mxusb::Endpoint::read ( unsigned char *  data,
int &  readBytes 
)

Read data from an endpoint. Enpoint OUT side must be enabled. This is a blocking call that won't return until data has been read or an error is encountered.
Only one thread at a time can call write on an endpoint. If two or more threads call this function on the same endpoint, the behaviour is undefined. Two thread one calling read and one calling write are allowed.

Parameters:
data buffer where read data is stored. Buffer size must be at least Endpoint::outSize()
readBytes number of bytes actually read. User code should inspect readBytes even in case of errors, since some bytes might be read before the error.
Returns:
false in case of errors, or if the host suspended/reconfigured the device
bool mxusb::Endpoint::write ( const unsigned char *  data,
int  size,
int &  written 
)

Write data to an endpoint. Enpoint IN side must be enabled. This is a blocking call that won't return until all data has been copied into the write buffer or an error is encountered. Because of the existence of a buffer, when the function returns some data might still be in the buffer waiting for the host to read it.
Only one thread at a time can call write on an endpoint. If two or more threads call this function on the same endpoint, the behaviour is undefined. Two thread one calling read and one calling write are allowed.

Parameters:
data data to write
size size of data to write
written number of bytes actually written. If no errors happened it should be equal to size. User code should inspect written in case of errors to know the number of bytes written before the error.
Returns:
false in case of errors, or if the host suspended/reconfigured the device

The documentation for this class was generated from the following files: