hyperoptimized file reading

This commit is contained in:
2026-08-14 18:00:02 +02:00
parent 901d5b53d9
commit 81cfc2ce0d
8 changed files with 172 additions and 150 deletions

View File

@@ -10,10 +10,7 @@
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int lcd_open(struct lcd_t *lcd, bool reopen);
void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, uint16_t len);
int lcd_open(struct lcd_t *lcd, const bool reopen) {
static int lcd_open(struct lcd_t *lcd, const bool reopen) {
applog(LOG_INF, "Opening serial port at %s", lcd->port);
if (lcd->fd <= 0 || reopen)
lcd->fd = open(lcd->port, O_WRONLY | O_NOCTTY);
@@ -36,7 +33,7 @@ void lcd_close(struct lcd_t *lcd) {
lcd->fd = -1;
}
void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, const uint16_t len) {
static void lcd_write(struct lcd_t *lcd, const uint8_t *cmdbuf, const uint16_t len) {
if (write(lcd->fd, cmdbuf, len) <= 0) {
applog(LOG_ERR, "failed to execute write(), lost access to port?");
lcd_close(lcd);
@@ -109,7 +106,7 @@ inline void lcd_clear_buf(struct lcd_t *lcd) {
/* flushes writebuffer to lcd, hyperoptmized, flushes buffer and commands in a single write operation */
inline void lcd_flush_buf(struct lcd_t *lcd) {
void lcd_flush_buf(struct lcd_t *lcd) {
constexpr uint8_t set_disp[] = {254, 71, 1, 1}; // set cursor to char 1, line 1
memcpy(&lcd->writebuf.text[0], set_disp, 4);
memcpy(&lcd->writebuf.text[2 * LCD_COLS + 4], set_disp, 4);