cirque_pinnacle_i2c.c 1.2 KB

12345678910111213141516171819202122232425262728
  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 "stdio.h"
  5. // Masks for Cirque Register Access Protocol (RAP)
  6. #define WRITE_MASK 0x80
  7. #define READ_MASK 0xA0
  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. i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT);
  13. if (i2c_read_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
  14. pd_dprintf("error cirque_pinnacle i2c_read_register\n");
  15. pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED);
  16. }
  17. }
  18. // Writes single-byte <data> to <address>
  19. void RAP_Write(uint8_t address, uint8_t data) {
  20. uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte
  21. if (i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) {
  22. pd_dprintf("error cirque_pinnacle i2c_write_register\n");
  23. pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED);
  24. }
  25. }