driver/touchscreen: Add support for mirror/swap

Add support for mirror/swap coordinates.
There are some touchscreen drivers not support mirror or swap coordinates.
For example, drivers/input/ft5x06 does not support mirror.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3
2025-07-05 00:06:23 +08:00
committed by Alan C. Assis
parent 7cd5d3db72
commit ed1384fc81
3 changed files with 47 additions and 13 deletions
+34 -10
View File
@@ -81,8 +81,9 @@ static int touch_ioctl(FAR struct file *filep, int cmd,
static int touch_poll(FAR struct file *filep, FAR struct pollfd *fds, static int touch_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup); bool setup);
static void touch_event_notify(FAR struct touch_openpriv_s *openpriv, static void touch_event_notify(FAR struct touch_upperhalf_s *upper,
FAR const struct touch_sample_s *sample); FAR struct touch_openpriv_s *openpriv,
FAR struct touch_sample_s *sample);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -384,17 +385,40 @@ errout:
* Name: touch_event_notify * Name: touch_event_notify
****************************************************************************/ ****************************************************************************/
static void touch_event_notify(FAR struct touch_openpriv_s *openpriv, static void touch_event_notify(FAR struct touch_upperhalf_s *upper,
FAR const struct touch_sample_s *sample) FAR struct touch_openpriv_s *openpriv,
FAR struct touch_sample_s *sample)
{ {
int semcount; FAR struct touch_lowerhalf_s *lower = upper->lower;
FAR struct touch_point_s *point = sample->point;
int n;
for (n = 0; lower->flags && n < sample->npoints; n++)
{
if (lower->flags & TOUCH_FLAG_SWAPXY)
{
int16_t p = point[n].x;
point[n].x = point[n].y;
point[n].y = p;
}
if (lower->flags & TOUCH_FLAG_MIRRORX)
{
point[n].x = upper->lower->xres - point[n].x;
}
if (lower->flags & TOUCH_FLAG_MIRRORY)
{
point[n].y = upper->lower->yres - point[n].y;
}
}
nxmutex_lock(&openpriv->lock); nxmutex_lock(&openpriv->lock);
circbuf_overwrite(&openpriv->circbuf, sample, circbuf_overwrite(&openpriv->circbuf, sample,
SIZEOF_TOUCH_SAMPLE_S(sample->npoints)); SIZEOF_TOUCH_SAMPLE_S(sample->npoints));
nxsem_get_value(&openpriv->waitsem, &semcount); nxsem_get_value(&openpriv->waitsem, &n);
if (semcount < 1) if (n < 1)
{ {
nxsem_post(&openpriv->waitsem); nxsem_post(&openpriv->waitsem);
} }
@@ -411,7 +435,7 @@ static void touch_event_notify(FAR struct touch_openpriv_s *openpriv,
* Name: touch_event * Name: touch_event
****************************************************************************/ ****************************************************************************/
void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample) void touch_event(FAR void *priv, FAR struct touch_sample_s *sample)
{ {
FAR struct touch_upperhalf_s *upper = priv; FAR struct touch_upperhalf_s *upper = priv;
FAR struct touch_openpriv_s *openpriv; FAR struct touch_openpriv_s *openpriv;
@@ -423,14 +447,14 @@ void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
if (upper->grab) if (upper->grab)
{ {
touch_event_notify(upper->grab, sample); touch_event_notify(upper, upper->grab, sample);
} }
else else
{ {
list_for_every_entry(&upper->head, openpriv, list_for_every_entry(&upper->head, openpriv,
struct touch_openpriv_s, node) struct touch_openpriv_s, node)
{ {
touch_event_notify(openpriv, sample); touch_event_notify(upper, openpriv, sample);
} }
} }
+1 -2
View File
@@ -309,8 +309,7 @@ static ssize_t uinput_touch_notify(FAR void *uinput_lower,
{ {
FAR struct uinput_touch_lowerhalf_s *utcs_lower = FAR struct uinput_touch_lowerhalf_s *utcs_lower =
(FAR struct uinput_touch_lowerhalf_s *)uinput_lower; (FAR struct uinput_touch_lowerhalf_s *)uinput_lower;
FAR const struct touch_sample_s *sample = FAR struct touch_sample_s *sample = (FAR struct touch_sample_s *)buffer;
(FAR const struct touch_sample_s *)buffer;
touch_event(utcs_lower->lower.priv, sample); touch_event(utcs_lower->lower.priv, sample);
return buflen; return buflen;
+12 -1
View File
@@ -141,6 +141,14 @@
#define TOUCH_SIZE_VALID (1 << 6) /* Hardware provided a valid H/W contact size */ #define TOUCH_SIZE_VALID (1 << 6) /* Hardware provided a valid H/W contact size */
#define TOUCH_GESTURE_VALID (1 << 7) /* Hardware provided a valid gesture */ #define TOUCH_GESTURE_VALID (1 << 7) /* Hardware provided a valid gesture */
/* These definitions provide the meaning of all of the bits that may be
* reported in the struct touch_lowerhalf_s flags.
*/
#define TOUCH_FLAG_SWAPXY (1 << 0) /* Swap the X and Y coordinates */
#define TOUCH_FLAG_MIRRORX (1 << 1) /* Mirror X coordinate */
#define TOUCH_FLAG_MIRRORY (1 << 2) /* Mirror Y coordinate */
/* These are definitions for touch gesture */ /* These are definitions for touch gesture */
#define TOUCH_DOUBLE_CLICK (0x00) #define TOUCH_DOUBLE_CLICK (0x00)
@@ -234,6 +242,9 @@ struct touch_sample_s
struct touch_lowerhalf_s struct touch_lowerhalf_s
{ {
uint8_t maxpoint; /* Maximal point supported by the touchscreen */ uint8_t maxpoint; /* Maximal point supported by the touchscreen */
uint8_t flags; /* Flags for rotation, see TOUCH_FLAG_* */
uint16_t xres; /* Horizontal resolution in pixels */
uint16_t yres; /* Vertical resolution in pixels */
FAR void *priv; /* Save the upper half pointer */ FAR void *priv; /* Save the upper half pointer */
/************************************************************************** /**************************************************************************
@@ -333,7 +344,7 @@ static inline uint64_t touch_get_time(void)
* sample - pointer to data of touch point event. * sample - pointer to data of touch point event.
****************************************************************************/ ****************************************************************************/
void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample); void touch_event(FAR void *priv, FAR struct touch_sample_s *sample);
/**************************************************************************** /****************************************************************************
* Name: touch_register * Name: touch_register