diff options
Diffstat (limited to 'drivers/sensors/cirque_pinnacle_spi.c')
| -rw-r--r-- | drivers/sensors/cirque_pinnacle_spi.c | 52 |
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 000000000..f3eee8875 --- /dev/null +++ b/drivers/sensors/cirque_pinnacle_spi.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license | ||
| 2 | #include "cirque_pinnacle.h" | ||
| 3 | #include "spi_master.h" | ||
| 4 | #include "print.h" | ||
| 5 | #include "debug.h" | ||
| 6 | |||
| 7 | // Masks for Cirque Register Access Protocol (RAP) | ||
| 8 | #define WRITE_MASK 0x80 | ||
| 9 | #define READ_MASK 0xA0 | ||
| 10 | |||
| 11 | extern bool touchpad_init; | ||
| 12 | |||
| 13 | /* RAP Functions */ | ||
| 14 | // Reads <count> Pinnacle registers starting at <address> | ||
| 15 | void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { | ||
| 16 | uint8_t cmdByte = READ_MASK | address; // Form the READ command byte | ||
| 17 | if (touchpad_init) { | ||
| 18 | if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_TRACKPAD_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) { | ||
| 19 | spi_write(cmdByte); | ||
| 20 | spi_read(); // filler | ||
| 21 | spi_read(); // filler | ||
| 22 | for (uint8_t i = 0; i < count; i++) { | ||
| 23 | data[i] = spi_read(); // each sepsequent read gets another register's contents | ||
| 24 | } | ||
| 25 | } else { | ||
| 26 | #ifdef CONSOLE_ENABLE | ||
| 27 | dprintf("error right touchpad\n"); | ||
| 28 | #endif | ||
| 29 | touchpad_init = false; | ||
| 30 | j | ||
| 31 | } | ||
| 32 | spi_stop(); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | // Writes single-byte <data> to <address> | ||
| 37 | void RAP_Write(uint8_t address, uint8_t data) { | ||
| 38 | uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte | ||
| 39 | |||
| 40 | if (touchpad_init) { | ||
| 41 | if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_TRACKPAD_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) { | ||
| 42 | spi_write(cmdByte); | ||
| 43 | spi_write(data); | ||
| 44 | } else { | ||
| 45 | #ifdef CONSOLE_ENABLE | ||
| 46 | dprintf("error right touchpad\n"); | ||
| 47 | #endif | ||
| 48 | touchpad_init = false; | ||
| 49 | } | ||
| 50 | spi_stop(); | ||
| 51 | } | ||
| 52 | } | ||
