Fork of official USB device library just changed PID (Product ID) in constructor in USBMSD.h to be different for USBMSD_AT45_HelloWorld program

Dependents:   USBMSD_AT45_HelloWorld

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

USBSerial Class Reference

USBSerial Class Reference

USBSerial example. More...

#include <USBSerial.h>

Inherits USBCDC.

Public Member Functions

 USBSerial (uint16_t vendor_id=0x1f00, uint16_t product_id=0x2012, uint16_t product_release=0x0001)
 Constructor.
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 writeBlock (uint8_t *buf, uint16_t size)
 Write a block of data.
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(*fn)(void))
 Attach a callback called when a packet is received.

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 47 of file USBSerial.h.


Constructor & Destructor Documentation

USBSerial ( uint16_t  vendor_id = 0x1f00,
uint16_t  product_id = 0x2012,
uint16_t  product_release = 0x0001 
)

Constructor.

Parameters:
vendor_idYour vendor_id (default: 0x1f00)
product_idYour product_id (default: 0x2012)
product_releaseYour preoduct_release (default: 0x0001)

Definition at line 58 of file USBSerial.h.


Member Function Documentation

int _getc (  ) [virtual]

Read a character: blocking.

Returns:
character read

Definition at line 27 of file USBSerial.cpp.

int _putc ( int  c ) [virtual]

Send a character.

You can use puts, printf.

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

Definition at line 22 of file USBSerial.cpp.

void attach ( T *  tptr,
void(T::*)(void)  mptr 
)

Attach a member function to call when a packet is received.

Parameters:
tptrpointer to the object to call the member function on
mptrpointer to the member function to be called

Definition at line 102 of file USBSerial.h.

void attach ( void(*)(void)  fn )

Attach a callback called when a packet is received.

Parameters:
fptrfunction pointer

Definition at line 113 of file USBSerial.h.

uint8_t available (  )

Check the number of bytes available.

Returns:
the number of bytes available

Definition at line 65 of file USBSerial.cpp.

bool writeBlock ( uint8_t *  buf,
uint16_t  size 
)

Write a block of data.

For more efficiency, a block of size 64 (maximum size of a bulk endpoint) has to be written.

Parameters:
bufpointer on data which will be written
sizesize of the buffer. The maximum size of a block is limited by the size of the endpoint (64 bytes)
Returns:
true if successfull

Definition at line 35 of file USBSerial.cpp.