-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 97bd889
Showing
77 changed files
with
55,643 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"platformio.platformio-ide" | ||
], | ||
"unwantedRecommendations": [ | ||
"ms-vscode.cpptools-extension-pack" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Felix Biego | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
This directory is intended for project header files. | ||
|
||
A header file is a file containing C declarations and macro definitions | ||
to be shared between several project source files. You request the use of a | ||
header file in your project source file (C, C++, etc) located in `src` folder | ||
by including it, with the C preprocessing directive `#include'. | ||
|
||
```src/main.c | ||
|
||
#include "header.h" | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
``` | ||
|
||
Including a header file produces the same results as copying the header file | ||
into each source file that needs it. Such copying would be time-consuming | ||
and error-prone. With a header file, the related declarations appear | ||
in only one place. If they need to be changed, they can be changed in one | ||
place, and programs that include the header file will automatically use the | ||
new version when next recompiled. The header file eliminates the labor of | ||
finding and changing all the copies as well as the risk that a failure to | ||
find one copy will result in inconsistencies within a program. | ||
|
||
In C, the usual convention is to give header files names that end with `.h'. | ||
It is most portable to use only letters, digits, dashes, and underscores in | ||
header file names, and at most one dot. | ||
|
||
Read more about using header files in official GCC documentation: | ||
|
||
* Include Syntax | ||
* Include Operation | ||
* Once-Only Headers | ||
* Computed Includes | ||
|
||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#include "CST816D.h" | ||
|
||
CST816D::CST816D(int8_t sda_pin, int8_t scl_pin, int8_t rst_pin, int8_t int_pin) | ||
{ | ||
_sda = sda_pin; | ||
_scl = scl_pin; | ||
_rst = rst_pin; | ||
_int = int_pin; | ||
} | ||
|
||
void CST816D::begin(void) | ||
{ | ||
// Initialize I2C | ||
if (_sda != -1 && _scl != -1) | ||
{ | ||
Wire.begin(_sda, _scl); | ||
} | ||
else | ||
{ | ||
Wire.begin(); | ||
} | ||
|
||
// Int Pin Configuration | ||
if (_int != -1) | ||
{ | ||
pinMode(_int, OUTPUT); | ||
digitalWrite(_int, HIGH); //高电平 | ||
delay(1); | ||
digitalWrite(_int, LOW); //低电平 | ||
delay(1); | ||
} | ||
|
||
// Reset Pin Configuration | ||
if (_rst != -1) | ||
{ | ||
pinMode(_rst, OUTPUT); | ||
digitalWrite(_rst, LOW); | ||
delay(10); | ||
digitalWrite(_rst, HIGH); | ||
delay(300); | ||
} | ||
|
||
// Initialize Touch | ||
i2c_write(0xFE, 0XFF); //禁止自动进入低功耗模式。 | ||
} | ||
|
||
bool CST816D::getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture) | ||
{ | ||
bool FingerIndex = false; | ||
FingerIndex = (bool)i2c_read(0x02); | ||
|
||
*gesture = i2c_read(0x01); | ||
if (!(*gesture == SlideUp || *gesture == SlideDown)) | ||
{ | ||
*gesture = None; | ||
} | ||
|
||
uint8_t data[4]; | ||
i2c_read_continuous(0x03, data, 4); | ||
*x = ((data[0] & 0x0f) << 8) | data[1]; | ||
*y = ((data[2] & 0x0f) << 8) | data[3]; | ||
|
||
//Flip X , if you x-axis is reversed,please uncomment the following code | ||
//*x=240-*x; | ||
|
||
return FingerIndex; | ||
} | ||
|
||
uint8_t CST816D::i2c_read(uint8_t addr) | ||
{ | ||
uint8_t rdData; | ||
uint8_t rdDataCount; | ||
do | ||
{ | ||
Wire.beginTransmission(I2C_ADDR_CST816D); | ||
Wire.write(addr); | ||
Wire.endTransmission(false); // Restart | ||
rdDataCount = Wire.requestFrom(I2C_ADDR_CST816D, 1); | ||
} while (rdDataCount == 0); | ||
while (Wire.available()) | ||
{ | ||
rdData = Wire.read(); | ||
} | ||
return rdData; | ||
} | ||
|
||
uint8_t CST816D::i2c_read_continuous(uint8_t addr, uint8_t *data, uint32_t length) | ||
{ | ||
Wire.beginTransmission(I2C_ADDR_CST816D); | ||
Wire.write(addr); | ||
if ( Wire.endTransmission(true))return -1; | ||
Wire.requestFrom(I2C_ADDR_CST816D, length); | ||
for (int i = 0; i < length; i++) { | ||
*data++ = Wire.read(); | ||
} | ||
return 0; | ||
} | ||
|
||
void CST816D::i2c_write(uint8_t addr, uint8_t data) | ||
{ | ||
Wire.beginTransmission(I2C_ADDR_CST816D); | ||
Wire.write(addr); | ||
Wire.write(data); | ||
Wire.endTransmission(); | ||
} | ||
|
||
uint8_t CST816D::i2c_write_continuous(uint8_t addr, const uint8_t *data, uint32_t length) | ||
{ | ||
Wire.beginTransmission(I2C_ADDR_CST816D); | ||
Wire.write(addr); | ||
for (int i = 0; i < length; i++) { | ||
Wire.write(*data++); | ||
} | ||
if ( Wire.endTransmission(true))return -1; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef _CST816D_H | ||
#define _CST816D_H | ||
|
||
#include <Wire.h> | ||
|
||
#define I2C_ADDR_CST816D 0x15 | ||
|
||
//手势 | ||
enum GESTURE | ||
{ | ||
None = 0x00, //无手势 | ||
SlideDown = 0x01, //向下滑动 | ||
SlideUp = 0x02, //向上滑动 | ||
SlideLeft = 0x03, //向左滑动 | ||
SlideRight = 0x04, //向右滑动 | ||
SingleTap = 0x05, //单击 | ||
DoubleTap = 0x0B, //双击 | ||
LongPress = 0x0C //长按 | ||
}; | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief CST816D I2C CTP controller driver | ||
*/ | ||
/**************************************************************************/ | ||
class CST816D | ||
{ | ||
public: | ||
CST816D(int8_t sda_pin = -1, int8_t scl_pin = -1, int8_t rst_pin = -1, int8_t int_pin = -1); | ||
|
||
void begin(void); | ||
bool getTouch(uint16_t *x, uint16_t *y, uint8_t *gesture); | ||
|
||
private: | ||
int8_t _sda, _scl, _rst, _int; | ||
|
||
uint8_t i2c_read(uint8_t addr); | ||
uint8_t i2c_read_continuous(uint8_t addr, uint8_t *data, uint32_t length); | ||
void i2c_write(uint8_t addr, uint8_t data); | ||
uint8_t i2c_write_continuous(uint8_t addr, const uint8_t *data, uint32_t length); | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
This directory is intended for project specific (private) libraries. | ||
PlatformIO will compile them to static libraries and link into executable file. | ||
|
||
The source code of each library should be placed in a an own separate directory | ||
("lib/your_library_name/[here are source files]"). | ||
|
||
For example, see a structure of the following two libraries `Foo` and `Bar`: | ||
|
||
|--lib | ||
| | | ||
| |--Bar | ||
| | |--docs | ||
| | |--examples | ||
| | |--src | ||
| | |- Bar.c | ||
| | |- Bar.h | ||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html | ||
| | | ||
| |--Foo | ||
| | |- Foo.c | ||
| | |- Foo.h | ||
| | | ||
| |- README --> THIS FILE | ||
| | ||
|- platformio.ini | ||
|--src | ||
|- main.c | ||
|
||
and a contents of `src/main.c`: | ||
``` | ||
#include <Foo.h> | ||
#include <Bar.h> | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
|
||
``` | ||
|
||
PlatformIO Library Dependency Finder will find automatically dependent | ||
libraries scanning project source files. | ||
|
||
More information about PlatformIO Library Dependency Finder | ||
- https://docs.platformio.org/page/librarymanager/ldf.html |
Oops, something went wrong.