New kernel drivers and device implementation updates (#561)

- Added modular device support and devicetree bindings for ILI9341, ILI9488, CST816S, XPT2046, and GPIO button input, updating several board configurations for display/touch/backlight/keyboard/battery.
- Added a setting to control deprecated HAL usage (device property + Kconfig).
This commit is contained in:
Ken Van Hoeylandt
2026-07-12 23:54:55 +02:00
committed by GitHub
parent 50c0a14a93
commit fa4a6e255c
148 changed files with 5837 additions and 2145 deletions
@@ -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(button-control-module
SRCS ${SOURCE_FILES}
INCLUDE_DIRS include/
REQUIRES TactilityKernel platform-esp32 lvgl driver
)
@@ -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.
+30
View File
@@ -0,0 +1,30 @@
# Button Control
Kernel driver for navigating apps with 1 or 2 GPIO buttons. Kernel-driver counterpart to
`Drivers/ButtonControl`, exposing a `KEYBOARD_TYPE` device (`tactility/drivers/keyboard.h`)
instead of an LVGL encoder indev.
Devicetree binding: `tactility,button-control` (see `bindings/tactility,button-control.yaml`).
## Modes
- **One-button** (`pin-secondary` absent): short press = `LV_KEY_NEXT`, long press = `LV_KEY_ENTER`.
- **Two-button** (`pin-secondary` present): primary short = `LV_KEY_ENTER`, primary long =
`LV_KEY_ESC`, secondary short = `LV_KEY_NEXT`, secondary long = `LV_KEY_PREV`.
Short vs. long press is only decided when the button is released, by comparing the hold
duration against `long-press-ms` - not at the moment it's pressed.
## Example
```dts
buttons {
compatible = "tactility,button-control";
pin-primary = <&gpio0 37 GPIO_FLAG_NONE>;
pin-secondary = <&gpio0 39 GPIO_FLAG_NONE>;
};
```
## License
[Apache License Version 2.0](LICENSE-Apache-2.0.md)
@@ -0,0 +1,36 @@
description: >
GPIO button(s) that emulate UI navigation keys, for boards with only 1 or 2 physical
buttons instead of a full keyboard or touchscreen. Exposes a KEYBOARD_TYPE device: each
button's short/long press is translated to an LVGL navigation key, decided once the
button is released (so a long press is only recognized after release, matching how long
a button was actually held).
compatible: "tactility,button-control"
properties:
pin-primary:
type: phandles
required: true
description: >
Primary button GPIO pin. One-button mode (pin-secondary absent): short press = select
next, long press = press/enter. Two-button mode (pin-secondary present): short press =
press/enter, long press = close app.
pin-secondary:
type: phandles
default: GPIO_PIN_SPEC_NONE
description: >
Optional secondary button GPIO pin. When present, enables two-button mode: short press
= select next, long press = select previous. When absent, the device runs in
one-button mode (see pin-primary).
active-low:
type: boolean
default: true
description: Whether a pressed button reads as a logic low level
debounce-ms:
type: int
default: 20
description: Minimum time between recognized level changes, for software debouncing
long-press-ms:
type: int
default: 500
description: Minimum hold duration (from press to release) recognized as a long press
@@ -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/button_control.h>
DEFINE_DEVICETREE(button_control, struct ButtonControlConfig)
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/module.h>
#ifdef __cplusplus
extern "C" {
#endif
extern struct Module button_control_module;
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,25 @@
// 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 ButtonControlConfig {
struct GpioPinSpec pin_primary;
// GPIO_PIN_SPEC_NONE selects one-button mode; see the binding description for the
// resulting short/long press key mapping in each mode.
struct GpioPinSpec pin_secondary;
bool active_low;
uint32_t debounce_ms;
uint32_t long_press_ms;
};
#ifdef __cplusplus
}
#endif
@@ -0,0 +1,226 @@
// SPDX-License-Identifier: Apache-2.0
#include <drivers/button_control.h>
#include <button_control_module.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/keyboard.h>
#include <tactility/error.h>
#include <tactility/log.h>
#include <tactility/time.h>
#include <lvgl.h>
#include <cstdlib>
#define TAG "ButtonControl"
#define GET_CONFIG(device) (static_cast<const ButtonControlConfig*>((device)->config))
// Worst case: both buttons complete a short/long press gesture (press + release, 2 events each)
// within the same read_key() polling interval.
constexpr auto BUTTON_CONTROL_PENDING_CAPACITY = 4;
struct ButtonControlPendingEvent {
uint32_t key;
bool pressed;
};
struct ButtonControlButtonState {
GpioDescriptor* descriptor;
bool in_use;
bool debounced_pressed;
uint32_t press_start_time;
uint32_t last_change_time;
uint32_t short_press_key;
uint32_t long_press_key;
};
struct ButtonControlInternal {
ButtonControlButtonState primary;
ButtonControlButtonState secondary;
ButtonControlPendingEvent pending[BUTTON_CONTROL_PENDING_CAPACITY];
uint8_t pending_head;
uint8_t pending_count;
};
static void push_pending(ButtonControlInternal* internal, uint32_t key, bool pressed) {
if (internal->pending_count >= BUTTON_CONTROL_PENDING_CAPACITY) {
LOG_W(TAG, "Pending event queue full, dropping event");
return;
}
uint8_t tail = (internal->pending_head + internal->pending_count) % BUTTON_CONTROL_PENDING_CAPACITY;
internal->pending[tail] = { .key = key, .pressed = pressed };
internal->pending_count++;
}
static bool pop_pending(ButtonControlInternal* internal, ButtonControlPendingEvent* out_event) {
if (internal->pending_count == 0) {
return false;
}
*out_event = internal->pending[internal->pending_head];
internal->pending_head = (internal->pending_head + 1) % BUTTON_CONTROL_PENDING_CAPACITY;
internal->pending_count--;
return true;
}
// region Driver lifecycle
static error_t acquire_button(const GpioPinSpec& pin, uint32_t short_press_key, uint32_t long_press_key, ButtonControlButtonState* out_state) {
if (pin.gpio_controller == nullptr) {
*out_state = {};
return ERROR_NONE;
}
auto* descriptor = gpio_descriptor_acquire(pin.gpio_controller, pin.pin, GPIO_OWNER_GPIO);
if (descriptor == nullptr) {
LOG_E(TAG, "Failed to acquire GPIO descriptor");
return ERROR_RESOURCE;
}
if (gpio_descriptor_set_flags(descriptor, pin.flags | GPIO_FLAG_DIRECTION_INPUT) != ERROR_NONE) {
LOG_E(TAG, "Failed to configure GPIO as input");
gpio_descriptor_release(descriptor);
return ERROR_RESOURCE;
}
*out_state = {
.descriptor = descriptor,
.in_use = true,
.debounced_pressed = false,
.press_start_time = 0,
.last_change_time = 0,
.short_press_key = short_press_key,
.long_press_key = long_press_key,
};
return ERROR_NONE;
}
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
auto* internal = static_cast<ButtonControlInternal*>(malloc(sizeof(ButtonControlInternal)));
if (internal == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
*internal = {};
bool two_button_mode = config->pin_secondary.gpio_controller != nullptr;
error_t error = acquire_button(
config->pin_primary,
two_button_mode ? LV_KEY_ENTER : LV_KEY_NEXT,
two_button_mode ? LV_KEY_ESC : LV_KEY_ENTER,
&internal->primary
);
if (error != ERROR_NONE) {
free(internal);
return error;
}
error = acquire_button(config->pin_secondary, LV_KEY_NEXT, LV_KEY_PREV, &internal->secondary);
if (error != ERROR_NONE) {
if (internal->primary.in_use) {
gpio_descriptor_release(internal->primary.descriptor);
}
free(internal);
return error;
}
device_set_driver_data(device, internal);
return ERROR_NONE;
}
static error_t stop(Device* device) {
auto* internal = static_cast<ButtonControlInternal*>(device_get_driver_data(device));
if (internal->primary.in_use) {
gpio_descriptor_release(internal->primary.descriptor);
}
if (internal->secondary.in_use) {
gpio_descriptor_release(internal->secondary.descriptor);
}
free(internal);
return ERROR_NONE;
}
// endregion
// region KeyboardApi
// Long press is only distinguished from short press at release time, by how long the button
// was held - not at the moment it's first pressed. This matches physical button behavior:
// you can't know a press is "long" until it either ends or the threshold is reached.
static void poll_button(const ButtonControlConfig* config, ButtonControlInternal* internal, ButtonControlButtonState* state) {
if (!state->in_use) {
return;
}
bool high = false;
if (gpio_descriptor_get_level(state->descriptor, &high) != ERROR_NONE) {
return;
}
bool raw_pressed = config->active_low ? !high : high;
uint32_t now = get_millis();
if ((now - state->last_change_time) < config->debounce_ms) {
return;
}
if (raw_pressed == state->debounced_pressed) {
return;
}
state->last_change_time = now;
state->debounced_pressed = raw_pressed;
if (raw_pressed) {
state->press_start_time = now;
return;
}
// Release: decide short vs. long press by elapsed hold duration, then queue a synthetic
// key tap (press followed by release) for the LVGL key this gesture maps to.
uint32_t held_ms = now - state->press_start_time;
uint32_t key = held_ms < config->long_press_ms ? state->short_press_key : state->long_press_key;
push_pending(internal, key, true);
push_pending(internal, key, false);
}
static error_t button_control_read_key(Device* device, KeyboardKeyData* data) {
const auto* config = GET_CONFIG(device);
auto* internal = static_cast<ButtonControlInternal*>(device_get_driver_data(device));
poll_button(config, internal, &internal->primary);
poll_button(config, internal, &internal->secondary);
ButtonControlPendingEvent event;
if (pop_pending(internal, &event)) {
data->key = event.key;
data->pressed = event.pressed;
data->continue_reading = internal->pending_count > 0;
} else {
data->key = 0;
data->pressed = false;
data->continue_reading = false;
}
return ERROR_NONE;
}
// endregion
static constexpr KeyboardApi button_control_api = {
.read_key = button_control_read_key,
};
Driver button_control_driver = {
.name = "button_control",
.compatible = (const char*[]) { "tactility,button-control", nullptr },
.start_device = start,
.stop_device = stop,
.api = &button_control_api,
.device_type = &KEYBOARD_TYPE,
.owner = &button_control_module,
.internal = nullptr
};
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/check.h>
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver button_control_driver;
static error_t start() {
/* We crash when construct fails, because if a single driver fails to construct,
* there is no guarantee that the previously constructed drivers can be destroyed */
check(driver_construct_add(&button_control_driver) == ERROR_NONE);
return ERROR_NONE;
}
static error_t stop() {
/* We crash when destruct fails, because if a single driver fails to destruct,
* there is no guarantee that the previously destroyed drivers can be recovered */
check(driver_remove_destruct(&button_control_driver) == ERROR_NONE);
return ERROR_NONE;
}
Module button_control_module = {
.name = "button-control",
.start = start,
.stop = stop,
.symbols = nullptr,
.internal = nullptr
};
} // extern "C"