From df7d2ca6b29c95d7581ebac3aed37243641b9235 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Tue, 13 Jul 2021 23:34:39 +0900 Subject: [PATCH] adds adc attenuation --- keyboards/moonlander/cirque_tm040040.c | 39 +++++++++++++++++++++----- keyboards/moonlander/cirque_tm040040.h | 10 ++++++- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/keyboards/moonlander/cirque_tm040040.c b/keyboards/moonlander/cirque_tm040040.c index 88e7e20639..3fdadbdd0d 100644 --- a/keyboards/moonlander/cirque_tm040040.c +++ b/keyboards/moonlander/cirque_tm040040.c @@ -52,18 +52,14 @@ void pointing_device_task(void) { } else { mouse_report.buttons &= ~MOUSE_BTN1; } - print_byte(touchData.xValue); - print_byte(touchData.yValue); - print_byte(touchData.zValue); - print_byte(touchData.buttonFlags); - print_byte(touchData.touchDown); - xprintf("\n"); #else Pinnacle_GetRelative(&rTouchData); mouse_report.x = rTouchData.xValue; mouse_report.y = rTouchData.yValue; + //xprintf("%d", result->buttonFlags); + xprintf("\n"); if (rTouchData.buttonFlags) { mouse_report.buttons |= MOUSE_BTN1; } else { @@ -96,6 +92,10 @@ void pointing_device_init(void) { // Host sets z-idle packet count to 5 (default is 30) RAP_Write(Z_IDLE_COUNT, Z_IDLE_COUNT_VALUE); + + setAdcAttenuation(0xFF); + tuneEdgeSensitivity(); + Pinnacle_EnableFeed(true); } // Reads XYZ data from Pinnacle registers 0x14 through 0x17 @@ -111,6 +111,7 @@ void Pinnacle_GetAbsolute(absData_t* result) { result->yValue = data[3] | ((data[4] & 0xF0) << 4); result->zValue = data[5] & 0x3F; + result->touchDown = result->xValue != 0; } @@ -228,7 +229,7 @@ void RAP_Write(uint8_t address, uint8_t data) { i2c_stop(); } if (address == FEEDCONFIG_1 && data == FEEDCONFIG_1_VALUE) { - data = 0xC3; + data = 0xC3; } if (touchpad_init[1]) { if (i2c2_writeReg(SLAVE_ADDR << 1, cmdByte, &data, sizeof(data), I2C_TIMEOUT) != I2C_STATUS_SUCCESS) { @@ -273,3 +274,27 @@ void ScaleData(absData_t* coordinates, uint16_t xResolution, uint16_t yResolutio coordinates->xValue = (uint16_t)(xTemp * xResolution / PINNACLE_X_RANGE); coordinates->yValue = (uint16_t)(yTemp * yResolution / PINNACLE_Y_RANGE); } + +void setAdcAttenuation(uint8_t adcGain) { + uint8_t temp = 0x00; + + ERA_ReadBytes(0x0187, &temp, 1); + temp &= 0x3F; // clear top two bits + temp |= adcGain; + ERA_WriteByte(0x0187, temp); + ERA_ReadBytes(0x0187, &temp, 1); +} + +// Changes thresholds to improve detection of fingers +void tuneEdgeSensitivity(void) { + uint8_t temp = 0x00; + + ERA_ReadBytes(0x0149, &temp, 1); + ERA_WriteByte(0x0149, 0x04); + ERA_ReadBytes(0x0149, &temp, 1); + + ERA_ReadBytes(0x0168, &temp, 1); + ERA_WriteByte(0x0168, 0x03); + ERA_ReadBytes(0x0168, &temp, 1); +} + diff --git a/keyboards/moonlander/cirque_tm040040.h b/keyboards/moonlander/cirque_tm040040.h index 856a606660..e4828c3b28 100644 --- a/keyboards/moonlander/cirque_tm040040.h +++ b/keyboards/moonlander/cirque_tm040040.h @@ -33,7 +33,8 @@ void RAP_Write(uint8_t address, uint8_t data); void ClipCoordinates(absData_t* coordinates); void ScaleData(absData_t* coordinates, uint16_t xResolution, uint16_t yResolution); void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); - +void setAdcAttenuation(uint8_t adcGain); +void tuneEdgeSensitivity(void); // Cirque's 7-bit I2C Slave Address #define SLAVE_ADDR 0x2A @@ -76,3 +77,10 @@ void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); #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