summaryrefslogtreecommitdiffstats
path: root/drivers/sensors/cirque_pinnacle.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sensors/cirque_pinnacle.c')
-rw-r--r--drivers/sensors/cirque_pinnacle.c232
1 files changed, 135 insertions, 97 deletions
diff --git a/drivers/sensors/cirque_pinnacle.c b/drivers/sensors/cirque_pinnacle.c
index 2db7f916fe..c50d5a2525 100644
--- a/drivers/sensors/cirque_pinnacle.c
+++ b/drivers/sensors/cirque_pinnacle.c
@@ -1,52 +1,24 @@
// Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
+// based on https://github.com/cirque-corp/Cirque_Pinnacle_1CA027/tree/master/Circular_Trackpad
+// with modifications and changes for QMK
+// refer to documentation: Gen2 and Gen3 (Pinnacle ASIC) at https://www.cirque.com/documentation
+
#include "cirque_pinnacle.h"
#include "print.h"
#include "debug.h"
#include "wait.h"
-
-// Registers for RAP
-// clang-format off
-#define FIRMWARE_ID 0x00
-#define FIRMWARE_VERSION_C 0x01
-#define STATUS_1 0x02
-#define SYSCONFIG_1 0x03
-#define FEEDCONFIG_1 0x04
-#define FEEDCONFIG_2 0x05
-#define CALIBRATION_CONFIG_1 0x07
-#define PS2_AU_CONTROL 0x08
-#define SAMPLE_RATE 0x09
-#define Z_IDLE_COUNT 0x0A
-#define Z_SCALER 0x0B
-#define SLEEP_INTERVAL 0x0C
-#define SLEEP_TIMER 0x0D
-#define PACKET_BYTE_0 0x12
-#define PACKET_BYTE_1 0x13
-#define PACKET_BYTE_2 0x14
-#define PACKET_BYTE_3 0x15
-#define PACKET_BYTE_4 0x16
-#define PACKET_BYTE_5 0x17
-
-#define ERA_VALUE 0x1B
-#define ERA_HIGH_BYTE 0x1C
-#define ERA_LOW_BYTE 0x1D
-#define ERA_CONTROL 0x1E
-
-// ADC-attenuation settings (held in BIT_7 and BIT_6)
-// 1X = most sensitive, 4X = least sensitive
-#define ADC_ATTENUATE_1X 0x00
-#define ADC_ATTENUATE_2X 0x40
-#define ADC_ATTENUATE_3X 0x80
-#define ADC_ATTENUATE_4X 0xC0
-
-// 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 Z_IDLE_COUNT_VALUE 0x05
-// clang-format on
+#include "timer.h"
+
+#ifndef CIRQUE_PINNACLE_ATTENUATION
+# ifdef CIRQUE_PINNACLE_CURVED_OVERLAY
+# define CIRQUE_PINNACLE_ATTENUATION EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_2X
+# else
+# define CIRQUE_PINNACLE_ATTENUATION EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_4X
+# endif
+#endif
bool touchpad_init;
-uint16_t scale_data = 1024;
+uint16_t scale_data = CIRQUE_PINNACLE_DEFAULT_SCALE;
void cirque_pinnacle_clear_flags(void);
void cirque_pinnacle_enable_feed(bool feedEnable);
@@ -103,45 +75,45 @@ void cirque_pinnacle_scale_data(pinnacle_data_t* coordinates, uint16_t xResoluti
// Clears Status1 register flags (SW_CC and SW_DR)
void cirque_pinnacle_clear_flags() {
- RAP_Write(STATUS_1, 0x00);
+ RAP_Write(HOSTREG__STATUS1, HOSTREG__STATUS1_DEFVAL & ~(HOSTREG__STATUS1__COMMAND_COMPLETE | HOSTREG__STATUS1__DATA_READY));
wait_us(50);
}
// Enables/Disables the feed
void cirque_pinnacle_enable_feed(bool feedEnable) {
- uint8_t temp;
-
- RAP_ReadBytes(FEEDCONFIG_1, &temp, 1); // Store contents of FeedConfig1 register
+ uint8_t feedconfig1;
+ RAP_ReadBytes(HOSTREG__FEEDCONFIG1, &feedconfig1, 1);
if (feedEnable) {
- temp |= 0x01; // Set Feed Enable bit
- RAP_Write(0x04, temp);
+ feedconfig1 |= HOSTREG__FEEDCONFIG1__FEED_ENABLE;
} else {
- temp &= ~0x01; // Clear Feed Enable bit
- RAP_Write(0x04, temp);
+ feedconfig1 &= ~HOSTREG__FEEDCONFIG1__FEED_ENABLE;
}
+ RAP_Write(HOSTREG__FEEDCONFIG1, feedconfig1);
}
/* ERA (Extended Register Access) Functions */
// 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 timeout_timer;
cirque_pinnacle_enable_feed(false); // Disable feed
- RAP_Write(ERA_HIGH_BYTE, (uint8_t)(address >> 8)); // Send upper byte of ERA address
- RAP_Write(ERA_LOW_BYTE, (uint8_t)(address & 0x00FF)); // Send lower byte of ERA address
+ RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_HIGH, (uint8_t)(address >> 8)); // Send upper byte of ERA address
+ RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_LOW, (uint8_t)(address & 0x00FF)); // Send lower byte of ERA address
for (uint16_t i = 0; i < count; i++) {
- RAP_Write(ERA_CONTROL, 0x05); // Signal ERA-read (auto-increment) to Pinnacle
+ RAP_Write(HOSTREG__EXT_REG_AXS_CTRL, HOSTREG__EREG_AXS__INC_ADDR_READ | HOSTREG__EREG_AXS__READ); // Signal ERA-read (auto-increment) to Pinnacle
// Wait for status register 0x1E to clear
+ timeout_timer = timer_read();
do {
- RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1);
- } while (ERAControlValue != 0x00);
+ RAP_ReadBytes(HOSTREG__EXT_REG_AXS_CTRL, &ERAControlValue, 1);
+ } while ((ERAControlValue != 0x00) && (timer_elapsed(timeout_timer) <= CIRQUE_PINNACLE_TIMEOUT));
- RAP_ReadBytes(ERA_VALUE, data + i, 1);
+ RAP_ReadBytes(HOSTREG__EXT_REG_AXS_VALUE, data + i, 1);
cirque_pinnacle_clear_flags();
}
@@ -149,49 +121,83 @@ 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 timeout_timer;
cirque_pinnacle_enable_feed(false); // Disable feed
- RAP_Write(ERA_VALUE, data); // Send data byte to be written
+ RAP_Write(HOSTREG__EXT_REG_AXS_VALUE, data); // Send data byte to be written
- RAP_Write(ERA_HIGH_BYTE, (uint8_t)(address >> 8)); // Upper byte of ERA address
- RAP_Write(ERA_LOW_BYTE, (uint8_t)(address & 0x00FF)); // Lower byte of ERA address
+ RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_HIGH, (uint8_t)(address >> 8)); // Upper byte of ERA address
+ RAP_Write(HOSTREG__EXT_REG_AXS_ADDR_LOW, (uint8_t)(address & 0x00FF)); // Lower byte of ERA address
- RAP_Write(ERA_CONTROL, 0x02); // Signal an ERA-write to Pinnacle
+ RAP_Write(HOSTREG__EXT_REG_AXS_CTRL, HOSTREG__EREG_AXS__WRITE); // Signal an ERA-write to Pinnacle
// Wait for status register 0x1E to clear
+ timeout_timer = timer_read();
do {
- RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1);
- } while (ERAControlValue != 0x00);
+ RAP_ReadBytes(HOSTREG__EXT_REG_AXS_CTRL, &ERAControlValue, 1);
+ } while ((ERAControlValue != 0x00) && (timer_elapsed(timeout_timer) <= CIRQUE_PINNACLE_TIMEOUT));
cirque_pinnacle_clear_flags();
}
void cirque_pinnacle_set_adc_attenuation(uint8_t adcGain) {
- uint8_t temp = 0x00;
+ uint8_t adcconfig = 0x00;
- ERA_ReadBytes(0x0187, &temp, 1);
- temp &= 0x3F; // clear top two bits
- temp |= adcGain;
- ERA_WriteByte(0x0187, temp);
- ERA_ReadBytes(0x0187, &temp, 1);
+ ERA_ReadBytes(EXTREG__TRACK_ADCCONFIG, &adcconfig, 1);
+ adcconfig &= EXTREG__TRACK_ADCCONFIG__ADC_ATTENUATE_MASK;
+ adcconfig |= adcGain;
+ ERA_WriteByte(EXTREG__TRACK_ADCCONFIG, adcconfig);
+ ERA_ReadBytes(EXTREG__TRACK_ADCCONFIG, &adcconfig, 1);
}
// Changes thresholds to improve detection of fingers
+// Not needed for flat overlay?
void cirque_pinnacle_tune_edge_sensitivity(void) {
- uint8_t temp = 0x00;
+ uint8_t widezmin = 0x00;
- ERA_ReadBytes(0x0149, &temp, 1);
- ERA_WriteByte(0x0149, 0x04);
- ERA_ReadBytes(0x0149, &temp, 1);
+ ERA_ReadBytes(EXTREG__XAXIS_WIDEZMIN, &widezmin, 1);
+ ERA_WriteByte(EXTREG__XAXIS_WIDEZMIN, 0x04); // magic number from Cirque sample code
+ ERA_ReadBytes(EXTREG__XAXIS_WIDEZMIN, &widezmin, 1);
- ERA_ReadBytes(0x0168, &temp, 1);
- ERA_WriteByte(0x0168, 0x03);
- ERA_ReadBytes(0x0168, &temp, 1);
+ ERA_ReadBytes(EXTREG__YAXIS_WIDEZMIN, &widezmin, 1);
+ ERA_WriteByte(EXTREG__YAXIS_WIDEZMIN, 0x03); // magic number from Cirque sample code
+ ERA_ReadBytes(EXTREG__YAXIS_WIDEZMIN, &widezmin, 1);
}
-/* Pinnacle-based TM040040 Functions */
+// Perform calibration
+void cirque_pinnacle_calibrate(void) {
+ uint8_t calconfig;
+ uint16_t timeout_timer;
+
+ RAP_ReadBytes(HOSTREG__CALCONFIG1, &calconfig, 1);
+ calconfig |= HOSTREG__CALCONFIG1__CALIBRATE;
+ RAP_Write(HOSTREG__CALCONFIG1, calconfig);
+
+ // Calibration takes ~100ms according to GT-AN-090624, doubling the timeout just to be safe
+ timeout_timer = timer_read();
+ do {
+ RAP_ReadBytes(HOSTREG__CALCONFIG1, &calconfig, 1);
+ } while ((calconfig & HOSTREG__CALCONFIG1__CALIBRATE) && (timer_elapsed(timeout_timer) <= 200));
+
+ cirque_pinnacle_clear_flags();
+}
+
+// Enable/disable cursor smoothing, smoothing is enabled by default
+void cirque_pinnacle_cursor_smoothing(bool enable) {
+ uint8_t feedconfig3;
+
+ RAP_ReadBytes(HOSTREG__FEEDCONFIG3, &feedconfig3, 1);
+ if (enable) {
+ feedconfig3 &= ~HOSTREG__FEEDCONFIG3__DISABLE_CROSS_RATE_SMOOTHING;
+ } else {
+ feedconfig3 |= HOSTREG__FEEDCONFIG3__DISABLE_CROSS_RATE_SMOOTHING;
+ }
+ RAP_Write(HOSTREG__FEEDCONFIG3, feedconfig3);
+}
+
+/* Pinnacle-based TM040040/TM035035/TM023023 Functions */
void cirque_pinnacle_init(void) {
#if defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
spi_init();
@@ -200,39 +206,71 @@ void cirque_pinnacle_init(void) {
#endif
touchpad_init = true;
+
// Host clears SW_CC flag
cirque_pinnacle_clear_flags();
- // Host configures bits of registers 0x03 and 0x05
- RAP_Write(SYSCONFIG_1, SYSCONFIG_1_VALUE);
- RAP_Write(FEEDCONFIG_2, FEEDCONFIG_2_VALUE);
+ // send a RESET command now, in case QMK had a soft-reset without a power cycle
+ RAP_Write(HOSTREG__SYSCONFIG1, HOSTREG__SYSCONFIG1__RESET);
+ wait_ms(30); // Pinnacle needs 10-15ms to boot, so wait long enough before configuring
+ RAP_Write(HOSTREG__SYSCONFIG1, HOSTREG__SYSCONFIG1_DEFVAL);
+ wait_us(50);
+
+ // FeedConfig2 (Feature flags for Relative Mode Only)
+ RAP_Write(HOSTREG__FEEDCONFIG2, HOSTREG__FEEDCONFIG2_DEFVAL);
- // Host enables preferred output mode (absolute)
- RAP_Write(FEEDCONFIG_1, FEEDCONFIG_1_VALUE);
+ // FeedConfig1 (Data Output Flags)
+ RAP_Write(HOSTREG__FEEDCONFIG1, CIRQUE_PINNACLE_POSITION_MODE ? HOSTREG__FEEDCONFIG1__DATA_TYPE__REL0_ABS1 : HOSTREG__FEEDCONFIG1_DEFVAL);
- // Host sets z-idle packet count to 5 (default is 30)
- RAP_Write(Z_IDLE_COUNT, Z_IDLE_COUNT_VALUE);
+ // Host sets z-idle packet count to 5 (default is 0x1E/30)
+ RAP_Write(HOSTREG__ZIDLE, 5);
- cirque_pinnacle_set_adc_attenuation(0xFF);
+ cirque_pinnacle_set_adc_attenuation(CIRQUE_PINNACLE_ATTENUATION);
+#ifdef CIRQUE_PINNACLE_CURVED_OVERLAY
cirque_pinnacle_tune_edge_sensitivity();
+#endif
+ // Force a calibration after setting ADC attenuation
+ cirque_pinnacle_calibrate();
+
cirque_pinnacle_enable_feed(true);
}
-// 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) {
- uint8_t data[6] = {0};
- pinnacle_data_t result = {0};
- RAP_ReadBytes(PACKET_BYTE_0, data, 6);
+ uint8_t data_ready = 0;
+ uint8_t data[6] = {0};
+ pinnacle_data_t result = {0};
+
+ // Check if there is valid data available
+ RAP_ReadBytes(HOSTREG__STATUS1, &data_ready, 1);
+ if ((data_ready & HOSTREG__STATUS1__DATA_READY) == 0) {
+ // no data available yet
+ result.valid = false; // be explicit
+ return result;
+ }
- cirque_pinnacle_clear_flags();
+ // Read all data bytes
+ RAP_ReadBytes(HOSTREG__PACKETBYTE_0, data, 6);
- result.buttonFlags = data[0] & 0x3F;
- result.xValue = data[2] | ((data[4] & 0x0F) << 8);
- result.yValue = data[3] | ((data[4] & 0xF0) << 4);
- result.zValue = data[5] & 0x3F;
+ // Get ready for the next data sample
+ cirque_pinnacle_clear_flags();
- result.touchDown = (result.xValue != 0 || result.yValue != 0);
+#if CIRQUE_PINNACLE_POSITION_MODE
+ // Decode data for absolute mode
+ // Register 0x13 is unused in this mode (palm detection area)
+ result.buttonFlags = data[0] & 0x3F; // bit0 to bit5 are switch 0-5, only hardware button presses (from input pin on the Pinnacle chip)
+ result.xValue = data[2] | ((data[4] & 0x0F) << 8); // merge high and low bits for X
+ result.yValue = data[3] | ((data[4] & 0xF0) << 4); // merge high and low bits for Y
+ result.zValue = data[5] & 0x3F; // Z is only lower 6 bits, upper 2 bits are reserved/unused
+ result.touchDown = (result.xValue != 0 || result.yValue != 0); // (0,0) is a "magic coordinate" to indicate "finger touched down"
+#else
+ // Decode data for relative mode
+ // Registers 0x16 and 0x17 are unused in this mode
+ result.buttons = data[0] & 0x07; // bit0 = primary button, bit1 = secondary button, bit2 = auxilary button, if Taps enabled then also software-recognized taps are reported
+ result.xDelta = data[1];
+ result.yDelta = data[2];
+ result.wheelCount = data[3];
+#endif
+ result.valid = true;
return result;
}