aboutsummaryrefslogtreecommitdiff
path: root/drivers/sensors/cirque_pinnacle_i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sensors/cirque_pinnacle_i2c.c')
-rw-r--r--drivers/sensors/cirque_pinnacle_i2c.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/sensors/cirque_pinnacle_i2c.c b/drivers/sensors/cirque_pinnacle_i2c.c
new file mode 100644
index 000000000..81dd982b0
--- /dev/null
+++ b/drivers/sensors/cirque_pinnacle_i2c.c
@@ -0,0 +1,43 @@
1// Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
2#include "cirque_pinnacle.h"
3#include "i2c_master.h"
4#include "print.h"
5#include "debug.h"
6#include "stdio.h"
7
8// Masks for Cirque Register Access Protocol (RAP)
9#define WRITE_MASK 0x80
10#define READ_MASK 0xA0
11
12extern bool touchpad_init;
13
14/* RAP Functions */
15// Reads <count> Pinnacle registers starting at <address>
16void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
17 uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
18 if (touchpad_init) {
19 i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
20 if (i2c_readReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
21#ifdef CONSOLE_ENABLE
22 dprintf("error right touchpad\n");
23#endif
24 touchpad_init = false;
25 }
26 i2c_stop();
27 }
28}
29
30// Writes single-byte <data> to <address>
31void RAP_Write(uint8_t address, uint8_t data) {
32 uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
33
34 if (touchpad_init) {
35 if (i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
36#ifdef CONSOLE_ENABLE
37 dprintf("error right touchpad\n");
38#endif
39 touchpad_init = false;
40 }
41 i2c_stop();
42 }
43}