summaryrefslogtreecommitdiff
path: root/drivers/sensors/cirque_pinnacle_spi.c
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-11-14 22:03:24 -0800
committerGitHub <noreply@github.com>2021-11-14 22:03:24 -0800
commit56e3f06a26851976e559aacf7a096c61403304be (patch)
tree1e9ec98ad239fdd241e77ac4c4822fc2721a9cea /drivers/sensors/cirque_pinnacle_spi.c
parent462c3a615113e84ac3ca837a5caeb928c0ec8505 (diff)
downloadqmk_firmware-56e3f06a26851976e559aacf7a096c61403304be.tar.gz
qmk_firmware-56e3f06a26851976e559aacf7a096c61403304be.zip
Rework and expand Pointing Device support (#14343)
Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
Diffstat (limited to 'drivers/sensors/cirque_pinnacle_spi.c')
-rw-r--r--drivers/sensors/cirque_pinnacle_spi.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/sensors/cirque_pinnacle_spi.c b/drivers/sensors/cirque_pinnacle_spi.c
new file mode 100644
index 0000000000..f3eee88758
--- /dev/null
+++ b/drivers/sensors/cirque_pinnacle_spi.c
@@ -0,0 +1,52 @@
+// 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
+
+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) {
+ uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
+ if (touchpad_init) {
+ if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_TRACKPAD_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
+ spi_write(cmdByte);
+ spi_read(); // filler
+ spi_read(); // filler
+ for (uint8_t i = 0; i < count; i++) {
+ data[i] = spi_read(); // each sepsequent read gets another register's contents
+ }
+ } else {
+#ifdef CONSOLE_ENABLE
+ dprintf("error right touchpad\n");
+#endif
+ touchpad_init = false;
+ j
+ }
+ spi_stop();
+ }
+}
+
+// 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
+
+ if (touchpad_init) {
+ if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_TRACKPAD_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
+ spi_write(cmdByte);
+ spi_write(data);
+ } else {
+#ifdef CONSOLE_ENABLE
+ dprintf("error right touchpad\n");
+#endif
+ touchpad_init = false;
+ }
+ spi_stop();
+ }
+}