From 62d299459fd2d14344b20a15e2016ac7f4ac5433 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Wed, 6 Nov 2019 16:27:39 +0100 Subject: [PATCH] drivers/hd44780: optimize detection of 4 and 8 bit modes The driver can only be used with either 4 or 8 bit modes. Checking if the 5th pin is set in the configuration is enough the determine if 8bit mode should be used or not --- drivers/hd44780/hd44780.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/hd44780/hd44780.c b/drivers/hd44780/hd44780.c index 4895c9b9db..dc6e2ba5af 100644 --- a/drivers/hd44780/hd44780.c +++ b/drivers/hd44780/hd44780.c @@ -110,20 +110,13 @@ int hd44780_init(hd44780_t *dev, const hd44780_params_t *params) LOG_ERROR("hd44780_init: invalid LCD size!\n"); return -1; } - uint8_t count_pins = 0; - /* check which pins are used */ - for (unsigned i = 0; i < HD44780_MAX_PINS; ++i) { - if (dev->p.data[i] != GPIO_UNDEF) { - ++count_pins; - } - } - /* set mode depending on configured pins */ dev->flag = 0; - if (count_pins < HD44780_MAX_PINS) { - dev->flag |= HD44780_4BITMODE; + /* set mode depending on configured pins */ + if (dev->p.data[4] != GPIO_UNDEF) { + dev->flag |= HD44780_8BITMODE; } else { - dev->flag |= HD44780_8BITMODE; + dev->flag |= HD44780_4BITMODE; } /* set flag for 1 or 2 row mode, 4 rows are 2 rows split half */ if (dev->p.rows > 1) {