[bug] ESP32SPI sends garbage data to display on 9-bit SPI
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- arduino, cpp
- 领域
- embedded-iot
调研方向
Start by reading Arduino_ESP32SPI's beginWrite(), writeRepeat(), and flush_data_buf() implementations, along with the linked ESP-IDF documentation on transactions whose sizes are not multiples of 8 bits. Check the open pull request before starting; done means 9-bit SPI communication no longer sends trailing garbage and the display can initialize and show output.
由索引模型根据 Issue 内容生成。
描述
Currently, the ESP32SPI databus cannot properly communicate with a display through 9-bit SPI, not even initialize it.
Since the ESP32 SPI driver sends data byte by byte, any message that does not make up a multiple of bytes gets padded with "random bits" as the official docs says. So in the flush function, pushing any amount of bits (consists of 9-bit commands) may include garbage data at the end to make up a full byte, breaking the communication.
If the amount of bits pushed is limited to multiple of 8, with some other additional changes (because flushing now may not leave the buffer empty), the communication would work and the display could display something.
my current changes
void Arduino_ESP32SPI::beginWrite()
{
// _data_buf_bit_idx = 0;
// _buffer[0] = 0;
...
}
void Arduino_ESP32SPI::writeRepeat(uint16_t p, uint32_t len)
{
...
if (_dc == GFX_NOT_DEFINED) // 9-bit SPI
{
for (uint32_t i = 0; i < len; i++) {
write16(p);
}
return; // TEMPORARY FIX
...
}
void Arduino_ESP32SPI::flush_data_buf()
{
if (_data_buf_bit_idx % 8 != 0) return;
uint16_t bytes = _data_buf_bit_idx / 8; // total bytes to flush, NOT including leftovers
// uint32_t len = (_data_buf_bit_idx + 31) / 32;
uint32_t len = (bytes + 3) / 4;
for (uint32_t i = 0; i < len; i++)
{
#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32P4 || CONFIG_IDF_TARGET_ESP32C5
_spi->dev->data_buf[i].val = _buffer32[i];
#else
_spi->dev->data_buf[i] = _buffer32[i];
#endif
}
POLL(bytes * 8 - 1);
uint16_t leftover_bits = _data_buf_bit_idx - bytes * 8;
_buffer[0] = _buffer[bytes];
_data_buf_bit_idx = leftover_bits;
// _data_buf_bit_idx = 0;
}
The better solution, I think, is padding flushes with no-op commands (9 zeros i believe) until the data is a multiple of bytes. At maximum, only 7 commands would be padded. This doesn't leave part of existing commands in the buffer after flushing, and the assumption that the buffer would be empty after flushing wouldn't be broken as well.
I'd love to create a PR for that if wanted, since I'm working with this 3-wire SPI display module myself already.
Thanks for the amazing library, and wish you a nice 2026 :)
- 主要语言
- C
- 星标
- 1.1k
- 派生
- 249
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 2
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
moononournation/Arduino_GFX 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
moononournation/Arduino_GFX#826 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 50/100
moononournation/Arduino_GFX#827 ·
-
难度 2/5 1-3 小时 新手友好度 52/100
moononournation/Arduino_GFX#825 · 6 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
moononournation/Arduino_GFX#715 · 11 条评论 ·
查看 moononournation/Arduino_GFX 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
raspberrypi/usbboot#419 ·
-
difficulty: easy docs good first issue help wanted
难度 2/5 1-3 小时 新手友好度 74/100
Ryan-Millard/Img2Num#842 ·
维护者通常 12 天内回复
-
难度 1/5 1 小时以内 新手友好度 85/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
SanderMertens/flecs#2461 ·
维护者通常 1 天内回复