cirque_pinnacle_spi.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // Masks for Cirque Register Access Protocol (RAP)
  5. #define WRITE_MASK 0x80
  6. #define READ_MASK 0xA0
  7. #define FILLER_BYTE 0xFC
  8. extern bool touchpad_init;
  9. /* RAP Functions */
  10. // Reads <count> Pinnacle registers starting at <address>
  11. void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
  12. uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
  13. if (touchpad_init) {
  14. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  15. spi_write(cmdByte); // write command byte, receive filler
  16. spi_write(FILLER_BYTE); // write & receive filler
  17. spi_write(FILLER_BYTE); // write & receive filler
  18. for (uint8_t i = 0; i < count; i++) {
  19. data[i] = spi_write(FILLER_BYTE); // write filler, receive data on the third filler send
  20. }
  21. } else {
  22. pd_dprintf("error cirque_pinnacle spi_start read\n");
  23. touchpad_init = false;
  24. }
  25. spi_stop();
  26. }
  27. }
  28. // Writes single-byte <data> to <address>
  29. void RAP_Write(uint8_t address, uint8_t data) {
  30. uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
  31. if (touchpad_init) {
  32. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  33. spi_write(cmdByte);
  34. spi_write(data);
  35. } else {
  36. pd_dprintf("error cirque_pinnacle spi_start write\n");
  37. touchpad_init = false;
  38. }
  39. spi_stop();
  40. }
  41. }