10 static const char *
const TAG =
"xpt2046";
28 int16_t data[6], x_raw, y_raw, z_raw;
33 int16_t touch_pressure_1 = this->
read_adc_(0xB1 );
34 int16_t touch_pressure_2 = this->
read_adc_(0xC1 );
35 z_raw = touch_pressure_1 + 0Xfff - touch_pressure_2;
36 ESP_LOGVV(TAG,
"Touchscreen Update z = %d", z_raw);
55 ESP_LOGD(TAG,
"Touchscreen Update [%d, %d], z = %d", x_raw, y_raw, z_raw);
62 ESP_LOGCONFIG(TAG,
"XPT2046:");
64 LOG_PIN(
" IRQ Pin: ", this->
irq_pin_);
65 ESP_LOGCONFIG(TAG,
" X min: %d", this->
x_raw_min_);
66 ESP_LOGCONFIG(TAG,
" X max: %d", this->
x_raw_max_);
67 ESP_LOGCONFIG(TAG,
" Y min: %d", this->
y_raw_min_);
68 ESP_LOGCONFIG(TAG,
" Y max: %d", this->
y_raw_max_);
70 ESP_LOGCONFIG(TAG,
" Swap X/Y: %s", YESNO(this->
swap_x_y_));
71 ESP_LOGCONFIG(TAG,
" Invert X: %s", YESNO(this->
invert_x_));
72 ESP_LOGCONFIG(TAG,
" Invert Y: %s", YESNO(this->
invert_y_));
74 ESP_LOGCONFIG(TAG,
" threshold: %d", this->
threshold_);
76 LOG_UPDATE_INTERVAL(
this);
82 int16_t delta_a, delta_b, delta_c;
85 delta_a = (value1 > value2) ? value1 - value2 : value2 - value1;
86 delta_b = (value1 > value3) ? value1 - value3 : value3 - value1;
87 delta_c = (value3 > value2) ? value3 - value2 : value2 - value3;
89 if (delta_a <= delta_b && delta_a <= delta_c) {
90 reta = (value1 + value2) >> 1;
91 }
else if (delta_b <= delta_a && delta_b <= delta_c) {
92 reta = (value1 + value3) >> 1;
94 reta = (value2 + value3) >> 1;
108 return ((data[0] << 8) | data[1]) >> 3;
int16_t read_adc_(uint8_t ctrl)
void dump_config() override
void spi_setup() override
virtual void pin_mode(gpio::Flags flags)=0
static int16_t best_two_avg(int16_t value1, int16_t value2, int16_t value3)
void write_byte(uint8_t data)
void attach_interrupt_(InternalGPIOPin *irq_pin, esphome::gpio::InterruptType type)
Call this function to send touch points to the on_touch listener and the binary_sensors.
void update_touches() override
void add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delay(uint32_t ms)
InternalGPIOPin * irq_pin_