PSoC™ 4 Forum Discussions
Hello Sir,
I am working on project touchpad uart based. The cursor moves smoothly but use left and right mouse button configuration, during rotating cursor continuously left and right mouse buttons window opens with it.
I am sending my code. Please check and suggest some changes.
/*------------------------------------------------------------------------------------
Version : V0
Description : This file is used to Process Trackpad data and transfers over UART to USB controller
-------------------------------------------------------------------------------------*/
//---------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)
#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)
/* 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)
/**********square Mouse code for testing*****************/
//static uint8 Mouse_Data[BufferSize] = {0}; /* [0] = Buttons, [1] = X-Axis, [2] = Y-Axis */
//static uint16 Delay = 0;
/*******************************************/
volatile int8 Mouse_Data[BufferSize] = {0}; /* [0] = Buttons, [1] = X-Axis, [2] = Y-Axis */
uint8 flag0 = 1;
uint8 Rflag = 0;
uint8 Lflag = 0;
uint8 sing_click = 0;
uint8 dou_click = 0;
/* 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 Square mouse data */
void squaremouse(void);
/* Function prototype for Capsense Scaning & processing data */
void capsensedata(void);
/* Function prototype for CapSense parameter initialization */
void capSenseInit(void);
/* Function prototype to process trackpad data and update UART buffer */
void TouchpadDataProcess(void);
/* Function prototype to update UART buffer with trackpad and button sensor status*/
void updateUARTBuffer(void);
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
/* Variable to store the XY touch coordinates */
uint32 tempCoordinates,gesture;
uint8 index;
BLE_UART_Start();
capSenseInit();
CapSense_InitializeGestures();
/* Capsense Start And initialization and Updation */
// CapSense_Start();
CapSense_InitializeAllBaselines();
CapSense_ScanAllWidgets();
// BLE_UART_UartPutString("Received data\n");
for(;;)
{
// CyDelay(5);
// BLE_UART_SpiUartPutArray((uint8 *)Mouse_Data,BufferSize);
/* Reset all the data */
/* Checked the Capsense is Busy or Not*/
if(CapSense_NOT_BUSY == CapSense_IsBusy())
{
// Capsense Starting and Processes
CapSense_UpdateAllBaselines();
CapSense_ScanAllWidgets();
CapSense_ProcessAllWidgets();
gesture = CapSense_DecodeWidgetGestures(CapSense_TRACKPAD_WDGT_ID);
switch(gesture)
{
case CapSense_NO_GESTURE:
break;
case CapSense_ONE_FINGER_SINGLE_CLICK:
sing_click =1;
break;
case CapSense_ONE_FINGER_DOUBLE_CLICK:
dou_click = 1;
break;
case CapSense_ONE_FINGER_ROTATE_CW:
break;
case CapSense_ONE_FINGER_SCROLL_UP:
break;
case CapSense_ONE_FINGER_SCROLL_DOWN:
break;
case CapSense_ONE_FINGER_SCROLL_RIGHT:
break;
case CapSense_ONE_FINGER_SCROLL_LEFT:
break;
}
fingerStatus = CapSense_IsWidgetActive(CapSense_TRACKPAD_WDGT_ID);
/* If trackpad is active, obtain XY coordinates */
if(fingerStatus == TRUE)
{
#ifndef SQUAREMOUSETEST
tempCoordinates = CapSense_GetXYCoordinates(CapSense_TRACKPAD_WDGT_ID);
/* Extract XY positions separately */
touchPosition[X_POSITION] = LO16(tempCoordinates);
touchPosition[Y_POSITION] = HI16 (tempCoordinates);
#endif
#ifdef SQUAREMOUSETEST
squaremouse();
#endif
}
/* 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;
}
TouchpadDataProcess();
updateUARTBuffer();
}
}
}
/******************************************************************************
* 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 = 0xFFFFFFFFu;
/* 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 TouchpadDataProcess(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(xyDirectionData & X_POSITION_NEGATIVE)
// {
diffPosition[X_POSITION] = -(diffPosition[X_POSITION]);
// xyDirectionData = 0;
// }
}
/* If previous X position is less than current X position */
else
{
diffPosition[X_POSITION] = touchPosition[X_POSITION] - prevTouchPosition[X_POSITION];
//diffPosition[X_POSITION] = diffPosition[X_POSITION] << 1u; //added
}
if(prevTouchPosition[Y_POSITION] > touchPosition[Y_POSITION])
{
diffPosition[Y_POSITION] = prevTouchPosition[Y_POSITION] - touchPosition[Y_POSITION];
// xyDirectionData = xyDirectionData | Y_POSITION_NEGATIVE;
// if(xyDirectionData & Y_POSITION_NEGATIVE)
// {
diffPosition[Y_POSITION] = -(diffPosition[Y_POSITION]);
// xyDirectionData = 0;
// }
}
/* If previous Y position is less than current Y position */
else
{
diffPosition[Y_POSITION] = touchPosition[Y_POSITION] - prevTouchPosition[Y_POSITION];
//diffPosition[Y_POSITION] = diffPosition[Y_POSITION] << 1u; //added
}
}
/* 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;
}
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] = 0u;
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;
}
}
}
/**********Square mouse for testing***********/
#ifdef SQUAREMOUSETEST
void squaremouse()
{
switch (Delay){ // Switch statement creates a state machine for mouse movement
case 128:
Mouse_Data[0] = 0;
Mouse_Data[1] = 5; // Moves mouse to right
Mouse_Data[2] = 0; // Keeps Y static
break;
case 256:
Mouse_Data[0] = 0;
Mouse_Data[1] = 0; // Keeps X static
Mouse_Data[2] = 5; // Moves mouse down
break;
case 384:
Mouse_Data[0] = 0;
Mouse_Data[1] = -5; // Moves mouse to left
Mouse_Data[2] = 0; // Keeps Y static
break;
case 512:
Mouse_Data[0] = 0;
Mouse_Data[1] = 0; // Keeps X static
Mouse_Data[2] = -5; // Moves mouse up
Delay = 0;
break;
default:
break;
}
Delay++;
}
#endif
Show Less
Greetings Sir,
Can you please provide the Size , thickness and what is the material used for touch panel in case we are using
Greetings Sir,
Can you please provide the Size , thickness and what is the material used for touch panel in case we are using
Hi Sir,
Now I am debugging a program to drive music beep. I have found a problem . In the project attached , I change PWM frequency to drive the music beep. The code as follows:
if(Sound_test==0) // 1667Hz
{
PWM_BUZZ_WritePeriod(0x64);
PWM_BUZZ_WriteCompare(0x64/2);
}
else if(Sound_test==40)
{
PWM_BUZZ_WriteCompare(0);
}
else if(Sound_test==100) //2KHz
{
PWM_BUZZ_WritePeriod(0x7D);
PWM_BUZZ_WriteCompare(0x7D/2);
Watch3 = PWM_BUZZ_PERIOD_REG;
Watch3 = PWM_BUZZ_PERIOD_REG;
}
else if(Sound_test==140)
{
PWM_BUZZ_WriteCompare(0);
}
else if(Sound_test==200) //2.48HZ
{
PWM_BUZZ_WritePeriod(0x95);
PWM_BUZZ_WriteCompare(0x95/2);
}
else if(Sound_test==300) //stop
{
PWM_BUZZ_WriteCompare(0);
}
Sound_test++;
if(Sound_test>=600) ///delay
{
Sound_test= 0;
}
If the TCPWM works, there will be three ring. But in fact ,sometimes only one. So , I use an oscilloscope to detect PWM output pins,I found the wave lost.
I don't know why.I have checked the register,but the address in the registers TRM and the project really confuse me . Please kindly help to check the TCPWM configuration and test the program .
Thanks.
Show Less
CY8C4025FNI-S402T, Please provide PCB hardware design Application note for the mentioned part number, and what is the capacitance value used for touch application.
Thanks & Regards,
Spandana.
Show LessPlease provide the application information about this CY8C4025FNI-S402T number, how it interface with touch sensor and provide part number of touch sensor.
Thanks & Regards,
Spandana.
Show LessThe chip I am using is CY8C4146LQS-S423.
Is there any tool to erase SFlash of this chip? How to use it?
A new PSoC4 series chip, the default value of SFlash storage is 0x00?
We've inherited a few thousand source code lines within a greater Project. The source code happens to be managed with PSoc Creator 4.2. The Project is a Bootloader Project for OTA update of a sensor. Below the Bootloader Project, we find a number of projects which are in my understanding completely independent.
We have to make some minor changes to 1 specific project and want to debug it using the SWD Interface. The SWD interface works completly fine because we are able to debug the Bootloader itself easily.
Just to verify the correct function of the changes we made, we want to debug the altered project stand alone - means as a normal project without OTA or bootloading
How can we modify the project to be a "Normal project" and not a Bootloadable
Best Regards
Hans
Show LessIs there a part number naming convention for the PSoC 4 ?