First Commit

This commit is contained in:
MindCreeper03
2025-02-27 19:31:50 +01:00
parent bcbb6aff9a
commit e490df1715
2470 changed files with 1479965 additions and 0 deletions

View File

@@ -0,0 +1,187 @@
/*!
* @file Adafruit_TSC2007.cpp
*
* @mainpage Adafruit TSC2007 Resistive Touch Panel library
*
* @section intro_sec Introduction
*
* I2C Driver for the Adafruit TSC2007 Resistive Touch Panel Sensor library
* for Arduino
*
* This is a library for the Adafruit TSC2007 breakout:
* https://www.adafruit.com/
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
* @section dependencies Dependencies
* This library depends on the Adafruit BusIO library
*
* @section author Author
*
* Limor Fried (Adafruit Industries)
*
* @section license License
*
* BSD (see license.txt)
*
* @section HISTORY
*
* v1.0 - First release
*/
#include "Arduino.h"
#include "Adafruit_TSC2007.h"
/*!
* @brief Instantiates a new TSC2007 class
*/
Adafruit_TSC2007::Adafruit_TSC2007(void) {}
Adafruit_TSC2007::~Adafruit_TSC2007(void) {
if (i2c_dev) {
delete i2c_dev; // remove old interface
}
}
/*!
* @brief Sets up the hardware and initializes I2C
* @param address
* The I2C address to use, defaults to 0x48
* @param wire
* The Wire object to be used for I2C connections.
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_TSC2007::begin(uint8_t address, TwoWire *wire) {
if (i2c_dev) {
delete i2c_dev; // remove old interface
}
i2c_dev = new Adafruit_I2CDevice(address, wire);
if (!i2c_dev->begin()) {
return false;
}
/*
uint8_t setupcmd = 0b10110000;
if (!i2c_dev->write(&setupcmd, 1)) {
return false;
}
*/
command(MEASURE_TEMP0, POWERDOWN_IRQON, ADC_12BIT);
return true;
}
/*!
* @brief Send a command and read 2 bytes from TSC
* @param func The command function to make
* @param pwr The power mode to enter after command
* @param res The ADC resolution
* @return 12 bits of data shifted from the 16-bit read value
*/
uint16_t Adafruit_TSC2007::command(adafruit_tsc2007_function func,
adafruit_tsc2007_power pwr,
adafruit_tsc2007_resolution res) {
uint8_t cmd = (uint8_t)func << 4;
cmd |= (uint8_t)pwr << 2;
cmd |= (uint8_t)res << 1;
uint8_t reply[2];
if (!i2c_dev->write(&cmd, 1)) {
return 0;
}
// Wait 1/2ms for conversion
delayMicroseconds(500);
if (!i2c_dev->read(reply, 2)) {
return 0;
}
return ((uint16_t)reply[0] << 4) | (reply[1] >> 4); // 12 bits
}
/*!
* @brief Read touch data from the TSC and then power down
* @param x Pointer to 16-bit value we will store x reading
* @param y Pointer to 16-bit value we will store y reading
* @param z1 Pointer to 16-bit value we will store z1 pressure reading
* @param z2 Pointer to 16-bit value we will store z2 pressure reading
* @return True if ADC was able to read the x & y values
*/
bool Adafruit_TSC2007::read_touch(uint16_t *x, uint16_t *y, uint16_t *z1,
uint16_t *z2) {
*z1 = command(MEASURE_Z1, ADON_IRQOFF, ADC_12BIT);
*z2 = command(MEASURE_Z2, ADON_IRQOFF, ADC_12BIT);
// take two measurements since there can be a 'flicker' on pen up
uint16_t x1, y1, x2, y2;
x1 = command(MEASURE_X, ADON_IRQOFF, ADC_12BIT);
y1 = command(MEASURE_Y, ADON_IRQOFF, ADC_12BIT);
x2 = command(MEASURE_X, ADON_IRQOFF, ADC_12BIT);
y2 = command(MEASURE_Y, ADON_IRQOFF, ADC_12BIT);
command(MEASURE_TEMP0, POWERDOWN_IRQON, ADC_12BIT);
if (abs((int32_t)x1 - (int32_t)x2) > 100)
return false;
if (abs((int32_t)y1 - (int32_t)y2) > 100)
return false;
*x = x1;
*y = y1;
return (*x != 4095) && (*y != 4095);
}
/*!
* @brief Function to get a point object rather than passing in pointers
* @returns A TS_Point, all values will be 0 if touchscreen read failed
*/
TS_Point Adafruit_TSC2007::getPoint(void) {
uint16_t x, y, z1, z2;
if (!this->read_touch(&x, &y, &z1, &z2)) {
return TS_Point(0, 0, 0);
}
return TS_Point(x, y, z1);
}
/*!
* @brief TS_Point constructor
*/
TS_Point::TS_Point() { x = y = 0; }
/*!
* @brief TS_Point constructor
* @param x0
* Initial x
* @param y0
* Initial y
* @param z0
* Initial z
*/
TS_Point::TS_Point(int16_t x0, int16_t y0, int16_t z0) {
x = x0;
y = y0;
z = z0;
}
/*!
* @brief Equality operator for TS_Point
* @return True if points are equal
*/
bool TS_Point::operator==(TS_Point p1) {
return ((p1.x == x) && (p1.y == y) && (p1.z == z));
}
/*!
* @brief Non-equality operator for TS_Point
* @return True if points are not equal
*/
bool TS_Point::operator!=(TS_Point p1) {
return ((p1.x != x) || (p1.y != y) || (p1.z != z));
}

View File

@@ -0,0 +1,99 @@
/*!
* @file Adafruit_TSC2007.h
*
* I2C Driver for the Adafruit TSC2007 Resistive Touch Panel Sensor library
*for Arduino
*
* This is a library for the Adafruit TSC2007 breakout:
* https://www.adafruit.com/
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing products from
* Adafruit!
*
*
* BSD license (see license.txt)
*/
#ifndef _ADAFRUIT_TSC2007_H
#define _ADAFRUIT_TSC2007_H
#include "Arduino.h"
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Wire.h>
#define TSC2007_I2CADDR_DEFAULT 0x48 ///< TSC2007 default i2c address
/*!
* @brief Class for working with points
*/
class TS_Point {
public:
TS_Point();
TS_Point(int16_t x, int16_t y, int16_t z);
bool operator==(TS_Point);
bool operator!=(TS_Point);
int16_t x; /**< x coordinate **/
int16_t y; /**< y coordinate **/
int16_t z; /**< z coordinate **/
};
/*!
* @brief Different function commands
*/
typedef enum {
MEASURE_TEMP0 = 0,
MEASURE_AUX = 2,
MEASURE_TEMP1 = 4,
ACTIVATE_X = 8,
ACTIVATE_Y = 9,
ACTIVATE_YPLUS_X = 10,
SETUP_COMMAND = 11,
MEASURE_X = 12,
MEASURE_Y = 13,
MEASURE_Z1 = 14,
MEASURE_Z2 = 15
} adafruit_tsc2007_function;
/*!
* @brief Power and IRQ modes
*/
typedef enum {
POWERDOWN_IRQON = 0,
ADON_IRQOFF = 1,
ADOFF_IRQON = 2,
} adafruit_tsc2007_power;
/*!
* @brief ADC resolution
*/
typedef enum {
ADC_12BIT = 0,
ADC_8BIT = 1,
} adafruit_tsc2007_resolution;
/*!
* @brief Class that stores state and functions for interacting with
* the TSC2007 driver
*/
class Adafruit_TSC2007 {
public:
Adafruit_TSC2007();
~Adafruit_TSC2007();
bool begin(uint8_t address = TSC2007_I2CADDR_DEFAULT, TwoWire *wire = &Wire);
uint16_t command(adafruit_tsc2007_function func, adafruit_tsc2007_power pwr,
adafruit_tsc2007_resolution res);
bool read_touch(uint16_t *x, uint16_t *y, uint16_t *z1, uint16_t *z2);
TS_Point getPoint();
private:
Adafruit_I2CDevice *i2c_dev = NULL; ///< Pointer to I2C bus interface
};
#endif

View File

@@ -0,0 +1,33 @@
# Adafruit TSC2007 [![Build Status](https://github.com/adafruit/Adafruit_TSC2007/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_TSC2007/actions)
This is the Adafruit TSC2007 Resistive Touch Panel Sensor library for Arduino
Tested and works great with the Adafruit TSC2007 Breakout Board
[<img src="assets/board.png?raw=true" width="500px">](https://www.adafruit.com/products/)
This chip uses I2C to communicate, 2 pins are required to interface
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
# Dependencies
* [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO)
# Contributing
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_TSC2007/blob/master/CODE_OF_CONDUCT.md>)
before contributing to help this project stay welcoming.
## Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
Some examples of how to use doxygen can be found in these guide pages:
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
Written by ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for "Adafruit TSC2007" and install the library.

Binary file not shown.

After

Width:  |  Height:  |  Size: 569 KiB

View File

@@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View File

@@ -0,0 +1,27 @@
#include "Adafruit_TSC2007.h"
Adafruit_TSC2007 touch;
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
if (!touch.begin()) {
Serial.println("Couldn't find touch controller");
while (1) delay(10);
}
Serial.println("Found touch controller");
}
void loop() {
uint16_t x, y, z1, z2;
if (touch.read_touch(&x, &y, &z1, &z2)) {
Serial.print("Touch point: (");
Serial.print(x); Serial.print(", ");
Serial.print(y); Serial.print(", ");
Serial.print(z1); Serial.print(" / ");
Serial.print(z2); Serial.println(")");
}
delay(100);
}

View File

@@ -0,0 +1,61 @@
#include <Adafruit_SH110X.h>
#include <Fonts/FreeSans9pt7b.h>
#include "Adafruit_TSC2007.h"
Adafruit_TSC2007 touch;
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
void setup() {
Serial.begin(115200);
//while (!Serial);
Serial.println("128x64 OLED FeatherWing TSC2007");
display.begin(0x3C, true); // Address 0x3C default
Serial.println("OLED begun");
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(1000);
// Clear the buffer.
display.clearDisplay();
display.display();
if (!touch.begin()) {
Serial.println("Failed to find Adafruit TSC chip");
while (1) { delay(10); }
}
Serial.println("TSC Found!");
display.setRotation(1);
display.setFont(&FreeSans9pt7b);
display.setTextColor(SH110X_WHITE);
}
void loop() {
display.clearDisplay();
display.setCursor(0, 15);
display.println("~TSC2007 QT~");
uint16_t x, y, z1, z2;
if (touch.read_touch(&x, &y, &z1, &z2) && (z1 > 100)) {
Serial.print("Touch point: (");
Serial.print(x); Serial.print(", ");
Serial.print(y); Serial.print(", ");
Serial.print(z1); Serial.print(" / ");
Serial.print(z2); Serial.println(")");
display.print("X: ");
display.println(x);
display.print("Y: ");
display.println(y);
}
display.display();
yield();
delay(100);
}

View File

@@ -0,0 +1,10 @@
name=Adafruit TSC2007
version=1.1.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the TSC2007 resistive touch screen drivers in the Adafruit shop
paragraph=Arduino library for the TSC2007 resistive touch screen drivers in the Adafruit shop
category=Sensors
url=https://github.com/adafruit/Adafruit_TSC2007
architectures=*
depends=Adafruit BusIO, Adafruit SH110X

View File

@@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2022 Limor Fried (Adafruit Industries)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.