ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
axs15231_touchscreen.cpp
Go to the documentation of this file.
2
4#include "esphome/core/log.h"
5
7
8static const char *const TAG = "ax15231.touchscreen";
9
10constexpr static const uint8_t AXS_READ_TOUCHPAD[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x0, 0x0, 0x0, 0x8};
11
12#define ERROR_CHECK(err) \
13 if ((err) != i2c::ERROR_OK) { \
14 this->status_set_warning(LOG_STR("Failed to communicate")); \
15 return; \
16 }
17
19 if (this->reset_pin_ != nullptr) {
20 this->reset_pin_->setup();
21 this->reset_pin_->digital_write(false);
22 delay(5);
23 this->reset_pin_->digital_write(true);
24 delay(10);
25 }
26 if (this->interrupt_pin_ != nullptr) {
28 this->interrupt_pin_->setup();
30 }
31 if (this->x_raw_max_ == 0) {
32 this->x_raw_max_ = this->display_->get_native_width();
33 }
34 if (this->y_raw_max_ == 0) {
35 this->y_raw_max_ = this->display_->get_native_height();
36 }
37}
38
41 uint8_t data[8]{};
42
43 err = this->write(AXS_READ_TOUCHPAD, sizeof(AXS_READ_TOUCHPAD));
44 ERROR_CHECK(err);
45 err = this->read(data, sizeof(data));
46 ERROR_CHECK(err);
48 if (data[0] != 0 || data[1] == 0) // no touches
49 return;
50 uint16_t x = encode_uint16(data[2] & 0xF, data[3]);
51 uint16_t y = encode_uint16(data[4] & 0xF, data[5]);
52 this->add_raw_touch_position_(0, x, y);
53}
54
56 ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen:");
57 LOG_I2C_DEVICE(this);
58 LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_);
59 LOG_PIN(" Reset Pin: ", this->reset_pin_);
60 ESP_LOGCONFIG(TAG,
61 " Width: %d\n"
62 " Height: %d",
63 this->x_raw_max_, this->y_raw_max_);
64}
65
66} // namespace esphome::axs15231
void status_clear_warning()
Definition component.h:289
virtual void pin_mode(gpio::Flags flags)=0
virtual void setup()=0
virtual void digital_write(bool value)=0
int get_native_width()
Get the native (original) width of the display in pixels.
Definition display.h:330
int get_native_height()
Get the native (original) height of the display in pixels.
Definition display.h:332
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:183
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:163
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 add_raw_touch_position_(uint8_t id, int16_t x_raw, int16_t y_raw, int16_t z_raw=0)
@ INTERRUPT_FALLING_EDGE
Definition gpio.h:51
@ FLAG_INPUT
Definition gpio.h:27
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
Definition i2c_bus.h:12
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
Definition helpers.h:859
void HOT delay(uint32_t ms)
Definition hal.cpp:85
uint16_t x
Definition tt21100.cpp:5
uint16_t y
Definition tt21100.cpp:6