Prusa MINI Firmware overview
term.h File Reference
#include <inttypes.h>
#include <stdio.h>

Go to the source code of this file.

Classes

struct  _term_t
 

Macros

#define TERM_ATTR_BACK_MASK   0x00
 
#define TERM_ATTR_BACK_BLACK   0x00
 
#define TERM_ATTR_BACK_WHITE   0x00
 
#define TERM_ATTR_TEXT_MASK   0x00
 
#define TERM_ATTR_TEXT_BLACK   0x00
 
#define TERM_ATTR_TEXT_WHITE   0x00
 
#define TERM_ATTR_INVERT   0x40
 
#define TERM_ATTR_BLINK   0x80
 
#define TERM_COLOR_BLACK   0
 
#define TERM_COLOR_RED   1
 
#define TERM_COLOR_GREEN   2
 
#define TERM_COLOR_YELLOW   3
 
#define TERM_COLOR_BLUE   4
 
#define TERM_COLOR_MAGENTA   5
 
#define TERM_COLOR_CYAN   6
 
#define TERM_COLOR_WHITE   7
 
#define TERM_FLG_FREEMEM   0x0080
 
#define TERM_FLG_CHANGED   0x0040
 
#define TERM_FLG_ESCAPE   0x0020
 
#define TERM_FLG_AUTOCR   0x0010
 
#define TERM_DEF_CHAR   ' '
 
#define TERM_DEF_ATTR   (TERM_ATTR_BACK_BLACK | TERM_ATTR_TEXT_WHITE)
 
#define TERM_BUFF_SIZE(c, r)   ((r * c * 2) + (r * c + 7) / 8)
 
#define TERM_PRINTF_MAX   0xff
 

Typedefs

typedef struct _term_t term_t
 

Functions

void term_init (term_t *pt, uint8_t cols, uint8_t rows, uint8_t *buff)
 
void term_done (term_t *pt)
 
void term_clear (term_t *pt)
 
uint8_t term_get_char_at (term_t *pt, uint8_t col, uint8_t row)
 
void term_set_char_at (term_t *pt, uint8_t col, uint8_t row, uint8_t ch)
 
uint8_t term_get_attr_at (term_t *pt, uint8_t col, uint8_t row)
 
void term_set_attr_at (term_t *pt, uint8_t col, uint8_t row, uint8_t attr)
 
void term_set_attr (term_t *pt, uint8_t attr)
 
void term_set_pos (term_t *pt, uint8_t col, uint8_t row)
 
void term_write_char (term_t *pt, uint8_t ch)
 
int term_printf (term_t *pt, const char *fmt,...)
 
int vterm_printf (term_t *pt, const char *fmt, va_list va)
 

Macro Definition Documentation

◆ TERM_ATTR_BACK_MASK

#define TERM_ATTR_BACK_MASK   0x00

◆ TERM_ATTR_BACK_BLACK

#define TERM_ATTR_BACK_BLACK   0x00

◆ TERM_ATTR_BACK_WHITE

#define TERM_ATTR_BACK_WHITE   0x00

◆ TERM_ATTR_TEXT_MASK

#define TERM_ATTR_TEXT_MASK   0x00

◆ TERM_ATTR_TEXT_BLACK

#define TERM_ATTR_TEXT_BLACK   0x00

◆ TERM_ATTR_TEXT_WHITE

#define TERM_ATTR_TEXT_WHITE   0x00

◆ TERM_ATTR_INVERT

#define TERM_ATTR_INVERT   0x40

◆ TERM_ATTR_BLINK

#define TERM_ATTR_BLINK   0x80

◆ TERM_COLOR_BLACK

#define TERM_COLOR_BLACK   0

◆ TERM_COLOR_RED

#define TERM_COLOR_RED   1

◆ TERM_COLOR_GREEN

#define TERM_COLOR_GREEN   2

◆ TERM_COLOR_YELLOW

#define TERM_COLOR_YELLOW   3

◆ TERM_COLOR_BLUE

#define TERM_COLOR_BLUE   4

◆ TERM_COLOR_MAGENTA

#define TERM_COLOR_MAGENTA   5

◆ TERM_COLOR_CYAN

#define TERM_COLOR_CYAN   6

◆ TERM_COLOR_WHITE

#define TERM_COLOR_WHITE   7

◆ TERM_FLG_FREEMEM

#define TERM_FLG_FREEMEM   0x0080

◆ TERM_FLG_CHANGED

#define TERM_FLG_CHANGED   0x0040

◆ TERM_FLG_ESCAPE

#define TERM_FLG_ESCAPE   0x0020

◆ TERM_FLG_AUTOCR

#define TERM_FLG_AUTOCR   0x0010

◆ TERM_DEF_CHAR

#define TERM_DEF_CHAR   ' '

◆ TERM_DEF_ATTR

#define TERM_DEF_ATTR   (TERM_ATTR_BACK_BLACK | TERM_ATTR_TEXT_WHITE)

◆ TERM_BUFF_SIZE

#define TERM_BUFF_SIZE (   c,
 
)    ((r * c * 2) + (r * c + 7) / 8)

◆ TERM_PRINTF_MAX

#define TERM_PRINTF_MAX   0xff

Typedef Documentation

◆ term_t

typedef struct _term_t term_t

Function Documentation

◆ term_init()

void term_init ( term_t pt,
uint8_t  cols,
uint8_t  rows,
uint8_t buff 
)
6  {
7  if (!pt /*|| pt->buff*/)
8  return;
9  pt->cols = cols;
10  pt->rows = rows;
11  pt->size = cols * rows * 2;
12  pt->flg = TERM_FLG_AUTOCR;
13  if (buff)
14  pt->buff = buff;
15  else {
16  pt->buff = (uint8_t *)gui_malloc(TERM_BUFF_SIZE(cols, rows));
17  pt->flg |= TERM_FLG_FREEMEM;
18  }
19  pt->attr = TERM_DEF_ATTR;
20  pt->col = 0;
21  pt->row = 0;
22  pt->file = 0;
23  term_clear(pt);
24 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ term_done()

void term_done ( term_t pt)
26  {
27  if (!pt || !(pt->buff))
28  return;
29  if (pt->flg & TERM_FLG_FREEMEM)
30  gui_free(pt->buff);
31  //pt->buff = 0;
32 }
Here is the call graph for this function:

◆ term_clear()

void term_clear ( term_t pt)
34  {
35  int r;
36  int c;
37  uint8_t *p = pt->buff;
38  if (!pt || !(pt->buff))
39  return;
40  for (r = 0; r < pt->rows; r++)
41  for (c = 0; c < pt->cols; c++) {
42  *(p++) = TERM_DEF_CHAR;
43  *(p++) = TERM_DEF_ATTR;
44  }
45  memset(pt->buff + pt->size, 0xff, 40 /*(pt->size + 15) >> 4*/);
46  pt->col = 0;
47  pt->row = 0;
48  pt->flg |= TERM_FLG_CHANGED;
49 }
Here is the caller graph for this function:

◆ term_get_char_at()

uint8_t term_get_char_at ( term_t pt,
uint8_t  col,
uint8_t  row 
)
51  {
52  if (!pt || !(pt->buff))
53  return 0;
54  if ((col >= pt->cols) || (row >= pt->rows))
55  return 0;
56  int i = col + row * pt->cols;
57  return pt->buff[2 * i + 0];
58 }

◆ term_set_char_at()

void term_set_char_at ( term_t pt,
uint8_t  col,
uint8_t  row,
uint8_t  ch 
)
60  {
61  if (!pt || !(pt->buff))
62  return;
63  if ((col >= pt->cols) || (row >= pt->rows))
64  return;
65  int i = col + row * pt->cols;
66  pt->buff[2 * i + 0] = ch;
67  pt->buff[pt->size + (i >> 3)] |= (1 << (i % 8));
68  pt->flg |= TERM_FLG_CHANGED;
69 }

◆ term_get_attr_at()

uint8_t term_get_attr_at ( term_t pt,
uint8_t  col,
uint8_t  row 
)
71  {
72  if (!pt || !(pt->buff))
73  return 0;
74  if ((col >= pt->cols) || (row >= pt->rows))
75  return 0;
76  int i = col + row * pt->cols;
77  return pt->buff[2 * i + 1];
78 }

◆ term_set_attr_at()

void term_set_attr_at ( term_t pt,
uint8_t  col,
uint8_t  row,
uint8_t  attr 
)
80  {
81  if (!pt || !(pt->buff))
82  return;
83  if ((col >= pt->cols) || (row >= pt->rows))
84  return;
85  int i = col + row * pt->cols;
86  pt->buff[2 * i + 1] = attr;
87  pt->buff[pt->size + (i >> 3)] |= (1 << (i % 8));
88  pt->flg |= TERM_FLG_CHANGED;
89 }

◆ term_set_attr()

void term_set_attr ( term_t pt,
uint8_t  attr 
)
97  {
98  if (!pt || !(pt->buff))
99  return;
100  pt->attr = attr;
101 }

◆ term_set_pos()

void term_set_pos ( term_t pt,
uint8_t  col,
uint8_t  row 
)
103  {
104  if (!pt || !(pt->buff))
105  return;
106  if (col >= pt->cols)
107  col = pt->cols - 1;
108  if (row >= pt->rows)
109  row = pt->rows - 1;
110  pt->col = col;
111  pt->row = row;
112 }

◆ term_write_char()

void term_write_char ( term_t pt,
uint8_t  ch 
)
157  {
158  if (!pt || !(pt->buff))
159  return;
160  if ((ch == 0x1b) || (pt->flg & TERM_FLG_ESCAPE))
161  term_write_escape_char(pt, ch);
162  else if (ch < 32)
163  term_write_control_char(pt, ch);
164  else {
165  int i = pt->col + pt->row * pt->cols;
166  pt->buff[2 * i + 0] = ch;
167  pt->buff[2 * i + 1] = pt->attr;
168  pt->buff[pt->size + (i >> 3)] |= (1 << (i % 8));
169  if (++(pt->col) >= pt->cols) {
170  pt->col = 0;
171  if (++(pt->row) >= pt->rows)
172  term_scroll_up(pt);
173  }
174  pt->flg |= TERM_FLG_CHANGED;
175  }
176 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ term_printf()

int term_printf ( term_t pt,
const char *  fmt,
  ... 
)
178  {
179  int ret;
180 
181  va_list va;
182  va_start(va, fmt);
183 
184  ret = vterm_printf(pt, fmt, va);
185  va_end(va);
186 
187  return ret;
188 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vterm_printf()

int vterm_printf ( term_t pt,
const char *  fmt,
va_list  va 
)
191  {
192  char text[TERM_PRINTF_MAX];
193  int ret;
194  int i;
195 
196  ret = vsnprintf(text, sizeof(text), fmt, va);
197 
198  for (i = 0; i < ret; i++)
199  term_write_char(pt, text[i]);
200  return ret;
201 }
Here is the call graph for this function:
Here is the caller graph for this function:
_term_t::attr
uint8_t attr
Definition: term.h:49
vterm_printf
int vterm_printf(term_t *pt, const char *fmt, va_list va)
Definition: term.c:191
term_write_escape_char
void term_write_escape_char(term_t *pt, uint8_t ch)
Definition: term.c:128
gui_free
void gui_free(void *ptr)
Definition: gui.c:39
term_write_char
void term_write_char(term_t *pt, uint8_t ch)
Definition: term.c:157
_term_t::row
uint8_t row
Definition: term.h:51
TERM_PRINTF_MAX
#define TERM_PRINTF_MAX
Definition: term.h:38
_term_t::rows
uint8_t rows
Definition: term.h:45
TERM_FLG_ESCAPE
#define TERM_FLG_ESCAPE
Definition: term.h:30
term_scroll_up
void term_scroll_up(term_t *pt)
Definition: term.c:114
TERM_FLG_CHANGED
#define TERM_FLG_CHANGED
Definition: term.h:29
gui_malloc
void * gui_malloc(unsigned int size)
Definition: gui.c:35
i
uint8_t i
Definition: screen_test_graph.c:72
_term_t::col
uint8_t col
Definition: term.h:50
_term_t::cols
uint8_t cols
Definition: term.h:44
TERM_DEF_ATTR
#define TERM_DEF_ATTR
Definition: term.h:34
term_clear
void term_clear(term_t *pt)
Definition: term.c:34
_term_t::flg
uint16_t flg
Definition: term.h:46
term_write_control_char
void term_write_control_char(term_t *pt, uint8_t ch)
Definition: term.c:146
uint8_t
const uint8_t[]
Definition: 404_html.c:3
TERM_FLG_FREEMEM
#define TERM_FLG_FREEMEM
Definition: term.h:28
TERM_DEF_CHAR
#define TERM_DEF_CHAR
Definition: term.h:33
TERM_BUFF_SIZE
#define TERM_BUFF_SIZE(c, r)
Definition: term.h:36
_term_t::file
FILE * file
Definition: term.h:52
_term_t::buff
uint8_t * buff
Definition: term.h:47
TERM_FLG_AUTOCR
#define TERM_FLG_AUTOCR
Definition: term.h:31
_term_t::size
uint16_t size
Definition: term.h:48