hd44780: fix I2C ifdef macro

This commit is contained in:
King Kévin 2020-02-13 14:28:41 +01:00
parent 3c71b83bb9
commit ff1b84f505
1 changed files with 8 additions and 10 deletions

View File

@ -31,7 +31,7 @@
/* own libraries */
#include "global.h" // common methods
#include "lcd_hd44780.h" // own definitions
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
#include "i2c_master.h" // I²C utilities
#endif
@ -39,7 +39,7 @@
* @note this removes the need to call lcd_hd44780_wait_busy but prevents you to do something else meanwhile, particularly when reading is enabled
* @note because I²C is already slow enough, there is no need to wait further
*/
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
#define LCD_HD44780_BUSY_WAIT_INCLUDE 1 // lcd_hd44780_wait_busy works, but the I²C bus is often slower
#else // LCD_HD44780_I2C
#define LCD_HD44780_BUSY_WAIT_INCLUDE 1 // you can change this value
@ -88,7 +88,7 @@
#define LCD_HD44780_LED (1 << 11) /**< Backlight Cathode */
/** @} */
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
/* I²C backpack PCF8574 GPIO expander pinout:
* - P0: RS
* - P1: RnW
@ -195,7 +195,7 @@ static bool lcd_hd44780_n_2lines = true;
*/
static void lcd_hd44780_set_signal(uint16_t signals)
{
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
if (signals & LCD_HD44780_RS) {
lcd_hd44780_i2c_output |= LCD_HD44780_I2C_RS;
}
@ -268,7 +268,7 @@ static void lcd_hd44780_set_signal(uint16_t signals)
*/
static void lcd_hd44780_clear_signal(uint16_t signals)
{
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
if (signals & LCD_HD44780_RS) {
lcd_hd44780_i2c_output &= ~LCD_HD44780_I2C_RS;
}
@ -342,7 +342,7 @@ static void lcd_hd44780_clear_signal(uint16_t signals)
*/
static void lcd_hd44780_flush_signal(void)
{
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
i2c_master_slave_write(LCD_HD44780_I2C_PERIPH, lcd_hd44780_i2c_addr, false, &lcd_hd44780_i2c_output, 1); // write the set signals
#endif
}
@ -619,7 +619,7 @@ static void lcd_hd44780_function_set(bool dl_8bit, bool n_2lines, bool f_5x10)
bool lcd_hd44780_setup(bool n_2lines, bool f_5x10)
{
sleep_ms(40 + 2); // wait for display to initialise after power on: 15 ms for VCC > 4.5 V, 40 ms for VCC > 2.7 V
#ifdef LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
// configure I²C peripheral
if (!i2c_master_check_signals(LCD_HD44780_I2C_PERIPH)) { // check if there are pull-ups to operator I²C
return false;
@ -694,14 +694,12 @@ bool lcd_hd44780_setup(bool n_2lines, bool f_5x10)
lcd_hd44780_entry_mode_set(true, false); // entry mode set
lcd_hd44780_wait_busy(LCD_HD44780_BUSY_WAIT_SHORT);
#if LCD_HD44780_I2C
return true; // I²C configuration succeeded
#endif
}
void lcd_hd44780_release(void)
{
#if LCD_HD44780_I2C
#if defined(LCD_HD44780_I2C) && LCD_HD44780_I2C
i2c_master_release(LCD_HD44780_I2C_PERIPH); // release I²C peripheral
#else // LCD_HD44780_I2C
// switch back GPIO back to input