Merged in hardlulz/modem-3.0-nuttx/fix-stmpe811-gpio (pull request #523)

Fix GPIO operation of STMPE811 driver.

Fixed issues:
1. STMPE811_GPIO_DIR was defined for register name
   and later was redefined to be the pin direction mask
   for `stmpe811_gpioconfig`

   I decided to change register name to be STMPE811_GPIO_DIR_REG,
   and keep pin direction mask STMPE811_GPIO_DIR, so that any
   external code that already use this driver will be unchanged.

2. The STMPE811 register GPIO_DIR uses bit value 1 for output
   and 0 for input, but `stmpe811_gpioconfig` set the opposite.

3. The call to `stmpe811_gpiowrite` from inside of `stmpe811_gpioconfig`
   leaded to deadlock.

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Dmitriy Linikov 2017-10-31 16:54:28 +00:00 committed by Gregory Nutt
parent 09d4874509
commit 61372551e9
2 changed files with 17 additions and 10 deletions

View file

@ -172,22 +172,29 @@ int stmpe811_gpioconfig(STMPE811_HANDLE handle, uint8_t pinconfig)
{
/* The pin is an output */
regval = stmpe811_getreg8(priv, STMPE811_GPIO_DIR);
regval &= ~pinmask;
stmpe811_putreg8(priv, STMPE811_GPIO_DIR, regval);
regval = stmpe811_getreg8(priv, STMPE811_GPIO_DIR_REG);
regval |= pinmask;
stmpe811_putreg8(priv, STMPE811_GPIO_DIR_REG, regval);
/* Set its initial output value */
stmpe811_gpiowrite(handle, pinconfig,
(pinconfig & STMPE811_GPIO_VALUE) != STMPE811_GPIO_ZERO);
if ((pinconfig & STMPE811_GPIO_VALUE) != STMPE811_GPIO_ZERO)
{
/* Set the output valu(s)e by writing to the SET register */
stmpe811_putreg8(priv, STMPE811_GPIO_SETPIN, (1 << pin));
}
else
{
/* Clear the output value(s) by writing to the CLR register */
stmpe811_putreg8(priv, STMPE811_GPIO_CLRPIN, (1 << pin));
}
}
else
{
/* It is an input */
regval = stmpe811_getreg8(priv, STMPE811_GPIO_DIR);
regval |= pinmask;
stmpe811_putreg8(priv, STMPE811_GPIO_DIR, regval);
regval = stmpe811_getreg8(priv, STMPE811_GPIO_DIR_REG);
regval &= ~pinmask;
stmpe811_putreg8(priv, STMPE811_GPIO_DIR_REG, regval);
/* Set up the falling edge detection */

View file

@ -190,7 +190,7 @@
#define STMPE811_GPIO_SETPIN 0x10 /* GPIO set pin register */
#define STMPE811_GPIO_CLRPIN 0x11 /* GPIO clear pin register */
#define STMPE811_GPIO_MPSTA 0x12 /* GPIO monitor pin state register */
#define STMPE811_GPIO_DIR 0x13 /* GPIO direction register */
#define STMPE811_GPIO_DIR_REG 0x13 /* GPIO direction register */
#define STMPE811_GPIO_ED 0x14 /* GPIO edge detect register */
#define STMPE811_GPIO_RE 0x15 /* GPIO rising edge register */
#define STMPE811_GPIO_FE 0x16 /* GPIO falling edge register */