2021-11-15 07:03:24 +01:00
|
|
|
// Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
|
|
|
|
#include "cirque_pinnacle.h"
|
|
|
|
#include "i2c_master.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
|
|
// Masks for Cirque Register Access Protocol (RAP)
|
|
|
|
#define WRITE_MASK 0x80
|
|
|
|
#define READ_MASK 0xA0
|
|
|
|
|
|
|
|
extern bool touchpad_init;
|
|
|
|
|
|
|
|
/* RAP Functions */
|
|
|
|
// Reads <count> Pinnacle registers starting at <address>
|
|
|
|
void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
|
2022-02-12 19:29:31 +01:00
|
|
|
uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
|
2021-11-15 07:03:24 +01:00
|
|
|
if (touchpad_init) {
|
2024-01-16 03:26:40 +01:00
|
|
|
i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
|
|
|
|
if (i2c_read_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
|
|
|
|
pd_dprintf("error cirque_pinnacle i2c_read_register\n");
|
2021-11-15 07:03:24 +01:00
|
|
|
touchpad_init = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes single-byte <data> to <address>
|
|
|
|
void RAP_Write(uint8_t address, uint8_t data) {
|
2022-02-12 19:29:31 +01:00
|
|
|
uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
|
2021-11-15 07:03:24 +01:00
|
|
|
|
|
|
|
if (touchpad_init) {
|
2024-01-16 03:26:40 +01:00
|
|
|
if (i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
|
|
|
|
pd_dprintf("error cirque_pinnacle i2c_write_register\n");
|
2021-11-15 07:03:24 +01:00
|
|
|
touchpad_init = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|