Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
Supppper yucky code, but it works nonetheless
Im kinda new to C++ so, Im learning the in's and out's of it, and it may or may not get rewritten to do things the right way (Glancing at tap, and app implementation)
  • Loading branch information
KaiyoFox authored Mar 28, 2024
0 parents commit 3f05299
Show file tree
Hide file tree
Showing 44 changed files with 45,476 additions and 0 deletions.
133 changes: 133 additions & 0 deletions RP2040-Touch-LCD-1.28/CST816S.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*****************************************************************************
* | File : CST816S.c
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V1.0
* | Date : 2022-12-02
* | Info : Basic version
*
******************************************************************************/
#include "CST816S.h"
CST816S Touch_CTS816;

void CST816S_I2C_Write(uint8_t reg, uint8_t value)
{
DEV_I2C_Write_Byte( CST816_ADDR, reg, value);
}
uint8_t CST816S_I2C_Read(uint8_t reg)
{
uint8_t res;
res = DEV_I2C_Read_Byte(CST816_ADDR, reg);
return res;
}

uint8_t CST816S_WhoAmI()
{
if (CST816S_I2C_Read(CST816_ChipID) == 0xB5)
return true;
else
return false;
}

void CST816S_Reset()
{
DEV_Digital_Write(Touch_RST_PIN, 0);
DEV_Delay_ms(100);
DEV_Digital_Write(Touch_RST_PIN, 1);
DEV_Delay_ms(100);
}

uint8_t CST816S_Read_Revision()
{
return CST816S_I2C_Read(CST816_FwVersion);
}

void CST816S_Wake_up()
{
DEV_Digital_Write(Touch_RST_PIN, 0);
DEV_Delay_ms(10);
DEV_Digital_Write(Touch_RST_PIN, 1);
DEV_Delay_ms(50);
CST816S_I2C_Write(CST816_DisAutoSleep, 0x01);
}

void CST816S_Stop_Sleep()
{
CST816S_I2C_Write(CST816_DisAutoSleep, 0x01);
}

void CST816S_Set_Mode(uint8_t mode)
{
if (mode == CST816S_Point_Mode)
{
//
CST816S_I2C_Write(CST816_IrqCtl, 0x41);

}
else if (mode == CST816S_Gesture_Mode)
{
CST816S_I2C_Write(CST816_IrqCtl, 0X11);
CST816S_I2C_Write(CST816_MotionMask, 0x01);
}
else
{
CST816S_I2C_Write(CST816_IrqCtl, 0X71);
}

}



uint8_t CST816S_init(uint8_t mode)
{
uint8_t bRet, Rev;
CST816S_Reset();

bRet = CST816S_WhoAmI();
if (bRet)
{
printf("Success:Detected CST816T.\r\n");
Rev = CST816S_Read_Revision();
printf("CST816T Revision = %d\r\n", Rev);
CST816S_Stop_Sleep();
}
else
{
printf("Error: Not Detected CST816T.\r\n");
return false;
}

CST816S_Set_Mode(mode);
Touch_CTS816.x_point = 0;
Touch_CTS816.y_point = 0;
CST816S_I2C_Write(CST816_IrqPluseWidth, 0x01);
CST816S_I2C_Write(CST816_NorScanPer, 0x01);

Touch_CTS816.mode = mode;

return true;
}

CST816S CST816S_Get_Point()
{
uint8_t x_point_h, x_point_l, y_point_h, y_point_l;
// CST816S_Wake_up();
x_point_h = CST816S_I2C_Read(CST816_XposH);
x_point_l = CST816S_I2C_Read(CST816_XposL);
y_point_h = CST816S_I2C_Read(CST816_YposH);
y_point_l = CST816S_I2C_Read(CST816_YposL);
Touch_CTS816.x_point = ((x_point_h & 0x0f) << 8) + x_point_l;
Touch_CTS816.y_point = ((y_point_h & 0x0f) << 8) + y_point_l;

return Touch_CTS816;
}
uint8_t CST816S_Get_Gesture(void)
{
uint8_t gesture;
gesture=CST816S_I2C_Read(CST816_GestureID);
return gesture;
}
98 changes: 98 additions & 0 deletions RP2040-Touch-LCD-1.28/CST816S.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*****************************************************************************
* | File : CST816S.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V1.0
* | Date : 2022-12-02
* | Info : Basic version
*
******************************************************************************/
#ifndef __CST816S_H
#define __CST816S_H
#include "DEV_Config.h"
#include <stdlib.h> //itoa()
#include <stdio.h>

#define CST816_ADDR (0x15)

typedef enum
{

CST816_GestureID = 0x01,
CST816_FingerNum,
CST816_XposH,
CST816_XposL,
CST816_YposH,
CST816_YposL,

CST816_ChipID = 0xA7,
CST816_ProjID,
CST816_FwVersion,
CST816_MotionMask,

CST816_BPC0H = 0xB0,
CST816_BPC0L,
CST816_BPC1H,
CST816_BPC1L,

CST816_IrqPluseWidth = 0xED,
CST816_NorScanPer,
CST816_MotionSlAngle,
CST816_LpScanRaw1H =0XF0,
CST816_LpScanRaw1L,
CST816_LpScanRaw2H,
CST816_LpScanRaw2L,
CST816_LpAutoWakeTime,
CST816_LpScanTH,
CST816_LpScanWin,
CST816_LpScanFreq,
CST816_LpScanIdac,
CST816_AutoSleepTime,
CST816_IrqCtl,
CST816_AutoReset,
CST816_LongPressTime,
CST816_IOCtl,
CST816_DisAutoSleep
} CST816S_Register;

/**
* Whether the graphic is filled
**/
typedef enum
{
CST816S_Point_Mode = 1,
CST816S_Gesture_Mode,
CST816S_ALL_Mode,
} CST816S_Mode;

typedef enum
{
CST816S_Gesture_None = 0,
CST816S_Gesture_Up,
CST816S_Gesture_Down,
CST816S_Gesture_Left,
CST816S_Gesture_Right,
CST816S_Gesture_Click,
CST816S_Gesture_Double_Click = 0x0b,
CST816S_Gesture_Long_Press=0x0c,
} CST816S_Gesture;

struct CST816S
{
uint16_t x_point;
uint16_t y_point;
uint8_t Gesture;
uint8_t mode;
} ;

extern CST816S Touch_CTS816;

uint8_t CST816S_init(uint8_t mode);
CST816S CST816S_Get_Point();
uint8_t CST816S_Get_Gesture(void);

#endif
Loading

0 comments on commit 3f05299

Please sign in to comment.