diff --git a/drivers/input/button_upper.c b/drivers/input/button_upper.c index 130443f39e..9ad42e5189 100644 --- a/drivers/input/button_upper.c +++ b/drivers/input/button_upper.c @@ -60,6 +60,7 @@ struct btn_upperhalf_s FAR const struct btn_lowerhalf_s *bu_lower; btn_buttonset_t bu_sample; /* Last sampled button states */ + bool bu_enabled; /* The following is a singly linked list of open references to the * button device. @@ -190,6 +191,16 @@ static void btn_enable(FAR struct btn_upperhalf_s *priv) DEBUGASSERT(lower->bl_enable); if (press != 0 || release != 0) { + /* Update last sampled button states when enabling interrupts for + * the first time. + */ + + if (!priv->bu_enabled) + { + priv->bu_enabled = true; + priv->bu_sample = lower->bl_buttons(lower); + } + /* Enable interrupts with the new button set */ lower->bl_enable(lower, press, release, @@ -197,6 +208,8 @@ static void btn_enable(FAR struct btn_upperhalf_s *priv) } else { + priv->bu_enabled = false; + /* Disable further interrupts */ lower->bl_enable(lower, 0, 0, NULL, NULL); @@ -332,6 +345,7 @@ static int btn_open(FAR struct file *filep) supported = lower->bl_supported(lower); opriv->bo_pollevents.bp_press = supported; opriv->bo_pollevents.bp_release = supported; + opriv->bo_pending = true; /* Attach the open structure to the device */ @@ -780,9 +794,6 @@ int btn_register(FAR const char *devname, priv->bu_lower = lower; - DEBUGASSERT(lower->bl_buttons); - priv->bu_sample = lower->bl_buttons(lower); - /* And register the button driver */ ret = register_driver(devname, &g_btn_fops, 0666, priv);