stm32f103-minimum: Fix a small BUG when reading from output pin. We need a different read_ops to read from output pin. This patch fixes the issue:

nsh> gpio -o 0 /dev/gpout1
Driver: /dev/gpout1
  Output pin:    Value=1
  Writing:       Value=0
  Verify:        Value=1

Now:

nsh> gpio -o 0 /dev/gpout1
Driver: /dev/gpout1
  Output pin:    Value=1
  Writing:       Value=0
  Verify:        Value=0
This commit is contained in:
Alan Carvalho de Assis 2017-06-09 15:09:03 -06:00 committed by Gregory Nutt
parent db80696d21
commit fa2c7a694f

View File

@ -67,7 +67,6 @@ struct stm32gpio_dev_s
{ {
struct gpio_dev_s gpio; struct gpio_dev_s gpio;
uint8_t id; uint8_t id;
bool value;
}; };
struct stm32gpint_dev_s struct stm32gpint_dev_s
@ -81,6 +80,7 @@ struct stm32gpint_dev_s
****************************************************************************/ ****************************************************************************/
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value); static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpout_write(FAR struct gpio_dev_s *dev, bool value); static int gpout_write(FAR struct gpio_dev_s *dev, bool value);
static int gpint_attach(FAR struct gpio_dev_s *dev, static int gpint_attach(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback); pin_interrupt_t callback);
@ -100,7 +100,7 @@ static const struct gpio_operations_s gpin_ops =
static const struct gpio_operations_s gpout_ops = static const struct gpio_operations_s gpout_ops =
{ {
.go_read = gpin_read, .go_read = gpout_read,
.go_write = gpout_write, .go_write = gpout_write,
.go_attach = NULL, .go_attach = NULL,
.go_enable = NULL, .go_enable = NULL,
@ -167,17 +167,31 @@ static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value)
FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev; FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL && value != NULL); DEBUGASSERT(stm32gpio != NULL && value != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOIN);
gpioinfo("Reading...\n"); gpioinfo("Reading...\n");
*value = stm32_gpioread(g_gpioinputs[stm32gpio->id]); *value = stm32_gpioread(g_gpioinputs[stm32gpio->id]);
return OK; return OK;
} }
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL && value != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
gpioinfo("Reading...\n");
*value = stm32_gpioread(g_gpiooutputs[stm32gpio->id]);
return OK;
}
static int gpout_write(FAR struct gpio_dev_s *dev, bool value) static int gpout_write(FAR struct gpio_dev_s *dev, bool value)
{ {
FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev; FAR struct stm32gpio_dev_s *stm32gpio = (FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL); DEBUGASSERT(stm32gpio != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
gpioinfo("Writing %d\n", (int)value); gpioinfo("Writing %d\n", (int)value);
stm32_gpiowrite(g_gpiooutputs[stm32gpio->id], value); stm32_gpiowrite(g_gpiooutputs[stm32gpio->id], value);