cirque_pinnacle_spi.c (1649B)
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 5 // Masks for Cirque Register Access Protocol (RAP) 6 #define WRITE_MASK 0x80 7 #define READ_MASK 0xA0 8 #define FILLER_BYTE 0xFC 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 15 if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) { 16 spi_write(cmdByte); // write command byte, receive filler 17 spi_write(FILLER_BYTE); // write & receive filler 18 spi_write(FILLER_BYTE); // write & receive filler 19 for (uint8_t i = 0; i < count; i++) { 20 data[i] = spi_write(FILLER_BYTE); // write filler, receive data on the third filler send 21 } 22 } else { 23 pd_dprintf("error cirque_pinnacle spi_start read\n"); 24 pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED); 25 } 26 spi_stop(); 27 } 28 29 // Writes single-byte <data> to <address> 30 void RAP_Write(uint8_t address, uint8_t data) { 31 uint8_t cmdByte = WRITE_MASK | address; // Form the WRITE command byte 32 33 if (spi_start(CIRQUE_PINNACLE_SPI_CS_PIN, CIRQUE_PINNACLE_SPI_LSBFIRST, CIRQUE_PINNACLE_SPI_MODE, CIRQUE_PINNACLE_SPI_DIVISOR)) { 34 spi_write(cmdByte); 35 spi_write(data); 36 } else { 37 pd_dprintf("error cirque_pinnacle spi_start write\n"); 38 pointing_device_set_status(POINTING_DEVICE_STATUS_FAILED); 39 } 40 spi_stop(); 41 }