Properly set Register values as defines and cleanup

This commit is contained in:
Drashna Jael're
2021-06-04 09:24:45 -07:00
parent b08a5412a7
commit 553a3ee742
2 changed files with 73 additions and 63 deletions

View File

@@ -2,28 +2,12 @@
#include "i2c_master.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
#define SYSCONFIG_1 0x00
#define FEEDCONFIG_1 0x03
#define FEEDCONFIG_2 0x1F
#define Z_IDLE_COUNT 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)
#define SYSCONFIG_1_VALUE 0x00
#define FEEDCONFIG_1_VALUE 0x03
#define FEEDCONFIG_2_VALUE 0x1F
#define Z_IDLE_COUNT_VALUE 0x05
absData_t touchData;
@@ -32,8 +16,8 @@ void print_byte(uint8_t byte) { dprintf("%c%c%c%c%c%c%c%c|", (byte & 0x80 ? '1'
#endif
void pointing_device_task(void) {
Pinnacle_GetAbsolute(&touchData);
ScaleData(&touchData, 256, 256); // Scale coordinates to arbitrary X, Y resolution
Pinnacle_GetAbsolute(&touchData);
ScaleData(&touchData, 256, 256); // Scale coordinates to arbitrary X, Y resolution
#ifdef CONSOLE_ENABLE
print_byte(touchData.xValue);
@@ -51,21 +35,21 @@ void pointing_device_init(void) {
Pinnacle_ClearFlags();
// Host configures bits of registers 0x03 and 0x05
RAP_Write(0x03, SYSCONFIG_1);
RAP_Write(0x05, FEEDCONFIG_2);
RAP_Write(SYSCONFIG_1, SYSCONFIG_1_VALUE);
RAP_Write(FEEDCONFIG_2, FEEDCONFIG_2_VALUE);
// 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)
RAP_Write(0x0A, Z_IDLE_COUNT);
RAP_Write(Z_IDLE_COUNT, Z_IDLE_COUNT_VALUE);
}
// 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, 0, 0, 0, 0, 0};
RAP_ReadBytes(0x12, data, 6);
RAP_ReadBytes(PACKET_BYTE_0), data, 6);
Pinnacle_ClearFlags();
@@ -79,7 +63,7 @@ void Pinnacle_GetAbsolute(absData_t* result) {
// Clears Status1 register flags (SW_CC and SW_DR)
void Pinnacle_ClearFlags() {
RAP_Write(0x02, 0x00);
RAP_Write(STATUS_1, 0x00);
wait_us(50);
}
@@ -87,13 +71,13 @@ void Pinnacle_ClearFlags() {
void Pinnacle_EnableFeed(bool feedEnable) {
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) {
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);
}
}
@@ -104,20 +88,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(0x1C, (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_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(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
do {
RAP_ReadBytes(0x1E, &ERAControlValue, 1);
} while (ERAControlValue != 0x00);
do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00);
RAP_ReadBytes(0x1B, data + i, 1);
RAP_ReadBytes(ERA_VALUE, data + i, 1);
Pinnacle_ClearFlags();
}
@@ -127,19 +109,17 @@ 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(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(0x1D, (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(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
do {
RAP_ReadBytes(0x1E, &ERAControlValue, 1);
} while (ERAControlValue != 0x00);
do { RAP_ReadBytes(ERA_CONTROL, &ERAControlValue, 1); } while (ERAControlValue != 0x00);
Pinnacle_ClearFlags();
}
@@ -147,35 +127,22 @@ void ERA_WriteByte(uint16_t address, uint8_t data) {
/* RAP Functions */
// Reads <count> Pinnacle registers starting at <address>
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);
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, NULL, 0, I2C_TIMEOUT);
i2c_readReg(SLAVE_ADDR << 1, cmdByte, data, count, I2C_TIMEOUT);
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>
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_start(SLAVE_ADDR << 1);
i2c_writeReg(SLAVE_ADDR << 1, cmdByte, &data, sizeof(data), I2C_TIMEOUT);
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 */

View File

@@ -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 ClipCoordinates(absData_t* coordinates);
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