Some additional, minor improvements to djoystick interrupt controls

This commit is contained in:
Gregory Nutt 2014-11-27 20:20:10 -06:00
parent 3909f28060
commit 2d9bd07525
2 changed files with 22 additions and 10 deletions

View File

@ -190,7 +190,8 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
{ {
FAR const struct djoy_lowerhalf_s *lower = priv->du_lower; FAR const struct djoy_lowerhalf_s *lower = priv->du_lower;
FAR struct djoy_open_s *opriv; FAR struct djoy_open_s *opriv;
djoy_buttonset_t intmask; djoy_buttonset_t press;
djoy_buttonset_t release;
irqstate_t flags; irqstate_t flags;
#ifndef CONFIG_DISABLE_POLL #ifndef CONFIG_DISABLE_POLL
int i; int i;
@ -207,7 +208,9 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
/* Visit each opened reference to the device */ /* Visit each opened reference to the device */
intmask = 0; press = 0;
release = 0;
for (opriv = priv->du_open; opriv; opriv = opriv->do_flink) for (opriv = priv->du_open; opriv; opriv = opriv->do_flink)
{ {
#ifndef CONFIG_DISABLE_POLL #ifndef CONFIG_DISABLE_POLL
@ -219,8 +222,8 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
{ {
/* Yes.. OR in the poll event buttons */ /* Yes.. OR in the poll event buttons */
intmask |= (opriv->do_pollevents.dp_press | press |= opriv->do_pollevents.dp_press;
opriv->do_pollevents.dp_release); release |= opriv->do_pollevents.dp_release;
break; break;
} }
} }
@ -229,24 +232,26 @@ static void djoy_enable(FAR struct djoy_upperhalf_s *priv)
#ifndef CONFIG_DISABLE_SIGNALS #ifndef CONFIG_DISABLE_SIGNALS
/* OR in the signal events */ /* OR in the signal events */
intmask |= (opriv->do_notify.dn_press | opriv->do_notify.dn_release); press |= opriv->do_notify.dn_press;
release |= opriv->do_notify.dn_release;
#endif #endif
} }
/* Enable/disable button interrupts */ /* Enable/disable button interrupts */
DEBUGASSERT(lower->dl_enable); DEBUGASSERT(lower->dl_enable);
if (intmask != 0) if (press != 0 || release != 0)
{ {
/* Enable interrupts with the new button set */ /* Enable interrupts with the new button set */
lower->dl_enable(lower, intmask, (djoy_interrupt_t)djoy_interrupt, priv); lower->dl_enable(lower, press, release,
(djoy_interrupt_t)djoy_interrupt, priv);
} }
else else
{ {
/* Disable further interrupts */ /* Disable further interrupts */
lower->dl_enable(lower, 0, NULL, NULL); lower->dl_enable(lower, 0, 0, NULL, NULL);
} }
irqrestore(flags); irqrestore(flags);
@ -812,7 +817,7 @@ int djoy_register(FAR const char *devname,
/* Make sure that all djoystick interrupts are disabled */ /* Make sure that all djoystick interrupts are disabled */
DEBUGASSERT(lower->dl_enable); DEBUGASSERT(lower->dl_enable);
lower->dl_enable(lower, (djoy_buttonset_t)0, NULL, NULL); lower->dl_enable(lower, 0, 0, NULL, NULL);
/* Initialize the new djoystick driver instance */ /* Initialize the new djoystick driver instance */

View File

@ -82,6 +82,13 @@
#define DJOY_BUTTON_3 (1 << 7) /* Bit 7: True = Button 4 pressed */ #define DJOY_BUTTON_3 (1 << 7) /* Bit 7: True = Button 4 pressed */
#define DJOY_BUTTONS_ALL 0xff /* The set of all buttons */ #define DJOY_BUTTONS_ALL 0xff /* The set of all buttons */
/* Typical usage */
#define DJOY_BUTTON_SELECT DJOY_BUTTON_1
#define DJOY_BUTTON_FIRE DJOY_BUTTON_2
#define DJOY_BUTTON_JUMP DJOY_BUTTON_3
#define DJOY_BUTTON_RUN DJOY_BUTTON_4
/* IOCTL commands /* IOCTL commands
* *
* Discrete joystick drivers do not support the character driver write() or * Discrete joystick drivers do not support the character driver write() or
@ -185,7 +192,7 @@ struct djoy_lowerhalf_s
*/ */
CODE void (*dl_enable)(FAR const struct djoy_lowerhalf_s *lower, CODE void (*dl_enable)(FAR const struct djoy_lowerhalf_s *lower,
djoy_buttonset_t buttons, djoy_buttonset_t press, djoy_buttonset_t release,
djoy_interrupt_t handler, FAR void *arg); djoy_interrupt_t handler, FAR void *arg);
}; };