118 lines
3.3 KiB
C
118 lines
3.3 KiB
C
/*
|
|
* 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 <sys/types.h>
|
|
#include <libgpio.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
gpio_handle_t handle;
|
|
// pin numbers
|
|
gpio_pin_t rs; // register select
|
|
gpio_pin_t rw; // read-write
|
|
gpio_pin_t en; // enable
|
|
gpio_pin_t d0;
|
|
gpio_pin_t d1;
|
|
gpio_pin_t d2;
|
|
gpio_pin_t d3;
|
|
gpio_pin_t d4;
|
|
gpio_pin_t d5;
|
|
gpio_pin_t d6;
|
|
gpio_pin_t d7;
|
|
int32_t bl;
|
|
|
|
// gpio_value_ternal use
|
|
bool is_read;
|
|
} LCD;
|
|
|
|
/*
|
|
* Allocate and initialize a new LCD object and return a pogpio_value_ter 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. If BL is 0 or greater, it is a pin
|
|
* that will enable the backlight when HIGH, and disable the backlight when LOW.
|
|
* Return: the newly created object.
|
|
*/
|
|
LCD *lcd_open(gpio_handle_t handle, gpio_pin_t rs, gpio_pin_t rw, gpio_pin_t en,
|
|
gpio_pin_t d0, gpio_pin_t d1, gpio_pin_t d2, gpio_pin_t d3,
|
|
gpio_pin_t d4, gpio_pin_t d5, gpio_pin_t d6, gpio_pin_t d7,
|
|
int32_t bl);
|
|
/*
|
|
* 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, gpio_value_t rs, gpio_value_t d0, gpio_value_t d1,
|
|
gpio_value_t d2, gpio_value_t d3, gpio_value_t d4,
|
|
gpio_value_t d5, gpio_value_t d6, gpio_value_t 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, gpio_value_t line, gpio_value_t 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, gpio_value_t b, gpio_value_t c, gpio_value_t 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, gpio_value_t id, gpio_value_t s);
|
|
|
|
/*
|
|
* Control direction and shift/move for cursor for LCD.
|
|
*/
|
|
void lcd_cursor_shift(LCD *lcd, gpio_value_t sc, gpio_value_t rl);
|
|
|
|
/*
|
|
* Return: weather the busy flag is set for LCD.
|
|
*/
|
|
bool lcd_is_busy(LCD *lcd);
|
|
|
|
/*
|
|
* Set the backlight's power to ENABLE.
|
|
*/
|
|
void lcd_backlight_set_enabled(LCD *lcd, bool enable);
|
|
|
|
#endif
|