Skip to content

Commit

Permalink
Merge pull request #12634 from aabadie/pr/drivers/hd44780_fix_sam0
Browse files Browse the repository at this point in the history
drivers/hd44780: fix potential hardfault during initialization
  • Loading branch information
aabadie authored Nov 6, 2019
2 parents 8c181d8 + 62d2994 commit 08e1cf2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions drivers/hd44780/hd44780.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +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;
}
}
dev->flag = 0;
/* set mode depending on configured pins */
if (count_pins < HD44780_MAX_PINS) {
dev->flag |= HD44780_4BITMODE;
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
2 changes: 1 addition & 1 deletion drivers/include/hd44780.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct {
gpio_t rs; /**< rs gpio pin */
gpio_t rw; /**< rw gpio pin */
gpio_t enable; /**< enable gpio pin */
gpio_t data[8]; /**< data gpio pins */
gpio_t data[HD44780_MAX_PINS]; /**< data gpio pins */
} hd44780_params_t;

/**
Expand Down

0 comments on commit 08e1cf2

Please # to comment.