You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.8 KiB

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