Prusa MINI Firmware overview
lcdsim.c File Reference
#include "lcdsim.h"
#include <string.h>
#include "dbg.h"

Macros

#define LCD_DDRAM_SIZE   0x80
 
#define LCD_CGRAM_SIZE   0x40
 
#define LCD_CMD_CLEARDISPLAY   0x01
 
#define LCD_CMD_RETURNHOME   0x02
 
#define LCD_CMD_ENTRYMODESET   0x04
 
#define LCD_CMD_DISPLAYCONTROL   0x08
 
#define LCD_CMD_CURSORSHIFT   0x10
 
#define LCD_CMD_FUNCTIONSET   0x20
 
#define LCD_CMD_SETCGRAMADDR   0x40
 
#define LCD_CMD_SETDDRAMADDR   0x80
 
#define LCD_FLG_FUNC8BIT   0x10
 
#define LCD_FLG_FUNC2LINE   0x08
 
#define LCD_FLG_FUNC10DOTS   0x04
 
#define LCD_FLG_SHIFTDISPLAY   0x08
 
#define LCD_FLG_SHIFTRIGHT   0x04
 
#define LCD_FLG_DISPLAYON   0x04
 
#define LCD_FLG_CURSORON   0x02
 
#define LCD_FLG_BLINKON   0x01
 
#define LCD_FLG_ENTRYLEFT   0x01
 
#define LCD_FLG_ENTRYSHIFTINC   0x02
 
#define LCD_EXPANDER_RS   0x01
 
#define LCD_EXPANDER_RW   0x02
 
#define LCD_EXPANDER_EN   0x04
 
#define LCD_EXPANDER_BL   0x08
 

Functions

void lcdsim_cmd_clearDisplay (void)
 
static uint8_t lcdsim_addr2row (uint8_t addr)
 
static uint8_t lcdsim_addr2col (uint8_t addr)
 
static uint8_t lcdsim_pos2addr (uint8_t col, uint8_t row)
 
void lcdsim_init (void)
 
void lcdsim_invalidate (void)
 
uint8_t lcdsim_char_at (uint8_t col, uint8_t row)
 
uint8_tlcdsim_user_charset_ptr (void)
 
uint16_t lcdsim_grab_text (char *text)
 
void lcdsim_cmd_setDDRamAddr (int8_t addr)
 
void lcdsim_cmd_setCGRamAddr (int8_t addr)
 
void lcdsim_cmd_functionSet (int func8bit, int func2line, int func10dots)
 
void lcdsim_cmd_cursorShift (int shiftDisplay, int shiftRight)
 
void lcdsim_cmd_displayControl (int displayOn, int cursorOn, int blinkOn)
 
void lcdsim_cmd_entryModeSet (int entryLeft, int entryShiftInc)
 
void lcdsim_cmd_returnHome (void)
 
void lcdsim_wr_cmd (uint8_t cmd)
 
void lcdsim_wr_data (uint8_t data)
 
void lcdsim_expander_write (uint8_t expander)
 

Variables

uint8_t lcdsim_expander
 
uint8_t lcdsim_ddram [LCD_DDRAM_SIZE]
 
uint8_t lcdsim_cgram [LCD_CGRAM_SIZE]
 
int8_t lcdsim_ddram_addr
 
int8_t lcdsim_cgram_addr
 
uint32_t lcdsim_inval_mask [LCDSIM_ROWS]
 
int8_t lcdsim_shift = 0
 
int lcdsim_func8bit = 1
 
int lcdsim_func2line = 1
 
int lcdsim_func10dots = 1
 
int lcdsim_displayOn = 1
 
int lcdsim_cursorOn = 1
 
int lcdsim_blinkOn = 1
 
int lcdsim_entryLeft = 0
 
int lcdsim_entryShiftInc = 0
 

Macro Definition Documentation

◆ LCD_DDRAM_SIZE

#define LCD_DDRAM_SIZE   0x80

◆ LCD_CGRAM_SIZE

#define LCD_CGRAM_SIZE   0x40

◆ LCD_CMD_CLEARDISPLAY

#define LCD_CMD_CLEARDISPLAY   0x01

◆ LCD_CMD_RETURNHOME

#define LCD_CMD_RETURNHOME   0x02

◆ LCD_CMD_ENTRYMODESET

#define LCD_CMD_ENTRYMODESET   0x04

◆ LCD_CMD_DISPLAYCONTROL

#define LCD_CMD_DISPLAYCONTROL   0x08

◆ LCD_CMD_CURSORSHIFT

#define LCD_CMD_CURSORSHIFT   0x10

◆ LCD_CMD_FUNCTIONSET

#define LCD_CMD_FUNCTIONSET   0x20

◆ LCD_CMD_SETCGRAMADDR

#define LCD_CMD_SETCGRAMADDR   0x40

◆ LCD_CMD_SETDDRAMADDR

#define LCD_CMD_SETDDRAMADDR   0x80

◆ LCD_FLG_FUNC8BIT

#define LCD_FLG_FUNC8BIT   0x10

◆ LCD_FLG_FUNC2LINE

#define LCD_FLG_FUNC2LINE   0x08

◆ LCD_FLG_FUNC10DOTS

#define LCD_FLG_FUNC10DOTS   0x04

◆ LCD_FLG_SHIFTDISPLAY

#define LCD_FLG_SHIFTDISPLAY   0x08

◆ LCD_FLG_SHIFTRIGHT

#define LCD_FLG_SHIFTRIGHT   0x04

◆ LCD_FLG_DISPLAYON

#define LCD_FLG_DISPLAYON   0x04

◆ LCD_FLG_CURSORON

#define LCD_FLG_CURSORON   0x02

◆ LCD_FLG_BLINKON

#define LCD_FLG_BLINKON   0x01

◆ LCD_FLG_ENTRYLEFT

#define LCD_FLG_ENTRYLEFT   0x01

◆ LCD_FLG_ENTRYSHIFTINC

#define LCD_FLG_ENTRYSHIFTINC   0x02

◆ LCD_EXPANDER_RS

#define LCD_EXPANDER_RS   0x01

◆ LCD_EXPANDER_RW

#define LCD_EXPANDER_RW   0x02

◆ LCD_EXPANDER_EN

#define LCD_EXPANDER_EN   0x04

◆ LCD_EXPANDER_BL

#define LCD_EXPANDER_BL   0x08

Function Documentation

◆ lcdsim_cmd_clearDisplay()

void lcdsim_cmd_clearDisplay ( void  )
153  {
154  int i;
155  //for (i = 0; i < LCD_CGRAM_SIZE; i++)
156  // lcdsim_cgram[i] = 0x00;
157  for (i = 0; i < LCD_DDRAM_SIZE; i++)
158  lcdsim_ddram[i] = ' ';
159  lcdsim_cgram_addr = -1;
160  lcdsim_ddram_addr = 0;
161  lcdsim_shift = 0;
163 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_addr2row()

static uint8_t lcdsim_addr2row ( uint8_t  addr)
static
59  {
60  return ((addr & 0x40) >> 6) | (((addr & 0x3f) >= 0x14) ? 2 : 0);
61 }
Here is the caller graph for this function:

◆ lcdsim_addr2col()

static uint8_t lcdsim_addr2col ( uint8_t  addr)
static
63  {
64  return (addr & 0x3f) % 20;
65 }
Here is the caller graph for this function:

◆ lcdsim_pos2addr()

static uint8_t lcdsim_pos2addr ( uint8_t  col,
uint8_t  row 
)
static
67  {
68  return lcdsim_row_addr[row & 0x03] + (col % 20);
69 }
Here is the caller graph for this function:

◆ lcdsim_init()

void lcdsim_init ( void  )
71  {
72  int i;
73  for (i = 0; i < LCD_CGRAM_SIZE; i++)
74  lcdsim_cgram[i] = 0x00;
75  lcdsim_expander = 0;
77 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_invalidate()

void lcdsim_invalidate ( void  )
79  {
80  int i;
81  for (i = 0; i < 4; i++)
82  lcdsim_inval_mask[i] = 0x000fffff;
83 }
Here is the caller graph for this function:

◆ lcdsim_char_at()

uint8_t lcdsim_char_at ( uint8_t  col,
uint8_t  row 
)
85  {
86  return lcdsim_ddram[lcdsim_pos2addr(col, row)];
87 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_user_charset_ptr()

uint8_t* lcdsim_user_charset_ptr ( void  )
89  {
90  return lcdsim_cgram;
91 }
Here is the caller graph for this function:

◆ lcdsim_grab_text()

uint16_t lcdsim_grab_text ( char *  text)
93  {
94  int row;
95  int col;
96  int i = 0;
97  for (row = 0; row < 4; row++) {
98  for (col = 0; col < 20; col++)
99  text[i + col] = lcdsim_char_at(col, row);
100  for (col = 19; col >= 0; col--)
101  if (text[i + col] != ' ')
102  break;
103  i += col + 1;
104  text[i++] = '\n';
105  }
106  text[i] = 0;
107  return i;
108 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_cmd_setDDRamAddr()

void lcdsim_cmd_setDDRamAddr ( int8_t  addr)
110  {
111  lcdsim_cgram_addr = -1; //stop CGRam write
112  lcdsim_ddram_addr = addr; //set address
113 }
Here is the caller graph for this function:

◆ lcdsim_cmd_setCGRamAddr()

void lcdsim_cmd_setCGRamAddr ( int8_t  addr)
115  {
116  lcdsim_cgram_addr = addr; //set address
117 }
Here is the caller graph for this function:

◆ lcdsim_cmd_functionSet()

void lcdsim_cmd_functionSet ( int  func8bit,
int  func2line,
int  func10dots 
)
119  {
120  lcdsim_func8bit = func8bit;
121  lcdsim_func2line = func2line;
122  lcdsim_func10dots = func10dots;
123 }
Here is the caller graph for this function:

◆ lcdsim_cmd_cursorShift()

void lcdsim_cmd_cursorShift ( int  shiftDisplay,
int  shiftRight 
)
125  {
126  lcdsim_cgram_addr = -1;
127  if (shiftDisplay) {
128  lcdsim_shift += shiftRight ? 1 : -1;
129  lcdsim_shift &= 0x3f;
130  } else {
131  lcdsim_ddram_addr += shiftRight ? 1 : -1;
132  lcdsim_ddram_addr &= 0x7f;
133  }
134 }
Here is the caller graph for this function:

◆ lcdsim_cmd_displayControl()

void lcdsim_cmd_displayControl ( int  displayOn,
int  cursorOn,
int  blinkOn 
)
136  {
137  lcdsim_displayOn = displayOn;
138  lcdsim_cursorOn = cursorOn;
139  lcdsim_blinkOn = blinkOn;
140 }
Here is the caller graph for this function:

◆ lcdsim_cmd_entryModeSet()

void lcdsim_cmd_entryModeSet ( int  entryLeft,
int  entryShiftInc 
)
142  {
143  lcdsim_entryLeft = entryLeft;
144  lcdsim_entryShiftInc = entryShiftInc;
145 }
Here is the caller graph for this function:

◆ lcdsim_cmd_returnHome()

void lcdsim_cmd_returnHome ( void  )
147  {
148  lcdsim_cgram_addr = -1;
149  lcdsim_ddram_addr = 0;
150  lcdsim_shift = 0;
151 }
Here is the caller graph for this function:

◆ lcdsim_wr_cmd()

void lcdsim_wr_cmd ( uint8_t  cmd)
165  {
166  if ((cmd & LCD_CMD_SETDDRAMADDR) != 0)
167  lcdsim_cmd_setDDRamAddr((uint8_t)(cmd & 0x7f));
168  else if ((cmd & LCD_CMD_SETCGRAMADDR) != 0)
169  lcdsim_cmd_setCGRamAddr((uint8_t)(cmd & 0x3f));
170  else if ((cmd & LCD_CMD_FUNCTIONSET) != 0)
171  lcdsim_cmd_functionSet((cmd & LCD_FLG_FUNC8BIT) != 0, (cmd & LCD_FLG_FUNC2LINE) != 0, (cmd & LCD_FLG_FUNC10DOTS) != 0);
172  else if ((cmd & LCD_CMD_CURSORSHIFT) != 0)
174  else if ((cmd & LCD_CMD_DISPLAYCONTROL) != 0)
175  lcdsim_cmd_displayControl((cmd & LCD_FLG_DISPLAYON) != 0, (cmd & LCD_FLG_DISPLAYON) != 0, (cmd & LCD_FLG_BLINKON) != 0);
176  else if ((cmd & LCD_CMD_ENTRYMODESET) != 0)
178  else if ((cmd & LCD_CMD_RETURNHOME) != 0)
180  else if ((cmd & LCD_CMD_CLEARDISPLAY) != 0)
182 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_wr_data()

void lcdsim_wr_data ( uint8_t  data)
184  {
185  if (lcdsim_cgram_addr >= 0) {
187  lcdsim_cgram_addr &= 0x3f;
188  } else {
192  lcdsim_inval_mask[row] |= (1 << col);
194  lcdsim_ddram_addr &= 0x7f;
195  }
196 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lcdsim_expander_write()

void lcdsim_expander_write ( uint8_t  expander)
204  {
205  static uint8_t d4_7 = 0;
206  uint8_t d0_7;
207  uint8_t change;
208  if (lcdsim_expander != expander) {
209  change = expander ^ lcdsim_expander;
210  if (change & LCD_EXPANDER_RS)
211  d4_7 = 0; //reset to first nibble if RS changed
212  if (change & lcdsim_expander & LCD_EXPANDER_EN) { // EN falling edge
213  if (d4_7) { //second (low) nibble
214  d0_7 = (d4_7 & 0xf0) | (expander >> 4);
215  if (expander & LCD_EXPANDER_RS)
216  lcdsim_wr_data(d0_7); //data
217  else
218  lcdsim_wr_cmd(d0_7); //command
219  d4_7 = 0;
220  } else //high nibble
221  d4_7 = expander | 0x0f;
222  }
223  lcdsim_expander = expander;
224  }
225 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ lcdsim_expander

uint8_t lcdsim_expander

◆ lcdsim_ddram

uint8_t lcdsim_ddram[LCD_DDRAM_SIZE]

◆ lcdsim_cgram

uint8_t lcdsim_cgram[LCD_CGRAM_SIZE]

◆ lcdsim_ddram_addr

int8_t lcdsim_ddram_addr

◆ lcdsim_cgram_addr

int8_t lcdsim_cgram_addr

◆ lcdsim_inval_mask

uint32_t lcdsim_inval_mask[LCDSIM_ROWS]

◆ lcdsim_shift

int8_t lcdsim_shift = 0

◆ lcdsim_func8bit

int lcdsim_func8bit = 1

◆ lcdsim_func2line

int lcdsim_func2line = 1

◆ lcdsim_func10dots

int lcdsim_func10dots = 1

◆ lcdsim_displayOn

int lcdsim_displayOn = 1

◆ lcdsim_cursorOn

int lcdsim_cursorOn = 1

◆ lcdsim_blinkOn

int lcdsim_blinkOn = 1

◆ lcdsim_entryLeft

int lcdsim_entryLeft = 0

◆ lcdsim_entryShiftInc

int lcdsim_entryShiftInc = 0
LCD_CMD_DISPLAYCONTROL
#define LCD_CMD_DISPLAYCONTROL
Definition: lcdsim.c:12
LCD_FLG_BLINKON
#define LCD_FLG_BLINKON
Definition: lcdsim.c:25
lcdsim_blinkOn
int lcdsim_blinkOn
Definition: lcdsim.c:53
LCD_CMD_RETURNHOME
#define LCD_CMD_RETURNHOME
Definition: lcdsim.c:10
lcdsim_cmd_setDDRamAddr
void lcdsim_cmd_setDDRamAddr(int8_t addr)
Definition: lcdsim.c:110
lcdsim_func2line
int lcdsim_func2line
Definition: lcdsim.c:49
LCD_FLG_ENTRYSHIFTINC
#define LCD_FLG_ENTRYSHIFTINC
Definition: lcdsim.c:27
lcdsim_char_at
uint8_t lcdsim_char_at(uint8_t col, uint8_t row)
Definition: lcdsim.c:85
LCD_FLG_FUNC8BIT
#define LCD_FLG_FUNC8BIT
Definition: lcdsim.c:18
lcdsim_addr2col
static uint8_t lcdsim_addr2col(uint8_t addr)
Definition: lcdsim.c:63
lcdsim_cmd_returnHome
void lcdsim_cmd_returnHome(void)
Definition: lcdsim.c:147
data
uint8_t data[8]
Definition: masstorage.h:49
LCD_DDRAM_SIZE
#define LCD_DDRAM_SIZE
Definition: lcdsim.c:6
LCD_FLG_ENTRYLEFT
#define LCD_FLG_ENTRYLEFT
Definition: lcdsim.c:26
LCD_CMD_ENTRYMODESET
#define LCD_CMD_ENTRYMODESET
Definition: lcdsim.c:11
i
uint8_t i
Definition: screen_test_graph.c:72
lcdsim_expander
uint8_t lcdsim_expander
Definition: lcdsim.c:34
lcdsim_ddram
uint8_t lcdsim_ddram[LCD_DDRAM_SIZE]
Definition: lcdsim.c:36
LCD_CMD_CLEARDISPLAY
#define LCD_CMD_CLEARDISPLAY
Definition: lcdsim.c:9
lcdsim_entryShiftInc
int lcdsim_entryShiftInc
Definition: lcdsim.c:55
lcdsim_cmd_setCGRamAddr
void lcdsim_cmd_setCGRamAddr(int8_t addr)
Definition: lcdsim.c:115
LCD_FLG_SHIFTDISPLAY
#define LCD_FLG_SHIFTDISPLAY
Definition: lcdsim.c:21
lcdsim_inval_mask
uint32_t lcdsim_inval_mask[LCDSIM_ROWS]
Definition: lcdsim.c:40
lcdsim_invalidate
void lcdsim_invalidate(void)
Definition: lcdsim.c:79
lcdsim_cmd_displayControl
void lcdsim_cmd_displayControl(int displayOn, int cursorOn, int blinkOn)
Definition: lcdsim.c:136
lcdsim_ddram_addr
int8_t lcdsim_ddram_addr
Definition: lcdsim.c:38
lcdsim_func8bit
int lcdsim_func8bit
Definition: lcdsim.c:48
lcdsim_cmd_functionSet
void lcdsim_cmd_functionSet(int func8bit, int func2line, int func10dots)
Definition: lcdsim.c:119
lcdsim_wr_data
void lcdsim_wr_data(uint8_t data)
Definition: lcdsim.c:184
LCD_CMD_CURSORSHIFT
#define LCD_CMD_CURSORSHIFT
Definition: lcdsim.c:13
LCD_FLG_SHIFTRIGHT
#define LCD_FLG_SHIFTRIGHT
Definition: lcdsim.c:22
LCD_EXPANDER_RS
#define LCD_EXPANDER_RS
Definition: lcdsim.c:29
lcdsim_cgram_addr
int8_t lcdsim_cgram_addr
Definition: lcdsim.c:39
LCD_CGRAM_SIZE
#define LCD_CGRAM_SIZE
Definition: lcdsim.c:7
lcdsim_entryLeft
int lcdsim_entryLeft
Definition: lcdsim.c:54
lcdsim_cmd_cursorShift
void lcdsim_cmd_cursorShift(int shiftDisplay, int shiftRight)
Definition: lcdsim.c:125
lcdsim_shift
int8_t lcdsim_shift
Definition: lcdsim.c:46
lcdsim_func10dots
int lcdsim_func10dots
Definition: lcdsim.c:50
lcdsim_cgram
uint8_t lcdsim_cgram[LCD_CGRAM_SIZE]
Definition: lcdsim.c:37
LCD_CMD_FUNCTIONSET
#define LCD_CMD_FUNCTIONSET
Definition: lcdsim.c:14
LCD_CMD_SETDDRAMADDR
#define LCD_CMD_SETDDRAMADDR
Definition: lcdsim.c:16
uint8_t
const uint8_t[]
Definition: 404_html.c:3
lcdsim_addr2row
static uint8_t lcdsim_addr2row(uint8_t addr)
Definition: lcdsim.c:59
lcdsim_cursorOn
int lcdsim_cursorOn
Definition: lcdsim.c:52
LCD_FLG_FUNC2LINE
#define LCD_FLG_FUNC2LINE
Definition: lcdsim.c:19
LCD_FLG_DISPLAYON
#define LCD_FLG_DISPLAYON
Definition: lcdsim.c:23
lcdsim_cmd_clearDisplay
void lcdsim_cmd_clearDisplay(void)
Definition: lcdsim.c:153
LCD_CMD_SETCGRAMADDR
#define LCD_CMD_SETCGRAMADDR
Definition: lcdsim.c:15
lcdsim_pos2addr
static uint8_t lcdsim_pos2addr(uint8_t col, uint8_t row)
Definition: lcdsim.c:67
lcdsim_wr_cmd
void lcdsim_wr_cmd(uint8_t cmd)
Definition: lcdsim.c:165
LCD_FLG_FUNC10DOTS
#define LCD_FLG_FUNC10DOTS
Definition: lcdsim.c:20
lcdsim_displayOn
int lcdsim_displayOn
Definition: lcdsim.c:51
LCD_EXPANDER_EN
#define LCD_EXPANDER_EN
Definition: lcdsim.c:31
lcdsim_cmd_entryModeSet
void lcdsim_cmd_entryModeSet(int entryLeft, int entryShiftInc)
Definition: lcdsim.c:142