34static const char*
s_tag =
"TOUCH";
40typedef enum : uint32_t {
156 uint8_t payload[k_payload_len];
162 (uint32_t)k_payload_len,
218 uint8_t emit = n_points;
219 if (emit > max_count) {
225 for (uint8_t i = 0U; i < emit; i++) {
467 if (emit > max_count) {
470 if (emit >
s_state.max_points) {
555 if (max_count == 0U) {
573[[nodiscard]]
ra8_err_t ra8_touch_test_decode(
const uint8_t* raw,
582 if (max_count == 0U) {
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_hw_init_failed
Hardware peripheral failed to initialise.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Injected I2C-bus seam consumed by Ring-3 I2C device drivers.
Interrupt Control Unit driver (IRQ pins, NMI).
ra8_err_t ra8_icu_configure_irq_pin(uint8_t irq_num, const ra8_icu_irq_cfg_t *cfg)
Programme one IRQCRi register.
@ k_ra8_icu_fclksel_pclkb
00: sample every PCLKB cycle.
@ k_ra8_icu_irqmd_falling
00: falling edge.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info(tag, message)
RA8 log info.
ra8_err_t ra8_touch_close(void)
Tear the driver down and detach any registered handler.
static ra8_err_t internal_gt911_read(uint16_t reg, uint8_t *buf, uint32_t len)
Read len bytes from the GT911 starting at reg.
static uint8_t internal_clamp_emit(uint8_t status_byte, uint8_t max_count)
Compute the actual number of touch records to drain.
ra8_err_t ra8_touch_open(const ra8_touch_cfg_t *cfg)
Bring up the touch IC over the injected I2C bus seam.
ra8_touch_internal_t
Implementation-only constants (no magic numbers).
@ k_ra8_touch_byte_shift
Bits per byte.
@ k_ra8_touch_product_id_byte0
First char of "911".
@ k_ra8_touch_irq_pin_count
Total ICU IRQ channels.
@ k_ra8_touch_byte_mask
8-bit byte mask.
static void internal_pack_reg(uint16_t reg, uint8_t *out_buf)
Pack a 16-bit GT911 register pointer into MSB-first wire order.
static void internal_decode_block(const uint8_t *raw, uint8_t n_points, ra8_touch_point_t *out, uint8_t max_count, uint8_t *got_count)
Decode n GT911 point records from a flat raw buffer.
static ra8_err_t internal_check_product_id(void)
Read the GT911 product id and verify the first byte is '9'.
static ra8_err_t internal_validate_cfg(const ra8_touch_cfg_t *cfg)
Validate a config descriptor.
ra8_err_t ra8_touch_read(ra8_touch_point_t *out_points, uint8_t max_count, uint8_t *got_count)
Drain the current touch frame.
static void internal_ack_frame(void)
Acknowledge the current frame; ignore I2C errors.
static void internal_decode_one(const uint8_t *raw, ra8_touch_point_t *out)
Decode one 8-byte GT911 point record.
static ra8_err_t internal_attach_irq_pin(uint8_t irq_pin)
Optional ICU IRQ-pin programming for the GT911 INT line.
void ra8_touch_dispatch_irq(void)
Test-callable IRQ dispatch shim.
static ra8_err_t internal_read_inner(ra8_touch_point_t *out_points, uint8_t max_count, uint8_t *got_count)
Inner read: assumes args validated and driver opened.
ra8_err_t ra8_touch_attach_handler(ra8_touch_event_fn_t fn, void *ctx)
Register a touch event callback.
static ra8_err_t internal_open_finalise(const ra8_touch_cfg_t *cfg)
Post-validate bring-up: product-id check, status ack, IRQ pin.
static ra8_err_t internal_gt911_write_byte(uint16_t reg, uint8_t value)
Write a single byte value into 16-bit register reg.
ra8_err_t ra8_touch_calibrate(void)
Run any backend-specific calibration routine.
static void internal_stash_state(const ra8_touch_cfg_t *cfg)
Stash the validated config into the state slot.
Multi-touch input driver – GoodIX GT911 backend.
void(* ra8_touch_event_fn_t)(void *ctx)
Touch-event callback signature.
@ k_ra8_touch_max_points
Hard cap (matches GT911 capacity).
Register layout for the GoodIX GT911 capacitive touch controller.
@ k_ra8_touch_gt911_cmd_clear_status
Acknowledge a touch frame.
@ k_ra8_touch_gt911_point_off_track
track_id field.
@ k_ra8_touch_gt911_point_off_y_lsb
Y low byte.
@ k_ra8_touch_gt911_point_off_size_lsb
Size low byte.
@ k_ra8_touch_gt911_point_off_y_msb
Y high byte.
@ k_ra8_touch_gt911_point_off_x_lsb
X low byte.
@ k_ra8_touch_gt911_point_off_x_msb
X high byte.
@ k_ra8_touch_gt911_max_points
Max simultaneous contacts.
@ k_ra8_touch_gt911_point_bytes
Bytes per per-point record.
@ k_ra8_touch_gt911_id_bytes
Length of PRODUCT_ID payload.
@ k_ra8_touch_gt911_reg_ptr_bytes
16-bit register-pointer width.
@ k_ra8_touch_gt911_status_ready_mask
bit7 buffer-ready.
@ k_ra8_touch_gt911_status_count_mask
bits[3:0] active touch count.
@ k_ra8_touch_gt911_addr_high
Alternate 7-bit target address.
@ k_ra8_touch_gt911_addr_low
Default 7-bit target address.
@ k_ra8_touch_gt911_reg_product
4-byte product id.
@ k_ra8_touch_gt911_reg_status
Status / point-count byte.
@ k_ra8_touch_gt911_reg_point0
First per-point record.
Caller-filled I2C controller-transfer seam (write / read / write-then-read).
ra8_err_t(* transfer)(void *ctx, uint8_t addr, const uint8_t *wr, uint32_t wr_len, uint8_t *rd, uint32_t rd_len)
Combined write-then-RESTART-then-read in one transaction.
ra8_err_t(* write)(void *ctx, uint8_t addr, const uint8_t *data, uint32_t len, bool send_stop)
Controller write of len bytes to 7-bit address addr.
One external-IRQ-pin configuration descriptor.
Configuration descriptor for ra8_touch_open.
uint8_t max_points
Cap on touches reported (clamped to 5).
ra8_i2c_bus_ops_t bus
Injected I2C transfer seam (app-bound).
uint8_t target_7b
7-bit GT911 address (0x5D or 0x14).
uint8_t irq_pin
IRQ pin 0..31, or k_ra8_touch_irq_pin_unset for polling-only.
One decoded touch contact.
uint16_t x
Panel X coordinate.
uint16_t y
Panel Y coordinate.
uint8_t track_id
Persistent contact id (0..15).
uint8_t pressure
Approximate pressure / contact-area, 0..255.
Driver-private state slot.
void * ctx
Callback context.
uint8_t irq_pin
IRQ pin or k_ra8_touch_irq_pin_unset.
ra8_i2c_bus_ops_t bus
Injected I2C transfer seam.
uint8_t target_7b
7-bit GT911 address.
ra8_touch_event_fn_t cb
Registered callback or NULL.
bool opened
True between open() and close().
uint8_t max_points
Cap on touches reported.