cirque_pinnacle_i2c.c (1278B)
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 6 // Masks for Cirque Register Access Protocol (RAP) 7 #define WRITE_MASK 0x80 8 #define READ_MASK 0xA0 9 10 /* RAP Functions */ 11 // Reads <count> Pinnacle registers starting at <address> 12 void RAP_ReadBytes(uint8_t address, uint8_t* data, uint8_t count) { 13 uint8_t cmdByte = READ_MASK | address; // Form the READ command byte 14 i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, NULL, 0, CIRQUE_PINNACLE_TIMEOUT); 15 if (i2c_read_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, data, count, CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) { 16 pd_dprintf("error cirque_pinnacle i2c_read_register\n"); 17 pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED); 18 } 19 } 20 21 // Writes single-byte <data> to <address> 22 void RAP_Write(uint8_t address, uint8_t data) { 23 uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte 24 if (i2c_write_register(CIRQUE_PINNACLE_ADDR << 1, cmdByte, &data, sizeof(data), CIRQUE_PINNACLE_TIMEOUT) != I2C_STATUS_SUCCESS) { 25 pd_dprintf("error cirque_pinnacle i2c_write_register\n"); 26 pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED); 27 } 28 }