Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add touchpad feature #24939

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,14 @@ ifeq ($(strip $(JOYSTICK_ENABLE)), yes)
endif
endif

FRAMEWORK_TOUCHPAD_ENABLE ?= no
ifeq ($(strip $(FRAMEWORK_TOUCHPAD_ENABLE)), yes)
OPT_DEFS += -DFRAMEWORK_TOUCHPAD_ENABLE
SRC += $(QUANTUM_DIR)/framework_touchpad.c

I2C_DRIVER_REQUIRED = yes
endif

USBPD_ENABLE ?= no
VALID_USBPD_DRIVER_TYPES = custom vendor
USBPD_DRIVER ?= vendor
Expand Down
48 changes: 48 additions & 0 deletions quantum/framework_touchpad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Copyright 2025
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "framework_touchpad.h"
#include "i2c_master.h"
#include "print.h"

#define FRAMEWORK_TOUCHPAD_I2C_ADDRESS (0x2c << 1)

void framework_touchpad_init(void) {
i2c_init();
}

void framework_touchpad_task(void) {
int length = 0;
int status = I2C_STATUS_SUCCESS;
uint8_t buffer[37] = {0};
uint8_t report[34] = {0};

status = i2c_receive(FRAMEWORK_TOUCHPAD_I2C_ADDRESS, buffer, 1, 100);
length = buffer[0];
if (status != I2C_STATUS_SUCCESS || buffer[0] <= 0) {
return;
}

status = i2c_receive(FRAMEWORK_TOUCHPAD_I2C_ADDRESS, buffer, length, 100);
if (status != I2C_STATUS_SUCCESS || buffer[2] != 0x01) {
return;
}

memcpy(report, buffer + 3, 34);

void host_framework_touchpad_send(uint8_t(*report)[34]);
host_framework_touchpad_send(&report);
}
27 changes: 27 additions & 0 deletions quantum/framework_touchpad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright 2025
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

/**
* \brief Handle the initialization of the subsystem.
*/
void framework_touchpad_init(void);

/**
* \brief Handle various subsystem background tasks.
*/
void framework_touchpad_task(void);
10 changes: 10 additions & 0 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef JOYSTICK_ENABLE
# include "joystick.h"
#endif
#ifdef FRAMEWORK_TOUCHPAD_ENABLE
# include "framework_touchpad.h"
#endif
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
Expand Down Expand Up @@ -469,6 +472,9 @@ void keyboard_init(void) {
#ifdef JOYSTICK_ENABLE
joystick_init();
#endif
#ifdef FRAMEWORK_TOUCHPAD_ENABLE
framework_touchpad_init();
#endif
#ifdef SLEEP_LED_ENABLE
sleep_led_init();
#endif
Expand Down Expand Up @@ -742,6 +748,10 @@ void keyboard_task(void) {
joystick_task();
#endif

#ifdef FRAMEWORK_TOUCHPAD_ENABLE
framework_touchpad_task();
#endif

#ifdef BLUETOOTH_ENABLE
bluetooth_task();
#endif
Expand Down
4 changes: 4 additions & 0 deletions quantum/quantum.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ extern layer_state_t layer_state;
# include "digitizer.h"
#endif

#ifdef FRAMEWORK_TOUCHPAD_ENABLE
# include "framework_touchpad.h"
#endif

#ifdef VIA_ENABLE
# include "via.h"
#endif
Expand Down
8 changes: 8 additions & 0 deletions tmk_core/protocol.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ ifeq ($(strip $(DIGITIZER_ENABLE)), yes)
endif
endif

ifeq ($(strip $(FRAMEWORK_TOUCHPAD_ENABLE)), yes)
OPT_DEFS += -DFRAMEWORK_TOUCHPAD_ENABLE
ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
OPT_DEFS += -DFRAMEWORK_TOUCHPAD_SHARED_EP
SHARED_EP_ENABLE = yes
endif
endif

ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
OPT_DEFS += -DSHARED_EP_ENABLE
endif
Expand Down
8 changes: 8 additions & 0 deletions tmk_core/protocol/chibios/usb_endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT] = {
[USB_ENDPOINT_IN_DIGITIZER] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, DIGITIZER_EPSIZE, DIGITIZER_IN_EPNUM, DIGITIZER_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_digitizer_t))),
#endif

#if defined(FRAMEWORK_TOUCHPAD_ENABLE) && !defined(FRAMEWORK_TOUCHPAD_SHARED_EP)
[USB_ENDPOINT_IN_FRAMEWORK_TOUCHPAD] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, DIGITIZER_EPSIZE, DIGITIZER_IN_EPNUM, DIGITIZER_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_digitizer_t))),
#endif

#if defined(CONSOLE_ENABLE)
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
[USB_ENDPOINT_IN_CONSOLE] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, CONSOLE_EPSIZE, CONSOLE_IN_EPNUM, CONSOLE_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(CONSOLE_EPSIZE)),
Expand Down Expand Up @@ -135,6 +139,10 @@ usb_endpoint_in_lut_t usb_endpoint_interface_lut[TOTAL_INTERFACES] = {
#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
[DIGITIZER_INTERFACE] = USB_ENDPOINT_IN_DIGITIZER,
#endif

#if defined(FRAMEWORK_TOUCHPAD_ENABLE) && !defined(FRAMEWORK_TOUCHPAD_SHARED_EP)
[FRAMEWORK_TOUCHPAD_INTERFACE] = USB_ENDPOINT_IN_FRAMEWORK_TOUCHPAD,
#endif
};

usb_endpoint_out_t usb_endpoints_out[USB_ENDPOINT_OUT_COUNT] = {
Expand Down
7 changes: 7 additions & 0 deletions tmk_core/protocol/chibios/usb_endpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ typedef enum {
USB_ENDPOINT_IN_DIGITIZER,
#endif

#if defined(FRAMEWORK_TOUCHPAD_ENABLE) && !defined(FRAMEWORK_TOUCHPAD_SHARED_EP)
USB_ENDPOINT_IN_FRAMEWORK_TOUCHPAD,
#endif

#if defined(CONSOLE_ENABLE)
USB_ENDPOINT_IN_CONSOLE,
#endif
Expand Down Expand Up @@ -116,6 +120,9 @@ typedef enum {
# if defined(DIGITIZER_SHARED_EP)
USB_ENDPOINT_IN_DIGITIZER = USB_ENDPOINT_IN_SHARED,
# endif
# if defined(FRAMEWORK_TOUCHPAD_SHARED_EP)
USB_ENDPOINT_IN_FRAMEWORK_TOUCHPAD = USB_ENDPOINT_IN_SHARED,
# endif
#endif
} usb_endpoint_in_lut_t;

Expand Down
6 changes: 6 additions & 0 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ void send_digitizer(report_digitizer_t *report) {
#endif
}

void send_framework_touchpad(report_framework_touchpad_t *report) {
#ifdef FRAMEWORK_TOUCHPAD_ENABLE
send_report(USB_ENDPOINT_IN_FRAMEWORK_TOUCHPAD, report, sizeof(report_framework_touchpad_t));
#endif
}

/* ---------------------------------------------------------
* Console functions
* ---------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tmk_core/protocol/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "digitizer.h"
#endif

#ifdef FRAMEWORK_TOUCHPAD_ENABLE
# include "framework_touchpad.h"
#endif

#ifdef JOYSTICK_ENABLE
# include "joystick.h"
#endif
Expand Down Expand Up @@ -240,6 +244,23 @@ void host_digitizer_send(digitizer_t *digitizer) {

__attribute__((weak)) void send_digitizer(report_digitizer_t *report) {}

#ifdef FRAMEWORK_TOUCHPAD_ENABLE
void host_framework_touchpad_send(uint8_t (*data)[34]) {
report_framework_touchpad_t report = {
# ifdef FRAMEWORK_TOUCHPAD_SHARED_EP
.report_id = REPORT_ID_FRAMEWORK_TOUCHPAD,
# endif
.report = {0},
};

memcpy(report.report, data, 34);

send_framework_touchpad(&report);
}
#endif

__attribute__((weak)) void send_framework_touchpad(report_framework_touchpad_t *report) {}

#ifdef PROGRAMMABLE_BUTTON_ENABLE
void host_programmable_button_send(uint32_t data) {
report_programmable_button_t report = {
Expand Down
1 change: 1 addition & 0 deletions tmk_core/protocol/host_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ typedef struct {

void send_joystick(report_joystick_t *report);
void send_digitizer(report_digitizer_t *report);
void send_framework_touchpad(report_framework_touchpad_t *report);
void send_programmable_button(report_programmable_button_t *report);
5 changes: 5 additions & 0 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ void EVENT_USB_Device_ConfigurationChanged(void) {
ConfigSuccess &= Endpoint_ConfigureEndpoint((DIGITIZER_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, DIGITIZER_EPSIZE, 1);
#endif

#if defined(FRAMEWORK_TOUCHPAD_ENABLE) && !defined(FRAMEWORK_TOUCHPAD_SHARED_EP)
/* Setup digitizer endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint((DIGITIZER_IN_EPNUM | ENDPOINT_DIR_IN), EP_TYPE_INTERRUPT, DIGITIZER_EPSIZE, 1);
#endif

usb_device_state_set_configuration(USB_DeviceState == DEVICE_STATE_Configured, USB_Device_ConfigurationNumber);
}

Expand Down
8 changes: 8 additions & 0 deletions tmk_core/protocol/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum hid_report_ids {
REPORT_ID_NKRO,
REPORT_ID_JOYSTICK,
REPORT_ID_DIGITIZER,
REPORT_ID_FRAMEWORK_TOUCHPAD,
REPORT_ID_COUNT = REPORT_ID_DIGITIZER
};

Expand Down Expand Up @@ -232,6 +233,13 @@ typedef struct {
uint16_t y;
} PACKED report_digitizer_t;

typedef struct {
#ifdef FRAMEWORK_TOUCHPAD_SHARED_EP
uint8_t report_id;
#endif
uint8_t report[34];
} PACKED report_framework_touchpad_t;

#if JOYSTICK_AXIS_RESOLUTION > 8
typedef int16_t joystick_axis_t;
#else
Expand Down
Loading