After turning on the system by power button, the first press of the power button is ineffective.

Signed-off-by: liushuai25 <liushuai25@xiaomi.com>
Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
liushuai25 2023-09-07 19:36:30 +08:00 committed by Petro Karashchenko
parent 1b97c05ab5
commit 10fce11e19
1 changed files with 14 additions and 3 deletions

View File

@ -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);