17 #include "cpt112s_config.h"
55 static uint16_t capsenseCurrent, sliderCurrent;
56 static uint16_t capsensePrevious, sliderPrevious;
59 static uint8_t i2c_rxBuffer[CPT112S_I2C_RXBUFFER_SIZE];
62 static volatile bool i2c_rxInProgress;
63 static volatile bool i2c_startTx;
72 static void parseI2C(
void);
82 uint16_t CPT112S_getCapsenseCurrent(
void)
84 return capsenseCurrent;
91 uint16_t CPT112S_getCapsensePrevious(
void)
93 return capsensePrevious;
99 uint16_t CPT112S_getSliderCurrent(
void)
101 return sliderCurrent;
107 uint16_t CPT112S_getSliderPrevious(
void)
109 return sliderPrevious;
115 void CPT112S_init(
void)
121 capsensePrevious = 0;
122 sliderCurrent = 0xFFFF;
123 sliderPrevious = 0xFFFF;
129 void CPT112S_update(
void)
132 capsensePrevious = capsenseCurrent;
133 sliderPrevious = sliderCurrent;
150 if((i2c_rxBuffer[0] & 0x0F) == CPT112S_I2C_TOUCH_EVENT)
152 sliderCurrent = 0xFFFF;
153 capsenseCurrent |= 1 << i2c_rxBuffer[1];
155 else if((i2c_rxBuffer[0] & 0x0F) == CPT112S_I2C_RELEASE_EVENT)
157 sliderCurrent = 0xFFFF;
158 capsenseCurrent &= ~(1 << i2c_rxBuffer[1]);
160 else if((i2c_rxBuffer[0] & 0x0F) == CPT112S_I2C_SLIDER_ACTIVITY)
162 sliderCurrent = (i2c_rxBuffer[1] << 8) | (i2c_rxBuffer[2]);
187 #ifdef I2C_INIT_FAST_MODE
195 #ifdef CS0_SENSOR_EN_PORT
207 #ifdef CS0_I2C_SDA_LOC
209 I2C0->ROUTEPEN = I2C_ROUTEPEN_SDAPEN | I2C_ROUTEPEN_SCLPEN;
210 I2C0->ROUTELOC0 = (CS0_I2C_SDA_LOC << _I2C_ROUTELOC0_SDALOC_SHIFT) |
211 (CS0_I2C_SCL_LOC << _I2C_ROUTELOC0_SCLLOC_SHIFT);
223 i2c_rxInProgress =
false;
238 i2cTransfer.
addr = CPT112S_I2C_ADDRESS;
240 i2cTransfer.
buf[0].
data = i2c_rxBuffer;
241 i2cTransfer.
buf[0].
len = CPT112S_I2C_RXBUFFER_SIZE;
Clock management unit (CMU) API.
void CMU_ClockSelectSet(CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref)
Select reference clock/oscillator used for a clock branch.
#define I2C_FLAG_READ
Indicate plain read sequence: S+ADDR(R)+DATA0+P.
I2C_TransferReturn_TypeDef I2C_TransferInit(I2C_TypeDef *i2c, I2C_TransferSeq_TypeDef *seq)
Prepare and start an I2C transfer (single master mode only).
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
Driver for retrieving capsense button and slider inputs from CPT112S.
void I2C_Init(I2C_TypeDef *i2c, const I2C_Init_TypeDef *init)
Initialize I2C.
General Purpose IO (GPIO) peripheral API.
struct I2C_TransferSeq_TypeDef::@0 buf[2]
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define _I2C_ROUTE_LOCATION_SHIFT
Master mode transfer message structure used to define a complete I2C transfer sequence (from start to...
void CMU_OscillatorEnable(CMU_Osc_TypeDef osc, bool enable, bool wait)
Enable/disable oscillator.
static void setupOscillators(void)
Starting oscillators and enabling clocks.
Inter-intergrated circuit (I2C) peripheral API.
static void performI2CTransfer(void)
Transmitting I2C data. Will busy-wait until the transfer is complete.
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
uint16_t addr
Address to use after (repeated) start.
static void setupI2C(void)
Setup I2C.
I2C_TransferReturn_TypeDef I2C_Transfer(I2C_TypeDef *i2c)
Continue an initiated I2C transfer (single master mode only).