Skip to content

Commit

Permalink
drivers/hd44780: optimize detection of 4 and 8 bit modes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aabadie committed Nov 6, 2019
1 parent 6c56972 commit 62d2994
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions drivers/hd44780/hd44780.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 62d2994

Please # to comment.