less hacky
This commit is contained in:
@@ -10,8 +10,10 @@
|
|||||||
struct lcd_t {
|
struct lcd_t {
|
||||||
int fd;
|
int fd;
|
||||||
uint32_t baud;
|
uint32_t baud;
|
||||||
char ccharbuf[8][11]; // 8 custom chars, each 11 bytes (3 byte command + 8 byte glyph)
|
struct {
|
||||||
char writebuf[LCD_LINES * LCD_COLS + 8]; // number of chars on the lcd + 2*4 byte set cursor commands
|
char cchar[8][11]; // 8 custom chars, each 11 bytes (3 byte command + 8 byte glyph)
|
||||||
|
char text[LCD_LINES * LCD_COLS + 8]; // number of chars on the lcd + 2*4 byte set cursor commands
|
||||||
|
} writebuf;
|
||||||
char port[96];
|
char port[96];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
19
src/lcd.c
19
src/lcd.c
@@ -61,7 +61,7 @@ void lcd_set_cursor(struct lcd_t *lcd, const uint8_t row, const uint8_t col) {
|
|||||||
void lcd_set_custom_char(struct lcd_t *lcd, const uint8_t index, const lcd_glyph_t *glyph) {
|
void lcd_set_custom_char(struct lcd_t *lcd, const uint8_t index, const lcd_glyph_t *glyph) {
|
||||||
uint8_t cmdbuf[] = {254, 78, index, 0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t cmdbuf[] = {254, 78, index, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
memcpy(&cmdbuf[3], glyph, sizeof(lcd_glyph_t));
|
memcpy(&cmdbuf[3], glyph, sizeof(lcd_glyph_t));
|
||||||
memcpy(lcd->ccharbuf[index], cmdbuf, sizeof(cmdbuf));
|
memcpy(lcd->writebuf.cchar[index], cmdbuf, sizeof(cmdbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* writes string to write buffer at calculated pos, we trust it to be null terminated */
|
/* writes string to write buffer at calculated pos, we trust it to be null terminated */
|
||||||
@@ -74,7 +74,7 @@ void lcd_write_buf(struct lcd_t *lcd, const uint8_t row, const uint8_t col, cons
|
|||||||
uint8_t pos = 4 + col + (LCD_COLS * (row % 2)); // skip 4 bytes to leave room for set cursor command
|
uint8_t pos = 4 + col + (LCD_COLS * (row % 2)); // skip 4 bytes to leave room for set cursor command
|
||||||
if (row >= 2)
|
if (row >= 2)
|
||||||
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
||||||
memcpy(lcd->writebuf + pos, str, len);
|
memcpy(lcd->writebuf.text + pos, str, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hyperoptimized function to write a formatted string to lcd buffer. */
|
/* hyperoptimized function to write a formatted string to lcd buffer. */
|
||||||
@@ -89,21 +89,20 @@ inline void lcd_writef(struct lcd_t *lcd, const uint8_t x, const uint8_t y, cons
|
|||||||
uint8_t pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
|
uint8_t pos = 4 + x + (LCD_COLS * (y % 2)); // skip 4 bytes to leave room for set cursor command
|
||||||
if (y >= 2)
|
if (y >= 2)
|
||||||
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
pos += 2 * LCD_COLS + 4; // if we're writing to disp2, skip another 4 bytes for set cursor command and 2*40 bytes of disp 1
|
||||||
memcpy(lcd->writebuf + pos, tmp, len); // copy to lcd writebuffer address + whatever pos is
|
memcpy(lcd->writebuf.text + pos, tmp, len); // copy to lcd writebuffer address + whatever pos is
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void lcd_clear_buf(struct lcd_t *lcd) {
|
inline void lcd_clear_buf(struct lcd_t *lcd) {
|
||||||
memset(lcd->writebuf, ' ', sizeof(lcd->writebuf));
|
memset(lcd->writebuf.text, ' ', sizeof(lcd->writebuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */
|
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */
|
||||||
inline void lcd_flush_buf(struct lcd_t *lcd) {
|
inline void lcd_flush_buf(struct lcd_t *lcd) {
|
||||||
const uint8_t set_disp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
|
const uint8_t set_disp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
|
||||||
memcpy(&lcd->writebuf[0], set_disp, 4);
|
memcpy(&lcd->writebuf.text[0], set_disp, 4);
|
||||||
memcpy(&lcd->writebuf[2 * LCD_COLS + 4], set_disp, 4);
|
memcpy(&lcd->writebuf.text[2 * LCD_COLS + 4], set_disp, 4);
|
||||||
lcd->writebuf[2 * LCD_COLS + 7] = 3; // overwrite set cursor c1 l1 to c1 l3
|
lcd->writebuf.text[2 * LCD_COLS + 7] = 3; // overwrite set cursor c1 l1 to c1 l3
|
||||||
// hacky, relies on charbuf being before writebuf in the lcd struct. we start at the charbuf pointer and write both at the same time
|
lcd_write(lcd, (const uint8_t *)&lcd->writebuf, sizeof(lcd->writebuf));
|
||||||
lcd_write(lcd, (const uint8_t *)lcd->ccharbuf, sizeof(lcd->ccharbuf) + sizeof(lcd->writebuf));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// i have a whole flushbuf func to avoid too many writes, but im writing on every bar, need to rethink this.
|
// i have a whole flushbuf func to avoid too many writes, but im writing on every bar, need to rethink this.
|
||||||
@@ -133,7 +132,7 @@ int lcd_init(struct lcd_t *lcd) {
|
|||||||
// zero out custom chars
|
// zero out custom chars
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
const uint8_t charbuf[] = {254, 78, i, 0, 0, 0, 0, 0, 0, 0, 0};
|
const uint8_t charbuf[] = {254, 78, i, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
memcpy(lcd->ccharbuf[i], charbuf, sizeof(charbuf));
|
memcpy(lcd->writebuf.cchar[i], charbuf, sizeof(charbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd_clear_buf(lcd);
|
lcd_clear_buf(lcd);
|
||||||
|
|||||||
Reference in New Issue
Block a user