#ifndef LOW_LEVEL_TOUCH_H #define LOW_LEVEL_TOUCH_H #include #include using std::int16_t; using std::uint8_t; using std::uint32_t; // Touch driver type enumeration typedef enum { TOUCH_TYPE_FT6336U, TOUCH_TYPE_NONE // For boards without touch } TouchType; // Maximum touch points (most capacitive touch controllers support 1-5 points) #define TOUCH_MAX_POINTS 2 // Touch event types typedef enum { TOUCH_EVENT_PRESS_DOWN = 0, TOUCH_EVENT_LIFT_UP = 1, TOUCH_EVENT_CONTACT = 2, TOUCH_EVENT_NO_EVENT = 3 } TouchEvent; // Touch point structure typedef struct { int16_t x; int16_t y; uint8_t event; uint8_t id; uint8_t pressure; // Touch pressure/area/weight } TouchPoint; // Touch data structure typedef struct { uint8_t touch_count; TouchPoint points[TOUCH_MAX_POINTS]; uint8_t gesture; } TouchData; // Abstract touch interface class LowLevelTouch { public: virtual ~LowLevelTouch() {} // Core touch operations virtual bool init() = 0; virtual bool read_touch(TouchData* data) = 0; virtual bool is_touched() = 0; // Touch properties virtual int get_screen_width() const = 0; virtual int get_screen_height() const = 0; virtual TouchType get_type() const = 0; virtual uint8_t get_max_touch_points() const = 0; // Optional: Device information virtual uint8_t get_chip_id() { return 0xFF; } virtual uint8_t get_firmware_version() { return 0xFF; } // Optional: Coordinate transformation (handled internally by driver) virtual void set_coordinate_transform(bool swap_xy, bool invert_x, bool invert_y) { (void)swap_xy; (void)invert_x; (void)invert_y; } // Optional: Interrupt callback virtual void set_interrupt_callback(void (*callback)(unsigned int gpio, uint32_t events)) { (void)callback; } // Optional: Test/diagnostic virtual bool test_communication() { return false; } // Factory method - creates touch controller based on type and screen dimensions // Uses board_config.h for pin definitions and optional transform parameters static LowLevelTouch* create(TouchType type, int screen_width, int screen_height, bool swap_xy = false, bool invert_x = false, bool invert_y = false); }; #endif // LOW_LEVEL_TOUCH_H