mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
5393a09872
* Introduce calibration settings for all touchscreen drivers. this will override the common values. The x,y coordinates only calculated when the right calibrations are set. * resolve issues reported by CI * remove unneeded spaces and newlines * Forgot to remove some obsolete code * remove get_setup_priority from xpt2046 * remove media_player changes. * media_player: removed to much, * Update suggestions * referd back the `get_setup_priority` removal so it can be moved into a othe PR. * tt21100: restore init read * fix spacing * load native display dimensions instead of using internal dimensons. and load it only onse on setup * moved `update_touches()` to protexted section * adding Clydes PR#6049 * add multitouch test script * Update all Touchscreen replacing `get_*_internal` to `get_native_*` * fixed some CI recomendations * couple of fixes * make sure the display is running before touchscreen is setup * fix clang * revert back last changes * xpt2046: change log level for testing * logging information * add test file * fix polling issue with the for example the xpt2046 * fixed some CI issues * fixed some CI issues * restore mirror parameter discriptions * same for the swap_xy * same for the transform * remove the above const from const.py * and put the above const bacl const.py * Merge branch 'nvds-touchscreen-fix1' of https://github.com/nielsnl68/esphome into nvds-touchscreen-fix1 * and put the above const bacl const.py * [tt21100] making interupt pin optional * [tt21100] making interupt pin optional (now complete) * update the display part based on @clyde' s changes. * fix issue with ft6x36 touvhscreen * reverd back touch check. add comment * add some extra checks to the ft6x36 * add an other log and a typo fixed * okay an other fix. * add an extra check like others do and fix data type * [ft6336] fix update race when ts is touched. * [touchscreen] update some log's with a verbose level. * fix clang issues * fix the clang issues * fix the clang issues * fix virtual issue. * fix the clang issues * an other clang issues * remove anti-aliased fonts support. It does not belong here. * remove anti-aliased fonts support. It does not belong here. * rename test script * Moving the test files to there right location. * rename the test files * clean up the code * add a new line * clang fixings * clang fixings * remove comment * remove comment * Update esphome/components/touchscreen/__init__.py Co-authored-by: guillempages <guillempages@users.noreply.github.com> * Update esphome/components/touchscreen/__init__.py Co-authored-by: guillempages <guillempages@users.noreply.github.com> * Update esphome/components/touchscreen/__init__.py Co-authored-by: guillempages <guillempages@users.noreply.github.com> * Update esphome/components/touchscreen/touchscreen.cpp * Update esphome/components/touchscreen/touchscreen.cpp * [ft63x6] add threshold --------- Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com> Co-authored-by: guillempages <guillempages@users.noreply.github.com>
131 lines
3.6 KiB
C++
131 lines
3.6 KiB
C++
#pragma once
|
|
|
|
#include "esphome/components/i2c/i2c.h"
|
|
#include "esphome/components/touchscreen/touchscreen.h"
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/core/hal.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace ft5x06 {
|
|
|
|
static const char *const TAG = "ft5x06.touchscreen";
|
|
|
|
enum VendorId {
|
|
FT5X06_ID_UNKNOWN = 0,
|
|
FT5X06_ID_1 = 0x51,
|
|
FT5X06_ID_2 = 0x11,
|
|
FT5X06_ID_3 = 0xCD,
|
|
};
|
|
|
|
enum FTCmd : uint8_t {
|
|
FT5X06_MODE_REG = 0x00,
|
|
FT5X06_ORIGIN_REG = 0x08,
|
|
FT5X06_RESOLUTION_REG = 0x0C,
|
|
FT5X06_VENDOR_ID_REG = 0xA8,
|
|
FT5X06_TD_STATUS = 0x02,
|
|
FT5X06_TOUCH_DATA = 0x03,
|
|
FT5X06_I_MODE = 0xA4,
|
|
FT5X06_TOUCH_MAX = 0x4C,
|
|
};
|
|
|
|
enum FTMode : uint8_t {
|
|
FT5X06_OP_MODE = 0,
|
|
FT5X06_SYSINFO_MODE = 0x10,
|
|
FT5X06_TEST_MODE = 0x40,
|
|
};
|
|
|
|
static const size_t MAX_TOUCHES = 5; // max number of possible touches reported
|
|
|
|
class FT5x06Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice {
|
|
public:
|
|
void setup() override {
|
|
esph_log_config(TAG, "Setting up FT5x06 Touchscreen...");
|
|
// wait 200ms after reset.
|
|
this->set_timeout(200, [this] { this->continue_setup_(); });
|
|
}
|
|
|
|
void continue_setup_(void) {
|
|
uint8_t data[4];
|
|
if (!this->set_mode_(FT5X06_OP_MODE))
|
|
return;
|
|
|
|
if (!this->err_check_(this->read_register(FT5X06_VENDOR_ID_REG, data, 1), "Read Vendor ID"))
|
|
return;
|
|
switch (data[0]) {
|
|
case FT5X06_ID_1:
|
|
case FT5X06_ID_2:
|
|
case FT5X06_ID_3:
|
|
this->vendor_id_ = (VendorId) data[0];
|
|
esph_log_d(TAG, "Read vendor ID 0x%X", data[0]);
|
|
break;
|
|
|
|
default:
|
|
esph_log_e(TAG, "Unknown vendor ID 0x%X", data[0]);
|
|
this->mark_failed();
|
|
return;
|
|
}
|
|
// reading the chip registers to get max x/y does not seem to work.
|
|
if (this->display_ != nullptr) {
|
|
if (this->x_raw_max_ == this->x_raw_min_) {
|
|
this->x_raw_max_ = this->display_->get_native_width();
|
|
}
|
|
if (this->y_raw_max_ == this->y_raw_min_) {
|
|
this->x_raw_max_ = this->display_->get_native_height();
|
|
}
|
|
}
|
|
esph_log_config(TAG, "FT5x06 Touchscreen setup complete");
|
|
}
|
|
|
|
void update_touches() override {
|
|
uint8_t touch_cnt;
|
|
uint8_t data[MAX_TOUCHES][6];
|
|
|
|
if (!this->read_byte(FT5X06_TD_STATUS, &touch_cnt) || touch_cnt > MAX_TOUCHES) {
|
|
esph_log_w(TAG, "Failed to read status");
|
|
return;
|
|
}
|
|
if (touch_cnt == 0)
|
|
return;
|
|
|
|
if (!this->read_bytes(FT5X06_TOUCH_DATA, (uint8_t *) data, touch_cnt * 6)) {
|
|
esph_log_w(TAG, "Failed to read touch data");
|
|
return;
|
|
}
|
|
for (uint8_t i = 0; i != touch_cnt; i++) {
|
|
uint8_t status = data[i][0] >> 6;
|
|
uint8_t id = data[i][2] >> 3;
|
|
uint16_t x = encode_uint16(data[i][0] & 0x0F, data[i][1]);
|
|
uint16_t y = encode_uint16(data[i][2] & 0xF, data[i][3]);
|
|
|
|
esph_log_d(TAG, "Read %X status, id: %d, pos %d/%d", status, id, x, y);
|
|
if (status == 0 || status == 2) {
|
|
this->add_raw_touch_position_(id, x, y);
|
|
}
|
|
}
|
|
}
|
|
|
|
void dump_config() override {
|
|
esph_log_config(TAG, "FT5x06 Touchscreen:");
|
|
esph_log_config(TAG, " Address: 0x%02X", this->address_);
|
|
esph_log_config(TAG, " Vendor ID: 0x%X", (int) this->vendor_id_);
|
|
}
|
|
|
|
protected:
|
|
bool err_check_(i2c::ErrorCode err, const char *msg) {
|
|
if (err != i2c::ERROR_OK) {
|
|
this->mark_failed();
|
|
esph_log_e(TAG, "%s failed - err 0x%X", msg, err);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
bool set_mode_(FTMode mode) {
|
|
return this->err_check_(this->write_register(FT5X06_MODE_REG, (uint8_t *) &mode, 1), "Set mode");
|
|
}
|
|
VendorId vendor_id_{FT5X06_ID_UNKNOWN};
|
|
};
|
|
|
|
} // namespace ft5x06
|
|
} // namespace esphome
|