Skip to content

Commit

Permalink
Time to break things
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Aug 10, 2023
1 parent 7162723 commit 0d5c1d8
Show file tree
Hide file tree
Showing 11 changed files with 602 additions and 108 deletions.
54 changes: 50 additions & 4 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,59 @@ config ZMK_BACKLIGHT_AUTO_OFF_USB
#ZMK_BACKLIGHT
endif

config ZMK_TRACKPAD
bool "Enable the trackpad HID reporting and processing"
default n

#Display/LED Options
endmenu

menuconfig ZMK_TRACKPAD
bool "Enable ZMK trackpad emulation"
default n

config ZMK_TRACKPAD_TICK_DURATION
int "Trackpad tick duration in ms"
default 8

config ZMK_TRACKPAD_MAX_FINGERS
int "Maximum number of fingers reported in PTP"
range 3 5
default 5

config ZMK_TRACKPAD_PHYSICAL_X
int "Maximum X size of trackpad in 0.1cm increments"
default 600

config ZMK_TRACKPAD_PHYSICAL_Y
int "Maximum Y size of trackpad in 0.1cm increments"
default 600


if ZMK_TRACKPAD

choice ZMK_TRACKPAD_WORK_QUEUE
prompt "Work queue selection for trackpad events"
default ZMK_TRACKPAD_WORK_QUEUE_DEDICATED

config ZMK_TRACKPAD_WORK_QUEUE_SYSTEM
bool "Use default system work queue for trackpad events"

config ZMK_TRACKPAD_WORK_QUEUE_DEDICATED
bool "Use dedicated work queue for trackpad events"

endchoice

if ZMK_TRACKPAD_WORK_QUEUE_DEDICATED

config ZMK_TRACKPAD_DEDICATED_THREAD_STACK_SIZE
int "Stack size for dedicated trackpad thread/queue"
default 2048

config ZMK_TRACKPAD_DEDICATED_THREAD_PRIORITY
int "Thread priority for dedicated trackpad thread/queue"
default 3

endif # ZMK_TRACKPAD_WORK_QUEUE_DEDICATED

endif

menu "Power Management"

config ZMK_IDLE_TIMEOUT
Expand Down
2 changes: 2 additions & 0 deletions app/boards/arm/bt60/bt60_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ CONFIG_PINCTRL=y
CONFIG_ZMK_USB_LOGGING=y

CONFIG_ZMK_TRACKPAD=y
CONFIG_ZMK_TRACKPAD_PHYSICAL_X=650
CONFIG_ZMK_TRACKPAD_PHYSICAL_Y=1065
CONFIG_I2C=y
CONFIG_GEN4=y
CONFIG_GEN4_TRIGGER_GLOBAL_THREAD=y
Expand Down
84 changes: 17 additions & 67 deletions app/drivers/sensor/gen4/gen4.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,68 +38,20 @@ static int gen4_channel_get(const struct device *dev, enum sensor_channel chan,
struct sensor_value *val) {
const struct gen4_data *data = dev->data;
switch ((enum sensor_channel_gen4)chan) {
case SENSOR_CHAN_FINGERS:
case SENSOR_CHAN_CONTACTS:
val->val1 = data->contacts;
break;
case SENSOR_CHAN_X_0:
val->val1 = data->fingers[0].x;
case SENSOR_CHAN_X:
val->val1 = data->finger.x;
break;
case SENSOR_CHAN_X_1:
val->val1 = data->fingers[1].x;
case SENSOR_CHAN_Y:
val->val1 = data->finger.y;
break;
case SENSOR_CHAN_X_2:
val->val1 = data->fingers[2].x;
case SENSOR_CHAN_CONFIDENCE_TIP:
val->val1 = data->finger.confidence_tip;
break;
case SENSOR_CHAN_X_3:
val->val1 = data->fingers[3].x;
break;
case SENSOR_CHAN_X_4:
val->val1 = data->fingers[4].x;
break;
case SENSOR_CHAN_Y_0:
val->val1 = data->fingers[0].y;
break;
case SENSOR_CHAN_Y_1:
val->val1 = data->fingers[1].y;
break;
case SENSOR_CHAN_Y_2:
val->val1 = data->fingers[2].y;
break;
case SENSOR_CHAN_Y_3:
val->val1 = data->fingers[3].y;
break;
case SENSOR_CHAN_Y_4:
val->val1 = data->fingers[4].y;
break;
case SENSOR_CHAN_PRESENT_0:
val->val1 = data->fingers[0].present;
break;
case SENSOR_CHAN_PRESENT_1:
val->val1 = data->fingers[1].present;
break;
case SENSOR_CHAN_PRESENT_2:
val->val1 = data->fingers[2].present;
break;
case SENSOR_CHAN_PRESENT_3:
val->val1 = data->fingers[3].present;
break;
case SENSOR_CHAN_PRESENT_4:
val->val1 = data->fingers[4].present;
break;
case SENSOR_CHAN_PALM_0:
val->val1 = data->fingers[0].palm;
break;
case SENSOR_CHAN_PALM_1:
val->val1 = data->fingers[1].palm;
break;
case SENSOR_CHAN_PALM_2:
val->val1 = data->fingers[2].palm;
break;
case SENSOR_CHAN_PALM_3:
val->val1 = data->fingers[3].palm;
break;
case SENSOR_CHAN_PALM_4:
val->val1 = data->fingers[4].palm;
case SENSOR_CHAN_FINGER:
val->val1 = data->finger_id;
break;
case SENSOR_CHAN_BUTTONS:
val->val1 = data->btns;
Expand Down Expand Up @@ -134,18 +86,16 @@ static int gen4_sample_fetch(const struct device *dev, enum sensor_channel) {
data->btns = packet[12];
}

uint8_t finger_id = (packet[3] & 0xFC) >> 2;
LOG_DBG("FINGER ID: %d", finger_id);
data->finger_id = (packet[3] & 0xFC) >> 2;
LOG_DBG("FINGER ID: %d", data->finger_id);
// Finger data
data->fingers[finger_id].present = (packet[3] & 0x02) >> 1;
data->fingers[finger_id].palm = packet[3] & 0x01;
data->fingers[finger_id].x = (uint16_t)packet[4] | (uint16_t)(packet[5] << 8);
data->fingers[finger_id].y = (uint16_t)packet[6] | (uint16_t)(packet[7] << 8);
data->finger.confidence_tip = (packet[3] & 0x03);
data->finger.x = (uint16_t)packet[4] | (uint16_t)(packet[5] << 8);
data->finger.y = (uint16_t)packet[6] | (uint16_t)(packet[7] << 8);

LOG_DBG("Finger detected: %d", data->fingers[finger_id].present);
LOG_DBG("Finger palm: %d", data->fingers[finger_id].palm);
LOG_DBG("Finger x: %d", data->fingers[finger_id].x);
LOG_DBG("Finger y: %d", data->fingers[finger_id].y);
LOG_DBG("Finger palm/detected: %h", data->finger.confidence_tip);
LOG_DBG("Finger x: %d", data->finger.x);
LOG_DBG("Finger y: %d", data->finger.y);

return 0;
}
Expand Down
10 changes: 4 additions & 6 deletions app/drivers/sensor/gen4/gen4.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
#define GEN4_ADDRESS 0x2C

struct gen4_finger_data {
bool present;
bool palm;
uint8_t confidence_tip;
uint16_t x, y;
};

struct gen4_data {
uint8_t contacts;
uint8_t btns;
struct gen4_finger_data fingers[5];
uint8_t contacts, btns, finger_id;
struct gen4_finger_data finger;
bool in_int;
#ifdef CONFIG_GEN4_TRIGGER
const struct device *dev;
Expand All @@ -43,7 +41,7 @@ struct gen4_config {
#if DT_INST_ON_BUS(0, i2c)
const struct i2c_dt_spec bus;
#endif
bool rotate_90, sleep_en, no_taps;
bool rotate_90;
#ifdef CONFIG_GEN4_TRIGGER
const struct gpio_dt_spec dr;
#endif
Expand Down
4 changes: 0 additions & 4 deletions app/drivers/zephyr/dts/bindings/sensor/cirque,gen4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ properties:
description: Data ready pin for the trackpad
rotate-90:
type: boolean
sleep:
type: boolean
no-taps:
type: boolean
26 changes: 5 additions & 21 deletions app/include/drivers/sensor/gen4.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,11 @@ extern "C" {
#include <zephyr/drivers/sensor.h>

enum sensor_channel_gen4 {
SENSOR_CHAN_FINGERS = SENSOR_CHAN_PRIV_START,
SENSOR_CHAN_X_0,
SENSOR_CHAN_X_1,
SENSOR_CHAN_X_2,
SENSOR_CHAN_X_3,
SENSOR_CHAN_X_4,
SENSOR_CHAN_Y_0,
SENSOR_CHAN_Y_1,
SENSOR_CHAN_Y_2,
SENSOR_CHAN_Y_3,
SENSOR_CHAN_Y_4,
SENSOR_CHAN_PRESENT_0,
SENSOR_CHAN_PRESENT_1,
SENSOR_CHAN_PRESENT_2,
SENSOR_CHAN_PRESENT_3,
SENSOR_CHAN_PRESENT_4,
SENSOR_CHAN_PALM_0,
SENSOR_CHAN_PALM_1,
SENSOR_CHAN_PALM_2,
SENSOR_CHAN_PALM_3,
SENSOR_CHAN_PALM_4,
SENSOR_CHAN_FINGER = SENSOR_CHAN_PRIV_START,
SENSOR_CHAN_X,
SENSOR_CHAN_Y,
SENSOR_CHAN_CONFIDENCE_TIP,
SENSOR_CHAN_CONTACTS,
SENSOR_CHAN_BUTTONS,
};

Expand Down
Loading

0 comments on commit 0d5c1d8

Please sign in to comment.