/* * lcd.h - Subroutines for communicating with HD44780U based LCD panels * Copyright (C) 2024 Alexander Rosenberg * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. See the LICENSE file for more information. */ #ifndef INCLUDED_LCD_H #define INCLUDED_LCD_H #include #include #include typedef struct { gpio_handle_t handle; // pin numbers int rs; // register select int rw; // read-write int en; // enable int d0; int d1; int d2; int d3; int d4; int d5; int d6; int d7; // internal use bool is_read; } LCD; /* * Allocate and initialize a new LCD object and return a pointer to it. HANDLE * is a gpio_handle_t, each of the other arguments corresponds to the GPIO pin * number that the given controller pin is connected to: "register select", * "read-write", "enable", and data pins 0-7. * Return: the newly created object. */ LCD *lcd_open(gpio_handle_t handle, int rs, int rw, int en, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7); /* * Close LCD by freeing any resources associated with it. */ void lcd_close(LCD *lcd); /* * Call a single instruction on LCD. Each argument is the value of that pin. */ void lcd_call(LCD *lcd, int rs, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7); /* * Write character C to LCD. */ void lcd_write_char(LCD *lcd, char c); /* * Write STR to LCD. * Return: the number of characters written. */ size_t lcd_write_string(LCD *lcd, const char *str); /* * Move the cursor to COL on LINE, which both start from 0. */ void lcd_move_to(LCD *lcd, int line, int col); /* * Clear LCD and return the cursor to the top right. */ void lcd_clear(LCD *lcd); #define LCD_DISPLAY_ON 1 #define LCD_DISPLAY_OFF 0 #define LCD_CURSOR_ON 1 #define LCD_CURSOR_OFF 0 #define LCD_CURSOR_BLINK 1 #define LCD_CURSOR_NO_BLINK 0 /* * Control B, cursor blink, C, cursor visibility, and D, display power for LCD. */ void lcd_display_control(LCD *lcd, int b, int c, int d); #define LCD_INCREMENT 1 #define LCD_DECREMENT 0 #define LCD_DISPLAY_SHIFT 1 #define LCD_CURSOR_MOVE 0 #define LCD_SHIFT_RIGHT 1 #define LCD_SHIFT_LEFT 0 /* * Control shift and increment for LCD. */ void lcd_entry_mode(LCD *lcd, int id, int s); /* * Control direction and shift/move for cursor for LCD. */ void lcd_cursor_shift(LCD *lcd, int sc, int rl); /* * Return: weather the busy flag is set for LCD. */ bool lcd_is_busy(LCD *lcd); #endif