i2ccaptouch.c File Reference

I2C touch support on Touch Display.

License

Copyright 2018 Silicon Laboratories Inc. www.silabs.com

SPDX-License-Identifier: Zlib

The licensor of this software is Silicon Laboratories Inc.

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

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 129 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 177 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 97 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 272 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 217 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 251 of file i2ccaptouch.c .

References I2CSPM_Init() .

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

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 332 of file i2ccaptouch.c .

Referenced by CAPT_getTouches() .