mirror of
https://github.com/zsa/qmk_firmware.git
synced 2026-05-05 16:59:20 +00:00
Properly set Register values as defines and cleanup
This commit is contained in:
@@ -2,28 +2,12 @@
|
|||||||
#include "i2c_master.h"
|
#include "i2c_master.h"
|
||||||
#include "cirque_tm040040.h"
|
#include "cirque_tm040040.h"
|
||||||
|
|
||||||
// Cirque's 7-bit I2C Slave Address
|
|
||||||
#define SLAVE_ADDR 0x2A
|
|
||||||
|
|
||||||
// Masks for Cirque Register Access Protocol (RAP)
|
|
||||||
#define WRITE_MASK 0x80
|
|
||||||
#define READ_MASK 0xA0
|
|
||||||
|
|
||||||
// Register config values for this demo
|
// Register config values for this demo
|
||||||
#define SYSCONFIG_1 0x00
|
#define SYSCONFIG_1_VALUE 0x00
|
||||||
#define FEEDCONFIG_1 0x03
|
#define FEEDCONFIG_1_VALUE 0x03
|
||||||
#define FEEDCONFIG_2 0x1F
|
#define FEEDCONFIG_2_VALUE 0x1F
|
||||||
#define Z_IDLE_COUNT 0x05
|
#define Z_IDLE_COUNT_VALUE 0x05
|
||||||
|
|
||||||
// Coordinate scaling values
|
|
||||||
#define PINNACLE_XMAX 2047 // max value Pinnacle can report for X
|
|
||||||
#define PINNACLE_YMAX 1535 // max value Pinnacle can report for Y
|
|
||||||
#define PINNACLE_X_LOWER 127 // min "reachable" X value
|
|
||||||
#define PINNACLE_X_UPPER 1919 // max "reachable" X value
|
|
||||||
#define PINNACLE_Y_LOWER 63 // min "reachable" Y value
|
|
||||||
#define PINNACLE_Y_UPPER 1471 // max "reachable" Y value
|
|
||||||
#define PINNACLE_X_RANGE (PINNACLE_X_UPPER - PINNACLE_X_LOWER)
|
|
||||||
#define PINNACLE_Y_RANGE (PINNACLE_Y_UPPER - PINNACLE_Y_LOWER)
|
|
||||||
|
|
||||||
absData_t touchData;
|
absData_t touchData;
|
||||||
|
|
||||||
@@ -51,21 +35,21 @@ void pointing_device_init(void) {
|
|||||||
Pinnacle_ClearFlags();
|
Pinnacle_ClearFlags();
|
||||||
|
|
||||||
// Host configures bits of registers 0x03 and 0x05
|
// Host configures bits of registers 0x03 and 0x05
|
||||||
RAP_Write(0x03, SYSCONFIG_1);
|
RAP_Write(SYSCONFIG_1, SYSCONFIG_1_VALUE);
|
||||||
RAP_Write(0x05, FEEDCONFIG_2);
|
RAP_Write(FEEDCONFIG_2, FEEDCONFIG_2_VALUE);
|
||||||
|
|
||||||
// Host enables preferred output mode (absolute)
|
// Host enables preferred output mode (absolute)
|
||||||
RAP_Write(0x04, FEEDCONFIG_1);
|
RAP_Write(FEEDCONFIG_1, FEEDCONFIG_1_VALUE);
|
||||||
|
|
||||||
// Host sets z-idle packet count to 5 (default is 30)
|
// Host sets z-idle packet count to 5 (default is 30)
|
||||||
RAP_Write(0x0A, Z_IDLE_COUNT);
|
RAP_Write(Z_IDLE_COUNT, Z_IDLE_COUNT_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads XYZ data from Pinnacle registers 0x14 through 0x17
|
// Reads XYZ data from Pinnacle registers 0x14 through 0x17
|
||||||
// Stores result in absData_t struct with xValue, yValue, and zValue members
|
// Stores result in absData_t struct with xValue, yValue, and zValue members
|
||||||
void Pinnacle_GetAbsolute(absData_t* result) {
|
void Pinnacle_GetAbsolute(absData_t* result) {
|
||||||
uint8_t data[6] = {0, 0, 0, 0, 0, 0};
|
uint8_t data[6] = {0, 0, 0, 0, 0, 0};
|
||||||
RAP_ReadBytes(0x12, data, 6);
|
RAP_ReadBytes(PACKET_BYTE_0), data, 6);
|
||||||
|
|
||||||
Pinnacle_ClearFlags();
|
Pinnacle_ClearFlags();
|
||||||
|
|
||||||
@@ -79,7 +63,7 @@ void Pinnacle_GetAbsolute(absData_t* result) {
|
|||||||
|
|
||||||
// Clears Status1 register flags (SW_CC and SW_DR)
|
// Clears Status1 register flags (SW_CC and SW_DR)
|
||||||
void Pinnacle_ClearFlags() {
|
void Pinnacle_ClearFlags() {
|
||||||
RAP_Write(0x02, 0x00);
|
RAP_Write(STATUS_1, 0x00);
|
||||||
wait_us(50);
|
wait_us(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +71,7 @@ void Pinnacle_ClearFlags() {
|
|||||||
void Pinnacle_EnableFeed(bool feedEnable) {
|
void Pinnacle_EnableFeed(bool feedEnable) {
|
||||||
uint8_t temp;
|
uint8_t temp;
|
||||||
|
|
||||||
RAP_ReadBytes(0x04, &temp, 1); // Store contents of FeedConfig1 register
|
RAP_ReadBytes(FEEDCONFIG_1, &temp, 1); // Store contents of FeedConfig1 register
|
||||||
|
|
||||||
if (feedEnable) {
|
if (feedEnable) {
|
||||||
temp |= 0x01; // Set Feed Enable bit
|
temp |= 0x01; // Set Feed Enable bit
|
||||||
@@ -106,18 +90,16 @@ void ERA_ReadBytes(uint16_t address, uint8_t* data, uint16_t count) {
|
|||||||
|
|
||||||
Pinnacle_EnableFeed(false); // Disable feed
|
Pinnacle_EnableFeed(false); // Disable feed
|
||||||
|
|
||||||
RAP_Write(0x1C, (uint8_t)(address >> 8)); // Send upper byte of ERA address
|
RAP_Write(ERA_HIGH_BYTE, (uint8_t)(address >> 8)); // Send upper byte of ERA address
|
||||||
RAP_Write(0x1D, (uint8_t)(address & 0x00FF)); // Send lower 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++) {
|
for (uint16_t i = 0; i < count; i++) {
|
||||||
RAP_Write(0x1E, 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
|
// Wait for status register 0x1E to clear
|
||||||
do {
|
do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00);
|
||||||
RAP_ReadBytes(0x1E, &ERAControlValue, 1);
|
|
||||||
} while (ERAControlValue != 0x00);
|
|
||||||
|
|
||||||
RAP_ReadBytes(0x1B, data + i, 1);
|
RAP_ReadBytes(ERA_VALUE, data + i, 1);
|
||||||
|
|
||||||
Pinnacle_ClearFlags();
|
Pinnacle_ClearFlags();
|
||||||
}
|
}
|
||||||
@@ -129,17 +111,15 @@ void ERA_WriteByte(uint16_t address, uint8_t data) {
|
|||||||
|
|
||||||
Pinnacle_EnableFeed(false); // Disable feed
|
Pinnacle_EnableFeed(false); // Disable feed
|
||||||
|
|
||||||
RAP_Write(0x1B, data); // Send data byte to be written
|
RAP_Write(ERA_VALUE, data); // Send data byte to be written
|
||||||
|
|
||||||
RAP_Write(0x1C, (uint8_t)(address >> 8)); // Upper byte of ERA address
|
RAP_Write(ERA_HIGH_BYTE, (uint8_t)(address >> 8)); // Upper byte of ERA address
|
||||||
RAP_Write(0x1D, (uint8_t)(address & 0x00FF)); // Lower byte of ERA address
|
RAP_Write(ERA_LOW_BYTE, (uint8_t)(address & 0x00FF)); // Lower byte of ERA address
|
||||||
|
|
||||||
RAP_Write(0x1E, 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
|
// Wait for status register 0x1E to clear
|
||||||
do {
|
do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00);
|
||||||
RAP_ReadBytes(0x1E, &ERAControlValue, 1);
|
|
||||||
} while (ERAControlValue != 0x00);
|
|
||||||
|
|
||||||
Pinnacle_ClearFlags();
|
Pinnacle_ClearFlags();
|
||||||
}
|
}
|
||||||
@@ -154,14 +134,6 @@ void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
|
|||||||
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, NULL, 0, I2C_TIMEOUT);
|
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, NULL, 0, I2C_TIMEOUT);
|
||||||
i2c_readReg(SLAVE_ADDR << 1, cmdByte, data, count, I2C_TIMEOUT);
|
i2c_readReg(SLAVE_ADDR << 1, cmdByte, data, count, I2C_TIMEOUT);
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
// Wire.beginTransmission(SLAVE_ADDR); // Set up an I2C-write to the I2C slave (Pinnacle)
|
|
||||||
// Wire.write(cmdByte); // Signal a RAP-read operation starting at <address>
|
|
||||||
// Wire.endTransmission(true); // I2C stop condition
|
|
||||||
|
|
||||||
// Wire.requestFrom((uint8_t)SLAVE_ADDR, count, (uint8_t) true); // Read <count> bytes from I2C slave
|
|
||||||
// while (Wire.available()) {
|
|
||||||
// data[i++] = Wire.read();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writes single-byte <data> to <address>
|
// Writes single-byte <data> to <address>
|
||||||
@@ -171,11 +143,6 @@ void RAP_Write(uint8_t address, uint8_t data) {
|
|||||||
i2c_start(SLAVE_ADDR << 1);
|
i2c_start(SLAVE_ADDR << 1);
|
||||||
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, &data, sizeof(data), I2C_TIMEOUT);
|
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, &data, sizeof(data), I2C_TIMEOUT);
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
|
|
||||||
// Wire.beginTransmission(SLAVE_ADDR); // Set up an I2C-write to the I2C slave (Pinnacle)
|
|
||||||
// Wire.send(cmdByte); // Signal a RAP-write operation at <address>
|
|
||||||
// Wire.send(data); // Write <data> to I2C slave
|
|
||||||
// Wire.endTransmission(true); // I2C stop condition
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Logical Scaling Functions */
|
/* Logical Scaling Functions */
|
||||||
|
|||||||
@@ -24,3 +24,46 @@ 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 ClipCoordinates(absData_t* coordinates);
|
||||||
void ScaleData(absData_t* coordinates, uint16_t xResolution, uint16_t yResolution);
|
void ScaleData(absData_t* coordinates, uint16_t xResolution, uint16_t yResolution);
|
||||||
|
|
||||||
|
// Cirque's 7-bit I2C Slave Address
|
||||||
|
#define SLAVE_ADDR 0x2A
|
||||||
|
|
||||||
|
// Masks for Cirque Register Access Protocol (RAP)
|
||||||
|
#define WRITE_MASK 0x80
|
||||||
|
#define READ_MASK 0xA0
|
||||||
|
|
||||||
|
// Registers for RAP
|
||||||
|
#define FIRMWARE_ID 0x00
|
||||||
|
#define FIRMWARE_VERSION 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
|
||||||
|
|
||||||
|
// Coordinate scaling values
|
||||||
|
#define PINNACLE_XMAX 2047 // max value Pinnacle can report for X
|
||||||
|
#define PINNACLE_YMAX 1535 // max value Pinnacle can report for Y
|
||||||
|
#define PINNACLE_X_LOWER 127 // min "reachable" X value
|
||||||
|
#define PINNACLE_X_UPPER 1919 // max "reachable" X value
|
||||||
|
#define PINNACLE_Y_LOWER 63 // min "reachable" Y value
|
||||||
|
#define PINNACLE_Y_UPPER 1471 // max "reachable" Y value
|
||||||
|
#define PINNACLE_X_RANGE (PINNACLE_X_UPPER - PINNACLE_X_LOWER)
|
||||||
|
#define PINNACLE_Y_RANGE (PINNACLE_Y_UPPER - PINNACLE_Y_LOWER)
|
||||||
|
|
||||||
|
#define ERA_VALUE 0x1B
|
||||||
|
#define ERA_HIGH_BYTE 0x1C
|
||||||
|
#define ERA_LOW_BYTE 0x1D
|
||||||
|
#define ERA_CONTROL 0x1E
|
||||||
|
|||||||
Reference in New Issue
Block a user