Prusa MINI Firmware overview
HalSerial Class Reference

#include <serial.h>

Collaboration diagram for HalSerial:

Public Member Functions

 HalSerial ()
 
void begin (int32_t)
 
void end ()
 
int peek ()
 
int read ()
 
size_t write (char c)
 
 operator bool ()
 
uint16_t available ()
 
void flush ()
 
uint8_t availableForWrite ()
 
void flushTX ()
 
void printf (const char *format,...)
 
void print_bin (uint32_t value, uint8_t num_digits)
 
void print (const char value[])
 
void print (char value, int nbase=0)
 
void print (unsigned char value, int nbase=0)
 
void print (int value, int nbase=0)
 
void print (unsigned int value, int nbase=0)
 
void print (long value, int nbase=0)
 
void print (unsigned long value, int nbase=0)
 
void print (float value, int round=6)
 
void print (double value, int round=6)
 
void println (const char value[])
 
void println (char value, int nbase=0)
 
void println (unsigned char value, int nbase=0)
 
void println (int value, int nbase=0)
 
void println (unsigned int value, int nbase=0)
 
void println (long value, int nbase=0)
 
void println (unsigned long value, int nbase=0)
 
void println (float value, int round=6)
 
void println (double value, int round=6)
 
void println ()
 

Public Attributes

volatile RingBuffer< uint8_t, 128 > receive_buffer
 
volatile RingBuffer< uint8_t, 128 > transmit_buffer
 
volatile bool host_connected
 

Constructor & Destructor Documentation

◆ HalSerial()

HalSerial::HalSerial ( )
84 { host_connected = true; }

Member Function Documentation

◆ begin()

void HalSerial::begin ( int32_t  )
86 {}

◆ end()

void HalSerial::end ( void  )
88 {}

◆ peek()

int HalSerial::peek ( void  )
90  {
91  uint8_t value;
92  return receive_buffer.peek(&value) ? value : -1;
93  }
Here is the call graph for this function:

◆ read()

int HalSerial::read ( void  )
95 { return receive_buffer.read(); }
Here is the call graph for this function:

◆ write()

size_t HalSerial::write ( char  c)
97  {
98  if (!host_connected) return 0;
99  while (!transmit_buffer.free());
100  return transmit_buffer.write(c);
101  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator bool()

HalSerial::operator bool ( )
103 { return host_connected; }

◆ available()

uint16_t HalSerial::available ( void  )
105  {
106  return (uint16_t)receive_buffer.available();
107  }
Here is the call graph for this function:

◆ flush()

void HalSerial::flush ( void  )
109 { receive_buffer.clear(); }
Here is the call graph for this function:

◆ availableForWrite()

uint8_t HalSerial::availableForWrite ( void  )
111  {
112  return transmit_buffer.free() > 255 ? 255 : (uint8_t)transmit_buffer.free();
113  }
Here is the call graph for this function:

◆ flushTX()

void HalSerial::flushTX ( )
115  {
116  if (host_connected)
117  while (transmit_buffer.available()) { /* nada */ }
118  }
Here is the call graph for this function:

◆ printf()

void HalSerial::printf ( const char *  format,
  ... 
)
120  {
121  static char buffer[256];
122  va_list vArgs;
123  va_start(vArgs, format);
124  int length = vsnprintf((char *) buffer, 256, (char const *) format, vArgs);
125  va_end(vArgs);
126  if (length > 0 && length < 256) {
127  if (host_connected) {
128  for (int i = 0; i < length;) {
129  if (transmit_buffer.write(buffer[i])) {
130  ++i;
131  }
132  }
133  }
134  }
135  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_bin()

void HalSerial::print_bin ( uint32_t  value,
uint8_t  num_digits 
)
142  {
143  uint32_t mask = 1 << (num_digits -1);
144  for (uint8_t i = 0; i < num_digits; i++) {
145  if (!(i % 4) && i) write(' ');
146  if (!(i % 16) && i) write(' ');
147  if (value & mask) write('1');
148  else write('0');
149  value <<= 1;
150  }
151  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [1/9]

void HalSerial::print ( const char  value[])
153 { printf("%s" , value); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/9]

void HalSerial::print ( char  value,
int  nbase = 0 
)
154  {
155  if (nbase == BIN) print_bin(value, 8);
156  else if (nbase == OCT) printf("%3o", value);
157  else if (nbase == HEX) printf("%2X", value);
158  else if (nbase == DEC ) printf("%d", value);
159  else printf("%c" , value);
160  }
Here is the call graph for this function:

◆ print() [3/9]

void HalSerial::print ( unsigned char  value,
int  nbase = 0 
)
161  {
162  if (nbase == BIN) print_bin(value, 8);
163  else if (nbase == OCT) printf("%3o", value);
164  else if (nbase == HEX) printf("%2X", value);
165  else printf("%u" , value);
166  }
Here is the call graph for this function:

◆ print() [4/9]

void HalSerial::print ( int  value,
int  nbase = 0 
)
167  {
168  if (nbase == BIN) print_bin(value, 16);
169  else if (nbase == OCT) printf("%6o", value);
170  else if (nbase == HEX) printf("%4X", value);
171  else printf("%d", value);
172  }
Here is the call graph for this function:

◆ print() [5/9]

void HalSerial::print ( unsigned int  value,
int  nbase = 0 
)
173  {
174  if (nbase == BIN) print_bin(value, 16);
175  else if (nbase == OCT) printf("%6o", value);
176  else if (nbase == HEX) printf("%4X", value);
177  else printf("%u" , value);
178  }
Here is the call graph for this function:

◆ print() [6/9]

void HalSerial::print ( long  value,
int  nbase = 0 
)
179  {
180  if (nbase == BIN) print_bin(value, 32);
181  else if (nbase == OCT) printf("%11o", value);
182  else if (nbase == HEX) printf("%8X", value);
183  else printf("%ld" , value);
184  }
Here is the call graph for this function:

◆ print() [7/9]

void HalSerial::print ( unsigned long  value,
int  nbase = 0 
)
185  {
186  if (nbase == BIN) print_bin(value, 32);
187  else if (nbase == OCT) printf("%11o", value);
188  else if (nbase == HEX) printf("%8X", value);
189  else printf("%lu" , value);
190  }
Here is the call graph for this function:

◆ print() [8/9]

void HalSerial::print ( float  value,
int  round = 6 
)
191 { printf("%f" , value); }
Here is the call graph for this function:

◆ print() [9/9]

void HalSerial::print ( double  value,
int  round = 6 
)
192 { printf("%f" , value); }
Here is the call graph for this function:

◆ println() [1/10]

void HalSerial::println ( const char  value[])
194 { printf("%s\n" , value); }
Here is the call graph for this function:

◆ println() [2/10]

void HalSerial::println ( char  value,
int  nbase = 0 
)
195 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [3/10]

void HalSerial::println ( unsigned char  value,
int  nbase = 0 
)
196 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [4/10]

void HalSerial::println ( int  value,
int  nbase = 0 
)
197 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [5/10]

void HalSerial::println ( unsigned int  value,
int  nbase = 0 
)
198 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [6/10]

void HalSerial::println ( long  value,
int  nbase = 0 
)
199 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [7/10]

void HalSerial::println ( unsigned long  value,
int  nbase = 0 
)
200 { print(value, nbase); println(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ println() [8/10]

void HalSerial::println ( float  value,
int  round = 6 
)
201 { printf("%f\n" , value); }
Here is the call graph for this function:

◆ println() [9/10]

void HalSerial::println ( double  value,
int  round = 6 
)
202 { printf("%f\n" , value); }
Here is the call graph for this function:

◆ println() [10/10]

void HalSerial::println ( void  )
203 { print('\n'); }
Here is the call graph for this function:

Member Data Documentation

◆ receive_buffer

volatile RingBuffer<uint8_t, 128> HalSerial::receive_buffer

◆ transmit_buffer

volatile RingBuffer<uint8_t, 128> HalSerial::transmit_buffer

◆ host_connected

volatile bool HalSerial::host_connected
RingBuffer::available
int available()
HalSerial::println
void println()
Definition: serial.h:203
BIN
#define BIN
Definition: serial.h:140
RingBuffer::peek
int peek()
HEX
#define HEX
Definition: serial.h:138
HalSerial::printf
void printf(const char *format,...)
Definition: serial.h:120
i
uint8_t i
Definition: screen_test_graph.c:72
RingBuffer::free
uint32_t free() volatile
Definition: serial.h:42
HalSerial::print
void print(const char value[])
Definition: serial.h:153
HalSerial::transmit_buffer
volatile RingBuffer< uint8_t, 128 > transmit_buffer
Definition: serial.h:206
HalSerial::receive_buffer
volatile RingBuffer< uint8_t, 128 > receive_buffer
Definition: serial.h:205
HalSerial::print_bin
void print_bin(uint32_t value, uint8_t num_digits)
Definition: serial.h:142
RingBuffer::clear
void clear() volatile
Definition: serial.h:45
HalSerial::host_connected
volatile bool host_connected
Definition: serial.h:207
uint8_t
const uint8_t[]
Definition: 404_html.c:3
HalSerial::write
size_t write(char c)
Definition: serial.h:97
DEC
#define DEC
Definition: serial.h:137
OCT
#define OCT
Definition: serial.h:139
length
png_uint_32 length
Definition: png.c:2247
RingBuffer::read
int read()
RingBuffer::write
ring_buffer_pos_t write(const uint8_t c)