/* 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. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ /** library to communication with Hitacho HD44780 LCD controller * @file * @author King Kévin * @date 2019 * @note peripherals used: GPIO @ref lcd_hd44780_gpio */ #pragma once /** set to 1 if R/nW is connected to ground, 0 else * @note the R/nW pin allows to read or write from/to the controller. this enables read back data, but more importantly read the busy flag to know when the controller finished processing the command. * @note tying R/nW to ground instead of a GPIO saves a pin, but no data can be read back. Also every command needs to wait a minimum time before being able to send the next one, even if the controlled might actually already have processed it and is not busy anymore. */ #define LCD_HD44780_WRITE_ONLY 0 /** setup peripherals to start communicating with HD4478 * @param[in] n_2lines 2 (true) or 1 (false) lines * @param[in] f_5x10 5x10 (true) or 5x8 (false) dots font */ void lcd_hd44780_setup(bool n_2lines, bool f_5x10); /** release peripherals */ void lcd_hd44780_release(void); /** wait until controller is not busy anymore * @param[in] timeout maximum time to wait in us * @return address count, or >= 0x80 if timeout expired */ uint8_t lcd_hd44780_wait_busy(uint16_t timeout); #if !LCD_HD44780_WRITE_ONLY /** read data (from CG or DDRAM) * @return read data */ uint8_t lcd_hd44780_read_data(void); #endif /** write data (to CG or DDRAM) * @param[in] data data to write * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37) */ void lcd_hd44780_write_data(uint8_t data); /** write command * @param[in] data instruction to write * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37) */ void lcd_hd44780_write_command(uint8_t data); /** clears entire display and sets DDRAM address 0 in address counter * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(1520) */ void lcd_hd44780_clear_display(void); /** sets DDRAM address 0 in address counter, also returns display from being shifted to original position * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(1520); */ void lcd_hd44780_return_home(void); /** sets cursor move direction and specifies display shift * @param[in] increment true = increment, false = decrement * @param[in] shift true = accompanies display shift * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37); */ void lcd_hd44780_entry_mode_set(bool increment, bool shift); /** set display control * @param[in] d entire display on (true) / off (false) * @param[in] c cursor on (true) / off (false) * @param[in] b blinking of cursor position character on (true) / off (false) * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37); */ void lcd_hd44780_display_control(bool d, bool c, bool b); /** sets CGRAM address. CGRAM data is sent and received after this setting. * @param[in] acg CGRAM address * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37); */ void lcd_hd44780_set_cgram_address(uint8_t acg); /** sets DDRAM address. DDRAM data is sent and received after this setting. * @param[in] add DDRAM address * @warning does not wait for operation to complete: use lcd_hd44780_wait_busy(37); */ void lcd_hd44780_set_ddram_address(uint8_t add); /** utility to write entire line * @param[in] line2 write line 1 (false) or 2 (true) * @param[in] data characters to write on the line * @param[in] length number of characters to write */ void lcd_hd44780_write_line(bool line2, const char* data, uint8_t length);