chipKIT® Development Platform

Inspired by Arduino™

Last edit: 2021-03-21 22:34 by Majenko

USBSerial

USBSerial
Quick Look
Hardware USB Capable Boards (WF32, Fubarino)
Core HardwareSerial.h

The USBSerial class implements methods for communicating over USB using the Wiring Serial objects.

  1. Detailed Introduction

  2. Full library usage

    1. USBSerial

      1. Constructors

      2. Constants

        1. kMaxUSBxmitPkt

      3. Public Functions

        1. (*rxIntr)(int)

        2. attachInterrupt(void (*callback)(int))

        3. detachInterrupt()

        4. begin(unsigned long baudRate)

        5. end()

      4. Virtual Private Functions

        1. available(void)

        2. peek()

        3. read(void)

        4. flush(void)

        5. write(uint8_t)

        6. write(const char *str)

        7. write(const uint8_t *buffer, size_t size)

        8. virtual unsigned long getBaudRate();

      5. Conversion Operator

        1. int()

      6. Print Class Functions

        1. write(const char *str)

        2. write(const char *buffer, size_t size)

  3. External Links

Detailed Introduction

The USBSerial class is derived from class Stream. It's purpose is to provide methods for sending and receiving data over the available USB ports when available. Boards must have USB capability such as the WF32 or Fubarino. Note that if USB is used for serial, the USB serial port gets instantiated as Serial and hardware serial port 0 gets instantiated as Serial0. If USBSSerial is not used then Hardware Serial (UART) gets instantiated as Serial.

Full library usage

USBSerial

Constructors

USBSerial(ring_buffer *rx_buffer);

Create a new USBSerial object.

Constants


kMaxUSBxmitPkt

	#define	kMaxUSBxmitPkt	63

Public Functions


(*rxIntr)(int)

void	(*rxIntr)(int);

Interrupt callback routine.

attachInterrupt(void (*callback)(int))

void	attachInterrupt(void (*callback)(int));

Attach the interrupt. The callback parameter takes a funtion pointer.

detachInterrupt()

void	detachInterrupt();

Detach the interrupt

begin(unsigned long baudRate)

void	begin(unsigned long baudRate);

Initialize the USB port for use. The baudRate parameted is required but the value is never used and therefore can be set to anything.

end()

void	end();

Has no functionality implemented and therefore it does nothing.

Virtual Private Functions


available(void)

virtual in	available(void);

Return the number of characters currently available in the receive buffer.

peek()

virtual int	peek();

This returns the next character in the receive buffer without removing it from the buffer, or -1 if no characters are in the buffer.

read(void)

virtual int	read(void);

Return the next character from the receive buffer and remove it from the buffer, or -1 if no characters are available in the buffer.

flush(void)

virtual void	flush(void);

Empty the send buffer.

write(uint8_t)

virtual	size_t	write(uint8_t);	

Transmit the specified character.

write(const char *str)

virtual size_t	write(const char *str);

Transmits the characters from the specified pointer.

write(const uint8_t *buffer, size_t size)

virtual size_t	write(const uint8_t *buffer, size_t size);

Transmits the specified number of characters from the buffer pointer. The size parameter is used to specify the number of characters to transmit. If size is less than kMaxUSBxmitPkt a single packet will be transmitted. However if if (size < kMaxUSBxmitPkt is transmitted then multiple packets will be sent.

virtual unsigned long getBaudRate();

virtual unsigned long c;

Returns a baud rate.

Conversion Operator


int()

operator  int();

Returns 1 if the com port is open and 0 if the com port is closed.

Print Class Functions


The following write functions are pulled in from the Print class.

write(const char *str)

size_t   write(const char *str);

write(const char *buffer, size_t size)

size_t   write(const char *buffer, size_t size);

External Links