ESPHome  2024.11.1
xpt2046.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include "esphome/core/helpers.h"
8 #include "esphome/core/log.h"
9 
10 namespace esphome {
11 namespace xpt2046 {
12 
13 using namespace touchscreen;
14 
16  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
17  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_2MHZ> {
18  public:
20  void set_threshold(int16_t threshold) { this->threshold_ = threshold; }
22  void set_irq_pin(InternalGPIOPin *pin) { this->irq_pin_ = pin; }
23 
24  void setup() override;
25  void dump_config() override;
26  // float get_setup_priority() const override;
27 
28  protected:
29  static int16_t best_two_avg(int16_t value1, int16_t value2, int16_t value3);
30 
31  int16_t read_adc_(uint8_t ctrl);
32 
33  void update_touches() override;
34 
35  int16_t threshold_;
36 
37  InternalGPIOPin *irq_pin_{nullptr};
38 };
39 
40 } // namespace xpt2046
41 } // namespace esphome
void setup()
void set_irq_pin(InternalGPIOPin *pin)
Set the pin used to detect the touch.
Definition: xpt2046.h:22
The SPIDevice is what components using the SPI will create.
Definition: spi.h:391
void set_threshold(int16_t threshold)
Set the threshold for the touch detection.
Definition: xpt2046.h:20
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7