SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
touch_ft63x6.cpp
Go to the documentation of this file.
1
30#include "sdkconfig.h"
31#include "esp_log.h"
32#include "esp_err.h"
33#include "i2c_driver.h"
34#include "freertos/FreeRTOS.h"
35
36#ifdef CONFIG_FT636X
37
38#include "TouchDrv.hpp"
39
40static const char *TAG = "FT63XX";
41
43
44extern uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2);
45
46static bool init_done = false;
47
48esp_err_t ft63x6_init()
49{
50 ESP_LOGI(TAG, "----DRIVER FT63XX----");
51
52 //* Implemented using read and write callback methods, applicable to other platforms
53#if CONFIG_I2C_COMMUNICATION_METHOD_CALLBACK_RW
54
55 uint8_t address = FT3267_SLAVE_ADDRESS;
56
57 // * Provide the device address to the callback function
58 i2c_drv_device_init(address);
59
60 ESP_LOGI(TAG, "Implemented using read and write callback methods");
61 if (touch.begin(i2c_wr_function, hal_callback, address)) {
62 ESP_LOGI(TAG, "Initialization of FT63XX is successful!");
63 } else {
64 ESP_LOGE(TAG, "Failed to initialize the FT63XX!");
65 return ESP_FAIL;
66 }
67#endif
68
69 //* Use the built-in esp-idf communication method
70#if CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW
71#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)) && defined(CONFIG_SENSORLIB_ESP_IDF_NEW_API)
72
73 ESP_LOGI(TAG, "Implemented using built-in read and write methods (Use higher version >= 5.0 API)");
74
75 // * Using the new API of esp-idf 5.x, you need to pass the I2C BUS handle,
76 // * which is useful when the bus shares multiple devices.
77 extern i2c_master_bus_handle_t bus_handle;
78
79 if (touch.begin(bus_handle)) {
80 ESP_LOGI(TAG, "Initialization of FT63XX is successful!");
81 } else {
82 ESP_LOGE(TAG, "Failed to initialize the FT63XX!");
83 return ESP_FAIL;
84 }
85
86#else
87
88 ESP_LOGI(TAG, "Implemented using built-in read and write methods (Use lower version < 5.0 API)");
89 if (touch.begin((i2c_port_t)CONFIG_I2C_MASTER_PORT_NUM, CONFIG_SENSOR_SDA, CONFIG_SENSOR_SCL)) {
90 ESP_LOGI(TAG, "Initialization of FT63XX is successful!");
91 } else {
92 ESP_LOGE(TAG, "Failed to initialize the FT63XX!");
93 return ESP_FAIL;
94 }
95#endif //ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5,0,0)
96#endif //CONFIG_I2C_COMMUNICATION_METHOD_BUILTIN_RW
97
98 init_done = true;
99
100 return ESP_OK;
101}
102
103void ft63x6_loop()
104{
105 if (!init_done) {
106 return;
107 }
108 int16_t x[2], y[2];
109 uint8_t numPoint = touch.getPoint(x, y, 2);
110 for (int i = 0; i < numPoint; ++i) {
111 ESP_LOGI("FT63X6", "Point[%02d] - X:%02d Y:%02d", i, x[i], y[i]);
112 }
113}
114
115#endif
116
@license MIT License
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback, uint8_t addr) override
Initialize the touch driver for custom communication.
virtual uint8_t getPoint(int16_t *x_array, int16_t *y_array, uint8_t get_point=1) __attribute__((deprecated("use getTouchPoints instead of getPoint")))
Retrieve touch point coordinates (deprecated).
uint32_t hal_callback(SensorCommCustomHal::Operation op, void *param1, void *param2)
bool i2c_wr_function(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite)
@license MIT License
uint8_t i
TouchDrvCSTXXX touch
Definition touch_drv.cpp:42
int16_t x[5]
int16_t y[5]