Device migrations, driver migrations and more (#575)

This commit is contained in:
Ken Van Hoeylandt
2026-07-20 23:43:17 +02:00
committed by GitHub
parent 2d768ef3a1
commit 2fbc44466a
221 changed files with 8824 additions and 3652 deletions
+11
View File
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.20)
include("${CMAKE_CURRENT_LIST_DIR}/../../Buildscripts/module.cmake")
file(GLOB_RECURSE SOURCE_FILES "source/*.c*")
tactility_add_module(cst816t-module
SRCS ${SOURCE_FILES}
INCLUDE_DIRS include/
REQUIRES TactilityKernel
)
@@ -0,0 +1,195 @@
Apache License
==============
_Version 2.0, January 2004_
_&lt;<http://www.apache.org/licenses/>&gt;_
### Terms and Conditions for use, reproduction, and distribution
#### 1. Definitions
“License” shall mean the terms and conditions for use, reproduction, and
distribution as defined by Sections 1 through 9 of this document.
“Licensor” shall mean the copyright owner or entity authorized by the copyright
owner that is granting the License.
“Legal Entity” shall mean the union of the acting entity and all other entities
that control, are controlled by, or are under common control with that entity.
For the purposes of this definition, “control” means **(i)** the power, direct or
indirect, to cause the direction or management of such entity, whether by
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
outstanding shares, or **(iii)** beneficial ownership of such entity.
“You” (or “Your”) shall mean an individual or Legal Entity exercising
permissions granted by this License.
“Source” form shall mean the preferred form for making modifications, including
but not limited to software source code, documentation source, and configuration
files.
“Object” form shall mean any form resulting from mechanical transformation or
translation of a Source form, including but not limited to compiled object code,
generated documentation, and conversions to other media types.
“Work” shall mean the work of authorship, whether in Source or Object form, made
available under the License, as indicated by a copyright notice that is included
in or attached to the work (an example is provided in the Appendix below).
“Derivative Works” shall mean any work, whether in Source or Object form, that
is based on (or derived from) the Work and for which the editorial revisions,
annotations, elaborations, or other modifications represent, as a whole, an
original work of authorship. For the purposes of this License, Derivative Works
shall not include works that remain separable from, or merely link (or bind by
name) to the interfaces of, the Work and Derivative Works thereof.
“Contribution” shall mean any work of authorship, including the original version
of the Work and any modifications or additions to that Work or Derivative Works
thereof, that is intentionally submitted to Licensor for inclusion in the Work
by the copyright owner or by an individual or Legal Entity authorized to submit
on behalf of the copyright owner. For the purposes of this definition,
“submitted” means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems, and
issue tracking systems that are managed by, or on behalf of, the Licensor for
the purpose of discussing and improving the Work, but excluding communication
that is conspicuously marked or otherwise designated in writing by the copyright
owner as “Not a Contribution.”
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
of whom a Contribution has been received by Licensor and subsequently
incorporated within the Work.
#### 2. Grant of Copyright License
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the Work and such
Derivative Works in Source or Object form.
#### 3. Grant of Patent License
Subject to the terms and conditions of this License, each Contributor hereby
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
irrevocable (except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
such license applies only to those patent claims licensable by such Contributor
that are necessarily infringed by their Contribution(s) alone or by combination
of their Contribution(s) with the Work to which such Contribution(s) was
submitted. If You institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
Contribution incorporated within the Work constitutes direct or contributory
patent infringement, then any patent licenses granted to You under this License
for that Work shall terminate as of the date such litigation is filed.
#### 4. Redistribution
You may reproduce and distribute copies of the Work or Derivative Works thereof
in any medium, with or without modifications, and in Source or Object form,
provided that You meet the following conditions:
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
this License; and
* **(b)** You must cause any modified files to carry prominent notices stating that You
changed the files; and
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
all copyright, patent, trademark, and attribution notices from the Source form
of the Work, excluding those notices that do not pertain to any part of the
Derivative Works; and
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
Derivative Works that You distribute must include a readable copy of the
attribution notices contained within such NOTICE file, excluding those notices
that do not pertain to any part of the Derivative Works, in at least one of the
following places: within a NOTICE text file distributed as part of the
Derivative Works; within the Source form or documentation, if provided along
with the Derivative Works; or, within a display generated by the Derivative
Works, if and wherever such third-party notices normally appear. The contents of
the NOTICE file are for informational purposes only and do not modify the
License. You may add Your own attribution notices within Derivative Works that
You distribute, alongside or as an addendum to the NOTICE text from the Work,
provided that such additional attribution notices cannot be construed as
modifying the License.
You may add Your own copyright statement to Your modifications and may provide
additional or different license terms and conditions for use, reproduction, or
distribution of Your modifications, or for any such Derivative Works as a whole,
provided Your use, reproduction, and distribution of the Work otherwise complies
with the conditions stated in this License.
#### 5. Submission of Contributions
Unless You explicitly state otherwise, any Contribution intentionally submitted
for inclusion in the Work by You to the Licensor shall be under the terms and
conditions of this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify the terms of
any separate license agreement you may have executed with Licensor regarding
such Contributions.
#### 6. Trademarks
This License does not grant permission to use the trade names, trademarks,
service marks, or product names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the NOTICE file.
#### 7. Disclaimer of Warranty
Unless required by applicable law or agreed to in writing, Licensor provides the
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
including, without limitation, any warranties or conditions of TITLE,
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
solely responsible for determining the appropriateness of using or
redistributing the Work and assume any risks associated with Your exercise of
permissions under this License.
#### 8. Limitation of Liability
In no event and under no legal theory, whether in tort (including negligence),
contract, or otherwise, unless required by applicable law (such as deliberate
and grossly negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special, incidental,
or consequential damages of any character arising as a result of this License or
out of the use or inability to use the Work (including but not limited to
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
any and all other commercial damages or losses), even if such Contributor has
been advised of the possibility of such damages.
#### 9. Accepting Warranty or Additional Liability
While redistributing the Work or Derivative Works thereof, You may choose to
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
other liability obligations and/or rights consistent with this License. However,
in accepting such obligations, You may act only on Your own behalf and on Your
sole responsibility, not on behalf of any other Contributor, and only if You
agree to indemnify, defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason of your
accepting any such warranty or additional liability.
_END OF TERMS AND CONDITIONS_
### APPENDIX: How to apply the Apache License to your work
To apply the Apache License to your work, attach the following boilerplate
notice, with the fields enclosed by brackets `[]` replaced with your own
identifying information. (Don't include the brackets!) The text should be
enclosed in the appropriate comment syntax for the file format. We also
recommend that a file or class name and description of purpose be included on
the same “printed page” as the copyright notice for easier identification within
third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+16
View File
@@ -0,0 +1,16 @@
# CST816T touch controller
A driver for the `CST816T` I2C capacitive touch controller by Hynitron.
Implemented directly against the register. (no `esp_lcd_touch` dependency)
- Manufacturer datasheet: https://github.com/koendv/cst816t/blob/master/extras/DS-CST816T%E6%95%B0%E6%8D%AE%E6%89%8B%E5%86%8CV2.2.pdf
- Original/reference code: https://github.com/koendv/cst816t (Arduino driver, `src/cst816t.cpp`/`src/cst816t.h`), licensed under [The Unlicense](https://github.com/koendv/cst816t/blob/master/LICENSE)
Single-touch only: the datasheet advertises "genuine two-point" support, but neither of the sources above documents a second touch-point register set, so only one point is read.
`enter_sleep`/`exit_sleep` are unimplemented (`nullptr` in the `PointerApi`, per its "null if not supported" contract).
The reference driver defines `REG_SLEEP_MODE` (0xE5) but never writes it, and the datasheet says waking from sleep needs
a hardware reset pulse anyway, not a register write.
License: [Apache v2.0](LICENSE-Apache-2.0.md)
@@ -0,0 +1,45 @@
description: Hynitron CST816T capacitive touch controller
include: ["i2c-device.yaml"]
compatible: "hynitron,cst816t"
bus: i2c
properties:
x-max:
type: int
required: true
description: Maximum X coordinate reported by the controller (typically the panel's horizontal resolution)
y-max:
type: int
required: true
description: Maximum Y coordinate reported by the controller (typically the panel's vertical resolution)
swap-xy:
type: boolean
default: false
description: Swap the X and Y axes
mirror-x:
type: boolean
default: false
description: Mirror the X axis
mirror-y:
type: boolean
default: false
description: Mirror the Y axis
pin-reset:
type: phandles
default: GPIO_PIN_SPEC_NONE
description: Reset GPIO pin
pin-interrupt:
type: phandles
default: GPIO_PIN_SPEC_NONE
description: Interrupt GPIO pin (currently unused - reads are polled via read_data())
reset-active-high:
type: boolean
default: false
description: Whether the reset pin is active high
interrupt-active-high:
type: boolean
default: false
description: Whether the interrupt pin is active high
+3
View File
@@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
bindings: bindings
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/bindings/bindings.h>
#include <drivers/cst816t.h>
DEFINE_DEVICETREE(cst816t, struct Cst816tConfig)
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/module.h>
#ifdef __cplusplus
extern "C" {
#endif
extern struct Module cst816t_module;
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include <tactility/drivers/gpio.h>
struct Cst816tConfig {
uint8_t address;
uint16_t x_max;
uint16_t y_max;
bool swap_xy;
bool mirror_x;
bool mirror_y;
struct GpioPinSpec pin_reset;
struct GpioPinSpec pin_interrupt;
bool reset_active_high;
bool interrupt_active_high;
};
#ifdef __cplusplus
}
#endif
+254
View File
@@ -0,0 +1,254 @@
// SPDX-License-Identifier: Apache-2.0
#include <drivers/cst816t.h>
#include <cst816t_module.h>
#include <tactility/check.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/gpio_descriptor.h>
#include <tactility/drivers/i2c_controller.h>
#include <tactility/drivers/pointer.h>
#include <tactility/error.h>
#include <tactility/log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <cstdlib>
constexpr auto* TAG = "CST816T";
#define GET_CONFIG(device) (static_cast<const Cst816tConfig*>((device)->config))
// Register map and reset/bring-up sequence taken from https://github.com/koendv/cst816t
// (src/cst816t.cpp) - the manufacturer datasheet (DS-CST816T V2.2) covers electrical
// characteristics and I2C timing only, not the register map.
static constexpr uint8_t REG_GESTURE_ID = 0x01;
static constexpr uint8_t REG_CHIP_ID = 0xA7;
static constexpr uint8_t REG_DIS_AUTOSLEEP = 0xFE;
static constexpr TickType_t TIMEOUT = pdMS_TO_TICKS(50);
struct Cst816tInternal {
GpioDescriptor* reset_descriptor;
bool swap_xy;
bool mirror_x;
bool mirror_y;
bool touched;
uint16_t x;
uint16_t y;
};
// region Driver lifecycle
// Timings match the reference driver linked above: it holds RST high for 100ms (well past the
// datasheet's Tpor/Tron minimum of 100ms), pulses it low for 10ms (Trst minimum is 0.1ms), then
// waits another 100ms (Tron) for the chip to finish reinitializing before any I2C traffic.
static error_t reset_pulse(GpioDescriptor* descriptor, bool active_high) {
bool idle_level = !active_high;
bool ok = gpio_descriptor_set_flags(descriptor, GPIO_FLAG_DIRECTION_OUTPUT) == ERROR_NONE;
ok = ok && gpio_descriptor_set_level(descriptor, idle_level) == ERROR_NONE;
vTaskDelay(pdMS_TO_TICKS(100));
ok = ok && gpio_descriptor_set_level(descriptor, active_high) == ERROR_NONE;
vTaskDelay(pdMS_TO_TICKS(10));
ok = ok && gpio_descriptor_set_level(descriptor, idle_level) == ERROR_NONE;
vTaskDelay(pdMS_TO_TICKS(100));
return ok ? ERROR_NONE : ERROR_RESOURCE;
}
static error_t start(Device* device) {
auto* parent = device_get_parent(device);
check(device_get_type(parent) == &I2C_CONTROLLER_TYPE);
const auto* config = GET_CONFIG(device);
auto* internal = static_cast<Cst816tInternal*>(malloc(sizeof(Cst816tInternal)));
if (internal == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
internal->reset_descriptor = nullptr;
internal->swap_xy = config->swap_xy;
internal->mirror_x = config->mirror_x;
internal->mirror_y = config->mirror_y;
internal->touched = false;
internal->x = 0;
internal->y = 0;
if (config->pin_reset.gpio_controller != nullptr) {
internal->reset_descriptor = gpio_descriptor_acquire(config->pin_reset.gpio_controller, config->pin_reset.pin, GPIO_OWNER_GPIO);
if (internal->reset_descriptor == nullptr) {
LOG_E(TAG, "Failed to acquire reset pin");
free(internal);
return ERROR_RESOURCE;
}
if (reset_pulse(internal->reset_descriptor, config->reset_active_high) != ERROR_NONE) {
LOG_E(TAG, "Failed to pulse reset pin");
gpio_descriptor_release(internal->reset_descriptor);
free(internal);
return ERROR_RESOURCE;
}
}
uint8_t chip_id = 0;
if (i2c_controller_register8_get(parent, config->address, REG_CHIP_ID, &chip_id, TIMEOUT) != ERROR_NONE) {
LOG_E(TAG, "Failed to read chip ID");
if (internal->reset_descriptor != nullptr) {
gpio_descriptor_release(internal->reset_descriptor);
}
free(internal);
return ERROR_RESOURCE;
}
LOG_I(TAG, "Chip ID 0x%02X", chip_id);
// Auto-sleep would otherwise drop the controller into standby after ~2s of inactivity,
// adding wake-up latency to the next touch; disabled since exit_sleep() isn't implemented
// here (see README) so there'd be no way back out once it kicked in.
uint8_t dis_auto_sleep = 0xFF;
if (i2c_controller_register8_set(parent, config->address, REG_DIS_AUTOSLEEP, dis_auto_sleep, TIMEOUT) != ERROR_NONE) {
LOG_W(TAG, "Failed to disable auto-sleep (non-fatal)");
}
device_set_driver_data(device, internal);
return ERROR_NONE;
}
static error_t stop(Device* device) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
if (internal->reset_descriptor != nullptr) {
gpio_descriptor_release(internal->reset_descriptor);
}
free(internal);
device_set_driver_data(device, nullptr);
return ERROR_NONE;
}
// endregion
// region PointerApi
static error_t cst816t_read_data(Device* device, TickType_t) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
const auto* config = GET_CONFIG(device);
auto* parent = device_get_parent(device);
// Burst-reads gesture_id, finger_num and X/Y in one transaction, matching the reference
// driver: the chip presents them as one contiguous 6-byte block starting at REG_GESTURE_ID.
uint8_t data[6];
error_t error = i2c_controller_read_register(parent, config->address, REG_GESTURE_ID, data, sizeof(data), TIMEOUT);
if (error != ERROR_NONE) {
return error;
}
uint8_t finger_num = data[1];
internal->touched = finger_num > 0;
// Top nibble of the high byte is reserved/event-type; the coordinate itself is 12-bit.
internal->x = static_cast<uint16_t>(((data[2] & 0x0F) << 8) | data[3]);
internal->y = static_cast<uint16_t>(((data[4] & 0x0F) << 8) | data[5]);
return ERROR_NONE;
}
// Single-touch only - see README for why.
static bool cst816t_get_touched_points(Device* device, uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* point_count, uint8_t max_point_count) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
const auto* config = GET_CONFIG(device);
if (!internal->touched || max_point_count == 0) {
*point_count = 0;
return false;
}
// Order matches esp_lcd_touch's own software coordinate adjustment (mirror X, mirror Y,
// then swap) so behavior lines up with the other touch modules in this codebase.
uint16_t point_x = internal->x;
uint16_t point_y = internal->y;
if (internal->mirror_x) {
point_x = config->x_max - point_x;
}
if (internal->mirror_y) {
point_y = config->y_max - point_y;
}
if (internal->swap_xy) {
uint16_t tmp = point_x;
point_x = point_y;
point_y = tmp;
}
x[0] = point_x;
y[0] = point_y;
if (strength != nullptr) {
strength[0] = 0;
}
*point_count = 1;
return true;
}
static error_t cst816t_set_swap_xy(Device* device, bool swap) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
internal->swap_xy = swap;
return ERROR_NONE;
}
static error_t cst816t_get_swap_xy(Device* device, bool* swap) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
*swap = internal->swap_xy;
return ERROR_NONE;
}
static error_t cst816t_set_mirror_x(Device* device, bool mirror) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
internal->mirror_x = mirror;
return ERROR_NONE;
}
static error_t cst816t_get_mirror_x(Device* device, bool* mirror) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
*mirror = internal->mirror_x;
return ERROR_NONE;
}
static error_t cst816t_set_mirror_y(Device* device, bool mirror) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
internal->mirror_y = mirror;
return ERROR_NONE;
}
static error_t cst816t_get_mirror_y(Device* device, bool* mirror) {
auto* internal = static_cast<Cst816tInternal*>(device_get_driver_data(device));
*mirror = internal->mirror_y;
return ERROR_NONE;
}
// endregion
static const PointerApi cst816t_pointer_api = {
// Unsupported (null per PointerApi's contract): the reference driver defines
// REG_SLEEP_MODE (0xE5) but never writes it, and the datasheet says waking up needs a
// hardware reset pulse rather than a register write.
.enter_sleep = nullptr,
.exit_sleep = nullptr,
.read_data = cst816t_read_data,
.get_touched_points = cst816t_get_touched_points,
.set_swap_xy = cst816t_set_swap_xy,
.get_swap_xy = cst816t_get_swap_xy,
.set_mirror_x = cst816t_set_mirror_x,
.get_mirror_x = cst816t_get_mirror_x,
.set_mirror_y = cst816t_set_mirror_y,
.get_mirror_y = cst816t_get_mirror_y,
};
Driver cst816t_driver = {
.name = "cst816t",
.compatible = (const char*[]) { "hynitron,cst816t", nullptr },
.start_device = start,
.stop_device = stop,
.api = &cst816t_pointer_api,
.device_type = &POINTER_TYPE,
.owner = &cst816t_module,
.internal = nullptr
};
+26
View File
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver cst816t_driver;
static error_t start() {
return driver_construct_add(&cst816t_driver);
}
static error_t stop() {
return driver_remove_destruct(&cst816t_driver);
}
Module cst816t_module = {
.name = "cst816t",
.start = start,
.stop = stop,
.symbols = nullptr,
.internal = nullptr
};
} // extern "C"