cirque_pinnacle_spi.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // Masks for Cirque Register Access Protocol (RAP)
  7. #define WRITE_MASK 0x80
  8. #define READ_MASK 0xA0
  9. extern bool touchpad_init;
  10. /* RAP Functions */
  11. // Reads <count> Pinnacle registers starting at <address>
  12. void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
  13. uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
  14. if (touchpad_init) {
  15. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  16. spi_write(cmdByte);
  17. spi_read(); // filler
  18. spi_read(); // filler
  19. for (uint8_t i = 0; i < count; i++) {
  20. data[i] = spi_read(); // each sepsequent read gets another register's contents
  21. }
  22. } else {
  23. #ifdef CONSOLE_ENABLE
  24. dprintf("error right touchpad\n");
  25. #endif
  26. touchpad_init = false;
  27. }
  28. spi_stop();
  29. }
  30. }
  31. // Writes single-byte <data> to <address>
  32. void RAP_Write(uint8_t address, uint8_t data) {
  33. uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
  34. if (touchpad_init) {
  35. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  36. spi_write(cmdByte);
  37. spi_write(data);
  38. } else {
  39. #ifdef CONSOLE_ENABLE
  40. dprintf("error right touchpad\n");
  41. #endif
  42. touchpad_init = false;
  43. }
  44. spi_stop();
  45. }
  46. }