Prusa MINI Firmware overview
USBSerial Class Reference

#include <USBSerial.h>

Inheritance diagram for USBSerial:
Collaboration diagram for USBSerial:

Public Member Functions

void begin (uint32_t)
 
virtual int available (void)
 
virtual int availableForWrite (void)
 
virtual int peek (void)
 
virtual int read (void)
 
virtual size_t readBytes (char *buffer, size_t length)
 
virtual size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
virtual void flush (void)
 
virtual size_t write (uint8_t)
 
virtual size_t write (const uint8_t *buffer, size_t size)
 
 operator bool (void)
 
- Public Member Functions inherited from Stream
 Stream ()
 
void setTimeout (unsigned long timeout)
 
unsigned long getTimeout (void)
 
bool find (const char *target)
 
bool find (const uint8_t *target)
 
bool find (const char *target, size_t length)
 
bool find (const uint8_t *target, size_t length)
 
bool find (char target)
 
bool findUntil (const char *target, const char *terminator)
 
bool findUntil (const uint8_t *target, const char *terminator)
 
bool findUntil (const char *target, size_t targetLen, const char *terminate, size_t termLen)
 
bool findUntil (const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen)
 
long parseInt (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
float parseFloat (LookaheadMode lookahead=SKIP_ALL, char ignore=NO_IGNORE_CHAR)
 
size_t readBytes (uint8_t *buffer, size_t length)
 
size_t readBytesUntil (char terminator, uint8_t *buffer, size_t length)
 
String readString ()
 
String readStringUntil (char terminator)
 
- Public Member Functions inherited from Print
 Print ()
 
int getWriteError ()
 
void clearWriteError ()
 
size_t write (const char *str)
 
size_t write (const char *buffer, size_t size)
 
size_t print (const __FlashStringHelper *)
 
size_t print (const String &)
 
size_t print (const char[])
 
size_t print (char)
 
size_t print (unsigned char, int=DEC)
 
size_t print (int, int=DEC)
 
size_t print (unsigned int, int=DEC)
 
size_t print (long, int=DEC)
 
size_t print (unsigned long, int=DEC)
 
size_t print (double, int=2)
 
size_t print (const Printable &)
 
size_t println (const __FlashStringHelper *)
 
size_t println (const String &s)
 
size_t println (const char[])
 
size_t println (char)
 
size_t println (unsigned char, int=DEC)
 
size_t println (int, int=DEC)
 
size_t println (unsigned int, int=DEC)
 
size_t println (long, int=DEC)
 
size_t println (unsigned long, int=DEC)
 
size_t println (double, int=2)
 
size_t println (const Printable &)
 
size_t println (void)
 
void println (int64_t, uint8_t=DEC)
 
void print (int64_t, uint8_t=DEC)
 
void println (uint64_t, uint8_t=DEC)
 
void print (uint64_t, uint8_t=DEC)
 

Additional Inherited Members

- Protected Member Functions inherited from Stream
int timedRead ()
 
int timedPeek ()
 
int peekNextDigit (LookaheadMode lookahead, bool detectDecimal)
 
long parseInt (char ignore)
 
float parseFloat (char ignore)
 
int findMulti (struct MultiTarget *targets, int tCount)
 
- Protected Member Functions inherited from Print
void setWriteError (int err=1)
 
- Protected Attributes inherited from Stream
unsigned long _timeout
 
unsigned long _startMillis
 

Member Function Documentation

◆ begin()

void USBSerial::begin ( uint32_t  baud_count)
67  {
68  // uart config is ignored in USB-CDC
69 }

◆ available()

int USBSerial::available ( void  )
virtual

Implements Stream.

71  {
72  return ibufc;
73 }

◆ availableForWrite()

int USBSerial::availableForWrite ( void  )
virtual
75  {
76  return (USBSERIAL_OBUF_SIZE - obufc);
77 }

◆ peek()

int USBSerial::peek ( void  )
virtual

Implements Stream.

79  {
80  int ch = -1;
81  if (ibufc)
82  ch = ibuff[ibufr];
83  return ch;
84 }

◆ read()

int USBSerial::read ( void  )
virtual

Implements Stream.

86  {
87  int ch = -1;
88  if (ibufc) {
89  ch = ibuff[ibufr++];
90  ibufc--;
92  ibufr = 0;
93  }
94  return ch;
95 }

◆ readBytes()

size_t USBSerial::readBytes ( char *  buffer,
size_t  length 
)
virtual

Reimplemented from Stream.

97  {
98  char ch;
99  size_t readed = 0;
100  while (ibufc && length) {
101  ch = ibuff[ibufr++];
102  buffer[readed++] = ch;
103  ibufc--;
104  length--;
105  if (ibufr >= USBSERIAL_IBUF_SIZE)
106  ibufr = 0;
107  }
108  return readed;
109 }

◆ readBytesUntil()

size_t USBSerial::readBytesUntil ( char  terminator,
char *  buffer,
size_t  length 
)
virtual

Reimplemented from Stream.

111  {
112  char ch;
113  size_t readed = 0;
114  while (ibufc && length) {
115  ch = ibuff[ibufr++];
116  buffer[readed++] = ch;
117  ibufc--;
118  length--;
119  if (ibufr >= USBSERIAL_IBUF_SIZE)
120  ibufr = 0;
121  if (ch == terminator)
122  break;
123  }
124  return readed;
125 }

◆ flush()

void USBSerial::flush ( void  )
virtual

Implements Stream.

127  {
128  if (obufc)
130 }
Here is the call graph for this function:

◆ write() [1/2]

size_t USBSerial::write ( uint8_t  ch)
virtual

Implements Print.

132  {
133  if (obufc >= USBSERIAL_OBUF_SIZE)
134  return 0; // buffer overflow
135  obuff[obufc++] = ch;
136  if (ch == '\n') // eoln
138  return 1;
139 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write() [2/2]

size_t USBSerial::write ( const uint8_t buffer,
size_t  size 
)
virtual

Reimplemented from Print.

141  {
142  size_t written = 0;
143  while (size--) {
144  if (write(*buffer) != 1)
145  break;
146  written++;
147  buffer++;
148  }
149  return written;
150 }
Here is the call graph for this function:

◆ operator bool()

USBSerial::operator bool ( void  )
152  {
153  return true;
154 }
ibufc
uint32_t ibufc
Definition: USBSerial.cpp:25
obuff
uint8_t obuff[USBSERIAL_OBUF_SIZE]
Definition: USBSerial.cpp:21
USBSERIAL_OBUF_SIZE
#define USBSERIAL_OBUF_SIZE
Definition: USBSerial.cpp:8
ibufr
uint32_t ibufr
Definition: USBSerial.cpp:26
ibuff
uint8_t ibuff[USBSERIAL_IBUF_SIZE]
Definition: USBSerial.cpp:24
obufc
uint32_t obufc
Definition: USBSerial.cpp:22
usb_cdc_tx_buffer
void usb_cdc_tx_buffer(void)
Definition: USBSerial.cpp:29
USBSerial::write
virtual size_t write(uint8_t)
Definition: USBSerial.cpp:132
length
png_uint_32 length
Definition: png.c:2247
USBSERIAL_IBUF_SIZE
#define USBSERIAL_IBUF_SIZE
Definition: USBSerial.cpp:9
size
static png_bytep size_t size
Definition: pngwrite.c:2170