mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
[axs15231] Touchscreen driver (#7592)
This commit is contained in:
parent
56fa6fef85
commit
5ad68e926d
12 changed files with 178 additions and 0 deletions
|
@ -50,6 +50,7 @@ esphome/components/atm90e26/* @danieltwagner
|
||||||
esphome/components/atm90e32/* @circuitsetup @descipher
|
esphome/components/atm90e32/* @circuitsetup @descipher
|
||||||
esphome/components/audio/* @kahrendt
|
esphome/components/audio/* @kahrendt
|
||||||
esphome/components/audio_dac/* @kbx81
|
esphome/components/audio_dac/* @kbx81
|
||||||
|
esphome/components/axs15231/* @clydebarrow
|
||||||
esphome/components/b_parasite/* @rbaron
|
esphome/components/b_parasite/* @rbaron
|
||||||
esphome/components/ballu/* @bazuchan
|
esphome/components/ballu/* @bazuchan
|
||||||
esphome/components/bang_bang/* @OttoWinter
|
esphome/components/bang_bang/* @OttoWinter
|
||||||
|
|
6
esphome/components/axs15231/__init__.py
Normal file
6
esphome/components/axs15231/__init__.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import esphome.codegen as cg
|
||||||
|
|
||||||
|
CODEOWNERS = ["@clydebarrow"]
|
||||||
|
DEPENDENCIES = ["i2c"]
|
||||||
|
|
||||||
|
axs15231_ns = cg.esphome_ns.namespace("axs15231")
|
36
esphome/components/axs15231/touchscreen/__init__.py
Normal file
36
esphome/components/axs15231/touchscreen/__init__.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
from esphome import pins
|
||||||
|
import esphome.codegen as cg
|
||||||
|
from esphome.components import i2c, touchscreen
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.const import CONF_ID, CONF_INTERRUPT_PIN, CONF_RESET_PIN
|
||||||
|
|
||||||
|
from .. import axs15231_ns
|
||||||
|
|
||||||
|
AXS15231Touchscreen = axs15231_ns.class_(
|
||||||
|
"AXS15231Touchscreen",
|
||||||
|
touchscreen.Touchscreen,
|
||||||
|
i2c.I2CDevice,
|
||||||
|
)
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = (
|
||||||
|
touchscreen.touchscreen_schema("50ms")
|
||||||
|
.extend(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(AXS15231Touchscreen),
|
||||||
|
cv.Optional(CONF_INTERRUPT_PIN): pins.internal_gpio_input_pin_schema,
|
||||||
|
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.extend(i2c.i2c_device_schema(0x3B))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def to_code(config):
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID])
|
||||||
|
await touchscreen.register_touchscreen(var, config)
|
||||||
|
await i2c.register_i2c_device(var, config)
|
||||||
|
|
||||||
|
if interrupt_pin := config.get(CONF_INTERRUPT_PIN):
|
||||||
|
cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin)))
|
||||||
|
if reset_pin := config.get(CONF_RESET_PIN):
|
||||||
|
cg.add(var.set_reset_pin(await cg.gpio_pin_expression(reset_pin)))
|
|
@ -0,0 +1,64 @@
|
||||||
|
#include "axs15231_touchscreen.h"
|
||||||
|
|
||||||
|
#include "esphome/core/helpers.h"
|
||||||
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace axs15231 {
|
||||||
|
|
||||||
|
static const char *const TAG = "ax15231.touchscreen";
|
||||||
|
|
||||||
|
constexpr static const uint8_t AXS_READ_TOUCHPAD[11] = {0xb5, 0xab, 0xa5, 0x5a, 0x0, 0x0, 0x0, 0x8};
|
||||||
|
|
||||||
|
#define ERROR_CHECK(err) \
|
||||||
|
if ((err) != i2c::ERROR_OK) { \
|
||||||
|
this->status_set_warning("Failed to communicate"); \
|
||||||
|
return; \
|
||||||
|
}
|
||||||
|
|
||||||
|
void AXS15231Touchscreen::setup() {
|
||||||
|
ESP_LOGCONFIG(TAG, "Setting up AXS15231 Touchscreen...");
|
||||||
|
if (this->reset_pin_ != nullptr) {
|
||||||
|
this->reset_pin_->setup();
|
||||||
|
this->reset_pin_->digital_write(false);
|
||||||
|
delay(5);
|
||||||
|
this->reset_pin_->digital_write(true);
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
if (this->interrupt_pin_ != nullptr) {
|
||||||
|
this->interrupt_pin_->pin_mode(gpio::FLAG_INPUT);
|
||||||
|
this->interrupt_pin_->setup();
|
||||||
|
this->attach_interrupt_(this->interrupt_pin_, gpio::INTERRUPT_FALLING_EDGE);
|
||||||
|
}
|
||||||
|
this->x_raw_max_ = this->display_->get_native_width();
|
||||||
|
this->y_raw_max_ = this->display_->get_native_height();
|
||||||
|
ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen setup complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
void AXS15231Touchscreen::update_touches() {
|
||||||
|
i2c::ErrorCode err;
|
||||||
|
uint8_t data[8]{};
|
||||||
|
|
||||||
|
err = this->write(AXS_READ_TOUCHPAD, sizeof(AXS_READ_TOUCHPAD), false);
|
||||||
|
ERROR_CHECK(err);
|
||||||
|
err = this->read(data, sizeof(data));
|
||||||
|
ERROR_CHECK(err);
|
||||||
|
this->status_clear_warning();
|
||||||
|
if (data[0] != 0) // no touches
|
||||||
|
return;
|
||||||
|
uint16_t x = encode_uint16(data[2] & 0xF, data[3]);
|
||||||
|
uint16_t y = encode_uint16(data[4] & 0xF, data[5]);
|
||||||
|
this->add_raw_touch_position_(0, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AXS15231Touchscreen::dump_config() {
|
||||||
|
ESP_LOGCONFIG(TAG, "AXS15231 Touchscreen:");
|
||||||
|
LOG_I2C_DEVICE(this);
|
||||||
|
LOG_PIN(" Interrupt Pin: ", this->interrupt_pin_);
|
||||||
|
LOG_PIN(" Reset Pin: ", this->reset_pin_);
|
||||||
|
ESP_LOGCONFIG(TAG, " Width: %d", this->x_raw_max_);
|
||||||
|
ESP_LOGCONFIG(TAG, " Height: %d", this->y_raw_max_);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace axs15231
|
||||||
|
} // namespace esphome
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "esphome/components/i2c/i2c.h"
|
||||||
|
#include "esphome/components/touchscreen/touchscreen.h"
|
||||||
|
#include "esphome/core/component.h"
|
||||||
|
#include "esphome/core/hal.h"
|
||||||
|
|
||||||
|
namespace esphome {
|
||||||
|
namespace axs15231 {
|
||||||
|
|
||||||
|
class AXS15231Touchscreen : public touchscreen::Touchscreen, public i2c::I2CDevice {
|
||||||
|
public:
|
||||||
|
void setup() override;
|
||||||
|
void dump_config() override;
|
||||||
|
|
||||||
|
void set_interrupt_pin(InternalGPIOPin *pin) { this->interrupt_pin_ = pin; }
|
||||||
|
void set_reset_pin(GPIOPin *pin) { this->reset_pin_ = pin; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void update_touches() override;
|
||||||
|
|
||||||
|
InternalGPIOPin *interrupt_pin_{};
|
||||||
|
GPIOPin *reset_pin_{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace axs15231
|
||||||
|
} // namespace esphome
|
20
tests/components/axs15231/common.yaml
Normal file
20
tests/components/axs15231/common.yaml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
i2c:
|
||||||
|
- id: i2c_axs15231
|
||||||
|
scl: 3
|
||||||
|
sda: 21
|
||||||
|
|
||||||
|
display:
|
||||||
|
- platform: ssd1306_i2c
|
||||||
|
id: ssd1306_display
|
||||||
|
model: SSD1306_128X64
|
||||||
|
reset_pin: 19
|
||||||
|
pages:
|
||||||
|
- id: page1
|
||||||
|
lambda: |-
|
||||||
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
|
|
||||||
|
touchscreen:
|
||||||
|
- platform: axs15231
|
||||||
|
display: ssd1306_display
|
||||||
|
interrupt_pin: 20
|
||||||
|
reset_pin: 18
|
1
tests/components/axs15231/test.esp32-ard.yaml
Normal file
1
tests/components/axs15231/test.esp32-ard.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
1
tests/components/axs15231/test.esp32-c3-ard.yaml
Normal file
1
tests/components/axs15231/test.esp32-c3-ard.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
1
tests/components/axs15231/test.esp32-c3-idf.yaml
Normal file
1
tests/components/axs15231/test.esp32-c3-idf.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
1
tests/components/axs15231/test.esp32-idf.yaml
Normal file
1
tests/components/axs15231/test.esp32-idf.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
19
tests/components/axs15231/test.esp8266-ard.yaml
Normal file
19
tests/components/axs15231/test.esp8266-ard.yaml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
i2c:
|
||||||
|
- id: i2c_axs15231
|
||||||
|
scl: 5
|
||||||
|
sda: 4
|
||||||
|
|
||||||
|
display:
|
||||||
|
- platform: ssd1306_i2c
|
||||||
|
id: ssd1306_display
|
||||||
|
model: SSD1306_128X64
|
||||||
|
reset_pin: 13
|
||||||
|
pages:
|
||||||
|
- id: page1
|
||||||
|
lambda: |-
|
||||||
|
it.rectangle(0, 0, it.get_width(), it.get_height());
|
||||||
|
|
||||||
|
touchscreen:
|
||||||
|
- platform: axs15231
|
||||||
|
display: ssd1306_display
|
||||||
|
interrupt_pin: 12
|
1
tests/components/axs15231/test.rp2040-ard.yaml
Normal file
1
tests/components/axs15231/test.rp2040-ard.yaml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<<: !include common.yaml
|
Loading…
Reference in a new issue