cirque_pinnacle_spi.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /* RAP Functions */
  9. // Reads <count> Pinnacle registers starting at <address>
  10. void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) {
  11. uint8_t cmdByte = READ_MASK | address; // Form the READ command byte
  12. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  13. spi_write(cmdByte); // write command byte, receive filler
  14. spi_write(FILLER_BYTE); // write & receive filler
  15. spi_write(FILLER_BYTE); // write & receive filler
  16. for (uint8_t i = 0; i < count; i++) {
  17. data[i] = spi_write(FILLER_BYTE); // write filler, receive data on the third filler send
  18. }
  19. } else {
  20. pd_dprintf("error cirque_pinnacle spi_start read\n");
  21. pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED);
  22. }
  23. spi_stop();
  24. }
  25. // Writes single-byte <data> to <address>
  26. void RAP_Write(uint8_t address, uint8_t data) {
  27. uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
  28. if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) {
  29. spi_write(cmdByte);
  30. spi_write(data);
  31. } else {
  32. pd_dprintf("error cirque_pinnacle spi_start write\n");
  33. pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED);
  34. }
  35. spi_stop();
  36. }