diff --git a/keyboards/moonlander/cirque_tm040040.c b/keyboards/moonlander/cirque_tm040040.c index 1928cc26a6..6944c30fa2 100644 --- a/keyboards/moonlander/cirque_tm040040.c +++ b/keyboards/moonlander/cirque_tm040040.c @@ -8,32 +8,49 @@ # define SYSCONFIG_1_VALUE 0x00 #endif #ifndef FEEDCONFIG_1_VALUE -# define FEEDCONFIG_1_VALUE 0x81 // 0x03 for absolute mode 0x01 for relative mode +# define FEEDCONFIG_1_VALUE 0x03 // 0x03 for absolute mode 0x01 for relative mode +// # define FEEDCONFIG_1_VALUE 0x81 // 0x03 for absolute mode 0x01 for relative mode #endif #ifndef FEEDCONFIG_2_VALUE -# define FEEDCONFIG_2_VALUE 0x18 // 0x1F for normal functionality 0x1E for intellimouse disabled +// # define FEEDCONFIG_2_VALUE 0x1F // 0x1F for normal functionality 0x1E for intellimouse disabled +# define FEEDCONFIG_2_VALUE 0x1C // 0x1F for normal functionality 0x1E for intellimouse disabled #endif #ifndef Z_IDLE_COUNT_VALUE # define Z_IDLE_COUNT_VALUE 0x05 #endif -absData_t touchData = { 0 }; -relData_t rTouchData ={ 0 }; +absData_t touchData = {0}; +relData_t rTouchData = {0}; void print_byte(uint8_t byte) { xprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1' : '0'), (byte & 0x40 ? '1' : '0'), (byte & 0x20 ? '1' : '0'), (byte & 0x10 ? '1' : '0'), (byte & 0x08 ? '1' : '0'), (byte & 0x04 ? '1' : '0'), (byte & 0x02 ? '1' : '0'), (byte & 0x01 ? '1' : '0')); } void pointing_device_task(void) { report_mouse_t mouse_report = pointing_device_get_report(); #if FEEDCONFIG_1_VALUE == 0x03 - Pinnacle_GetAbsolute(&touchData); - ScaleData(&touchData, 256, 256); // Scale coordinates to arbitrary X, Y resolution + static uint16_t x = 0, y = 0; + Pinnacle_GetAbsolute(&touchData); + ScaleData(&touchData, 256, 256); // Scale coordinates to arbitrary X, Y resolution + + if (x && y && touchData.xValue && touchData.yValue) { + mouse_report.x = (int8_t)(touchData.xValue - x); + mouse_report.y = (int8_t)(touchData.yValue - y); + } + x = touchData.xValue; + y = touchData.yValue; + + if (rTouchData.buttonFlags) { + mouse_report.buttons |= MOUSE_BTN1; + } 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"); + #elif FEEDCONFIG_1_VALUE == 0x81 Pinnacle_GetRelative(&rTouchData); @@ -71,7 +88,7 @@ void pointing_device_init(void) { // Reads XYZ data from Pinnacle registers 0x14 through 0x17 // Stores result in absData_t struct with xValue, yValue, and zValue members void Pinnacle_GetAbsolute(absData_t* result) { - uint8_t data[6] = { 0 }; + uint8_t data[6] = {0}; RAP_ReadBytes(PACKET_BYTE_0, data, 6); Pinnacle_ClearFlags(); @@ -83,19 +100,16 @@ void Pinnacle_GetAbsolute(absData_t* result) { result->touchDown = result->xValue != 0; } -// Reads XYZ data from Pinnacle registers 0x14 through 0x17 -// Stores result in absData_t struct with xValue, yValue, and zValue members + void Pinnacle_GetRelative(relData_t* result) { - uint8_t data[3] = { 0 }; + uint8_t data[3] = {0}; RAP_ReadBytes(PACKET_BYTE_0, data, 3); Pinnacle_ClearFlags(); result->buttonFlags = (bool)(data[0] & 0x07); - result->xValue = (int8_t)data[1]; - result->yValue = (int8_t)data[2]; - xprintf("Raw X: %3u Neg: %u Raw Y: %3u Neg: %u X:%4d Y: %4d\n", data[1], (data[0] >> 4) & 0x1, data[2], (data[0] >> 5) & 0x1, (int8_t)data[1], (int8_t)data[2]); - + result->xValue = (int8_t)data[1]; + result->yValue = (int8_t)data[2]; } // Clears Status1 register flags (SW_CC and SW_DR) @@ -108,13 +122,13 @@ void Pinnacle_ClearFlags() { void Pinnacle_EnableFeed(bool feedEnable) { uint8_t temp; - RAP_ReadBytes(FEEDCONFIG_1, &temp, 1); // Store contents of FeedConfig1 register + RAP_ReadBytes(FEEDCONFIG_1, &temp, 1); // Store contents of FeedConfig1 register if (feedEnable) { - temp |= 0x01; // Set Feed Enable bit + temp |= 0x01; // Set Feed Enable bit RAP_Write(0x04, temp); } else { - temp &= ~0x01; // Clear Feed Enable bit + temp &= ~0x01; // Clear Feed Enable bit RAP_Write(0x04, temp); } } @@ -125,16 +139,18 @@ void Pinnacle_EnableFeed(bool feedEnable) { void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) { uint8_t ERAControlValue = 0xFF; - Pinnacle_EnableFeed(false); // Disable feed + Pinnacle_EnableFeed(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(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 for (uint16_t i = 0; i < count; i++) { - RAP_Write(ERA_CONTROL, 0x05); // Signal ERA-read (auto-increment) to Pinnacle + RAP_Write(ERA_CONTROL, 0x05); // Signal ERA-read (auto-increment) to Pinnacle // Wait for status register 0x1E to clear - do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00); + do { + RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); + } while (ERAControlValue != 0x00); RAP_ReadBytes(ERA_VALUE, data + i, 1); @@ -146,17 +162,19 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) { void ERA_WriteByte(uint16_t address, uint8_t data) { uint8_t ERAControlValue = 0xFF; - Pinnacle_EnableFeed(false); // Disable feed + Pinnacle_EnableFeed(false); // Disable feed - RAP_Write(ERA_VALUE, data); // Send data byte to be written + RAP_Write(ERA_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(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(ERA_CONTROL, 0x02); // Signal an ERA-write to Pinnacle + RAP_Write(ERA_CONTROL, 0x02); // Signal an ERA-write to Pinnacle // Wait for status register 0x1E to clear - do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00); + do { + RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); + } while (ERAControlValue != 0x00); Pinnacle_ClearFlags(); } @@ -164,7 +182,7 @@ void ERA_WriteByte(uint16_t address, uint8_t data) { /* RAP Functions */ // Reads Pinnacle registers starting at
void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { - uint8_t cmdByte = READ_MASK | address; // Form the READ command byte + uint8_t cmdByte = READ_MASK | address; // Form the READ command byte // uint8_t i = 0; i2c_start(SLAVE_ADDR << 1); @@ -175,7 +193,7 @@ void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { // Writes single-byte to
void RAP_Write(uint8_t address, uint8_t data) { - uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte + uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte i2c_start(SLAVE_ADDR << 1); i2c_writeReg(SLAVE_ADDR << 1, cmdByte, &data, sizeof(data), I2C_TIMEOUT); diff --git a/keyboards/moonlander/cirque_tm040040.h b/keyboards/moonlander/cirque_tm040040.h index fa37a0f1a0..4052868213 100644 --- a/keyboards/moonlander/cirque_tm040040.h +++ b/keyboards/moonlander/cirque_tm040040.h @@ -29,7 +29,7 @@ void Pinnacle_EnableFeed(bool feedEnable); void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count); void ERA_WriteByte(uint16_t address, uint8_t data); void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count); -void RAP_Write(uint8_t address, uint8_t data);;;- +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);