ESP32-2432S022C Implementation (#657)

This commit is contained in:
NellowTCS 2026-09-25 11:23:12 -06:00 committed by GitHub
parent 79d3dd4fdb
commit c2082b3f46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 1956 additions and 5 deletions

View File

@ -0,0 +1,6 @@
file(GLOB_RECURSE SOURCE_FILES source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
REQUIRES TactilityKernel
)

View File

@ -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.

View File

@ -0,0 +1,99 @@
/dts-v1/;
#include <tactility/bindings/root.h>
#include <tactility/bindings/esp32_wifi_pinned.h>
#include <tactility/bindings/esp32_gpio.h>
#include <tactility/bindings/esp32_i2c_master.h>
#include <tactility/bindings/esp32_spi.h>
#include <tactility/bindings/esp32_sdspi.h>
#include <tactility/bindings/esp32_pwm_ledc.h>
#include <tactility/bindings/pwm_backlight.h>
#include <tactility/bindings/esp32_usbdevice.h>
#include <bindings/st7789_soft_i8080.h>
#include <bindings/cst816s.h>
#include <bindings/esp32_dac_speaker.h>
/ {
compatible = "root";
model = "CYD 2432S022C";
wifi0 {
compatible = "espressif,esp32-wifi-pinned";
};
gpio0 {
compatible = "espressif,esp32-gpio";
gpio-count = <40>;
};
i2c0 {
compatible = "espressif,esp32-i2c-master";
port = <I2C_NUM_0>;
clock-frequency = <400000>;
pin-sda = <&gpio0 21 GPIO_FLAG_NONE>;
pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
touch {
compatible = "hynitron,cst816s";
reg = <0x15>;
x-max = <240>;
y-max = <320>;
};
};
display_backlight_pwm {
compatible = "espressif,esp32-pwm-ledc";
pin = <&gpio0 0 GPIO_FLAG_NONE>;
period-ns = <33333>;
ledc-timer = <0>;
ledc-channel = <0>;
};
display_backlight {
compatible = "pwm-backlight";
// Off by default so display power-on won't show the screen from before the last power loss.
// The display backlight is turned on during the boot process.
status = "disabled";
pwm = <&display_backlight_pwm>;
};
display {
compatible = "sitronix,st7789-soft-i8080";
horizontal-resolution = <240>;
vertical-resolution = <320>;
pin-d0 = <&gpio0 15 GPIO_FLAG_NONE>;
pin-d1 = <&gpio0 13 GPIO_FLAG_NONE>;
pin-d2 = <&gpio0 12 GPIO_FLAG_NONE>;
pin-d3 = <&gpio0 14 GPIO_FLAG_NONE>;
pin-d4 = <&gpio0 27 GPIO_FLAG_NONE>;
pin-d5 = <&gpio0 25 GPIO_FLAG_NONE>;
pin-d6 = <&gpio0 33 GPIO_FLAG_NONE>;
pin-d7 = <&gpio0 32 GPIO_FLAG_NONE>;
pin-cs = <&gpio0 17 GPIO_FLAG_NONE>;
pin-dc = <&gpio0 16 GPIO_FLAG_NONE>;
pin-wr = <&gpio0 4 GPIO_FLAG_NONE>;
pin-rd = <&gpio0 2 GPIO_FLAG_NONE>;
backlight = <&display_backlight>;
};
spi1 {
compatible = "espressif,esp32-spi";
host = <SPI3_HOST>;
cs-gpios = <&gpio0 5 GPIO_FLAG_NONE>;
pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
miso-pull-up;
sdcard@0 {
compatible = "espressif,esp32-sdspi";
frequency-khz = <20000>;
};
};
speaker {
compatible = "espressif,esp32-dac-speaker";
pin = <&gpio0 26 GPIO_FLAG_NONE>;
sample-rate = <16000>;
};
};

View File

@ -0,0 +1,16 @@
general.vendor=CYD
general.name=2432S022C
apps.launcherAppId=tactility.launcher
hardware.target=ESP32
hardware.flashSize=4MB
hardware.spiRam=false
storage.userDataLocation=SD
display.size=2.2"
display.shape=rectangle
display.dpi=182
lvgl.colorDepth=16

View File

@ -0,0 +1,7 @@
dependencies:
- Platforms/platform-esp32
- Drivers/st7789-soft-i8080-module
- Drivers/cst816s-module
- Drivers/esp32-dac-speaker-module
- Drivers/audio-stream-module
dts: cyd,2432s022c.dts

View File

@ -0,0 +1,14 @@
#include <tactility/module.h>
extern "C" {
Module cyd_2432s022c_module = {
.name = "cyd-2432s022c",
.start = nullptr,
.stop = nullptr,
.drivers = nullptr,
.symbols = nullptr,
.internal = nullptr
};
}

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(esp32-dac-speaker-module
SRCS ${SOURCE_FILES}
INCLUDE_DIRS include/
REQUIRES TactilityKernel platform-esp32 driver esp_driver_dac
)

View File

@ -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.

View File

@ -0,0 +1,6 @@
# ESP32 internal-DAC speaker
An output-only `AUDIO_CODEC_TYPE` driver that routes 8-bit mono PCM to an ESP32
internal DAC channel behind an external analog audio amplifier.
License: Apache v2.0 [LICENSE-Apache-2.0.md]

View File

@ -0,0 +1,13 @@
description: ESP32 internal DAC driving an external analog audio amplifier (8-bit mono PCM output)
compatible: "espressif,esp32-dac-speaker"
properties:
pin:
type: phandles
required: true
description: DAC output pin (ESP32 - GPIO25 = DAC1, GPIO26 = DAC2)
sample-rate:
type: int
default: 16000
description: Native output sample rate in Hz (8-bit mono PCM only)

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
bindings: bindings

View File

@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/bindings/bindings.h>
#include <drivers/esp32_dac_speaker.h>
#ifdef __cplusplus
extern "C" {
#endif
DEFINE_DEVICETREE(esp32_dac_speaker, struct Esp32DacSpeakerConfig)
#ifdef __cplusplus
}
#endif

View File

@ -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>
/**
* @brief ESP32 internal-DAC speaker configuration.
*
* Routes 8-bit mono PCM to an ESP32 DAC channel behind an external analog amplifier.
* The DAC channel is derived from the pin number (ESP32: GPIO25 = DAC1, GPIO26 = DAC2).
*/
struct Esp32DacSpeakerConfig {
/** DAC output pin. Must map to a DAC channel; anything else fails to start. */
struct GpioPinSpec pin;
/** Native sample rate the DAC is driven at in Hz (8-bit data). */
uint32_t sample_rate;
};
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern const struct Module esp32_dac_speaker_module;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,463 @@
// SPDX-License-Identifier: Apache-2.0
#include <drivers/esp32_dac_speaker.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/audio_codec.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/error.h>
#include <tactility/log.h>
#include <cstddef>
#include <cstdint>
#include <new>
#include "freertos/FreeRTOS.h"
#include "soc/soc.h"
#if SOC_DAC_SUPPORTED
#include "driver/dac_continuous.h"
#include "soc/dac_channel.h"
#endif
#define TAG "Esp32DacSpeaker"
namespace {
// The ESP32 DAC is 8-bit.
constexpr size_t CONVERT_CHUNK_SAMPLES = 1024;
constexpr uint32_t DMA_DESC_COUNT = 8;
constexpr size_t DMA_BUF_SIZE = 2048; // 1024 samples per descriptor, 8 descriptors = 512 ms at 16 kHz
// The DAC digital controller on ESP32 can only reach audio rates through the APLL clock source
constexpr uint8_t MID_DAC_LEVEL = 128;
#if SOC_DAC_SUPPORTED
struct Esp32DacSpeakerInternal {
dac_continuous_handle_t handle = nullptr;
struct GpioDescriptor* pin_descriptor = nullptr;
// Open stream state.
bool is_open = false;
uint8_t open_bits_per_sample = 0;
uint32_t open_sample_rate = 0;
// Software volume/mute
int volume_percent = 100;
bool muted = false;
uint8_t scratch[CONVERT_CHUNK_SAMPLES];
};
#endif
#define GET_CONFIG(device) (static_cast<const Esp32DacSpeakerConfig*>((device)->config))
#define GET_DATA(device) (static_cast<Esp32DacSpeakerInternal*>(device_get_driver_data(device)))
#if SOC_DAC_SUPPORTED
dac_channel_mask_t pin_to_channel_mask(uint8_t pin) {
if (pin == DAC_CHAN0_GPIO_NUM) {
return DAC_CHANNEL_MASK_CH0;
}
if (pin == DAC_CHAN1_GPIO_NUM) {
return DAC_CHANNEL_MASK_CH1;
}
return 0;
}
int ticks_to_timeout_ms(TickType_t ticks) {
if (ticks == portMAX_DELAY) {
return -1;
}
return (int) (((uint64_t) ticks) * 1000 / configTICK_RATE_HZ);
}
// Create (or recreate, on a rate change) the DAC continuous channel at the given rate
error_t create_channel(Esp32DacSpeakerInternal* data, const Esp32DacSpeakerConfig* config, uint32_t sample_rate) {
dac_channel_mask_t mask = pin_to_channel_mask(config->pin.pin);
if (mask == 0) {
LOG_E(TAG, "Pin %u is not a DAC channel (ESP32: GPIO25 or GPIO26)", config->pin.pin);
return ERROR_NOT_SUPPORTED;
}
if (data->handle != nullptr) {
dac_continuous_disable(data->handle);
dac_continuous_del_channels(data->handle);
data->handle = nullptr;
}
const dac_continuous_config_t cfg = {
.chan_mask = mask,
.desc_num = DMA_DESC_COUNT,
.buf_size = DMA_BUF_SIZE,
.freq_hz = sample_rate,
.offset = 0,
.clk_src = DAC_DIGI_CLK_SRC_APLL,
.chan_mode = DAC_CHANNEL_MODE_SIMUL,
};
if (dac_continuous_new_channels(&cfg, &data->handle) != ESP_OK) {
LOG_E(TAG, "Failed to create continuous DAC channel at %lu Hz", (unsigned long) sample_rate);
data->handle = nullptr;
return ERROR_RESOURCE;
}
if (dac_continuous_enable(data->handle) != ESP_OK) {
LOG_E(TAG, "Failed to enable continuous DAC channel");
dac_continuous_del_channels(data->handle);
data->handle = nullptr;
return ERROR_RESOURCE;
}
return ERROR_NONE;
}
// Convert a chunk of 16-bit mono PCM into 8-bit DAC samples with software volume/mute applied.
void convert_pcm16_to_dac8(
Esp32DacSpeakerInternal* data,
const int16_t* pcm,
size_t samples,
int volume_percent,
uint8_t* out
) {
for (size_t i = 0; i < samples; i++) {
int32_t scaled = ((int32_t) pcm[i] * volume_percent) / 100;
out[i] = data->muted ? MID_DAC_LEVEL : (uint8_t) ((scaled >> 8) + 128);
}
}
// Same, for already-8-bit mono PCM (values 0..255, centered on 128).
void convert_pcm8_to_dac8(
Esp32DacSpeakerInternal* data,
const uint8_t* pcm,
size_t samples,
int volume_percent,
uint8_t* out
) {
for (size_t i = 0; i < samples; i++) {
int32_t scaled = (((int32_t) pcm[i] - 128) * volume_percent) / 100;
int32_t level = scaled + 128;
out[i] = data->muted ? MID_DAC_LEVEL : (uint8_t) (level < 0 ? 0 : (level > 255 ? 255 : level));
}
}
#endif // SOC_DAC_SUPPORTED
// region AudioCodecApi
error_t open(Device* device, const struct AudioCodecStreamConfig* config) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
const auto* cfg = GET_CONFIG(device);
if (data == nullptr || cfg == nullptr) {
return ERROR_RESOURCE;
}
if (config->direction != AUDIO_CODEC_DIR_OUTPUT && config->direction != AUDIO_CODEC_DIR_BOTH) {
return ERROR_NOT_SUPPORTED;
}
if (config->bits_per_sample != 8 && config->bits_per_sample != 16) {
return ERROR_NOT_SUPPORTED;
}
if (config->channels != 1) {
return ERROR_NOT_SUPPORTED;
}
if (config->sample_rate == 0) {
return ERROR_INVALID_ARGUMENT;
}
if (data->is_open) {
bool same_config = data->open_bits_per_sample == config->bits_per_sample
&& data->open_sample_rate == config->sample_rate;
return same_config ? ERROR_NONE : ERROR_RESOURCE;
}
if (create_channel(data, cfg, config->sample_rate) != ERROR_NONE) {
return ERROR_RESOURCE;
}
data->open_bits_per_sample = config->bits_per_sample;
data->open_sample_rate = config->sample_rate;
data->is_open = true;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t close(Device* device) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_RESOURCE;
}
if (data->is_open && data->handle != nullptr) {
dac_continuous_disable(data->handle);
dac_continuous_del_channels(data->handle);
data->handle = nullptr;
}
data->is_open = false;
data->open_bits_per_sample = 0;
data->open_sample_rate = 0;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t read(Device* device, void* buffer, size_t size, size_t* bytes_read, TickType_t timeout) {
(void) device;
(void) buffer;
(void) size;
(void) bytes_read;
(void) timeout;
return ERROR_NOT_SUPPORTED;
}
error_t write(Device* device, const void* buffer, size_t size, size_t* bytes_written, TickType_t timeout) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr || !data->is_open || data->handle == nullptr) {
return ERROR_RESOURCE;
}
const size_t frame_size = data->open_bits_per_sample / 8;
const size_t whole_bytes = size - (size % frame_size); // drop partial trailing frames
const size_t frame_count = whole_bytes / frame_size;
const uint8_t* input = static_cast<const uint8_t*>(buffer);
const int timeout_ms = ticks_to_timeout_ms(timeout);
size_t frames_done = 0;
while (frames_done < frame_count) {
const size_t chunk = frame_count - frames_done < CONVERT_CHUNK_SAMPLES
? frame_count - frames_done
: CONVERT_CHUNK_SAMPLES;
if (data->open_bits_per_sample == 16) {
convert_pcm16_to_dac8(data, reinterpret_cast<const int16_t*>(input + frames_done * frame_size), chunk, data->volume_percent, data->scratch);
} else {
convert_pcm8_to_dac8(data, input + frames_done * frame_size, chunk, data->volume_percent, data->scratch);
}
size_t loaded = 0;
esp_err_t result = dac_continuous_write(data->handle, data->scratch, chunk, &loaded, timeout_ms);
if (result != ESP_OK) {
*bytes_written = (frames_done + loaded) * frame_size;
return result == ESP_ERR_TIMEOUT ? ERROR_TIMEOUT : ERROR_RESOURCE;
}
frames_done += chunk;
}
*bytes_written = frame_count * frame_size;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t set_volume(Device* device, AudioCodecDirection direction, float volume_percent) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_RESOURCE;
}
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
if (volume_percent < 0.0f || volume_percent > 100.0f) {
return ERROR_INVALID_ARGUMENT;
}
data->volume_percent = (int) (volume_percent + 0.5f);
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t get_volume(Device* device, AudioCodecDirection direction, float* volume_percent) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_RESOURCE;
}
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
*volume_percent = (float) data->volume_percent;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t set_mute(Device* device, AudioCodecDirection direction, bool muted) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_RESOURCE;
}
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
data->muted = muted;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t get_mute(Device* device, AudioCodecDirection direction, bool* muted) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_RESOURCE;
}
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
*muted = data->muted;
return ERROR_NONE;
#else
return ERROR_NOT_SUPPORTED;
#endif
}
error_t get_native_channels(Device* device, AudioCodecDirection direction, uint8_t* channels) {
(void) device;
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
*channels = 1;
return ERROR_NONE;
}
error_t get_native_sample_rate(Device* device, AudioCodecDirection direction, uint32_t* rate_hz) {
if (direction != AUDIO_CODEC_DIR_OUTPUT) {
return ERROR_NOT_SUPPORTED;
}
auto* config = GET_CONFIG(device);
if (config != nullptr) {
*rate_hz = config->sample_rate;
return ERROR_NONE;
}
return ERROR_RESOURCE;
}
error_t get_capabilities(Device* device, AudioCodecDirection* supported_directions) {
(void) device;
*supported_directions = AUDIO_CODEC_DIR_OUTPUT;
return ERROR_NONE;
}
static const struct AudioCodecApi API = {
.open = open,
.close = close,
.read = read,
.write = write,
.set_volume = set_volume,
.get_volume = get_volume,
.set_mute = set_mute,
.get_mute = get_mute,
.get_native_sample_rate = get_native_sample_rate,
.get_native_channels = get_native_channels,
.get_capabilities = get_capabilities,
};
// endregion
// region Driver lifecycle
error_t start_device(Device* device) {
#if SOC_DAC_SUPPORTED
const auto* config = GET_CONFIG(device);
if (config == nullptr) {
return ERROR_RESOURCE;
}
if (pin_to_channel_mask(config->pin.pin) == 0) {
LOG_E(TAG, "Pin %u is not an ESP32 DAC channel (GPIO25 = DAC1, GPIO26 = DAC2)", config->pin.pin);
return ERROR_NOT_SUPPORTED;
}
auto* data = new (std::nothrow) Esp32DacSpeakerInternal();
if (data == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
if (config->pin.gpio_controller != nullptr) {
// GPIO_OWNER_PERIPHERAL: the DAC driver configures the pin's mux/function itself, so we
// only reserve ownership to keep it out of other consumers' hands.
data->pin_descriptor = gpio_descriptor_acquire(
config->pin.gpio_controller,
config->pin.pin,
config->pin.flags | GPIO_FLAG_DIRECTION_OUTPUT,
GPIO_OWNER_PERIPHERAL
);
if (data->pin_descriptor == nullptr) {
LOG_E(TAG, "Failed to reserve DAC pin %u", config->pin.pin);
delete data;
return ERROR_RESOURCE;
}
}
device_set_driver_data(device, data);
return ERROR_NONE;
#else
(void) device;
return ERROR_NOT_SUPPORTED;
#endif
}
error_t stop_device(Device* device) {
#if SOC_DAC_SUPPORTED
auto* data = GET_DATA(device);
if (data == nullptr) {
return ERROR_NONE;
}
if (data->handle != nullptr) {
dac_continuous_disable(data->handle);
dac_continuous_del_channels(data->handle);
data->handle = nullptr;
}
if (data->pin_descriptor != nullptr) {
gpio_descriptor_release(data->pin_descriptor);
data->pin_descriptor = nullptr;
}
device_set_driver_data(device, nullptr);
delete data;
return ERROR_NONE;
#else
(void) device;
return ERROR_NONE;
#endif
}
// endregion
} // namespace
extern "C" {
Driver esp32_dac_speaker_driver = {
.name = "esp32_dac_speaker",
.compatible = (const char*[]) { "espressif,esp32-dac-speaker", nullptr },
.start_device = start_device,
.stop_device = stop_device,
.api = &API,
.device_type = &AUDIO_CODEC_TYPE,
.owner = nullptr,
.internal = nullptr,
};
}

View File

@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver esp32_dac_speaker_driver;
static Driver* const esp32_dac_speaker_drivers[] = {
&esp32_dac_speaker_driver,
nullptr
};
extern const ModuleSymbol esp32_dac_speaker_module_symbols[];
Module esp32_dac_speaker_module = {
.name = "esp32_dac_speaker",
.start = nullptr,
.stop = nullptr,
.drivers = esp32_dac_speaker_drivers,
.symbols = esp32_dac_speaker_module_symbols,
.internal = nullptr
};
}

View File

@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/module.h>
const struct ModuleSymbol esp32_dac_speaker_module_symbols[] = {
MODULE_SYMBOL_TERMINATOR
};

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(st7789-soft-i8080-module
SRCS ${SOURCE_FILES}
INCLUDE_DIRS include/
REQUIRES TactilityKernel platform-esp32 driver
)

View File

@ -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.

View File

@ -0,0 +1,5 @@
# ST7789 Soft i8080 Display Driver
A kernel driver for the `ST7789` display panel over a soft (bit-banged) 8-bit parallel (i8080) interface, driven directly from GPIO registers.
License: [Apache v2.0](LICENSE-Apache-2.0.md)

View File

@ -0,0 +1,97 @@
description: Sitronix ST7789 display panel driven over a bit-banged 8-bit parallel (8080) interface.
compatible: "sitronix,st7789-soft-i8080"
properties:
horizontal-resolution:
type: int
required: true
description: Horizontal resolution in pixels
vertical-resolution:
type: int
required: true
description: Vertical resolution in pixels
gap-x:
type: int
default: 0
description: X offset applied to all draw operations
gap-y:
type: int
default: 0
description: Y offset applied to all draw operations
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
invert-color:
type: boolean
default: false
description: Invert the panel's color output
bgr-order:
type: boolean
default: false
description: Use BGR element order instead of RGB
pin-d0:
type: phandles
required: true
description: Parallel data bus bit 0 GPIO pin
pin-d1:
type: phandles
required: true
description: Parallel data bus bit 1 GPIO pin
pin-d2:
type: phandles
required: true
description: Parallel data bus bit 2 GPIO pin
pin-d3:
type: phandles
required: true
description: Parallel data bus bit 3 GPIO pin
pin-d4:
type: phandles
required: true
description: Parallel data bus bit 4 GPIO pin
pin-d5:
type: phandles
required: true
description: Parallel data bus bit 5 GPIO pin
pin-d6:
type: phandles
required: true
description: Parallel data bus bit 6 GPIO pin
pin-d7:
type: phandles
required: true
description: Parallel data bus bit 7 GPIO pin
pin-cs:
type: phandles
required: true
description: Chip-select GPIO pin (active low)
pin-dc:
type: phandles
required: true
description: Data/command select GPIO pin
pin-wr:
type: phandles
required: true
description: Write strobe GPIO pin (data latched on the rising edge)
pin-rd:
type: phandles
required: true
description: Read strobe GPIO pin (active low, kept high)
pin-reset:
type: phandles
default: GPIO_PIN_SPEC_NONE
description: Optional hardware reset GPIO pin (active low)
backlight:
type: phandle
default: "NULL"
description: Optional reference to this display's backlight device

View File

@ -0,0 +1,3 @@
dependencies:
- TactilityKernel
bindings: bindings

View File

@ -0,0 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/bindings/bindings.h>
#include <drivers/st7789_soft_i8080.h>
DEFINE_DEVICETREE(st7789_soft_i8080, struct St7789SoftI8080Config)

View File

@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#include <tactility/device.h>
#include <tactility/drivers/gpio.h>
struct St7789SoftI8080Config {
uint16_t horizontal_resolution;
uint16_t vertical_resolution;
int32_t gap_x;
int32_t gap_y;
bool swap_xy;
bool mirror_x;
bool mirror_y;
bool invert_color;
bool bgr_order;
struct GpioPinSpec pin_d0;
struct GpioPinSpec pin_d1;
struct GpioPinSpec pin_d2;
struct GpioPinSpec pin_d3;
struct GpioPinSpec pin_d4;
struct GpioPinSpec pin_d5;
struct GpioPinSpec pin_d6;
struct GpioPinSpec pin_d7;
struct GpioPinSpec pin_cs;
struct GpioPinSpec pin_dc;
struct GpioPinSpec pin_wr;
struct GpioPinSpec pin_rd;
struct GpioPinSpec pin_reset;
struct Device* backlight;
};
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include <tactility/module.h>
#ifdef __cplusplus
extern "C" {
#endif
extern struct Module st7789_soft_i8080_module;
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,23 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/driver.h>
#include <tactility/module.h>
extern "C" {
extern Driver st7789_soft_i8080_driver;
static Driver* const st7789_soft_i8080_drivers[] = {
&st7789_soft_i8080_driver,
nullptr
};
Module st7789_soft_i8080_module = {
.name = "st7789_soft_i8080",
.start = nullptr,
.stop = nullptr,
.drivers = st7789_soft_i8080_drivers,
.symbols = nullptr,
.internal = nullptr
};
} // extern "C"

View File

@ -0,0 +1,434 @@
// SPDX-License-Identifier: Apache-2.0
#include <drivers/st7789_soft_i8080.h>
#include <st7789_soft_i8080_module.h>
#include <tactility/check.h>
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/display.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/error.h>
#include <tactility/log.h>
#include <driver/gpio.h>
#include <soc/gpio_struct.h>
#include <freertos/task.h>
#include <cstdlib>
#include <initializer_list>
#define TAG "ST7789SOFT"
#define GET_CONFIG(device) (static_cast<const St7789SoftI8080Config*>((device)->config))
// Bit-banged 8-bit parallel ST7789 transport.
struct St7789SoftI8080Internal {
// GPIO register bit masks per pin.
struct MaskPair {
uint32_t low; // GPIO0..31 bits
uint32_t high; // GPIO32..39 bits
};
MaskPair set_mask_by_byte[256];
MaskPair clear_mask_by_byte[256];
MaskPair cs_mask;
MaskPair dc_mask;
MaskPair wr_mask;
uint8_t madctl;
int16_t gap_x;
int16_t gap_y;
// pin descriptors (8 data + CS/DC/WR/RD), kept for release on stop().
struct GpioDescriptor* descriptors[12];
uint8_t descriptor_count;
};
static St7789SoftI8080Internal::MaskPair bitbang_mask_for_pin(gpio_pin_t pin) {
St7789SoftI8080Internal::MaskPair pair = { 0, 0 };
if (pin < 32) {
pair.low = 1U << pin;
} else {
pair.high = 1U << (pin - 32);
}
return pair;
}
static error_t bitbang_init_pins(St7789SoftI8080Internal* internal, const St7789SoftI8080Config* config) {
const struct GpioPinSpec* data_specs[8] = {
&config->pin_d0, &config->pin_d1, &config->pin_d2, &config->pin_d3,
&config->pin_d4, &config->pin_d5, &config->pin_d6, &config->pin_d7,
};
const struct GpioPinSpec* control_specs[4] = {
&config->pin_cs, &config->pin_dc, &config->pin_wr, &config->pin_rd,
};
internal->descriptor_count = 0;
const auto acquire = [internal](const struct GpioPinSpec& spec) {
// Bit-bang pins carry no logical meaning
struct GpioDescriptor* descriptor = gpio_descriptor_acquire(
spec.gpio_controller, spec.pin, spec.flags | GPIO_FLAG_DIRECTION_OUTPUT, GPIO_OWNER_GPIO
);
if (descriptor == nullptr) {
for (int i = 0; i < internal->descriptor_count; i++) {
gpio_descriptor_release(internal->descriptors[i]);
}
return false;
}
internal->descriptors[internal->descriptor_count++] = descriptor;
return true;
};
for (const struct GpioPinSpec* spec : data_specs) {
if (!acquire(*spec)) {
return ERROR_RESOURCE;
}
}
for (const struct GpioPinSpec* spec : control_specs) {
if (!acquire(*spec)) {
return ERROR_RESOURCE;
}
}
gpio_pin_t data_pins[8];
for (int i = 0; i < 8; i++) {
gpio_descriptor_get_pin_number(internal->descriptors[i], &data_pins[i]);
}
internal->cs_mask = bitbang_mask_for_pin(config->pin_cs.pin);
internal->dc_mask = bitbang_mask_for_pin(config->pin_dc.pin);
internal->wr_mask = bitbang_mask_for_pin(config->pin_wr.pin);
gpio_set_level(static_cast<gpio_num_t>(config->pin_cs.pin), 1);
gpio_set_level(static_cast<gpio_num_t>(config->pin_rd.pin), 1);
gpio_set_level(static_cast<gpio_num_t>(config->pin_wr.pin), 1);
gpio_set_level(static_cast<gpio_num_t>(config->pin_dc.pin), 1);
for (int i = 0; i < 8; i++) {
gpio_set_level(static_cast<gpio_num_t>(data_pins[i]), 0);
}
// Precompute per-byte set/clear masks
for (uint32_t value = 0; value < 256; value++) {
St7789SoftI8080Internal::MaskPair set_pair = { 0, 0 };
St7789SoftI8080Internal::MaskPair clear_pair = { 0, 0 };
for (size_t i = 0; i < 8; i++) {
St7789SoftI8080Internal::MaskPair pin_mask = bitbang_mask_for_pin(data_pins[i]);
if (value & (1U << i)) {
set_pair.low |= pin_mask.low;
set_pair.high |= pin_mask.high;
} else {
clear_pair.low |= pin_mask.low;
clear_pair.high |= pin_mask.high;
}
}
internal->set_mask_by_byte[value] = set_pair;
internal->clear_mask_by_byte[value] = clear_pair;
}
return ERROR_NONE;
}
static void bitbang_set_mask(const St7789SoftI8080Internal::MaskPair& mask) {
GPIO.out_w1ts = mask.low;
GPIO.out1_w1ts.val = mask.high;
}
static void bitbang_clear_mask(const St7789SoftI8080Internal::MaskPair& mask) {
GPIO.out_w1tc = mask.low;
GPIO.out1_w1tc.val = mask.high;
}
static void bitbang_write_byte(St7789SoftI8080Internal* internal, uint8_t value) {
// Clear-then-set avoids read-modify-write on GPIO.out
bitbang_clear_mask(internal->clear_mask_by_byte[value]);
bitbang_set_mask(internal->set_mask_by_byte[value]);
bitbang_clear_mask(internal->wr_mask);
bitbang_set_mask(internal->wr_mask); // rising edge latches the byte
}
static void bitbang_send_cmd(St7789SoftI8080Internal* internal, uint8_t cmd, const uint8_t* params, size_t len) {
bitbang_clear_mask(internal->cs_mask);
bitbang_clear_mask(internal->dc_mask);
bitbang_write_byte(internal, cmd);
if (len > 0) {
bitbang_set_mask(internal->dc_mask);
for (size_t i = 0; i < len; i++) {
bitbang_write_byte(internal, params[i]);
}
}
bitbang_set_mask(internal->cs_mask);
}
static void bitbang_send_madctl(St7789SoftI8080Internal* internal) {
bitbang_send_cmd(internal, 0x36, &internal->madctl, 1);
}
static error_t bitbang_init_panel(St7789SoftI8080Internal* internal, const St7789SoftI8080Config* config) {
internal->gap_x = config->swap_xy ? config->gap_y : config->gap_x;
internal->gap_y = config->swap_xy ? config->gap_x : config->gap_y;
bitbang_send_cmd(internal, 0x01, nullptr, 0); // SWRESET
vTaskDelay(pdMS_TO_TICKS(150));
bitbang_send_cmd(internal, 0x11, nullptr, 0); // SLPOUT
vTaskDelay(pdMS_TO_TICKS(120));
internal->madctl = (config->bgr_order ? 0x08 : 0x00) |
(config->mirror_y ? 0x80 : 0x00) |
(config->mirror_x ? 0x40 : 0x00) |
(config->swap_xy ? 0x20 : 0x00);
bitbang_send_madctl(internal);
const uint8_t colmod = 0x55; // 16 bits per pixel
bitbang_send_cmd(internal, 0x3A, &colmod, 1);
// RAMCTRL little-endian
const uint8_t ramctl[] = { 0x00, 0xF8 };
bitbang_send_cmd(internal, 0xB0, ramctl, 2);
if (config->invert_color) {
bitbang_send_cmd(internal, 0x21, nullptr, 0); // INVON
}
bitbang_send_cmd(internal, 0x29, nullptr, 0); // DISPON
vTaskDelay(pdMS_TO_TICKS(20));
return ERROR_NONE;
}
static void bitbang_draw_bitmap(St7789SoftI8080Internal* internal, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const uint8_t* color_data) {
int32_t x0 = x_start + internal->gap_x;
int32_t x1 = x_end + internal->gap_x;
int32_t y0 = y_start + internal->gap_y;
int32_t y1 = y_end + internal->gap_y;
const uint8_t caset[] = { (uint8_t)(x0 >> 8), (uint8_t)x0, (uint8_t)((x1 - 1) >> 8), (uint8_t)(x1 - 1) };
bitbang_send_cmd(internal, 0x2A, caset, 4);
const uint8_t raset[] = { (uint8_t)(y0 >> 8), (uint8_t)y0, (uint8_t)((y1 - 1) >> 8), (uint8_t)(y1 - 1) };
bitbang_send_cmd(internal, 0x2B, raset, 4);
bitbang_clear_mask(internal->cs_mask);
bitbang_clear_mask(internal->dc_mask);
bitbang_write_byte(internal, 0x2C); // RAMWR
bitbang_set_mask(internal->dc_mask);
size_t len = (size_t)(x1 - x0) * (y1 - y0) * 2;
for (size_t i = 0; i < len; i++) {
bitbang_write_byte(internal, color_data[i]);
}
bitbang_set_mask(internal->cs_mask);
}
static error_t bitbang_mirror(St7789SoftI8080Internal* internal, bool mirror_x, bool mirror_y) {
internal->madctl = (internal->madctl & ~0xC0) | (mirror_x ? 0x40 : 0x00) | (mirror_y ? 0x80 : 0x00);
bitbang_send_madctl(internal);
return ERROR_NONE;
}
static error_t bitbang_swap_xy(St7789SoftI8080Internal* internal, bool swap_axes) {
internal->madctl = (internal->madctl & ~0x20) | (swap_axes ? 0x20 : 0x00);
bitbang_send_madctl(internal);
return ERROR_NONE;
}
static error_t bitbang_invert_color(St7789SoftI8080Internal* internal, bool invert_color_data) {
bitbang_send_cmd(internal, invert_color_data ? 0x21 : 0x20, nullptr, 0);
return ERROR_NONE;
}
static error_t bitbang_disp_on_off(St7789SoftI8080Internal* internal, bool on_off) {
bitbang_send_cmd(internal, on_off ? 0x29 : 0x28, nullptr, 0);
return ERROR_NONE;
}
static error_t bitbang_disp_sleep(St7789SoftI8080Internal* internal, bool sleep) {
bitbang_send_cmd(internal, sleep ? 0x10 : 0x11, nullptr, 0);
if (!sleep) {
vTaskDelay(pdMS_TO_TICKS(120));
}
return ERROR_NONE;
}
// region Driver lifecycle
static error_t start(Device* device) {
const auto* config = GET_CONFIG(device);
auto* internal = static_cast<St7789SoftI8080Internal*>(malloc(sizeof(St7789SoftI8080Internal)));
if (internal == nullptr) {
return ERROR_OUT_OF_MEMORY;
}
error_t err = bitbang_init_pins(internal, config);
if (err != ERROR_NONE) {
free(internal);
return err;
}
err = bitbang_init_panel(internal, config);
if (err != ERROR_NONE) {
for (int i = 0; i < internal->descriptor_count; i++) {
gpio_descriptor_release(internal->descriptors[i]);
}
free(internal);
return err;
}
device_set_driver_data(device, internal);
LOG_I(TAG, "Panel driven via bit-banged 8-bit GPIO transport");
return ERROR_NONE;
}
static error_t stop(Device* device) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
for (int i = 0; i < internal->descriptor_count; i++) {
gpio_descriptor_release(internal->descriptors[i]);
}
free(internal);
device_set_driver_data(device, nullptr);
return ERROR_NONE;
}
// endregion
// region DisplayApi
static error_t st7789_soft_i8080_reset(Device*) {
// The panel was fully initialised in start(); there is no reset line on the board this
// targets, so re-init is a no-op.
// TODO: Implement a reset sequence if a reset line is added for support for other boards.
return ERROR_NONE;
}
static error_t st7789_soft_i8080_init(Device*) {
return ERROR_NONE;
}
static error_t st7789_soft_i8080_draw_bitmap(Device* device, int32_t x_start, int32_t y_start, int32_t x_end, int32_t y_end, const void* color_data) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
bitbang_draw_bitmap(internal, x_start, y_start, x_end, y_end, static_cast<const uint8_t*>(color_data));
return ERROR_NONE;
}
static error_t st7789_soft_i8080_mirror(Device* device, bool x_axis, bool y_axis) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return bitbang_mirror(internal, x_axis, y_axis);
}
static error_t st7789_soft_i8080_swap_xy(Device* device, bool swap_axes) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return bitbang_swap_xy(internal, swap_axes);
}
static bool st7789_soft_i8080_get_swap_xy(Device* device) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return (internal->madctl & 0x20) != 0;
}
static bool st7789_soft_i8080_get_mirror_x(Device* device) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return (internal->madctl & 0x40) != 0;
}
static bool st7789_soft_i8080_get_mirror_y(Device* device) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return (internal->madctl & 0x80) != 0;
}
static int32_t st7789_soft_i8080_get_gap_x(Device* device) {
const auto* config = GET_CONFIG(device);
return config->swap_xy ? config->gap_y : config->gap_x;
}
static int32_t st7789_soft_i8080_get_gap_y(Device* device) {
const auto* config = GET_CONFIG(device);
return config->swap_xy ? config->gap_x : config->gap_y;
}
static error_t st7789_soft_i8080_set_gap(Device* device, int32_t x_gap, int32_t y_gap) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
internal->gap_x = x_gap;
internal->gap_y = y_gap;
return ERROR_NONE;
}
static error_t st7789_soft_i8080_invert_color(Device* device, bool invert_color_data) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return bitbang_invert_color(internal, invert_color_data);
}
static error_t st7789_soft_i8080_disp_on_off(Device* device, bool on_off) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return bitbang_disp_on_off(internal, on_off);
}
static error_t st7789_soft_i8080_disp_sleep(Device* device, bool sleep) {
auto* internal = static_cast<St7789SoftI8080Internal*>(device_get_driver_data(device));
return bitbang_disp_sleep(internal, sleep);
}
static enum DisplayColorFormat st7789_soft_i8080_get_color_format(Device*) {
return DISPLAY_COLOR_FORMAT_RGB565;
}
static uint16_t st7789_soft_i8080_get_resolution_x(Device* device) {
return GET_CONFIG(device)->horizontal_resolution;
}
static uint16_t st7789_soft_i8080_get_resolution_y(Device* device) {
return GET_CONFIG(device)->vertical_resolution;
}
static void st7789_soft_i8080_get_frame_buffer(Device*, uint8_t, void** out_buffer) {
*out_buffer = nullptr;
}
static uint8_t st7789_soft_i8080_get_frame_buffer_count(Device*) {
return 0;
}
static error_t st7789_soft_i8080_get_backlight(Device* device, Device** backlight) {
auto* configured_backlight = GET_CONFIG(device)->backlight;
if (configured_backlight == nullptr) {
return ERROR_NOT_SUPPORTED;
}
*backlight = configured_backlight;
return ERROR_NONE;
}
// endregion
static const DisplayApi st7789_soft_i8080_display_api = {
.capabilities = DISPLAY_CAPABILITY_CAP_MIRROR | DISPLAY_CAPABILITY_CAP_SWAP_XY |
DISPLAY_CAPABILITY_CAP_SET_GAP | DISPLAY_CAPABILITY_INVERT_COLOR | DISPLAY_CAPABILITY_ON_OFF |
DISPLAY_CAPABILITY_SLEEP | DISPLAY_CAPABILITY_BACKLIGHT,
.reset = st7789_soft_i8080_reset,
.init = st7789_soft_i8080_init,
.draw_bitmap = st7789_soft_i8080_draw_bitmap,
.clear = nullptr,
.refresh = nullptr,
.mirror = st7789_soft_i8080_mirror,
.swap_xy = st7789_soft_i8080_swap_xy,
.get_swap_xy = st7789_soft_i8080_get_swap_xy,
.get_mirror_x = st7789_soft_i8080_get_mirror_x,
.get_mirror_y = st7789_soft_i8080_get_mirror_y,
.set_gap = st7789_soft_i8080_set_gap,
.get_gap_x = st7789_soft_i8080_get_gap_x,
.get_gap_y = st7789_soft_i8080_get_gap_y,
.invert_color = st7789_soft_i8080_invert_color,
.disp_on_off = st7789_soft_i8080_disp_on_off,
.disp_sleep = st7789_soft_i8080_disp_sleep,
.get_color_format = st7789_soft_i8080_get_color_format,
.get_resolution_x = st7789_soft_i8080_get_resolution_x,
.get_resolution_y = st7789_soft_i8080_get_resolution_y,
.get_frame_buffer = st7789_soft_i8080_get_frame_buffer,
.get_frame_buffer_count = st7789_soft_i8080_get_frame_buffer_count,
.get_backlight = st7789_soft_i8080_get_backlight,
.has_capability = nullptr,
};
Driver st7789_soft_i8080_driver = {
.name = "st7789_soft_i8080",
.compatible = (const char*[]) { "sitronix,st7789-soft-i8080", nullptr },
.start_device = start,
.stop_device = stop,
.probe = nullptr,
.api = &st7789_soft_i8080_display_api,
.device_type = &DISPLAY_TYPE,
.owner = &st7789_soft_i8080_module,
.internal = nullptr
};

View File

@ -141,7 +141,8 @@ void pixel_buffer_clear(struct PixelBuffer* buffer) {
// bounds beyond its own logical size are unknown, so its range is left as-is and // bounds beyond its own logical size are unknown, so its range is left as-is and
// ESP_CACHE_MSYNC_FLAG_UNALIGNED is passed instead, letting the cache API handle the misalignment // ESP_CACHE_MSYNC_FLAG_UNALIGNED is passed instead, letting the cache API handle the misalignment
// without this code guessing at memory it doesn't own. // without this code guessing at memory it doesn't own.
static esp_err_t pixel_buffer_msync_range(struct PixelBuffer* buffer, uint8_t* addr, size_t bytes) { static bool pixel_buffer_msync_range(struct PixelBuffer* buffer, uint8_t* addr, size_t bytes) {
esp_err_t err;
if (buffer->owns_data) { if (buffer->owns_data) {
const size_t offset = (size_t)(addr - buffer->data); const size_t offset = (size_t)(addr - buffer->data);
const size_t aligned_offset = offset & ~(size_t)63; const size_t aligned_offset = offset & ~(size_t)63;
@ -150,9 +151,14 @@ static esp_err_t pixel_buffer_msync_range(struct PixelBuffer* buffer, uint8_t* a
if (aligned_end > capacity) { if (aligned_end > capacity) {
aligned_end = capacity; aligned_end = capacity;
} }
return esp_cache_msync(buffer->data + aligned_offset, aligned_end - aligned_offset, ESP_CACHE_MSYNC_FLAG_DIR_C2M); err = esp_cache_msync(buffer->data + aligned_offset, aligned_end - aligned_offset, ESP_CACHE_MSYNC_FLAG_DIR_C2M);
} else {
err = esp_cache_msync(addr, bytes, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED);
} }
return esp_cache_msync(addr, bytes, ESP_CACHE_MSYNC_FLAG_DIR_C2M | ESP_CACHE_MSYNC_FLAG_UNALIGNED); // esp_cache_msync() reports ESP_ERR_NOT_SUPPORTED for ranges not mapped through a cache
// (plain internal DRAM on ESP32-class cores). There is nothing to sync there, so treat it
// as success rather than failing the present.
return err == ESP_OK || err == ESP_ERR_NOT_SUPPORTED;
} }
#endif #endif
@ -163,13 +169,13 @@ bool pixel_buffer_msync(struct PixelBuffer* buffer, int x, int y, int width, int
if (contiguous) { if (contiguous) {
uint8_t* addr = pixel_buffer_get_row(buffer, y); uint8_t* addr = pixel_buffer_get_row(buffer, y);
const size_t bytes = buffer->stride_bytes * (size_t)height; const size_t bytes = buffer->stride_bytes * (size_t)height;
ok = pixel_buffer_msync_range(buffer, addr, bytes) == ESP_OK; ok = pixel_buffer_msync_range(buffer, addr, bytes);
} else { } else {
const size_t rowBytes = pixel_buffer_row_stride_bytes(buffer->format, width); const size_t rowBytes = pixel_buffer_row_stride_bytes(buffer->format, width);
const size_t xBytes = pixel_buffer_row_stride_bytes(buffer->format, x); const size_t xBytes = pixel_buffer_row_stride_bytes(buffer->format, x);
for (int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
uint8_t* rowPtr = (uint8_t*)pixel_buffer_get_row(buffer, y + row) + xBytes; uint8_t* rowPtr = (uint8_t*)pixel_buffer_get_row(buffer, y + row) + xBytes;
if (pixel_buffer_msync_range(buffer, rowPtr, rowBytes) != ESP_OK) { if (!pixel_buffer_msync_range(buffer, rowPtr, rowBytes)) {
ok = false; ok = false;
} }
} }