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.

43 lines
1.4 KiB

  1. // Copyright (c) 2018 Cirque Corp. Restrictions apply. See: www.cirque.com/sw-license
  2. #include "cirque_pinnacle.h"
  3. #include "i2c_master.h"
  4. #include "print.h"
  5. #include "debug.h"
  6. #include "stdio.h"
  7. // Masks for Cirque Register Access Protocol (RAP)
  8. #define WRITE_MASK 0x80
  9. #define READ_MASK 0xA0
  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. i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
  17. if (i2c_readReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
  18. #ifdef CONSOLE_ENABLE
  19. dprintf("error right touchpad\n");
  20. #endif
  21. touchpad_init = false;
  22. }
  23. i2c_stop();
  24. }
  25. }
  26. // Writes single-byte <data> to <address>
  27. void RAP_Write(uint8_t address, uint8_t data) {
  28. uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
  29. if (touchpad_init) {
  30. if (i2c_writeReg(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
  31. #ifdef CONSOLE_ENABLE
  32. dprintf("error right touchpad\n");
  33. #endif
  34. touchpad_init = false;
  35. }
  36. i2c_stop();
  37. }
  38. }