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

Cirque Pinnacle usability updates #17098

Closed
wants to merge 6 commits into from
Closed
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
52 changes: 47 additions & 5 deletions drivers/sensors/cirque_pinnacle.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define SYSCONFIG_1 0x03
#define FEEDCONFIG_1 0x04
#define FEEDCONFIG_2 0x05
#define FEEDCONFIG_3 0x06
#define CALIBRATION_CONFIG_1 0x07
#define PS2_AU_CONTROL 0x08
#define SAMPLE_RATE 0x09
Expand All @@ -38,11 +39,20 @@
#define ADC_ATTENUATE_3X 0x80
#define ADC_ATTENUATE_4X 0xC0

// Set ADC-attenuation according to overlay
#ifdef CIRQUE_PINNACLE_CURVED_OVERLAY
#define ADC_ATTENUATION_VALUE ADC_ATTENUATE_2X
#else
#define ADC_ATTENUATION_VALUE ADC_ATTENUATE_4X
#endif

// Register config values for this demo
#define SYSCONFIG_1_VALUE 0x00
#define FEEDCONFIG_1_VALUE 0x03 // 0x03 for absolute mode 0x01 for relative mode
#define FEEDCONFIG_2_VALUE 0x1C // 0x1F for normal functionality 0x1E for intellimouse disabled
#define FEEDCONFIG_3_VALUE 0x02 // 0x02 to disable smoothing
#define Z_IDLE_COUNT_VALUE 0x05
#define STATUS_1_VALUE 0x04 // 0x04 for software data ready
// clang-format on

bool touchpad_init;
Expand Down Expand Up @@ -126,7 +136,8 @@ void cirque_pinnacle_enable_feed(bool feedEnable) {
// Reads <count> bytes from an extended register at <address> (16-bit address),
// stores values in <*data>
void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {
uint8_t ERAControlValue = 0xFF;
uint8_t ERAControlValue = 0xFF;
uint16_t retry = 0;

cirque_pinnacle_enable_feed(false); // Disable feed

Expand All @@ -139,7 +150,7 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {
// Wait for status register 0x1E to clear
do {
RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1);
} while (ERAControlValue != 0x00);
} while ((ERAControlValue != 0x00) && (++retry != 0));

RAP_ReadBytes(ERA_VALUE, data + i, 1);

Expand All @@ -149,7 +160,8 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {

// Writes a byte, <data>, to an extended register at <address> (16-bit address)
void ERA_WriteByte(uint16_t address, uint8_t data) {
uint8_t ERAControlValue = 0xFF;
uint8_t ERAControlValue = 0xFF;
uint16_t retry = 0;

cirque_pinnacle_enable_feed(false); // Disable feed

Expand All @@ -163,7 +175,7 @@ void ERA_WriteByte(uint16_t address, uint8_t data) {
// Wait for status register 0x1E to clear
do {
RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1);
} while (ERAControlValue != 0x00);
} while ((ERAControlValue != 0x00) && (++retry != 0));

cirque_pinnacle_clear_flags();
}
Expand Down Expand Up @@ -191,6 +203,22 @@ void cirque_pinnacle_tune_edge_sensitivity(void) {
ERA_ReadBytes(0x0168, &temp, 1);
}

// Perform calibration
void cirque_pinnacle_calibrate(void) {
uint8_t calconfig;
uint16_t retry = 0;

RAP_ReadBytes(CALIBRATION_CONFIG_1, &calconfig, 1);
calconfig |= 0x01;
RAP_Write(CALIBRATION_CONFIG_1, calconfig);

do {
RAP_ReadBytes(CALIBRATION_CONFIG_1, &calconfig, 1);
} while ((calconfig & 0x01) && (++retry != 0));

cirque_pinnacle_clear_flags();
}

/* Pinnacle-based TM040040 Functions */
void cirque_pinnacle_init(void) {
#if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
Expand All @@ -207,17 +235,31 @@ void cirque_pinnacle_init(void) {
RAP_Write(SYSCONFIG_1, SYSCONFIG_1_VALUE);
RAP_Write(FEEDCONFIG_2, FEEDCONFIG_2_VALUE);

#ifdef CIRQUE_PINNACLE_DISABLE_SMOOTHING
RAP_Write(FEEDCONFIG_3, FEEDCONFIG_3_VALUE);
#endif

// Host enables preferred output mode (absolute)
RAP_Write(FEEDCONFIG_1, FEEDCONFIG_1_VALUE);

// Host sets z-idle packet count to 5 (default is 30)
RAP_Write(Z_IDLE_COUNT, Z_IDLE_COUNT_VALUE);

cirque_pinnacle_set_adc_attenuation(0xFF);
cirque_pinnacle_set_adc_attenuation(ADC_ATTENUATION_VALUE);
// Perform manual calibration on initialization
cirque_pinnacle_calibrate();
cirque_pinnacle_tune_edge_sensitivity();
cirque_pinnacle_enable_feed(true);
}

// Reads status register
// Returns data readiness based on software data ready bit
bool cirque_pinnacle_data_ready(void) {
uint8_t status;
RAP_ReadBytes(STATUS_1, &status, 1);
return !!(status & STATUS_1_VALUE);
}

// Reads XYZ data from Pinnacle registers 0x14 through 0x17
// Stores result in pinnacle_data_t struct with xValue, yValue, and zValue members
pinnacle_data_t cirque_pinnacle_read_data(void) {
Expand Down
1 change: 1 addition & 0 deletions drivers/sensors/cirque_pinnacle.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct {

void cirque_pinnacle_init(void);
pinnacle_data_t cirque_pinnacle_read_data(void);
bool cirque_pinnacle_data_ready(void);
void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResolution, uint16_t yResolution);
uint16_t cirque_pinnacle_get_scale(void);
void cirque_pinnacle_set_scale(uint16_t scale);
Expand Down
22 changes: 17 additions & 5 deletions quantum/pointing_device_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,21 @@ const pointing_device_driver_t pointing_device_driver = {
# endif

report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
pinnacle_data_t touchData = cirque_pinnacle_read_data();
static uint16_t x = 0, y = 0, mouse_timer = 0;
pinnacle_data_t touchData;
static uint16_t x = 0, y = 0;
int8_t report_x = 0, report_y = 0;
static bool is_z_down = false;
# ifndef CIRQUE_PINNACLE_DISABLE_TAP
static uint16_t mouse_timer = 0;
static bool is_z_down = false;
# endif

# ifndef POINTING_DEVICE_MOTION_PIN
if (!cirque_pinnacle_data_ready()) {
return mouse_report;
}
# endif

touchData = cirque_pinnacle_read_data();
cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); // Scale coordinates to arbitrary X, Y resolution

if (x && y && touchData.xValue && touchData.yValue) {
Expand All @@ -129,16 +139,17 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
x = touchData.xValue;
y = touchData.yValue;

# ifndef CIRQUE_PINNACLE_DISABLE_TAP
if ((bool)touchData.zValue != is_z_down) {
is_z_down = (bool)touchData.zValue;
if (!touchData.zValue) {
if (timer_elapsed(mouse_timer) < CIRQUE_PINNACLE_TAPPING_TERM && mouse_timer != 0) {
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1);
pointing_device_set_report(mouse_report);
pointing_device_send();
# if TAP_CODE_DELAY > 0
# if TAP_CODE_DELAY > 0
wait_ms(TAP_CODE_DELAY);
# endif
# endif
mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
pointing_device_set_report(mouse_report);
pointing_device_send();
Expand All @@ -149,6 +160,7 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
if (timer_elapsed(mouse_timer) > (CIRQUE_PINNACLE_TOUCH_DEBOUNCE)) {
mouse_timer = 0;
}
# endif
mouse_report.x = report_x;
mouse_report.y = report_y;

Expand Down