i2ccaptouch.c File Reference

I2C touch support on Touch Display.

License

Copyright 2018 Silicon Labs, http://www.silabs.com

This file is licensensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.

Definition in file i2ccaptouch.c .

#include " i2ccaptouch.h "
#include "captouchconfig.h"
#include "i2cspmconfig.h"
#include " i2cspm.h "
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include " em_device.h "
#include " em_cmu.h "
#include " em_core.h "
#include " em_gpio.h "
#include " em_i2c.h "
#include " emstatus.h "
#include " ustimer.h "

Functions

uint32_t CAPT_enable (bool enable, bool wait)
Enable touch controller. When enabling this function will wait until the controller is started before returning.
uint32_t CAPT_getTouches ( CAPT_Touch *touchBuffer, uint8_t len, uint8_t *nTouches)
Update the list of registered touches This function also updates the list of new touches since last time CAPT_update was called.
uint32_t CAPT_init (void)
Initialize capacitive touch controller.
static I2C_TransferReturn_TypeDef controllerRead (void)
Read contents of all registers in the touch controller.
static uint32_t gpioInit (void)
Initialize all GPIO pins.
static uint32_t i2cInit (void)
Initialize I2C peripheral.
static uint32_t parseData ( CAPT_Touch *buffer, uint8_t len, uint8_t *nTouches)
Parse data from i2cReadBuffer into buffer.

Variables

static I2C_TypeDef * i2c = CAPT_CONFIG_I2C
static uint8_t i2cReadBuffer [CAPT_I2C_BUFFER_SIZE]
static volatile uint8_t samplesSinceLastUpdate = 0

Function Documentation

uint32_t CAPT_enable ( bool enable,
bool wait
)

Enable touch controller. When enabling this function will wait until the controller is started before returning.

Parameters
enable If true the controller will be enabled, otherwise it will be disabled.
wait If true when enabling controller, wait for the touch controller to boot after enabling it. Has no effect when disabling the touch controller.
Returns
CAPT_OK on success.

Definition at line 113 of file i2ccaptouch.c .

References GPIO_PinOutClear() , GPIO_PinOutSet() , USTIMER_DeInit() , USTIMER_DelayIntSafe() , and USTIMER_Init() .

uint32_t CAPT_getTouches ( CAPT_Touch * touchBuffer,
uint8_t len,
uint8_t * nTouches
)

Update the list of registered touches This function also updates the list of new touches since last time CAPT_update was called.

Parameters
*buffer Pointer to a buffer in which to store the CAPT_Touch structs
len Length (in number of CAPT_Touch elements) of the buffer
*nTouches Number of touches read out
Returns
CAPT_OK on success. CAPT_ERROR_PARSE_ERROR if data is invalid. CAPT_ERROR_BUFFER_TOO_SMALL if the buffer is too short. In this case as much data as possible is stored in the buffer. CAPT_ERROR_I2C_ERROR on I2C transfer error

Definition at line 161 of file i2ccaptouch.c .

References controllerRead() , and parseData() .

uint32_t CAPT_init ( void )

Initialize capacitive touch controller.

Returns
CAPT_OK on success

Definition at line 81 of file i2ccaptouch.c .

References gpioInit() , and i2cInit() .

static I2C_TransferReturn_TypeDef controllerRead ( void )
static

Read contents of all registers in the touch controller.

Returns
i2cTransferDone on success.

Definition at line 256 of file i2ccaptouch.c .

References I2C_TransferSeq_TypeDef::addr , I2C_TransferSeq_TypeDef::buf , I2C_TransferSeq_TypeDef::data , I2C_TransferSeq_TypeDef::flags , I2C_FLAG_READ , I2C_FLAG_WRITE , I2CSPM_Transfer() , i2cTransferDone , and I2C_TransferSeq_TypeDef::len .

Referenced by CAPT_getTouches() .

static uint32_t gpioInit ( void )
static

Initialize all GPIO pins.

Returns
CAPT_OK on success

Definition at line 201 of file i2ccaptouch.c .

References CMU_ClockEnable() , cmuClock_GPIO , GPIO_PinModeSet() , gpioModeInput , gpioModePushPull , and gpioModeWiredAnd .

Referenced by CAPT_init() .

static uint32_t i2cInit ( void )
static

Initialize I2C peripheral.

Returns
CAPT_OK on success

Definition at line 235 of file i2ccaptouch.c .

References I2CSPM_Init() .

Referenced by BOARD_init() , BSP_initBoard() , CAPT_init() , I2CSPM_Init() , and setupI2C() .

static uint32_t parseData ( CAPT_Touch * buffer,
uint8_t len,
uint8_t * nTouches
)
static

Parse data from i2cReadBuffer into buffer.

Parameters
*buffer Pointer to a buffer in which to store the CAPT_Touch structs
len Length (in number of CAPT_Touch elements) of the buffer
*nTouches Number of touches read out
Returns
CAPT_OK on success. CAPT_ERROR_PARSE_ERROR if data is invalid. CAPT_ERROR_BUFFER_TOO_SMALL if the buffer is too short. In this case as much data as possible is stored in the buffer.

Definition at line 316 of file i2ccaptouch.c .

Referenced by CAPT_getTouches() .