Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
shilpasonone04
Level 1
Level 1
25 sign-ins 10 sign-ins 5 questions asked

My touchpad code is for cursor rotation and left and right buttons. but it not working proper. My code is as below. please check and suggest  required changes.

/*------------------------------------------------------------------------------------

Project : Touchpad USB Output(LP3963)
File Name :
Conrtroller : CYPRESS CY8C4246AZI-L445 Bit:32
Version : V0
Description : This file is used to Process Trackpad & Gesture status and transfers over UART to USB controller
Created By : Jagdish Mali
Date : 10th July 2021
-------------------------------------------------------------------------------------*/

//---------Inclusion of Header Files-------//
#include "project.h"
/* Include boolean function definition */
#include <stdbool.h>
#include <cytypes.h>

//#define SQUARMOUSETEST
//#define PRINTtoTERMINAL

/* Trackpad X and Y coordinate related macros */
#define X_POSITION (0u)
#define Y_POSITION (1u)
#define X_POSITION_NEGATIVE (2u)
#define Y_POSITION_NEGATIVE (4u)

#define BufferSize (5u) //Button,X Data,Y Data,Wheel

#define DATA_BYTE1_INDEX (0u)
#define DATA_BYTE2_INDEX (1u)
#define DATA_BYTE3_INDEX (2u)
#define DATA_BYTE4_INDEX (3u)
#define DATA_BYTE5_INDEX (4u)

/* Mouse click function macros */
#define MOUSE_FN_NO_CLICK (0u)
#define MOUSE_FN_LEFT_CLICK (1u)
#define MOUSE_FN_RIGHT_CLICK (2u)
/* HID macros */
#define MOUSE_FUNCTION (1u)
#define MOUSE_DATA_BYTES_COUNT (5u)
#define HID_DATA_INVALID (0u)
#define HID_DATA_VALID (1u)
#define DUT_ID_INDEX (0u)
#define HID_DATA_VALID_INDEX (1u)
#define BYTES_IN_BUFFER_INDEX (2u)
#define HID_TYPE_INDEX (3u)

/* Threshold for the delta position after which
* position is scaled by a factor of 2.
*/
#define DELTA_POS_MULT_THRESHOLD (5u)

#define FALSE (false)
#define TRUE (true)

/* Defines the relative horizontal scroll bar movement to report when the user
* issues the scroll gesture for the first time.
*/
#define START_SCROLL_SPEED (4)

/* This macro defines the relative horizontal scroll bar movement to report when
* the user intends to scroll continuously.
*/
#define CONT_SCROLL_SPEED (1)
/* When the user intends to move the scroll bar continuously, the relative
* position is not continuously sent to the computer. In order to control the
* speed, the position is sent periodically with zero in between. The position
* is sent whenever the value of an incrementing variable reaches this macro
* value.
*/
#define CONT_SCROLL_UPDATE_FREQ (10)
/* Device power mode related macros */
#define LOOP_TIME_FASTSCANMODE (20u)
#define LOOP_TIME_SLOWSCANMODE (150u)
#define ILO_CLOCK_FACTOR (40u)

#define WDT_TIMEOUT_FAST_SCAN (ILO_CLOCK_FACTOR * LOOP_TIME_FASTSCANMODE)

/* Scan period is LOOP_TIME_SLOWSCANMODE in SLOW_SCAN_MODE */
#define WDT_TIMEOUT_SLOW_SCAN (ILO_CLOCK_FACTOR * LOOP_TIME_SLOWSCANMODE)

/* This timeout is for device scan mode shift from fast scan to slow scan if there is
no proximity detected. 2
*/
#define SCANMODE_TIMEOUT_VALUE (150u)

#define FALSE (false)
#define TRUE (true)

/* Variable to check if device woke up because of WDT interrupt or other sources */
volatile uint8 wdtInterruptOccured = FALSE;

/* Watchdog timer match value. Device starts with fast scan mode after power-up */
volatile uint32 wdtMatchValue = WDT_TIMEOUT_FAST_SCAN;

/* Interrupt number for watchdog */
#define WDT_IRQ_NUMBER (6u)

/* Software timer reset value */
#define SW_TIMER_RESET (0u)

/**********square Mouse code for testing*****************/
//static uint8 Mouse_Data[BufferSize] = {0}; /* [0] = Buttons, [1] = X-Axis, [2] = Y-Axis */
//static uint16 Delay = 0;
/*******************************************/
typedef enum
{
SENSOR_SCAN = 1u, /* Sensor is scanned in this state */
WAIT_FOR_SCAN_COMPLETE = 2u, /* CPU is put to sleep in this state */
PROCESS_DATA = 3u, /* Sensor data is processed */
DEEP_SLEEP = 4u /* Device is put to deep sleep */
} DEVICE_STATE;

/* Firmware implements two refresh rates for reducing average power consumption */
typedef enum
{
SLOW_SCAN_MODE = 0u,
FAST_SCAN_MODE = 1u
} SCAN_MODE;
/* This variable is used to indicate the power mode */
SCAN_MODE deviceScanMode;

volatile int8 Mouse_Data[BufferSize] = {0}; /* [0] = Buttons, [1] = X-Axis, [2] = Y-Axis */

uint8 flag0 = 1;
uint8 Rflag = 0;
uint8 Lflag = 0;

// This variable is used to control the speed of the scroll bar movement.
//static uint32 scrollUpdateThreshold = 0;
uint8 ScrollStatus;
//static GestureId prevGestureId = GESTURE_NONE;

/* Variable indicates if trackpad is touched or not */
uint16 fingerStatus;

/* Contains information of whether DeltaX and DeltaY is negative */
uint8 xyDirectionData;

/* Contains mouse left and right click data */
uint8 mouseClickData;

/* Variable to store X, Y touch coordinates */
uint16 touchPosition[2];

/* Contains previous active X, Y coordinates of trackpad */
uint16 prevTouchPosition[2];

/* Contains DeltaX and DeltaY trackpad coordinates, used for HID (mouse) */
uint16 diffPosition[2];


/* Function prototype for CapSense parameter initialization */
void capSenseInit(void);

/* Function prototype to process trackpad data and update UART buffer */
void mouseDataProcess(void);

/* Function prototype to update UART buffer with trackpad and button sensor status*/
void updateUARTBuffer(void);
/* Function prototype to start watchdog timer */
void WDT_Start(void);

/* Function prototype to put the device to deep sleep */
void enterDeepSleepLowPowerMode(void);

/* Function that checks if trackpad or button sensors are ON */
bool anyWidgetActive(void);

/* API to get WDT match value to generate accurate scan intervals */
void CalibrateWdtMatchValue(void);


int main(void)
{
/* Variable to store the XY touch coordinates */
// uint32 tempCoordinates;

DEVICE_STATE currentState = SENSOR_SCAN;

/* Variable to check for timeout condition of sensor inactive condition */
uint32 timeoutCounter = 0u;

/* Variable to hold the widget# that should be scanned in FAST_SCAN_MODE */
uint8 currentWidget = CapSense_TRACKPAD_WDGT_ID;

/* Variable to store the XY touch coordinates */
uint32 tempCoordinates;

/* Variable to store interrupt state */
// uint32 interruptState = 0u;

/* Set the current power mode. */
deviceScanMode = FAST_SCAN_MODE;

/* Enable interrupts. This is required for CapSense and I2C operation */
CyGlobalIntEnable;

BLE_UART_Start();

capSenseInit();

/* Sets up a callback function using sysTick timer isr, the callback function
is part of the CySysTickSetCallback API */


/* Capsense Start And initialization and Updation */
// CapSense_Start();
CapSense_InitializeAllBaselines();
CapSense_ScanAllWidgets();

for(;;)
{
switch(currentState)
{
case SENSOR_SCAN:
/* Initiate new scan only if the CapSense hardware is idle */
if(CapSense_NOT_BUSY == CapSense_IsBusy())
{
#if (TUNER_ENABLE)
/* Update CapSense parameters set via CapSense tuner */
CapSense_RunTuner();
#endif

/* If device is in fast scan mode, set the parameters for trackpad or button widget scanning */
if(deviceScanMode == FAST_SCAN_MODE)
{
/* Check which widget has to be scanned and configure the parameters for scanning
* Each of the three widgets (trackpad, and 2 buttons) are scanned one at a time
* in fast scan mode. The currentWidget variable is used to switch between the three
* widgets in a round robin fashion and to configure the parameters for scanning.
* Ganged sensor widget is scanned in this state to reset its state to OFF state.
*/
if(currentWidget == CapSense_TRACKPAD_WDGT_ID)
{
/* Configure trackpad before scanning */
CapSense_CSDSetupWidget(CapSense_TRACKPAD_WDGT_ID);

/* Scan LeftClick button after trackpad */
currentWidget = CapSense_LEFTCLICK_WDGT_ID;
}
else if(currentWidget == CapSense_LEFTCLICK_WDGT_ID)
{
/* Configure LeftClick button widget before scanning */
CapSense_CSDSetupWidget(CapSense_LEFTCLICK_WDGT_ID);

/* Scan RightClick button after scanning LeftClick */
currentWidget = CapSense_RIGHTCLICK_WDGT_ID;
}
else if (currentWidget == CapSense_RIGHTCLICK_WDGT_ID)
{
/* Configure RightClick button widget before scanning */
CapSense_CSDSetupWidget(CapSense_RIGHTCLICK_WDGT_ID);

/* If gangsensor status is ON and trackpad, buttons are inactive,
* scan ganged sensor until its status is OFF */
if(CapSense_IsWidgetActive(CapSense_GANGEDSENSOR_WDGT_ID) && (!anyWidgetActive()))
{
currentWidget = CapSense_GANGEDSENSOR_WDGT_ID;
}
/* If gangsensor status is OFF, scan trackpad after RightClick button */
else
{
/* Scan trackpad after scanning RightClick */
currentWidget = CapSense_TRACKPAD_WDGT_ID;
}
}
/* If currentWidget is gangsensor, configure it for scanning */
else
{
/* Configure gangsensor before scanning */
CapSense_CSDSetupWidget(CapSense_GANGEDSENSOR_WDGT_ID);

/* Scan trackpad after scanning gangsensor */
currentWidget = CapSense_TRACKPAD_WDGT_ID;
}
}
/* If scan mode is slow scan mode, configure ganged sensor widget for scanning */
else
{
/* Set up ganged sensor for scanning */
CapSense_CSDSetupWidget(CapSense_GANGEDSENSOR_WDGT_ID);
}

/* Scan the widget which was configured in the previous step */
CapSense_Scan();

/* Set the state machine to wait state until the scan is complete */
currentState = WAIT_FOR_SCAN_COMPLETE;
}

break;

case WAIT_FOR_SCAN_COMPLETE:
/* Device is in sleep state until CapSense scanning is complete or
* device is woken-up by either CapSense interrupt or I2C interrupt
*/
/* Disable interrupts, so that ISR is not serviced while
* checking for CapSense scan status. Otherwise, interrupt might
* get serviced after checking for IsBusy condition and device
* might not wakeup since CapSense interrupt is already serviced
*/


/* Check if CapSense scanning is complete */
if(CapSense_NOT_BUSY == CapSense_IsBusy())

{
/* In fast scan mode, keep scanning the widgets until the widget is trackpad */
if((deviceScanMode == FAST_SCAN_MODE) && (currentWidget != CapSense_TRACKPAD_WDGT_ID))
{
currentState = SENSOR_SCAN;
}
/* In slow scan mode, process data directly as only gangsensor is scanned
* In fast scan mode, data is processed after all the sensors are scanned
*/
else
{
/* If current widget is trackpad or mode is slow scan mode, process the sensor data */
currentState = PROCESS_DATA;
}
}

break;

case PROCESS_DATA:
/* Set next state to SLEEP */
currentState = DEEP_SLEEP;

if(deviceScanMode == FAST_SCAN_MODE)
{
/* If mode is fast scan mode, process trackpad and button widget data.
* Filters are applied only for ganged sensor.
* For trackpad, filters are not applied to get best response time
*/
CapSense_ProcessWidget(CapSense_TRACKPAD_WDGT_ID);
CapSense_ProcessWidget(CapSense_LEFTCLICK_WDGT_ID);
CapSense_ProcessWidget(CapSense_RIGHTCLICK_WDGT_ID);

/* If trackpad and button sensor are inactive and gangsensor status is ON
* process the gang sensor data until its status is OFF
*/
if((!anyWidgetActive()) && CapSense_IsWidgetActive(CapSense_GANGEDSENSOR_WDGT_ID))
CapSense_ProcessWidget(CapSense_GANGEDSENSOR_WDGT_ID);

/* Check if trackpad is active */
fingerStatus = CapSense_IsWidgetActive(CapSense_TRACKPAD_WDGT_ID);

/* If trackpad is active, obtain XY coordinates */
if(fingerStatus == TRUE)
{
tempCoordinates = CapSense_GetXYCoordinates(CapSense_TRACKPAD_WDGT_ID);

/* Extract XY positions separately */
touchPosition[X_POSITION] = LO16(tempCoordinates);
touchPosition[Y_POSITION] = HI16 (tempCoordinates);
}
/* If trackpad is inactive, set touch position to 0. This will reset all the
* previous history
*/
else
{
touchPosition[X_POSITION] = 0u;
touchPosition[Y_POSITION] = 0u;
}

/* Compute deltaX and deltaY touch position */
mouseDataProcess();

/* Update the I2C buffer with HID data */
updateUARTBuffer();

/* If trackpad or button sensor is not active, increment the timeout counter */
if(!CapSense_IsAnyWidgetActive())
{
/* Turn-off LED */
// Red_LED_Write(LED_OFF);

/* Increment timeout counter variable */
timeoutCounter++;

/* Check if sensor is inactive for a duration greater than SCANMODE_TIMEOUT_VALUE */
if(timeoutCounter >= SCANMODE_TIMEOUT_VALUE)
{
/* Configure refresh interval to slow rate to reduce device power */
wdtMatchValue = WDT_TIMEOUT_SLOW_SCAN;

/* Set mode to slow scan mode to scan only ganged sensor */
deviceScanMode = SLOW_SCAN_MODE;
}
}
/* If either trackpad or button sensors are active, turn-on LED and reset the timeout counter */
else
{
// Red_LED_Write(LED_ON);

/* Because sensor is active, reset the counter */
timeoutCounter = 0u;
}
}
/* If device is in SLOW_SCAN_MODE, perform the below operations */
else
{
/* Update baseline, sensor status for ganged sensor */
CapSense_ProcessWidget(CapSense_GANGEDSENSOR_WDGT_ID);

/* Check ganged sensor status */
if(CapSense_IsWidgetActive(CapSense_GANGEDSENSOR_WDGT_ID))
{
/* Set watchdog match value to fast scan mode */
wdtMatchValue = WDT_TIMEOUT_FAST_SCAN;

/* Reset counter */
timeoutCounter = SW_TIMER_RESET;

/* Change the device mode to fast because touch is detected on gang sensor */
deviceScanMode = FAST_SCAN_MODE;

/* Scan trackpad widget first */
currentWidget = CapSense_TRACKPAD_WDGT_ID;

/* Skip sleep state and set next state to sensor scan */
currentState = SENSOR_SCAN;
}
}
break;

case DEEP_SLEEP:


currentState = SENSOR_SCAN;


/* Calibrate the ILO to ensure accurate scan intervals */
CalibrateWdtMatchValue();

break;
default:
/*******************************************************************
* Unknown power mode state. Unexpected situation.
******************************************************************/
CYASSERT(0);
break;
}
}
}



/******************************************************************************
* Function Name: capSenseInit
*******************************************************************************
*
* Summary: This API initializes CapSense block

*
* Parameters:
* None.
*
* Return:
* None.
*
* Theory:
* capSenseInit() performs following functions:
* 1: Starts the CapSense block
* 2: Scan the trackpad widget and initialize the previous touch coordinate values
*
* Side Effects: None
*
* Note: None
*
*******************************************************************************/
void capSenseInit(void)
{
/* Temporary variable to store trackpad coordinates */
uint32 tempCoordinates;

/* Starts the CapSense block and performs baseline initialization */
CapSense_Start();

/* Set the default finger presence status and touch coordinates */
fingerStatus = 0x0u;
tempCoordinates = 0xFFFFu;

/* Get the touch position */
touchPosition[X_POSITION] = LO16(tempCoordinates);
touchPosition[Y_POSITION] = HI16 (tempCoordinates);

/* Initialize the previous touch position */
prevTouchPosition[X_POSITION] = touchPosition[X_POSITION];
prevTouchPosition[Y_POSITION] = touchPosition[Y_POSITION];
}

void mouseDataProcess(void)
{
/* Variable to detect raising edge of left button status */
static uint8 prevLeftClick = 0u;
uint8 currentLeftClick = 0u;

/* Variable to detect raising edge of right button status */
static uint8 prevRightClick = 0u;
uint8 currentRightClick = 0u;

/* Variable to detect rising edge/falling edge of trackpad status */
static uint8 prevfingerStatus = 0u;
uint8 currentfingerStatus = 0u;

/* Initialize the sign indication variable to '0' */
xyDirectionData = 0u;

/* If trackpad is active, perform delta position computation */
currentfingerStatus = CapSense_IsWidgetActive(CapSense_TRACKPAD_WDGT_ID);

/* Compute delta positions only when the finger is placed on the trackpad
* Delta position is not computed when there is a touchdown or liftoff condition is detected
*/
if((currentfingerStatus && prevfingerStatus))
{
/* Get the DeltaX and DeltaY coordinates and sign information */
if(prevTouchPosition[X_POSITION] > touchPosition[X_POSITION])
{
diffPosition[X_POSITION] = prevTouchPosition[X_POSITION] - touchPosition[X_POSITION];
xyDirectionData = xyDirectionData | X_POSITION_NEGATIVE;

}
/* If previous X position is less than current X position */
else
{
diffPosition[X_POSITION] = touchPosition[X_POSITION] - prevTouchPosition[X_POSITION];
}

if(prevTouchPosition[Y_POSITION] > touchPosition[Y_POSITION])
{
diffPosition[Y_POSITION] = prevTouchPosition[Y_POSITION] - touchPosition[Y_POSITION];
diffPosition[Y_POSITION] = (diffPosition[Y_POSITION]);

}
/* If previous Y position is less than current Y position */
else
{
diffPosition[Y_POSITION] = touchPosition[Y_POSITION] - prevTouchPosition[Y_POSITION];
xyDirectionData = xyDirectionData | Y_POSITION_NEGATIVE;
}
}
/* If either trackpad is not active, or a touchdown or liftoff condition is detected
* delta position is initialized to 0.
*/
else
{
diffPosition[X_POSITION] = 0u;
diffPosition[Y_POSITION] = 0u;
}

/* If delta position is greater than the threshold limit, scale the
* delta position by a factor of 2.
*/
if(diffPosition[X_POSITION] > DELTA_POS_MULT_THRESHOLD)
diffPosition[X_POSITION] = diffPosition[X_POSITION] << 1u;

if(diffPosition[Y_POSITION] > DELTA_POS_MULT_THRESHOLD)
diffPosition[Y_POSITION] = diffPosition[Y_POSITION] << 1u;

/* Update previous touch position variables once delta position is computed */
prevTouchPosition[X_POSITION] = touchPosition[X_POSITION];
prevTouchPosition[Y_POSITION] = touchPosition[Y_POSITION];

/* Get the current button status */
currentLeftClick = CapSense_IsWidgetActive(CapSense_LEFTCLICK_WDGT_ID);
currentRightClick = CapSense_IsWidgetActive(CapSense_RIGHTCLICK_WDGT_ID);


/* Get the mouse left click and right click data */

mouseClickData = 0;

// Send left click only on the raising edge of left-click button status

if((prevLeftClick == 0) && (currentLeftClick != 0))
{
mouseClickData |= MOUSE_FN_LEFT_CLICK;
}
else
{
mouseClickData &= ~(MOUSE_FN_LEFT_CLICK);
}

// Send right click only on the raising edge of right-click button status

if((prevRightClick == 0) && (currentRightClick != 0))
{
mouseClickData |= MOUSE_FN_RIGHT_CLICK;
}
else
{
mouseClickData &= ~(MOUSE_FN_RIGHT_CLICK);
}
/* Update previous trackpad and button status */
prevfingerStatus = currentfingerStatus;
prevLeftClick = currentLeftClick;
prevRightClick = currentRightClick;

/* Single and double click data sent in Byte1 */


}

void updateUARTBuffer(void)
{
uint8 index;
/* To send interger data over UART char array is declared */
// char string[20];

/* If either trackpad or button sensor is touched, update the I2C buffer */
if(fingerStatus || mouseClickData)
//if(fingerStatus)
{
/* Reset all the data */
for(index = 0; index < BufferSize;index++)
{
Mouse_Data[index] = 0u;
}

/* 5 bytes of data is sent to host
BYTE1 - Mouse click data
BYTE2 - Delta x data
BYTE3 - Delta y data
BYTE4 - 0 (Scroll data, not used in this code example)
BYTE5 - delta x and delta y sign information
*/
#ifndef SQUAREMOUSETEST
Mouse_Data[DATA_BYTE1_INDEX] = mouseClickData;
Mouse_Data[DATA_BYTE2_INDEX] = (diffPosition[X_POSITION]);
Mouse_Data[DATA_BYTE3_INDEX] = (diffPosition[Y_POSITION]);
Mouse_Data[DATA_BYTE4_INDEX] = ScrollStatus;
Mouse_Data[DATA_BYTE5_INDEX] = xyDirectionData;

#endif
BLE_UART_SpiUartPutArray((uint8 *)Mouse_Data,BufferSize);

#ifdef PRINTtoTERMINAL
sprintf(string,"%d \t",Mouse_Data[DATA_BYTE1_INDEX]);
BLE_UART_UartPutString(string);
sprintf(string,"%d \t",Mouse_Data[DATA_BYTE2_INDEX]);
BLE_UART_UartPutString(string);
sprintf(string,"%d \n",Mouse_Data[DATA_BYTE3_INDEX]);
BLE_UART_UartPutString(string);
//sprintf(string, "%d \t",Mouse_Data[3]);
//BLE_UART_UartPutString(string);
//sprintf(string, "%d \n",Mouse_Data[4]);
//BLE_UART_UartPutString(string);
CyDelay(10);
#endif


// BLE_UART_SpiUartClearTxBuffer();

for(index = 0; index < BufferSize;index++)
{
Mouse_Data[index] = 0u;
}

}
}
/******************************************************************************
* Function Name: Timer_Interrupt
*******************************************************************************
*
* Summary:
* Handles the Interrupt Service Routine for the WDT timer.
*
* Parameters:
* None.
*
* Return:
* None.
*
* Theory: The interrupt is cleared on the ISR as watchdog in this project is
* used for timing maintenance only. Match value is updated to maintain
* the loop time.
*
* Side Effects: None
*
* Note: None
*
*******************************************************************************/

CY_ISR(Timer_Interrupt)
{
/* Clear the watchdog interrupt */
CySysWdtClearInterrupt(CY_SYS_WDT_COUNTER1_INT);

/* Update the watchdog match value */
CySysWdtWriteMatch((CY_SYS_WDT_COUNTER0 ||CY_SYS_WDT_COUNTER1), wdtMatchValue);

/* Set flag to true to indicate main loop that interrupt is because of WDT */
wdtInterruptOccured = TRUE;
}
void WDT_Start(void)
{
/* Setup ISR for watchdog interrupt */
CyIntSetVector(WDT_IRQ_NUMBER, Timer_Interrupt);

/* Get the actual match value required to generate a given delay */
CalibrateWdtMatchValue();

/* WDT match value is updated in order to obtain periodic interrupts */
CySysWdtWriteMatch((CY_SYS_WDT_COUNTER0 ||CY_SYS_WDT_COUNTER1), wdtMatchValue);

/* Pass the WDT interrupt from SRSS to NVIC */
// CySysWdtUnmaskInterrupt();

/* Enable WDT interrupt in NVIC to pass it to CPU */
CyIntEnable(WDT_IRQ_NUMBER);
}

void enterDeepSleepLowPowerMode(void)
{
/* EZI2C_Sleep routine should be called only after on-going I2C
* transaction is complete
* Enter critical section to lock slave state
*/

/* Variable to store interrupt state */
uint32 interruptState = 0u;

interruptState = CyEnterCriticalSection();

/* Check if I2C is busy. If so, skip deep sleep until I2C is free */
if (!( BLE_UART_CTRL_ENABLED_POS & BLE_UART_CTRL_EZBUF_MODE_POS))
{
/* Prepare for deep sleep - stop ILO calibration */
CySysClkIloStopMeasurement();

/* Configure slave to be wakeup source */
BLE_UART_Stop();

/* Enter DeepSleep. */
CySysPmDeepSleep();

/* WDT or any I2C communication wakes up device from deep sleep. */

/* Configure slave for active mode operation */
BLE_UART_Enable();

/* Start the ILO accuracy measurement for accurate scan interval generation */
CySysClkIloStartMeasurement();
}
/* Enable interrupts */
CyExitCriticalSection(interruptState);
}

/*******************************************************************************
* Function Name: anyWidgetActive
********************************************************************************
*
* Summary:
* This API checks if any widget is active
*
* Parameters:
* None.
*
* Theory: This API checks if any of the LeftClick, RightClick or trackpad sensors
* are active and returns true if any one of them is active.
*
* Side Effects: None
*
* Note: None
*
*******************************************************************************/

bool anyWidgetActive(void)
{
/* Check if either trackpad or any of the two button sensors are active */
if(CapSense_IsWidgetActive(CapSense_TRACKPAD_WDGT_ID) || \
CapSense_IsWidgetActive(CapSense_LEFTCLICK_WDGT_ID) || \
CapSense_IsWidgetActive(CapSense_RIGHTCLICK_WDGT_ID)
)
{
return TRUE;
}
else
{
return FALSE;
}
}


/*******************************************************************************
* Function Name: CalibrateWdtMatchValue
********************************************************************************
* Summary:
* This function calibrates the match value of the Watchdog Timer
*
* Parameter:
* None
*
* Return:
* void
*
* Theory: The ILO is calibrated using IMO to improve the accuracy of ILO.
*
* Side Effects: None
*
* Note:
*
*******************************************************************************/
void CalibrateWdtMatchValue()
{
/* Contains ILO Trimmed value */
uint32 tempIloCounts = 0u;

/* Contains ILO Trimmed value */
uint32 desiredDelay = 0;

/* Desired delay for ILO Trimming */
if(deviceScanMode == FAST_SCAN_MODE)
{
desiredDelay = WDT_TIMEOUT_FAST_SCAN;
}
else
{
desiredDelay = WDT_TIMEOUT_SLOW_SCAN;
}

/* Get the ILO compensated counts i.e. the actual counts for the desired ILO frequency
* Trimming is done to improve ILO accuracy using IMO; ILO default accuracy is +/- 60%
*/
if(CYRET_SUCCESS == CySysClkIloCompensate(desiredDelay, &tempIloCounts))
{
wdtMatchValue = (uint32)tempIloCounts;
}
}

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @shilpasonone04 

 

Can you please elaborate on the issue you are facing? Is it a Touchpad Tuning issue or the detection issue? Can you try using the CapSense tuner to ensure the touchpad is tuned correctly? In case you are seeing correct data in Tuner and not in your application code, it is likely a timing issue and that can be fixed in firmware. 

Are you using a kit or a custom board? In case you are using a custom board, what are the touchpad dimension and the overlay material you are using?

I also see that you are using a CSD trackpad. Note that CSD trackpads inherently have a 'ghosting' issue where multi-finger detection is poor. A CSX trackpad is better as it supports multi-finger detection. 

 

Best regards, 
Hari

View solution in original post

0 Likes
1 Reply
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi @shilpasonone04 

 

Can you please elaborate on the issue you are facing? Is it a Touchpad Tuning issue or the detection issue? Can you try using the CapSense tuner to ensure the touchpad is tuned correctly? In case you are seeing correct data in Tuner and not in your application code, it is likely a timing issue and that can be fixed in firmware. 

Are you using a kit or a custom board? In case you are using a custom board, what are the touchpad dimension and the overlay material you are using?

I also see that you are using a CSD trackpad. Note that CSD trackpads inherently have a 'ghosting' issue where multi-finger detection is poor. A CSX trackpad is better as it supports multi-finger detection. 

 

Best regards, 
Hari

0 Likes