ST7123 Capacitive Touchscreen
What is the ST7123. The ST7123 is an I2C capacitive multi-touch controller used on TDDI (Touch and Display Driver Integration) panels. It reports up to ten simultaneous contacts, optional gesture codes, and contact intensity. The same I2C register map is also used by related parts such as the ST7121.
Purpose. The ST7123 driver is a touchscreen lower-half that probes
the controller over I2C, reads complete touch frames on interrupt, and
delivers multi-touch samples through the common touchscreen upper-half.
Once registered, the device appears as /dev/inputN and applications
read struct touch_sample_s samples as described in
Touchscreen Device Drivers.
Driver Overview. The board supplies a persistent
struct st7123_config_s whose attach member wires the controller
INT pin to the driver interrupt handler. st7123_register() probes
the part, registers /dev/inputN, then calls config->attach() with
the driver ISR and the allocated device instance as arg. On each
falling edge of INT the ISR queues st7123_data_worker() on the
high-priority work queue. The worker fetches one full touch frame
(advanced-touch header plus every touch area) in a single I2C
transaction, converts per-area valid bits into TOUCH_DOWN /
TOUCH_MOVE / TOUCH_UP transitions, and pushes the sample with
touch_event(). The upper half stores the sample in a circular
buffer for read() / poll() clients.
Configuration. Enable the driver with:
CONFIG_INPUT=yCONFIG_INPUT_TOUCHSCREEN=yCONFIG_INPUT_ST7123=yCONFIG_SCHED_HPWORK=y(required; frame processing runs on HPWORK)CONFIG_INPUT_ST7123_I2C_FREQUENCY(default400000)CONFIG_INPUT_ST7123_I2C_ADDRESS(default0x55)
Board Support. To support the ST7123 a board must provide:
I2C Bus
An initialized
struct i2c_master_sinstance that can reach the controller atCONFIG_INPUT_ST7123_I2C_ADDRESS.
Board Configuration / Interrupt Attach
A persistent
struct st7123_config_swhoseattachmember configures the INT GPIO (typically active-low / falling edge with pull-up) and connects it to the givenxcpt_thandler, passing through the opaqueargprovided by the driver.attachmust remain valid for the lifetime of the driver; the structure is not copied.Registration fails with
-EINVALifconfigorconfig->attachisNULL.
Registration Hook
Call
st7123_register(i2c, minor, &config)during board bring-up. The driver attaches and may enable the interrupt only aftertouch_register()succeeds, so an early edge cannot reach an uninitialized device.
Example board wiring:
static int board_st7123_attach(FAR const struct st7123_config_s *config,
xcpt_t isr, FAR void *arg)
{
/* Configure the INT GPIO and attach isr(arg) to it */
}
static const struct st7123_config_s g_st7123_config =
{
.attach = board_st7123_attach,
};
int err = st7123_register(i2c, 0, &g_st7123_config);
Data Path Summary.
Board obtains the I2C master and calls
st7123_register(i2c, 0, &g_st7123_config)st7123_register()allocates the device instance, probes firmware / resolution / touch count, fillsstruct touch_lowerhalf_s, and callstouch_register(..., "/dev/input0", maxpoint)config->attach()wires the INT pin to the driver ISR with the device instance asargEach INT schedules
st7123_data_worker()on HPWORKThe worker reads the frame starting at register
0x10and reports contacts throughtouch_event()Applications open
/dev/input0and readstruct touch_sample_s(sized withSIZEOF_TOUCH_SAMPLE_S(n))
Open / Close Behavior.
open()powers the controller up (clearsDEV_CTRL), disables smart-wakeup with a read-modify-write ofMISC_CTRLwhen the part advertises that feature, and waits untilSTATUSreportsNORMAL.close()sets the power-down bit inDEV_CTRLand verifies thatSTATUSreportsPOWER_DOWN.
Touch Samples. Each reported contact uses the touch-area index as
its stable id. Flags follow the common touchscreen conventions:
First contact:
TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID | TOUCH_PRESSURE_VALIDContinued contact:
TOUCH_MOVEwith the same validity bitsLost contact:
TOUCH_UP | TOUCH_ID_VALID | TOUCH_POS_VALIDat the last known coordinates
Supported gesture codes from the controller are mapped onto the common
TOUCH_* gesture values (double-click and slide directions).
Application Notes.
read()returns a variable-length sample. Buffers must be at leastSIZEOF_TOUCH_SAMPLE_S(maxpoint)bytes; reading onlysizeof(struct touch_sample_s)(one contact) desynchronizes the stream when multiple fingers are down.The example under
apps/examples/touchscreencurrently assumes a single-point sample size and is not suitable for multi-touch testing without a larger read buffer.Header:
include/nuttx/input/st7123.hDriver:
drivers/input/st7123.c