Message ID | 20240119-feature-ts_virtobj_patch-v7-4-eda70985808f@wolfvision.net (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Input: support overlay objects on touchscreens | expand |
Hi Javier, On Fri, Jan 19, 2024 at 08:43:36AM +0100, Javier Carrasco wrote: > Use touch-overlay to support overlay objects such as buttons and a resized > frame defined in the device tree. > > If buttons are provided, register an additional device to report key > events separately. A key event will be generated if the coordinates > of a touch event are within the area defined by the button properties. > > Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net> Reviewed-by: Jeff LaBundy <jeff@labundy.com> > --- > drivers/input/touchscreen/st1232.c | 48 +++++++++++++++++++++++++++----------- > 1 file changed, 34 insertions(+), 14 deletions(-) > > diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c > index 6475084aee1b..4fa31447dbc1 100644 > --- a/drivers/input/touchscreen/st1232.c > +++ b/drivers/input/touchscreen/st1232.c > @@ -22,6 +22,7 @@ > #include <linux/pm_qos.h> > #include <linux/slab.h> > #include <linux/types.h> > +#include <linux/input/touch-overlay.h> > > #define ST1232_TS_NAME "st1232-ts" > #define ST1633_TS_NAME "st1633-ts" > @@ -57,6 +58,7 @@ struct st1232_ts_data { > struct dev_pm_qos_request low_latency_req; > struct gpio_desc *reset_gpio; > const struct st_chip_info *chip_info; > + struct list_head touch_overlay_list; > int read_buf_len; > u8 *read_buf; > }; > @@ -138,14 +140,20 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) > > for (i = 0; i < ts->chip_info->max_fingers; i++) { > u8 *buf = &ts->read_buf[i * 4]; > + bool contact = buf[0] & BIT(7); > + unsigned int x, y; > > - if (buf[0] & BIT(7)) { > - unsigned int x = ((buf[0] & 0x70) << 4) | buf[1]; > - unsigned int y = ((buf[0] & 0x07) << 8) | buf[2]; > - > - touchscreen_set_mt_pos(&pos[n_contacts], > - &ts->prop, x, y); > + if (contact) { > + x = ((buf[0] & 0x70) << 4) | buf[1]; > + y = ((buf[0] & 0x07) << 8) | buf[2]; > + } > + if (touch_overlay_process_event(&ts->touch_overlay_list, input, > + contact ? &x : NULL, > + contact ? &y : NULL, i)) > + continue; > > + if (contact) { > + touchscreen_set_mt_pos(&pos[n_contacts], &ts->prop, x, y); > /* st1232 includes a z-axis / touch strength */ > if (ts->chip_info->have_z) > z[n_contacts] = ts->read_buf[i + 6]; > @@ -292,18 +300,30 @@ static int st1232_ts_probe(struct i2c_client *client) > if (error) > return error; > > - /* Read resolution from the chip */ > - error = st1232_ts_read_resolution(ts, &max_x, &max_y); > - if (error) { > - dev_err(&client->dev, > - "Failed to read resolution: %d\n", error); > - return error; > - } > - > if (ts->chip_info->have_z) > input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, > ts->chip_info->max_area, 0, 0); > > + /* map overlay objects if defined in the device tree */ > + INIT_LIST_HEAD(&ts->touch_overlay_list); > + error = touch_overlay_map(&ts->touch_overlay_list, input_dev); > + if (error) > + return error; > + > + if (touch_overlay_mapped_touchscreen(&ts->touch_overlay_list)) { > + /* Read resolution from the overlay touchscreen if defined */ > + touch_overlay_get_touchscreen_abs(&ts->touch_overlay_list, > + &max_x, &max_y); > + } else { > + /* Read resolution from the chip */ > + error = st1232_ts_read_resolution(ts, &max_x, &max_y); > + if (error) { > + dev_err(&client->dev, > + "Failed to read resolution: %d\n", error); > + return error; > + } > + } > + > input_set_abs_params(input_dev, ABS_MT_POSITION_X, > 0, max_x, 0, 0); > input_set_abs_params(input_dev, ABS_MT_POSITION_Y, > > -- > 2.39.2 > Kind regards, Jeff LaBundy
diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c index 6475084aee1b..4fa31447dbc1 100644 --- a/drivers/input/touchscreen/st1232.c +++ b/drivers/input/touchscreen/st1232.c @@ -22,6 +22,7 @@ #include <linux/pm_qos.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/input/touch-overlay.h> #define ST1232_TS_NAME "st1232-ts" #define ST1633_TS_NAME "st1633-ts" @@ -57,6 +58,7 @@ struct st1232_ts_data { struct dev_pm_qos_request low_latency_req; struct gpio_desc *reset_gpio; const struct st_chip_info *chip_info; + struct list_head touch_overlay_list; int read_buf_len; u8 *read_buf; }; @@ -138,14 +140,20 @@ static int st1232_ts_parse_and_report(struct st1232_ts_data *ts) for (i = 0; i < ts->chip_info->max_fingers; i++) { u8 *buf = &ts->read_buf[i * 4]; + bool contact = buf[0] & BIT(7); + unsigned int x, y; - if (buf[0] & BIT(7)) { - unsigned int x = ((buf[0] & 0x70) << 4) | buf[1]; - unsigned int y = ((buf[0] & 0x07) << 8) | buf[2]; - - touchscreen_set_mt_pos(&pos[n_contacts], - &ts->prop, x, y); + if (contact) { + x = ((buf[0] & 0x70) << 4) | buf[1]; + y = ((buf[0] & 0x07) << 8) | buf[2]; + } + if (touch_overlay_process_event(&ts->touch_overlay_list, input, + contact ? &x : NULL, + contact ? &y : NULL, i)) + continue; + if (contact) { + touchscreen_set_mt_pos(&pos[n_contacts], &ts->prop, x, y); /* st1232 includes a z-axis / touch strength */ if (ts->chip_info->have_z) z[n_contacts] = ts->read_buf[i + 6]; @@ -292,18 +300,30 @@ static int st1232_ts_probe(struct i2c_client *client) if (error) return error; - /* Read resolution from the chip */ - error = st1232_ts_read_resolution(ts, &max_x, &max_y); - if (error) { - dev_err(&client->dev, - "Failed to read resolution: %d\n", error); - return error; - } - if (ts->chip_info->have_z) input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, ts->chip_info->max_area, 0, 0); + /* map overlay objects if defined in the device tree */ + INIT_LIST_HEAD(&ts->touch_overlay_list); + error = touch_overlay_map(&ts->touch_overlay_list, input_dev); + if (error) + return error; + + if (touch_overlay_mapped_touchscreen(&ts->touch_overlay_list)) { + /* Read resolution from the overlay touchscreen if defined */ + touch_overlay_get_touchscreen_abs(&ts->touch_overlay_list, + &max_x, &max_y); + } else { + /* Read resolution from the chip */ + error = st1232_ts_read_resolution(ts, &max_x, &max_y); + if (error) { + dev_err(&client->dev, + "Failed to read resolution: %d\n", error); + return error; + } + } + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, max_x, 0, 0); input_set_abs_params(input_dev, ABS_MT_POSITION_Y,
Use touch-overlay to support overlay objects such as buttons and a resized frame defined in the device tree. If buttons are provided, register an additional device to report key events separately. A key event will be generated if the coordinates of a touch event are within the area defined by the button properties. Signed-off-by: Javier Carrasco <javier.carrasco@wolfvision.net> --- drivers/input/touchscreen/st1232.c | 48 +++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-)