2021-11-15 12:03:24 +06:00
|
|
|
// Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
|
|
|
|
#include "cirque_pinnacle.h"
|
|
|
|
#include "spi_master.h"
|
|
|
|
#include "print.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
// Masks for Cirque Register Access Protocol (RAP)
|
|
|
|
#define WRITE_MASK 0x80
|
|
|
|
#define READ_MASK 0xA0
|
2022-05-13 12:21:25 +06:00
|
|
|
#define FILLER_BYTE 0xFC
|
2021-11-15 12:03:24 +06:00
|
|
|
|
|
|
|
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-13 00:29:31 +06:00
|
|
|
uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
|
2021-11-15 12:03:24 +06:00
|
|
|
if (touchpad_init) {
|
2021-12-16 03:41:07 +06:00
|
|
|
if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
|
2022-05-13 12:21:25 +06:00
|
|
|
spi_write(cmdByte); // write command byte, receive filler
|
|
|
|
spi_write(FILLER_BYTE); // write & receive filler
|
|
|
|
spi_write(FILLER_BYTE); // write & receive filler
|
2021-11-15 12:03:24 +06:00
|
|
|
for (uint8_t i = 0; i < count; i++) {
|
2022-05-13 12:21:25 +06:00
|
|
|
data[i] = spi_write(FILLER_BYTE); // write filler, receive data on the third filler send
|
2021-11-15 12:03:24 +06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#ifdef CONSOLE_ENABLE
|
2022-06-26 02:22:28 +06:00
|
|
|
dprintf("error cirque_pinnacle spi_start read\n");
|
2021-11-15 12:03:24 +06:00
|
|
|
#endif
|
|
|
|
touchpad_init = false;
|
|
|
|
}
|
|
|
|
spi_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Writes single-byte <data> to <address>
|
|
|
|
void RAP_Write(uint8_t address, uint8_t data) {
|
2022-02-13 00:29:31 +06:00
|
|
|
uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
|
2021-11-15 12:03:24 +06:00
|
|
|
|
|
|
|
if (touchpad_init) {
|
2021-12-16 03:41:07 +06:00
|
|
|
if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
|
2021-11-15 12:03:24 +06:00
|
|
|
spi_write(cmdByte);
|
|
|
|
spi_write(data);
|
|
|
|
} else {
|
|
|
|
#ifdef CONSOLE_ENABLE
|
2022-06-26 02:22:28 +06:00
|
|
|
dprintf("error cirque_pinnacle spi_start write\n");
|
2021-11-15 12:03:24 +06:00
|
|
|
#endif
|
|
|
|
touchpad_init = false;
|
|
|
|
}
|
|
|
|
spi_stop();
|
|
|
|
}
|
|
|
|
}
|